If you Like Our Blog Then

Sunday, August 3, 2008

How does a computer boot ?

0 comments

I have this idea of developing a bootstrap program which allows one to load iso images directly from hard disk. This can have real advantage where a system is lacking cd/dvd writer and has bootable iso images lying around on hard disk. However as simple as it may sound, bootstrap or boot loader is a very critical code in a computer system.

Bootstrap is a small program loaded by BIOS upon system startup. BIOS has no information about environment required by OS and thus cannot do anything to initialize the system beyond putting hardware in a known state. This is where bootstrap program comes to play. BIOS loads bootstrap program from a fixed location and transfers control to it. OS specific bootloaders either load operating system itself or perform a multi-stage boot by loading a more complex and advanced initialization program. It's the bootstrap's responsibility to load code and build an appropriate operating environment.

Basics of Bootstrap

A bootstrap is loaded from 1st sector of disk, track 0, head 0, sector 1. Which disk the bootstrap is loaded from is dependent on BIOS configuration saved in NVRAM. This single 512 byte sector is loaded in memory at physical address 0000:7C00. The BIOS then examines final two bytes of bootstrap (offset 1FEh) for value AA55h. If final two bytes are AA55h then it's a valid bootstap and disk is bootable. A bootstrap must be exactly 512 bytes long. After verifying a bootstrap, BIOS jumps to 0000:7C00 and turn control over to bootstrap.

Another important fact about bootstrap is that it's a 16bit code. This limitation is due to the fact that during the period when BIOS is making a jump to bootstrap, CPU is still executing in 16bit Real Mode.

Simplest bootstrap code could be as follows:

;**************************
[BITS 16]
[ORG 0x7C00h]

INT 0x18

TIMES 510-($-$$) db 0
dw 0xAA55h
;**************************

We can compile this code using nasm as follows:

nasm bootstrap.asm -o bootstrap.bin

One can add functionality to this bootloader by loading another program through this bootstrap which doesn't have to obey 512bytes limitation and thus can have more functionality and also which can execute in 32bit Protected Mode.

I guess I'd post more on this issue later, when I'm through with my own bootstrap. Till then happy coding....

Advertisements

0 comments:

Post a Comment

No Abusive comment will be approved. Make comment related to Topic only.

Enter your email address:

Delivered by FeedBurner