/* * Initial boot sequence. */ static void boot(void) { int retval; /* * The order of these is important! * Don't go changing it without thinking about the consequences. * * Among other things, be aware that console output gets * buffered up at first and does not actually appear until * dev_bootstrap() attaches the console device. This can be * remarkably confusing if a bug occurs at this point. So * don't put new code before dev_bootstrap if you don't * absolutely have to. * * Also note that the buffer for this is only 1k. If you * overflow it, the system will crash without printing * anything at all. You can make it larger though (it's in * dev/generic/console.c). */ kprintf("\n"); kprintf("OS/161 base system version %s\n", BASE_VERSION); kprintf("%s", harvard_copyright); kprintf("\n"); kprintf("Put-your-group-name-here's system version %s (%s #%d)\n", GROUP_VERSION, buildconfig, buildversion); kprintf("\n"); ram_bootstrap(); scheduler_bootstrap(); thread_bootstrap(); vfs_bootstrap(); dev_bootstrap(); vm_bootstrap(); kprintf_bootstrap(); sys_getpid(&retval); sys_printchar('c'); kprintf("\nretval::%d",retval); // kprintf("\n printing helloworld..."); // _helloworld(0); // _printint(88); /* Default bootfs - but ignore failure, in case emu0 doesn't exist */ vfs_setbootfs("emu0"); /* * Make sure various things aren't screwed up. */ assert(sizeof(userptr_t)==sizeof(char *)); assert(sizeof(*(userptr_t)0)==sizeof(char)); }
void start(void) { sys_priority(PRIORITY); sys_share(SHARE); int i; for (i = 0; i < RUNCOUNT; i++) { #ifndef __EXERCISE_8__ // Get lock while (atomic_swap(&lock, 1) != 0) continue; // Print char *cursorpos++ = PRINTCHAR; // Release lock atomic_swap(&lock, 0); // Yield after printing sys_yield(); #else // Make system call to prin character sys_printchar(PRINTCHAR); #endif } // Yield forever. while (1) sys_exit(0); }
void mips_syscall(struct trapframe *tf) { int callno; int32_t retval; int err; assert(curspl==0); /* * Initialize retval to 0. Many of the system calls don't * really return a value, just 0 for success and -1 on * error. Since retval is the value returned on success, * initialize it to 0 by default; thus it's not necessary to * deal with it except for calls that return other values, * like write. */ retval = 0; callno=tf->tf_v0; char ch; switch (callno) { case SYS_reboot: err = sys_reboot(tf->tf_a0); break; case SYS__exit: thread_exit(); break; /* Add stuff here */ /*calls for assignment 0*/ case SYS__helloworld: //err = sys_helloworld(tf->tf_a0); break; case SYS__printint: //err=sys_printint(tf->tf_a0,tf->tf_a1); break; case SYS_getpid: err=sys_getpid(&retval); break; case SYS__printchar: err=sys_printchar(tf->tf_a0); break; case SYS__readchar: err=sys_readchar(&ch); //kprintf("\nin syscall::%c",ch); break; case SYS_fork: //kprintf("\n ::current addr space::%x",curthread->t_vmspace); err=sys_fork(tf,curthread->t_vmspace); break; case SYS_execv: err=sys_execv(tf->tf_a0,tf->tf_a1); //(const char *prog, char *const *args); //prog points to a const string, const char pointer pointing to a const string break; default: kprintf("Unknown syscall %d\n", callno); //kprintf("\ncallno::%d",tf->tf_v0); err = ENOSYS; break; } if (err) { /* * Return the error code. This gets converted at * userlevel to a return value of -1 and the error * code in errno. */ tf->tf_v0 = err; tf->tf_a3 = 1; /* signal an error */ } else { /* Success. */ if(callno==SYS__readchar){ tf->tf_v0=ch; tf->tf_a0=0; } else{ tf->tf_v0 = retval; tf->tf_a3 = 0; /* signal no error */ } } /* * Now, advance the program counter, to avoid restarting * the syscall over and over again. */ tf->tf_epc += 4; /* Make sure the syscall code didn't forget to lower spl */ assert(curspl==0); //kprintf("Exiting mips_syscall\n"); }