1
0
Fork 0

Clean up build process

main
Mark 2024-12-12 07:14:44 -08:00
parent 3fc40ce6be
commit 379d8dbcdc
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
4 changed files with 72 additions and 41 deletions

View File

@ -1,11 +1,27 @@
BUILD_DIR=./build
export QEMU?=qemu-system-x86_64
.PHONY: bios
bios: $(BUILD_DIR)/bios.bin $(BUILD_DIR)/bios.img
.PHONY: clean
all: $(BUILD_DIR)/bootloader.bin
include make/bios
include make/bootloader
clean:
rm -drf $(BUILD_DIR)
rm -drf $(BUILD_DIR)
cd bootloader; cargo clean
qemu: $(BUILD_DIR)/bios.img
$(QEMU) \
-d cpu_reset \
-no-reboot \
-smp 4 -m 2048 \
-chardev stdio,id=debug,signal=off,mux=on \
-serial chardev:debug \
-mon chardev=debug \
-machine q35 \
-net none \
-enable-kvm \
-cpu host \
-drive file="$<",format=raw
include make/bios

View File

@ -1,12 +1,56 @@
BIOS_SRC = ./bios
STAGE3_BIN = $(BUILD_DIR)/stage3.elf
# Build script for BIOS (legacy) boot.
#
# This compiles our bootloader as a static library,
# and wraps it in a multistage loader.
$(BUILD_DIR)/bootloader.bin: $(wildcard $(BIOS_SRC)/*.asm) $(STAGE3_BIN)
# Compile bootloader as library
LIB_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f)
$(BUILD_DIR)/bios.lib: $(LIB_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 bootloader
BIOS_LD = ./bootloader/linkers/x86-unknown-none.ld
$(BUILD_DIR)/bios.elf: $(BUILD_DIR)/bios.lib $(BIOS_LD)
ld \
-m elf_i386 \
--gc-sections \
-z max-page-size=0x1000 \
-T "$(BIOS_LD)" \
-o "$@" \
"$<"
objcopy --only-keep-debug "$@" "$@.sym"
objcopy --strip-debug "$@"
# Wrap bootloader in three-stage BIOS loader
BIOS_SRC = ./bios
$(BUILD_DIR)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD_DIR)/bios.elf
@mkdir -p "$(BUILD_DIR)"
nasm \
-f bin \
-o "$@" \
-l "$@.lst" \
-D STAGE3="$(STAGE3_BIN)" \
-D STAGE3="$(BUILD_DIR)/bios.elf" \
-i "$(BIOS_SRC)" \
"$(BIOS_SRC)/bootloader.asm"
"$(BIOS_SRC)/main.asm"
# Build demo disk image
$(BUILD_DIR)/bios.img: $(BUILD_DIR)/bios.bin
rm -f "$@.partial"
fallocate -l 256MiB "$@.partial"
parted -s -a minimal "$@.partial" mklabel msdos
parted -s -a minimal "$@.partial" mkpart primary 2MiB 100%
dd if="$<" of="$@.partial" bs=1 count=512 conv=notrunc
dd if="$<" of="$@.partial" bs=512 skip=1 seek=1 conv=notrunc
mv "$@.partial" "$@"

View File

@ -1,29 +0,0 @@
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 "$@"