/ xv6

Compiling Xv6 on OS X 10.9

What follows here is how I managed to compile Xv6 on Mac OS X Mavericks 10.9

This semester I am super excited to be taking Operating Systems Design. A large chunk of the course is working on the open source operating system Xv6 made by MIT. The available documentation is two years old and was not designed to be compiled on clang, the compiler that 10.9 ships with. The most difficult part of this process was figuring out how to compile gcc into an ELF cross compiler.

Without further ado, let's get started. Note: There is quite a bit of compiling to be done, this process will take at least 30 minutes.

Install gcc-4.8 via Homebrew:

brew tap homebrew/versions && brew install gcc48

Install QEMU dependencies:

brew deps qemu | xargs brew install

We need to use our own gcc for the rest of this:

export PATH=/usr/local/bin:$PATH
alias gcc=/usr/local/bin/gcc-4.8

Download the necessary requirements:

mkdir ~/Downloads/Xv6 && cd ~/Downloads/Xv6

If you don't have wget, brew install wget

wget http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2

wget http://www.mpfr.org/mpfr-3.1.0/mpfr-3.1.0.tar.bz2

wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2

wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz

wget http://ftpmirror.gnu.org/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2

wget http://ftpmirror.gnu.org/gdb/gdb-6.8a.tar.gz

I chose to put all of my Xv6 related binaries in their own location and then export the path when I need them.

mkdir /usr/local/xv6

Extract binutils:

tar -xzf binutils-2.21.1.tar.bz2 && cd binutils-2.21.1

Compile and install binutils:

CFLAGS=-Wno-error=deprecated-declarations ./configure --target=i386-jos-elf --disable-nls --prefix=/usr/local/xv6 && make && make install
cd .. && mkdir install

Extract and install gmp:

tar -xzf gmp-5.0.4.tar.bz2 && mkdir gmp-build; cd gmp-build
../gmp-5.0.4/configure --prefix=$(cd ../install && pwd) && make && make install

Extract and install mpfr:

cd .. && tar -xzf mpfr-3.1.0.tar.bz2 && mkdir mpfr-build; cd mpfr-build
../mpfr-3.1.0/configure --prefix=$(cd ../install && pwd) --with-gmp=$(cd ../install && pwd) && make && make install

Extract and install mpc:

cd .. && tar -xzf mpc-0.8.2.tar.gz && mkdir mpc-build; cd mpc-build
../mpc-0.8.2/configure --prefix=$(cd ../install && pwd) --with-gmp=$(cd ../install && pwd) --with-mpfr=$(cd ../install && pwd) && make && make install

Extract and install gcc using our fresh libs (there will be long pauses):

cd .. && tar -xzf gcc-core-4.5.1.tar.bz2 && mkdir gcc-build; cd gcc-build
../gcc-4.5.1/configure --target=i386-jos-elf --disable-nls --without-headers --with-newlib --disable-threads --disable-shared --disable-libmudflap --disable-libssp --with-gmp=$(cd ../install && pwd) --with-mpfr=$(cd ../install && pwd) --with-mpc=$(cd ../install && pwd) --prefix=/usr/local/xv6 && make && make install

Extract and install gdb using our new gcc:

export PATH=/usr/local/xv6/bin:$PATH
cd .. && tar -xzf gdb-6.8a.tar.gz && mkdir gdb-build; cd gdb-build
../gdb-6.8/configure --target=i386-jos-elf --program-prefix=i386-jos-elf- --disable-werror --prefix=/usr/local/xv6 && make && make install

Install QEMU:

cd .. && git clone http://pdos.csail.mit.edu/6.828/qemu.git -b 6.828-0.15 && cd qemu
./configure --disable-kvm --disable-sdl --prefix=/usr/local/xv6 --target-list="i386-softmmu x86_64-softmmu" && make && make install

If you don't have the Xv6 repo cloned do so now (I place mine in ~/Code/xv6):

cd ~/Code && git clone git://pdos.csail.mit.edu/xv6/xv6.git && cd xv6

Edit the Makefile and uncomment the line with TOOLPREFIX = i386-jos-elf-. Save and quit.

Everytime we use Xv6 we need to export our path:

export PATH=/usr/local/xv6/bin:$PATH
make clean && make qemu