|
| 1 | ++++ |
| 2 | +title = "This Month in Rust OSDev (March 2021)" |
| 3 | +date = 2021-04-05 |
| 4 | + |
| 5 | +[extra] |
| 6 | +month = "March 2021" |
| 7 | +authors = [ |
| 8 | + "phil-opp", |
| 9 | + "IsaacWoods", |
| 10 | + # add yourself here |
| 11 | +] |
| 12 | ++++ |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +<!-- more --> |
| 17 | + |
| 18 | +This series is openly developed [on GitHub](https://github.com/rust-osdev/homepage/). 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](https://github.com/rust-osdev/homepage/issues/new) or using our [_comment form_](#comment-form) at the bottom of this page. |
| 19 | + |
| 20 | +## Project Updates |
| 21 | + |
| 22 | +In this section, we give an overview of notable changes to the projects hosted under the [`rust-osdev`] organization. |
| 23 | + |
| 24 | +[`rust-osdev`]: https://github.com/rust-osdev/about |
| 25 | + |
| 26 | +### [`bootloader`](https://github.com/rust-osdev/bootloader) |
| 27 | + |
| 28 | +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: |
| 29 | + |
| 30 | +- [Fix linker errors on latest nightlies](https://github.com/rust-osdev/bootloader/pull/139) <span class="gray">(published as `v0.9.15`)</span> |
| 31 | +- [Replace all remaining `lea`s with `mov` + `offset`](https://github.com/rust-osdev/bootloader/pull/140) <span class="gray">(published as `v0.9.16`)</span> |
| 32 | + |
| 33 | +We also made some good progress on the [UEFI rewrite](https://github.com/rust-osdev/bootloader/pull/130): |
| 34 | + |
| 35 | +- [Set up VESA mode properly instead of hardcoding it](https://github.com/rust-osdev/bootloader/pull/130/commits/7f7fec78ffb7125a7eb0312698714d7897bf9fb9) |
| 36 | +- [Detect actual pixel format instead of hardcoding it (BIOS)](https://github.com/rust-osdev/bootloader/pull/130/commits/58564910a743ec48e6c1b3113151d96c7b54ca63) |
| 37 | +- [Use `quote` crate for creating `Config` struct instead of debug impls](https://github.com/rust-osdev/bootloader/pull/130/commits/f7478eba3034c98bde0c7725ce21a7b56a473d61) |
| 38 | +- [Allow specifying addresses as TOML integers too](https://github.com/rust-osdev/bootloader/pull/130/commits/ba9d943dbb18ef756979f1d2c14df297c1003b45) |
| 39 | +- [Add docs for crate and `Config` struct](https://github.com/rust-osdev/bootloader/pull/130/commits/536e0f6b53b8dcd53b6125c3383dec3bdb7a3cc3) |
| 40 | +- [Document the created disk images](https://github.com/rust-osdev/bootloader/pull/130/commits/eccb89d61a3e390b36f767d6d8780187bd962e58) |
| 41 | + |
| 42 | +### [`x86_64`](https://github.com/rust-osdev/x86_64) |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +In March, we merged these changes: |
| 47 | + |
| 48 | +- [Implement `Clone` for `PageTable`](https://github.com/rust-osdev/x86_64/pull/236) <span class="gray">(published as `v0.13.3`)</span> |
| 49 | +- [Implement more fmt traits for addr types](https://github.com/rust-osdev/x86_64/pull/237) <span class="gray">(published as `v0.13.4`)</span> |
| 50 | + |
| 51 | +Thanks to [@toku-sa-n](https://github.com/toku-sa-n) and [@dbeckwith](https://github.com/dbeckwith) for their contributions! |
| 52 | + |
| 53 | +### [`uefi-rs`](https://github.com/rust-osdev/uefi-rs) |
| 54 | + |
| 55 | +The `uefi` crate provides safe and performant wrappers for [UEFI](https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface), the successor to the BIOS. In March, we merged the following changes: |
| 56 | + |
| 57 | +- [Expose device path types](https://github.com/rust-osdev/uefi-rs/pull/202) |
| 58 | +- [Fix running tests in CI](https://github.com/rust-osdev/uefi-rs/pull/203) |
| 59 | +- [Fix typo in regular.rs](https://github.com/rust-osdev/uefi-rs/pull/204) |
| 60 | + |
| 61 | +Thanks to [@gil0mendes](https://github.com/gil0mendes) and [@ocadaruma](https://github.com/ocadaruma) for their contributions! |
| 62 | + |
| 63 | +### [`multiboot2`](https://github.com/rust-osdev/multiboot2-elf64) |
| 64 | + |
| 65 | +The `multiboot2` crate provides abstraction types for the boot information of multiboot2 bootloaders. We merged the following updates this month: |
| 66 | + |
| 67 | +- [Use `impl Iterator` as return type instead of named types](https://github.com/rust-osdev/multiboot2-elf64/pull/72) |
| 68 | +- [Docs: Remove fragile `asm!` code example](https://github.com/rust-osdev/multiboot2-elf64/pull/73) |
| 69 | +- [Apply `rustfmt`](https://github.com/rust-osdev/multiboot2-elf64/pull/74) |
| 70 | + |
| 71 | +Thanks to [@toku-sa-n](https://github.com/toku-sa-n) for their contributions! |
| 72 | + |
| 73 | +### [`volatile`](https://github.com/rust-osdev/volatile) |
| 74 | + |
| 75 | +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: |
| 76 | + |
| 77 | +- [Replace feature `range_bounds_assert_len` with `slice_range`](https://github.com/rust-osdev/volatile/pull/21) <span class="gray">(published as `v0.4.4`)</span> |
| 78 | +- [Add a test for `slice::as_chunks_mut` usage](https://github.com/rust-osdev/volatile/commit/15bbfac9c7cb42ff56698ac5c00daeddbcdb6a0d) |
| 79 | + - 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). |
| 80 | + |
| 81 | +Thanks to [@KernelFreeze](https://github.com/KernelFreeze) for their contribution! |
| 82 | + |
| 83 | +### [`acpi`](https://github.com/rust-osdev/acpi) |
| 84 | + |
| 85 | +The `acpi` repository contains crates for parsing the ACPI tables – data structures that the firmware of modern |
| 86 | +computers use to relay information about the hardware to the OS. This month has seen substantial changes to both |
| 87 | +the `acpi` and `aml` crates: |
| 88 | + |
| 89 | +- [We made the types that represent raw ACPI tables public](https://github.com/rust-osdev/acpi/pull/86). This allows library users to work directly with tables such as the |
| 90 | + [FADT](https://docs.rs/acpi/2.3.1/acpi/fadt/struct.Fadt.html) if they need to, which is needed to access power |
| 91 | + management features we don't yet expose. <span class="gray">(published as `acpi v2.3.1`)</span> |
| 92 | +- [Native functions are now supported by the AML interpreter!](https://github.com/rust-osdev/acpi/pull/88). A |
| 93 | + 'native function' is an AML method that is defined in Rust, rather than using AML bytecode. This is useful for |
| 94 | + defining "up-call" methods (where a method is provided by the OS, and called by the firmware), and will hopefully |
| 95 | + by useful in the future for patching methods in broken tables. A native method can easily be created with |
| 96 | + the [`AmlValue::native_method` constructor](https://docs.rs/aml/0.11.0/aml/value/enum.AmlValue.html#method.native_method). |
| 97 | +- However, supporting native functions needed a bit of breakage - `AmlValue` no longer implements `PartialEq` or `Eq`. This actually improves correctness, |
| 98 | + as correctly comparing two `AmlValue`s may require type conversions to be done, and so should be done with the |
| 99 | + [`AmlValue::cmp`](https://docs.rs/aml/0.11.0/aml/value/enum.AmlValue.html#method.cmp) method, but does make `aml |
| 100 | + v0.11.0` a breaking change. |
| 101 | +- We also used this opportunity to remove the `legacy_mode` parameter to `AmlContext::new`, which will affect all |
| 102 | + crate users, but makes user's lives simpler - handling old tables will now be done automatically. |
| 103 | +- Fallout from `AmlValue` no longer being `Eq` also led to some cleanups in how control flow is handled in the |
| 104 | + interpreter. This is not likely to affect users, but the "fake" error `AmlError::Return` has been removed, which |
| 105 | + is also technically a breaking change in `aml v0.11.0`. |
| 106 | +- The AML interpreter now correctly supplies the `\_OS`, `\_OSI`, and `\_REV` objects. These objects were designed |
| 107 | + to allow firmware to detect OS support for new AML features, but [come with a bit of baggage](https://www.kernel.org/doc/html/latest/firmware-guide/acpi/osi.html). |
| 108 | + This is important for supporting running on real hardware, which often assumes the existence of these objects. |
| 109 | + <span class="gray">(published as `aml v0.11.0`)</span> |
| 110 | + |
| 111 | +## Call for Participation |
| 112 | +Want to contribute to a Rust OSDev project, but don't know where to start? Pick up one of these outstanding |
| 113 | +issues in one of our projects and get started! |
| 114 | + |
| 115 | +If you maintain a Rust OSDev project and are looking for contributors, especially for tasks suited to people |
| 116 | +getting started in this space, please [create a PR](https://github.com/rust-osdev/homepage/pulls) against the |
| 117 | +`next` branch with the tasks you want to include in the next issue. |
| 118 | + |
| 119 | +- [(`acpi`) Record attempted conversion in `AmlError::IncompatibleValueConversion`](https://github.com/rust-osdev/acpi/issues/53) |
| 120 | +- [(`acpi`) Support the new MADT Multiprocessor Wakeup structure](https://github.com/rust-osdev/acpi/issues/87) |
| 121 | + |
| 122 | +## Personal Projects |
| 123 | + |
| 124 | +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](https://github.com/rust-osdev/homepage/pulls) with the updates of your OS project for the next post. |
| 125 | + |
| 126 | +### [`phil-opp/blog_os`](https://github.com/phil-opp/blog_os) |
| 127 | + |
| 128 | +<span class="gray">(Section written by [@phil-opp](https://github.com/phil-opp))</span> |
| 129 | + |
| 130 | +The [_"Writing an OS in Rust"_](https://os.phil-opp.com) blog received the following updates this month: |
| 131 | + |
| 132 | +- [Translate post-05 to Japanese](https://github.com/phil-opp/blog_os/pull/941) |
| 133 | +- [Fix rendering of Japanese translation: Add spaces around some "two asterisk" notations](https://github.com/phil-opp/blog_os/pull/943) |
| 134 | +- [Convert `before_build.py` to python3](https://github.com/phil-opp/blog_os/commit/f87cc129fc660473f2d14e9c8d1f8f1e484e105d) |
| 135 | +- [Lots of grammar and typo fixes](https://github.com/phil-opp/blog_os/pulls?q=is%3Apr+is%3Aclosed+merged%3A2021-03-22..2021-03-31+) |
| 136 | + |
| 137 | +Thanks to [@woodyZootopia](https://github.com/woodyZootopia), [@alexxroche](https://github.com/alexxroche), and [@ClementNerma](https://github.com/ClementNerma) for their contributions! |
| 138 | + |
| 139 | +The third edition is making progress too. I mostly worked on the post about UEFI booting this month: |
| 140 | + |
| 141 | +- [Describe how to include the uefi crate](https://github.com/phil-opp/blog_os/commit/8740b619a5debe3fa1069c47c61ceed471a3b2f6) |
| 142 | +- [Describe how to use various UEFI protocols with the `uefi` crate](https://github.com/phil-opp/blog_os/commit/9c1babd0273ff3d4f632b6e1acf288267138b90f) |
| 143 | +- [Provide a high-level explanation on how to create bootloader](https://github.com/phil-opp/blog_os/commit/db47b2702446c1a469e8e064fb090370040bfa2e) |
| 144 | + |
| 145 | +### [`rust-embedded/rust-raspberrypi-OS-tutorials`](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials) |
| 146 | + |
| 147 | +<span class="gray">(Section written by [@andre-richter](https://github.com/andre-richter))</span> |
| 148 | + |
| 149 | +The [Operating System development tutorials in Rust on the Raspberry Pi](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials) project |
| 150 | +got two more tutorials this month: |
| 151 | + |
| 152 | +- [Tutorial 15 - `Virtual Memory Part 3: Precomputed Translation Tables`](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/15_virtual_mem_part3_precomputed_tables) |
| 153 | +- [Tutorial 16 - `Virtual Memory Part 4: Higher-Half Kernel`](https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials/tree/master/16_virtual_mem_part4_higher_half_kernel) |
| 154 | + |
| 155 | +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**. |
| 156 | + |
| 157 | +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): |
| 158 | + |
| 159 | +```console |
| 160 | +[5.011] Booting on: Raspberry Pi 4 |
| 161 | +[5.011] MMU online: |
| 162 | +[5.011] -------------------------------------------------------------------------------------------------------------- |
| 163 | +[5.013] Virtual Physical Size Attr Entity |
| 164 | +[5.015] -------------------------------------------------------------------------------------------------------------- |
| 165 | +[5.017] 0xffff_ffff_8008_0000..0xffff_ffff_8008_ffff --> 0x0008_0000..0x0008_ffff | 64 KiB | C RO X | Kernel code |
| 166 | +[5.018] 0xffff_ffff_8009_0000..0xffff_ffff_800f_ffff --> 0x0009_0000..0x000f_ffff | 448 KiB | C RW XN | Kernel data |
| 167 | +[5.020] 0xffff_ffff_8011_0000..0xffff_ffff_8018_ffff --> 0x0011_0000..0x0018_ffff | 512 KiB | C RW XN | Kernel stack |
| 168 | +[5.021] 0xffff_ffff_f000_0000..0xffff_ffff_f000_ffff --> 0xfe20_0000..0xfe20_ffff | 64 KiB | D RW XN | BCM GPIO |
| 169 | +[5.023] | BCM PL011 UART |
| 170 | +[5.024] 0xffff_ffff_f001_0000..0xffff_ffff_f001_ffff --> 0xff84_0000..0xff84_ffff | 64 KiB | D RW XN | GICD |
| 171 | +[5.026] | GICC |
| 172 | +[5.027] -------------------------------------------------------------------------------------------------------------- |
| 173 | +[5.029] Current privilege level: EL1 |
| 174 | +``` |
| 175 | + |
| 176 | +## Join Us? |
| 177 | + |
| 178 | +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 [gitter channel](https://gitter.im/rust-osdev/Lobby). |
0 commit comments