summaryrefslogtreecommitdiff
path: root/x86-bare-metal/mbr-e820/Makefile
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-29 01:49:25 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-29 01:49:25 +0100
commit107017c693333b5deeb484d23010e38534d1fe03 (patch)
tree5e833a0afdd00746d3998a782289daffe7bd7b9d /x86-bare-metal/mbr-e820/Makefile
parenta2ce17753fa4a727f082bfb9bd515dc3fde56f02 (diff)
downloadzig-playground-107017c693333b5deeb484d23010e38534d1fe03.tar.gz
zig-playground-107017c693333b5deeb484d23010e38534d1fe03.zip
mbr: example to query memory map (e820)HEADmain
Diffstat (limited to 'x86-bare-metal/mbr-e820/Makefile')
-rw-r--r--x86-bare-metal/mbr-e820/Makefile29
1 files changed, 29 insertions, 0 deletions
diff --git a/x86-bare-metal/mbr-e820/Makefile b/x86-bare-metal/mbr-e820/Makefile
new file mode 100644
index 0000000..5dc465f
--- /dev/null
+++ b/x86-bare-metal/mbr-e820/Makefile
@@ -0,0 +1,29 @@
+O := BUILD
+
+COMMON_FLAGS := -fno-unwind-tables -fno-strip -target x86-freestanding-code16 -O ReleaseSmall -mcpu=i386
+
+$(O)/boot: $(O)/boot.elf | check_ep dump_info
+ objcopy -O binary $< $@
+
+$(O)/boot.elf: mbr.ld mbr.zig | $(O)
+ zig build-exe -femit-bin=$@ $(COMMON_FLAGS) -fno-entry --script $^
+
+clean:
+ $(RM) -r $(O)
+
+$(O):
+ mkdir -p $(O)
+
+# Check entry point is exactly at 0x7c00.
+check_ep: $(O)/boot.elf
+ readelf -h $< | awk '/Entry point address:/ { print $$4 }' | grep 0x7c00 >& /dev/null
+
+# Dump some debug info (disasm, elf load segments, code size).
+dump_info: $(O)/boot.elf
+ objdump -Mintel -m i8086 --disassemble --visualize-jumps=extended-color $<
+ readelf -W -l $<
+ size $<
+ size $< | awk '/$(notdir $<)/ { print "MBR utilization " $$1/512 "%" }'
+
+run: $(O)/boot
+ qemu-system-i386 -hda $< $(QEMU_ARGS)