diff options
| author | salmonik <salmonik@tuta.io> | 2026-07-31 03:22:20 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-07-31 03:22:20 +0200 |
| commit | 0ace22d6f88692883584119c64ff010f4cee6738 (patch) | |
| tree | 6f575f9088dec8bab90943d6c23e174bca183f0a /scripts/qemu.sh | |
| parent | restructure: rsnix kernel + shell crate + rsdos entry point (diff) | |
| download | rs-dos-0ace22d6f88692883584119c64ff010f4cee6738.tar.gz rs-dos-0ace22d6f88692883584119c64ff010f4cee6738.zip | |
fix(rsdos): organizational changes
Diffstat (limited to 'scripts/qemu.sh')
| -rwxr-xr-x | scripts/qemu.sh | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/scripts/qemu.sh b/scripts/qemu.sh new file mode 100755 index 0000000..b75bed4 --- /dev/null +++ b/scripts/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 | # ============================================================================= | ||
| 14 | set -euo pipefail | ||
| 15 | |||
| 16 | SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" | ||
| 17 | cd "$SCRIPT_DIR" | ||
| 18 | |||
| 19 | # Defaults | ||
| 20 | GUI_FLAG="" | ||
| 21 | DEBUG_FLAG="" | ||
| 22 | DRIVE_ARGS=(-drive file=fat:rw:esp,format=raw) | ||
| 23 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | ||
| 24 | MEM="${MEM:-256M}" | ||
| 25 | SMP="${SMP:-1}" | ||
| 26 | |||
| 27 | # Pre-build | ||
| 28 | make all | ||
| 29 | |||
| 30 | # Parse args | ||
| 31 | while [ $# -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 | ||
| 67 | done | ||
| 68 | |||
| 69 | QEMU_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") | ||
| 82 | if [ -n "$DEBUG_FLAG" ]; then | ||
| 83 | # Split the flag string safely into words | ||
| 84 | read -ra dbg <<<"$DEBUG_FLAG" | ||
| 85 | QEMU_CMD+=("${dbg[@]}") | ||
| 86 | fi | ||
| 87 | |||
| 88 | echo " OVMF : $OVMF" | ||
| 89 | echo " Drive : ${DRIVE_ARGS[*]}" | ||
| 90 | echo " Mem : $MEM" | ||
| 91 | echo " SMP : $SMP" | ||
| 92 | echo " GDB : $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo 'off')" | ||
| 93 | echo " GUI : $([ -n "$GUI_FLAG" ] && echo 'yes' || echo 'no')" | ||
| 94 | echo "" | ||
| 95 | |||
| 96 | exec "${QEMU_CMD[@]}" | ||
