Skip to content
Snippets Groups Projects
Commit b47bebda authored by abinade2's avatar abinade2
Browse files

fixed user program squashing

parent 7cc010b4
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,7 @@ void exception_handler(int interrupt_index) ...@@ -68,7 +68,7 @@ void exception_handler(int interrupt_index)
printf("GENERAL PROTECTION EXCEPTION\n"); printf("GENERAL PROTECTION EXCEPTION\n");
break; break;
case -15: case -15:
printf("PAGE FAULT EXCEPTION"); printf("PAGE FAULT EXCEPTION\n");
break; break;
case -17: case -17:
printf("MATH FAULT EXCEPTION\n"); printf("MATH FAULT EXCEPTION\n");
...@@ -84,8 +84,10 @@ void exception_handler(int interrupt_index) ...@@ -84,8 +84,10 @@ void exception_handler(int interrupt_index)
break; break;
} }
cli(); printf("Squashing user level program...\n");
while(1); // halt the kernel, since an exception occurs
//return control to shell
halt(-1);
} }
/* /*
......
...@@ -373,8 +373,7 @@ void KB_handler(void) { ...@@ -373,8 +373,7 @@ void KB_handler(void) {
} }
page_table[0xB8] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT; remap1();
flush_tlb();
// 0x15 = scancode for L // 0x15 = scancode for L
// check if ctrl-L is pressed // check if ctrl-L is pressed
......
...@@ -49,7 +49,7 @@ void paging_initi(void){ ...@@ -49,7 +49,7 @@ void paging_initi(void){
//term_id = current //term_id = current
void remap1(int32_t term_id){ void remap1(void){
page_table[0xB8] = (uint32_t)(0xB8000) | USER | READ_WRITE | PRESENT; page_table[0xB8] = (uint32_t)(0xB8000) | USER | READ_WRITE | PRESENT;
flush_tlb(); flush_tlb();
return; return;
......
...@@ -58,7 +58,7 @@ void loadPageDirectory(unsigned int*); ...@@ -58,7 +58,7 @@ void loadPageDirectory(unsigned int*);
*/ */
void enablePaging(void); void enablePaging(void);
extern void remap1(int32_t term_id); extern void remap1(void);
extern void remap2(int32_t term_id); extern void remap2(int32_t term_id);
......
...@@ -102,7 +102,6 @@ int32_t execute(const uint8_t* command) ...@@ -102,7 +102,6 @@ int32_t execute(const uint8_t* command)
uint8_t argv[MAX_ARGUMENT_NUM][MAX_ARGUMENT_SIZE]; uint8_t argv[MAX_ARGUMENT_NUM][MAX_ARGUMENT_SIZE];
int32_t ret, arg_num; //number that indicated special command int32_t ret, arg_num; //number that indicated special command
int32_t pid = set_pid();
//if( pid == -1) return -1; // reach max process //if( pid == -1) return -1; // reach max process
ret = parse_cmd(command, parsed_cmd, argv); ret = parse_cmd(command, parsed_cmd, argv);
...@@ -141,6 +140,8 @@ int32_t execute(const uint8_t* command) ...@@ -141,6 +140,8 @@ int32_t execute(const uint8_t* command)
return -1; return -1;
} }
int32_t pid = set_pid();
// Get a new pid // Get a new pid
total_prog_count++; total_prog_count++;
terminal[running_terminal].terminal_prog_count++; terminal[running_terminal].terminal_prog_count++;
......
...@@ -218,7 +218,7 @@ int32_t switch_terminal(int32_t term_id) ...@@ -218,7 +218,7 @@ int32_t switch_terminal(int32_t term_id)
visible_terminal = term_id; visible_terminal = term_id;
//restore paging from 0xb8000 to prev_terminal video mapping //restore paging from 0xb8000 to prev_terminal video mapping
remap1(prev_terminal); remap1();
//store previous terminal data into memory //store previous terminal data into memory
memcpy( (void*) terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB ); memcpy( (void*) terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB );
...@@ -234,29 +234,3 @@ int32_t switch_terminal(int32_t term_id) ...@@ -234,29 +234,3 @@ int32_t switch_terminal(int32_t term_id)
//check if shell is running on that terminal //check if shell is running on that terminal
return ( terminal[term_id].terminal_prog_count == 0) ? 0 : 1; return ( 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)
{
//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*) terminal[term_id].vid_mem, _4_KB );
else
memcpy( (void*) terminal[term_id].vid_mem, (const void*)TERM_VID, _4_KB );
return;
}
...@@ -16,7 +16,7 @@ extern int32_t terminal_write(int32_t fd, const void* buf, int32_t nbytes); ...@@ -16,7 +16,7 @@ extern int32_t terminal_write(int32_t fd, const void* buf, int32_t nbytes);
extern int32_t terminal_open(const uint8_t* filename); extern int32_t terminal_open(const uint8_t* filename);
extern int32_t terminal_close(int32_t fd); extern int32_t terminal_close(int32_t fd);
void remap1(int32_t term_id); void remap1(void);
void remap2(int32_t term_id); void remap2(int32_t term_id);
extern int32_t switch_terminal(int32_t term_id); extern int32_t switch_terminal(int32_t term_id);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define MAX_FILE_NUM 8 #define MAX_FILE_NUM 8
#define MIN_FILE_NUM 0 #define MIN_FILE_NUM 0
#define MAX_COMMAND_SIZE 10 #define MAX_COMMAND_SIZE 10
#define MAX_ARGUMENT_NUM 2 #define MAX_ARGUMENT_NUM 1
#define MAX_ARGUMENT_SIZE 40 #define MAX_ARGUMENT_SIZE 40
//for terminal //for terminal
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment