RustForge

rust-kernel

Rustbelt: a hobby x86_64 kernel written in Rust

rust-kernel / scripts / run-headless.sh
936 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/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