#!/usr/bin/env bash # # scripts/boot.sh — quick direct boot in QEMU (dev loop) # # Builds the kernel, stages the system image, and boots directly as # BOOTX64.EFI via QEMU's FAT driver. One image = one drive. # # Usage: # ./scripts/boot.sh [--gui] [--debug] [--release] [--mem 512M] [--smp 2] # # Boot chain: firmware → rsnix (direct) # Full chain: use ./scripts/boot-image.sh (firmware → rsboot → rsnix) # # 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) # SYSTEM_IMG system image path (default: /tmp/system.img) # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_DIR" # ---- config ---- OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" MEM="${MEM:-256M}" SMP="${SMP:-1}" SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}" PROFILE="release" GUI="" DEBUG="" # ---- args ---- source "$SCRIPT_DIR/lib-boot-args.sh" handle_arg() { case "$1" in --debug) PROFILE="debug" CARGO_FLAGS="" ;; *) echo "unknown: $1" exit 1 ;; esac } parse_boot_args "$@" OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" # ---- build ---- echo "=== Building kernel ($PROFILE) ===" if [ "$PROFILE" = "release" ]; then cargo build --release --package rsdos --target x86_64-unknown-uefi else cargo build --package rsdos --target x86_64-unknown-uefi fi # ---- stage system image ---- echo "=== Staging system image ===" "$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG" echo " system image: $SYSTEM_IMG" # ---- boot ---- echo "" echo "=== Booting (direct: firmware → rsnix) ===" 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=$SYSTEM_IMG,format=raw,if=none,id=disk" \ -device ide-hd,drive=disk,bus=ide.0 \ -serial stdio \ -m "$MEM" \ -machine q35 \ -cpu qemu64 \ -no-reboot \ -smp "$SMP" \ $GUI $DEBUG