# run `just` to list recipes. override a setting with `just = `, # e.g. `just profile=release run` or `just cmdline="foo=bar" run` set shell := ["bash", "-euo", "pipefail", "-c"] arch := "x86_64" profile := "debug" cmdline := "" test_timeout := "60" nasm := "nasm" ld := "ld" qemu := "qemu-system-" + arch target := arch + "-unknown-none" out := "build" boot := "kernel/src/arch" / arch / "boot" kernel_bin := out / "kernel.bin" kernel_iso := out / "kernel.iso" test_bin := out / "test.bin" test_iso := out / "test.iso" lib := "target" / target / profile / "libkernel.a" linker := boot / "linker.ld" cargo_flags := "--target " + target + if profile == "release" { " --release" } else { "" } ldflags := "-n --gc-sections -z noexecstack --no-warn-rwx-segments" qemu_flags := "-serial stdio -no-reboot -display none" test_qemu_flags := qemu_flags + " -device isa-debug-exit,iobase=0xf4,iosize=0x04" # list the recipes default: @just --list # build and link the kernel binary build: (_link "" kernel_bin) # build a bootable ISO image iso: build (_iso kernel_bin kernel_iso) # build and boot in QEMU; extra arguments go to QEMU run *args: iso {{qemu}} -cdrom {{kernel_iso}} {{qemu_flags}} {{args}} # boot halted, waiting for gdb on :1234 debug: iso {{qemu}} -cdrom {{kernel_iso}} {{qemu_flags}} -s -S # boot the test kernel and report the results test: (_link "--features test" test_bin) (_iso test_bin test_iso) #!/usr/bin/env bash # isa-debug-exit makes QEMU exit with (code << 1) | 1, 33 is a pass # timeout(1) exits 124 from a hanging test set -uo pipefail timeout --foreground {{test_timeout}} {{qemu}} -cdrom {{test_iso}} {{test_qemu_flags}} &2 exit 1 fi root={{out}}/isofiles rm -rf "$root" mkdir -p "$root/boot/grub" cp {{bin}} "$root/boot/kernel.bin" printf '%s\n' 'set timeout=0' 'set default=0' 'menuentry "Crossing the Boundary" {' \ ' multiboot2 /boot/kernel.bin {{cmdline}}' \ ' boot' '}' > "$root/boot/grub/grub.cfg" "$mkrescue" -o {{image}} "$root" >{{out}}/grub.log 2>&1 || { cat {{out}}/grub.log; exit 1; } rm -rf "$root"