Setting Up a Development Environment

In today’s class we will begin with a tour of the starter code for our kernel, and then set up the development environment on MathLAN and any personal machine(s) you plan to use for this class. To begin, download the starter code archive and extract the file contents. Follow the instructions for the platform you are using below, and repeat for any other platforms you want to set up.

Setting Up

MathLAN

By the time we start this exercise we should have discussed cross-compilation and the need for target-specific tools to build the kernel. I have already built these tools on MathLAN and you can use them without having to recompile them yourself. To use the pre-built tools you will need to add the following line to the .bashrc file in your MathLAN home directory so your shell will look for executables where I’ve installed them:

export PATH="$PATH:/home/curtsinger/.local/bin"

After adding that line, start a new terminal and run the following commands (shown with their expected output):

$ which x86_64-elf-ld
/home/curtsinger/.local/bin/x86_64-elf-ld
$ which xorriso
/home/curtsinger/.local/bin/xorriso

If you see different output, something is not set up correctly. Please raise your hand and ask for help.

Once you’ve verified that you have access to the command line tools above, move to the kernel starter code you extracted earlier. Run the following command to build the kernel:

$ make
(lots of output)

You should now have a file named boot.iso in the current directory. If you do not have that file something went wrong. Raise your hand and ask for help.

Finally, you can boot the kernel inside of the QEMU emulator with the following command:

$ make run

You should see a “Hello World” message in an otherwise-blank screen. To quit, type esc+2 to enter the QEMU monitor. You might have to press the keys a few times to get it, but you’ll eventually see a “(qemu)” prompt. Type in “quit” and hit entry to exit.

You’re all set up on MathLAN now. If you have a personal machine to set up you can move on to that step, or you can start working on our first implementation task.

macOS

To build the kernel on macOS you will need a few extra packages. I use the Homebrew package manager, but if you have a different package manager you like you may be able to find equivalent packages there. The first step is to install our build dependencies. Run the following brew install commands in a terminal on your mac:

$ brew install xorriso x86_64-elf-binutils qemu

Once the installation has finished you should be able to run the same make and make run commands you used on MathLAN to launch the kernel on your machine.

Other Linux Computers

If you’re setting up a Linux computer the procedure will be almost identical to the MathLAN set up, but you will need to install a few packages and build the Binutils package for our x86_64-elf target. I will assume you are using Ubuntu or Debian and can use the apt package manager. If you use a different distribution you will need to find comparable packages for your system.

First, you’ll need to install some basic tools:

$ sudo apt-get install clang xorriso qemu-system

Next, you have to build Binutils to target our emulated machine. To do this, download a copy of Binutils 2.37 with the link https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.gz. Open a terminal in the extracted directory and run the following commands:

$ ./configure --target=x86_64-elf
$ make
$ sudo make install

At this point you should have x86_64-elf-ld installed and you can proceed with the MathLAN instructions above to test the kernel.

Windows (experimental)

I do not have access to a Windows machine, so this is my best guess at the setup procedure. I recommend using Windows Services for Linux. Follow the setup guide for WSL and install an Ubuntu or Debian linux distribution (I recommend Ubuntu 20.04).

Once you have WSL set up you should be able to follow the Linux guide above.

Acknowledgements

This starter code is based on the following example projects:

In addition to the above example projects, the following references were used when setting up this code: