2.3 Cross-compiler Installation

Nachos simulates a machine with a processor that roughly approximates the MIPS architecture. The simulated MIPS processor can execute arbitrary user programs. Nachos has two modes of execution, one of which is the MIPS simulator. The second mode corresponds to the Nachos “kernel”. In MIPS simulator mode, a MIPS cross compiler is required to compile user programs written in C into COFF binary to be executed in Nachos. One can find many user programs in nachos/test directory, which is the default directory to store them.

An instructional machine with MIPS compiler pre-installed will be provided; if you are not using an instructional machine, you must download and install the appropriate cross-compiler from here. Before you start downloading, you need to check the architecture of your system.MAKE SURE you download the correct one as this is crucial. This can be accomplished by typing the command (In Linux and Mac OSX): uname -a. Figure 8 and 8 show the output of uname -a on Linux and Mac OSX respectively.

PIC

Figure 8: Architecture information in Ubuntu

PIC

Figure 9: Architecture information in Mac OSX

The work flow of running user programs in Nachos is depicted in Figure 10.

Implementation note: Since a user program is written in C, one can in fact compile using GCC with minor modifications. To do so, one needs to replace the #include statements with proper header files (e.g, replacing #include "stdio.h" with #include <stdio.h>).
pict
Figure 10: The relationship between MIPS and Nachos

2.3.1 Linux Installation

We highly recommend to use 32-bit Linux to install MIPS compiler. The installation is straightforward. Let us take 32-bit Ubuntu 12.04 LTS as an example to illustrate the detailed procedure of MIPS compiler installation.

  1. Download an architecture compatible MIPS package from the link. Here, you need to select mips-x86.linux-xgcc.tar.gz.
  2. Extract the files: tar -xzvf mips-x86.linux-xgcc.tar.gz. The location of this folder will be used in the following step. You can go to this folder and get the absolute path of this folder:
    cd mips-x86.linux-xgcc/
    pwd
  3. Set environment variable ARCHDIR. The configuration of environment variable depends on the local OS and shell version. Typically, you need to edit file .bashrc in your HOME directory. This is a hidden file which is not visible. To see this file, you need to use the command ls -a. Open the file with your preferred editor and add two new lines:
    export ARCHDIR=Your mips cp dir
    export PATH=$ARCHDIR:Your nachos bin dir:$PATH
    Then save and quit the editor. Note that, to make this configuration effective, you need to restart your TERMINAL(Not Machine).

    PIC

    Figure 11: The configuration of environmental variables
  4. To this end, the configuration of MIPS is finished. Now we need to test it works. Navigate to nachos/test, and run make clean. Then run make. Proceed to the next step if there are no errors produced here. If you run into errors such as “unrecognized flag” then check your ARCHDIR and where you appended it to the PATH variable.

    PIC

    Figure 12: Test configuration of MIPS compiler
  5. Navigate to nachos/proj2 and compile it with make, then run nachos -d ac -x halt.coff. This allows us to run nachos with a user program (halt.c, translated using the MIPS compiler to halt.coff) as input. Your output should look something like Figure  13.

    PIC

    Figure 13: Test the compiled COFF file

2.3.2 Mac OSX Installation

The installation of MIPS compiler in Mac OSX are almost identical. The differences are listed as follows:

  1. The environment variable configuration file in Mac OSX system is .bash_profile rather than .bashrc.
  2. You should download a different MIPS installation package.

There is a good chance that you will see an error as shown in Figure 14.

PIC

Figure 14: A common error when running MIPS on Mac OSX

This error occurs because you do not have libmpc lib installed. To install this library, follow the following steps:

Step 1 Install the Xcode Command Lines. If you have Xcode installed, use the Download tab in Xcode Preferences to install the Command Line Tools. If you do not have Xcode installed, you can download the Command Line Tools for free from the Apple Developer website.

PIC

Figure 15: Install command line tools in Xcode

Step 2 Install GNU Multiprecision library (aka libmpc). We recommend that you use the brew package manager to compile and install libmpc. Homebrew offers a very clean and simple way to install command line tools and libraries on a Mac. To install it. It should be as simple as running:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
To check whether Homebrew is installed successfully, you can run command: brew doctor. If it is installed successfully, you will see something like Figure 16.

PIC

Figure 16: Check whether Homebrew is installed successfully

Step 3 Install libmpc. Use command brew install libmpc. And to make sure that the library is correctly installed, you can run command: ls /usr/local/lib/libmpc.3.dylib.

Step 4 Go to nachos/test to make again. The compilation should be successful as shown Figure 17.

PIC

Figure 17: Run MIPS compiler

2.3.3 Windows Installation

We do NOT recommend to use Windows as developing environment for Nachos. We’ve encountered many errors while executing MIPS in Windows (Typically in Cygwin). That being said, the basic steps of configuration of MIPS in Cygwin is described as follows. Please use with caution.

  1. Run tar -zxvf your_mips_tar to extract the folder. It is recommended to keep your MIPS folder in the same directory as the Nachos directory for ease of access.
  2. Now we must add the MIPS directory to the PATH variable the same way we added the JDK. To do so, first define an ARCHDIR variable that contains the path to the extracted MIPS folder, and then append this variable to the PATH variable. MAKE SURE that ARCHDIR is appended to the path variable before anything else (Figure 18). Note that if the folder is placed in your Cygwin home directory, you can use the $HOME variable in .bash_profile.

    pict

    Figure 18: Adding ARCHDIR to the PATH variable
  3. Navigate to nachos/test, and run make. If you run into errors such as “unrecognized flag” then check ARCHDIR and if the path variable has been set properly.
Tips
  1. Nachos accepts COFF binary files produced by any MIPS compiler be it installed on Linux, Windows or Mac OSX. Therefore, you can compile your user program on the instructional machine and copy to your test directory for execution.
  2. Errors in compiling user programs typically come from incompatibility between the compiler and the machine. or example, you may install 64-bit MIPS compiler in a 32-bit machine. Make sure you have the right MIPS compiler for your local environment.