Go to the previous, next section.

The Initialisation Process

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.

Boot Loader

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.

Determining Media Characteristics

The aim of this process is to determine the number of heads, cylinders and sectors on the boot media. There are two methods used to achieve this depending on whether the media is a floppy disk or a hard disk.

Hard Disk Media

This can be determined by simply making a call to the BIOS with the appropriate hard disk number. This returns to maximum heads, cylinders and sectors available on the media.

Floppy Disk Media

This requires a different strategy because using the call to the BIOS will only reveal the characteristics of the disk drive and not the disk inside it. Therefore the media is found using a combination of probing and fixed values. The number of heads is set at 2 since all floppy disk drives only have two heads. Since the information about the number of cylinders on a disk is not used this is set at 80. This is a reasonable default since floppy disks only have 40 or 80 tracks, with 40 only being found on older disk systems. The final stage is to probe the disk for the number of sectors per track. This is done by having a list of the possible values for this number and then trying to read the maximum sector off of each track. For example if the test is probing for 18 sectors per track, then an attempt is made to read sector 18. If it passes this is taken as the value to use otherwise the next number in the list is tested. The list must be in descending order for this to work.

Loading The Loader

Because the boot sector only allows for 512 bytes of code and data, it is just enough to load up a more complicated program to initialise the system and load the kernel. The boot sector loads this program up into the high end of conventional memory and then passes execution to it.

System Check

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.

Loading 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.

Setting Hardware To A Known State

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:

Setting Up Page Tables

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

Setting Up Descriptor Tables

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.

Entering Protected Mode

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.

32-bit Setup

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:

Go to the previous, next section.