From 4130562b1555cabe441efe9420cebe12e7ed8d39 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 13 Jan 2024 16:43:49 -0500 Subject: application loading --- makefile | 58 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'makefile') diff --git a/makefile b/makefile index 82734bc..7b14369 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,12 @@ -GPP_ARGS = -Wall -Wextra -O3 -ggdb -I include -ffreestanding -fno-exceptions -fno-rtti -mno-sse -KERNEL_OBJECTS = allocator.cpp entry.cpp framebuffer.cpp paging.asm paging.cpp storage.cpp \ - storage/bd/memory.cpp storage/fs/tarfs.cpp terminal.cpp utility.cpp vfile.cpp +GPP_ARGS = -Wall -Wextra -O3 -ggdb -I include \ + -ffreestanding -fno-exceptions -fno-rtti -mno-sse +KGPP_ARGS = ${GPP_ARGS} +AGPP_ARGS = ${GPP_ARGS} + +LD_ARGS = -z noexecstack +KLD_ARGS = -T kernel/link.ld ${LD_ARGS} +ALD_ARGS = -T applications/link.ld ${LD_ARGS} +LLD_ARGS = ${LD_ARGS} all: out/disk.iso @@ -15,37 +21,61 @@ dist-clean: rm -f include/mercury/kernel/limine.hpp limine: - git clone --depth=1 -b v6.x-branch https://github.com/limine-bootloader/limine.git limine + git clone --depth=1 -b v6.x-branch \ + https://github.com/limine-bootloader/limine.git limine cd limine && ./bootstrap && ./configure -q --enable-bios --enable-bios-cd +make -C limine cp limine/limine.h include/mercury/kernel/limine.hpp obj/kernel/entry.cpp.o: kernel/entry.cpp limine @mkdir -p $(@D) - g++ -c ${GPP_ARGS} $< -o $@ + g++ -c ${KGPP_ARGS} $< -o $@ obj/kernel/%.cpp.o: kernel/%.cpp @mkdir -p $(@D) - g++ -c ${GPP_ARGS} $< -o $@ + g++ -c ${KGPP_ARGS} $< -o $@ obj/kernel/%.asm.o: kernel/%.asm @mkdir -p $(@D) nasm -f elf64 $< -o $@ +KERNEL_OBJECTS = allocator.cpp application.cpp entry.cpp framebuffer.cpp \ + paging.asm paging.cpp storage.cpp storage/bd/memory.cpp terminal.cpp \ + storage/fs/tarfs.cpp utility.cpp vfile.cpp syscall.asm syscall.cpp obj/kernel.elf: ${KERNEL_OBJECTS:%=obj/kernel/%.o} - ld -T kernel/link.ld $^ -o $@ + ld ${KLD_ARGS} $^ -o $@ + +obj/stdlib/%.asm.o: stdlib/%.asm + @mkdir -p $(@D) + nasm -f elf64 $< -o $@ + +obj/stdlib/%.cpp.o: stdlib/%.cpp + @mkdir -p $(@D) + g++ -c ${AGPP_ARGS} $< -o $@ + +STDLIB_OBJECTS = entry.cpp syscall.asm +obj/stdlib.o: ${STDLIB_OBJECTS:%=obj/stdlib/%.o} + ld -r ${LLD_ARGS} $^ -o $@ + +obj/%.cpp.o: applications/%.cpp + @mkdir -p $(@D) + g++ -c ${AGPP_ARGS} $< -o $@ + +INIT_OBJECTS = main.cpp +obj/initfs/bin/init.elf: ${INIT_OBJECTS:%=obj/init/%.o} obj/stdlib.o + @mkdir -p $(@D) + ld ${ALD_ARGS} $^ -o $@ -obj/initfs.tgz: - @mkdir -p obj/initfs - echo test > obj/initfs/test.txt - mkdir -p obj/initfs/dir/dir2 - ln -s ../test.txt obj/initfs/dir/test2.txt +APPLICATIONS = init +obj/initfs.tgz: ${APPLICATIONS:%=obj/initfs/bin/%.elf} tar czf obj/initfs.tgz -C obj/initfs . out/disk.iso: obj/kernel.elf obj/initfs.tgz limine mkdir -p obj/iso out - cp obj/kernel.elf obj/initfs.tgz limine/bin/limine-bios.sys limine/bin/limine-bios-cd.bin limine.cfg obj/iso/ + cp obj/kernel.elf obj/initfs.tgz limine/bin/limine-bios.sys \ + limine/bin/limine-bios-cd.bin limine.cfg obj/iso/ cp terminus/ter-u16b.psf obj/iso/termfont.psf - xorriso -as mkisofs -quiet -no-emul-boot -boot-info-table -boot-load-size 4 -b limine-bios-cd.bin obj/iso -o $@ + xorriso -as mkisofs -quiet -no-emul-boot -boot-info-table \ + -boot-load-size 4 -b limine-bios-cd.bin obj/iso -o $@ limine/bin/limine bios-install $@ rm -rf obj/iso -- cgit v1.2.3