As a part of the OS pro­ject for the uni­ver­sity there has been a re­quest to also write up the ex­per­i­ences and chal­lenges en­countered. This is the first post of the series on writ­ing a x64 op­er­at­ing sys­tem when boot­ing straight from UE­FI. Please keep in mind that these posts are writ­ten by a not-even-hob­by­ist and con­tent in these posts should be taken with a grain of salt.

Ker­nel and UEFI I’ve de­cided to write a ker­nel tar­get­ing x64 as an UEFI ap­plic­a­tion. There are a num­ber of reas­ons to write a ker­nel as an UEFI ap­plic­a­tion as op­posed to writ­ing a multi­boot ker­nel. Namely: For x86 fam­ily of pro­cessors, you avoid the work ne­ces­sary to up­grade from real mode to pro­tec­ted mode and then from pro­tec­ted mode to long mode which is more com­monly known as a 64-bit mode. As an UEFI ap­plic­a­tion your ker­nel gets a fully work­ing x64 en­vir­on­ment from the get-go; Un­like BIOS, UEFI is a well doc­u­mented firm­ware. Most of the in­ter­faces provided by BIOS are de facto and you’re lucky if they work at all, while most of these provided by UEFI are de jure and usu­ally just work; UEFI is ex­tens­ible, whereas BIOS is not really; Fi­nally, UEFI is a mod­ern tech­no­logy which is likely to stay around, while BIOS is a 40 years old piece of tech­no­logy on the death row. Learn­ing about soon-to-be-dead tech­no­logy is a waste of the ef­fort. Des­pite my strong at­tach­ment to the Rust com­munity and Rust’s per­fect suit­ab­il­ity for ker­nels , I’ll be writ­ing the ker­nel in C. Mostly be­cause of how un­likely it is for people at the uni­ver­sity to be fa­mil­iar with Rust. Also be­cause GNU-EFI is a C lib­rary and I can­not be bothered to bind it. I’d surely be writ­ing it in Rust was I more ser­i­ous about the pro­ject.

Tool­chain As it turns out, de­vel­op­ing a x64 ker­nel on a x64 host greatly sim­pli­fies set­ting up the build tool­chain. I’ll be us­ing: clang to com­pile the C code (no cross-­com­piler is ne­ces­sary !);

to com­pile the C code (no cross-­com­piler is ne­ces­sary !); gnu-efi lib­rary to in­ter­act with the UEFI firm­ware;

lib­rary to in­ter­act with the UEFI firm­ware; qemu emu­lator to run my ker­nel; and

emu­lator to run my ker­nel; and OVMF as the UEFI firm­ware.