//printf needs following syscalls: sbrk write close fstat isatty lseek read // #include #include #include #include "../fs/fs.h" static int preread; static int alloc; easywrite(char *c); void syscalls_init() { preread=0; alloc=0xff0000; } int close(int file) { // easywrite("syscall: close\n"); return -1; } int fstat(int file, struct stat *st) { // easywrite("syscall: fstat\n"); st->st_mode = S_IFCHR; return 0; } int isatty(int file) { // easywrite("syscall: isatty\n"); return 1; } int lseek(int file, int ptr, int dir) { // printf("syscall: lseek %i %i %i",file,ptr,dir); if(dir==0)preread=ptr; else{ puts("other modes unsupported sorry"); while(1);} return preread; } int read(int file, char *ptr, int len) { int ebx; // will hold return value; asm("pusha"); // select syscall asm("mov $62,%eax"); // pass params asm("mov %0,%%edx"::"m"(file)); asm("mov %0,%%ecx"::"m"(ptr)); asm("mov %0,%%ebx"::"m"(len)); // interrrupt asm("int $0x80"); // get return value asm("mov %%ebx, %0": "=b" (ebx)); asm("popa"); return ebx; } int readdir(const char *name,fs_dirent *dirs,int max) { int ebx; // WILL Hold return value; asm("pusha"); // select syscall asm("mov $63,%eax"); // pass params asm("mov %0,%%edx"::"m"(name)); asm("mov %0,%%ecx"::"m"(dirs)); asm("mov %0,%%ebx"::"m"(max)); // interrrupt asm("int $0x80"); // get return value asm("mov %%ebx, %0": "=b" (ebx)); asm("popa"); return ebx; } int open(const char *name, int flags, int mode) { // easywrite("syscall: open\n"); return 99; return -1; } int write(int file, char *ptr, int len) { int ebx; // will hold return value; asm("pusha"); // select syscall asm("mov $61,%eax"); // pass params asm("mov %0,%%edx"::"m"(file)); asm("mov %0,%%ecx"::"m"(ptr)); asm("mov %0,%%ebx"::"m"(len)); // interrupt asm("int $0x80"); // get return value asm("mov %%ebx, %0": "=b" (ebx)); asm("popa"); return ebx; } caddr_t sbrk(int incr) { // easywrite("syscall: sbrk!!\n"); int oldalloc=alloc; alloc+=incr; return oldalloc; /* extern char end; // char _end; static char *heap_end; char *prev_heap_end; if (heap_end == 0) { heap_end = &end; } prev_heap_end = heap_end; if (heap_end + incr > stack_ptr) { write (1, "Heap and stack collision\n", 25); abort (); } heap_end += incr; return (caddr_t) prev_heap_end; */ } // // helpers easywrite(char *c) { write(1,c,strlen(c)); }