#!/usr/bin/env bash # Build the kernel with the `headless` feature and boot it in QEMU with no # window. Serial output goes to this terminal; the kernel powers QEMU off via # the isa-debug-exit device when done. A timeout guards against hangs. set -euo pipefail cd "$(dirname "$0")/.." cargo bootimage --features headless IMG=target/x86_64-rust_kernel/debug/bootimage-rust_kernel.bin set +e timeout 30 qemu-system-x86_64 \ -drive format=raw,file="$IMG" \ -device isa-debug-exit,iobase=0xf4,iosize=0x04 \ -serial stdio -display none -no-reboot code=$? set -e # isa-debug-exit: QEMU exit status = (value << 1) | 1, so Success(0x10) -> 33. case $code in 33) echo "[run-headless] kernel exited OK"; exit 0 ;; 35) echo "[run-headless] kernel reported FAILURE"; exit 1 ;; 124) echo "[run-headless] timed out (kernel hung?)"; exit 124 ;; *) echo "[run-headless] QEMU exited with $code"; exit "$code" ;; esac