1 /*********** MTX Multitasking System ************/
3 /***********************************************************
7 #define NQUEUE NPROC // at most NPROC ready queues
9 #define FREE 0 // proc statuc
15 // For KUmode: PROC added uss,usp at offsets 4,6.
16 // Then, name[32], exitValue.
22 int uss, usp; // at 4, 6
36 int time; // for Umode running time slice
38 int kstack[SSIZE]; // Kmode per process stack
41 **************************************************************/
44 struct rqueue rqueue
[NQUEUE
]; // at most NPROC separate ready queues
46 PROC proc
[NPROC
], *running
, *freeList
, *sleepList
;
48 int procsize
= sizeof(PROC
);
51 int inkmode
= 1; // ADD KUmode transition flag; start in Kmode
54 char *pname
[]={"Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter",
55 "Saturn", "Uranus", "Neptune" };
58 /**********************************************************
64 *********************************************************/
74 printf("MTX initializing ....\n");
76 for (i
=0; i
< NPROC
; i
++){
78 proc
[i
].status
= FREE
;
79 proc
[i
].next
= (PROC
*)&proc
[(i
+1)];
81 strcpy(proc
[i
].name
, pname
[i
]);
83 proc
[NPROC
-1].next
= NULL
;
84 freeList
= &proc
[0]; // all PROC are FREE initially
86 for (i
=0; i
<NQUEUE
; i
++){ // initialize the scheduling queues
87 rqueue
[i
].priority
= i
;
93 p
= getproc(); // get a FREE PROC
96 p
->pri
= 0; /* lowest priority 0 */
97 p
->pid
= 0; /* process 0 or P0 */
99 p
->ppid
= running
->pid
; /* P0's parent is P0 */
102 printf("initialization complete\n");
110 printf("------------------------------------------\n");
111 printf("I am process P%d My parent=%d\n", running
->pid
, running
->ppid
);
113 //color = 0x0001 + running->pid;
114 printf("******************************************\n");
115 printf("freeList = "); printList(freeList
);
118 printf("******************************************\n");
120 printf("input a command : [s|q|f|w|u] : ");
125 case 's' : do_switch(); break;
126 case 'q' : do_exit(100); break; /* no return */
127 case 'f' : do_kfork(); break;
128 case 'w' : do_wait(0); break;
129 case 'u' : goUmode(); break;
138 int set_vec(vector
, addr
) ushort vector
, addr
;
141 location
= vector
<< 2;
142 put_word(addr
, 0, location
);
143 put_word(0x1000,0,location
+2);
148 //*************** main() ***************
153 printf("vid_init : console display driver initialized\n");
155 printf("\nWelcome to the MTX Operating System\n");
161 printf("P0 forks P1\n");
168 printf("P0 switches to P1\n");
174 printf("P0 resumes: all dead, happy ending!\n");
177 //******** scheduler *******************
184 if (running
->status
== READY
)
187 for (i
=NQUEUE
-1; i
>=0; i
--){
188 running
= dequeue(&rqueue
[i
].queue
);
194 color
= 0x09 + running
->pid
;
195 printf("next running=%d time : ", running
->pid
);