From 40bfcbb2cf8a39e58ec19b21956caaf4685c9b8b Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 6 May 2025 12:34:48 -0400 Subject: terrible hack to not overwrite mboot data --- kernel/mboot/mboot.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'kernel/mboot/mboot.c') diff --git a/kernel/mboot/mboot.c b/kernel/mboot/mboot.c index e4547e7..8163f04 100644 --- a/kernel/mboot/mboot.c +++ b/kernel/mboot/mboot.c @@ -5,6 +5,8 @@ static volatile void *mboot = NULL; +extern char kernel_end[]; + void mboot_init(long magic, volatile void *ptr) { if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) @@ -12,6 +14,23 @@ void mboot_init(long magic, volatile void *ptr) mboot = ptr; } +void *mboot_end(void) +{ + if (mboot == NULL) + return NULL; + + struct multiboot *info = (struct multiboot *)mboot; + uintptr_t mboot_end, initrd_end; + size_t initrd_len; + + mboot_end = (uintptr_t)info + info->total_size; + initrd_end = (uintptr_t)mboot_get_initrd_phys(&initrd_len); + if (initrd_end) + initrd_end += initrd_len; + + return (void *)MAX(mboot_end, initrd_end); +} + void *locate_mboot_table(uint32_t type) { if (mboot == NULL) -- cgit v1.2.3-freya