void StartProcISR(int new_pid, int func_addr) { MyBzero((char *) &pcb[new_pid], sizeof(pcb_t)); //clear the PCB of the new pid //phase 5 MyBzero((char *) &msg_q[new_pid], sizeof(msg_q_t)); pcb[new_pid].state = READY; //set its state to READY if(new_pid != 0) //if new pid is not 0 (IdleProc), { EnQ(new_pid, &ready_q); //then, enqueue this new pid into the ready queue } //build initial trapframe in proc stack MyBzero((char *)&proc_stack[new_pid], PROC_STACK_SIZE); //call MyBzero() to clear the stack 1st pcb[new_pid].TF_ptr = (TF_t *) &proc_stack[new_pid][PROC_STACK_SIZE - sizeof(TF_t)]; //set TF_ptr of PCB to close to end (top) of stack pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; //set INTR flag pcb[new_pid].TF_ptr->cs = get_cs(); //standard fair pcb[new_pid].TF_ptr->ds = get_ds(); //standard fair pcb[new_pid].TF_ptr->es = get_es(); //standard fair pcb[new_pid].TF_ptr->fs = get_fs(); //standard fair pcb[new_pid].TF_ptr->gs = get_gs(); //standard fair pcb[new_pid].TF_ptr->eip = func_addr; }
void StartProcISR(int new_pid) { //clear the PCB of the new pid MyBzero((char *) &pcb[new_pid], sizeof(pcb_t)); //set its state to READY pcb[new_pid].state = READY; //if new pid is not 0 (IdleProc), //then, enqueue this new pid into the ready queue*/ if(new_pid != 0){ EnQ(new_pid, &ready_q); } //Clears the stack MyBzero((char *) &proc_stack[new_pid], PROC_STACK_SIZE); //Set TF_ptr of PCB close to end (top) of stack, then fill out pcb[new_pid].TF_ptr = (TF_t *) &proc_stack[new_pid][PROC_STACK_SIZE - sizeof(TF_t)]; pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; // set INTR flag pcb[new_pid].TF_ptr->cs = get_cs(); // standard fair pcb[new_pid].TF_ptr->ds = get_ds(); // standard fair pcb[new_pid].TF_ptr->es = get_es(); // standard fair pcb[new_pid].TF_ptr->fs = get_fs(); // standard fair pcb[new_pid].TF_ptr->gs = get_gs(); // standard fair if(new_pid == 0){ pcb[new_pid].TF_ptr->eip = (unsigned int) IdleProc; // if pid is 0, points to IdleProc }else{ pcb[new_pid].TF_ptr->eip = (unsigned int) UserProc; // or UserProc } }
void StartProcISR(int new_pid, int func_addr) { MyBzero( (char*) &pcb[new_pid], sizeof (pcb_t)); //clear process msg queue MyBzero( (char*) &msg_q[new_pid], sizeof (msg_q_t)); pcb[new_pid].state= READY; if(new_pid > 0 ) { EnQ(new_pid, &ready_q); } MyBzero( (char*) &proc_stack[new_pid], PROC_STACK_SIZE); pcb[new_pid].TF_ptr =(TF_t*) &proc_stack[new_pid][PROC_STACK_SIZE]; pcb[new_pid].TF_ptr--; pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; // set INTR flag pcb[new_pid].TF_ptr->cs = get_cs(); // standard fair pcb[new_pid].TF_ptr->ds = get_ds(); // standard fair pcb[new_pid].TF_ptr->es = get_es(); // standard fair pcb[new_pid].TF_ptr->fs = get_fs(); // standard fair pcb[new_pid].TF_ptr->gs = get_gs(); // standard fair pcb[new_pid].TF_ptr->eip = (unsigned int) func_addr; }
void InitKernelData() { int i; //call MyBzero() to clear queues (which is to be coded in toolfunc.h/.c) MyBzero((char *)&ready_q, sizeof(q_t)); MyBzero((char *)&free_q, sizeof(q_t)); for(i = 0; i < Q_LEN; i++) // loop number i from 0 to 19 { EnQ(i, &free_q); //call EnQ() to enqueue i to free_q MyBzero((char *) &pcb[i], sizeof(pcb_t)); //call MyBzero() to clear pcb[i] } running_pid = 0; //set running_pid to 0; none initially, need to chose by Scheduler() //Phase 2 OS_clock = 0; //reset OS_clock to 0 MyBzero((char *)&sleep_q, sizeof(q_t)); //reset sleep_q }
void ForkISR(int pid, int* addr, int size, int value) { // Only thing new for ForkISR int i; int * p; for(i=0;i<NUM_PAGE;i++) { if(pages[i].owner == -1) break; } // The rest was a copy from spwnisr. pages[i].owner = pid; MyBzero((char *)pages[i].addr, USER_STACK_SIZE); MyBzero((void *)user_stacks[pid], USER_STACK_SIZE); MyBzero(&mboxes[pid], sizeof(mbox_t)); p = (int *) (pages[i].addr + USER_STACK_SIZE); p--; *p = value; pcbs[pid].tf_p = (tf_t*) p; pcbs[pid].tf_p--; // points to trap frame MyMemCpy((char *)(pages[i].addr), (char *)(addr), size); pcbs[pid].tf_p->eflags = EF_DEFAULT_VALUE|EF_INTR; pcbs[pid].tf_p->eip = pages[i].addr; pcbs[pid].tf_p->cs = get_cs(); pcbs[pid].tf_p->ds = get_ds(); pcbs[pid].tf_p->es = get_es(); pcbs[pid].tf_p->fs = get_fs(); pcbs[pid].tf_p->gs = get_gs(); pcbs[pid].tick_count = pcbs[pid].total_tick_count = 0; pcbs[pid].state = READY; pcbs[pid].ppid = cur_pid; EnQ(pid, &ready_q); }
void SemGetISR(int limit){ int sem_id; sem_id = DeQ(&sem_q); if(sem_id == -1){ pcb[running_pid].TF_ptr->ebx= -1; return; } MyBzero((char*)&sem[sem_id].wait_q,sizeof(q_t)); sem[sem_id].limit = limit; pcb[running_pid].TF_ptr->ebx= sem_id; }
void InitKernelData() { int i; MyBzero((char *)&ready_q, sizeof(q_t)); MyBzero((char *)&free_q, sizeof(q_t)); //phase 3 MyBzero((char *)&sem_q, sizeof(q_t)); //clear the available semaphore queue for(i = 0; i < Q_LEN; i++) // loop number i from 0 to 19 { EnQ(i, &free_q); //call EnQ() to enqueue i to free_q //phase 3 EnQ(i, &sem_q); //fill it with available semaphore ID's (from 0 to Q_SIZE-1). MyBzero((char *) &pcb[i], sizeof(pcb_t)); } running_pid = 0;//set running_pid to 0; none initially, need to chose by Scheduler() //Phase 2 OS_clock = 0; //reset OS_clock to 0 MyBzero((char *)&sleep_q, sizeof(q_t)); //reset sleep_q //phase 4 MyBzero((char *)&msg_q, sizeof(msg_q_t)); }
void InitKernelData() { int i; MyBzero((char *)&ready_q, sizeof(q_t)); MyBzero((char *)&free_q, sizeof(q_t)); //phase 3 MyBzero((char *)&sem_q, sizeof(q_t)); //clear the available semaphore queue for(i = 0; i < Q_LEN; i++) // loop number i from 0 to 19 { EnQ(i, &free_q); //call EnQ() to enqueue i to free_q //phase 3 EnQ(i, &sem_q); //fill it with available semaphore ID's . MyBzero((char *) &pcb[i], sizeof(pcb_t)); } running_pid = 0; //Phase 2 OS_clock = 0; //reset OS_clock to 0 MyBzero((char *)&sleep_q, sizeof(q_t)); //reset sleep_q //phase 4 for(i =0; i < MAX_PROC_NUM; i++) { MyBzero((char *)&msg_q[i], sizeof(msg_q_t)); } //phase 8 for(i = 0; i < 100; i++) { DRAM[i].addr = (i * PROC_STACK_SIZE) + 14680064; DRAM[i].owner = -1; } }
void SpawnISR(int pid, func_ptr_t addr) { MyBzero((void *)user_stacks[pid], USER_STACK_SIZE); MyBzero(&mboxes[pid], sizeof(mbox_t)); // 1st. point to just above of user stack, then drop by 64 bytes (tf_t) pcbs[pid].tf_p = (tf_t *)&user_stacks[pid][USER_STACK_SIZE]; pcbs[pid].tf_p--; // pointer arithmetic, now points to trapframe // fill in CPU's register context pcbs[pid].tf_p->eflags = EF_DEFAULT_VALUE|EF_INTR; pcbs[pid].tf_p->eip = (unsigned int) addr; // new process code pcbs[pid].tf_p->cs = get_cs(); pcbs[pid].tf_p->ds = get_ds(); pcbs[pid].tf_p->es = get_es(); pcbs[pid].tf_p->fs = get_fs(); pcbs[pid].tf_p->gs = get_gs(); pcbs[pid].tick_count = pcbs[pid].total_tick_count = 0; pcbs[pid].state = READY; if(pid != 0) EnQ(pid, &ready_q); // IdleProc (PID 0) is not queued }
///////////////////////////////Phase 3 void SemGetISR(int limit) { int sem_id; sem_id = DeQ(&sem_q); if(sem_id == -1) { pcb[running_pid].TF_ptr->ebx = -1; } else { MyBzero((char *) &sem[sem_id], sizeof(sem_t)); //clear sem[sem_id] sem[sem_id].limit = limit; pcb[running_pid].TF_ptr->ebx = sem_id; //put semid into ebx of TF of running process } }
void InitKernelData() { int i; MyBzero((char*)&sleep_q,sizeof (q_t)); MyBzero((char*)&ready_q,sizeof(q_t)); //clear queues MyBzero((char*)&free_q,sizeof(q_t)); MyBzero((char*)&sem_q,sizeof(q_t)); for(i=0; i<MAX_PROC_NUM;i++){ MyBzero((char*)&msg_q[i],sizeof(msg_q_t)); } //loop number i from 0 to 19: for(i=0; i<Q_LEN; i++){ EnQ(i,&free_q); EnQ(i,&sem_q); MyBzero((char*)&pcb[i],sizeof(pcb_t)); } OS_clock = 0; running_pid = 0; }
// Copy bytes from file into user's buffer. Returns actual count of bytes // transferred. Read from fd_array[fd].offset (initially given 0) for // buff_size in bytes, and record the offset. may reach FM_EOF though... int ReadObj( int fd, char *buff, int owner, int *lp_actual ) { int result; int remaining; dir_t *lp_dir; *lp_actual=0; result = CanAccessFD( fd, owner ); // check if owner owns the fd if( result != GOOD ) return result; lp_dir = fd_array[fd].item; if( A_ISDIR(lp_dir->mode ) ) { // it's a dir // if reading directory, return attr_t structure followed by an obj name. // a chunk returned per read. `offset' is index into root_dir[] table. dir_t *this_dir = lp_dir; attr_t *attr_p = (attr_t *)buff; dir_t *dir_p; if( 101 < sizeof( *attr_p ) + 2) return BUF_SMALL; // use current dir, advance to next dir for next time when called do { dir_p = ( (dir_t *)this_dir->data ); dir_p += fd_array[fd].offset ; if( dir_p->inode == END_DIR_INODE ) return FM_EOF; fd_array[fd].offset++; // advance } while( dir_p->name == NULL ); // MyBzero() fills buff with 0's, necessary to clean buff // since Dir2Attr may not completely overwrite whole buff... MyBzero( buff, 101 ); Dir2Attr( dir_p, attr_p ); // copy obj name after attr_t, add 1 to length for null MyMemcpy((char *)( attr_p + 1 ), dir_p->name, MyStrlen( dir_p->name ) + 1); // *lp_actual = sizeof(*dir_p) + MyStrlen((char *)(attr_p + 1)) + 1; *lp_actual = sizeof( attr_t ) + MyStrlen( dir_p->name ) + 1; } else { // a file, not dir // compute max # of bytes can transfer then MyMemcpy() remaining = lp_dir->size - fd_array[fd].offset; if( remaining == 0 ) return FM_EOF; MyBzero( buff, 101 ); // null termination for any part of file read result = remaining<100?remaining:100; // -1 saving is for last NULL MyMemcpy( buff, &lp_dir->data[ fd_array[ fd ].offset ], result ); fd_array[fd].offset += result; // advance our "current" ptr *lp_actual = result; } return GOOD; }