-
Notifications
You must be signed in to change notification settings - Fork 0
/
Init.h
106 lines (85 loc) · 1.53 KB
/
Init.h
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
#define MAX_THREADS 20
#define StackSize(E) (sizeof(E) / sizeof(E[0]))
#define MAX_INTERRUPTS 7
extern int ThreadCount;
extern int ThreadNext;
extern int NextThreadID;
extern int Quanta;
typedef void (*interrupt_handler) ();
typedef long int big;
typedef int op;
enum interrupts
{
intNone = -1,
intTimer,
intIO,
intFatalError,
intInvalidOpcode,
intDivideByZero,
intStackOverflow,
intStackUnderflow
};
enum opcodes
{
opHalt = -9999,
opNop,
opInc,
opDec,
opEmit,
opStartStr,
opPrintStr,
opLoop,
opEndLoop,
opStat
};
enum thread_states
{
BIRTH_STATE,
READY_STATE,
RUNNING_STATE,
DEATH_STATE
};
typedef struct
{
int create_time;
int ready_start_time;
int ready_wait_time;
int num_cpu_bursts;
}
ThreadStat;
typedef struct
{
char *name;
int id;
int state;
op *code;
int ip;
op stack[50];
int sp;
ThreadStat Stat;
}
Thread;
extern Thread *ThreadQueue[MAX_THREADS];
// Global Scope Function
//Supporters
void Raise(char*);
void Message(char*);
//Interrupts
void EnableInterrupt();
void DisableInterrupt();
interrupt_handler SetHandler(int,interrupt_handler);
void SetInterrupt(int);
int GetInterrupt();
//Machine
void MachineInit();
big GetCycle();
void machine();
void ContextSwitching(Thread*);
//Thread
void ThreadInit();
void MakeThreadReady(Thread*);
void RemoveThread(Thread*);
void SwitchToThread(Thread*);
void ThreadDetails();
//Scheduler
void Schedule();