KOS() { /* Semaphores */ writeOK = make_kt_sem(0); writers = make_kt_sem(1); readers = make_kt_sem(1); nElem = make_kt_sem(0); consoleWait = make_kt_sem(0); /* Generics */ sys_stop_read = 0; current_pid = 0; console_size = 256; buffer_head, buffer_tail; // Zero out memory bzero(main_memory, MemorySize); bzero(memory_space_array, 8); /* Initializers */ currentProcess = (PCB *) malloc(sizeof(PCB)); initialize_console_buffer(&buffer_head, &buffer_tail); readyQ = new_dllist(); found_node = make_jrb(); pid_tree = make_jrb(); kt_fork(initialize_user_process, (void *)kos_argv); kt_fork(console_buf_read, (void *)kos_argv[0]); kt_joinall(); start_timer(10); scheduler(); }
//static char *Argv[5] = {"argtest","Rex", "my", "man",NULL}; KOS() { //exitSignal = 0; // printf("Starting kos\n"); bzero(main_memory, MemorySize); //make a PCB curProc = (PCB *) malloc(sizeof(PCB)); //make a dllist(readyq) which holds user processes to be run readyq = new_dllist(); //circular console size, head, and tail cbSize = 256; //Step 16 cbHead = 0; cbTail = 0; //step 14: should be initialized to 1 writers = make_kt_sem(1); readers = make_kt_sem(1); writeok = make_kt_sem(0); //step 17: consoleWait= make_kt_sem(0); nelem = make_kt_sem(0); nslots = make_kt_sem(256); //printf("Before Forking\n"); //Step 10: pids curpid = 0; rbtree = make_jrb(); foundPid = make_jrb(); //has to be its own mini tree //Lab4 globalFD = 0; //Step 12: Memory splitting 8 bzero(mem8,8); //fork to the file with args provided, just loading it kt_fork(initialize_user_process, kos_argv); //Step 4: fork to the file with args provided, now reading it, start from the very beginning kos_argv[0] kt_fork(console_buffer, kos_argv[0]); //now join all the threads kt_joinall(); //call the scheduler // start_timer(10); //scheduler(); scheduler(); }
KOS() { writeok = make_kt_sem(0); writers = make_kt_sem(1); readers = make_kt_sem(1); nelem = make_kt_sem(0); consoleWait = make_kt_sem(0); sysStopRead = 0; consoleSize = BUFSIZE; bzero(main_memory, MemorySize); current = (PCB *) malloc(sizeof(PCB)); initialize_console_buffer(&consoleBufferHead, &consoleBufferTail); queue = new_dllist(); kt_fork(initialize_user_process, NULL); kt_fork(console_buf_read, NULL); kt_joinall(); scheduler(); }
void exceptionHandler(ExceptionType which) { int type, r5, r6, r7, newPC; int buf[NumTotalRegs]; examine_registers(buf); type = buf[4]; r5 = buf[5]; r6 = buf[6]; r7 = buf[7]; newPC = buf[NextPCReg]; /* * for system calls type is in r4, arg1 is in r5, arg2 is in r6, and * arg3 is in r7 put result in r2 and don't forget to increment the * pc before returning! */ //set current register to buf. setReg(current, buf); switch (which) { case SyscallException: /* the numbers for system calls is in <sys/syscall.h> */ switch (type) { case 0: /* 0 is our halt system call number */ DEBUG('e', "Halt initiated by user program\n"); SYSHalt(); case SYS_exit: /* this is the _exit() system call */ DEBUG('e', "SYS Exit\n"); kt_fork(do_exit,current); break; case SYS_read: DEBUG('e', "SYS Read\n"); kt_fork(do_read,current); break; case SYS_write: DEBUG('e', "SYS Write\n"); kt_fork(do_write,current); break; case SYS_ioctl: DEBUG('e',"Sys ioctl\n"); kt_fork(do_ioctl,current); break; case SYS_fstat: DEBUG('e',"Sys fstat\n"); kt_fork(do_fstat,current); break; case SYS_getpagesize: DEBUG('e', "Sys getpagesize\n"); kt_fork(do_getpagesize,current); break; case SYS_sbrk: DEBUG('e',"Sys_sbrk\n"); kt_fork(do_sbrk,current); break; case SYS_execve: DEBUG('e',"Sys execve\n"); kt_fork(do_execve,current); break; case SYS_getpid: DEBUG('e',"SYS_getpid\n"); kt_fork(do_getpid,current); break; case SYS_fork: DEBUG('e', "SYS_fork\n"); kt_fork(do_fork,current); break; case SYS_getppid: DEBUG('e', "SYS_getppid\n"); kt_fork(do_getppid,current); //SYSHalt();//STUB break; case SYS_wait: DEBUG('e', "SYS_wait\n"); //SYSHalt();//STUB kt_fork(do_wait,current); break; case SYS_getdtablesize: DEBUG('e', "SYS_getdtablesize\n"); kt_fork(do_getdtablesize,current); break; case SYS_close: DEBUG('e', "SYS_close\n"); kt_fork(do_close,current); break; case SYS_pipe: DEBUG('e', "SYS_pipe\n"); kt_fork(do_pipe,current); break; case SYS_dup: DEBUG('e', "SYS_dup\n"); kt_fork(do_dup,current); break; case SYS_dup2: DEBUG('e', "SYS_dup2\n"); kt_fork(do_dup2,current); break; default: DEBUG('e', "Unknown system call\n"); SYSHalt(); break; } break; case PageFaultException: DEBUG('e', "Exception PageFaultException\n"); break; case BusErrorException: DEBUG('e', "Exception BusErrorException\n"); break; case AddressErrorException: DEBUG('e', "Exception AddressErrorException\n"); break; case OverflowException: DEBUG('e', "Exception OverflowException\n"); break; case IllegalInstrException: DEBUG('e', "Exception IllegalInstrException\n"); break; default: printf("Unexpected user mode exception %d %d\n", which, type); exit(1); } scheduler(); }