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:
- Fix linker errors on latest nightlies (published as
v0.9.15
) - Replace all remaining
lea
s withmov
+offset
(published asv0.9.16
)
We also made some good progress on the UEFI rewrite:
- Set up VESA mode properly instead of hardcoding it
- Detect actual pixel format instead of hardcoding it (BIOS)
- Use
quote
crate for creatingConfig
struct instead of debug impls - Allow specifying addresses as TOML integers too
- Add docs for crate and
Config
struct - Document the created disk images
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:
- Implement
Clone
forPageTable
(published asv0.13.3
) - Implement more fmt traits for addr types (published as
v0.13.4
)
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:
- Use
impl Iterator
as return type instead of named types - Docs: Remove fragile
asm!
code example - Apply
rustfmt
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:
- Replace feature
range_bounds_assert_len
withslice_range
(published asv0.4.4
) - Add a test for
slice::as_chunks_mut
usage- By using
as_chunks_mut
, it is possible read and write multiple slice elements through a single volatile operation. This allows the compiler to optimize the code better (compared to reading the elements one by one).
- By using
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 implementsPartialEq
orEq
. This actually improves correctness, as correctly comparing twoAmlValue
s may require type conversions to be done, and so should be done with theAmlValue::cmp
method, but does makeaml v0.11.0
a breaking change. - We also used this opportunity to remove the
legacy_mode
parameter toAmlContext::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 beingEq
also led to some cleanups in how control flow is handled in the interpreter. This is not likely to affect users, but the "fake" errorAmlError::Return
has been removed, which is also technically a breaking change inaml 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 asaml 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.
- (
acpi
) Record attempted conversion inAmlError::IncompatibleValueConversion
- (
acpi
) Support the new MADT Multiprocessor Wakeup structure
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:
- Translate post-05 to Japanese
- Fix rendering of Japanese translation: Add spaces around some "two asterisk" notations
- Convert
before_build.py
to python3 - Lots of grammar and typo fixes
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:
- Describe how to include the uefi crate
- Describe how to use various UEFI protocols with the
uefi
crate - Provide a high-level explanation on how to create bootloader
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:
- Tutorial 15 -
Virtual Memory Part 3: Precomputed Translation Tables
- Tutorial 16 -
Virtual Memory Part 4: Higher-Half Kernel
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.