diff options
author | Freya Murphy <freya@freyacat.org> | 2025-05-01 20:19:38 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-05-01 20:19:38 -0400 |
commit | 8a7653bcfadc48e400ad7c6b1346a6c6d7f73deb (patch) | |
tree | 10b94172c4f13f851417d2b554a2ebcab610fdc9 /kernel/mboot/module.c | |
parent | add some warnings so i know what the fuck is going wrong, bah (diff) | |
download | comus-8a7653bcfadc48e400ad7c6b1346a6c6d7f73deb.tar.gz comus-8a7653bcfadc48e400ad7c6b1346a6c6d7f73deb.tar.bz2 comus-8a7653bcfadc48e400ad7c6b1346a6c6d7f73deb.zip |
ramdisk
Diffstat (limited to '')
-rw-r--r-- | kernel/mboot/module.c | 30 |
1 files changed, 26 insertions, 4 deletions
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 <comus/mboot.h> #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; } |