The Boot Sequence

Recently I have been entering into the realm of operating system development. Taking this into account it only seems logical that I would do some posts that would relate to this subject. Said posts are eventually going to be part of a larger resource that is currently under construction, so please stay tuned for that announcement.
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
BIOS begins its POST duties when the CPU resets. POST can also alert you of hardware errors by way of beep codes and diagnostic codes.
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:
OffsetSize (bytes)Description
0x001Boot indicator (0x80=bootable, 0x00=not bootable)
0x011Starting head number
0x022Starting cylinder number (10bits) and sector(6 bits)
0x041Descriptor (Type of partition/filesystem)
0x051Ending head number
0x062Ending cylinder and sector numbers
0x084Starting sector (relative to the beginning of the disk)
0x0C4Number of sectors in partition
The MBR is usually written by the disk partitioning program.
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
This doesn't need to be done in this order, but it all has to be done before kmain() can be called (the main kernel function).

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.

Share this post!

Bookmark and Share

0 comments:

Post a Comment

Our Recent Videos


Contact Us!Popular:   WindowsLinuxInternet

Shop Amazon