Installing NACHOS 4.0


Follow these steps to install NACHOS in your home directory in penguin.

1. Go to the directory you want to install NACHOS in (use the pwd command in order to check that you are in the right directory).

2. Copy the NACHOS source code from directory /u1/cs3mh3/group/nachos-4.02 to your directory using the command

cp -r /u1/cs3mh3/group/nachos-4.02 .

3. Go to the code/test directory inside your nachos-4.02 directory. The test directory contains test user programs written in C, and you can add your own test programs here. Read the Makefile in order to see how you'll be compiling new programs. For now, just use make to compile the already existing ones. General note:  In all the Makefiles you'll be using there is the option of first cleaning-up all existing precompiled files, so that everything will be compiled from scratch. To do that just type make distclean and afterwards you can go ahead with your compilation (using make).

4. The source code for the NACHOS program itself lives in several directories: code/lib, code/machine, code/threads, code/filesys, code/userprog, and code/network. The program is built using the Makefile in one of the "build" directories. In our case (penguin) you will need to build the Linux version. Hence, go to the code/build.linux directory and issue the following commands:

make distclean      (it will clean-up any precompiled files)
make depend      
make

Since your assignments will be changing the NACHOS code itself, you are going to be constantly recompiling the source code. Read the Makefile carefully. It explains how to build the nachos program.

5. If all has gone well, you now have the ./nachos executable in the code/build.linux directory. You may want to include this directory in your PATH variable.

Running Nachos

Once you have built nachos, you should be able to run it by simply typing

    ./nachos

in the code/build.linux directory. The command line argument -u will give you a list of the available command line options. Using these options, you can control what nachos does when it runs. For starters, you may wish to try the -K and -C flags, which run some simple self-tests. You can also try asking Nachos to run a very simple test program called halt, which is found in the code/test directory. To try this, type

    ./nachos -d ca -x ../test/halt

The -d ca turns on the address space (a) and system call (c) related debugging output. The halt program simply makes the "Halt" system call, which causes the machine simulator to halt and print out some statistics. Have a look at the halt program. It is in code/test/halt.c

For more details, you can look in the file code/threads/main.cc. In fact, this is the best place to start reading the Nachos code, since this is where it all begins.

Nachos Directory Structure

The main nachos directory contains three sub-directories:

coff2noff/
    The source code and Makefiles for coff2noff.x86Linux, which is a program for converting COFF (Common Object File Format) files to NOFF (Nachos Object File Format) files. Note that noff.h in this directory is a link to the file noff.h in code/userprog.

c++-example/
    The Nachos operating system is written in a subset of C++. This directory contains an excellent primer on C++. This primer is good reading for those who need a refresher, and even for those of you who are experienced C++ programmers. In particular, it explains why some of the "features" of C++ are not used at all in Nachos.

code/
    All of the source code for the Nachos operating system, the machine simulation, and the test programs can be found here. This code is organized into several sub-directories:

    lib/
        utilities used by the rest of the Nachos code

    machine/
        The machine simulation. Except as noted in machine.h, you may not modify the code in this directory.

    threads/
        Nachos is a multi-threaded program. Thread support is found here. This directory also contains the main() routine of the nachos program, in main.cc.

    userprog/
        Nachos operating system code to support the creation of address spaces, loading of user (test) programs, and execution of test programs on the simulated machine. The exception handling code is here, in exception.cc.

    filesys/
        Two different file system implementations are here. The "real" file system uses the simulated workstation's simulated disk to hold files. A "stub" file system translates Nachos file system calls into UNIX file system calls. This is useful initially, so that files can be used (e.g., to hold user programs) before you have had a chance to fix up the "real" file system. By default, the "stub" file system is build into the nachos program and the "real" file system is not. This can be changed by setting a flag in the Nachos makefile.

    network/
        Nachos operating system support for networking, which implements a simple "post office" facility. Several independent simulated Nachos machines can talk to each other through a simulated network. Unix sockets are used to simulate network connections among the machines.
 
    test/
        User test programs to run on the simulated machine. As indicated earlier, these are separate from the source for the Nachos operating system and workstation simulation. This directory contains its own Makefile. The test programs are very simple and are written in C rather than C++.