Summary
The QEMU x86-64 OS named DOS-OS failed to boot, displaying “No bootable device found” despite having a complete implementation, including battery detection, file system, and a 512-byte main.asm with the magic number 0xAA55. The issue stems from improper memory layout configuration and BIOS interrupt handling, preventing the BIOS from locating the bootable kernel.
Root Cause
- Missing Memory Layout: The OS lacked a defined memory map, causing the BIOS to fail in locating the boot sector.
- Incorrect BIOS Interrupt Handling: The BIOS could not identify the bootable kernel due to improper interrupt setup.
- Bootloader Misalignment: The bootloader was not placed at the correct memory address (typically 0x7C00), rendering it invisible to the BIOS.
Why This Happens in Real Systems
- Memory Layout is Critical: Real systems rely on a predefined memory map to locate bootable components.
- BIOS Expectations: The BIOS expects the bootloader to be at 0x7C00 and to handle interrupts properly.
- Magic Number Alone is Insufficient: While 0xAA55 is necessary, it is not sufficient without proper memory and interrupt configuration.
Real-World Impact
- Boot Failure: The OS becomes unbootable, halting development and testing.
- Wasted Resources: Time spent on features like battery detection and file systems is rendered useless until the boot issue is resolved.
- Debugging Complexity: Without a clear memory layout, diagnosing boot failures becomes significantly harder.
Example or Code (if necessary and relevant)
[org 0x7C00] ; Ensure bootloader starts at the correct address
mov si, msg
call print_string
jmp $
msg db 'DOS-OS Bootloader', 0
print_string:
mov ah, 0x0E ; BIOS teletype function
.repeat:
lodsb
or al, al
jz .done
int 0x10
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Padding
dw 0xAA55 ; Boot sector magic number
How Senior Engineers Fix It
- Define Memory Layout: Explicitly map the bootloader, kernel, and other components in memory.
- Place Bootloader at 0x7C00: Ensure the bootloader is loaded at the BIOS-expected address.
- Handle BIOS Interrupts Properly: Implement interrupt routines for disk reads and other BIOS services.
- Test with Debugging Tools: Use QEMU’s
-d intflag to trace interrupts and verify memory access.
Why Juniors Miss It
- Overlooking Memory Layout: Juniors often assume the BIOS will automatically locate the bootloader.
- Ignoring BIOS Requirements: Lack of awareness about the 0x7C00 address and interrupt handling.
- Focusing on Features, Not Fundamentals: Spending too much time on advanced features before ensuring basic boot functionality.