FreeSourceCodes.com

Inside the Boot Sector

Writing a boot sector code is a reasonably straight forward process. You just need to understand a few things first.

What is a Boot Sector?

The Boot Sector is the first sector of a disk - the first on the track 0 and side 0. A valid Boot sector would have the word 0x0AA55 at offset 510. 

On an IBM PC, after performing POST, the BIOS  routines look for a valid Boot Sector. If it finds one, it loads it (the whole 512 bytes) into memory at address 0x7C00 and jumps to this code. You need to remember that it jumps to the address 0:7C00h - that is the CS register contains a 0000h and the IP contains 7C00h. So what ever code you put in there executes. :)

You need to remember the following.

1.    The Boot Sector signature 0x0AA55 at offset 510

2.    The start address of execution is 0:7C00h

Ready for some sample code?

1.    Skeleton code

2.    A boot sector that just prints dots on the screen 

3.    A boot sector that recognizes the Ext2 File system and loads a file with inode number 5 (the boot inode number)  

How do I compile the boot sector code?

    I use NASM to compile my code. Remember to compile the code into plain binary. This is the command that does it with NASM

nasm boot.asm -l boot.lst -o boot.bin  

Boot.bin will now contain the binary code

How do I get the code into the boot sector?

1.    Well, I personally prefer to use Hex Workshop to copy the binary code into the boot sector. I open the boot.bin file mark and copy the code then open my boot device (floppy) and paste it into the first sector.

2.    An alternative is to use DEBUG.EXE

C:\DEBUG.EXE BOOTSTRAP.BIN 
-W 100 0 0 1 
-Q

Related Links

VnutZ's Domain - BootStrap Tutorial

Boot Sector Overview - by Chris Lattner

Click here to contact me.

Last updated on 08-November-2002

Free Downloads