CLOSE
Updated on 27 Jul, 202514 mins read 91 views

What pass data from bootloader to kernel?

Because when the kernel starts, it knows nothing about the system. It needs the bootloader to hand over critical information.

As we already know that the bootloader's job is to:

  1. Load the kernel binary into memory
  2. Set up the execution environment.
  3. Pass system information to the kernel
  4. Transfer control to the kernel's entry point.

But the kernel starts from scratch – it doesn't automatically know:

  • Where it was loaded from
  • The system's memory layout
  • Command-line arguments
  • Graphics/framebuffer info
  • What modules were loaded

Without this info, the kernel cannot:

  • Allocate memory safely
  • Mount an initial file system
  • Display graphics
  • Or even print debug output

That's why passing data from the bootloader is essential – the kernel relies on it to initialize the system correctly.

What data is passed?

Common data passed includes:

Data TypeWhy It’s Needed
Memory MapTo know usable vs. reserved memory
Framebuffer InfoFor graphics / GUI init
Boot ArgumentsKernel parameters (e.g., root=/dev/sda1)
ModulesInitramfs, drivers, etc.
Boot Device InfoTo find root disk
ACPI/SMBIOS InfoFor power management, system info

What is the Boot Descriptor Structure?

The boot descriptor structure (often referred to as the multiboot information structure) is a data structure populated by the bootloader and passed to the kernel. This structure provides information about the system’s memory, boot device, command-line arguments, and more. GRUB or any multiboot-compliant bootloader will fill in this structure after loading the kernel.

struc OsBootDescriptor
	.KernelAddr 	resd 	1  ; Address where kernel is loaded
	.KernelSize		resd 	1  ; Size of the kernel
	.RamDiskAddr	resd 	1  ; Address of the RAM disk
	.RamDiskSize 	resd 	1  ; Size of the RAM disk
	.ExportAddr		resd 	1  ; Export table address
	.ExportSize		resd 	1  ; Size of the export table
	.SymbolsAddr	resd	1  ; Symbol table address
	.SymbolsSize	resd	1  ; Size of the symbol table
endstruc

Each resd 1 reserve a 32-bit value (4 bytes), so the total structure size is 8 * 4 = 32 bytes.

How It's Used

  • Bootloader fills this structure with information after loading the kernel.
  • Then it is passed to the kernel – typically via a register like ESI or EBX.

What is the Multiboot Header?

Definition:

The Multiboot header is a data structure embedded inside the kernel binary, usually near the beginning (within the first 8 KB). It tells the bootloader how to load the kernel, where to find it, and what options are required.

  • A special structure placed at the start of the kernel binary.
  • GRUB (or another Multiboot bootloader) searches for this structure to:
    • Validate the kernel
    • Know how to load it
    • Know what information to pass to the kernel

It's part of the Multiboot Specification, and must meet specific requirements.

  • Aligned on a 4-byte boundary
  • Located within the first 8 KB of the kernel binary
  • Starts with a fixed magic number

The header typically includes details about the memory layout, entry point, flags, and other relevant information required by the bootloader to load the kernel correctly.

struc MultiBoot
	.Flags				resd	1 ; What field are valid
	.MemoryLo			resd	1 ; Lower memory (KB)
	.MemoryHi			resd	1 ; Upper memory (KB)
	.BootDevice			resd	1 ; BIOS boot device
	.CmdLine			resd	1 ; Address of kernel command line
	.ModuleCount		resd	1 ; Number of loaded modules
	.ModuleAddr			resd	1 ; Address of first module
	.Symbols0			resd	1 ; Depends on flags
	.Symbols1			resd	1
	.Symbols2			resd	1
	.Symbols3			resd	1
	.MemMapLength		resd	1 ; Length of memory map
	.MemMapAddr			resd	1 ; Address of memory map
	.DrivesLength		resd	1 ; Drive info length
	.DrivesAddr			resd	1 ; Drive info address
	.ROMConfigTable		resd	1 ; ROM config table
	.BootLoaderName		resd	1 ; ASCII string with bootloader name
	.ApmTable			resd	1 ; APM table (for power management)
	.VBEControllerInfo	resd	1 ; VESA BIOS Extensions (VBE) info
	.VBEModeInfo		resd	1
	.VBEMode			resd	1
	.VBEInterfaceSeg	resd	1
	.VBEInterfaceOff	resd	1
	.VBEInterfaceLen	resd	1
endstruc

This structure is populated by the bootloader and passed to the kernel in register EBX(for 32-bit kernels).

https://github.com/The-Jat/TheTaaJ/tree/edb7f3941c0f5992357272be9e8ebb362c7861c3

Leave a comment

Your email address will not be published. Required fields are marked *