FileIO Schema started
This commit is contained in:
165
runtime/newlib/newlib.c
Normal file
165
runtime/newlib/newlib.c
Normal file
@@ -0,0 +1,165 @@
|
||||
|
||||
|
||||
#include "../io/vx_io.h"
|
||||
#include "../fileio/fileio.h"
|
||||
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define CLOSE 1
|
||||
#define ISATTY 2
|
||||
#define LSEEK 3
|
||||
#define READ 4
|
||||
#define WRITE 5
|
||||
#define FSTAT 6
|
||||
|
||||
#define FILE_IO_WRITE 0x71000000
|
||||
#define FILE_IO_READ 0x72000000
|
||||
|
||||
void upload(char ** ptr, char * src, int size)
|
||||
{
|
||||
char * drain = *ptr;
|
||||
|
||||
*drain = size;
|
||||
drain += 4;
|
||||
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
(*drain) = src[i];
|
||||
drain += 1;
|
||||
}
|
||||
|
||||
*ptr = drain;
|
||||
}
|
||||
|
||||
void download(char ** ptr, char * drain)
|
||||
{
|
||||
char * src = *ptr;
|
||||
|
||||
int size;
|
||||
size = *((int *) src);
|
||||
src += 4;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
drain[i] = (*src);
|
||||
src += 1;
|
||||
}
|
||||
|
||||
*ptr = src;
|
||||
}
|
||||
|
||||
void _close()
|
||||
{
|
||||
vx_print_str("Hello from _close\n");
|
||||
}
|
||||
|
||||
int _fstat(int file, struct stat * st)
|
||||
{
|
||||
char * write_buffer = (char *) FILE_IO_WRITE;
|
||||
|
||||
int cmd_id = FSTAT;
|
||||
|
||||
upload((char **) &write_buffer, (char *) &cmd_id, sizeof(int));
|
||||
upload((char **) &write_buffer, (char *) &file , sizeof(int));
|
||||
|
||||
vx_fstat();
|
||||
|
||||
char * read_buffer = (char *) FILE_IO_READ;
|
||||
|
||||
download((char **) &read_buffer, (char *) st);
|
||||
}
|
||||
|
||||
int _isatty (int file)
|
||||
{
|
||||
vx_print_str("Hello from _isatty\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _lseek()
|
||||
{
|
||||
|
||||
vx_print_str("Hello from _lseek\n");
|
||||
}
|
||||
|
||||
void _read()
|
||||
{
|
||||
|
||||
vx_print_str("Hello from _read\n");
|
||||
}
|
||||
|
||||
int _write (int file, char *buf, int nbytes)
|
||||
{
|
||||
|
||||
char * write_buffer = (char *) FILE_IO_WRITE;
|
||||
|
||||
int cmd_id = WRITE;
|
||||
|
||||
upload((char **) &write_buffer, (char *) &cmd_id, sizeof(int));
|
||||
upload((char **) &write_buffer, (char *) &file , sizeof(int));
|
||||
|
||||
upload((char **) &write_buffer, (char *) buf , nbytes);
|
||||
|
||||
vx_write();
|
||||
|
||||
|
||||
// int i;
|
||||
|
||||
// unsigned int volatile * const print_addr = (unsigned int *) 0x00010000;
|
||||
|
||||
// for (i = 0; i < nbytes; i++)
|
||||
// {
|
||||
// (*print_addr) = buf[i];
|
||||
// }
|
||||
|
||||
// return nbytes;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int heap_start = (int) 0x10000000;
|
||||
static int head_end = (int) 0x20000000;
|
||||
|
||||
void * _sbrk (int nbytes)
|
||||
{
|
||||
//vx_print_str("Hello from _sbrk\n");
|
||||
//vx_printf("nbytes: ", nbytes);
|
||||
|
||||
//if (nbytes < 0) vx_print_str("nbytes less than zero\n");
|
||||
// printf("nBytes: %d\n", nbytes);
|
||||
|
||||
if (nbytes < 0)
|
||||
{
|
||||
nbytes = nbytes * -1;
|
||||
}
|
||||
|
||||
if (nbytes > 10240)
|
||||
{
|
||||
nbytes = 10240;
|
||||
}
|
||||
|
||||
// if (((unsigned) head_end) > ((unsigned) (heap_ptr + nbytes)))
|
||||
if (true)
|
||||
{
|
||||
int base = heap_start;
|
||||
heap_start += nbytes;
|
||||
//vx_print_str("_sbrk returning: ");
|
||||
//vx_print_hex((unsigned) base);
|
||||
//vx_print_str("\n");
|
||||
return (void *) base;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *) -1;
|
||||
}
|
||||
} /* _sbrk () */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
182
runtime/newlib/newlib.s
Normal file
182
runtime/newlib/newlib.s
Normal file
@@ -0,0 +1,182 @@
|
||||
|
||||
|
||||
|
||||
# .type __lttf2, @function
|
||||
# .global __lttf2
|
||||
# __lttf2:
|
||||
# ret
|
||||
|
||||
|
||||
# .type __extenddftf2, @function
|
||||
# .global __extenddftf2
|
||||
# __extenddftf2:
|
||||
# ret
|
||||
|
||||
|
||||
# .type __trunctfdf2, @function
|
||||
# .global __trunctfdf2
|
||||
# __trunctfdf2:
|
||||
# ret
|
||||
|
||||
|
||||
# .type __multf3, @function
|
||||
# .global __multf3
|
||||
# __multf3:
|
||||
# ret
|
||||
|
||||
|
||||
# .type __fixtfsi, @function
|
||||
# .global __fixtfsi
|
||||
# __fixtfsi:
|
||||
# ret
|
||||
|
||||
# .type __floatsitf, @function
|
||||
# .global __floatsitf
|
||||
# __floatsitf:
|
||||
# ret
|
||||
|
||||
# .type __subtf3, @function
|
||||
# .global __subtf3
|
||||
# __subtf3:
|
||||
# ret
|
||||
|
||||
# .type __gttf2, @function
|
||||
# .global __gttf2
|
||||
# __gttf2:
|
||||
# ret
|
||||
|
||||
|
||||
# .type __eqtf2, @function
|
||||
# .global __eqtf2
|
||||
# __eqtf2:
|
||||
# ret
|
||||
|
||||
# .type __netf2, @function
|
||||
# .global __netf2
|
||||
# __netf2:
|
||||
# ret
|
||||
|
||||
# define __udivdi3 __udivsi3
|
||||
# define __umoddi3 __umodsi3
|
||||
# define __divdi3 __divsi3
|
||||
# define __moddi3 __modsi3
|
||||
|
||||
# .type __udivsi3, @function
|
||||
# .global __udivsi3
|
||||
# __udivsi3:
|
||||
# move t0, ra
|
||||
# jal __udivdi3
|
||||
# jr t0
|
||||
|
||||
|
||||
# .type __umodsi3, @function
|
||||
# .global __umodsi3
|
||||
# __umodsi3:
|
||||
# move t0, ra
|
||||
# jal __udivdi3
|
||||
# mv a0, a1
|
||||
# jr t0
|
||||
|
||||
|
||||
|
||||
# .type __divsi3, @function
|
||||
# .global __divsi3
|
||||
# __divsi3:
|
||||
# ret
|
||||
# #endif
|
||||
|
||||
# .type __divdi3, @function
|
||||
# .global __divdi3
|
||||
# __divdi3:
|
||||
# bltz a0, .L10
|
||||
# bltz a1, .L11
|
||||
# /* Since the quotient is positive, fall into __udivdi3. */
|
||||
|
||||
|
||||
# .type __udivdi3, @function
|
||||
# .global __udivdi3
|
||||
# __udivdi3:
|
||||
# mv a2, a1
|
||||
# mv a1, a0
|
||||
# li a0, -1
|
||||
# beqz a2, .L5
|
||||
# li a3, 1
|
||||
# bgeu a2, a1, .L2
|
||||
# .L1:
|
||||
# blez a2, .L2
|
||||
# slli a2, a2, 1
|
||||
# slli a3, a3, 1
|
||||
# bgtu a1, a2, .L1
|
||||
# .L2:
|
||||
# li a0, 0
|
||||
# .L3:
|
||||
# bltu a1, a2, .L4
|
||||
# sub a1, a1, a2
|
||||
# or a0, a0, a3
|
||||
# .L4:
|
||||
# srli a3, a3, 1
|
||||
# srli a2, a2, 1
|
||||
# bnez a3, .L3
|
||||
# .L5:
|
||||
# ret
|
||||
|
||||
# .type __umoddi3, @function
|
||||
# .global __umoddi3
|
||||
# __umoddi3:
|
||||
# move t0, ra
|
||||
# jal __udivdi3
|
||||
# move a0, a1
|
||||
# jr t0
|
||||
|
||||
# .L10:
|
||||
# neg a0, a0
|
||||
# bgez a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */
|
||||
# neg a1, a1
|
||||
# j __udivdi3 /* Compute __udivdi3(-a0, -a1). */
|
||||
# .L11: /* Compute __udivdi3(a0, -a1), then negate the result. */
|
||||
# neg a1, a1
|
||||
# .L12:
|
||||
# move t0, ra
|
||||
# jal __udivdi3
|
||||
# neg a0, a0
|
||||
# jr t0
|
||||
|
||||
|
||||
# .type __moddi3, @function
|
||||
# .global __moddi3
|
||||
# __moddi3:
|
||||
# move t0, ra
|
||||
# bltz a1, .L31
|
||||
# bltz a0, .L32
|
||||
# .L30:
|
||||
# jal __udivdi3 /* The dividend is not negative. */
|
||||
# move a0, a1
|
||||
# jr t0
|
||||
# .L31:
|
||||
# neg a1, a1
|
||||
# bgez a0, .L30
|
||||
# .L32:
|
||||
# neg a0, a0
|
||||
# jal __udivdi3 /* The dividend is hella negative. */
|
||||
# neg a0, a1
|
||||
# jr t0
|
||||
|
||||
# .type __modsi3, @function
|
||||
# .global __modsi3
|
||||
# __modsi3:
|
||||
# move t0, ra
|
||||
# bltz a1, .L34
|
||||
# bltz a0, .L35
|
||||
# .L33:
|
||||
# jal __udivdi3 /* The dividend is not negative. */
|
||||
# move a0, a1
|
||||
# jr t0
|
||||
# .L34:
|
||||
# neg a1, a1
|
||||
# bgez a0, .L30
|
||||
# .L35:
|
||||
# neg a0, a0
|
||||
# jal __udivdi3 /* The dividend is hella negative. */
|
||||
# neg a0, a1
|
||||
# jr t0
|
||||
|
||||
0
runtime/newlib/newlib_notimp.c
Normal file
0
runtime/newlib/newlib_notimp.c
Normal file
Reference in New Issue
Block a user