diff options
-rw-r--r-- | clock.c | 141 | ||||
-rw-r--r-- | com.c | 6 | ||||
-rw-r--r-- | comdrtst.c | 125 | ||||
-rw-r--r-- | comdrtsw.c | 73 | ||||
-rw-r--r-- | comhan.c | 186 | ||||
-rw-r--r-- | io.c | 192 | ||||
-rw-r--r-- | main.c | 61 | ||||
-rw-r--r-- | mpx.h | 41 | ||||
-rw-r--r-- | pcb.c | 10 | ||||
-rw-r--r-- | printer.c | 5 | ||||
-rw-r--r-- | proc1.asm | 62 | ||||
-rw-r--r-- | proc2.asm | 63 | ||||
-rw-r--r-- | proc3.asm | 63 | ||||
-rw-r--r-- | proc4.asm | 63 | ||||
-rw-r--r-- | proc5.asm | 62 | ||||
-rw-r--r-- | prtdrtst.c | 68 | ||||
-rw-r--r-- | qtest.c | 19 | ||||
-rw-r--r-- | sys_sppt.c | 186 | ||||
-rw-r--r-- | testn.c | 119 |
19 files changed, 513 insertions, 1032 deletions
@@ -0,0 +1,141 @@ +/*
+ * Clock support for MPX-OS
+ * Ben Burwell & Averill Morash
+ * CSI350 - Fall 2013
+ */
+
+#include <dos.h>
+#include "mpx.h"
+
+void interrupt (*vect08)();
+unsigned long clock; /* The clock counter */
+
+/*
+ * Set up MXP clock
+ */
+void clock_open() {
+ unsigned char imr;
+
+ disable();
+ /* set up interrupt vector for timer interrupts */
+ vect08 = getvect(0x08);
+ setvect(0x08,&clock_int);
+
+ // set the timer mode
+ outportb(CMR, 0x36);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+
+ // set the count clock
+ clock = 0L;
+
+ // enable timer interrupts
+ imr = inportb(IMR); // Get current IMR
+ imr = imr & CLOCK_ENABLE; // Clear timer bit
+ outportb(IMR, imr); // Set new IMR
+
+ enable();
+}
+
+/*
+ * Restore the MS DOS clock
+ */
+void clock_close() {
+ disable();
+ setvect(0x08,vect08);
+ enable();
+}
+
+void interrupt clock_int() {
+ disable();
+ // if it's been 24 hours, reset clock to 0
+ if (clock >= 1572462L) {
+ clock = 0L;
+ } else {
+ clock++;
+ }
+ outportb(0x20, 0x20);
+ enable();
+}
+
+void stop_clock() {
+ unsigned char imr;
+ disable();
+
+ imr = inportb(IMR); // Get the old imr
+ imr = imr | CLOCK_DISABLE; // Disable timer interrupts
+ outportb(IMR, imr); // Set the new imr
+
+ enable();
+}
+
+/*
+ * Enables the timer interrupt
+ */
+void start_clock() {
+ unsigned char imr;
+ disable();
+
+ imr = inportb(IMR); // Get the old imr
+ imr = imr & CLOCK_ENABLE; // Enable timer interrupts
+ outportb(IMR, imr); // Set the new imr
+
+ enable();
+}
+
+/*
+ * Sets the value of the clock
+ */
+int set_clock(int hr, int m, int s) {
+ unsigned long ticks;
+
+ // Validate input
+ if (hr > 23 || hr < 0 || m > 59 || m < 0 || s > 59 || s < 0) {
+ return -1;
+ }
+
+ // set clock
+ ticks = 0L;
+ ticks = ((unsigned long)hr * 3600L * 91L / 5L);
+ ticks += ((unsigned long)m * 60L * 91L / 5L);
+ ticks += ((unsigned long)s * 91L / 5L);
+
+ disable();
+ clock = ticks;
+ enable();
+
+ return 0;
+}
+
+/*
+ * Gets the value of the clock
+ */
+void read_clock(int *hr, int *m, int *s) {
+ unsigned long ticks;
+ long total_seconds = 0L;
+ int l_hr = 0;
+ int l_m = 0; //local vars for hr, m
+
+ disable();
+ ticks = clock;
+ enable();
+
+ total_seconds = ticks * 10L;
+ total_seconds = total_seconds / 182L;
+
+ //count the whole hours
+ while (total_seconds >= 3600L) {
+ l_hr++;
+ total_seconds = total_seconds - 3600L;
+ }
+
+ //count the whole minutes
+ while (total_seconds >= 60L) {
+ l_m++;
+ total_seconds = total_seconds - 60L;
+ }
+
+ *hr = l_hr;
+ *m = l_m;
+ *s = total_seconds;
+}
\ No newline at end of file @@ -13,7 +13,6 @@ void interrupt (*vect0c)();
-dcb com;
int com_opened;
@@ -106,8 +105,11 @@ void com_close() { void interrupt com_int() {
int iir;
+ int *lst_stk;
int ret = 0; //0 indicates not finished, 1 indicated finshed
+ lst_stk = _BP;
+
// check IIR to see what caused the interrupt
iir = inportb(IIR);
// only look at bits 1, 2
@@ -123,7 +125,7 @@ void interrupt com_int() { }
if (ret == 1) {
- IO_complete();
+ IO_complete(COM, lst_stk);
}
// write end of interrupt to 8259
diff --git a/comdrtst.c b/comdrtst.c deleted file mode 100644 index e5fd8c6..0000000 --- a/comdrtst.c +++ /dev/null @@ -1,125 +0,0 @@ -/***********************************************************************
-*
-* Name: comdrtst
-*
-* Purpose: Test program for comdrive read and write
-*
-* Algorithm: Tests both comdrive for both input (com_read)
-* and output (com_write)
-*
-***************************************************************************/
-
-#include <stdio.h>
-#include <dos.h>
-
-extern int com_read(char far *buff, int far *len);
-extern int com_write(char far *buff, int far *len);
-
-
-int main()
-{
- int e_flag;
- int tmp;
- int rc;
- char buffer[100];
- char prompt[20];
-
- int length;
-
- rc = com_open(&e_flag,1200);
-
- /* if bad return code, display value and exit */
- if (rc != 0)
- {
- printf("\nrc(com_open) = %d",rc);
- exit();
- }
-
- strcpy(buffer,"");
- while (strcmp(buffer,"quit") != 0)
- {
- /* command prompt on com port */
- length = 16;
- e_flag = 0;
- rc = com_write("\015\012Enter string: ",&length);
-
- /* if bad return code, display value and exit */
- if (rc != 0)
- {
- printf("\nrc(com_write) = %x",rc);
- exit();
- }
-
- /* loop until write complete */
- while (e_flag == 0)
- printf("wait for write\n");
-
- /* read string */
- length = 30;
- e_flag = 0;
- rc = com_read(buffer,&length);
-
- /* if bad return code, display value and exit */
-
- if (rc != 0)
- {
- printf("\nrc(com_read) = %x",rc);
- exit();
- }
-
- /* loop until read is done */
- while (e_flag == 0)
- printf("wait - reading\n");
-
-
-
- /* display string entered */
- e_flag = 0;
- tmp = 22;
- rc = com_write("\015\012string entered was: ",&tmp);
-
- /* if bad return code, display value and exit */
- if (rc != 0)
- {
- printf("\nrc(com_write) = %x",rc);
- exit();
- }
-
- /* loop until write is done */
- while (e_flag == 0)
- printf("wait for string to be written\n");
-
-
- e_flag = 0;
- rc = com_write(buffer,&length);
-
- /* if bad return code, display value and exit */
- if (rc != 0)
- {
- printf("\nrc(com_write) = %x",rc);
- }
- /* loop until write is done */
- while (e_flag == 0);
-}
-
- length = 29;
- e_flag = 0;
- rc = com_write ("\015\012Com Driver Test Completed\015\012",&length);
-
- /* if bad return code, display value and exit */
- if (rc != 0)
- {
- printf("\nrc(com_write) = %x",rc);
- }
-
- /* loop until last write is done */
- while (e_flag == 0);
-
- com_close();
- return 0;
- }
-
-int IO_complete(int device, int *stkptr)
-{
- return 0;
-}
diff --git a/comdrtsw.c b/comdrtsw.c deleted file mode 100644 index f8a99b3..0000000 --- a/comdrtsw.c +++ /dev/null @@ -1,73 +0,0 @@ -/***********************************************************************
-*
-* Name: comdrtsw
-*
-* Purpose: Test program for write portion of comdrive
-*
-* Algorithm: Tests com_open(), com_write(), and com_close()
-*
-************************************************************************/
-
-#include <stdio.h>
-#include <dos.h>;
-
-extern int com_read(char far *buff, int far *len);
-extern int com_write(char far *buff, int far *len);
-
-int main()
- {
- int e_flag;
- int tmp;
- int rc;
- char buffer[100];
- int length;
-
- /* open com port */
-
- rc = com_open(&e_flag,1200);
- if ( rc != 0)
- {
- printf("\nrc(open) = %d",rc);
- exit();
- }
-
- /* prepare test string */
- strcpy(buffer,"This is a test of the com_write procedure .. 1234567890......\015\012");
- length = 64;
-
- /* print test string 25 times */
- for (tmp = 1; tmp <25; tmp++)
- {
- e_flag = 0; /* Clear event flag */
- rc = com_write(buffer,&length); /* Start COM write */
- if (rc != 0)
- {
- printf("\nrc(write) = %d",rc);
- exit();
- }
-
- /* Loop until com write is done. */
- /* This look like an infinite loop */
- while (e_flag == 0)
- printf("waiting %d\n",tmp);
- }
-
- e_flag = 0;
- length = 28;
- rc = com_write("End of Com Driver Test ...\015\012",&length);
- if (rc != 0)
- {
- printf("\nrc(write) = %d",rc);
- exit();
- }
-
- /* loop until com write is done */
- while (e_flag == 0);
-
- com_close();
- }
-
-int IO_complete(int device, int *stkptr)
-{
- return 0;
-}
@@ -9,6 +9,7 @@ #include <string.h>
#include <stdlib.h>
#include <math.h>
+#include <dos.h>
#include "mpx.h"
#define BUF_SIZE 80 /* Size of the command line buffer. */
@@ -69,13 +70,15 @@ void comhan() { do {
printf("%s ",prompt); /* Print a prompt. */
+ //length = 4; //mpx>
+ //sys_req(COM, WRITE, prompt, &length);
length = BUF_SIZE; /* Reset length of buffer. */
sys_req(CON,READ,buffer,&length); /* Request CON input */
set_args(buffer, args);
switch (get_cmd(args[0])) {
- case VERSION: cmd_version(); break;
+ case VERSION: cmd_version(); break;
case DATE: cmd_date(args); break;
case DIRECTORY: cmd_directory(); break;
case STOP: do_stop = cmd_stop(); break;
@@ -83,18 +86,18 @@ void comhan() { case PROMPT: cmd_prompt(args); break;
case ALIAS: cmd_alias(args); break;
case SHOW: cmd_show(args); break;
- case ALLOCATE: cmd_allocate(args); break;
- case CMD_FREE: cmd_free(args); break;
+// case ALLOCATE: cmd_allocate(args); break;
+// case CMD_FREE: cmd_free(args); break;
case CMD_LOAD: cmd_load(args); break;
case CMD_RESUME: cmd_resume(args); break;
case CMD_RUN: cmd_run(args); break;
case CMD_SUSPEND: cmd_suspend(args); break;
case CMD_TERMINATE: cmd_terminate(args); break;
case CMD_SETPRI: cmd_setpri(args); break;
- case CMD_DISPATCH: cmd_dispatch(); break;
- case CLOCK: cmd_clock(args); break;
+// case CMD_DISPATCH: cmd_dispatch(); break;
+ case CLOCK: cmd_clock(args); break;
default:
- printf("Can't recognize.\n");
+ printf("Can't recognize. %s\n", args[0]);
break;
}
} while (!do_stop);
@@ -125,7 +128,8 @@ int get_cmd(char cmd[]){ int set_args(char buffer[], char *args[]) {
/* use string tok to set the contents of args from buffer
and return the number of args (will go into argc) */
- char separators[5] = " =/,:"; //Characters that separate tokens
+ char separators[5] = " /,:"; //Characters that separate tokens
+ // TODO: put = back in separators
int i = 0; //loop control
args[i] = strtok(buffer, separators); //Get first token
@@ -205,6 +209,7 @@ int cmd_stop(){ }
p = p->chain;
} while(p != NULL);
+ sys_exit();
printf("** COMHAN execution complete **\n");
return 1;
} else {
@@ -321,7 +326,9 @@ void cmd_show(char *args[]) { printf("------ -------- --- ------ ------ ------ --- ------ \n");
if (strcmp(args[1], "init") == 0 || strcmp(args[1], "ready") == 0) {
- current = (strcmp(args[1], "init") == 0)? io_init_queue : ready_queue;
+ disable();
+ current = (strcmp(args[1], "init") == 0)? io_init_queue : ready_queue_locked;
+ enable();
if (current == NULL) {
return;
@@ -357,128 +364,6 @@ void cmd_show(char *args[]) { } while (current != NULL);
}
-void cmd_allocate(char *args[]) {
- pcb * new;
- int result;
- int type, state, suspend, priority;
- pcb * exists;
-
- if (!args[1] || !args[2] || !args[3] || !args[4] || !args[5]) {
- printf("Error: Please use the correct number of arguments. \n");
- return;
- }
-
- if (strcmp(args[2], "f") != 0 &&
- strcmp(args[2], "a") != 0 &&
- strcmp(args[2], "s") != 0) {
- printf("Error: PCB type must be f(ree), a(pplication) or s(ystem). \n");
- printf("You said: %s \n", args[2]);
- return;
- }
-
- if (strcmp(args[3], "r") != 0 &&
- strcmp(args[3], "o") != 0 &&
- strcmp(args[3], "b") != 0) {
- printf("Error: PCB state must be r(eady), o(running), or b(locked). \n");
- printf("You said: %s \n", args[3]);
- return;
- }
-
- if (strcmp(args[4], "y") != 0 &&
- strcmp(args[4], "n") != 0) {
- printf("Error: PCB suspended flag must be y(es) or n(o). \n");
- printf("You said: %s \n", args[4]);
- return;
- }
-
- priority = atoi(args[5]);
-
- exists = search_pcb(pcb_list, args[1]);
-
- if(exists != NULL){
- printf("Error: A pcb with that name already esists. \n");
- return;
- }
-
- new = get_pcb(pcb_list);
-
- type = FREE;
- if (strcmp(args[2], "a") == 0) {
- type = APP_PROCESS;
- } else if (strcmp(args[2], "s") == 0) {
- type = SYS_PROCESS;
- }
-
- state = READY;
- if (strcmp(args[3], "o") == 0) {
- state = RUNNING;
- } else if (strcmp(args[3], "b") == 0) {
- state = BLOCKED;
- }
-
- suspend = NOT_SUSPENDED;
- if (strcmp(args[4], "y") == 0) {
- suspend = SUSPENDED;
- }
-
- if (type == APP_PROCESS && (priority < -126 || priority > 126)) {
- printf("Error: The priority for an application process must be \n");
- printf("between -126 and 126, inclusive. \n");
- return;
- }
-
- if (type == SYS_PROCESS && (priority < -128 || priority > 127)) {
- printf("Error: The priority for a system process must be \n");
- printf("between -128 and 127, inclusive. \n");
- return;
- }
-
- result = build_pcb(new, args[1], type, state, suspend, priority,
- NULL, NULL, NULL, NULL);
-
- switch (result) {
- case 1: break;
-
- case -1: printf("Error: There was no space for another pcb. \n");
- break;
-
- case -2: printf("Error: Invalid type \n");
- break;
-
- case -3: printf("Error: Invalid state \n");
- break;
-
- case -4: printf("Error: Invalid suspend \n");
- break;
- }
-
- //put the pcb in a queue
- if (state == READY) {
- insert_pcb(&ready_queue, new, 0); //insert in priority order
- } else if (state == BLOCKED) {
- insert_pcb(&io_init_queue, new, 1); //insert at end of queue
- }
-
- return;
-}
-
-void cmd_free(char *args[]) {
- pcb * to_free = search_pcb(pcb_list, args[1]);
- int result;
-
- if (to_free->state == READY) {
- remove_pcb(&ready_queue, to_free);
- } else if(to_free->state == BLOCKED) {
- remove_pcb(&io_init_queue, to_free);
- }
-
- result = free_pcb(pcb_list, to_free);
- switch (result) {
- case -1: printf("Error: Couldn't find PCB\n"); break;
- case -2: printf("Error: PCB already free\n"); break;
- }
-}
-
/**
* Load
*/
@@ -491,6 +376,11 @@ void cmd_load(char *args[]) { // figure out how many directory entries
int num = directory(direct, DIR_SIZE);
+ if (num < 1) {
+ printf("Error: no programs available to load. \n");
+ return;
+ }
+
// search in the directory for the specified program
i = 0;
while (stricmp(direct[i].dirnam, name) != 0) {
@@ -541,8 +431,9 @@ void cmd_load(char *args[]) { printf("Error: Unable to build PCB. \n");
return;
}
-
- insert_pcb(&ready_queue, p, 0);
+ disable();
+ insert_pcb(&ready_queue_locked, p, 0);
+ enable();
return;
}
@@ -625,11 +516,13 @@ void cmd_terminate(char *args[]) { do {
if (p->type == APP_PROCESS) {
// remove from queue as needed
+ disable();
if (p->state == READY) {
- remove_pcb(&ready_queue, p);
+ remove_pcb(&ready_queue_locked, p);
} else if (p->state == BLOCKED) {
remove_pcb(&io_init_queue, p);
}
+ enable();
// free it
freemem(p->loadaddr);
@@ -643,12 +536,14 @@ void cmd_terminate(char *args[]) { if (p != NULL && p->type == APP_PROCESS) {
+ disable();
// remove from queue as needed
if (p->state == READY) {
- remove_pcb(&ready_queue, p);
+ remove_pcb(&ready_queue_locked, p);
} else if (p->state == BLOCKED) {
remove_pcb(&io_init_queue, p);
}
+ enable();
// free it
freemem(p->loadaddr);
@@ -674,9 +569,11 @@ void cmd_setpri(char *args[]) { if (p != NULL) {
// Check the priority is valid
if (p->type == APP_PROCESS && new_priority >= -128 && new_priority <= 127) {
- remove_pcb(&ready_queue, p); // Take pcb out of ready queue
+ disable();
+ remove_pcb(&ready_queue_locked, p); // Take pcb out of ready queue
p->priority = new_priority; // Change priority
- insert_pcb(&ready_queue, p, 0); // Re-insert pcb in ready queue
+ insert_pcb(&ready_queue_locked, p, 0); // Re-insert pcb in ready queue
+ enable();
} else {
printf("Error: invalid priority. \n");
}
@@ -685,23 +582,6 @@ void cmd_setpri(char *args[]) { }
}
-/**
- * Dispatch
- */
-void cmd_dispatch() {
- // set up a pointer to the ready queue
- pcb dummy;
- cop = &dummy;
- cop -> next = ready_queue;
-
- // save the stack pointer so we can return here
- sp_save = _SP - 24;
-
- // call sys_sppt's dispatch
- dispatch();
- return;
-}
-
/*
* stop, start, set, or show the clock based on args[1]
*/
@@ -0,0 +1,192 @@ +/*
+ * IO functionality
+ * for MPX-OS
+ * Ben Burwell & Averill Morash
+ * CSI350 - Fall 2013
+ */
+
+#include <dos.h>
+#include <stdio.h>
+#include "mpx.h"
+
+#define DS_OFFSET 6 // was 3 before
+
+int count = 0;
+void IO_sup(pcb *p) {
+ char far *buffer;
+ int far *length;
+ unsigned *ds_add;
+ int con_w = 0;
+ int rc;
+
+ disable();
+
+ if (DEBUG_PRINTS) { printf("in io_sup \n");}
+
+ //make the far pointers (see page 107)
+ ds_add = p->stack_ptr + DS_OFFSET;
+ buffer = MK_FP(*ds_add, p->parm_add->buffer);
+ length = MK_FP(*ds_add, p->parm_add->length);
+
+ //call com_read or equivalent
+ switch (p->parm_add->op_number){
+ case COM:
+ // IO_sched should have validated input
+ // Assume that op_type is either read or write
+ if (p->parm_add->op_type == READ) {
+ if (DEBUG_PRINTS){printf("com read req \n");}
+ com_eflag = 0;
+ rc = com_read(buffer, length);
+ } else {
+ if (DEBUG_PRINTS) {printf("com write req \n");}
+ com_eflag = 0;
+ rc = com_write(buffer, length);
+ }
+ break;
+ case CON:
+ if (p->parm_add->op_type == READ) {
+ if (DEBUG_PRINTS){printf("con read req\n");}
+ con_eflag = 0;
+ con.current_op = READ_OP;
+ rc = con_read(buffer, length);
+ } else {
+ if (DEBUG_PRINTS){printf("con_write req\n");}
+ con_w = 1;
+ rc = con_write(buffer, length);
+ }
+ break;
+ case PRT:
+ if (DEBUG_PRINTS){printf("prt write req\n");}
+ prt_eflag = 0;
+ rc = prt_write(buffer, length);
+ break;
+ }
+
+ if (rc < 0) {
+ printf("Somthing went wrong in io_sup\n");
+ }
+
+ // put the pcb back in the ready queue, if it was a con_write
+ if (con_w == 1) {
+ insert_pcb(&ready_queue_locked, p,0);
+ }
+ enable();
+ return;
+}
+
+// Handle completion of an IO request
+int IO_complete(int device, int *stk_ptr) {
+
+ pcb *current;
+ dcb *d;
+
+ disable();
+ switch (device){
+ case CON:
+ d = &con;
+ d->current_op = NO_OP;
+ break;
+ case COM:
+ d = &com;
+ break;
+ case PRT:
+ d = &prt;
+ break;
+ }
+
+ if (DEBUG_PRINTS){printf("in io complete\n");}
+
+ // save interrupted process's stack pointer
+ cop->stack_ptr = stk_ptr;
+
+ // insert running process into ready queue
+ insert_pcb(&ready_queue_locked, cop, 0);
+
+ // set running process to ready state
+ cop->state = READY;
+
+ // get address of PCB whose IO just completed
+ current = d->current_pcb;
+
+ // insert into ready queue
+ insert_pcb(&ready_queue_locked, current, 0);
+
+ // set its state to ready
+ current->state = READY;
+
+ if (strcmp(d->current_pcb->name, "iocom2")==0) {
+ count++;
+ if (count > 20) {
+ d = &com;
+ }
+ }
+ if (d->pcb_head != NULL) {
+ // if there are pending IO requests for this device
+ //schedule them (IO_sched)
+ remove_pcb(&(d->pcb_head), d->pcb_head);
+ IO_sched(d->pcb_head);
+ }
+
+ outportb(0x20,0x20); // EOI signal
+ enable();
+ dispatch();
+
+ return 0;
+}
+
+// Service an IO request
+// Returns:
+// 0 for success
+// -1 for invalid operation
+// -2 for invalid device
+int IO_sched(pcb *p) {
+
+ dcb *d;
+ int op_num;
+ int op_type;
+
+ if (DEBUG_PRINTS) {printf("in io sched\n");}
+
+ // determine which device is requested
+ op_num = p->parm_add->op_number;
+ op_type = p->parm_add->op_type;
+
+ switch (op_num) {
+ case CON:
+ if (op_type != READ
+ && op_type != WRITE) {
+ return -1;
+ }
+ d = &con;
+ break;
+ case COM:
+ if (op_type != READ
+ && op_type != WRITE) {
+ return -1;
+ }
+ d = &com;
+ break;
+ case PRT:
+ if (op_type != WRITE) {
+ return -1;
+ }
+ d = &prt;
+ break;
+ default:
+ return -2;
+ }
+
+ if (d->current_op != NO_OP) {
+ disable();
+ // put pcb in IO queue
+ insert_pcb(&(d->pcb_head), p, 1);
+ // take pcb out of ready q
+ remove_pcb(&ready_queue_locked, p);
+ enable();
+ } else {
+ d->current_pcb = p;
+ IO_sup(p);
+ }
+
+ return 0;
+}
@@ -6,10 +6,11 @@ */
#include <stdio.h>
+#include <dos.h>
#include "mpx.h"
pcb * pcb_list;
-pcb * ready_queue;
+pcb * ready_queue_locked;
pcb * io_init_queue;
pcb * cop;
@@ -26,12 +27,30 @@ pcb pcb9; pcb pcb10;
pcb pcb11;
+dcb com;
+dcb prt;
+dcb con;
+int com_eflag;
+int con_eflag;
+int prt_eflag;
+
unsigned sys_stack[STACK_SIZE];
int main(void) {
pcb * pcb_addr;
+ int rc;
+ dcb * d = &con;//test
+ char *args[] = {"load", "idle"};
+
printf("Booting MPX... \n");
- /* Put initialization code here */
+
+ sys_init();
+
+ if (DEBUG_PRINTS) printf("did init \n");
+
+ d->event_flag = &con_eflag;
+
+ if (DEBUG_PRINTS) printf("making chain \n");
// create the chain
pcb0.chain = &pcb1;
@@ -47,6 +66,8 @@ int main(void) { pcb10.chain = &pcb11;
pcb11.chain = NULL;
+ if (DEBUG_PRINTS) printf("building pcbs \n");
+
build_pcb(&pcb0, " ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
build_pcb(&pcb1, " ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
build_pcb(&pcb2, " ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
@@ -65,8 +86,40 @@ int main(void) { // initialize the currently running process
cop = NULL;
- sys_init();
- comhan(); /* Execute the command handler */
+ // set up command handler as a PCB
+ pcb_addr = get_pcb(pcb_list);
+ rc = build_pcb(pcb_addr, "ComHan", SYS_PROCESS, READY, NOT_SUSPENDED, 127, _CS,
+ (unsigned)comhan, _DS, 0x200);
+
+ disable();
+ insert_pcb(&ready_queue_locked, pcb_addr, 0);
+ enable();
+
+ if (DEBUG_PRINTS) printf("comhan in queue \n");
+
+
+ // set up idle process
+ cmd_load(args);
+
+ if (DEBUG_PRINTS) printf("loaded \n");
+
+ // update priority for idle process
+ // we can't do this when initially calling because of
+ // APP_PROCESS type priority validation
+ pcb_addr = search_pcb(&pcb_list, "idle");
+ pcb_addr->priority = -128;
+ pcb_addr->suspend = NOT_SUSPENDED;
+ pcb_addr->type = SYS_PROCESS;
+
+ if (DEBUG_PRINTS) printf("pri set \n");
+
+ // ALREADY IN QUEUE THANKS TO CMD_LOAD
+ //insert_pcb(&ready_queue, pcb_addr, 0);
+
+ if (DEBUG_PRINTS) printf("idle in queue \n");
+
+ dispatch();
+
sys_exit();
return 0;
@@ -14,6 +14,8 @@ #define PRT 2 /* The printer device - LPT1. */
#define COM 3 /* The serial port - COM1. */
+#define DEBUG_PRINTS 0 // 1 for print out debugging statements
+
/* MPX System request types. */
#define READ 0 /* Read from device. */
@@ -32,6 +34,17 @@ struct dirstruct { /* Data type for a directory entry. */ typedef struct dirstruct dir; /* Use dir as the data typer name. */
/**
+ * parm is a struct to keep track of parameters passed to sys_req
+ */
+struct parmstruct {
+ int op_number;
+ int op_type;
+ char *buffer;
+ int *length;
+};
+typedef struct parmstruct parm;
+
+/**
* PCB
*/
@@ -43,7 +56,7 @@ typedef struct dirstruct dir; /* Use dir as the data typer name. */ #define BLOCKED 2
#define NOT_SUSPENDED 0
#define SUSPENDED 1
-#define STACK_SIZE 400
+#define STACK_SIZE 900
struct pcbstruct {
struct pcbstruct * chain;
@@ -57,7 +70,7 @@ struct pcbstruct { unsigned stack_ptr;
unsigned stack[STACK_SIZE];
unsigned loadaddr;
- unsigned parm_add; // added during mod because sys_call said so
+ parm *parm_add;
int mem_size;
};
typedef struct pcbstruct pcb;
@@ -86,6 +99,8 @@ typedef struct pcbstruct pcb; struct dcb_struct {
unsigned current_op;
unsigned * event_flag;
+ pcb * current_pcb;
+ pcb * pcb_head;
far int * length;
far char * buffer;
int count;
@@ -115,8 +130,8 @@ void cmd_help(char *[]); void cmd_prompt(char *[]);
void cmd_alias(char *[]);
void cmd_show(char *[]);
-void cmd_allocate(char *[]);
-void cmd_free(char *[]);
+//void cmd_allocate(char *[]);
+//void cmd_free(char *[]);
void cmd_load(char *[]);
void cmd_resume(char *[]);
@@ -124,7 +139,7 @@ void cmd_run(char *[]); void cmd_suspend(char *[]);
void cmd_terminate(char *[]);
void cmd_setpri(char *[]);
-void cmd_dispatch();
+//void cmd_dispatch();
void cmd_clock(char *[]);
void sys_req(int,int,char *,int *); /* MPX system request function. */
@@ -187,10 +202,15 @@ int com_write_int(); #define PDR 0x3bc
int prt_open(int *);
-int prt_write(char far *, int *);
+int prt_write(char far *, int far *);
int prt_close(void);
void interrupt prt_int(void);
+
+int IO_complete(int, int*);
+int IO_sched(pcb *);
+void IO_sup(pcb *);
+
/*
* Global variable EXTERN directives.
*
@@ -201,11 +221,16 @@ void interrupt prt_int(void); */
#define DIR_SIZE 20
extern dcb com;
+extern dcb prt;
+extern dcb con;
extern dir direct[]; /* Array of directory entries - see direct.c */
extern int directory(dir *direct, int dir_size);
extern pcb * pcb_list;
-extern pcb * ready_queue;
+extern pcb * ready_queue_locked;
extern pcb * io_init_queue;
extern pcb * cop; /* The currently operating process. */
extern unsigned sys_stack[];
-extern unsigned sp_save; /* So that mod 4 can return to cmd_dispatch */
\ No newline at end of file +extern unsigned sp_save; /* So that mod 4 can return to cmd_dispatch */
+extern int prt_eflag;
+extern int con_eflag;
+extern int com_eflag;
@@ -1,6 +1,7 @@ #include "mpx.h"
#include <string.h>
#include <stdio.h>
+#include <dos.h>
#define STK_PSW (STACK_SIZE - 1)
#define STK_CS (STACK_SIZE - 2)
@@ -125,9 +126,12 @@ int insert_pcb(pcb **queue, pcb * addr, int method) { pcb * current = *queue;
pcb * one_after;
+ disable();
+
// if there's nothing in the queue yet, make the PCB the start
if (current == NULL) {
*queue = addr;
+ enable();
return 1;
}
@@ -143,6 +147,7 @@ int insert_pcb(pcb **queue, pcb * addr, int method) { current->next = addr;
addr->next = NULL;
addr->prev = current;
+ enable();
return 1;
} else if (method == 0) {
// insert in priority order
@@ -171,8 +176,10 @@ int insert_pcb(pcb **queue, pcb * addr, int method) { addr->next = current;
*queue = addr;
}
+ enable();
return 1;
} else {
+ enable();
// There was a problem, return error code
return -1;
}
@@ -184,11 +191,13 @@ int insert_pcb(pcb **queue, pcb * addr, int method) { int remove_pcb(pcb **queue, pcb * addr) {
pcb * current = *queue;
+ disable();
// are we removing the head?
if (addr == *queue) {
*queue = addr->next;
if (addr->next != NULL) {
(addr->next)->prev = NULL;
+ addr->next = NULL;
}
return 0;
}
@@ -206,5 +215,6 @@ int remove_pcb(pcb **queue, pcb * addr) { }
current = current->next;
} while (current != NULL);
+ enable();
return -1;
}
@@ -10,7 +10,6 @@ #include "mpx.h";
void interrupt (*vect0f)();
-dcb prt;
int prt_opened;
@@ -48,7 +47,7 @@ int prt_open(int * prt_flag) { return 0;
}
-int prt_write(char far *buffer, int *length) {
+int prt_write(char far *buffer, int far *length) {
unsigned char pcr;
disable();
@@ -133,7 +132,7 @@ void interrupt prt_int() { // call io-complete
// TODO: the book says (pg 86) that there should be stuff passed to io-complete
- IO_complete(2, lst_stk);
+ IO_complete(PRT, lst_stk);
// send end of interrupt signal
outportb(0x20, 0x20);
diff --git a/proc1.asm b/proc1.asm deleted file mode 100644 index 06aa1d4..0000000 --- a/proc1.asm +++ /dev/null @@ -1,62 +0,0 @@ -;*************************************************************************
-;
-; MPX-PC Test Process
-; Name: PROC1
-; Description: Test process
-; Module: 4
-;
-;************************************************************************
-
-
- CON EQU 01H
- PRT EQU 02H
- WRITE EQU 01H
-
- CR EQU 0DH
- LF EQU 0AH
-
- STACK SEGMENT STACK
- DB 32 DUP ('STACK ') ; 256 BYTES
- STACK ENDS
-
- DATA SEGMENT
- MSG1 DB 'Proc1 dispatched. ',CR,LF,'$'
- LEN DW 20
- DATA ENDS
-
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
-
- MAIN PROC FAR
- START: MOV AX,DATA ; SET UP DATA SEGMENT
- MOV DS,AX
- MOV ES,AX ; SET UP EXTRA SEGMENT
-
- ; Set up stack for dummy sys_call
-
- MOV DX,OFFSET LEN
- PUSH DX ; LOAD LENGTH PARM
- MOV DX,OFFSET MSG1
- PUSH DX ; LOAD MESSAGE ADDRESS
- MOV DX,WRITE
- PUSH DX ; LOAD OPERATION TYPE
- MOV DX,PRT
- PUSH DX ; LOAD OPERATION NUMBER
- MOV DX,0AAH
- PUSH DX ; PUSH EXTRA BYTE TO MAINTAIN
- MOV DX,0ABH ; COMPATIBILITY WITH C ROUTINES
- PUSH DX
-
- LOOP: MOV DX,OFFSET MSG1
- MOV AH,09H ; PRINT STRING
- INT 21H
-
- MOV CX,0 ; RUN ONLY ONCE
- INT 60H ; INT TO DISP
- JMP LOOP
-
- MAIN ENDP
- CODE ENDS
- END START
-
-
diff --git a/proc2.asm b/proc2.asm deleted file mode 100644 index 1419a2a..0000000 --- a/proc2.asm +++ /dev/null @@ -1,63 +0,0 @@ -;*************************************************************************
-;
-; MPX-PC Test Process
-; Name: PROC2
-; Description: Test process
-; Module: 4
-;
-;************************************************************************
-
-
- CON EQU 01H
- PRT EQU 02H
- WRITE EQU 01H
-
- CR EQU 0DH
- LF EQU 0AH
-
- STACK SEGMENT STACK
- DB 32 DUP ('STACK ') ; 256 BYTES
- STACK ENDS
-
- DATA SEGMENT
- MSG1 DB 'Proc2 dispatched. ',CR,LF,'$'
- BUF DB 124 dup(?)
- LEN DW 20
- DATA ENDS
-
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
-
- MAIN PROC FAR
- START: MOV AX,DATA ; SET UP DATA SEGMENT
- MOV DS,AX
- MOV ES,AX ; SET UP EXTRA SEGMENT
-
- ; Set up stack for dummy sys_call
-
- MOV DX,OFFSET LEN
- PUSH DX ; LOAD LENGTH PARM
- MOV DX,OFFSET MSG1
- PUSH DX ; LOAD MESSAGE ADDRESS
- MOV DX,WRITE
- PUSH DX ; LOAD OPERATION TYPE
- MOV DX,PRT
- PUSH DX ; LOAD OPERATION NUMBER
- MOV DX,0AAH
- PUSH DX ; PUSH EXTRA BYTE TO MAINTAIN
- MOV DX,0ABH ; COMPATIBILITY WITH C ROUTINES
- PUSH DX
-
- LOOP: MOV DX,OFFSET MSG1
- MOV AH,09H ; PRINT STRING
- INT 21H
-
- MOV CX,0 ; RUN ONLY ONCE
- INT 60H ; INT TO DISP
- JMP LOOP
-
- MAIN ENDP
- CODE ENDS
- END START
-
-
diff --git a/proc3.asm b/proc3.asm deleted file mode 100644 index e47a4bd..0000000 --- a/proc3.asm +++ /dev/null @@ -1,63 +0,0 @@ -;*************************************************************************
-;
-; MPX-PC Test Process
-; Name: PROC3
-; Description: Test process
-; Module: 4
-;
-;************************************************************************
-
-
- CON EQU 01H
- PRT EQU 02H
- WRITE EQU 01H
-
- CR EQU 0DH
- LF EQU 0AH
-
- STACK SEGMENT STACK
- DB 32 DUP ('STACK ') ; 256 BYTES
- STACK ENDS
-
- DATA SEGMENT
- MSG1 DB 'Proc3 dispatched. ',CR,LF,'$'
- BUF DB 70 dup(?)
- LEN DW 20
- DATA ENDS
-
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
-
- MAIN PROC FAR
- START: MOV AX,DATA ; SET UP DATA SEGMENT
- MOV DS,AX
- MOV ES,AX ; SET UP EXTRA SEGMENT
-
- ; Set up stack for dummy sys_call
-
- MOV DX,OFFSET LEN
- PUSH DX ; LOAD LENGTH PARM
- MOV DX,OFFSET MSG1
- PUSH DX ; LOAD MESSAGE ADDRESS
- MOV DX,WRITE
- PUSH DX ; LOAD OPERATION TYPE
- MOV DX,PRT
- PUSH DX ; LOAD OPERATION NUMBER
- MOV DX,0AAH
- PUSH DX ; PUSH EXTRA BYTE TO MAINTAIN
- MOV DX,0ABH ; COMPATIBILITY WITH C ROUTINES
- PUSH DX
-
- LOOP: MOV DX,OFFSET MSG1
- MOV AH,09H ; PRINT STRING
- INT 21H
-
- MOV CX,0 ; RUN ONLY ONCE
- INT 60H ; INT TO DISP
- JMP LOOP
-
- MAIN ENDP
- CODE ENDS
- END START
-
-
diff --git a/proc4.asm b/proc4.asm deleted file mode 100644 index 1043ff9..0000000 --- a/proc4.asm +++ /dev/null @@ -1,63 +0,0 @@ -;*************************************************************************
-;
-; MPX-PC Test Process
-; Name: PROC4
-; Description: Test process
-; Module: 4
-;
-;************************************************************************
-
-
- CON EQU 01H
- PRT EQU 02H
- WRITE EQU 01H
-
- CR EQU 0DH
- LF EQU 0AH
-
- STACK SEGMENT STACK
- DB 32 DUP ('STACK ') ; 256 BYTES
- STACK ENDS
-
- DATA SEGMENT
- MSG1 DB 'Proc4 dispatched. ',CR,LF,'$'
- BUF DB 243 dup(?)
- LEN DW 20
- DATA ENDS
-
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
-
- MAIN PROC FAR
- START: MOV AX,DATA ; SET UP DATA SEGMENT
- MOV DS,AX
- MOV ES,AX ; SET UP EXTRA SEGMENT
-
- ; Set up stack for dummy sys_call
-
- MOV DX,OFFSET LEN
- PUSH DX ; LOAD LENGTH PARM
- MOV DX,OFFSET MSG1
- PUSH DX ; LOAD MESSAGE ADDRESS
- MOV DX,WRITE
- PUSH DX ; LOAD OPERATION TYPE
- MOV DX,PRT
- PUSH DX ; LOAD OPERATION NUMBER
- MOV DX,0AAH
- PUSH DX ; PUSH EXTRA BYTE TO MAINTAIN
- MOV DX,0ABH ; COMPATIBILITY WITH C ROUTINES
- PUSH DX
-
- LOOP: MOV DX,OFFSET MSG1
- MOV AH,09H ; PRINT STRING
- INT 21H
-
- MOV CX,0 ; RUN ONLY ONCE
- INT 60H ; INT TO DISP
- JMP LOOP
-
- MAIN ENDP
- CODE ENDS
- END START
-
-
diff --git a/proc5.asm b/proc5.asm deleted file mode 100644 index e1b09f1..0000000 --- a/proc5.asm +++ /dev/null @@ -1,62 +0,0 @@ -;*************************************************************************
-;
-; MPX-PC Test Process
-; Name: PROC5
-; Description: Test process
-; Module: 4
-;
-;************************************************************************
-
-
- CON EQU 01H
- PRT EQU 02H
- WRITE EQU 01H
-
- CR EQU 0DH
- LF EQU 0AH
-
- STACK SEGMENT STACK
- DB 32 DUP ('STACK ') ; 256 BYTES
- STACK ENDS
-
- DATA SEGMENT
- MSG1 DB 'Proc5 dispatched. ',CR,LF,'$'
- LEN DW 20
- DATA ENDS
-
- CODE SEGMENT
- ASSUME CS:CODE,DS:DATA,ES:DATA,SS:STACK
-
- MAIN PROC FAR
- START: MOV AX,DATA ; SET UP DATA SEGMENT
- MOV DS,AX
- MOV ES,AX ; SET UP EXTRA SEGMENT
-
- ; Set up stack for dummy sys_call
-
- MOV DX,OFFSET LEN
- PUSH DX ; LOAD LENGTH PARM
- MOV DX,OFFSET MSG1
- PUSH DX ; LOAD MESSAGE ADDRESS
- MOV DX,WRITE
- PUSH DX ; LOAD OPERATION TYPE
- MOV DX,PRT
- PUSH DX ; LOAD OPERATION NUMBER
- MOV DX,0AAH
- PUSH DX ; PUSH EXTRA BYTE TO MAINTAIN
- MOV DX,0ABH ; COMPATIBILITY WITH C ROUTINES
- PUSH DX
-
- LOOP: MOV DX,OFFSET MSG1
- MOV AH,09H ; PRINT STRING
- INT 21H
-
- MOV CX,0 ; RUN ONLY ONCE
- INT 60H ; INT TO DISP
- JMP LOOP
-
- MAIN ENDP
- CODE ENDS
- END START
-
-
diff --git a/prtdrtst.c b/prtdrtst.c deleted file mode 100644 index 52de3af..0000000 --- a/prtdrtst.c +++ /dev/null @@ -1,68 +0,0 @@ -/***********************************************************************
-*
-* Name: prtdrtst
-*
-* Purpose: Test program for prtdrive
-*
-* Algorithm: Tests prt_open, prt_write, and prt_close of prtdrive
-*
-**************************************************************************/
-
-#include <stdio.h>
-#include <dos.h>;
-
-int main()
-{
- int e_flag;
- int tmp;
- int rc;
- char buffer[100];
- int length;
- extern int prt_write(char far *buff,int far *len);
-
- /* open printer */
- rc = 1;
- rc = prt_open(&e_flag);
- if ( rc != 0) {
- printf("\nrc(open) = %d",rc);
- exit();
- }
-
- /* prepare test string */
- strcpy(buffer,"This is a test of the printer driver ... 1234567890 ...........\015\012");
- length = 65;
-
- /* print test string 25 times */
- for (tmp = 1; tmp < 26; tmp++) {
- e_flag = 0;
- rc = prt_write(buffer,&length);
- if (rc != 0) {
- printf("\nrc(write) = %d",rc);
- }
-
- /* loop until printer done */
- while (e_flag == 0)
- printf("waiting %d\n",tmp);
- }
-
-
-
- e_flag = 0;
- length = 29;
- rc = prt_write("End of Printer Driver Test\015\012\n",&length);
- if (rc != 0) {
- printf("\nrc(write) = %d",rc);
- }
-
- /* loop until printer done */
- while (e_flag == 0)
- printf("Waiting for Printer test to finish\n");
-
- prt_close();
- return 0;
-}
-
-int IO_complete(int device, int *stkptr)
-{
- return 0;
-}
diff --git a/qtest.c b/qtest.c deleted file mode 100644 index a0e97d0..0000000 --- a/qtest.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <stdio.h>
-#include "mpx.h"
-
-int main() {
- dcb com;
- char c;
-
- dcb_init(&com);
-
- for (c = 'a'; c <= 'z'; c++) {
- dcb_enqueue(&com, c);
- }
-
- for (c = 'a'; c <= 'z' + 2; c++) {
- printf("Dequeueing %c \n", dcb_dequeue(&com));
- }
-
- return 0;
-}
\ No newline at end of file @@ -21,9 +21,6 @@ void interrupt (*vect60)(); /* Storage for DOS int 60h */
/* interrupt vector. */
-void interrupt (*vect08)(); /* Storage for DOS int 08h */
- /* interrupt vector. */
-unsigned long clock; /* The clock counter */
void sys_init()
{
@@ -33,6 +30,15 @@ void sys_init() // set up the clock
clock_open();
+
+ // set up com
+ com_open(&com_eflag, 1200);
+
+ // set up printer
+ prt_open(&prt_eflag);
+
+ // set up con
+ con_open(&con_eflag);
}
@@ -41,38 +47,48 @@ void sys_exit() // restore the clock
clock_close();
+ com_close();
+ con_close();
+ prt_close();
+
/* restore interrupt vector 60 and exit */
setvect(0x60,vect60);
exit();
}
-
+// dispatch the process at the head of the ready queue
void interrupt dispatch()
{
- /* MOD 4 dispatch */
- do {
- cop = cop -> next;
- } while (cop != NULL && cop->suspend == SUSPENDED);
+ disable();
+ if (DEBUG_PRINTS) {printf("in dispatch \n ");}
+ // TODO fix this.. .cop is null when we start
+ cop = ready_queue_locked;
+ // skip over suspended processes
+ while (cop != NULL && cop->suspend == SUSPENDED) {
+ cop = cop -> next;
+ }
+ if (DEBUG_PRINTS){
if (cop == NULL) {
- _SP = sp_save;
+ printf("!!cop null?!!!\n");
} else {
- _SP = cop -> stack_ptr;
+ printf("cop - %s\n", cop->name);
+ }
}
+
+ remove_pcb(&ready_queue_locked, cop);
+ enable();
+ _SP = cop -> stack_ptr;
+
}
void interrupt sys_call()
{
- struct parm {
- int op_number;
- int op_type;
- char *buffer;
- int *length;
- };
+ static parm *parm_add;
- static struct parm *parm_add;
+ if (DEBUG_PRINTS) {printf("in sys_call \n ");}
/* Save stack pointer for current process */
cop->stack_ptr = _SP;
@@ -84,140 +100,20 @@ void interrupt sys_call() somewhere in the pcb as suggested below*/
cop->parm_add = parm_add;
+ _SP = &sys_stack[STACK_SIZE-1];
+
// find out if the process wants to die... and kill it
if (parm_add->op_number == EXIT_CODE) {
- cop->suspend = SUSPENDED;
+ strcpy(cop->name,"averill");
+ //TODO: CHECK IF THE PCB HAS IO PENDING
+ freemem(cop->loadaddr);
+ free_pcb(pcb_list, cop);
+ } else {
+ IO_sched(cop);
}
dispatch();
}
-/*
- * Set up MXP clock
- */
-void clock_open() {
- unsigned char imr;
-
- disable();
- /* set up interrupt vector for timer interrupts */
- vect08 = getvect(0x08);
- setvect(0x08,&clock_int);
-
- // set the timer mode
- outportb(CMR, 0x36);
- outportb(0x40, 0);
- outportb(0x40, 0);
- // set the count clock
- clock = 0L;
- // enable timer interrupts
- imr = inportb(IMR); // Get current IMR
- imr = imr & CLOCK_ENABLE; // Clear timer bit
- outportb(IMR, imr); // Set new IMR
-
- enable();
-}
-
-/*
- * Restore the MS DOS clock
- */
-void clock_close() {
- disable();
- setvect(0x08,vect08);
- enable();
-}
-
-void interrupt clock_int() {
- disable();
- // if it's been 24 hours, reset clock to 0
- if (clock >= 1572462L) {
- clock = 0L;
- } else {
- clock++;
- }
- outportb(0x20, 0x20);
- enable();
-}
-
-void stop_clock() {
- unsigned char imr;
- disable();
-
- imr = inportb(IMR); // Get the old imr
- imr = imr | CLOCK_DISABLE; // Disable timer interrupts
- outportb(IMR, imr); // Set the new imr
-
- enable();
-}
-
-/*
- * Enables the timer interrupt
- */
-void start_clock() {
- unsigned char imr;
- disable();
-
- imr = inportb(IMR); // Get the old imr
- imr = imr & CLOCK_ENABLE; // Enable timer interrupts
- outportb(IMR, imr); // Set the new imr
-
- enable();
-}
-
-/*
- * Sets the value of the clock
- */
-int set_clock(int hr, int m, int s) {
- unsigned long ticks;
-
- // Validate input
- if (hr > 23 || hr < 0 || m > 59 || m < 0 || s > 59 || s < 0) {
- return -1;
- }
-
- // set clock
- ticks = 0L;
- ticks = ((unsigned long)hr * 3600L * 91L / 5L);
- ticks += ((unsigned long)m * 60L * 91L / 5L);
- ticks += ((unsigned long)s * 91L / 5L);
-
- disable();
- clock = ticks;
- enable();
-
- return 0;
-}
-
-/*
- * Gets the value of the clock
- */
-void read_clock(int *hr, int *m, int *s) {
- unsigned long ticks;
- long total_seconds = 0L;
- int l_hr = 0;
- int l_m = 0; //local vars for hr, m
-
- disable();
- ticks = clock;
- enable();
-
- total_seconds = ticks * 10L;
- total_seconds = total_seconds / 182L;
-
- //count the whole hours
- while (total_seconds >= 3600L) {
- l_hr++;
- total_seconds = total_seconds - 3600L;
- }
-
- //count the whole minutes
- while (total_seconds >= 60L) {
- l_m++;
- total_seconds = total_seconds - 60L;
- }
-
- *hr = l_hr;
- *m = l_m;
- *s = total_seconds;
-}
diff --git a/testn.c b/testn.c deleted file mode 100644 index 2d09d82..0000000 --- a/testn.c +++ /dev/null @@ -1,119 +0,0 @@ -/***********************************************************************
-*
-* Name: testn.c
-*
-* Purpose: Provides statically-loaded (via linker) test processes
-* for Round Robin Dispatcher of Module 3.
-*
-* Procedures In Module:
-* test1 - test process
-* test2 - test process
-* test3 - test process
-* test4 - test process
-* test5 - test process
-*
-* Name: Processes test1, test2, test3, test4, and test5.
-*
-* Algorithm: Each process prints a message to the screen and gives up
-* control to the dispatcher using sys_req. Each process
-* loops a certain number of times, displaying a message to
-* the screen inside the loop. (test1 loops 5 times, test2
-* loops 10, test3 loops 15, test4 loops 20, and test5 loops
-* 25 times). Each test process eventually requests
-* termination. If a dispatcher dispatches a test process
-* after it requested termination, it prints a message
-* indicating so, and the process starts over.
-*
-*****************************************************************************/
-
-#include <dos.h>
-#include "mpx.h"
-
-#define op 1 /* dummy operation request code */
-#define type 1 /* dummy operation type */
-
-void test1(void)
-{
- char buffer[8];
- int len;
- int i;
-
- while (1) {
- for (i=1; i <= 5; i++) {
- printf("\ntest1 dispatched; Value of i = %d",i);
- /* give up control to the dispatcher */
- sys_req(op,type,buffer,&len);
- }
- sys_req(EXIT_CODE,0,buffer,&len);
- printf ("\ntest1 dispatched after it exited!!!");
- }
-}
-
-
-void test2(void)
-{
- char buffer[8];
- int len;
- int i;
-
- while (1) {
- for (i=1; i <= 10; i++) {
- printf("\ntest2 dispatched; Value of i = %d",i);
- /* give up control to the dispatcher */
- sys_req(op,type,buffer,&len);
- }
- sys_req(EXIT_CODE,0,buffer,&len);
- printf ("\ntest1 dispatched after it exited!!!");
- }
-}
-
-void test3(void)
-{
- char buffer[8];
- int len;
- int i;
- while (1) {
- for (i=1; i <= 15; i++) {
- printf("\ntest3 dispatched; Value of i = %d",i);
- /* give up control to the dispatcher */
- sys_req(op,type,buffer,&len);
- }
- sys_req(EXIT_CODE,0,buffer,&len);
- printf ("\ntest3 dispatched after it exited!!!");
- }
-}
-
-void test4(void)
-{
- char buffer[8];
- int len;
- int i;
-
- while (1) {
- for (i=1; i <= 20; i++) {
- printf("\ntest4 dispatched; Value of i = %d",i);
- /* give up control to the dispatcher */
- sys_req(op,type,buffer,&len);
- }
- sys_req(EXIT_CODE,0,buffer,&len);
- printf ("\ntest4 dispatched after it exited!!!");
- }
-}
-
-void test5(void)
-{
- char buffer[8];
- int len;
- int i;
-
- while (1) {
- for (i=1; i <= 25; i++) {
- printf("\ntest5 dispatched; Value of i = %d",i);
- /* give up control to the dispatcher */
- sys_req(op,type,buffer,&len);
- }
- sys_req(EXIT_CODE,0,buffer,&len);
- printf ("\ntest5 dispatched after it exited!!!");
- }
-}
-
|