diff options
Diffstat (limited to '')
| -rwxr-xr-x | scripts/qemu.sh | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/scripts/qemu.sh b/scripts/qemu.sh index b8997ba..eeaf4de 100755 --- a/scripts/qemu.sh +++ b/scripts/qemu.sh | |||
| @@ -1,28 +1,32 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # ============================================================================= | 2 | # ============================================================================= |
| 3 | # tools/qemu.sh — Run raisernics in QEMU with various options | 3 | # scripts/qemu.sh — flexible QEMU launcher for rs-dos |
| 4 | # | 4 | # |
| 5 | # Usage: | 5 | # Usage: |
| 6 | # ./tools/qemu.sh # serial console (no graphics) | 6 | # ./scripts/qemu.sh # serial console (no graphics) |
| 7 | # ./tools/qemu.sh --gui # graphical window | 7 | # ./scripts/qemu.sh --gui # graphical window |
| 8 | # ./tools/qemu.sh --debug # GDB stub on :1234 | 8 | # ./scripts/qemu.sh --debug # GDB stub on :1234 |
| 9 | # ./tools/qemu.sh --image foo.img # boot from raw disk image | 9 | # ./scripts/qemu.sh --chain # full boot chain (firmware → rsboot → rsnix) |
| 10 | # ./tools/qemu.sh --bios /path/to.fd # custom OVMF | 10 | # ./scripts/qemu.sh --bios /path/to.fd # custom OVMF |
| 11 | # ./tools/qemu.sh --mem 512M # memory size | 11 | # ./scripts/qemu.sh --mem 512M # memory size |
| 12 | # ./tools/qemu.sh --smp 2 # SMP cores | 12 | # ./scripts/qemu.sh --smp 2 # SMP cores |
| 13 | # | ||
| 14 | # One image, one drive — the system image contains kernel + ESP + data. | ||
| 13 | # ============================================================================= | 15 | # ============================================================================= |
| 14 | set -euo pipefail | 16 | set -euo pipefail |
| 15 | 17 | ||
| 16 | SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" | 18 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 17 | cd "$SCRIPT_DIR" | 19 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 20 | cd "$PROJECT_DIR" | ||
| 18 | 21 | ||
| 19 | # Defaults | 22 | # Defaults |
| 20 | GUI_FLAG="" | 23 | GUI_FLAG="" |
| 21 | DEBUG_FLAG="" | 24 | DEBUG_FLAG="" |
| 22 | DRIVE_ARGS=(-drive file=fat:rw:esp,format=raw) | 25 | CHAIN_FLAG="" |
| 23 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | 26 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" |
| 24 | MEM="${MEM:-256M}" | 27 | MEM="${MEM:-256M}" |
| 25 | SMP="${SMP:-1}" | 28 | SMP="${SMP:-1}" |
| 29 | SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}" | ||
| 26 | 30 | ||
| 27 | # Pre-build | 31 | # Pre-build |
| 28 | make all | 32 | make all |
| @@ -38,12 +42,13 @@ while [ $# -gt 0 ]; do | |||
| 38 | DEBUG_FLAG="-s -S" | 42 | DEBUG_FLAG="-s -S" |
| 39 | shift | 43 | shift |
| 40 | ;; | 44 | ;; |
| 45 | --chain | -c) | ||
| 46 | CHAIN_FLAG=1 | ||
| 47 | SYSTEM_IMG="${SYSTEM_IMG:-rs-dos.img}" | ||
| 48 | shift | ||
| 49 | ;; | ||
| 41 | --image | -i) | 50 | --image | -i) |
| 42 | _img_file="$(printf -- '-drive file=%s,format=raw,if=none,id=hd' "$2")" | 51 | SYSTEM_IMG="$2" |
| 43 | # Explicit buses: data disk -> ide.0 (port 0), ESP -> ide.1. | ||
| 44 | DRIVE_ARGS=("$_img_file" '-device' 'ide-hd,drive=hd,bus=ide.0' | ||
| 45 | '-drive' 'file=fat:rw:esp,format=raw,if=none,id=esp' | ||
| 46 | '-device' 'ide-hd,drive=esp,bus=ide.1') | ||
| 47 | shift 2 | 52 | shift 2 |
| 48 | ;; | 53 | ;; |
| 49 | --bios | -b) | 54 | --bios | -b) |
| @@ -58,42 +63,37 @@ while [ $# -gt 0 ]; do | |||
| 58 | SMP="$2" | 63 | SMP="$2" |
| 59 | shift 2 | 64 | shift 2 |
| 60 | ;; | 65 | ;; |
| 61 | --help | -h) | ||
| 62 | head -20 "$0" | grep "^# " | sed 's/^# //' | ||
| 63 | exit 0 | ||
| 64 | ;; | ||
| 65 | *) | 66 | *) |
| 66 | echo "Unknown option: $1" | 67 | echo "unknown: $1" |
| 67 | exit 1 | 68 | exit 1 |
| 68 | ;; | 69 | ;; |
| 69 | esac | 70 | esac |
| 70 | done | 71 | done |
| 71 | 72 | ||
| 72 | QEMU_CMD=( | 73 | # Stage system image if needed |
| 73 | qemu-system-x86_64 | 74 | if [ -n "$CHAIN_FLAG" ]; then |
| 74 | -bios "$OVMF" | 75 | ./scripts/mksystem.sh --chain --gpt "$SYSTEM_IMG" |
| 75 | "${DRIVE_ARGS[@]}" | 76 | else |
| 76 | -serial stdio | 77 | ./scripts/mksystem.sh "$SYSTEM_IMG" |
| 77 | -m "$MEM" | ||
| 78 | -machine q35 | ||
| 79 | -cpu qemu64 | ||
| 80 | -no-reboot | ||
| 81 | -smp "$SMP" | ||
| 82 | ) | ||
| 83 | |||
| 84 | [ -n "$GUI_FLAG" ] && QEMU_CMD+=("$GUI_FLAG") | ||
| 85 | if [ -n "$DEBUG_FLAG" ]; then | ||
| 86 | # Split the flag string safely into words | ||
| 87 | read -ra dbg <<<"$DEBUG_FLAG" | ||
| 88 | QEMU_CMD+=("${dbg[@]}") | ||
| 89 | fi | 78 | fi |
| 90 | 79 | ||
| 91 | echo " OVMF : $OVMF" | 80 | echo "" |
| 92 | echo " Drive : ${DRIVE_ARGS[*]}" | 81 | echo "=== Booting ===" |
| 93 | echo " Mem : $MEM" | 82 | echo " image: $SYSTEM_IMG" |
| 94 | echo " SMP : $SMP" | 83 | echo " ovmf: $OVMF" |
| 95 | echo " GDB : $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo 'off')" | 84 | echo " mem: $MEM smp: $SMP" |
| 96 | echo " GUI : $([ -n "$GUI_FLAG" ] && echo 'yes' || echo 'no')" | 85 | echo " gui: $([ -n "$GUI_FLAG" ] && echo yes || echo no)" |
| 86 | echo " gdb: $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo off)" | ||
| 97 | echo "" | 87 | echo "" |
| 98 | 88 | ||
| 99 | exec "${QEMU_CMD[@]}" | 89 | exec qemu-system-x86_64 \ |
| 90 | -bios "$OVMF" \ | ||
| 91 | -drive "file=$SYSTEM_IMG,format=raw,if=none,id=hd" \ | ||
| 92 | -device ide-hd,drive=hd \ | ||
| 93 | -serial stdio \ | ||
| 94 | -m "$MEM" \ | ||
| 95 | -machine q35 \ | ||
| 96 | -cpu qemu64 \ | ||
| 97 | -no-reboot \ | ||
| 98 | -smp "$SMP" \ | ||
| 99 | $GUI_FLAG $DEBUG_FLAG | ||
