|
| 1 | + |
| 2 | +typedef int BOOL; |
| 3 | +#define TRUE 1 |
| 4 | +#define FALSE 0 |
| 5 | + |
| 6 | +/* A PID is just an int */ |
| 7 | + |
| 8 | +typedef int PID_type; |
| 9 | + |
| 10 | +/* This is the variable (e.g. a special register) containing |
| 11 | + the PID of the process that is currently running */ |
| 12 | + |
| 13 | +extern PID_type current_pid; |
| 14 | + |
| 15 | + |
| 16 | +/* This defines the maximum number of processes that can |
| 17 | + be supported on this machine */ |
| 18 | + |
| 19 | +#define MAX_NUMBER_OF_PROCESSES 20 |
| 20 | + |
| 21 | +/* When there is no process ready to run, the current_pid |
| 22 | + should be set to the pid of the "idle process", |
| 23 | + i.e IDLE_PROCESS (with a pid of -1). */ |
| 24 | + |
| 25 | +#define IDLE_PROCESS -1 |
| 26 | + |
| 27 | + |
| 28 | +/* Time is kept as an unsigned int, in units of |
| 29 | + milliseconds */ |
| 30 | + |
| 31 | +typedef unsigned int CLOCK_TIME; /* time in ms */ |
| 32 | + |
| 33 | + |
| 34 | +/* These are the machine's registers that are used |
| 35 | + to store information about trap or interrupt |
| 36 | + that has occurred (see below). */ |
| 37 | + |
| 38 | +extern int R1, R2, R3, R4; /* registers for holding |
| 39 | + trap or interrupt info */ |
| 40 | + |
| 41 | + |
| 42 | +/* This is the clock holding the current time (in ms). |
| 43 | + Only the hardware can change the value of it, do |
| 44 | + not write to it! */ |
| 45 | + |
| 46 | +extern CLOCK_TIME clock; /* system clock in ms */ |
| 47 | + |
| 48 | +/* A clock interrupt is generated by the hardware every 10 ms. |
| 49 | + Note that this may be shorter than the quantum given to |
| 50 | + each process. */ |
| 51 | + |
| 52 | +#define CLOCK_INTERRUPT_PERIOD 10 |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +/* These are the interrupt numbers for various different interrupts (including |
| 57 | + a trap). IMPORTANT: An interrupt number corresponds to the element in the |
| 58 | + INTERRUPT_TABLE containing a pointer to the interrupt handler */ |
| 59 | + |
| 60 | + |
| 61 | +/* A Trap is interrupt 0. Note the description below about the state of |
| 62 | + the registers when a trap occurs, in order to determine why the trap |
| 63 | + occurred (disk read request, keyboard request, etc.) */ |
| 64 | + |
| 65 | +#define TRAP 0 |
| 66 | + |
| 67 | + |
| 68 | +/* The clock interrupt is interrupt 1. */ |
| 69 | + |
| 70 | +#define CLOCK_INTERRUPT 1 |
| 71 | + |
| 72 | + |
| 73 | +/* A disk interrupt, issued by the hardware when a requested disk read |
| 74 | + operation has completed, is interrupt 2. The PID of process that requested the |
| 75 | + disk read is placed in R1 by the hardware */ |
| 76 | + |
| 77 | +#define DISK_INTERRUPT 2 |
| 78 | + |
| 79 | + |
| 80 | +/* A keyboard interrupt, issued by the hardware when a requested keyboard read |
| 81 | + operation has completed, is interrupt 2. The PID of process that requested the |
| 82 | + keyboard read is placed in R1 by the hardware */ |
| 83 | + |
| 84 | +#define KEYBOARD_INTERRUPT 3 /* occurs when requested keyboard buffer is available */ |
| 85 | + |
| 86 | + |
| 87 | +/* The various kinds of TRAPs are listed below. When a trap occurs (via |
| 88 | + interrupt 0, see above) register R1 will contain one of the following |
| 89 | + values. Register R2 will, in some of the cases as described below, |
| 90 | + contain a value as well. */ |
| 91 | + |
| 92 | +#define DISK_READ 0 /* Size of data should be placed in R2 */ |
| 93 | +#define DISK_WRITE 1 /* non-blocking write to disk */ |
| 94 | +#define KEYBOARD_READ 2 /* Blocking read of keyboard buffer */ |
| 95 | +#define FORK_PROGRAM 3 /* PID of new process will be in R2 */ |
| 96 | +#define END_PROGRAM 4 /* PID of ending processing will be in R2 */ |
| 97 | + |
| 98 | + |
| 99 | +/* The interrupt table, INTERRUPT_TABLE, is an array of pointers |
| 100 | + to functions (with no arguments and no return type). For |
| 101 | + example, if the handler for a trap is the function defined by |
| 102 | +
|
| 103 | + void handle_trap() { ... } |
| 104 | +
|
| 105 | + then the appropriate element of the interrupt table can be assigned |
| 106 | + as follows: |
| 107 | +
|
| 108 | + INTERRUPT_TABLE[TRAP] = handle_trap; |
| 109 | +
|
| 110 | + When a trap occurs (due to a system call by the running process), |
| 111 | + the function that INTERRUPT_TABLE[TRAP] points to will automatically |
| 112 | + be called. */ |
| 113 | + |
| 114 | +typedef void (*FN_TYPE)(); |
| 115 | + |
| 116 | +extern FN_TYPE INTERRUPT_TABLE[]; |
| 117 | + |
0 commit comments