This turns the MMUKO boot idea into a tiny QEMU-bootable kernel.
Important distinction:
mmuko-boot.cfrom the gist is a normal hosted C program. It usesprintf,malloc,calloc, and the host OS C runtime.- QEMU boots firmware, boot sectors, kernels, or disk images. At boot time there is no hosted C runtime, so MMUKO needs to run as freestanding code.
This scaffold supports two boot paths.
This path uses the tools already common in a MinGW + QEMU setup:
asgccldqemu-system-i386
Build the raw boot image:
.\build-direct.ps1Run it:
qemu-system-i386 -drive format=raw,file=build\mmuko-direct.img,if=ide,index=0 -display none -serial stdio -no-rebootThe kernel deliberately halts at the end, so QEMU will keep running until you
stop it with Ctrl+C.
The direct boot path works like this:
boot16.sstarts as a 512-byte BIOS boot sector.- It loads
kernel-flat.binfrom disk LBA 1 into memory at0x10000. - It switches to 32-bit protected mode.
- It jumps into
kernel-entry.s. kernel-entry.scallskernel_main()inkernel.c.
The GRUB path uses GRUB Multiboot as the loader:
- GRUB starts the kernel in 32-bit protected mode.
kernel_main()initializes screen and serial output.mmuko_boot()runs the MMUKO boot phases.mmuko_program_main()runs after boot succeeds.
boot.asm- Multiboot entry point and stack setup.boot16.s- Direct BIOS boot sector.kernel-entry.s- Direct boot flat-kernel entry point.kernel.c- Freestanding MMUKO boot model and example MMUKO program.linker.ld- Places the kernel at 1 MiB for GRUB.linker-flat.ld- Places the direct boot kernel at0x10000.grub.cfg- GRUB menu entry.Makefile- Builds an ISO and runs it in QEMU.build-direct.ps1- Builds the direct BIOS boot image on Windows.
The easiest path on Windows is WSL or MSYS2 with:
nasmi686-elf-gccgrub-mkrescuegrub-filexorrisoqemu-system-i386make
On a Debian/Ubuntu-like environment, QEMU/GRUB/NASM can usually be installed with:
sudo apt install make nasm grub-pc-bin grub-common xorriso qemu-system-x86You still need an i686-elf-gcc cross compiler. If you do not have one yet,
use an OSDev-style cross compiler, or adapt the Makefile to your existing
freestanding i386 compiler.
make
make runQEMU will show VGA text, and the same log is also written to serial with
-serial stdio.
Edit this function in kernel.c:
static void mmuko_program_main(MMUKO_System *sys)That function is the first MMUKO "program" in this scaffold. It only runs after
mmuko_boot(sys) returns BOOT_OK.
Later, you can replace it with a loader that reads a separate payload from disk and jumps to it, but compiling the program into the kernel is the simplest way to experiment with QEMU first.