11 Kernel

 

This chapter covers

  • Writing and compiling your own OS kernel
  • Gaining a deeper understanding of the Rust compiler’s capabilities
  • Extending cargo with custom subcommands

Let’s build an operating system (OS). By the end of the chapter, you’ll be running your own OS (or, at least, a minimal subset of one). Not only that, but you will have compiled your own bootloader, your own kernel, and the Rust language directly for that new target (which doesn’t exist yet).

This chapter covers many features of Rust that are important for programming without an OS. Accordingly, the chapter is important for programmers who intend to work with Rust on embedded devices.

11.1 A fledgling operating system (FledgeOS)

In this section, we’ll implement an OS kernel. The OS kernel performs several important roles, such as interacting with hardware and memory management, and coordinating work. Typically, work is coordinated through processes and threads. We won’t be able to cover much of that in this chapter, but we will get off the ground. We’ll fledge, so let’s call the system we’re building FledgeOS.

11.1.1 Setting up a development environment for developing an OS kernel

11.1.2 Verifying the development environment

11.2 Fledgeos-0: Getting something working

11.2.1 First boot

11.2.2 Compilation instructions

11.2.3 Source code listings

11.2.4 Panic handling

11.2.5 Writing to the screen with VGA-compatible text mode

11.2.6 _start(): The main() function for FledgeOS

11.3 fledgeos-1: Avoiding a busy loop

11.3.1 Being power conscious by interacting with the CPU directly

11.3.2 fledgeos-1 source code

11.4 fledgeos-2: Custom exception handling

11.4.1 Handling exceptions properly, almost

11.4.2 fledgeos-2 source code