1. Boot process: general
To boot an OS we start with the bare hardware and whatever it provides, and load in increasingly large pieces of the OS until we have our system fully up and running. Typically this may involve several stages:
- Load up or have pre-stored some initial bootstrap routine.
- Bootstrap routine finds and initializes storage devices.
Bootstrap routine reads boot loader from some boot device (e.g. a hard drive, CD-ROM, or USB key; or in the bad old days: punch cards, paper tape, cassette tapes).
- Boot loader reads kernel from boot device.
- Kernel initializes rest of hardware.
- Kernel loads user-space startup code.
- Startup code brings up user system.
2. PC architecture
On an x86 PC, the initial bootstrap is handled by the BIOS, which lives in ROM wired onto the motherboard. The BIOS expects to run in real mode (simulating a vintage 1981 8088-based PC), so that's what the system comes up in. The details of the process are as follows:
- BIOS setup.
- On reset, the CPU switches to real mode and jumps to FFFF0. (Really FFFFFFF0, but address gets truncated.) This is the BIOS entry point.
- BIOS executes Power On Self Test (POST).
- BIOS calls initialization routines provided in ROM by video card (at 0xC0000) and disk controller (0xC8000).
- Memory test.
- Look for I/O devices and assign them interrupt vectors.
- Look for bootable drive.
- Boot sector at (0,0,1) tagged with 55 AA marker.
- Load boot sector to address 0000:7c00.
- Jump to boot sector.
- Boot sector.
- Initialize stack.
- SS gets 9000
- SP gets FFFE (for 16-bit mode)
- Load kernel to some standard location, e.g. 0000:1000
- Jump to kernel.
- Initialize stack.
The rest of the setup is up to the kernel, and is likely to include switching to protected mode, setting up memory management and interrupt handling, further device initialization, initializing the filesystem, loading user-space programs, etc.