Fixes and improvements for Limine 9.x

This commit is contained in:
Mintsuki 2025-03-27 22:32:16 +01:00
parent af8e036e7b
commit fc076d183c
4 changed files with 57 additions and 57 deletions

View File

@ -66,7 +66,7 @@ umount_tempdisk
echo "Rebuilding kernel headers, kernel, OS, and building Distro ISO ..." echo "Rebuilding kernel headers, kernel, OS, and building Distro ISO ..."
$QEMU_BIN_PATH/qemu-system-x86_64 -machine q35 $KVM -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -smp 4 -device isa-debug-exit $QEMU_HEADLESS $QEMU_BIN_PATH/qemu-system-x86_64 -machine q35 $KVM -drive format=raw,file=$TMPDISK -m 1G -rtc base=localtime -smp 4 -device isa-debug-exit $QEMU_HEADLESS
LIMINE_BINARY_BRANCH="v8.x-binary" LIMINE_BINARY_BRANCH="v9.x-binary"
if [ -d "limine" ] if [ -d "limine" ]
then then
@ -116,13 +116,13 @@ sudo mv $TMPMOUNT/Tmp/DVDKernel.ZXE $TMPISODIR/Boot/Kernel.ZXE
sudo rm $TMPISODIR/Tmp/DVDKernel.ZXE 2> /dev/null sudo rm $TMPISODIR/Tmp/DVDKernel.ZXE 2> /dev/null
umount_tempdisk umount_tempdisk
xorriso -joliet "on" -rockridge "on" -as mkisofs -b Boot/Limine-BIOS-CD.BIN \ xorriso -as mkisofs -R -r -J -b Boot/Limine-BIOS-CD.BIN \
-no-emul-boot -boot-load-size 4 -boot-info-table \ -no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
--efi-boot Boot/Limine-UEFI-CD.BIN \ -apm-block-size 2048 --efi-boot Boot/Limine-UEFI-CD.BIN \
-efi-boot-part --efi-boot-image --protective-msdos-label \ -efi-boot-part --efi-boot-image --protective-msdos-label \
$TMPISODIR -o ZealOS-limine.iso $TMPISODIR -o ZealOS-limine.iso
./limine/limine bios-install ZealOS-limine.iso ./limine/limine bios-install ZealOS-limine.iso --no-gpt-to-mbr-isohybrid-conversion
if [ "$TESTING" = true ]; then if [ "$TESTING" = true ]; then
if [ ! -d "ovmf" ]; then if [ ! -d "ovmf" ]; then

View File

