Rust OSDev Operating System Development in Rust

This Month in Rust OSDev (March 2021)

Welcome to a new issue of "This Month in Rust OSDev". In these posts, we give a regular overview of notable changes in the Rust operating system development ecosystem.

This series is openly developed on GitHub. Feel free to open pull requests there with content you would like to see in the next issue. If you find some issues on this page, please report them by creating an issue or using our comment form at the bottom of this page.

Project Updates

In this section, we give an overview of notable changes to the projects hosted under the rust-osdev organization.

bootloader

The bootloader crate implements a custom Rust-based bootloader for easy loading of 64-bit ELF executables. This month, we fixed some build errors that were caused by the update to LLVM 12 in recent Rust nightlies:

We also made some good progress on the UEFI rewrite:

x86_64

The x86_64 crate provides various abstractions for x86_64 systems, including wrappers for CPU instructions, access to processor-specific registers, and abstraction types for architecture-specific structures such as page tables and descriptor tables.

In March, we merged these changes:

Thanks to @toku-sa-n and @dbeckwith for their contributions!

uefi-rs

The uefi crate provides safe and performant wrappers for UEFI, the successor to the BIOS. In March, we merged the following changes:

Thanks to @gil0mendes and @ocadaruma for their contributions!

multiboot2

The multiboot2 crate provides abstraction types for the boot information of multiboot2 bootloaders. We merged the following updates this month:

Thanks to @toku-sa-n for their contributions!

volatile

The volatile crate provides a safe wrapper type for implementing volatile read and write operations. This is useful for accessing memory regions that have side-effects, such as memory-mapped hardware registers or framebuffers. In March, we fixed a build error that was caused by a change in nightly Rust:

Thanks to @KernelFreeze for their contribution!

acpi

The acpi repository contains crates for parsing the ACPI tables – data structures that the firmware of modern computers use to relay information about the hardware to the OS. This month has seen substantial changes to both the acpi and aml crates:

  • We made the types that represent raw ACPI tables public. This allows library users to work directly with tables such as the FADT if they need to, which is needed to access power management features we don't yet expose. (published as acpi v2.3.1)
  • Native functions are now supported by the AML interpreter!. A 'native function' is an AML method that is defined in Rust, rather than using AML bytecode. This is useful for defining "up-call" methods (where a method is provided by the OS, and called by the firmware), and will hopefully by useful in the future for patching methods in broken tables. A native method can easily be created with the AmlValue::native_method constructor.
  • However, supporting native functions needed a bit of breakage - AmlValue no longer implements PartialEq or Eq. This actually improves correctness, as correctly comparing two AmlValues may require type conversions to be done, and so should be done with the AmlValue::cmp method, but does make aml v0.11.0 a breaking change.
  • We also used this opportunity to remove the legacy_mode parameter to AmlContext::new, which will affect all crate users, but makes user's lives simpler - handling old tables will now be done automatically.
  • Fallout from AmlValue no longer being Eq also led to some cleanups in how control flow is handled in the interpreter. This is not likely to affect users, but the "fake" error AmlError::Return has been removed, which is also technically a breaking change in aml v0.11.0.
  • The AML interpreter now correctly supplies the \_OS, \_OSI, and \_REV objects. These objects were designed to allow firmware to detect OS support for new AML features, but come with a bit of baggage. This is important for supporting running on real hardware, which often assumes the existence of these objects. (published as aml v0.11.0)

Call for Participation

Want to contribute to a Rust OSDev project, but don't know where to start? Pick up one of these outstanding issues in one of our projects and get started!

If you maintain a Rust OSDev project and are looking for contributors, especially for tasks suited to people getting started in this space, please create a PR against the next branch with the tasks you want to include in the next issue.

Personal Projects

In this section, we describe updates to personal projects that are not directly related to the rust-osdev organization. Feel free to create a pull request with the updates of your OS project for the next post.

phil-opp/blog_os

(Section written by @phil-opp)

The "Writing an OS in Rust" blog received the following updates this month:

Thanks to @woodyZootopia, @alexxroche, and @ClementNerma for their contributions!

The third edition is making progress too. I mostly worked on the post about UEFI booting this month:

rust-embedded/rust-raspberrypi-OS-tutorials

(Section written by @andre-richter)

The Operating System development tutorials in Rust on the Raspberry Pi project got two more tutorials this month:

The two tutorials finally conclude the challenging but rewarding journey of enabling the kernel to execute from the top of the 64 bit virtual address space.

Here is a sneak peek of the end result when booting the kernel on a Raspberry Pi 4 (slightly modified to fit on the page):

[5.011] Booting on: Raspberry Pi 4
[5.011] MMU online:
[5.011]   --------------------------------------------------------------------------
[5.013]           Virtual            Physical      Size      Attr       Entity
[5.015]   --------------------------------------------------------------------------
[5.017]   0xffff_ffff_8008_0000 --> 0x0008_0000 |  64 KiB | C RO X  | Kernel code
[5.018]   0xffff_ffff_8009_0000 --> 0x0009_0000 | 448 KiB | C RW XN | Kernel data
[5.020]   0xffff_ffff_8011_0000 --> 0x0011_0000 | 512 KiB | C RW XN | Kernel stack
[5.021]   0xffff_ffff_f000_0000 --> 0xfe20_0000 |  64 KiB | D RW XN | BCM GPIO
[5.023]                                                             | BCM PL011 UART
[5.024]   0xffff_ffff_f001_0000 --> 0xff84_0000 |  64 KiB | D RW XN | GICD
[5.026]                                                             | GICC
[5.027]   --------------------------------------------------------------------------
[5.029] Current privilege level: EL1

Join Us?

Are you interested in Rust-based operating system development? Our rust-osdev organization is always open to new members and new projects. Just let us know if you want to join! A good way for getting in touch is our Zulip chat.

Comments