Forge

ForgeOS64 — a 16-to-64-bit boot chain in pure Forge

A real-mode → long-mode boot chain written entirely in Forge — no inline assembly anywhere. It is the reference implementation of the x86_64 raw kernel target and lives in examples/os64/.

Three stages

Stage Source Output Sectors (LBA) Loaded at
1 — boot sector src/boot/boot.dev build/boot.bin 0 0x7C00 (BIOS)
2 — loader src/boot/loader.dev build/loader.raw 1–2 0x9000
3 — kernel src/kernel/kernel.dev build/kernel.raw 3–10 0x100000 (physical)

Before switching, the builtin probes CPUID for long-mode support (leaf 0x80000001’s LM bit, guarded by the max-extended-leaf check) and, on a 32-bit-only CPU, prints No 64-bit CPU over COM1 and halts instead of triple-faulting.

Build and run

cargo build --release
./examples/os64/build.sh             # assemble build/os64.img
./examples/os64/build.sh run         # ...and boot it in QEMU
qemu-system-x86_64 -accel tcg,thread=multi \
    -drive file=examples/os64/build/os64.img,format=raw,if=ide -nographic

Expected output:

ForgeOS64: loading kernel: ok
ForgeOS64: hello from 64-bit long mode

The kernel then halts.

Linker descriptors

The kernel alone can be built with:

./target/release/forgec kernel.dev -o kernel.raw --linker examples/os64/os64-kernel.fld

The kernel uses std.hal for its serial and VGA setup — port I/O through typed wrappers, no extern declarations.

Testing

QEMU integration tests cover the full chain: os64_boot_chain_enters_long_mode boots the three-stage image and asserts the 64-bit banner; os64_32bit_cpu_guard_halts verifies the CPUID guard falls back gracefully on a 32-bit-only CPU. They need qemu-system-x86_64 on PATH.