aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorXander <xander@icth.xyz>2023-06-28 17:20:46 +0200
committerXander <xander@icth.xyz>2023-06-28 17:20:46 +0200
commitb83b28b21571f9b1fadd251295f5ca03d9dfedc7 (patch)
tree0de3d841a23358aedc706fdedc35fec7ff4e773a /Makefile
parentebc6738ad4265db0b2b8d1b5c653d8f9597ff335 (diff)
downloadats-os-b83b28b21571f9b1fadd251295f5ca03d9dfedc7.tar.xz
ats-os-b83b28b21571f9b1fadd251295f5ca03d9dfedc7.zip
Booting to protected mode
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile36
1 files changed, 36 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..6d4c9a8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,36 @@
+arch ?= x86_64
+kernel := build/kernel-$(arch).bin
+iso := build/os-$(arch).iso
+
+linker_script := src/arch/$(arch)/linker.ld
+grub_cfg := src/arch/$(arch)/grub.cfg
+assembly_source_files := $(wildcard src/arch/$(arch)/*.asm)
+assembly_object_files := $(patsubst src/arch/$(arch)/%.asm, \
+ build/arch/$(arch)/%.o, $(assembly_source_files))
+
+.PHONY: all clean run iso
+
+all: $(kernel)
+
+clean:
+ @rm -r build
+
+run: $(iso)
+ @qemu-system-x86_64 -cdrom $(iso)
+
+iso: $(iso)
+
+$(iso): $(kernel) $(grub_cfg)
+ @mkdir -p build/isofiles/boot/grub
+ @cp $(kernel) build/isofiles/boot/kernel.bin
+ @cp $(grub_cfg) build/isofiles/boot/grub
+ @grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
+ @rm -r build/isofiles
+
+$(kernel): $(assembly_object_files) $(linker_script)
+ @ld -n -T $(linker_script) -o $(kernel) $(assembly_object_files)
+
+# compile assembly files
+build/arch/$(arch)/%.o: src/arch/$(arch)/%.asm
+ @mkdir -p $(shell dirname $@)
+ @nasm -felf64 $< -o $@