Writing a bootloader: learnings

Sarthak Choudhary

  1. The instruction pointer of the CPU, on boot, is hardcoded to the value 0xFFFFFFF0 i.e. the last 16 bytes of the 32-bit address space.

  2. On boot, the BIOS copies itself to some address in memory.
    So, the address contains 0xFFFFFFF0 contains a jump instruction to the place in memory where the BIOS has copied itself.

  3. Once the BIOS is loaded, it goes through the list of devices to check which are bootable: by checking the bytes 511 and 512 of the first sector of each device. If the value of those bytes is 0xAA55, that device is bootable.

  4. Once a bootable device is found, copy the contents of the device’s first sector into memory to the address 0x7c00. This address now contains the bootloader. Jump to this address and execute the code. The bootloader then loads the kernel at 0x100000.

Fun facts:

  1. All x86 processors begin in a 16-bit mode called real mode. The bootloader switches to 32-bit protected mode by setting the lowest bit of CR0 register to 1.

  2. 0xb8000 is the start of video memory. This memory supports 25 lines, each line contains 80 ASCII characters. Each element here is of 2 bytes (1 byte for the ASCII character, 1 byte is the attribute byte like color). So, we can set the color of each character we want to display by writing bytes starting from this address.

Top comments (0)


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Cloudy | #1 secure, private, and affordable online storage solutions. Wishlist urban safari pet.