Home

Awesome

OS DEV

This should be a very simple jumping off point to modern kernel development.

The idea behind this project is to provide an easy to understand, minimalist bootstrap that lowers the barrier to entry for any new comers.

Code works for both

run ./build.sh and you can boot the resulting example kernel on both x86_64 and AArch64

Crystal Kernel

This bootstrap is being used to load this hobby OS https://github.com/stakach/crystal-kernel

Getting started

Very easy to test and run on Windows with VirtualBox see Crystal Kernel for details on how to test and even step through debug your kernel on macOS.

Building an EFI bootable executable

EFI expects the bootable file to be in COFF/PE32+ format

you can also do this manually

  1. run make -f makefile_x86_64
  2. this will output
    • bin/efi/boot/bootx64.efi
    • bin/kernelx64.elf
  3. you can inspect symbols in the object files using nm -C bin/uefi_bootstrap.obj (or kernelx64.elf)
    • anything with a U tag, i.e. U memcpy means memcpy needs to be defined in your project

Create a disk image for booting

Very simple to do this on Windows, for macOS see Crystal Kernel which builds disk images as part of the build script

unmount the disk before booting it in VirtualBox <img src="https://user-images.githubusercontent.com/368013/136745462-d5793f29-e85a-4642-9854-98ea047e3bf9.png" alt="unmount" width="300"/>

Create a VM

Starting the VM will now boot the bootx64.efi file

<img src="https://user-images.githubusercontent.com/368013/136746021-11f16641-0666-4cdc-bd5a-5d9975eba328.png" alt="unmount" width="700"/>

Diving into the code

The process of booting should be fairly simple to follow along looking at uefi_bootstrap.zig The real trick with UEFI code is that

The bootstrap code likewise expects a few things of the kernel.elf file:

Take a look at kernel.ld to see how this is laid out. For instance I currently have the boot_info label in the text section. But I could probably swap around the text and data sections if I wanted boot_info as part of data or bss

Accessing the full address space

https://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models