Building a MIPS cross-compiler for Linux


Note: Some sections of these instructions are out of date. If you can't figure out how to build the cross-compiler on your own, please contact course personnel at cs350@student.cs for further guidance.

This section will describe how to build the MIPS cross-compiler suitable for Nachos on Linux. This information may be of some help if you run into trouble using the binaries supplied in the ~cs350/common/linux-gcc.tar.gz file. If you decide to re-create the gcc cross-compiler from source for yourself, be warned that you will need lots of free disk space, probably at least 50M. The following instructions assume you are on a Linux machine, of course ;).

Ok, so here is what was done to create linux-gcc.tar.gz:

  1. Get the binutils and gcc packages, binutils-2.5.2.tar.gz and gcc-2.6.3.tar.gz, via anonymous ftp to prep.ai.mit.edu.
  2. Unpack them both:
    tar xzf binutils-2.5.2.tar.gz
    tar xzf gcc-2.6.3.tar.gz
  3. Build the binutils package, and install under /usr/local/nachos/:
    cd binutils-2.5.2
    ./configure --prefix=/usr/local/nachos --host=i486-linux --target=decstation-ultrix
    make
    make install
  4. Build gcc, and install under /usr/local/nachos/:
    cd ../gcc-2.6.3
    ./configure --host=i486-linux --target=decstation-ultrix --with-gnu-as --with-gnu-ld --prefix /usr/local/nachos --local-prefix /usr/local/nachos
    Before building gcc, you need to make a few changes. After building the cross-compiler, the Makefile is going to try to use it to build a set of libraries, and a couple of test cases. The libraries depend on Unix headers (such as stdio.h) which Nachos does not support, so we need to fake out the Makefile by creating dummy lib files:
    ar rc libgcc.a /dev/null
    ar rc libgcc2.a /dev/null
    Also, you need to comment a couple of lines in the Makefile. The first line begins with:
    ENQUIRE = ...
    and the second begins with:
    CROSS_TEST = ...
    We need to do one more step before the compile. Change line 57 in the file sdbout.c from #include <syms.h> to #include "gsyms.h".
    make LANGUAGES=c
    make install LANGUAGES=c
    At the end of the each compile, you will get an error building libgcc2; ignore it an proceed.
  5. Reduce the space used by /usr/local/nachos/ by removing some unecessary stuff, and by stripping binaries. There is probably more pruning possible, but I don't know gcc well enough to know what is safe to remove.
    cd /usr/local/nachos; strip `find . -type f -perm -111 -print`
    rm -rf info man include
    cd lib; rm lib*
  6. Build linux-gcc.tgz:
    cd /; tar cf linux-gcc.tar usr/local/nachos; gzip linux-gcc.tar