From bebed12bf4aa1440485c6013cce75d90edaa9a33 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 11 Dec 2024 18:21:14 -0800 Subject: [PATCH] Added makefiles --- Makefile | 11 +++++++++++ make/bios | 12 ++++++++++++ make/bootloader | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 Makefile create mode 100644 make/bios create mode 100644 make/bootloader diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..847008d --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +BUILD_DIR=./build + +.PHONY: clean + +all: $(BUILD_DIR)/bootloader.bin + +include make/bios +include make/bootloader + +clean: + rm -drf $(BUILD_DIR) \ No newline at end of file diff --git a/make/bios b/make/bios new file mode 100644 index 0000000..17ea865 --- /dev/null +++ b/make/bios @@ -0,0 +1,12 @@ +BIOS_SRC = ./bios +STAGE3_BIN = $(BUILD_DIR)/stage3.elf + +$(BUILD_DIR)/bootloader.bin: $(wildcard $(BIOS_SRC)/*.asm) $(STAGE3_BIN) + @mkdir -p "$(BUILD_DIR)" + nasm \ + -f bin \ + -o "$@" \ + -l "$@.lst" \ + -D STAGE3="$(STAGE3_BIN)" \ + -i "$(BIOS_SRC)" \ + "$(BIOS_SRC)/bootloader.asm" \ No newline at end of file diff --git a/make/bootloader b/make/bootloader new file mode 100644 index 0000000..73d68f9 --- /dev/null +++ b/make/bootloader @@ -0,0 +1,29 @@ +STAGE3_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f) +STAGE3_LD = ./bootloader/linkers/x86-unknown-none.ld + +# Compile stage 3 bootloader +$(BUILD_DIR)/stage3.lib.a: $(STAGE3_SRC) + @mkdir -p $(BUILD_DIR) + env RUSTFLAGS="-C soft-float" \ + cargo rustc \ + --manifest-path="./bootloader/Cargo.toml" \ + -Z build-std=core,alloc \ + -Z build-std-features=compiler-builtins-mem \ + --target "./bootloader/targets/x86-unknown-none.json" \ + --lib \ + --release \ + -- \ + --emit link="$(CURDIR)/$@" + +# Link stage 3 bootloader +$(BUILD_DIR)/stage3.elf: $(BUILD_DIR)/stage3.lib.a $(STAGE3_LD) + ld \ + -m elf_i386 \ + --gc-sections \ + -z max-page-size=0x1000 \ + -T "$(STAGE3_LD)" \ + -o "$@" \ + "$<" + + objcopy --only-keep-debug "$@" "$@.sym" + objcopy --strip-debug "$@" \ No newline at end of file