1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/***********************************************************************
*
* Name: sys_sppt.c
*
* Purpose: Support Routines for Modules 3 and 4 of MPX-PC
*
* Sample Call:
* sys_init()
* sys_exit()
*
* Procedures In Module:
* sys_init - Sets up interrupt vector 60 for MPX-PC
* sys_exit - Resets interrupt vector 60 and exits to DOS
*
*
****************************************************************************/
#include <stdio.h>
#include <dos.h>
#include "mpx.h"
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()
{
/* set up interrupt vector for MPX sys_calls */
vect60 = getvect(0x60);
setvect(0x60,&sys_call);
// set up the clock
clock_open();
}
void sys_exit()
{
// restore the clock
clock_close();
/* restore interrupt vector 60 and exit */
setvect(0x60,vect60);
exit();
}
void interrupt dispatch()
{
/* MOD 4 dispatch */
do {
cop = cop -> next;
} while (cop != NULL && cop->suspend == SUSPENDED);
if (cop == NULL) {
_SP = sp_save;
} else {
_SP = cop -> stack_ptr;
}
}
void interrupt sys_call()
{
struct parm {
int op_number;
int op_type;
char *buffer;
int *length;
};
static struct parm *parm_add;
/* Save stack pointer for current process */
cop->stack_ptr = _SP;
/* Get address of sys_call parameters */
parm_add = _SP + 0x1c; // parameter offset = 0x1C
/* Note that you should save this parameter address
somewhere in the pcb as suggested below*/
cop->parm_add = parm_add;
// find out if the process wants to die... and kill it
if (parm_add->op_number == EXIT_CODE) {
cop->suspend = SUSPENDED;
}
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;
}
|