2018-07-20 15:41:58 +02:00
|
|
|
# Used to generated .d file that deal with header dependencies
|
|
|
|
CPPFLAGS = -MMD
|
|
|
|
AS=nasm
|
|
|
|
ASFLAGS += -f elf32
|
2018-11-16 14:47:21 +01:00
|
|
|
#LDFLAGS += -m32 -nostdlib -mkernel -fno-stack-protector
|
2018-11-09 10:50:20 +01:00
|
|
|
LDFLAGS += -m32 -nostdlib -static -fno-common -fno-use-cxa-atexit -fno-exceptions -fno-non-call-exceptions -fno-weak -fno-rtti -fno-stack-protector
|
2019-05-16 23:45:45 +02:00
|
|
|
CFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-pie -fno-stack-protector -fno-tree-vectorize
|
2018-11-19 13:56:19 +01:00
|
|
|
CXXFLAGS += -m32 -Wall -Wextra -Werror -ffreestanding -fno-exceptions -fno-rtti -fno-pie
|
|
|
|
DEBUG_FLAGS += -g -Og -DDEBUG -fno-omit-frame-pointer -fno-inline
|
2018-07-20 15:41:58 +02:00
|
|
|
|
2020-04-27 23:45:38 +02:00
|
|
|
ARCH?=x86
|
|
|
|
SUBDIRS := core drivers tests arch/$(ARCH)
|
2018-07-20 15:41:58 +02:00
|
|
|
|
|
|
|
CPPFLAGS += $(foreach dir, $(SUBDIRS), -I$(dir))
|
|
|
|
|
2020-04-29 23:07:01 +02:00
|
|
|
asmsrc=$(wildcard arch/$(ARCH)/boot/*.asm)
|
2018-07-20 15:41:58 +02:00
|
|
|
asmobj=$(asmsrc:%.asm=%.o)
|
|
|
|
csrc=$(shell find $(SUBDIRS) -type f -name "*.c")# $(wildcard *.c)
|
2020-04-27 23:45:38 +02:00
|
|
|
cobj=$(csrc:%.c=%.o) arch/$(ARCH)/cpu_context_switch.o arch/$(ARCH)/irq_pit.o
|
2018-07-20 15:41:58 +02:00
|
|
|
deps = $(csrc:%.c=%.d)
|
|
|
|
|
|
|
|
kernel:$(asmobj) $(cobj) linker.ld
|
2018-07-20 16:41:32 +02:00
|
|
|
$(CC) -m32 -ffreestanding -nostdlib $(cobj) $(asmobj) -o $@ -T linker.ld
|
2018-07-20 17:10:58 +02:00
|
|
|
objcopy --only-keep-debug $@ $@.sym
|
|
|
|
objcopy --strip-debug $@
|
|
|
|
|
2018-07-20 16:55:41 +02:00
|
|
|
fd.iso: kernel
|
|
|
|
mkdir -p isodir/boot/grub
|
2018-08-05 14:12:18 +02:00
|
|
|
cp $< isodir/boot/
|
2019-05-12 22:56:51 +02:00
|
|
|
@printf "menuentry \"myos\" {\n\tmultiboot /boot/kernel\n}" > isodir/boot/grub/grub.cfg
|
2018-07-20 16:55:41 +02:00
|
|
|
grub-mkrescue -o $@ isodir
|
|
|
|
|
2018-07-20 15:41:58 +02:00
|
|
|
|
|
|
|
#https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#x86-Function-Attributes
|
2020-04-27 23:45:38 +02:00
|
|
|
arch/$(ARCH)/exception_handler.o:arch/$(ARCH)/exception_handler.c
|
2018-11-16 19:57:56 +01:00
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -mgeneral-regs-only -c $< -o $@
|
2020-04-27 23:45:38 +02:00
|
|
|
arch/$(ARCH)/irq_handler.o:arch/$(ARCH)/irq_handler.c
|
2018-11-16 19:57:56 +01:00
|
|
|
$(CC) $(CFLAGS) $(CPPFLAGS) -mgeneral-regs-only -c $< -o $@
|
2018-07-20 15:41:58 +02:00
|
|
|
|
|
|
|
%.o:%.asm
|
|
|
|
$(AS) $(ASFLAGS) -o $@ $<
|
|
|
|
|
2019-05-15 23:22:28 +02:00
|
|
|
%.o: %.S
|
|
|
|
$(CC) "-I$(PWD)" -c "$<" $(CFLAGS) -o "$@"
|
|
|
|
|
|
|
|
|
2018-11-19 13:56:19 +01:00
|
|
|
self_test: CFLAGS += -DRUN_TEST -DDEBUG
|
2018-11-08 22:09:12 +01:00
|
|
|
self_test: clean kernel
|
|
|
|
qemu-system-x86_64 -kernel kernel -serial stdio
|
|
|
|
|
2018-07-20 15:41:58 +02:00
|
|
|
test:kernel
|
2018-07-20 16:41:32 +02:00
|
|
|
qemu-system-x86_64 -kernel $<
|
2018-07-20 15:41:58 +02:00
|
|
|
|
2018-11-16 14:47:21 +01:00
|
|
|
debug: CFLAGS += $(DEBUG_FLAGS)
|
|
|
|
debug: CXXFLAGS += $(DEBUG_FLAGS)
|
2018-08-05 14:12:18 +02:00
|
|
|
debug:kernel kernel.sym
|
2020-04-19 14:30:48 +02:00
|
|
|
#qemu-system-x86_64 -s -S -kernel kernel&
|
|
|
|
qemu-system-i386 -s -S -kernel kernel&
|
2020-05-06 21:05:09 +02:00
|
|
|
gdb -s kernel.sym -ex "target remote localhost:1234" -ex "dir core:driver:arch/$(ARCH))'"
|
2018-08-05 14:12:18 +02:00
|
|
|
|
2018-07-20 15:41:58 +02:00
|
|
|
clean:
|
2018-07-20 17:10:58 +02:00
|
|
|
$(RM) kernel $(asmobj) $(cobj) $(deps) fd.iso kernel.sym
|
2019-01-09 17:21:51 +01:00
|
|
|
$(RM) -r isodir
|
2018-07-20 15:41:58 +02:00
|
|
|
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
-include $(deps)
|
|
|
|
endif
|