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