diff --git a/Makefile b/Makefile index e69de29..8d8721e 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,22 @@ +export BASE_DIR=$(shell pwd) +export TARGET_ISO=HelloOS.iso +export CONFIG_x86_64=y +export CC=gcc +export AS=as +export HIDE=@ +ifneq ($(HIDE),) + MAKEFLAGS += --no-print-dirctory +endif + + +HelloOS: + $(HIDE)make -C arch + +clean: + $(HIDE)make -C arch clean + +cleanall: + $(HIDE)make -C arch cleanall + +run: + qemu-system-x86_64 -m 1G -cdrom arch/$(TARGET_ISO) -nographic \ No newline at end of file diff --git a/arch/Makefile b/arch/Makefile new file mode 100644 index 0000000..d0570c1 --- /dev/null +++ b/arch/Makefile @@ -0,0 +1,34 @@ +kernel_target=kernel.elf +SRCS = $(BASE_DIR)/init $(BASE_DIR)/kernel $(BASE_DIR)/mm +ifeq ($(CONFIG_x86_64), y) + SRCS += $(BASE_DIR)/arch/x86 + lds = $(BASE_DIR)/arch/x86/boot/vmlinux.lds +else + $(HIDE)echo "unkown arch..." +endif + +$(TARGET_ISO): $(kernel_target) + $(HIDE)rm -rf build_dir + $(HIDE)mkdir -p build_dir/boot/grub + $(HIDE)cp $(kernel_target) build_dir/boot + + $(HIDE)echo 'set timeout=0' > build_dir/boot/grub/grub.cfg + $(HIDE)echo 'set default=0' >> build_dir/boot/grub/grub.cfg + $(HIDE)echo 'menuentry "HelloOS" {' >> build_dir/boot/grub/grub.cfg + $(HIDE)echo ' multiboot2 /boot/kernel.elf "HelloOS"' >> build_dir/boot/grub/grub.cfg + $(HIDE)echo '}' >> build_dir/boot/grub/grub.cfg + + $(HIDE)grub-mkrescue -o $(TARGET_ISO) build_dir + $(HIDE)rm -rf build_dir + +$(kernel_target): + $(HIDE)for dir in $(SRCS); do \ + make -C $$dir || exit 1; \ + done + $(HIDE)ld -b elf64-x86-64 -z muldefs -o $(kernel_target) -Map=./kernel.map -T $(lds) $(shell find $(SRCS) -name "*.o") + +clean: + $(HIDE)rm -rf $(kernel_target) $(TARGET_ISO) kernel.map + +cleanall: clean + $(HIDE)rm -rf $(kernel_target) $(TARGET_ISO) \ No newline at end of file diff --git a/arch/x86/Makefile b/arch/x86/Makefile new file mode 100644 index 0000000..4044ecd --- /dev/null +++ b/arch/x86/Makefile @@ -0,0 +1,9 @@ +export ASFLAGS=--64 +export CFLAGS = -I$(BASE_DIR)/include --static -fno-pie -fno-builtin -fno-stack-protector -m64 + +x86_srcs = boot kernel + +build: + $(HIDE)for dir in $(x86_srcs); do \ + make -C $$dir || exit 1; \ + done \ No newline at end of file diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile new file mode 100644 index 0000000..8015748 --- /dev/null +++ b/arch/x86/boot/Makefile @@ -0,0 +1,6 @@ + +build: header.o + +header.o: header.S + $(HIDE)$(CC) -E $(CFLAGS) $< > header.i + $(HIDE)$(AS) $(ASFLAGS) -o $@ header.i diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile new file mode 100644 index 0000000..f527665 --- /dev/null +++ b/arch/x86/kernel/Makefile @@ -0,0 +1,4 @@ + +head_64.o: head_64.S + $(HIDE)$(CC) -E $(CFLAGS) $< > head_64.i + $(HIDE)$(AS) $(ASFLAGS) -o $@ head_64.i \ No newline at end of file diff --git a/init/Makefile b/init/Makefile new file mode 100644 index 0000000..f04bf7b --- /dev/null +++ b/init/Makefile @@ -0,0 +1,3 @@ + +build: + echo "init" \ No newline at end of file diff --git a/kernel/Makefile b/kernel/Makefile new file mode 100644 index 0000000..6c490cd --- /dev/null +++ b/kernel/Makefile @@ -0,0 +1,4 @@ + +build: + echo $(baseDir) + diff --git a/mm/Makefile b/mm/Makefile new file mode 100644 index 0000000..4ce1b39 --- /dev/null +++ b/mm/Makefile @@ -0,0 +1,3 @@ + +build: + echo "mm" \ No newline at end of file