From 2065090d3f38a6a52a2fe92d19650ed9466d416d Mon Sep 17 00:00:00 2001 From: kernalix7 Date: Fri, 10 Jul 2026 16:52:44 +0900 Subject: [PATCH] chore(scripts): add aarch64/riscv64 QEMU run scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproducible boot harnesses mirroring run-qemu.sh. run-qemu-aarch64.sh uses '-M virt,gic-version=3' (the kernel drives GICv3; the virt default GICv2 has no redistributor and faults init_gic) and routes PL011 serial to stdout — verified to boot through heap/GICv3/timer to the halt loop. run-qemu-riscv64.sh uses the virt NS16550/PLIC layout with OpenSBI (-bios default); documented for parity (needs qemu-system-riscv64). --- scripts/run-qemu-aarch64.sh | 50 +++++++++++++++++++++++++++++++++++++ scripts/run-qemu-riscv64.sh | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100755 scripts/run-qemu-aarch64.sh create mode 100755 scripts/run-qemu-riscv64.sh diff --git a/scripts/run-qemu-aarch64.sh b/scripts/run-qemu-aarch64.sh new file mode 100755 index 00000000..7aa67782 --- /dev/null +++ b/scripts/run-qemu-aarch64.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Copyright 2026 ONCRIX Contributors +# SPDX-License-Identifier: Apache-2.0 +# +# Run the ONCRIX kernel in QEMU (aarch64, `virt` machine). +# Usage: ./scripts/run-qemu-aarch64.sh [--release] +# +# The kernel targets the GICv3 interrupt controller, so `gic-version=3` +# is required (the `virt` machine defaults to GICv2, which has no +# redistributor and faults `init_gic`). Serial (PL011 @ 0x0900_0000) is +# routed to stdout. Expected output: +# [ONCRIX/aarch64] Kernel booting... +# [ONCRIX/aarch64] PL011 UART initialized (115200 8N1) +# [ONCRIX/aarch64] Heap initialized (16 MiB) +# [ONCRIX/aarch64] GICv3 initialized +# [ONCRIX/aarch64] Generic timer armed (10 ms) +# [ONCRIX/aarch64] All early initialization complete. +# [ONCRIX/aarch64] Entering halt loop. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +TARGET="aarch64-unknown-none" + +PROFILE="debug" +if [[ "${1:-}" == "--release" ]]; then + PROFILE="release" + shift + cargo build -p oncrix-kernel --bin oncrix-kernel --target "$TARGET" --release +else + cargo build -p oncrix-kernel --bin oncrix-kernel --target "$TARGET" +fi + +KERNEL="$PROJECT_DIR/target/$TARGET/$PROFILE/oncrix-kernel" + +if [[ ! -f "$KERNEL" ]]; then + echo "Error: kernel binary not found at $KERNEL" + exit 1 +fi + +exec qemu-system-aarch64 \ + -M virt,gic-version=3 \ + -cpu cortex-a72 \ + -m 512M \ + -nographic \ + -monitor none \ + -no-reboot \ + -kernel "$KERNEL" \ + "$@" diff --git a/scripts/run-qemu-riscv64.sh b/scripts/run-qemu-riscv64.sh new file mode 100755 index 00000000..a27fdf02 --- /dev/null +++ b/scripts/run-qemu-riscv64.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Copyright 2026 ONCRIX Contributors +# SPDX-License-Identifier: Apache-2.0 +# +# Run the ONCRIX kernel in QEMU (riscv64, `virt` machine). +# Usage: ./scripts/run-qemu-riscv64.sh [--release] +# +# The kernel uses the NS16550 UART (@ 0x1000_0000) and PLIC (@ 0x0C00_0000) +# that the `virt` machine provides. `-bios default` boots via OpenSBI in +# M-mode, which then enters the kernel in S-mode. Serial is on stdout. +# +# Requires qemu-system-riscv64 (part of the `qemu-system-misc` package on +# Debian/Ubuntu, `qemu` on Arch). + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +TARGET="riscv64gc-unknown-none-elf" + +PROFILE="debug" +if [[ "${1:-}" == "--release" ]]; then + PROFILE="release" + shift + cargo build -p oncrix-kernel --bin oncrix-kernel --target "$TARGET" --release +else + cargo build -p oncrix-kernel --bin oncrix-kernel --target "$TARGET" +fi + +KERNEL="$PROJECT_DIR/target/$TARGET/$PROFILE/oncrix-kernel" + +if [[ ! -f "$KERNEL" ]]; then + echo "Error: kernel binary not found at $KERNEL" + exit 1 +fi + +exec qemu-system-riscv64 \ + -M virt \ + -m 512M \ + -nographic \ + -monitor none \ + -no-reboot \ + -bios default \ + -kernel "$KERNEL" \ + "$@"