In this post we will detail the computer's boot sequence. This is intended to provide an in depth look into the process, so if you don't understand something please do not hesitate to ask!
Post
Whenever a computer boots or resets it runs through what is called the POST test. POST stands for Power On Self-Test. This process includes scanning for a bootable device, rather this be the hard disk or cdrom, etc. The main duties of the POST test are handled by the computer's BIOS (Basic Input/Output System). The BIOS may then hand some specialized tasks, such as initialization of some peripheral devices, to another, more specialized application. The main duties of the BIOS during POST are:
- Verify the integrity of the BIOS code
- find, size up, and verify the system's main memory
- discover, initialize, and catalog all the system buses and devices
- pass control to the other specialized programs
- provide the user interface for the system's configuration
- identify, organize, and select the devices that are available for booting
- construct the system environment required by the target operating system
Master Boot Record
A device is bootable only if it carries a boot sector with the byte sequence 0x55, 0xAA in bytes 511 and 512 respectively. When the BIOS locates one of these boot sectors it's loaded into memory at a specific location, most often 0x0000:0x7c00. However, some BIOS' load to 0x7c0:0x0000, which resolves to the same physical address.
If the wrong CS:IP pair is used the absolute near jumps can't work properly. As a result and code like mov ax,cs; mov ds,ax will result in unexpected variable locations. It is considered good practice to maintain CS:IP pairs from the very start of the boot sector. As an example in assembler:
ORG 0x7C00
jmp 0x0000:start
start :
Execution will then be transfered to the loaded boot record. On a hard drive the Master Boot Record (MBR) holds executable code at the offset 0x0000-0x01bd, followed by table entries for the four primary partitions, using 16 bytes per entry, and the two byte signature (0x01fe - 0x01ff). The layout for the table entries are as follows:
| Offset | Size (bytes) | Description |
| 0x00 | 1 | Boot indicator (0x80=bootable, 0x00=not bootable) |
| 0x01 | 1 | Starting head number |
| 0x02 | 2 | Starting cylinder number (10bits) and sector(6 bits) |
| 0x04 | 1 | Descriptor (Type of partition/filesystem) |
| 0x05 | 1 | Ending head number |
| 0x06 | 2 | Ending cylinder and sector numbers |
| 0x08 | 4 | Starting sector (relative to the beginning of the disk) |
| 0x0C | 4 | Number of sectors in partition |
Loading
Now the computer can actually load. When booting from the hard drive there are only 446 bytes available for the boot record. Taking a look at everything involved reveals that this is not much at all:
- Determine which partition to boot from
- determine where the kernel image is located
- load the kernel image into memory
- enable protected mode
- prepare the runtime environment for the kernel
That's the basics of the computer boot sequence. If you have any questions please don't hesitate to ask. You can either post a comment or email me at: adam@lotpblog.com and I'll try my very best to respond to any and all questions.












0 comments:
Post a Comment