diff --git a/student-distrib/idt_asm.S b/student-distrib/idt_asm.S index 3edc99756ce1d06ec139165ed0738b5cbd19cbee..df7b47b32027a570b9c61fd0206260354a4851d4 100644 --- a/student-distrib/idt_asm.S +++ b/student-distrib/idt_asm.S @@ -185,4 +185,5 @@ PIT_INTERRUPT: STI - IRET \ No newline at end of file + IRET + \ No newline at end of file diff --git a/student-distrib/kernel.c b/student-distrib/kernel.c index 61d88d57abb67a649770d1cc47486efa50400656..e5f8a61c13dc7966c865b92ed1df87dfa86eb7ec 100644 --- a/student-distrib/kernel.c +++ b/student-distrib/kernel.c @@ -16,7 +16,7 @@ //#include "filesys.h" #include "terminal.h" //#include "syscall.h" - +#include "pit.h" #include "types.h" #define RUN_TESTS @@ -182,8 +182,6 @@ void entry(unsigned long magic, unsigned long addr) { init_terminal(); - init_ready = 1; - sti(); clear(); @@ -195,7 +193,8 @@ void entry(unsigned long magic, unsigned long addr) { //launch_tests(); #endif /* Execute the first program ("shell") ... */ - execute((uint8_t*) "shell"); + //if(switch_terminal(0) == 0) + execute((uint8_t*) "shell"); /* Spin (nicely, so we don't chew up cycles) */ asm volatile (".1: hlt; jmp .1;"); diff --git a/student-distrib/keyboard.h b/student-distrib/keyboard.h index bbfe8ec71c8152f5e22278c1d8c58808fe3d457f..ff5cb7b957c69913b3ad53e12ed11387879ff6d5 100644 --- a/student-distrib/keyboard.h +++ b/student-distrib/keyboard.h @@ -4,6 +4,7 @@ #include "lib.h" #include "i8259.h" #include "syscall.h" +#include "terminal.h" // keyboard driver for the kernel /************************ KB driver constants ************************/ diff --git a/student-distrib/lib.c b/student-distrib/lib.c index 3fd4942a8cc9e9bc0047529cf75cffbc61ff4558..7c4461ec9503a98094f0d2117e7aa09f019e458f 100644 --- a/student-distrib/lib.c +++ b/student-distrib/lib.c @@ -9,8 +9,6 @@ #define NUM_ROWS 25 #define ATTRIB 0x7 -init_ready = 0; - static char* video_mem = (char *)VIDEO; /* void clear(void); @@ -76,12 +74,7 @@ void scroll_up(int32_t term_id) { int32_t i; - uint8_t * video_memory; - - if(term_id == -1) - video_memory = video_mem; - else - video_memory = control.terminal[term_id].vid_mem; + uint8_t * video_memory = (uint8_t *)control.terminal[term_id].vid_mem; //shift text up by one row for (i = 0; i < (NUM_ROWS - 1) * NUM_COLS; i++) @@ -272,21 +265,10 @@ void putc(uint8_t c, int32_t term_id) { uint8_t * video_memory; - int32_t terminal_to_write; - - if(term_id == -1) - { - terminal_to_write = control.cur_terminal; - video_memory = video_mem; - } - else - { - terminal_to_write = term_id; - video_memory = control.terminal[term_id].vid_mem; - } + if(term_id < 0 || term_id > 2) + return; - // if(init_ready) - // video_memory = control.terminal[control.cur_terminal].vid_mem; + video_memory = (uint8_t *)control.terminal[term_id].vid_mem; if(c == 0x08) //backspace { @@ -297,42 +279,43 @@ void putc(uint8_t c, int32_t term_id) { if(c == '\n' || c == '\r') { - control.terminal[terminal_to_write].terminal_y++; - control.terminal[terminal_to_write].terminal_x = 0; + control.terminal[term_id].terminal_y++; + control.terminal[term_id].terminal_x = 0; } else { - *(uint8_t *)(video_memory + ((NUM_COLS * control.terminal[terminal_to_write].terminal_y - + control.terminal[terminal_to_write].terminal_x) << 1)) = c; + *(uint8_t *)(video_memory + ((NUM_COLS * control.terminal[term_id].terminal_y + + control.terminal[term_id].terminal_x) << 1)) = c; - *(uint8_t *)(video_memory + ((NUM_COLS * control.terminal[terminal_to_write].terminal_y - + control.terminal[terminal_to_write].terminal_x) << 1) + 1) = ATTRIB; + *(uint8_t *)(video_memory + ((NUM_COLS * control.terminal[term_id].terminal_y + + control.terminal[term_id].terminal_x) << 1) + 1) = ATTRIB; - control.terminal[terminal_to_write].terminal_x++; + control.terminal[term_id].terminal_x++; //control.terminal[control.cur_terminal].terminal_x %= NUM_COLS; - control.terminal[terminal_to_write].terminal_y = - (control.terminal[terminal_to_write].terminal_y + - ((control.terminal[terminal_to_write].terminal_x%NUM_COLS) / NUM_COLS)) % NUM_ROWS; + control.terminal[term_id].terminal_y = + (control.terminal[term_id].terminal_y + + ((control.terminal[term_id].terminal_x%NUM_COLS) / NUM_COLS)) % NUM_ROWS; } - if(control.terminal[terminal_to_write].terminal_x == NUM_COLS && - control.terminal[terminal_to_write].terminal_y < NUM_ROWS-1) + if(control.terminal[term_id].terminal_x == NUM_COLS && + control.terminal[term_id].terminal_y < NUM_ROWS-1) { - control.terminal[terminal_to_write].terminal_y++; - control.terminal[terminal_to_write].terminal_x = 0; + control.terminal[term_id].terminal_y++; + control.terminal[term_id].terminal_x = 0; } - else if((control.terminal[terminal_to_write].terminal_x == NUM_COLS && - control.terminal[terminal_to_write].terminal_y == NUM_ROWS-1) || - control.terminal[terminal_to_write].terminal_y > NUM_ROWS-1) + else if((control.terminal[term_id].terminal_x == NUM_COLS && + control.terminal[term_id].terminal_y == NUM_ROWS-1) || + control.terminal[term_id].terminal_y > NUM_ROWS-1) { scroll_up(term_id); - control.terminal[terminal_to_write].terminal_x = 0; - control.terminal[terminal_to_write].terminal_y = NUM_ROWS-1; + control.terminal[term_id].terminal_x = 0; + control.terminal[term_id].terminal_y = NUM_ROWS-1; } - if(term_id == -1) - update_cursor(); + + update_cursor(); + } /* int8_t* itoa(uint32_t value, int8_t* buf, int32_t radix); diff --git a/student-distrib/lib.h b/student-distrib/lib.h index 15c53ff505d312f40e9601e07426066d24080126..73c2b60f80dcc12528a24a39be5ec7a617f9f604 100644 --- a/student-distrib/lib.h +++ b/student-distrib/lib.h @@ -8,8 +8,6 @@ #include "types.h" #include "i8259.h" -int32_t init_ready; - int32_t printf(int8_t *format, ...); void putc(uint8_t c, int32_t term_id); int32_t puts(int8_t *s); diff --git a/student-distrib/paging.c b/student-distrib/paging.c index b353fe6027855891e6c29e6de9281aea5c0b71f5..86698e20246819b1eb45b643ed4f8142d8b7bf10 100644 --- a/student-distrib/paging.c +++ b/student-distrib/paging.c @@ -25,10 +25,10 @@ void paging_initi(void){ page_table[0] = 0x0; /* Set page table for video memory */ - page_table[VIDEO_MEM + 0] |= PRESENT; - page_table[VIDEO_MEM + 1] |= PRESENT; //for 1st terminal - page_table[VIDEO_MEM + 2] |= PRESENT; //for 2nd terminal - page_table[VIDEO_MEM + 3] |= PRESENT; //for 3rd terminal + page_table[VIDEO_MEM + 0] |= USER | PRESENT; + page_table[VIDEO_MEM + 1] |= USER | PRESENT; //for 1st terminal + page_table[VIDEO_MEM + 2] |= USER | PRESENT; //for 2nd terminal + page_table[VIDEO_MEM + 3] |= USER | PRESENT; //for 3rd terminal /* Put the page table in the page directory */ page_directory[0] = ((uint32_t)page_table) | READ_WRITE | PRESENT; @@ -87,8 +87,8 @@ void remap_term(int32_t term_id){ uint32_t addr = control.terminal[term_id].vid_mem; - // if (control.cur_terminal == term_id) - // addr = TERM_VID; + if (control.cur_terminal == term_id) + addr = TERM_VID; page_table[VIDEO_MEM] = addr | USER | READ_WRITE | PRESENT; diff --git a/student-distrib/pit.c b/student-distrib/pit.c index 366a55827256af1f61a93564a70877094174ce86..c6b8d1271104198943ade56e93d335b427078b08 100644 --- a/student-distrib/pit.c +++ b/student-distrib/pit.c @@ -16,7 +16,7 @@ void i8253_init(void){ -void pit_handler(){ +void pit_handler(void){ //printf("[PIT] Interrupt Test"); //scheduler(); diff --git a/student-distrib/pit.h b/student-distrib/pit.h index 7029ff9412d8ba7265fa1b5cd742681b20be79c0..95e5a28fabbfa251ac38421d52fc460a8abfe44e 100644 --- a/student-distrib/pit.h +++ b/student-distrib/pit.h @@ -5,3 +5,6 @@ #define FREQUENCY 1193182 #define CHANNEL_0 0x40 #define CMD_REG 0x43 + +void i8253_init(void); +void pit_handler(void); diff --git a/student-distrib/syscall.c b/student-distrib/syscall.c index c570b260c3971f781afc9dce1dcca9c6b5fe25a3..da2d13b26ba6cc9be760655d62d5211084e7546d 100644 --- a/student-distrib/syscall.c +++ b/student-distrib/syscall.c @@ -17,7 +17,8 @@ int32_t halt (uint8_t status){ //pcb_t * pcb_cur = control.curr_pcb; pcb_t* pcb_prev = pcb_cur->parent_pcb; - printf("[halt] entered halt with pcb = %x\n", pcb_cur); + + pcb_cur->running_terminal = control.cur_terminal; /* set all present flags in PCB to "Not In Use" */ for (i = 0; i < MAX_FILE_NUM; i++) @@ -179,6 +180,7 @@ int32_t execute(const uint8_t* command){ //control.curr_pcb = pcb_ptr; pcb_ptr->running_terminal = control.cur_terminal; + control.running_terminal = control.cur_terminal; // Save current ESP, EBP asm volatile(" \n\ @@ -193,10 +195,7 @@ int32_t execute(const uint8_t* command){ control.terminal[control.cur_terminal].pcb = pcb_ptr; if (strncmp("shell", (int8_t*)parsed_cmd, 5) == 0) - { - printf("entered shell if\n"); control.terminal[control.cur_terminal].pcb->shell_flag = 1; - } //--------------------- 6: context switch----------------------------------- diff --git a/student-distrib/terminal.c b/student-distrib/terminal.c index aa196f115e87640690b98a1ba2554e560fba76cc..39b7bfa9e2847f313ffabd324796d8a19f4a83b0 100644 --- a/student-distrib/terminal.c +++ b/student-distrib/terminal.c @@ -93,13 +93,7 @@ int32_t terminal_write(int32_t fd, const void* buf, int32_t nbytes) pcb_t * pcb_ptr = current_pcb(); - int32_t terminal_to_write = (pcb_ptr->running_terminal == control.cur_terminal) ? -1 : control.cur_terminal; - - if(pcb_ptr->shell_flag) - terminal_to_write = -1; - - //printf("[terminal_write] shell_flag = %d\n", pcb_ptr->shell_flag); - //printf("[terminal_write] cur_terminal %d , running_terminal = %d , terminal_to_write = %d\n", control.cur_terminal, pcb_ptr->running_terminal, terminal_to_write); + int32_t terminal_to_write = (pcb_ptr->running_terminal == control.cur_terminal) ? control.cur_terminal : pcb_ptr->running_terminal; // checks if buf is null or overflow if((int8_t*)buf == NULL /*|| nbytes > MAX_BUF_SIZE-1*/) @@ -191,16 +185,18 @@ void init_terminal(void) */ int32_t switch_terminal(int32_t term_id) { - //retrieve currently visible terminal - int32_t prev_terminal = control.cur_terminal; + int32_t prev_terminal; //check for valid terminal id (from 0 to 2) and if we maxed out on processes if( term_id < 0 || term_id > 2 || control.total_prog_count >= MAX_PROCESS) return -2; + //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; + // if(term_id == prev_terminal) + // return -1; //set current terminal in control structure control.cur_terminal = term_id; @@ -209,12 +205,18 @@ int32_t switch_terminal(int32_t term_id) //store previous terminal data into memory memcpy( (void*)control.terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB ); - //remap_term(term_id); - clear(); - update_cursor(); + //restore paging from 0xb8000 to prev_terminal video mapping + remap_term(prev_terminal); + + //clear(); //display new terminal video memory - memcpy( (void*)TERM_VID, (const void*)control.terminal[term_id].vid_mem, _4_KB ); + memcpy( (void*)TERM_VID, (const void*)control.terminal[control.cur_terminal].vid_mem, _4_KB ); + + //set new terminal to update to physical video memory + remap_term(control.cur_terminal); + + update_cursor(); //check if shell is running on that terminal return (control.terminal[term_id].terminal_prog_count == 0) ? 0 : 1; diff --git a/student-distrib/types.h b/student-distrib/types.h index 13e79f2dafde29dd2c7ab5b6346fbf715c3f970d..7dcf04c869f57665a2ae6d4b2b6a75a3ef3eda0d 100644 --- a/student-distrib/types.h +++ b/student-distrib/types.h @@ -185,7 +185,7 @@ typedef struct control { pcb_t * curr_pcb; int32_t cur_terminal; int32_t visible_terminal; - //int32_t running_terminal; + int32_t running_terminal; int32_t total_prog_count; uint32_t filesys_start; int32_t pid_array[MAX_PROCESS];