CSEP 551 – PMP Operating Systems

Time: Wednesday, 6.30pm – 9.20pm
Location: UW: CSE 306, MS: Building 99, Room 1915
Instructors: Andrew Baumann, Simon Peter
TAs: Naveen Kr. Sharma, Jialin Li

Tools used in this course

You'll use two sets of tools in this class: an x86 emulator, QEMU, for running your kernel; and a compiler toolchain, including assembler, linker, C compiler, and debugger, for compiling and testing your kernel. This page has the information you'll need to download and install your own copies. This class assumes familiarity with Unix commands throughout.

We recommend you use a virtual machine with Linux. If you really want to, you can build and install the tools on your own machine. These instructions generally assume you're using Linux (most of which work for MacOS), but brief instructions for Windows and Cygwin appear below.

It should be possible to get this development environment running under windows with the help of Cygwin. Install cygwin, and be sure to install the flex and bison packages (they are under the development header).

Using a Virtual Machine

The easiest way to get a compatible toolchain is to install a modern Linux distribution on your computer. With platform virtualization, Linux can cohabitate with your normal computing environment. Installing a Linux virtual machine is a two step process. First, you download the virtualization platform.

VirtualBox is a little slower and less flexible, but free!

Once the virtualization platform is installed, download a boot disk image for the Linux distribution of your choice.

This will download a file named something like ubuntu-14.04.1-desktop-i386.iso. Start up your virtualization platform and create a new (32-bit) virtual machine. Use the downloaded Ubuntu image as a boot disk; the procedure differs among VMs but is pretty simple. Type objdump -i, as above, to verify that your toolchain is now set up. You will do your work inside the VM.

For an overview of useful commands in the tools used in this course, see the lab tools guide.

Compiler Toolchain

A "compiler toolchain" is the set of programs, including a C compiler, assemblers, and linkers, that turn code into executable binaries. You'll need a compiler toolchain that generates code for 32-bit Intel architectures ("x86" architectures) in the ELF binary format.

Test Your Compiler Toolchain

Modern Linux and BSD UNIX distributions already provide a toolchain suitable for this course. To test your distribution, try the following commands:

% objdump -i
    

The second line should say elf32-i386.

% gcc -m32 -print-libgcc-file-name
    

The command should print something like /usr/lib/gcc/i486-linux-gnu/version/libgcc.a or /usr/lib/gcc/x86_64-linux-gnu/version/32/libgcc.a

If both these commands succeed, you're all set, and don't need to compile your own toolchain.

If the gcc command fails, you may need to install a development environment. On Ubuntu Linux, try this:

% sudo apt-get install -y build-essential gdb
    

On 64-bit machines, you may need to install a 32-bit support library. The symptom is that linking fails with error messages like "__udivdi3 not found" and "__muldi3 not found". On Ubuntu Linux, try this to fix the problem:

% sudo apt-get install gcc-multilib
    

Most modern Linuxes and BSDs have an ELF toolchain compatible with the labs. That is, the system-standard gcc, as, ld and objdump should just work. The lab makefile should automatically detect this. However, if your machine is in this camp and the makefile fails to detect this, you can override it by adding the following line to conf/env.mk:

GCCPREFIX=
    

If you are using something other than standard x86 Linux or BSD, you will need the GNU C compiler toolchain, configured and built as a cross-compiler for the target 'i386-jos-elf', as well as the GNU debugger, configured for the i386-jos-elf toolchain. You can download the specific versions we used via these links, although any recent versions of gcc, binutils, and GDB should work:

Once you've unpacked these archives, run the following commands as root:

    # cd binutils-2.21.1
    # ./configure --target=i386-jos-elf --disable-nls
    # make
    # make install
    # cd ../gcc-4.5.1
    # ./configure --target=i386-jos-elf --disable-nls --without-headers \
                  --with-newlib --disable-threads --disable-shared \
                  --disable-libmudflap --disable-libssp
    # make
    # make install
    # cd ../gdb-6.8
    # ./configure --target=i386-jos-elf --program-prefix=i386-jos-elf- \
                  --disable-werror
    # make
    # make install
    

Then you'll have in /usr/local/bin a bunch of binaries with names like i386-jos-elf-gcc. The lab makefile should detect this toolchain and use it in preference to your machine's default toolchain. If this doesn't work, there are instructions on how to override the toolchain inside the GNUmakefile in the labs.

QEMU Emulator

QEMU is a modern and fast PC emulator.

Unfortunately, QEMU's debugging facilities, while powerful, are somewhat immature, so we highly recommend you use our patched version of QEMU instead of the stock version that may come with your distribution. To build your own patched version of QEMU:

  1. Clone the patched QEMU git repository
    git clone https://github.com/geofft/qemu.git -b 6.828-1.7.0
  2. On Linux, you may need to install the SDL development libraries to get a graphical VGA window and other dependencies. On Debian/Ubuntu, this is the libsdl1.2-dev package. This blog post can help you in the installation http://theintobooks.wordpress.com/2012/10/30/installing-qemu/
  3. Configure the source code
    Linux: ./configure --disable-kvm [--prefix=PFX] [--target-list="i386-softmmu x86_64-softmmu"]
    OS X: ./configure --disable-kvm --disable-sdl [--prefix=PFX] [--target-list="i386-softmmu x86_64-softmmu"]
    The prefix argument specifies where to install QEMU; without it QEMU will install to /usr/local by default. The target-list argument simply slims down the architectures QEMU will build support for.
  4. Run sudo make && sudo make install
  5. You can drop the sudo in the above commands if the prefix points to a directory for which you have write permissions.

Working on Windows

It is also possible to get this development environment running under Windows with the help of Cygwin. Install cygwin, and be sure to install the flex and bison packages (they are under the development header). You'll then need to build and install a cross-compiler toolchain for x86 ELF, following the top-rated answer here (or if you're lazy and trusting, grab the prebuilt one linked at the end). You'll also need a working QEMU; you can find prebuilt Windows binaries here; for example, the 20140801 x86 build seems to work well. This is sufficient for doing the first lab, but does not include (all?) of the extra debugging support in the patches from MIT that are helpful in subsequent assignments.