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

mp3.5 final commit

parent f045a8f0
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,9 @@ void update_cursor(int32_t term_id) ...@@ -34,6 +34,9 @@ void update_cursor(int32_t term_id)
{ {
term_id = visible_terminal; term_id = visible_terminal;
uint16_t position = terminal[term_id].terminal_y * NUM_COLS + terminal[term_id].terminal_x; uint16_t position = terminal[term_id].terminal_y * NUM_COLS + terminal[term_id].terminal_x;
//HEX values copied from https://wiki.osdev.org/Text_Mode_Cursor
outb(0x0F, 0x3D4); outb(0x0F, 0x3D4);
outb((uint8_t)(position&0xFF), 0x3D5); outb((uint8_t)(position&0xFF), 0x3D5);
outb(0x0E, 0x3D4); outb(0x0E, 0x3D4);
......
...@@ -34,9 +34,8 @@ void control_initilization(void) ...@@ -34,9 +34,8 @@ void control_initilization(void)
total_prog_count = 0; total_prog_count = 0;
visible_terminal = 0; visible_terminal = 0;
running_terminal = 0; running_terminal = 1; // initialized to 1 so we end in the first shell
cur_pid = 0; cur_pid = 0;
counter = 0;
} }
/* The file descriptor table checking function /* The file descriptor table checking function
...@@ -198,7 +197,7 @@ int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[M ...@@ -198,7 +197,7 @@ int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[M
/* copy command to parsed_cmd */ /* copy command to parsed_cmd */
for (i = 0; i < (end - start); i++) for (i = 0; i < (end - start); i++)
if(command[i+start] != 0x0D) //check for \n if(command[i+start] != 0x0D) //0x0D = \n
parsed_cmd[i] = command[i+start]; parsed_cmd[i] = command[i+start];
command_length = strlen((int8_t*)command); command_length = strlen((int8_t*)command);
...@@ -236,7 +235,7 @@ int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[M ...@@ -236,7 +235,7 @@ int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[M
/* copy argument to return array */ /* copy argument to return array */
for (i = 0; i < (end - start); i++) for (i = 0; i < (end - start); i++)
if(command[i+start] != 0x0D) //check for \n if(command[i+start] != 0x0D) //0x0D = \n
argv[j][i] = command[i+start]; argv[j][i] = command[i+start];
} }
......
...@@ -80,9 +80,9 @@ void rtc_interrupt(void) ...@@ -80,9 +80,9 @@ void rtc_interrupt(void)
*/ */
int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes) int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes)
{ {
/* Set flag */ /* Set flag */
rtc_flag[running_terminal] = 1; if(rtc_active[running_terminal] == 1)
rtc_flag[running_terminal] = 1;
sti(); sti();
...@@ -130,38 +130,6 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes) ...@@ -130,38 +130,6 @@ int32_t rtc_write(int32_t fd, const void* buf, int32_t nbytes)
rtc_init_counter[running_terminal] = rtc_counter[running_terminal]; rtc_init_counter[running_terminal] = rtc_counter[running_terminal];
// /* Translate frequency to rate */
// temp_freq = freq;
// for (i = 1; i <= MAX_FREQ_POW; i++)
// {
// temp_freq = temp_freq >> 1;
// if ((temp_freq & bit_mask) == 1)
// {
// rate = RATE_OFFSET - i;
// break;
// }
// //temp_freq = temp_freq >> 1;
// }
// /* Set the rate */
// rate &= 0x0F;
// /* Disable interrupts */
// cli();
// /* set index to register A, disable NMI */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* get initial value of register A */
// prev = inb(RTC_DATA);
// /* reset index to A */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* write only our rate to A. Note, rate is the bottom 4 bits. */
// outb((prev & 0xF0) | rate, RTC_DATA);
// /* Enable interrupts */
// sti();
/* Return number of bytes written */ /* Return number of bytes written */
return FOUR_BYTES; return FOUR_BYTES;
} }
...@@ -183,38 +151,16 @@ int32_t rtc_open(const uint8_t* filename) ...@@ -183,38 +151,16 @@ int32_t rtc_open(const uint8_t* filename)
rtc_init_counter[running_terminal] = rtc_counter[running_terminal]; rtc_init_counter[running_terminal] = rtc_counter[running_terminal];
return 0; return 0;
// uint8_t rate, prev;
// /* Set the frequency to 2 Hz */
// rate = TWO_HZ;
// rate &= 0x0F;
// /* Disable interrupts */
// cli();
// /* set index to register A, disable NMI */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* get initial value of register A */
// prev = inb(RTC_DATA);
// /* reset index to A */
// outb(DISABLE_NMI_A, RTC_PORT);
// /* write only our rate to A. Note, rate is the bottom 4 bits. */
// outb((prev & 0xF0) | rate, RTC_DATA);
// /* Enable interrupts */
// sti();
// return 0;
} }
/* rtc_close() /* rtc_close()
* Inputs: fd - file descriptor * Inputs: fd - file descriptor
* Return Value: returns 0 * Return Value: returns 0
* Function: *Not virtualized yet* * Function: *Not virtualized yet*
*/ */
int32_t rtc_close(int32_t fd) int32_t rtc_close(int32_t fd)
{ {
/* Not virtualised yet */ rtc_active[running_terminal] = 0;
return 0; return 0;
} }
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
/* The scheduler function /* The scheduler function
* *
* DISCRIPTION: This function switch running process every 15 ms * DESCRIPTION: This function switch running process every 15 ms
* * Input: NONE
* Output: NONE
* Side Effects: switches processes
*/ */
void scheduler(void){ void scheduler(void){
// Bookkeeping // get current pcb
pcb_t * curr_pcb = terminal[running_terminal].pcb; pcb_t * curr_pcb = terminal[running_terminal].pcb;
// check if no program is running on that terminal
if(curr_pcb == NULL) if(curr_pcb == NULL)
{ {
...@@ -18,6 +21,7 @@ void scheduler(void){ ...@@ -18,6 +21,7 @@ void scheduler(void){
pcb_t pcb; pcb_t pcb;
pcb.scheduler_flag = 1; pcb.scheduler_flag = 1;
//move esp and ebp to pcb
asm volatile( asm volatile(
"movl %%esp, %0 \n" "movl %%esp, %0 \n"
"movl %%ebp, %1 \n" "movl %%ebp, %1 \n"
...@@ -26,17 +30,22 @@ void scheduler(void){ ...@@ -26,17 +30,22 @@ void scheduler(void){
: "memory" : "memory"
); );
// set pointer to terminal pcb
terminal[running_terminal].pcb = &pcb; terminal[running_terminal].pcb = &pcb;
// perform terminal switch to the next terminal
switch_terminal(running_terminal); switch_terminal(running_terminal);
printf("terminal = %d\n", running_terminal); printf("terminal = %d\n", running_terminal+1);
// send PIT eoi now because we don't return here after execute
send_eoi(PIT_IRQ); send_eoi(PIT_IRQ);
// start shell
execute((uint8_t *)"shell"); execute((uint8_t *)"shell");
} }
// save esp and ebp of old process
asm volatile( asm volatile(
"movl %%esp, %0 \n" "movl %%esp, %0 \n"
"movl %%ebp, %1 \n" "movl %%ebp, %1 \n"
...@@ -46,34 +55,42 @@ void scheduler(void){ ...@@ -46,34 +55,42 @@ void scheduler(void){
); );
// Round Robin // Round Robin
running_terminal = (running_terminal + 1) % 3; running_terminal = (running_terminal + 1) % MAX_TERMINAL;
// check again for non initialized pcb
if(terminal[running_terminal].pcb == NULL) if(terminal[running_terminal].pcb == NULL)
{ {
send_eoi(PIT_IRQ); send_eoi(PIT_IRQ);
return; return;
} }
// remap video memory
remap_vidmem(); remap_vidmem();
// adjust memory for terminals
store_vid_mem(running_terminal); store_vid_mem(running_terminal);
// get next process
pcb_t* next_pcb = terminal[running_terminal].pcb; pcb_t* next_pcb = terminal[running_terminal].pcb;
// update current pid, tss and remap paging // update current pid, tss and remap paging
remap_proc(next_pcb->pid); remap_proc(next_pcb->pid);
// store kernel stack segment and esp
tss.ss0 = KERNEL_DS; tss.ss0 = KERNEL_DS;
tss.esp0 = _8_MB - _8_KB * (next_pcb->pid); tss.esp0 = _8_MB - _8_KB * (next_pcb->pid);
// send PIT eoi now because we don't return here
send_eoi(PIT_IRQ); send_eoi(PIT_IRQ);
// perform process switch by changing esp and ebp
asm volatile( asm volatile(
//change esp and ebp
"movl %0, %%esp \n" "movl %0, %%esp \n"
"movl %1, %%ebp \n" "movl %1, %%ebp \n"
: :
: "r" (next_pcb->current_esp), "r" (next_pcb->current_ebp) : "r" (next_pcb->current_esp), "r" (next_pcb->current_ebp)
: "esp" , "ebp" : "esp" , "ebp"
); );
// printf("[SCHEDULE] after ebp and esp breaking");
return;
} }
...@@ -21,6 +21,7 @@ int32_t halt (uint8_t status) { ...@@ -21,6 +21,7 @@ int32_t halt (uint8_t status) {
/* set all present flags in PCB to "Not In Use" */ /* set all present flags in PCB to "Not In Use" */
for (i = 0; i < MAX_FILE_NUM; i++) for (i = 0; i < MAX_FILE_NUM; i++)
{ {
// close all files for current pcb
if( i > 1 && pcb_cur->fd[i].flags == 1 ) if( i > 1 && pcb_cur->fd[i].flags == 1 )
close(i); close(i);
...@@ -452,9 +453,9 @@ int32_t vidmap (uint8_t** screen_start) ...@@ -452,9 +453,9 @@ int32_t vidmap (uint8_t** screen_start)
remap_vidmem(); remap_vidmem();
*screen_start = (uint8_t *)(0x8400000); // 132MB, video memory starting address *screen_start = (uint8_t *)(_132_MB); // 132MB, video memory starting address
return 0x8400000; return _132_MB;
} }
/* /*
......
...@@ -141,25 +141,24 @@ typedef struct file_object { ...@@ -141,25 +141,24 @@ typedef struct file_object {
/* Process control block structure */ /* Process control block structure */
typedef struct pcb { typedef struct pcb {
file_object_t fd[MAX_FILE_NUM]; /* File descriptor array */ file_object_t fd[MAX_FILE_NUM]; /* File descriptor array */
int32_t shell_flag; int32_t shell_flag; /* indicates if pcb is shell */
int32_t scheduler_flag; int32_t scheduler_flag; /* overrides esp and ebp setting in pcb_init */
uint32_t pid; /* Holds current process ID */ uint32_t pid; /* Holds current process ID */
uint32_t current_esp; /* Store Current esp for scheduling */ uint32_t current_esp; /* Store Current esp for scheduling */
uint32_t current_ebp; /* Store Current ebp for scheduling */ uint32_t current_ebp; /* Store Current ebp for scheduling */
uint32_t current_eip; /* Store Current eip for scheduling */
struct pcb* parent_pcb; struct pcb* parent_pcb;
uint32_t parent_pid; /* Holds parent process ID */ uint32_t parent_pid; /* Holds parent process ID */
uint32_t parent_esp; /* Stores Kernel ESP, EBP*/ uint32_t parent_esp; /* Stores Kernel ESP, EBP*/
uint32_t parent_ebp; /* Stores Kernel ESP, EBP*/ uint32_t parent_ebp; /* Stores Kernel ESP, EBP*/
uint32_t tss_esp0; /* saves TSS before context switch */ uint32_t tss_esp0; /* saves TSS before context switch */
uint32_t arg_num; /* Number of arguments in argv */ uint32_t arg_num; /* Number of arguments in argv */
uint8_t cmd[MAX_COMMAND_SIZE]; /* Command */ uint8_t cmd[MAX_COMMAND_SIZE]; /* Command */
uint8_t argv[MAX_ARGUMENT_NUM][MAX_ARGUMENT_SIZE]; /* Argument table */ uint8_t argv[MAX_ARGUMENT_NUM][MAX_ARGUMENT_SIZE]; /* Argument table */
} pcb_t; } pcb_t;
...@@ -184,7 +183,6 @@ volatile int32_t buffer_index; ...@@ -184,7 +183,6 @@ volatile int32_t buffer_index;
/*---------------------------- Global variable -------------------------------*/ /*---------------------------- Global variable -------------------------------*/
uint32_t filesys_start; /* Starting place for file system */ uint32_t filesys_start; /* Starting place for file system */
int32_t counter; /* */
terminal_t terminal[MAX_TERMINAL]; /* Terminal array that store the information for each termianl */ terminal_t terminal[MAX_TERMINAL]; /* Terminal array that store the information for each termianl */
int32_t visible_terminal; /* */ int32_t visible_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