π§ Simple x86 Bootloader with BIOS Sector Read
This project is a simple 16-bit bootloader written in x86 Assembly that demonstrates how to read a specific disk sector using BIOS interrupt INT 13h. It is designed for floppy disk emulation (e.g., in QEMU) and uses BIOS services to print messages and load data from the disk.
π Project Structure
.
βββ asm/
β βββ disk\_read.asm # Reads one disk sector using BIOS INT 13h
β βββ print.asm # BIOS-based print functions (char, string)
β βββ stage1\_bootloader.asm # Main bootloader (runs at 0x7C00)
βββ build/
β βββ bootloader.bin # Compiled bootloader binary
βββ README.md # Project documentation
π§Ύ Features
- Reads sector 2 from a floppy disk using BIOS interrupt β¦
π§ Simple x86 Bootloader with BIOS Sector Read
This project is a simple 16-bit bootloader written in x86 Assembly that demonstrates how to read a specific disk sector using BIOS interrupt INT 13h. It is designed for floppy disk emulation (e.g., in QEMU) and uses BIOS services to print messages and load data from the disk.
π Project Structure
.
βββ asm/
β βββ disk\_read.asm # Reads one disk sector using BIOS INT 13h
β βββ print.asm # BIOS-based print functions (char, string)
β βββ stage1\_bootloader.asm # Main bootloader (runs at 0x7C00)
βββ build/
β βββ bootloader.bin # Compiled bootloader binary
βββ README.md # Project documentation
π§Ύ Features
- Reads sector 2 from a floppy disk using BIOS interrupt
INT 13h. - Loads the sector into memory at
0x0000:0500. - Displays custom messages using BIOS interrupt
INT 10h. - Demonstrates modular assembly structure with reusable print and disk functions.
π Getting Started
π§ Prerequisites
Ensure the following tools are installed:
- NASM β Assembler for x86 architecture
Install with:
sudo apt install nasm(Linux) or from https://www.nasm.us/ - QEMU β Emulator to run the bootloader
Install with:
sudo apt install qemu-system-x86or from https://www.qemu.org/ - Unix-like terminal (Linux, macOS, WSL, or Git Bash on Windows)
βοΈ Build Instructions
# 1. Assemble the bootloader
nasm -f bin asm/stage1_bootloader.asm -o build/bootloader.bin
# 2. Create a 1.44MB floppy disk image
dd if=/dev/zero of=build/os_image.img bs=512 count=2880
# 3. Write the bootloader to sector 1 (boot sector)
dd if=build/bootloader.bin of=build/os_image.img conv=notrunc
# 4. Write test data to sector 2 (512-byte sector)
echo -n ">> Sector 2 loaded!" | dd of=build/os_image.img bs=512 seek=1 conv=notrunc
π§ͺ Run with QEMU
qemu-system-x86_64 -boot a -fda build/os_image.img
You should see the following output in the QEMU window:
Reading sector 2...
>> Sector 2 loaded!
π§ How It Works
Bootloader Flow:
- BIOS loads boot sector (512 bytes) to
0x7C00and jumps to it. - Bootloader initializes segment registers (DS, ES).
- Displays message
"Reading sector 2..." - Calls
read_sector, which uses BIOSINT 13hto read sector 2 - If read succeeds, it prints the content of memory at
0x0500
Key BIOS Calls:
INT 10h / 0Eh: Print character in text modeINT 13h / 02h: Read sectors from disk
π οΈ Modular Assembly
print.asm: Provides reusable routines to print characters and strings.disk_read.asm: Abstracts BIOS sector read into a callable subroutine.stage1_bootloader.asm: Main bootloader logic, includes the other modules.
π Notes
- This project assumes the boot device is a floppy (
DL = 0x00). ChangeDLto0x80if using hard disk emulation. - The sector read logic is minimal and may fail silently if BIOS returns an error.
- BIOS limits restrict this to CHS access; advanced support (e.g., LBA) is not included here.
π References
π License
This project is open-source and licensed under the MIT License.
π¨βπ» Author
Aayush Gid Electronics & Communication Engineering Driven by systems programming, embedded systems, and OS dev.