blob: 5b8e6faea9acb895b36ea9464419a35a63b5c5c8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#!/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 ----
source "$SCRIPT_DIR/lib-boot-args.sh"
# boot.sh-specific flags live here; everything else is shared.
handle_arg() {
case "$1" in
--release | -r)
PROFILE="release"
CARGO_FLAGS="--release"
;;
*)
echo "unknown: $1"
exit 1
;;
esac
}
parse_boot_args "$@"
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
|