// // syscall.C // // Description: // Implements the SYSCALL instruction. // // Version: // $Id$ // // Revision: // $Log$ // // Author: // Brian J. Alliet // #include "includes.h" // This only allows for a little less than 256K of // dynamically alloced memory (libarch limits us to // 1MB of memory) static long mips_brk = 768*1024; long mips_syscall(long nr, long a0, long a1, long a2) { //fprintf(stderr,"syscall: %ld: (%ld,%ld,%ld)\n",nr,a0,a1,a2); switch(nr) { case 1: /* SYS_exit */ printf("Process exited with status: %ld\n",a0); exit(a0); return 0; case 6: { /* SYS_write */ char buf[1024]; if(a2 > (long) sizeof(buf)) a2 = sizeof(buf); for(long i=0;i < a2;i++) buf[i] = (char) dmem.mem.get(a1+i); if(a0 != 1 && a0 != 2) return -81 /* EBADFD */; return write(a0,buf,a2); } case 8: { /* SYS_fstat */ if(a0 != 1 && a0 != 2) return -81 /* EBADFD */; for(int i=0;i<60;i++) dmem.mem.put(a1+i,0); dmem.mem.put(a1+4,0x32); // st_mode == S_IFCHR return 0; } case 19: /* SYS_getpagesize */ return 4096; case 7: { /* SYS_sbrk */ if(a0 < 0) return -12 /* ENOMEM */; if(a0 == 0) return mips_brk; long old_brk = mips_brk; a0 = (a0 + 3) & ~3; if((unsigned long) mips_brk + a0 >= MEM_SIZE - STACK_SIZE) { fprintf(stderr,"WARNING: out of heap space\n"); return -12 /* ENOMEM */; } mips_brk += a0; return old_brk; } case 38: /* SYS_memset */ for(long i=0;i