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.
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.
- Go into the bin directory and make coff2noff.
- Go into the test directory and:
- Write a program which calls Exec() and Halt(). Exec() should pass a
string. (Actually, a pointer to a string.)
- Edit Makefile, cloning an entry for your program from the entry for
halt.
- Make your program.
- Go into the userprog directory and:
- Open exception.cc for editing.
- 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.
- The if condition for Exec should be quite similar to that of Halt.
- Sketch of what the Exec handler should do:
- Read the register in which the string pointer was passed. What
register number?
- Print the string (don't forget to perform the necessary address
translation).
- Increment the three PC-related registers. (Read a register,
update the value and write-back the new value.)
- Make nachos. Cheese optional. (At Westminster, I had a machine
named cheese!)
- Use nachos to run your program. For example:
./nachos -x ../test/foo
Was the string printed? Did nachos halt properly?
- Edit and make your program to pass a different string and re-run
nachos (without re-making). Was the new string printed?
- 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:
- Can this executable run directly on the underlying Intel hardware?
- What will happen if this program has "real" I/O in it? (E.g., a call
to printf().)
- How did nachos get your program running?
- How did your program get nachos to print that string?
Thomas P. Kelliher
Wed Mar 25 10:10:16 EST 1998
Tom Kelliher