summaryrefslogtreecommitdiffstats
path: root/scripts/boot-image.sh
blob: e8c093cc9925a9324ace88d9a4c16d2a86770d60 (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
#
# scripts/boot-image.sh — boot rs-dos full chain disk image in QEMU
#
# Builds the image first if needed, then boots with UEFI firmware through
# the real boot chain: firmware → rsboot → rsnix kernel.
#
# Usage:
#   ./scripts/boot-image.sh [--gui] [--debug] [--mem 512M] [--smp 2]
#
# Keybindings:
#   Ctrl-A X   — quit
#   Ctrl-A C   — QEMU monitor
#
# Environment:
#   OVMF    path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd)
#   MEM     memory size (default: 256M)
#   SMP     CPU count (default: 1)
#
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

cd "$PROJECT_DIR"

IMAGE="rs-dos.img"

# ---- config ----
OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
MEM="${MEM:-256M}"
SMP="${SMP:-1}"
GUI=""
DEBUG=""

# ---- args ----
source "$SCRIPT_DIR/lib-boot-args.sh"
parse_boot_args "$@"

# ---- build image if missing ----
if [ ! -f "$IMAGE" ]; then
	echo "Image not found, building..."
	"$SCRIPT_DIR/build-image.sh"
fi

# ---- boot ----
echo ""
echo "=== Booting (full chain: firmware → rsboot → rsnix) ==="
echo "  image:  $IMAGE"
echo "  ovmf:   $OVMF"
echo "  mem:    $MEM   smp: $SMP"
echo "  gui:    $([ -n "$GUI" ] && echo yes || echo no)"
echo "  gdb:    $([ -n "$DEBUG" ] && echo ':1234' || echo off)"
echo ""

exec qemu-system-x86_64 \
	-bios "$OVMF" \
	-drive file="$IMAGE",format=raw,if=none,id=hd \
	-device ide-hd,drive=hd \
	-serial stdio \
	-m "$MEM" \
	-machine q35 \
	-cpu qemu64 \
	-no-reboot \
	-smp "$SMP" \
	$GUI $DEBUG