Booting/Bootloader
From WhitixDoc
| |
arch/i386/boot/iso/isoboot.asm
| |
| This file is compiled and placed at the beginning of the ISO image. |
The Whitix bootloader loads the kernel and a setup file into main memory from a filesystem, and then executes the loaded code.
This article covers the ISO bootloader, which is currently the only one supported. The ISO bootloader's code was based on IsoLinux, written by Peter Anvin.
At the very start
The BIOS loads a 2048 byte sector from the CD into memory location 0x7C00. The BIOS then transfers control to the bootloader, which begins by disabling interrupts (line 7) and jumping over the ISO boot table (line 8).
Now the bootloader has space to perform a number of early setup tasks while the CPU is in 16-bit mode:
- Setting up the stack pointer and segment. (line 22). The stack, which expands downwards, is placed at 0x7C00, and the stack segment register
ssis set to zero. - Zeroing the segment registers. (line 26).
ds,es,fsandgsare all set to zero to ensure a consistent view of memory for each segment register. - Saving the BIOS drive number. (line 32). The drive number represents the driver the BIOS booted from, which may be useful to the kernel at a later stage.
- Enabling interrupts. (line 33). The interrupts were initially disabled so the stack pointer and segment could be set atomically.
- Switching to text mode. (line 37). The bootloader calls the BIOS to set the graphical mode to a text-based one. This enables text to be output to the screen in case of an error, and allows the kernel startup text to be displayed.
- Printing "Loading..". (line 41). Confirms Whitix is being loaded.
Drive setup
The bootloader then retrieves information about the CD drive it was booted from. It zeroes out the spec packet buffer (line 44), and the BIOS fills in the data structure (line 64). The bootloader uses the information from the BIOS to check it has booted from the right CD drive (line 69). If it has, the bootloader continues on to set up the ISO filesystem code.
However, some Award BIOSes are unable to process this drive information call, and so Whitix notifies the user that they have a broken BIOS. (line 78) If the call fails on a normal BIOS (for whatever reason), the bootloader retries the BIOS call 255 times. (line 82). If the bootloader still cannot resolve the BIOS drive number, it halts with "Cannot locate the CD-ROM drive." (line 121)
ISO filesystem setup
First of all, to locate the root directory, the bootloader reads the primary volume descriptor into memory. (line 310)
- This short article needs expansion or improvement. Why not help?
| Developer manual > Kernel overview > Booting/Bootloader |