56 lines
1.5 KiB
Plaintext
56 lines
1.5 KiB
Plaintext
# Build script for BIOS (legacy) boot.
|
|
#
|
|
# This compiles our bootloader as a static library,
|
|
# and wraps it in a multistage loader.
|
|
|
|
|
|
# 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="$(BUILD_DIR)/bios.elf" \
|
|
-i "$(BIOS_SRC)" \
|
|
"$(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" "$@" |