The BIOS
6
kernel
Copyright(c)1992-2013TheFreeBSD↺
Project.
Copyright(c)1979,1980,1983,1986,↺
1988,1989,1991,1992,1993,1994
TheRegentsoftheUniversityof↺
California.Allrightsreserved.
FreeBSDisaregisteredtrademarkofThe↺
FreeBSDFoundation.
FreeBSD10.0-RELEASE#0r260789:ThuJan↺
1622:34:59UTC2014
root@snap.freebsd.org:/usr/obj/usr/src/
sys/GENERICamd64
FreeBSDclangversion3.3(tags/RELEASE_33/
final183502)20130610
a
This prompt will appear if the user presses a key just after selecting an OS to boot at the boot0 stage.
1.3.The BIOS
When the computer powers on, the processor's registers are set to some predefined values. One of the registers is
the instruction pointer register, and its value after a power on is well defined: it is a 32-bit value of 0xfffffff0 . The
instruction pointer register (also known as the Program Counter) points to code to be executed by the processor.
Another important register is the cr0 32-bit control register, and its value just after a reboot is 0. One of cr0's bits,
the PE (Protection Enabled) bit, indicates whether the processor is running in 32-bit protected mode or 16-bit real
mode. Since this bit is cleared at boot time, the processor boots in 16-bit real mode. Real mode means, among other
things, that linear and physical addresses are identical. The reason for the processor not to start immediately in
32-bit protected mode is backwards compatibility. In particular, the boot process relies on the services provided
by the BIOS, and the BIOS itself works in legacy, 16-bit code.
The value of 0xfffffff0 is slightly less than 4GB, so unless the machine has 4GB of physical memory, it cannot
point to a valid memory address. The computer's hardware translates this address so that it points to a BIOS mem-
ory block.
The BIOS (Basic Input Output System) is a chip on the motherboard that has a relatively small amount of read-only
memory (ROM). This memory contains various low-level routines that are specific to the hardware supplied with
the motherboard. The processor will rst jump to the address 0xf0, which really resides in the BIOS's memory.
Usually this address contains a jump instruction to the BIOS's POST routines.
The POST (Power On Self Test) is a set of routines including the memory check, system bus check, and other low-
level initialization so the CPU can set up the computer properly. The important step of this stage is determining the
boot device. Modern BIOS implementations permit the selection of a boot device, allowing booting from a floppy,
CD-ROM, hard disk, or other devices.
The very last thing in the POST is the INT 0x19 instruction. The INT 0x19 handler reads 512 bytes from the
rst sector of boot device into the memory at address 0x7c00 . The term rst sector originates from hard drive
architecture, where the magnetic plate is divided into a number of cylindrical tracks. Tracks are numbered, and
every track is divided into a number (usually 64) of sectors. Track numbers start at 0, but sector numbers start
from 1. Track 0 is the outermost on the magnetic plate, and sector 1, the rst sector, has a special purpose. It is
also called the MBR, or Master Boot Record. The remaining sectors on the rst track are never used.
This sector is our boot-sequence starting point. As we will see, this sector contains a copy of our boot0 program.
A jump is made by the BIOS to address 0x7c00 so it starts executing.
1.4.The Master Boot Record (boot0 )
After control is received from the BIOS at memory address 0x7c00 , boot0 starts executing. It is the rst piece of
code under FreeBSD control. The task of boot0 is quite simple: scan the partition table and let the user choose