diff --git a/student-distrib/kernel.c b/student-distrib/kernel.c index 00b9854297201d9d813ca7b1b37122129dd2c589..57bb7d4f6d99890df39981f18193f249d5b2f784 100644 --- a/student-distrib/kernel.c +++ b/student-distrib/kernel.c @@ -193,6 +193,7 @@ void entry(unsigned long magic, unsigned long addr) { //launch_tests(); #endif /* Execute the first program ("shell") ... */ + switch_terminal(0); execute((uint8_t*) "shell"); diff --git a/student-distrib/paging.c b/student-distrib/paging.c index 9bdd3d68a9ee354ba47e2fca9767e6e7ff916f88..8118e69f4d4782592862cbe27cea9c96bccbf1fd 100644 --- a/student-distrib/paging.c +++ b/student-distrib/paging.c @@ -43,30 +43,20 @@ void paging_initi(void){ return; } - - - - - //term_id = current -void remap1(int32_t term_id){ - page_table[ 0xB8 + term_id + 1] = ((uint32_t)(0xB8000 + (term_id+1)*0x1000 )) | USER | READ_WRITE | PRESENT; +void remap_prev(int32_t prev_id){ + page_table[ 0xB8 + prev_id + 1] = ((uint32_t)(0xB8000 + (prev_id+1)*0x1000 )) | USER | READ_WRITE | PRESENT; flush_tlb(); return; } - //term_id = ther terminal we want to display -void remap2(int32_t term_id){ - page_table[ 0xB8 + term_id + 1] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT; +void remap_new(int32_t new_id){ + page_table[ 0xB8 + new_id + 1] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT; flush_tlb(); return; } - - - - /* remap_vidmem * Inputs: PID number of process * Return Value: void diff --git a/student-distrib/paging.h b/student-distrib/paging.h index 3bae8d9ed19b08f59e2290e7e9ed2f66cc89a716..e2716eb0db1446c5f1249a942a1afcecc187f3de 100644 --- a/student-distrib/paging.h +++ b/student-distrib/paging.h @@ -58,8 +58,8 @@ void loadPageDirectory(unsigned int*); */ void enablePaging(void); -extern void remap1(int32_t term_id); -extern void remap2(int32_t term_id); +extern void remap_prev(int32_t prev_id); +extern void remap_new(int32_t new_id); extern uint8_t* remap_vidmem(uint32_t pid); diff --git a/student-distrib/terminal.c b/student-distrib/terminal.c index c18b3fa237d24c877049b3e7bc42ced2fe8ce4d7..d0468d8a6f86ce571827a97b22075be89eff5888 100644 --- a/student-distrib/terminal.c +++ b/student-distrib/terminal.c @@ -156,19 +156,19 @@ void init_terminal(void) clear_buffer(); int i; - for (i = 0; i < 3; i++){ + for (i = 0; i < 3; i++){ control.terminal[i].pcb = (pcb_t*)NULL; control.terminal[i].terminal_x = 0; control.terminal[i].terminal_y = 0; control.terminal[i].buffer_index = 0; control.terminal[i].terminal_prog_count = 0; - } + } //control.terminal[0].vid_mem = TERM_VID; control.terminal[0].vid_mem = TERM0_VID; control.terminal[1].vid_mem = TERM1_VID; control.terminal[2].vid_mem = TERM2_VID; - return; + return; } /* @@ -194,29 +194,16 @@ int32_t switch_terminal(int32_t term_id) //retrieve currently visible terminal prev_terminal = control.cur_terminal; - //check if we're not switching to the same screen - // if(term_id == prev_terminal) - // return -1; - - //set current terminal in control structure control.cur_terminal = term_id; control.visible_terminal = term_id; //restore paging from 0xb8000 to prev_terminal video mapping - remap1(prev_terminal); - - //store previous terminal data into memory - memcpy( (void*)control.terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB ); - - + remap_prev(prev_terminal); - //clear(); - - //display new terminal video memory - memcpy( (void*)TERM_VID, (const void*)control.terminal[control.cur_terminal].vid_mem, _4_KB ); + copy_video_mem(prev_terminal, control.cur_terminal); //set new terminal to update to physical video memory - remap2(control.cur_terminal); + remap_new(control.cur_terminal); update_cursor(); @@ -224,28 +211,13 @@ int32_t switch_terminal(int32_t term_id) return (control.terminal[term_id].terminal_prog_count == 0) ? 0 : 1; } -// NOT IN USE ANYMORE -/* - * FUNCTIONALITY: helper function for copying terminal video memory data - * - * INPUT: term_id -- the terminal id of the ther terminal that we want to switch to - * cmd: 0 -- copy from video memory to terminal info storage - * 1 -- copy from terminal info storage to video memory - * OUTPUT: None - */ -void copy_term_data(int32_t term_id, int32_t cmd) + +void copy_video_mem(int32_t prev_terminal, int32_t new_terminal) { - //validate parameters - if(cmd != 0 || cmd != 1 || term_id < 0 || term_id > 2) - { - printf("[copy_term_data] break early - cmd = %d, term_id = %d\n", cmd, term_id); - return; - } - if(cmd) - memcpy( (void*)TERM_VID, (const void*)control.terminal[term_id].vid_mem, _4_KB ); - else - memcpy( (void*)control.terminal[term_id].vid_mem, (const void*)TERM_VID, _4_KB ); + // store old terminal to its corresponding space + memcpy( (void*)control.terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB ); - return; + // copy new terminal to 0xB8000 + memcpy( (void*)TERM_VID, (const void*)control.terminal[new_terminal].vid_mem, _4_KB ); }