aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 41269bfc23795acaab6064dd30b41cc855579710 (plain)
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
/*  file:  main.c
 *
 *  This file contains the function main
 *  for the MPX Operating System - this is where
 *  the program's execution begins
 */

#include <stdio.h>
#include <dos.h>
#include "mpx.h"

pcb * pcb_list;
pcb * ready_queue_locked;
pcb * io_init_queue;
pcb * cop;

pcb pcb0;
pcb pcb1;
pcb pcb2;
pcb pcb3;
pcb pcb4;
pcb pcb5;
pcb pcb6;
pcb pcb7;
pcb pcb8;
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");

	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;
	pcb1.chain  = &pcb2;
	pcb2.chain  = &pcb3;
	pcb3.chain  = &pcb4;
	pcb4.chain  = &pcb5;
	pcb5.chain  = &pcb6;
	pcb6.chain  = &pcb7;
	pcb7.chain  = &pcb8;
	pcb8.chain  = &pcb9;
	pcb9.chain  = &pcb10;
	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);
	build_pcb(&pcb3,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb4,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb5,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb6,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb7,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb8,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb9,  "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb10, "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);
	build_pcb(&pcb11, "        ", FREE, -1, -1, 0, NULL, NULL, NULL, NULL);

	pcb_list = &pcb0;

	// initialize the currently running process
	cop = NULL;

	// 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;
}