diff --git a/test/.gitignore b/test/.gitignore index 4ce83ce5..78e641bf 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,2 +1,3 @@ test.o test.elf +limine.h diff --git a/test/GNUmakefile b/test/GNUmakefile index 8f3329a3..bfc80ee9 100644 --- a/test/GNUmakefile +++ b/test/GNUmakefile @@ -12,56 +12,80 @@ override LD := $(LD_FOR_TARGET) override QEMU := qemu-system-x86_64 QEMUFLAGS = -m 1G -enable-kvm -cpu host -override INTERNALLDFLAGS := \ - -Tlinker.ld \ - -nostdlib \ - -zmax-page-size=0x1000 \ - -static \ - -pie \ - --no-dynamic-linker \ - -ztext +ifneq ($(findstring x86_64,$(CC_FOR_TARGET)),) +override LDFLAGS += \ + -m elf_x86_64 +endif +ifneq ($(findstring aarch64,$(CC_FOR_TARGET)),) +override LDFLAGS += \ + -m aarch64elf +endif -override INTERNAL_LD_FLAGS_MULTIBOOT2 := \ - -m elf_i386 \ - -Tmultiboot2.ld \ - -nostdlib \ - -zmax-page-size=0x1000 \ - -static +override LDFLAGS += \ + -Tlinker.ld \ + -nostdlib \ + -zmax-page-size=0x1000 \ + -static \ + -pie \ + --no-dynamic-linker \ + -ztext -override INTERNAL_LD_FLAGS_MULTIBOOT1 := \ - -m elf_i386 \ - -Tmultiboot.ld \ - -nostdlib \ - -zmax-page-size=0x1000 \ - -static +override LDFLAGS_MB2 := \ + -m elf_i386 \ + -Tmultiboot2.ld \ + -nostdlib \ + -zmax-page-size=0x1000 \ + -static -override INTERNALCFLAGS := \ - -std=c11 \ - -ffreestanding \ - -fno-stack-protector \ - -fno-stack-check \ - -fno-lto \ - -fPIE \ - -mgeneral-regs-only \ - -mno-red-zone \ - -I. \ - -I.. +override LDFLAGS_MB1 := \ + -m elf_i386 \ + -Tmultiboot.ld \ + -nostdlib \ + -zmax-page-size=0x1000 \ + -static -override INTERNALCFLAGS_MB := \ - -std=c11 \ - -ffreestanding \ - -fno-stack-protector \ - -fno-stack-check \ - -fno-lto \ - -fno-PIE \ - -fno-PIC \ - -m32 \ - -march=i686 \ - -mabi=sysv \ - -mno-80387 \ - -I. \ - -I.. \ - -I../common/protos +override CFLAGS += \ + -std=c11 \ + -nostdinc \ + -ffreestanding \ + -fno-stack-protector \ + -fno-stack-check \ + -fno-lto \ + -fPIE \ + -I../freestanding-headers \ + -I. \ + -D_LIMINE_PROTO + +ifneq ($(findstring x86_64,$(CC_FOR_TARGET)),) +override CFLAGS += \ + -m64 \ + -march=x86-64 \ + -mabi=sysv \ + -mgeneral-regs-only \ + -mno-red-zone +endif + +ifneq ($(findstring aarch64,$(CC_FOR_TARGET)),) +override CFLAGS += \ + -mgeneral-regs-only +endif + +override CFLAGS_MB := \ + -std=c11 \ + -nostdinc \ + -ffreestanding \ + -fno-stack-protector \ + -fno-stack-check \ + -fno-lto \ + -fno-PIE \ + -fno-PIC \ + -m32 \ + -march=i686 \ + -mabi=sysv \ + -mgeneral-regs-only \ + -I../freestanding-headers \ + -I. \ + -I../common/protos ifneq ($(findstring 86,$(CC_FOR_TARGET)),) all: test.elf multiboot2.elf multiboot.elf @@ -69,21 +93,26 @@ else all: test.elf endif +limine.h: + cp -v ../limine.h ./ + test.elf: limine.o e9print.o memory.o - $(LD) $^ $(LDFLAGS) $(INTERNALLDFLAGS) -o $@ + $(LD) $^ $(LDFLAGS) -o $@ multiboot2.elf: multiboot2_trampoline.o - $(CC) $(CFLAGS) $(INTERNALCFLAGS_MB) -c multiboot2.c -o multiboot2.o - $(CC) $(CFLAGS) $(INTERNALCFLAGS_MB) -c e9print.c -o e9print.o - $(LD) $^ multiboot2.o e9print.o $(LDFLAGS) $(INTERNAL_LD_FLAGS_MULTIBOOT2) -m elf_i386 -o $@ + $(CC) $(CFLAGS_MB) -c memory.c -o memory.o + $(CC) $(CFLAGS_MB) -c multiboot2.c -o multiboot2.o + $(CC) $(CFLAGS_MB) -c e9print.c -o e9print.o + $(LD) $^ memory.o multiboot2.o e9print.o $(LDFLAGS_MB2) -o $@ multiboot.elf: multiboot_trampoline.o - $(CC) $(CFLAGS) $(INTERNALCFLAGS_MB) -c multiboot.c -o multiboot.o - $(CC) $(CFLAGS) $(INTERNALCFLAGS_MB) -c e9print.c -o e9print.o - $(LD) $^ multiboot.o e9print.o $(LDFLAGS) $(INTERNAL_LD_FLAGS_MULTIBOOT1) -m elf_i386 -o $@ + $(CC) $(CFLAGS_MB) -c memory.c -o memory.o + $(CC) $(CFLAGS_MB) -c multiboot.c -o multiboot.o + $(CC) $(CFLAGS_MB) -c e9print.c -o e9print.o + $(LD) $^ memory.o multiboot.o e9print.o $(LDFLAGS_MB1) -o $@ -%.o: %.c - $(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@ +%.o: %.c limine.h + $(CC) $(CFLAGS) -c $< -o $@ %.o: %.asm nasm -felf32 -F dwarf -g $< -o $@ @@ -92,3 +121,4 @@ clean: rm -rf test.elf limine.o e9print.o memory.o rm -rf multiboot2.o multiboot2.elf multiboot2_trampoline.o rm -rf multiboot.o multiboot_trampoline.o multiboot.elf + rm -rf limine.h diff --git a/test/limine.c b/test/limine.c index 9e103dea..87b9754f 100644 --- a/test/limine.c +++ b/test/limine.c @@ -244,7 +244,7 @@ static void write_shim(const char *s, uint64_t l) { _terminal_request.response->write(terminal, s, l); } -void limine_main(void) { +static void limine_main(void) { if (_terminal_request.response) { limine_print = write_shim; } diff --git a/test/linker.ld b/test/linker.ld index ce95d7f3..d1b5e892 100644 --- a/test/linker.ld +++ b/test/linker.ld @@ -1,5 +1,3 @@ -ENTRY(limine_main) - PHDRS { text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */