From 3e47427b06219a5b9e664fce08414c66cd47aafb Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 25 Nov 2020 14:32:16 +0500 Subject: [PATCH] Make kernel in separate directory --- Makefile | 74 +++++--------------------------------- src/.gitignore | 1 + src/Makefile | 68 +++++++++++++++++++++++++++++++++++ linker.ld => src/linker.ld | 0 4 files changed, 78 insertions(+), 65 deletions(-) create mode 100644 src/.gitignore create mode 100644 src/Makefile rename linker.ld => src/linker.ld (100%) diff --git a/Makefile b/Makefile index 5e6f642..b65c0e8 100644 --- a/Makefile +++ b/Makefile @@ -1,65 +1,15 @@ -CCPREFIX = i686-elf- - -AR = $(CCPREFIX)ar -AS = $(CCPREFIX)as -CC = $(CCPREFIX)gcc - GRUBCFG = rootfs/boot/grub/grub.cfg KERNEL = rootfs/boot/kernelmq.multiboot2 PROCMAN = rootfs/boot/procman -CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra - IMAGE = image.iso -# Architecture-dependent -OBJS = start.s.o -OBJS += main.c.o -OBJS += init.c.o -OBJS += multiboot.c.o -OBJS += panic.c.o panic.asm.cpp.o -OBJS += pfa.c.o -OBJS += paging.c.o paging.asm.cpp.o -OBJS += pagedir.c.o - -# Architecture-independent -OBJS += info.c.o - -# Stdlib -OBJS += memset.c.o -OBJS += strlen.c.o -OBJS += itoa.c.o -OBJS += strncpy.c.o - -# Built-in drivers -OBJS += console.c.o -OBJS += pic.c.o -OBJS += timer.c.o - -# For debugging -OBJS += logger.c.o - -OBJS += protected.c.o protected.asm.cpp.o - -OBJS += tss.c.o tss.asm.cpp.o -OBJS += tasks.asm.cpp.o - -OBJS += interrupt.asm.cpp.o - -OBJS += exception.c.o -OBJS += hwint.c.o -OBJS += syscall.c.o - -OBJS := $(addprefix src/, $(OBJS)) - run: $(IMAGE) qemu-system-i386 -cdrom $< -display none -serial stdio clean: - rm -f $(OBJS) - rm -f $(IMAGE) - rm -f $(KERNEL) - rm -f $(PROCMAN) + rm -f $(KERNEL) $(PROCMAN) + make -C src clean make -C procman clean $(IMAGE): $(GRUBCFG) $(KERNEL) $(PROCMAN) @@ -69,20 +19,14 @@ $(KERNEL): $(OBJS) $(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^ grub-file --is-x86-multiboot2 $@ +$(KERNEL): src/kernelmq.multiboot2 + cp $< $@ + $(PROCMAN): procman/procman - cp procman/procman $(PROCMAN) + cp $< $@ + +src/kernelmq.multiboot2: + make -C src kernelmq.multiboot2 procman/procman: make -C procman procman - -%.c.o: %.c - $(CC) -c $< -o $@ $(CFLAGS) - -%.s.o: %.s - $(AS) $< -o $@ - -%.asm.cpp.o: %.asm.cpp - nasm -felf32 -o $@ $< - -%.asm.cpp: %.asm - cpp -P $< $@ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..e8e784e --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +/kernelmq.multiboot2 diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..c699084 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,68 @@ +CCPREFIX = i686-elf- + +AR = $(CCPREFIX)ar +AS = $(CCPREFIX)as +CC = $(CCPREFIX)gcc + +KERNEL = kernelmq.multiboot2 + +CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra + +# Architecture-dependent +OBJS = start.s.o +OBJS += main.c.o +OBJS += init.c.o +OBJS += multiboot.c.o +OBJS += panic.c.o panic.asm.cpp.o +OBJS += pfa.c.o +OBJS += paging.c.o paging.asm.cpp.o +OBJS += pagedir.c.o + +# Architecture-independent +OBJS += info.c.o + +# Stdlib +OBJS += memset.c.o +OBJS += strlen.c.o +OBJS += itoa.c.o +OBJS += strncpy.c.o + +# Built-in drivers +OBJS += console.c.o +OBJS += pic.c.o +OBJS += timer.c.o + +# For debugging +OBJS += logger.c.o + +OBJS += protected.c.o protected.asm.cpp.o + +OBJS += tss.c.o tss.asm.cpp.o +OBJS += tasks.asm.cpp.o + +OBJS += interrupt.asm.cpp.o + +OBJS += exception.c.o +OBJS += hwint.c.o +OBJS += syscall.c.o + +all: $(KERNEL) + +clean: + rm -f $(KERNEL) $(OBJS) + +$(KERNEL): $(OBJS) + $(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^ + grub-file --is-x86-multiboot2 $@ + +%.c.o: %.c + $(CC) -c $< -o $@ $(CFLAGS) + +%.s.o: %.s + $(AS) $< -o $@ + +%.asm.cpp.o: %.asm.cpp + nasm -felf32 -o $@ $< + +%.asm.cpp: %.asm + cpp -P $< $@ diff --git a/linker.ld b/src/linker.ld similarity index 100% rename from linker.ld rename to src/linker.ld