Nachos 2, Exercise 1

CS 318

Mar. 27

It would prove fruitful to look through the named files ahead of time. The Exec() handler is pretty simple, but you have to know where to find and how to use the relevant #define constants, machine class methods, and machine class members. It'll be a waste of our class time to be reading other's code.

Summary

You should be able to split up tasks 1--3 and work in parallel on them, bringing each other up to speed once you've finished. Consider task 4 as a group.

  1. Go into the bin directory and make coff2noff.

  2. Go into the test directory and:
    1. Write a program which calls Exec() and Halt(). Exec() should pass a string. (Actually, a pointer to a string.)

    2. Edit Makefile, cloning an entry for your program from the entry for halt.

    3. Make your program.

  3. Go into the userprog directory and:
    1. Open exception.cc for editing.

    2. Find ExceptionHandler(), you're going to add code for the Exec() call. Look in syscall.h for important #define constants. Look in ../machine/machine.h for register names and the methods associated with the machine class.

    3. The if condition for Exec should be quite similar to that of Halt.

    4. Sketch of what the Exec handler should do:
      1. Read the register in which the string pointer was passed. What register number?

      2. Print the string (don't forget to perform the necessary address translation).

      3. Increment the three PC-related registers. (Read a register, update the value and write-back the new value.)

    5. Make nachos. Cheese optional. (At Westminster, I had a machine named cheese!)

    6. Use nachos to run your program. For example:
      ./nachos -x ../test/foo
      
      Was the string printed? Did nachos halt properly?

    7. Edit and make your program to pass a different string and re-run nachos (without re-making). Was the new string printed?

  4. Trace through the Exec call by hand: your program, syscall.h/start.s, exception.cc. How is each step taken? Think about the fact that nachos is using a MIPS simulator to run a program cross-compiled independently of itself. Answer these questions:
    1. Can this executable run directly on the underlying Intel hardware?

    2. What will happen if this program has "real" I/O in it? (E.g., a call to printf().)

    3. How did nachos get your program running?

    4. How did your program get nachos to print that string?



Thomas P. Kelliher
Wed Mar 25 10:10:16 EST 1998
Tom Kelliher