Homework 1: Boot into Rust

This assignment will teach you to build a minimal bootable kernel that boots on real hardware into Rust. Technically, you can do this assignment on Linux, Mac or WSL (Windows Subsystem for Linux). Submit your code through Gradescope (see instructions at the bottom of this page).

NOTE: YOU CANNOT PUBLICLY RELEASE SOLUTIONS TO THIS HOMEWORK.

It’s ok to show your work to your future employer as a private Git repo, however any public release is prohibited.

Building a freestanding Rust binary

To build a freestanding Rust binary we will follow the ideas from the Philipp Oppermann’s blog (3rd edition) but use the build system we provide.

To get started clone the hw1 Brach of the Hello-OS and look over it. This branch provides a template for the build system that we discussed in class and other bits that you have to fill in.

Work through Philipp Oppermann’s blog (3rd edition) blog to first compile a standalone Rust binary.

Main things you need to do are:

Booting into Rust

To boot into Rust you can read bits of A Minimal Rust Kernel and specifically the multiboot standard. In our build system we use GRUB and multiboot. Everything is already wired up together in the build system but you have to read through the files to make sure you understand how it works.

Your job, however, is to fill in the missing gaps in boot.asm file. Specifically you should read through the code and configure the huge page table to make sure you can switch into long mode (64bit mode of execution) and jump into rust_main().

Specifically, you need one PML4 level page that points to one PML3 level page, which maps the first 4GB of address space 1-to-1 (i.e., virtual addresses are mapped to the same physical addresses).

I left some comments for what needs to be done. If you absolutely got stuck take a look at how Redleaf does it.

Printing on serial line

Your next step is to implement support for printing on serial line. Read through Printing to the Console and implement similar support in your kernel. Maybe it makes sense to read through VGA Text Mode first.

Running under QEMU

The end goal for this homework is to boot into Rust and print “Hello from Rust!” on the serial line. You should map the frist 4GBs of virtual memory.

As part of our build environment we support nix shell which will help you to carry cross-platform development on Mac. Take a look at README file for how to install nix and enter the nix shell.

In our build system the following command will start QEMU with serial line

make run-nox

Debugging your work

To debug your kernel you have to use two terminals on the same machine. Type

make run-nox-gdb

in one of them, and

make gdb

in another. If you need a refresher on how to use GDB, you can read bits of cs5460 HW1 and cs5460 HW3

Submitting your work

TBA on Gradescope