Go to the previous, next section.
This is the process that gains control when the machine is first booted up and continues up until the kernel gains control. It has to perform the startup functions required of any standard operating machine.
The Boot loader is the first part of the system to be executed. When it is loaded, it initially checks to see if the disk is marked as a system disk. If not, it prints a message onto the screen telling the user this and asking him to reboot. If the disk is found to be a system disk, then the boot media byte is retrieved from the boot sector and this is then used to determine the characteristics of the boot media.
The first thing done by the loader program is to perform a GROPE (General
Reconnaissance of Peripheral Equipment) to determine the available hardware.
The first step is to determine the model of CPU and FPU in the system and then
find the standard hardware available in the machine which includes the memory,
display, serial and parallel ports and the disk subsystem. The CPU is also
examined to see what operating mode it is running in. The information found
by the hardware search is written into the cookie
structure to be later
accessed by the kernel.
If the system check determines that an 80386 or greater processor is available and it is operating in Real Mode then execution can continue. At this point it should be noted that all code executed prior to this stage is written to execute on any Intel processor from the 8088 upwards. If an incompatible processor is detected then a message informing the user of this is displayed and the machine halted. The kernel is located on the disk by means of information present in the boot sector and is loaded to a known location by the kernel loader.
Once the kernel is loaded, the hardware is setup to a known state so that there are no unexpected hardware problems for the kernel. The following hardware was set to a known state:
This is required for initial entry into Protected Mode with paging enabled. The Page directory is setup with the following entries:
After this, the page tables for the kernel are setup, providing the mapping
from its logical address to its physical address. A null entry is also
added at logical address 0 to capture stray pointer references.
CR3
(Control Register 3) is then loaded with the physical
address of the Page Directory
The GDT (Global Descriptor Table) and IDT (Interrupt Descriptor Table) are staticly allocated so the appropriate descriptor table register are loaded with pointers to these tables.
The final part of the 16bit initialisation if the transition from 16-bit Real
Mode to 32-bit Protected Mode. This is accomplished by setting bits 0 and 31
to 1 in CR0
(Control Register 0). Immediately after this a far jump is
performed to the kernel's 32-bit entry point. This far jump is required to
flush the prefetch queue of the processor because instructions in this queue
would have been decoded as 16-bit instructions and could have be fetched from
the wrong address because the processor was not using the paging system at
the time. At this point the processor enters a flat-model 32-bit protected
mode operating state.
The 32-bit setup provides the `glue' between the 16-bit initialisation and
the call to the kernel's main
function. The action taken by this setup
is as follows:
DS
, ES
, FS
, GS
and
SS
are set to point to the kernel data selector.
ESP
(stack pointer) is set to point to a valid stack area.
CR3
reloaded with the Page
Directory to flush the TLB (Translation Lookaside Buffer).
main
function is called and execution of the C portion
of the kernel starts.
Go to the previous, next section.