#!/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. # # Usage: ./scripts/run-headless.sh # normal boot, exits after ~3 s of timer ticks # ./scripts/run-headless.sh stack-overflow # extra cargo features, comma separated set -euo pipefail cd "$(dirname "$0")/.." cargo build --features "headless${1:+,$1}" # Force bootimage to repack the disk image (see scripts/runner.sh for why). touch target/x86_64-rust_kernel/debug/rust_kernel cargo bootimage --features "headless${1:+,$1}" IMG=target/x86_64-rust_kernel/debug/bootimage-rust_kernel.bin set +e timeout 30 qemu-system-x86_64 \ -drive format=raw,file="$IMG" \ -drive file=target/disk.img,format=raw,if=virtio,snapshot=on \ -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