RustForge

rust-kernel

Rustbelt: a hobby x86_64 kernel written in Rust

rust-kernel / scripts / screenshot.sh
908 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
# Boot the (non-headless) kernel with no window, wait a moment, then ask the
# QEMU monitor to dump the VGA screen to boot.png. Handy on a headless box.
set -euo pipefail
cd "$(dirname "$0")/.."

cargo bootimage
IMG=target/x86_64-rust_kernel/debug/bootimage-rust_kernel.bin
OUT="${1:-$PWD/boot.png}"
SOCK=$(mktemp -u /tmp/qemu-mon.XXXXXX)

qemu-system-x86_64 -drive format=raw,file="$IMG" \
    -serial stdio -display none -monitor unix:"$SOCK",server,nowait &
QPID=$!
sleep 3   # give the BIOS + bootloader + kernel time to draw

# Talk to the QEMU monitor over its UNIX socket (python avoids needing socat).
python3 - "$SOCK" "$OUT" <<'PY'
import socket, sys, time
s = socket.socket(socket.AF_UNIX); s.connect(sys.argv[1])
s.sendall(f"screendump {sys.argv[2]} -f png\n".encode()); time.sleep(1)
s.sendall(b"quit\n"); time.sleep(0.5)
PY
wait $QPID || true
echo "[screenshot] saved $OUT"