From 78c1155430faa285f85c1bad6e3e21f82d308f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 23 Feb 2018 18:50:05 +0100 Subject: [PATCH] Organizing the kernel code. --- Makefile | 27 +++++++++------------ boot_sect.asm => boot/boot_sect.asm | 0 disk.asm => boot/disk.asm | 0 gdt.asm => boot/gdt.asm | 0 print.asm => boot/print.asm | 0 print32.asm => boot/print32.asm | 0 switch_prot.asm => boot/switch_prot.asm | 0 kernel.c => kernel/kernel.c | 0 kernel_entry.asm => kernel/kernel_entry.asm | 0 9 files changed, 11 insertions(+), 16 deletions(-) rename boot_sect.asm => boot/boot_sect.asm (100%) rename disk.asm => boot/disk.asm (100%) rename gdt.asm => boot/gdt.asm (100%) rename print.asm => boot/print.asm (100%) rename print32.asm => boot/print32.asm (100%) rename switch_prot.asm => boot/switch_prot.asm (100%) rename kernel.c => kernel/kernel.c (100%) rename kernel_entry.asm => kernel/kernel_entry.asm (100%) diff --git a/Makefile b/Makefile index 85a20a9..905c5cd 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,33 @@ ASM=nasm -AFLAGS=-f bin BIN=bin CFLAGS=-ffreestanding -fno-pie -m32 CC=gcc LD=ld LDFLAGS=-melf_i386 -Ttext 0x1000 --oformat binary +OBJ=kernel/kernel_entry.o kernel/kernel.o + all: os-image -os-image: boot_sect.bin kernel.bin +os-image: boot/boot_sect.bin kernel.bin mkdir -p $(BIN) cat $^ > $(BIN)/$@ # build kernel binary file -kernel.bin: kernel_entry.o kernel.o +kernel.bin: $(OBJ) $(LD) $(LDFLAGS) $^ -o $@ -# build kernel object file -kernel.o: kernel.c +%.o: %.c ${HEADERS} $(CC) $(CFLAGS) -c $< -o $@ -# build kernel entry object file -kernel_entry.o: kernel_entry.asm - $(ASM) -f elf $< -o $@ - -boot_sect.bin: boot_sect.asm - $(ASM) $< $(AFLAGS) -o $@ - -basicos: boot_sect.bin kernel.bin - mkdir -p $(BIN) - cat boot_sect.bin kernel.bin > $(BIN)/os-image +%.o: %.asm + $(ASM) $< -f elf -o $@ +%.bin: %.asm + $(ASM) $< -f bin -I 'boot/' -o $@ .PHONY: clean clean: - rm -f *.bin *.o + rm -rf boot/*.bin boot/*.o + rm -rf kernel/*.o boot/*.o drivers/*.o diff --git a/boot_sect.asm b/boot/boot_sect.asm similarity index 100% rename from boot_sect.asm rename to boot/boot_sect.asm diff --git a/disk.asm b/boot/disk.asm similarity index 100% rename from disk.asm rename to boot/disk.asm diff --git a/gdt.asm b/boot/gdt.asm similarity index 100% rename from gdt.asm rename to boot/gdt.asm diff --git a/print.asm b/boot/print.asm similarity index 100% rename from print.asm rename to boot/print.asm diff --git a/print32.asm b/boot/print32.asm similarity index 100% rename from print32.asm rename to boot/print32.asm diff --git a/switch_prot.asm b/boot/switch_prot.asm similarity index 100% rename from switch_prot.asm rename to boot/switch_prot.asm diff --git a/kernel.c b/kernel/kernel.c similarity index 100% rename from kernel.c rename to kernel/kernel.c diff --git a/kernel_entry.asm b/kernel/kernel_entry.asm similarity index 100% rename from kernel_entry.asm rename to kernel/kernel_entry.asm