Mmuko 启动序列 —— 一个在 QEMU 中运行的微型独立 C 内核。
Mmuko Boot Sequence – a tiny freestanding C kernel that boots in QEMU

原始链接: https://github.com/obinexus/mmuko-boot

本项目将 MMUKO 引导模型转换为可独立启动的 QEMU 内核。与托管的 C 程序不同,该实现作为独立代码运行,绕过宿主操作系统运行时,直接在硬件上操作。 该架构支持两种主要的引导路径: 1. **直接 BIOS 引导**:通过自定义的 512 字节引导扇区将内核加载到内存,并切换到 32 位保护模式。 2. **GRUB Multiboot 引导**:使用 GRUB 加载程序在保护模式下初始化内核,这是许多操作系统开发环境的标准做法。 代码库包含上述两种路径的汇编入口点、包含核心引导逻辑的 C 内核,以及用于内存布局的链接脚本。用户可通过修改 `kernel.c` 中的 `mmuko_program_main` 函数进行实验。 构建该环境需要 `i686-elf-gcc` 交叉编译器以及 NASM、QEMU 和 Xorriso(用于创建 ISO)等标准工具。此设置兼容 Windows(通过 WSL/MSYS2)和 Linux,并提供 VGA 和串口输出以供调试。通过将程序直接编译进内核,开发者可以在虚拟化环境中快速测试和迭代 MMUKO 引导模型。

**MMUKO Boot** 是一个实验性的微型独立 C 语言内核,旨在作为操作系统开发的模块化脚手架。它并非作为标准的宿主 C 应用程序运行,而是提供了一个裸机环境,目前支持两种主要的引导路径:512 字节 BIOS 引导扇区和 GRUB Multiboot。 该项目负责处理向 32 位保护模式的转换并执行独立的 `kernel_main()` 函数。它包含了构建最小化操作系统所需的所有核心组件,例如汇编入口点、自定义链接脚本,以及串口和 VGA 输出驱动。该项目支持在 Windows 和 Unix 平台上进行跨平台构建,并设计为可在 QEMU 中运行。开发者正在积极寻求关于项目架构的反馈,旨在构建一个具有稳定 ABI 和可互换组件的小型模块化内核。
相关文章

原文

This turns the MMUKO boot idea into a tiny QEMU-bootable kernel.

Important distinction:

  • mmuko-boot.c from the gist is a normal hosted C program. It uses printf, 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.

Path A: Direct BIOS Boot On This Windows Machine

This path uses the tools already common in a MinGW + QEMU setup:

  • as
  • gcc
  • ld
  • qemu-system-i386

Build the raw boot image:

Run it:

qemu-system-i386 -drive format=raw,file=build\mmuko-direct.img,if=ide,index=0 -display none -serial stdio -no-reboot

The 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:

  1. boot16.s starts as a 512-byte BIOS boot sector.
  2. It loads kernel-flat.bin from disk LBA 1 into memory at 0x10000.
  3. It switches to 32-bit protected mode.
  4. It jumps into kernel-entry.s.
  5. kernel-entry.s calls kernel_main() in kernel.c.

The GRUB path uses GRUB Multiboot as the loader:

  1. GRUB starts the kernel in 32-bit protected mode.
  2. kernel_main() initializes screen and serial output.
  3. mmuko_boot() runs the MMUKO boot phases.
  4. 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 at 0x10000.
  • 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:

  • nasm
  • i686-elf-gcc
  • grub-mkrescue
  • grub-file
  • xorriso
  • qemu-system-i386
  • make

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-x86

You 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.

QEMU will show VGA text, and the same log is also written to serial with -serial stdio.

Where To Write Your Program

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.

联系我们 contact @ memedata.com