A Sampling of the x86 Bootstrap Process

Looking forward to a three day weekend, I thought about what I could do to pretty much relax from work. I have always been curious about the bootstrap process on a PC, but I never had the time or skill to understand the assembly language and process involved in writing one. After having exposure to proprietary assembly languages at work, I decided to revisit the x86 assembly language, which is the first low-level language that I’ve encountered and should know as a software developer who started computing on an “IBM-compatible” machine, and study example bootstrap code.

My first “Hello, World” program toward a functional bootstrap code is VnutZ’s minimalist bootstrap code:

     [BITS 16]
     ORG 0
     int 0x18
     
     TIMES 510-($-$$) DB 0
     DW 0xAA55


The above code is input to the assembler, and the resulting binary file is written out to the first sector of a disk. The BITS directive sets the target processor mode. According to VnutZ, the processor is in 16-bit real mode when processing is handed off to the bootloader. The ORG directive specifies “the origin address which NASM will assume the program begins at when it is loaded into memory.” The x86 assembly instruction, int 0x18, is a BIOS interrupt call to have the BIOS interpret BASIC code in the ROM. The TIMES directive is used to write zeros after the sole assembly instruction up to and including the 510th byte. The value, 0x55, is written for the 511th byte, and 0xAA is written for the 512th byte. This marker value indicates to the BIOS that a valid bootloader application resides in the sector when the BIOS inspects it.

A personal copy of the PC Bootsector Programming Tutorial in ASM for future reference is found here.
Questions, comments, and responses are welcomed and appreciated.

Leave a Reply