The test programs for a Nachos kernel are C programs that compile into executables for the MIPS R2000 architecture. These executable programs run on a simulated MIPS machine using the SPIM machine simulator linked with your nachos executable. In effect, your nachos reads the test program executables as data and interprets them, simulating their execution on a real MIPS processor running your Nachos kernel.
Because the user programs are compiled for the MIPS architecture, they will not run directly on the SPARC CPU that you run Nachos on. In fact, since they use Nachos system calls rather than Unix system calls, they cannot even execute correctly on a real MIPS CPU running an operating system such as IRIX or DEC Ultrix. They are built specifically to execute under Nachos. The bizarre nature of these executables introduces some special considerations for building them.
The Makefile in the test directory takes care of all the details of producing the Nachos user program executables. The user programs are compiled using a gcc cross-compiler that runs on Solaris/SPARC but generates code for the MIPS processor. The compiled code is then linked with the MIPS assembly language routines in start.s. (Look at these routines and be sure your understand what they do.) Finally, the programs are converted into a MIPS executable file format called NOFF, using the program coff2noff (supplied).
To run the test programs, you must first build a Nachos kernel that supports user-mode programs. The raw Nachos release has skeletal support for running a single user program at a time; you will extend Nachos to support multiprogramming, virtual memory, and file system calls during the course of the semester. To build a Nachos kernel that can run user programs, edit your Nachos makefile to uncomment the ``cd userprog'' lines, then run gmake to build a new Nachos executable within the userprog directory. You may then use this kernel to execute a user program using the nachos -x option. The argument to -x is the name of the test program executable, produced as described above.
The Nachos distribution includes several sample test programs. For example, look at test/halt.c, which simply asks the operating system to shut the ``machine'' down using the Nachos Halt system call. Run the halt program with the command nachos -x halt, or nachos -x ../test/halt. It may be useful to trace the execution of the halt program using the debug flag. The test directory includes other simple user programs to test your kernels in the later assignments. For these assignments you are also expected to extend these tests and add some of your own.
Some students have difficulty building new test programs. The following guidelines will help you avoid trouble.