diff --git a/student-distrib/keyboard.c b/student-distrib/keyboard.c index 7a004a000fcd50a5c80c357d7372f5f54fe7b80b..047bf36d4f636c3020ec50a461db13e1ee3be013 100644 --- a/student-distrib/keyboard.c +++ b/student-distrib/keyboard.c @@ -383,8 +383,8 @@ void KB_handler(void) { clear(); reset_cursor(); - if(terminal[visible_terminal].pcb->shell_flag) - printf("391OS> "); + //if(terminal[visible_terminal].pcb->shell_flag) + // printf("391OS> "); remap2(running_terminal); send_eoi(KB_IRQ); diff --git a/student-distrib/paging.c b/student-distrib/paging.c index d451d094cb2fd9e74e6aeec4e779ae858d6d5f27..4be459aacc52db98da5eefd2d80b8ae4a7741cc9 100644 --- a/student-distrib/paging.c +++ b/student-distrib/paging.c @@ -80,16 +80,15 @@ void remap2(int32_t term_id){ * Return Value: void * Function: Initialises page for video memory */ -void remap_vidmem(){ +void remap_vidmem() +{ page_directory[33] = (uint32_t)(uint32_t)page_table | USER | READ_WRITE | PRESENT; if(visible_terminal == running_terminal) - page_table[0] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT; - + else - page_table[0] = ((uint32_t)(0xB8000 + (running_terminal+1)*0x1000 )) | USER | READ_WRITE | PRESENT; // flush TLB diff --git a/student-distrib/proc.c b/student-distrib/proc.c index 25eb4ac954272c56f14cff1cfe664048de213ca4..4abf58a4741338fa83e6aac83618669bacf0f2cf 100644 --- a/student-distrib/proc.c +++ b/student-distrib/proc.c @@ -12,18 +12,20 @@ int32_t fail(){ return -1; } +/* Initialized at bootup */ void control_initilization(void) { int i; + + /* All PID entries to present */ for(i = 0; i < MAX_PROCESS; i++) pid_array[i] = 0; total_prog_count = 0; - visible_terminal = 0; + visible_terminal = 0; running_terminal = 0; - cur_pid = 0; - counter = 0; - // running_terminal = 0; + cur_pid = 0; + counter = 0; } /* Checks if FD is valid @@ -41,7 +43,7 @@ int32_t fd_check(int32_t fd) return -1; } -//clearing fd +/* Clear FD for process on halt */ void fd_clear(int32_t fd) { terminal[ running_terminal].pcb->fd[fd].fileop_ptr.read = 0; @@ -51,14 +53,18 @@ void fd_clear(int32_t fd) terminal[ running_terminal].pcb->fd[fd].inode_index = 0; terminal[ running_terminal].pcb->fd[fd].file_pos = 0; terminal[ running_terminal].pcb->fd[fd].flags = 0; + return; } -//initialize pcb +/* Initialize PCB for new process on execute */ void pcb_init(pcb_t* pcb , uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZE], uint32_t pid, uint32_t arg_num) { int i; - for( i = 0; i < MAX_FILE_NUM ; i++){ + + /* Set FD array */ + for( i = 0; i < MAX_FILE_NUM ; i++) + { pcb->fd[i].fileop_ptr.read = 0; pcb->fd[i].fileop_ptr.write = 0; pcb->fd[i].fileop_ptr.open = 0; @@ -68,31 +74,28 @@ void pcb_init(pcb_t* pcb , uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZ pcb->fd[i].flags = 0; } - //initialze stdin + /* Initialze STDIN */ pcb->fd[STDIN_FD].fileop_ptr = (f_table_t)stdin_jumptable; pcb->fd[STDIN_FD].inode_index = 0; pcb->fd[STDIN_FD].file_pos = 0; pcb->fd[STDIN_FD].flags = 1; - //initialze stdout + /* Initialize STDOUT */ pcb->fd[STDOUT_FD].fileop_ptr = (f_table_t)stdout_jumptable; pcb->fd[STDOUT_FD].inode_index = 0; pcb->fd[STDOUT_FD].file_pos = 0; pcb->fd[STDOUT_FD].flags = 1; - + /* Set the PID sent in as argument */ pcb->pid = pid; pcb->scheduler_flag = 0; - // no program other than the shell initiates another program + /* no program other than the shell initiates another program */ pcb->parent_pid = 0; pcb->arg_num = arg_num; - pcb->running_terminal = visible_terminal; - pcb->shell_flag = 0; - memcpy(pcb->cmd, parsed_cmd, MAX_COMMAND_SIZE); for(i = 0; i < MAX_ARGUMENT_NUM; i++) @@ -100,26 +103,14 @@ void pcb_init(pcb_t* pcb , uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZ pcb->parent_esp = 0; pcb->parent_ebp = 0; - pcb->parent_pcb = terminal[visible_terminal].pcb; - pcb->tss_esp0 = tss.esp0; + pcb->parent_pcb = terminal[running_terminal].pcb; + pcb->tss_esp0 = tss.esp0; return; } -//function that return a pointer to the current pcb -pcb_t* current_pcb(void) -{ - pcb_t* pcb; - asm volatile( - "andl %%esp, %0" - : "=r" (pcb) - : "r" (PCB_M) - ); - return pcb; -} - -//parsing the command, extract command and argument -//return number of arguments when success, -2 when exit, -1 when fail +/* Parsing the command, extracting the command and the argument + * returns number of arguments when successful, -2 fot exit, -1 for failure */ int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZE]) { int32_t i,j, command_length; diff --git a/student-distrib/rtc.c b/student-distrib/rtc.c index 08f0457315dc3a73a4331b9bf28f8c03de6bdd65..c99778c333c90245f468372aa3b37b742aae27cd 100644 --- a/student-distrib/rtc.c +++ b/student-distrib/rtc.c @@ -84,7 +84,7 @@ int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes) /* Set flag */ rtc_flag[running_terminal] = 1; - //interrupt_flag = 1; + sti(); /* Wait until interrupt handler clears flag */ diff --git a/student-distrib/syscall.c b/student-distrib/syscall.c index f581486da377dd23026afb588c3ac038b2dfe8ab..06eb2c79cfb17128343460915b42abcf40a7dff8 100644 --- a/student-distrib/syscall.c +++ b/student-distrib/syscall.c @@ -35,7 +35,7 @@ int32_t halt (uint8_t status) { clear_pid(pcb_cur->pid); total_prog_count--; - terminal[pcb_cur->running_terminal].terminal_prog_count--; + terminal[running_terminal].terminal_prog_count--; } if(terminal[running_terminal].terminal_prog_count == 0) @@ -212,13 +212,6 @@ int32_t execute(const uint8_t* command) terminal[running_terminal].pcb = pcb_ptr; - if(strncmp("shell", (int8_t *) parsed_cmd, 5) == 0) - terminal[running_terminal].pcb->shell_flag = 1; - - //printf("[EXE] using pcb = %x\n", terminal[running_terminal].pcb); - - //printf("[EXE] set pcb ebp to %x , esp to %x\n", terminal[running_terminal].pcb->current_ebp, terminal[running_terminal].pcb->current_esp); - //printf("[EXE] should be ebp %x , esp %x\n", temp_ebp, temp_esp); //--------------------- 6: scheduling initilization ----------------------- diff --git a/student-distrib/types.h b/student-distrib/types.h index c32f740e234b0966be5fc49e228b1a2e75d462cc..3cf826c219286ae4a78c6c77938737247b5e6cdb 100644 --- a/student-distrib/types.h +++ b/student-distrib/types.h @@ -143,9 +143,6 @@ typedef struct pcb { file_object_t fd[MAX_FILE_NUM]; /* File descriptor array */ - int32_t running_terminal; - int32_t shell_flag; - int32_t scheduler_flag; uint32_t pid; /* Holds current process ID */