Bootloader
SlayerOS uses the Limine bootloader to initialize the system and load the kernel. This document explains how the bootloader works and how the kernel interacts with it.
Limine Bootloader
Limine is a modern, feature-rich bootloader that supports both BIOS and UEFI systems. It provides a clean interface for the kernel to retrieve system information and resources.
Key Features
- Multiboot2 and Limine protocol support
- BIOS and UEFI compatibility
- Memory map information
- Framebuffer initialization
- Module loading
- SMP (Symmetric Multiprocessing) initialization
Boot Process
- The system firmware (BIOS or UEFI) loads the Limine bootloader
- Limine parses its configuration file (
limine.conf
) - Limine loads the kernel into memory
- Limine prepares the environment (memory map, framebuffer, etc.)
- Limine transfers control to the kernel's entry point (
_start
)
Limine Configuration
The Limine configuration file (misc/boot/limine.conf
) specifies various boot parameters:
TIMEOUT=0
SERIAL=yes
:SlayerOS
PROTOCOL=limine
KERNEL_PATH=boot/slay.kernel
TIMEOUT=0
: Boot immediately without showing a menuSERIAL=yes
: Enable serial output for debugging:SlayerOS
: Start of an entry named "SlayerOS"PROTOCOL=limine
: Use the Limine protocolKERNEL_PATH=boot/slay.kernel
: Path to the kernel binary on the boot medium
Limine Protocol
The Limine protocol is a communication mechanism between the bootloader and the kernel. The kernel places "requests" in its binary, and the bootloader fills in "responses" before transferring control.
Request Structure
struct limine_request {
uint64_t id[4];
uint64_t revision;
void *response;
};
Common Requests
SlayerOS uses several Limine requests:
- Memory Map Request: Provides information about available memory regions
- Framebuffer Request: Provides a framebuffer for graphics output
- HHDM Request: Provides a Higher Half Direct Map for accessing physical memory
- Kernel File Request: Provides information about the kernel file
Boot Context
SlayerOS defines a BootloaderCtx
structure to store information provided by the bootloader:
struct BootloaderCtx {
struct limine_memmap_response *memmap;
struct limine_framebuffer_response *fb_info;
struct limine_hhdm_response *hhdm;
struct limine_kernel_file_response *kernel_file;
};
This structure is populated in bootloader/limine.cxx
and used throughout the kernel.
Kernel Initialization
After the bootloader transfers control to the kernel, the following steps occur:
- The
_start
function (assembly) sets up the stack and calls_kernel_start
_kernel_start
initializes the UART for logging- The kernel collects bootloader information by accessing the Limine responses
- The kernel initializes the frame allocator using the memory map
- The kernel initializes the paging system
- The kernel initializes the framebuffer for graphics output
Debugging with Serial Output
Limine can redirect kernel output to a serial port for debugging. This is enabled with the SERIAL=yes
option in limine.conf
. The kernel can then use the serial port for logging and debugging output.
Building and Running
To build an ISO image with Limine and the SlayerOS kernel:
- Compile the kernel
- Create a directory structure for the ISO
- Copy the kernel and Limine files to the appropriate locations
- Use
xorriso
to create the ISO image - Install the Limine bootloader to the ISO
This process is automated in the Makefile with the iso
target.
Best Practices
When working with the bootloader:
- Always check that bootloader responses are valid before using them
- Don't rely on bootloader-reclaimable memory after initialization
- Use the memory map to avoid overwriting important memory regions
- Initialize essential hardware (like the serial port) early for debugging
These documents provide comprehensive information about the memory management system and bootloader in SlayerOS, based on the architecture overview. They explain the key components, their functions, and how they work together to initialize and manage the system.