Comments
This commit is contained in:
48
Makefile
48
Makefile
@ -2,7 +2,7 @@ BUILD=./build
|
||||
|
||||
# Default rule
|
||||
.PHONY: default
|
||||
default: all
|
||||
default: $(BUILD)/disk.img
|
||||
|
||||
# Remove all build files
|
||||
.PHONY: clean
|
||||
@ -10,23 +10,18 @@ clean:
|
||||
rm -drf $(BUILD)
|
||||
cd tetros; cargo clean
|
||||
|
||||
# Make everything
|
||||
# (but don't run qemu)
|
||||
.PHONY: all
|
||||
all: img
|
||||
|
||||
#
|
||||
# MARK: boot
|
||||
# MARK: disk
|
||||
#
|
||||
|
||||
# Compile tetros as library
|
||||
# Compile tetros as a library
|
||||
# (so that we can link it with a custom linker script)
|
||||
LIB_SRC = ./tetros/Cargo.toml ./tetros/Cargo.lock $(shell find ./tetros/src -type f)
|
||||
$(BUILD)/tetros.lib: $(LIB_SRC)
|
||||
@mkdir -p $(BUILD)
|
||||
cd tetros && \
|
||||
env RUSTFLAGS="-C soft-float" \
|
||||
cargo rustc \
|
||||
--manifest-path="./Cargo.toml" \
|
||||
-Z build-std=core \
|
||||
-Z build-std-features=compiler-builtins-mem \
|
||||
--target "./targets/x86-unknown-none.json" \
|
||||
@ -35,7 +30,7 @@ $(BUILD)/tetros.lib: $(LIB_SRC)
|
||||
-- \
|
||||
--emit link="$(CURDIR)/$@"
|
||||
|
||||
# Link tetros
|
||||
# Link tetros using custom linker script
|
||||
BIOS_LD = ./tetros/linkers/x86-unknown-none.ld
|
||||
$(BUILD)/tetros.elf: $(BUILD)/tetros.lib $(BIOS_LD)
|
||||
ld \
|
||||
@ -49,13 +44,13 @@ $(BUILD)/tetros.elf: $(BUILD)/tetros.lib $(BIOS_LD)
|
||||
objcopy --only-keep-debug "$@" "$@.sym"
|
||||
objcopy --strip-debug "$@"
|
||||
|
||||
# Wrap tetros in three-stage BIOS loader
|
||||
# Wrap tetros in BIOS loader
|
||||
# Parameters:
|
||||
# - BIOS_SRC: source directory of bios assembly
|
||||
# - STAGE2_SECTOR: the index of the first sector of the stage 2 binary on the disk
|
||||
BIOS_SRC = ./bios
|
||||
STAGE2_SECTOR = 1
|
||||
$(BUILD)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD)/tetros.elf
|
||||
$(BUILD)/disk.img: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD)/tetros.elf
|
||||
@mkdir -p "$(BUILD)"
|
||||
nasm \
|
||||
-f bin \
|
||||
@ -66,30 +61,12 @@ $(BUILD)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD)/tetros.elf
|
||||
-i "$(BIOS_SRC)" \
|
||||
"$(BIOS_SRC)/main.asm"
|
||||
|
||||
# Extract full mbr (first 512 bytes)
|
||||
$(BUILD)/mbr.bin: $(BUILD)/bios.bin
|
||||
@mkdir -p "$(BUILD)"
|
||||
@echo ""
|
||||
dd if="$<" bs=512 count=1 of="$@"
|
||||
|
||||
# Extract stage 2 (rest of file)
|
||||
$(BUILD)/stage2.bin: $(BUILD)/bios.bin
|
||||
@mkdir -p "$(BUILD)"
|
||||
@echo ""
|
||||
dd if="$<" bs=512 skip=1 of="$@"
|
||||
|
||||
#
|
||||
# MARK: bundle
|
||||
# MARK: qemu
|
||||
#
|
||||
# Do not use `-enable-kvm` or `-cpu host`,
|
||||
# this confuses gdb.
|
||||
#
|
||||
|
||||
# Make full disk image
|
||||
.PHONY: img
|
||||
img: $(BUILD)/disk.img
|
||||
$(BUILD)/disk.img: $(BUILD)/mbr.bin $(BUILD)/stage2.bin
|
||||
@mkdir -p $(BUILD)
|
||||
@echo ""
|
||||
dd if="$(BUILD)/mbr.bin" of=$@ conv=notrunc bs=512
|
||||
dd if="$(BUILD)/stage2.bin" of=$@ conv=notrunc seek=$(STAGE2_SECTOR) bs=512
|
||||
|
||||
.PHONY: qemu
|
||||
qemu: $(BUILD)/disk.img
|
||||
@ -128,6 +105,3 @@ qemu-gdb: $(BUILD)/disk.img
|
||||
-fda "$<" \
|
||||
-gdb tcp::26000 \
|
||||
-S
|
||||
|
||||
# Do not use `-enable-kvm` or `-cpu host`,
|
||||
# this confuses gdb.
|
Reference in New Issue
Block a user