The Beginning: Booting your PC
CS 321 Lecture,
Dr. Lawlor, 2006/01/23
Announce the now-complete HW1 on the PC bootloader.
The Silberschatz book has just two pages on the boot loader: pages 463 &
464. System calls are documented in more detail, in section 2.3.
How a PC boots
The boot sequence on an IBM PC is initiated by the BIOS (Basic
Input/Output System) stored in the computer's ROM (Read-Only
Memory).
Actually, everything in that sentence is partially a lie:
- IBM PC's aren't made by IBM anymore. They're made by Dell,
HP, Compaq, and a zillion other manufacturers. IBM sold off its
PC business to the Chinese Lenovo Group in late 2004. What we've
meant by "IBM PC" for the last twenty years is actually "PC's that are
compatible with the software that used to run on actual IBM PC's", like
MS-DOS.
- The BIOS isn't very Basic (typical BIOS is a few hundred
kilobytes compressed), and hasn't been used for Input/Output since the
DOS days (modern OS's invariably talk directly to hardware to do
I/O). I guess it's still a System.
- The BIOS isn't stored in ROM anymore, since it's so complicated
it now has bugs. Thus it's stored on a chunk of flash memory,
which you can upgrade with a BIOS update.
Er, so back to the the booting process.
- Power flows into the CPU.
- The CPU is wired to begin executing code out of its own
internal ROM (or flash memory). This is called "microcode", and
is set up at the CPU factory. The CPU initializes itself (e.g.,
clears out its registers and cache, and puts itself into a known good
state), and performs a self-test.
- Once the CPU self-test passes, the CPU jumps to a known location
in memory, which is hardwired on your motherboard to point to your
motherboard's ROM (er, flash memory).
- Your motherboard's ROM contains a piece of software called the
"BIOS" that has just one purpose: to load up the *real* operating
system. This is harder than it sounds, because the operating
system might be stored on:
- A floppy disk, controlled by the floppy drive controller
- A CD-ROM drive, controlled via ATAPI (SCSI over IDE) on the IDE controller
- A SCSI disk, controlled via SCSI commands on the SCSI controller
- A USB mass storage device, controlled via the USB controller
- An IDE hard disk (Of course, the OS is almost always actually here. Except when it's not.)
- Once the BIOS finds a bootable disk, it loads up the "boot
sector" (a disk sector, or disk block, of just 512 bytes) and executes
it in 16-bit mode. Why? Because the original 8086 IBM PC
back in 1981 executed the boot sector in 16-bit mode, that's why.
It was good enough for 1981, why isn't it good enough today? Huh?
In a perfect world, the boot sector would actually be the kernel (more
on that in a minute) of the operating system. Sadly:
- The boot sector is run in 16-bit addressing mode, which limits
you to 64KB at a time. Of course, by switching segments, you can
access a whopping 1MB of memory in 16-bit mode. Of that 1MB,
chunks are reserved for display memory (0xA????), the network card, the
BIOS code (0xF????), etc., so you're actually limited to 640K of real
RAM in 16-bit mode. (See Memory Maps of the ancient world.)
- The boot sector is 512 *bytes*. Wow.
The standard thing to do from inside a boot sector is to load up the
*real* OS loader ("bootloader") from disk. The first 64 sectors
of the disk are reserved for this, so the real bootloader can be up to
32K. Known bootloaders include:
- NTLDR.COM, the Windows NT bootloader. It uses "boot.ini"
- LILO, the LInux LOader. It uses a compiled-in "/etc/lilo.conf" file.
- GRUB, the new Linux bootloader. It's configurable at runtime.
The bootloader then loads up the real OS. So the boot sequence is overall the following amazing cascade:
- CPU internal microcode
- BIOS code
- Boot sector
- Bootloader (possibly multi-stage!)
- OS
- Applications!