1 /************ t.c file **********************************/
3 #define SSIZE 1024 /* kstack int size */
5 #define DEAD 0 /* proc status */
10 int ksp
; /* saved sp; offset = 2 */
12 int status
; /* READY|DEAD, etc */
13 int kstack
[SSIZE
]; // kmode stack of task
16 #include "io.c" /* <===== use YOUR OWN io.c with printf() ****/
18 PROC proc
[NPROC
], *running
;
20 int procSize
= sizeof(PROC
);
22 /****************************************************************
23 Initialize the proc's as shown:
24 running ---> proc[0] -> proc[1];
26 proc[1] to proc[N-1] form a circular list:
28 proc[1] --> proc[2] ... --> proc[NPROC-1] -->
30 |<---------------------------------------<-
32 Each proc's kstack contains:
33 retPC, ax, bx, cx, dx, bp, si, di, flag; all 2 bytes
34 *****************************************************************/
43 for (i
=0; i
< NPROC
; i
++){
49 if (i
){ // initialize kstack[ ] of proc[1] to proc[N-1]
51 p
->kstack
[SSIZE
- j
] = 0; // all saved registers = 0
52 p
->kstack
[SSIZE
-1]=(int)body
; // called tswitch() from body
53 p
->ksp
= &(p
->kstack
[SSIZE
-9]); // ksp -> kstack top
57 proc
[NPROC
-1].next
= &proc
[1];
58 printf("initialization complete\n");
62 "Oh! You are killing me .......",
63 "Oh! I am dying ...............",
64 "Oh! I am a goner .............",
65 "Bye! Bye! World...............",
69 printf("\n*****************************************\n");
70 printf("Task %d %s\n", running
->pid
,gasp
[(running
->pid
) % 4]);
71 printf("*****************************************\n");
72 running
->status
= DEAD
;
74 tswitch(); /* journey of no return */
81 printf("running = %d\n", running
->pid
);
85 printf("readyProcs = ");
86 while(p
!= running
&& p
->status
==READY
){
87 printf("%d -> ", p
->pid
);
97 printf("I am Proc %d in body()\n", running
->pid
);
98 printf("Input a char : [s|q] ");
101 case 's': tswitch(); break;
102 case 'q': grave(); break;
111 printf("\nWelcome to the 460 Multitasking System\n");
113 printf("P0 switch to P1\n");
115 printf("P0 resumes: all dead, happy ending\n");
124 while (p
->status
!= READY
&& p
!= running
)
132 printf("\n-----------------------------\n");
133 printf("next running proc = %d\n", running
->pid
);
134 printf("-----------------------------\n");