The Multiboot Specification simplifies the process of initializing the kernel and interact with the hardware by providing a standardized way for bootloaders (like GRUB) to pass essential system information to the kernel. At the heat of this specification lies the Multiboot Information Structure
, a data structure that contains everything the kernel needs to know about the system's hardware and boot environment.
What is the Multiboot Information Structure ?
The Multiboot Information Structure is a data structure passed by a Multiboot-compliant bootloader (e.g., GRUB) to the operating system kernel. It contains detailed information about the system's hardware and boot environment, such as:
- Memory layout (available RAM, reserved memory, etc.).
Boot device information. - Command-line arguments passed to the kernel.
- Loaded modules (e.g., drivers or initramfs).
- Memory map (physical memory regions and their types).
- Other optional information (e.g., BIOS drive data, APM table, etc.).
This structure is passed to the kernel as a pointer, typically in the EBX
register (on x86 architecture), and is essential for the kernel to initialize itself and manage system resources.
It is a variable-sized data structure because some of its fields are optional and depend on the
flags
field.
Why is the Multiboot Information Structure Important?
The Multiboot Information Structure serves as a bridge between the bootloader and the kernel. It provides the kernel with the information it needs to:
1 Initialize Memory Management:
The memory map and memory size fields help the kernel set up its memory manager and avoid using reserved or unavailable memory regions.
2 Process Command-Line Arguments:
The command-line field allows the kernel to receive and process boot-time arguments or configuration options.
3 Load Additional Modules:
The module fields provide information about additional modules (e.g., drivers or initramfs) loaded by the bootloader.
4 Access Hardware Information:
Fields like the boot device, BIOS drive information, and APM table provide details about the system's hardware.
By standardizing this information, the Multiboot Specification ensures compatibility between bootloaders and kernels, making it easier to develop and boot operating systems.
Layout of the Multiboot Information Structure
The Multiboot Information Structure is defined as a C-like structure in the Multiboot Specification. Here is its layout:
struct multiboot_info {
uint32_t flags; // Flags indicating which fields are valid
uint32_t mem_lower; // Amount of lower memory (below 1 MB) in KB
uint32_t mem_upper; // Amount of upper memory (above 1 MB) in KB
uint32_t boot_device; // Boot device (BIOS disk device)
uint32_t cmdline; // Pointer to the command line string
uint32_t mods_count; // Number of modules loaded
uint32_t mods_addr; // Pointer to the first module structure
uint32_t syms[4]; // Symbol table information (deprecated)
uint32_t mmap_length; // Size of the memory map
uint32_t mmap_addr; // Pointer to the memory map
uint32_t drives_length; // Size of the BIOS drive information
uint32_t drives_addr; // Pointer to the BIOS drive information
uint32_t config_table; // Pointer to the ROM configuration table
uint32_t boot_loader_name; // Pointer to the bootloader name string
uint32_t apm_table; // Pointer to the APM (Advanced Power Management) table
uint32_t vbe_control_info; // VBE (VESA BIOS Extensions) control information
uint32_t vbe_mode_info; // VBE mode information
uint16_t vbe_mode; // VBE mode number
uint16_t vbe_interface_seg; // VBE interface segment
uint16_t vbe_interface_off; // VBE interface offset
uint16_t vbe_interface_len; // VBE interface length
};
Key Fields in the Multiboot Information Structure:
1 flags
(uint32_t)
- A bitmask indicating which fields in the structure are valid. Each bit corresponds to a specific field:
- Bit 0: mem_lower and mem_upper are valid.
- Bit 1: boot_device is valid.
- Bit 2: cmdline is valid.
- Bit 3: mods_count and mods_addr are valid.
- Bit 4: syms is valid (deprecated in Multiboot 2).
- Bit 5: mmap_length and mmap_addr are valid.
- Bit 6: drives_length and drives_addr are valid.
- Bit 7: config_table is valid.
- Bit 8: boot_loader_name is valid.
- Bit 9: apm_table is valid.
- Bit 10: vbe_control_info, vbe_mode_info, and related fields are valid.
2 mem_lower
and mem_upper
(uint32_t)
- These fields specify the amount of lower memory (below 1 MB) and upper memory (above 1 MB) in kilobytes. They are valid if Bit 0 of flags is set.
3 cmdline
(uint32_t)
- A pointer to a null-terminated string containing the command line passed to the kernel. This field is valid if Bit 2 of flags is set.
4 mmap_length
and mmap_addr
(uint32_t)
- These fields provide a memory map of the system. The mmap_addr field points to an array of memory map entries, each describing a region of memory. This field is valid if Bit 5 of flags is set.
5 mods_count
and mods_addr
(uint32_t)
- These fields provide information about additional modules loaded by the bootloader. The mods_addr field points to an array of module structures. This field is valid if Bit 3 of flags is set.
6 boot_loader_name
(uint32_t)
- A pointer to a null-terminated string containing the name of the bootloader (e.g., "GRUB"). This field is valid if Bit 8 of flags is set.
Size of the Multiboot Information Structure
The Multiboot Information Structure is a variable-sized data structure because some of its fields are optional and depend on the flag
field. The size of the structure is determined by which fields are valid (as indicated by the flags
bitmask) and which optional fields are present.
Minimum Size of the Multiboot Information Structure:
If only the flags
field is valid (i.e., no optional fields are present), the structure is 4
bytes in size.
Maximum Size of the Multiboot Information Structure:
If all optional fields are present, the structure includes all the fields listed above. Adding up the sizes of all fields:
- flags: 4 bytes
- mem_lower: 4 bytes
- mem_upper: 4 bytes
- boot_device: 4 bytes
- cmdline: 4 bytes
- mods_count: 4 bytes
- mods_addr: 4 bytes
- syms: 16 bytes
- mmap_length: 4 bytes
- mmap_addr: 4 bytes
- drives_length: 4 bytes
- drives_addr: 4 bytes
- config_table: 4 bytes
- boot_loader_name: 4 bytes
- apm_table: 4 bytes
- vbe_control_info: 4 bytes
- vbe_mode_info: 4 bytes
- vbe_mode: 2 bytes
- vbe_interface_seg: 2 bytes
- vbe_interface_off: 2 bytes
- vbe_interface_len: 2 bytes
Total Size: 4 + 4 + 4 + 4 + 4 + 4 + 4 + 16 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + 2 + 2 + 2 + 2 = 72 bytes