From e781fb26fdd422ea72c3a0eeba817e4faa5f663b Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Wed, 1 Apr 2015 20:22:48 -0400 Subject: as of 2013-10-17 --- pcb.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'pcb.c') diff --git a/pcb.c b/pcb.c index 8f4034a..c383a37 100644 --- a/pcb.c +++ b/pcb.c @@ -2,6 +2,12 @@ #include #include +#define STK_PSW (STACK_SIZE - 1) +#define STK_CS (STACK_SIZE - 2) +#define STK_IP (STACK_SIZE - 3) +#define STK_DS (STACK_SIZE - 9) +#define INIT_STACK (STACK_SIZE - 12) + /** * Returns the address of the PCB with the specified name */ @@ -54,7 +60,7 @@ int free_pcb(pcb * list, pcb * addr) { return -2; } else { // we need to free the PCB - build_pcb(current, " ", 0, -1, -1, 0); + build_pcb(current, " ", 0, -1, -1, 0, NULL, NULL, NULL, NULL); return 1; } } @@ -69,7 +75,8 @@ int free_pcb(pcb * list, pcb * addr) { * Sets the properties of the given PCB. */ int build_pcb(pcb * addr, char name[], int type, int state, - int suspend, int priority) { + int suspend, int priority, unsigned cs, unsigned ip, + unsigned ds, unsigned psw) { // check that address is valid if (addr == 0 || addr == NULL) { return -1; @@ -99,6 +106,13 @@ int build_pcb(pcb * addr, char name[], int type, int state, addr->prev = NULL; addr->priority = priority; + // set up the stack + addr->stack[STK_PSW] = psw; + addr->stack[STK_CS] = cs; + addr->stack[STK_IP] = ip; + addr->stack[STK_DS] = ds; + + addr->stack_ptr =(unsigned) &(addr->stack[INIT_STACK]); return 1; } @@ -172,7 +186,9 @@ int remove_pcb(pcb **queue, pcb * addr) { // are we removing the head? if (addr == *queue) { *queue = addr->next; - (addr->next)->prev = NULL; + if (addr->next != NULL) { + (addr->next)->prev = NULL; + } return 0; } -- cgit v1.2.3