From 76103215711d268b4b02f62e900f2be3032cf295 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 02:18:30 +0200 Subject: Initial commit: raisernics toy kernel - Bare-metal x86_64 UEFI kernel (PE32+, no libc) - GOP framebuffer + 8x16 bitmap font - PS/2 keyboard (polling, scancode set 1) - UART 16550 serial driver (COM1, 115200 8N1) - Bump allocator as #[global_allocator] (alloc::String, Vec, format!) - UEFI memory map capture (static buffer, ADR 0001) - Shell with 7 commands (help, echo, clear, hello, info, mem, halt) - Dual output: GOP framebuffer + serial console - Makefile: run, run-gui, debug, release, image targets - tools/: qemu.sh, boot-image.sh, debug-kernel.py --- Makefile | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f03f93 --- /dev/null +++ b/Makefile @@ -0,0 +1,124 @@ +# shellcheck shell=sh disable=SC2046,SC2091,SC2086,SC2155 +# NOTE: $(VAR) in this file is MAKE syntax, not shell substitution. +export TARGET=x86_64-unknown-uefi +export PROFILE=debug +export OUT_DIR=target/$(TARGET)/$(PROFILE) +export ESP_DIR=esp +export KERNEL=$(OUT_DIR)/raisernics.efi +export BZIMAGE=$(ESP_DIR)/bzImage +export INITRD=$(ESP_DIR)/initramfs.cpio.gz +export BOOTLOADER=../rng/rsbl/../build/bootloader/BOOTX64.EFI +export OVMF=/usr/share/edk2/x64/OVMF.4m.fd +export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI + +.PHONY: all run run-gui clean image debug release fmt + +# ---- Build --------------------------------------------------------------- + +all: $(BZIMAGE) $(INITRD) $(BOOT_EFI) + +release: PROFILE=release +release: export PROFILE=release +release: export OUT_DIR=target/$(TARGET)/release +release: CARGO_FLAGS=--release +release: all + +# shellcheck disable=SC2034 +CARGO_FLAGS= + +$(OUT_DIR)/raisernics.efi: $(shell find src -name '*.rs') Cargo.toml build.rs + cargo build --target $(TARGET) $(CARGO_FLAGS) + +$(BZIMAGE): $(KERNEL) | $(ESP_DIR) + cp "$<" "$@" + +$(BOOT_EFI): $(BOOTLOADER) | $(ESP_DIR) + mkdir -p $(ESP_DIR)/EFI/BOOT + cp "$<" "$@" + +$(ESP_DIR): + mkdir -p $(ESP_DIR) + +$(INITRD): | $(ESP_DIR) + printf '' | gzip > "$@" + +# ---- QEMU runners -------------------------------------------------------- + +run: all + qemu-system-x86_64 \ + -bios $(OVMF) \ + -drive file=fat:rw:$(ESP_DIR),format=raw \ + -serial stdio \ + -m 256M \ + -machine q35 \ + -cpu qemu64 \ + -no-reboot \ + -display none + +run-gui: all + qemu-system-x86_64 \ + -bios $(OVMF) \ + -drive file=fat:rw:$(ESP_DIR),format=raw \ + -serial stdio \ + -m 256M \ + -machine q35 \ + -cpu qemu64 \ + -no-reboot \ + -vga std + +# GDB stub on :1234 +debug: all + qemu-system-x86_64 \ + -bios $(OVMF) \ + -drive file=fat:rw:$(ESP_DIR),format=raw \ + -serial stdio \ + -m 256M \ + -machine q35 \ + -cpu qemu64 \ + -no-reboot \ + -display none \ + -s -S + +# Boot from a raw disk image (created by tools/boot-image.sh) +run-image: all + qemu-system-x86_64 \ + -bios $(OVMF) \ + -drive file=$(IMG),format=raw,if=none,id=hd \ + -device ide-hd,drive=hd \ + -serial stdio \ + -m 256M \ + -machine q35 \ + -cpu qemu64 \ + -no-reboot \ + -display none + +# ---- Disk image ---------------------------------------------------------- + +image: all + ./tools/boot-image.sh raisernics.img + +# ---- Utilities ----------------------------------------------------------- + +fmt: + cargo fmt + +clean: + cargo clean + rm -rf $(ESP_DIR) raisernics.img + +help: + @echo "raisernics — Make targets" + @echo "" + @echo " make build kernel + ESP (default)" + @echo " make release build with --release (smaller binary)" + @echo " make image create bootable USB image (raisernics.img)" + @echo " make run QEMU serial console (no graphics)" + @echo " make run-gui QEMU with graphical window (GOP/PS2)" + @echo " make debug QEMU + GDB stub on :1234" + @echo " make clean remove build artifacts" + @echo " make fmt format Rust source" + @echo "" + @echo "Scripts:" + @echo " ./tools/qemu.sh flexible QEMU launcher" + @echo " ./tools/boot-image.sh create bootable disk image" + @echo " ./tools/debug-kernel.py GDB plugin (attach after 'make debug')" -- cgit v1.2.3