#!/usr/bin/env bash # # scripts/boot.sh — quick direct boot in QEMU (dev loop) # # Fastest iteration: boots the kernel directly as BOOTX64.EFI via QEMU's # FAT driver, skipping the bootloader entirely. # # 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) # DISK_IMG raw disk image attached as the SATA data disk (default: /tmp/disk.img) # # The data disk is pinned to AHCI port 0 (ide.0) and the ESP to port 1 # (ide.1); the implicit `-drive file=fat:rw:esp` would otherwise grab # port 0 and the kernel would find the ESP where it expects a FAT32 disk. # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR" ESP_DIR="$PROJECT_DIR/esp" # ---- config ---- OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" MEM="${MEM:-256M}" SMP="${SMP:-1}" DISK_IMG="${DISK_IMG:-/tmp/disk.img}" PROFILE="debug" CARGO_FLAGS="" GUI="" DEBUG="" # ---- args ---- while [ $# -gt 0 ]; do case "$1" in --gui | -g) GUI="-vga std" ;; --debug | -d) DEBUG="-s -S" ;; --release | -r) PROFILE="release" CARGO_FLAGS="--release" ;; --mem) shift MEM="$1" ;; --smp) shift SMP="$1" ;; --help | -h) head -20 "$0" | grep "^#" | sed 's/^# //' exit 0 ;; *) echo "unknown: $1" exit 1 ;; esac shift done OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" KERNEL="$OUT_DIR/rsdos.efi" # ---- build ---- echo "=== Building kernel ($PROFILE) ===" cargo build --package rsdos --target x86_64-unknown-uefi $CARGO_FLAGS # ---- deploy ---- mkdir -p "$ESP_DIR/EFI/BOOT" cp "$KERNEL" "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" echo " kernel: $(ls -lh "$KERNEL" | awk '{print $5}')" # ---- boot ---- echo "" echo "=== Booting (direct: firmware → rsnix) ===" echo " ovmf: $OVMF" echo " mem: $MEM smp: $SMP" echo " disk: $([ -f "$DISK_IMG" ] && echo "$DISK_IMG" || echo "none ($DISK_IMG missing)")" echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" echo "" if [ ! -f "$DISK_IMG" ]; then echo " (creating missing disk image: $DISK_IMG)" "$SCRIPT_DIR/mkdisk.sh" "$DISK_IMG" fi if [ -f "$DISK_IMG" ]; then DISK_ARGS=( -drive "file=$DISK_IMG,format=raw,if=none,id=disk" -device ide-hd,drive=disk,bus=ide.0 ) else DISK_ARGS=() fi exec qemu-system-x86_64 \ -bios "$OVMF" \ "${DISK_ARGS[@]}" \ -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ -device ide-hd,drive=esp,bus=ide.1 \ -serial stdio \ -m "$MEM" \ -machine q35 \ -cpu qemu64 \ -no-reboot \ -smp "$SMP" \ $GUI $DEBUG