This project implements a multi-stage bootloader shim designed to transition from a 32-bit Multiboot environment (like QEMU's -kernel option) or a 64-bit UEFI environment back to 16-bit real mode. The included MS-DOS boot is provided as an example payload.
The QEMU -kernel code path successfully loads and executes the MS-DOS io.sys file. Upon execution, io.sys displays:
Non-System disk or error
Replace and press any key when ready
This error occurs because no formatted hard drives are available for DOS to read from. The MS-DOS payload is included as an example and served as the initial motivation for the project.
- Implement INT 0x13 HDD simulation pointing to an in-memory FAT12 disk image containing
msdos.sysandcommand.com - Initialize VGA BIOS after exiting UEFI to enable VGA functionality for real-mode applications on modern 64-bit computers
- Test on real hardware
- Develop a driver for mounting DOS RAM drives in extended memory, accessible to real-mode DOS, potentially using techniques similar to EMM386 (hosting real-mode DOS in a virtual machine)
The boot process consists of three stages, with different entry points depending on the boot method:
- Stage 2 (
realmode.asm):- Mode: 16-bit Real Mode
- Entry: 0x4000 (0x0400:0x0000)
- Function: Sets Video Mode 3 (80x25 VGA), loads the embedded MS-DOS
io.systo 0x0070:0x0000, and executes it.
- Stage 0 (
loader.asm):- Mode: 32-bit Protected Mode
- Entry: 0x100000 (Multiboot)
- Function: Copies Stage 1 to 0x3200 and jumps to it.
- Stage 1 (
stage1_32_protected.asm):- Mode: 32-bit Protected Mode
- Entry: 0x3200
- Function: Copies Stage 2 to 0x4000, switches to 16-bit Real Mode, and jumps to Stage 2.
- UEFI Loader (
uefi_loader.c):- Mode: 64-bit Long Mode (UEFI)
- Function: Allocates memory at 0x1000, copies the Trampoline to 0x1000 and Stage 1 to 0x3200, sets Console Mode 0, exits Boot Services, and jumps to the Trampoline.
- Trampoline (
uefi_entry.asm):- Mode: 64-bit Long Mode
- Entry: 0x1000
- Function: Switches CPU to 32-bit Compatibility Mode, disables Paging/Long Mode to enter 32-bit Protected Mode, and jumps to Stage 1 at 0x3200.
- Stage 1 (
stage1_32_protected.asm):- Mode: 32-bit Protected Mode
- Entry: 0x3200
- Function: Same as Legacy Path (Copies Stage 2, switches to Real Mode).
- NASM: Assembler
- GCC: C Compiler (native Linux)
- GNU-EFI: UEFI development libraries (
libgnuefi,libefi) - QEMU: Emulator (
qemu-system-i386andqemu-system-x86_64) - OVMF: UEFI Firmware for QEMU
To assemble and link the kernel:
makeTo boot the kernel in QEMU:
make runTo build the UEFI application (BOOTX64.EFI):
make -f Makefile.uefiTo run the UEFI application in QEMU:
make -f Makefile.uefi runTo remove build artifacts:
make clean
make -f Makefile.uefi clean