exec_kernel.sh (2072B)
1 # test/lib/exec_kernel.sh — per-arch qemu-system runner for 2 # kernel_image cases. 3 # 4 # Distinct from exec_target.sh (which uses qemu-user / podman to run 5 # linux-userland ELFs): kernel_image cases are freestanding boot images 6 # with their own entry stub, no Linux ABI, exiting via arch-specific 7 # semihosting / test-device MMIO. The harness invokes 8 # 9 # exec_kernel_run <arch> <exe> <out> <err> 10 # 11 # which sets RUN_RC. Returns rc=127 if no qemu-system-* is available 12 # for the requested arch. 13 # 14 # Per-arch exit conventions: 15 # aa64: ARM semihosting hlt #0xf000 + ADP_Stopped_ApplicationExit 16 # (subcode = host exit code). 17 # rv64: SIFIVE_TEST MMIO device at 0x100000; writing 0x5555 = pass 18 # (host exit 0), 0x3333 = fail (host nonzero). 19 20 exec_kernel_supported() { 21 local arch="$1" 22 case "$arch" in 23 aa64) command -v qemu-system-aarch64 >/dev/null 2>&1 ;; 24 rv64) command -v qemu-system-riscv64 >/dev/null 2>&1 ;; 25 *) return 1 ;; 26 esac 27 } 28 29 # Runs synchronously; sets RUN_RC. 30 exec_kernel_run() { 31 local arch="$1" exe="$2" out="$3" err="$4" 32 local bin 33 case "$arch" in 34 aa64) 35 bin="$(command -v qemu-system-aarch64 2>/dev/null || true)" 36 if [ -z "$bin" ]; then RUN_RC=127; return; fi 37 "$bin" -machine virt -cpu cortex-a72 \ 38 -kernel "$exe" -nographic \ 39 -semihosting-config enable=on,target=native \ 40 -no-reboot >"$out" 2>"$err" 41 RUN_RC=$? 42 ;; 43 rv64) 44 bin="$(command -v qemu-system-riscv64 2>/dev/null || true)" 45 if [ -z "$bin" ]; then RUN_RC=127; return; fi 46 # -bios none: skip OpenSBI; we own 0x80000000 entry. The 47 # SIFIVE_TEST MMIO device on -machine virt handles exit 48 # via writes to 0x100000 from the kernel. 49 "$bin" -machine virt -bios none \ 50 -kernel "$exe" -nographic \ 51 -no-reboot >"$out" 2>"$err" 52 RUN_RC=$? 53 ;; 54 *) 55 RUN_RC=127 56 ;; 57 esac 58 }