From 5a490b03f9f8fa4d4cb52e4da2f104ba95acf261 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 26 Jan 2026 00:52:34 +0100 Subject: [PATCH] feat(run): initial run script --- run.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..2da46fa --- /dev/null +++ b/run.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# -x -> trace: print every command +# -u -> exit if undefined variables are used +# -e -> exit if an error occurs +set -xue + +QEMU=qemu-system-riscv32 + +# Compile +CC=clang +# -ffreestanding: do not use stdlib of the host environment +# -fuse-ld=lld: LLVM linker +# -fno-stack-protector: disable stack protection +# -Wl,-Tkernel.ld: linker script +# -Wl,-Map=kernel.map: output a map file (linker allocationr result) +CFLAGS="-std=c11 -O2 -g3 -Wall -Wextra --target=riscv32-unknown-elf -fuse-ld=lld -fno-stack-protector -ffreestanding -nostdlib" + +$CC $CFLAGS -Wl,-Tkernel.ld -Wl,-Map=kernel.map -o kernel.elf \ + src/kernel.c + +# Run QEMU +# -machine virt: generic riscv platform +# -bios default: load the default firmware (OpenSBI) +# -nographic: disable VGA, everything on console +# -serial mon:stdio: serial port is connected to terminal's stdin/stdout +# --no-reboot: do not reboot if there's panic/shutdown/crash +$QEMU -machine virt -bios default -nographic -serial mon:stdio --no-reboot \ + -kernel kernel.elf + +# Press Ctrl+A and then C to enter QEMU debug console and quit with `q`