@ -6,45 +6,41 @@ MAKEFLAGS += -rR
# Change as needed. # Change as needed.
override OUTPUT := kernel override OUTPUT := kernel
# Convenience macro to reliably declare user overridable variables.
override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2)))
# User controllable C compiler command. # User controllable C compiler command.
$(call USER_VARIABLE,KCC,cc) CC := cc
# User controllable linker command. # User controllable archiver command.
$(call USER_VARIABLE,KLD,ld) AR := ar
# User controllable C flags. # User controllable C flags.
$(call USER_VARIABLE,KCFLAGS,-g -O2 -pipe) CFLAGS := -g -O2 -pipe
# User controllable C preprocessor flags. We set none by default. # User controllable C preprocessor flags. We set none by default.
$(call USER_VARIABLE,KCPPFLAGS,) CPPFLAGS :=
# User controllable nasm flags. # User controllable nasm flags.
$(call USER_VARIABLE,KNASMFLAGS,-F dwarf -g) NASMFLAGS := -F dwarf -g
# User controllable linker flags. We set none by default. # User controllable linker flags. We set none by default.
$(call USER_VARIABLE,KLDFLAGS,) LDFLAGS :=
# Check if KCC is Clang. # Check if CC is Clang.
override KCC_IS_CLANG := $(shell ! $(KCC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?) override CC_IS_CLANG := $(shell ! $(CC) --version 2>/dev/null | grep 'clang' >/dev/null 2>&1; echo $$?)
# If the C compiler is Clang, set the target as needed. # If the C compiler is Clang, set the target as needed.
ifeq ($(KCC_IS_CLANG),1) ifeq ($(CC_IS_CLANG),1)
override KCC += \ override CC += \
-target x86_64-unknown-none -target x86_64-unknown-none
endif endif
# Internal C flags that should not be changed by the user. # Internal C flags that should not be changed by the user.
override KCFLAGS += \ override CFLAGS += \
-Wall \ -Wall \
-Wextra \ -Wextra \
-std=gnu11 \ -std=gnu11 \
-ffreestanding \ -ffreestanding \
-fno-stack-protector \ -fno-stack-protector \
-fno-stack-check \ -fno-stack-check \
-fno-lto \
-fno-PIC \ -fno-PIC \
-ffunction-sections \ -ffunction-sections \
-fdata-sections \ -fdata-sections \
@ -58,70 +54,74 @@ override KCFLAGS += \
-mcmodel=kernel -mcmodel=kernel
# Internal C preprocessor flags that should not be changed by the user. # Internal C preprocessor flags that should not be changed by the user.
override KCPPFLAGS := \ override CPPFLAGS := \
-I src \ -I src \
-I src/lib \ -I src/lib \
$(KCPPFLAGS) \ $(CPPFLAGS) \
-DLIMINE_API_REVISION=3 \
-MMD \ -MMD \
-MP -MP
# Internal nasm flags that should not be changed by the user. # Internal nasm flags that should not be changed by the user.
override KNASMFLAGS += \ override NASMFLAGS += \
-Wall \ -Wall \
-f elf64 -f elf64
# Internal linker flags that should not be changed by the user. # Internal linker flags that should not be changed by the user.
override KLDFLAGS += \ override LDFLAGS += \
-m elf_x86_64 \ -Wl,-m,elf_x86_64 \
-Wl,--build-id=none \
-nostdlib \ -nostdlib \
-static \ -static \
-z max-page-size=0x1000 \ -z max-page-size=0x1000 \
-gc-sections \ -Wl,--gc-sections \
-T linker.ld -T linker.ld
# Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the # Use "find" to glob all *.c, *.S, and *.asm files in the tree and obtain the
# object and header dependency file names. # object and header dependency file names.
override CFILES := $(shell cd src && find -L * -type f -name '*.c' | LC_ALL=C sort) override SRCFILES := $(shell cd src && find -L * -type f | LC_ALL=C sort)
override ASFILES := $(shell cd src && find -L * -type f -name '*.S' | LC_ALL=C sort) override CFILES := $(filter %.c,$(SRCFILES))
override NASMFILES := $(shell cd src && find -L * -type f -name '*.asm' | LC_ALL=C sort) override ASFILES := $(filter %.S,$(SRCFILES))
override NASMFILES := $(filter %.asm,$(SRCFILES))
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o)) override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d)) override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
# Default target. # Default target. This must come first, before header dependencies.
.PHONY: all .PHONY: all
all: bin/$(OUTPUT) all: bin/$(OUTPUT)
# Include header dependencies.
-include $(HEADER_DEPS)
src/limine.h: src/limine.h:
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h || cp ../build/limine/limine.h src/limine.h || echo "ERROR" curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h || cp ../build/limine/limine.h src/limine.h || echo "ERROR"
# Link rules for the final executable. # Link rules for the final executable.
bin/$(OUTPUT): GNUmakefile linker.ld $(OBJ) bin/$(OUTPUT): GNUmakefile linker.ld $(OBJ)
mkdir -p "$$(dirname $@)" mkdir -p "$$(dirname $@)"
$(KLD) $(OBJ) $(KLDFLAGS) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@
# Include header dependencies.
-include $(HEADER_DEPS)
# Compilation rules for *.c files. # Compilation rules for *.c files.
obj/%.c.o: src/%.c GNUmakefile src/limine.h obj/%.c.o: src/%.c GNUmakefile src/limine.h
mkdir -p "$$(dirname $@)" mkdir -p "$$(dirname $@)"
$(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.S files. # Compilation rules for *.S files.
obj/%.S.o: src/%.S GNUmakefile src/limine.h obj/%.S.o: src/%.S GNUmakefile src/limine.h
mkdir -p "$$(dirname $@)" mkdir -p "$$(dirname $@)"
$(KCC) $(KCFLAGS) $(KCPPFLAGS) -c $< -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.asm (nasm) files. # Compilation rules for *.asm (nasm) files.
obj/%.asm.o: src/%.asm GNUmakefile obj/%.asm.o: src/%.asm GNUmakefile
mkdir -p "$$(dirname $@)" mkdir -p "$$(dirname $@)"
nasm $(KNASMFLAGS) $< -o $@ nasm $(NASMFLAGS) $< -o $@
# Remove object files and the final executable. # Remove object files and the final executable.
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf bin obj rm -rf bin obj
# Remove everything built and generated including downloaded dependencies.
.PHONY: distclean .PHONY: distclean
distclean: clean distclean: clean
rm -f src/limine.h rm -f src/limine.h

View File

@ -9,7 +9,7 @@ ENTRY(kmain)
/* process. */ /* process. */
PHDRS PHDRS
{ {
requests PT_LOAD; limine_requests PT_LOAD;
text PT_LOAD; text PT_LOAD;
rodata PT_LOAD; rodata PT_LOAD;
data PT_LOAD; data PT_LOAD;
@ -24,11 +24,11 @@ SECTIONS
. = 0xffffffff80000000; . = 0xffffffff80000000;
/* Define a section to contain the Limine requests and assign it to its own PHDR */ /* Define a section to contain the Limine requests and assign it to its own PHDR */
.requests : { .limine_requests : {
KEEP(*(.requests_start_marker)) KEEP(*(.limine_requests_start))
KEEP(*(.requests)) KEEP(*(.limine_requests))
KEEP(*(.requests_end_marker)) KEEP(*(.limine_requests_end))
} :requests } :limine_requests
/* Move to the next memory page for .text */ /* Move to the next memory page for .text */
. = ALIGN(CONSTANT(MAXPAGESIZE)); . = ALIGN(CONSTANT(MAXPAGESIZE));

View File

@ -4,43 +4,43 @@
#include <limine.h> #include <limine.h>
#include <lib.h> #include <lib.h>
__attribute__((used, section(".requests_start_marker"))) __attribute__((used, section(".limine_requests_start")))
static volatile LIMINE_REQUESTS_START_MARKER; static volatile LIMINE_REQUESTS_START_MARKER;
__attribute__((used, section(".requests_end_marker"))) __attribute__((used, section(".limine_requests_end")))
static volatile LIMINE_REQUESTS_END_MARKER; static volatile LIMINE_REQUESTS_END_MARKER;
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_module_request module_request = { static volatile struct limine_module_request module_request = {
.id = LIMINE_MODULE_REQUEST, .id = LIMINE_MODULE_REQUEST,
.revision = 0 .revision = 0
}; };
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_hhdm_request hhdm_request = { static volatile struct limine_hhdm_request hhdm_request = {
.id = LIMINE_HHDM_REQUEST, .id = LIMINE_HHDM_REQUEST,
.revision = 0 .revision = 0
}; };
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_memmap_request memmap_request = { static volatile struct limine_memmap_request memmap_request = {
.id = LIMINE_MEMMAP_REQUEST, .id = LIMINE_MEMMAP_REQUEST,
.revision = 0 .revision = 0
}; };
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_framebuffer_request framebuffer_request = { static volatile struct limine_framebuffer_request framebuffer_request = {
.id = LIMINE_FRAMEBUFFER_REQUEST, .id = LIMINE_FRAMEBUFFER_REQUEST,
.revision = 0 .revision = 0
}; };
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_smbios_request smbios_request = { static volatile struct limine_smbios_request smbios_request = {
.id = LIMINE_SMBIOS_REQUEST, .id = LIMINE_SMBIOS_REQUEST,
.revision = 0 .revision = 0
}; };
__attribute__((used, section(".requests"))) __attribute__((used, section(".limine_requests")))
static volatile struct limine_efi_system_table_request efi_request = { static volatile struct limine_efi_system_table_request efi_request = {
.id = LIMINE_EFI_SYSTEM_TABLE_REQUEST, .id = LIMINE_EFI_SYSTEM_TABLE_REQUEST,
.revision = 0 .revision = 0
@ -292,7 +292,7 @@ void kmain(void) {
printf(" "); printf(" ");
switch (entry->type) { switch (entry->type) {
case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE: case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE:
case LIMINE_MEMMAP_KERNEL_AND_MODULES: case LIMINE_MEMMAP_EXECUTABLE_AND_MODULES:
case LIMINE_MEMMAP_USABLE: case LIMINE_MEMMAP_USABLE:
zeal_mem_type = MEM_E820T_USABLE; zeal_mem_type = MEM_E820T_USABLE;
printf(" USABLE: "); printf(" USABLE: ");
@ -343,7 +343,7 @@ void kmain(void) {
printf("sys_gdt_ptr: 0x%X\n", sys_gdt_ptr); printf("sys_gdt_ptr: 0x%X\n", sys_gdt_ptr);
void *sys_smbios_entry = smbios_request.response->entry_32; void *sys_smbios_entry = (void *)smbios_request.response->entry_32;
if (sys_smbios_entry != NULL) { if (sys_smbios_entry != NULL) {
kernel->sys_smbios_entry = (uintptr_t)sys_smbios_entry - hhdm_request.response->offset; kernel->sys_smbios_entry = (uintptr_t)sys_smbios_entry - hhdm_request.response->offset;
} }