Skip to content
Snippets Groups Projects
Commit 33556291 authored by Divyam Khandelwal's avatar Divyam Khandelwal
Browse files

Minor logic changes

parent 6e7f5573
No related branches found
No related tags found
No related merge requests found
...@@ -383,8 +383,8 @@ void KB_handler(void) { ...@@ -383,8 +383,8 @@ void KB_handler(void) {
clear(); clear();
reset_cursor(); reset_cursor();
if(terminal[visible_terminal].pcb->shell_flag) //if(terminal[visible_terminal].pcb->shell_flag)
printf("391OS> "); // printf("391OS> ");
remap2(running_terminal); remap2(running_terminal);
send_eoi(KB_IRQ); send_eoi(KB_IRQ);
......
...@@ -80,16 +80,15 @@ void remap2(int32_t term_id){ ...@@ -80,16 +80,15 @@ void remap2(int32_t term_id){
* Return Value: void * Return Value: void
* Function: Initialises page for video memory * 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; page_directory[33] = (uint32_t)(uint32_t)page_table | USER | READ_WRITE | PRESENT;
if(visible_terminal == running_terminal) if(visible_terminal == running_terminal)
page_table[0] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT; page_table[0] = ((uint32_t)0xB8000) | USER | READ_WRITE | PRESENT;
else else
page_table[0] = ((uint32_t)(0xB8000 + (running_terminal+1)*0x1000 )) | USER | READ_WRITE | PRESENT; page_table[0] = ((uint32_t)(0xB8000 + (running_terminal+1)*0x1000 )) | USER | READ_WRITE | PRESENT;
// flush TLB // flush TLB
......
...@@ -12,18 +12,20 @@ int32_t fail(){ ...@@ -12,18 +12,20 @@ int32_t fail(){
return -1; return -1;
} }
/* Initialized at bootup */
void control_initilization(void) void control_initilization(void)
{ {
int i; int i;
/* All PID entries to present */
for(i = 0; i < MAX_PROCESS; i++) for(i = 0; i < MAX_PROCESS; i++)
pid_array[i] = 0; pid_array[i] = 0;
total_prog_count = 0; total_prog_count = 0;
visible_terminal = 0; visible_terminal = 0;
running_terminal = 0; running_terminal = 0;
cur_pid = 0; cur_pid = 0;
counter = 0; counter = 0;
// running_terminal = 0;
} }
/* Checks if FD is valid /* Checks if FD is valid
...@@ -41,7 +43,7 @@ int32_t fd_check(int32_t fd) ...@@ -41,7 +43,7 @@ int32_t fd_check(int32_t fd)
return -1; return -1;
} }
//clearing fd /* Clear FD for process on halt */
void fd_clear(int32_t fd) void fd_clear(int32_t fd)
{ {
terminal[ running_terminal].pcb->fd[fd].fileop_ptr.read = 0; terminal[ running_terminal].pcb->fd[fd].fileop_ptr.read = 0;
...@@ -51,14 +53,18 @@ void fd_clear(int32_t fd) ...@@ -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].inode_index = 0;
terminal[ running_terminal].pcb->fd[fd].file_pos = 0; terminal[ running_terminal].pcb->fd[fd].file_pos = 0;
terminal[ running_terminal].pcb->fd[fd].flags = 0; terminal[ running_terminal].pcb->fd[fd].flags = 0;
return; 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) 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; 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.read = 0;
pcb->fd[i].fileop_ptr.write = 0; pcb->fd[i].fileop_ptr.write = 0;
pcb->fd[i].fileop_ptr.open = 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 ...@@ -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; pcb->fd[i].flags = 0;
} }
//initialze stdin /* Initialze STDIN */
pcb->fd[STDIN_FD].fileop_ptr = (f_table_t)stdin_jumptable; pcb->fd[STDIN_FD].fileop_ptr = (f_table_t)stdin_jumptable;
pcb->fd[STDIN_FD].inode_index = 0; pcb->fd[STDIN_FD].inode_index = 0;
pcb->fd[STDIN_FD].file_pos = 0; pcb->fd[STDIN_FD].file_pos = 0;
pcb->fd[STDIN_FD].flags = 1; 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].fileop_ptr = (f_table_t)stdout_jumptable;
pcb->fd[STDOUT_FD].inode_index = 0; pcb->fd[STDOUT_FD].inode_index = 0;
pcb->fd[STDOUT_FD].file_pos = 0; pcb->fd[STDOUT_FD].file_pos = 0;
pcb->fd[STDOUT_FD].flags = 1; pcb->fd[STDOUT_FD].flags = 1;
/* Set the PID sent in as argument */
pcb->pid = pid; pcb->pid = pid;
pcb->scheduler_flag = 0; 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->parent_pid = 0;
pcb->arg_num = arg_num; pcb->arg_num = arg_num;
pcb->running_terminal = visible_terminal;
pcb->shell_flag = 0;
memcpy(pcb->cmd, parsed_cmd, MAX_COMMAND_SIZE); memcpy(pcb->cmd, parsed_cmd, MAX_COMMAND_SIZE);
for(i = 0; i < MAX_ARGUMENT_NUM; i++) 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 ...@@ -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_esp = 0;
pcb->parent_ebp = 0; pcb->parent_ebp = 0;
pcb->parent_pcb = terminal[visible_terminal].pcb; pcb->parent_pcb = terminal[running_terminal].pcb;
pcb->tss_esp0 = tss.esp0; pcb->tss_esp0 = tss.esp0;
return; return;
} }
//function that return a pointer to the current pcb /* Parsing the command, extracting the command and the argument
pcb_t* current_pcb(void) * returns number of arguments when successful, -2 fot exit, -1 for failure */
{
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
int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZE]) int32_t parse_cmd(const uint8_t* command, uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZE])
{ {
int32_t i,j, command_length; int32_t i,j, command_length;
......
...@@ -84,7 +84,7 @@ int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes) ...@@ -84,7 +84,7 @@ int32_t rtc_read(int32_t fd, void* buf, int32_t nbytes)
/* Set flag */ /* Set flag */
rtc_flag[running_terminal] = 1; rtc_flag[running_terminal] = 1;
//interrupt_flag = 1;
sti(); sti();
/* Wait until interrupt handler clears flag */ /* Wait until interrupt handler clears flag */
......
...@@ -35,7 +35,7 @@ int32_t halt (uint8_t status) ...@@ -35,7 +35,7 @@ int32_t halt (uint8_t status)
{ {
clear_pid(pcb_cur->pid); clear_pid(pcb_cur->pid);
total_prog_count--; 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) if(terminal[running_terminal].terminal_prog_count == 0)
...@@ -212,13 +212,6 @@ int32_t execute(const uint8_t* command) ...@@ -212,13 +212,6 @@ int32_t execute(const uint8_t* command)
terminal[running_terminal].pcb = pcb_ptr; 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 ----------------------- //--------------------- 6: scheduling initilization -----------------------
......
...@@ -143,9 +143,6 @@ typedef struct pcb { ...@@ -143,9 +143,6 @@ 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 running_terminal;
int32_t shell_flag;
int32_t scheduler_flag; int32_t scheduler_flag;
uint32_t pid; /* Holds current process ID */ uint32_t pid; /* Holds current process ID */
......
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