summaryrefslogtreecommitdiffstats
path: root/tools/qemu.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qemu.sh')
-rwxr-xr-xtools/qemu.sh96
1 files changed, 96 insertions, 0 deletions
diff --git a/tools/qemu.sh b/tools/qemu.sh
new file mode 100755
index 0000000..428954f
--- /dev/null
+++ b/tools/qemu.sh
@@ -0,0 +1,96 @@
1#!/usr/bin/env bash
2# =============================================================================
3# tools/qemu.sh — Run raisernics in QEMU with various options
4#
5# Usage:
6# ./tools/qemu.sh # serial console (no graphics)
7# ./tools/qemu.sh --gui # graphical window
8# ./tools/qemu.sh --debug # GDB stub on :1234
9# ./tools/qemu.sh --image foo.img # boot from raw disk image
10# ./tools/qemu.sh --bios /path/to.fd # custom OVMF
11# ./tools/qemu.sh --mem 512M # memory size
12# ./tools/qemu.sh --smp 2 # SMP cores
13# =============================================================================
14set -euo pipefail
15
16SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
17cd "$SCRIPT_DIR"
18
19# Defaults
20GUI_FLAG=""
21DEBUG_FLAG=""
22DRIVE_ARGS=(-drive file=fat:rw:esp,format=raw)
23OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
24MEM="${MEM:-256M}"
25SMP="${SMP:-1}"
26
27# Pre-build
28make all
29
30# Parse args
31while [ $# -gt 0 ]; do
32 case "$1" in
33 --gui | -g)
34 GUI_FLAG="-vga std"
35 shift
36 ;;
37 --debug | -d)
38 DEBUG_FLAG="-s -S"
39 shift
40 ;;
41 --image | -i)
42 _img_file="$(printf -- '-drive file=%s,format=raw,if=none,id=hd' "$2")"
43 DRIVE_ARGS=("$_img_file" '-device' 'ide-hd,drive=hd')
44 shift 2
45 ;;
46 --bios | -b)
47 OVMF="$2"
48 shift 2
49 ;;
50 --mem)
51 MEM="$2"
52 shift 2
53 ;;
54 --smp)
55 SMP="$2"
56 shift 2
57 ;;
58 --help | -h)
59 head -20 "$0" | grep "^# " | sed 's/^# //'
60 exit 0
61 ;;
62 *)
63 echo "Unknown option: $1"
64 exit 1
65 ;;
66 esac
67done
68
69QEMU_CMD=(
70 qemu-system-x86_64
71 -bios "$OVMF"
72 "${DRIVE_ARGS[@]}"
73 -serial stdio
74 -m "$MEM"
75 -machine q35
76 -cpu qemu64
77 -no-reboot
78 -smp "$SMP"
79)
80
81[ -n "$GUI_FLAG" ] && QEMU_CMD+=("$GUI_FLAG")
82if [ -n "$DEBUG_FLAG" ]; then
83 # Split the flag string safely into words
84 read -ra dbg <<< "$DEBUG_FLAG"
85 QEMU_CMD+=("${dbg[@]}")
86fi
87
88echo " OVMF : $OVMF"
89echo " Drive : ${DRIVE_ARGS[*]}"
90echo " Mem : $MEM"
91echo " SMP : $SMP"
92echo " GDB : $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo 'off')"
93echo " GUI : $([ -n "$GUI_FLAG" ] && echo 'yes' || echo 'no')"
94echo ""
95
96exec "${QEMU_CMD[@]}"