LAB Assignment #3

   
           DUE & DEMO: PRE_WORK: week of 9-14, 2009 
                       LAB#3     week of 9-21, 2009

1. PRE-work: Due: Week of 9-14, 2009 (THIS WEEK)

   Down load files from ~samples/lab3:
        s.s : assembly file, use it AS IS
        t.c : C file for MTX, which calls printf() in YOUR io.c
        io.c: YOUR gets() and printf()
        mk  : sh script for generating MTX kernel : /boot/mtx

   In the mk sh script, 
          ld86 -d s.o t.o mtxlib /usr/lib/bss/lib.c
   uses the GIVEN mxtlib, which contains printf() in io.o for you to 
   generate  /boot/mtx to get started.
 
   But you MUST supply YOUR own io.c containing YOUR printf() to create /boot/mtx.
   Also, use YOUR MTX booter in LAB#1 on the FD for booting up /boot/mtx
 
(1). Write YOUR own printf() as speicified in the class lecture.
     Use your printf() in an io.c file to generate the MTX kernel.

(2). Implement a    pid = kfork();
     function, which creates a CHILD process, put it into the ready queue
     and return its pid. Return -1 if kfork() fails (due to no more FREE
     proc's). Use YOUR kfork() to create P1. 

(3). Finish the enqueue() function, which enters a proc (pointer) into 
     readyqueue by priority (FIFO if same priority).

(4). Add a 'f' command to body(), which creates a CHILD process, puts it
     into ready queue and return its pid (or -1 if failure).

     Demonstrate YOUR 'f' command. (It should be able to create new procs
     in ready queue and 's' should run different procs.
 
----------------------------------------------------------------------------   

2. MAIN WORK OF LAB #3

Modify the MTX system to include the following:

1. sleep(event)/wakeup(event):
   As shown in Notes #4

2. pid = wait(int *status):
   The logic of wait() is explained in Notes #4.
   Implement it in YOUR MTX.

3. kexit(exitValue) int exitValue:
   A process calls kexit(exitValue) to die, in which it
     . become a ZOMBIE; 
     . record the exitValue in its PROC;
     . give away all children to Task1;
     . wakeup its parent;
     . finally, tswitch() to give up CPU.
 
   Also, implement these into kexit():
     Process P1 cannot die if there are other READY tasks.

4. Add the follwoing commands FOR DEMO:
    
    Print the status of ALL tasks, including
          running pid
          freeList 
          sleepList 
  
    w  : pid=wait(int *exitValue); wait for a ZOMBIE child, get its pid and 
                               exitValue, free the ZOMBIE proc;
         Then, print the dead child pid and its last gasp string.

5. LAB3/lab3.bin.gz is a sample solution.