From 8a7653bcfadc48e400ad7c6b1346a6c6d7f73deb Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 1 May 2025 20:19:38 -0400 Subject: ramdisk --- kernel/mboot/module.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'kernel/mboot') diff --git a/kernel/mboot/module.c b/kernel/mboot/module.c index 79d092e..cb05b45 100644 --- a/kernel/mboot/module.c +++ b/kernel/mboot/module.c @@ -1,3 +1,4 @@ +#include "comus/memory.h" #include #include "mboot.h" @@ -12,13 +13,34 @@ struct multiboot_tag_module { char cmdline[]; }; +static void *mapped_addr = NULL; +size_t initrd_len; + void *mboot_get_initrd(size_t *len) { - void *tag = locate_mboot_table(MULTIBOOT_TAG_TYPE_MODULE); + struct multiboot_tag_module *mod; + void *tag, *phys; + + // if already loaded, return + if (mapped_addr) { + *len = initrd_len; + return mapped_addr; + } + + // locate + tag = locate_mboot_table(MULTIBOOT_TAG_TYPE_MODULE); if (tag == NULL) return NULL; - struct multiboot_tag_module *mod = (struct multiboot_tag_module *)tag; - *len = mod->mod_end - mod->mod_start; - return (void *)(uintptr_t)mod->mod_start; + mod = (struct multiboot_tag_module *)tag; + phys = (void *) (uintptr_t) mod->mod_start; + initrd_len = mod->mod_end - mod->mod_start; + + // map addr + mapped_addr = kmapaddr(phys, NULL, initrd_len, F_PRESENT | F_WRITEABLE); + if (mapped_addr == NULL) + return NULL; + + *len = initrd_len; + return mapped_addr; } -- cgit v1.2.3-freya