aboutsummaryrefslogtreecommitdiff
path: root/sys_sppt.c
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2015-04-01 20:32:27 -0400
committerBen Burwell <ben@benburwell.com>2015-04-01 20:32:27 -0400
commit684fc27f6389f44102b5a3b31f62badc35a9a9ce (patch)
tree016c28c9b7501475bff2075ba660477e7eec491d /sys_sppt.c
parent2b30f30a330ee9bc9feb9ec4e55c8b6f3e6eb8fe (diff)
as of 2013-12-042013-12-04
Diffstat (limited to 'sys_sppt.c')
-rw-r--r--sys_sppt.c186
1 files changed, 41 insertions, 145 deletions
diff --git a/sys_sppt.c b/sys_sppt.c
index 7facead..c5b784e 100644
--- a/sys_sppt.c
+++ b/sys_sppt.c
@@ -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;
-}