efi

Rust-based OS booting with UEFI (2)

All code of this tutorial can be accessed at my GitHub repo

What is an OS?

In modern days, the word 'OS' may denote many things.

OS can be used to name a kernel, e.g. Linux, Mach (the kernel of macOS), and etc.

OS can also be used to name a kernel and a set of userland programs, e.g. GNU/Linux, macOS, and etc.

In this series of articles, we mainly focus on the kernel part of an OS.

In term of an OS kernel, let's talk about what tasks should be done by an OS kernel.

The major role of an OS kernel is to provide a virtualization abstraction of hardware resources, and to provide a set of APIs for userland programs to use these resources.

In this definition, an OS kernel should:

  1. Manages computational (CPU, GPU, application specific accelerators) and storage resources (memory, disks, and etc.), and distribute them to userland programs.
  2. Provides a unified interface to operate periphrals (keyboard, mouse, network, and etc.).

Therefore, in this episode, we will try to detect the core hardware resources of the device via UEFI interface:

  1. CPU
  2. Memory layout
  3. Graphics

Rust-based OS booting with UEFI (1)

All code of this tutorial can be accessed at my GitHub repo

Time to Write OS Tutorials in UEFI

There are quite a lot of OS tutorials and YouTube videos out there. However, most of them are written to boot in BIOS mode.

However, it is 2023 now, 19 years since Intel open sourced UEFI. Meanwhile, Intel is trying to replace x86_64 with x86_64s, which is a pure 64bit platform. And, of course, it will only support UEFI (UEFI CSM will be removed).

UEFI is a more secure and more powerful booting system. Almost all modern operating system are booted via UEFI. There seems to be no reason to continue writing OS tutorials for BIOS. Taking care about switching to long mode, or enabling paging is no longer necessary, but annoying technology details.

After searching Google, I see there are very limited information about writing OS in UEFI. The information are scattered in different places, and it is hard to find a complete tutorial. Therefore, I decided to write a series of tutorials about writing OS in UEFI.