From f39578f4e316c97b4d7b898f09e41cf8ca58dcdd Mon Sep 17 00:00:00 2001 From: mintsuki Date: Fri, 18 Mar 2022 08:48:48 +0100 Subject: [PATCH] limine: Move module request to using SoA --- common/limine.h | 17 ++++++--------- common/protos/limine.c | 47 +++++++++++++++++++++++------------------- test/limine.c | 16 +++++++------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/common/limine.h b/common/limine.h index fdda475b..3e71fb0f 100644 --- a/common/limine.h +++ b/common/limine.h @@ -186,20 +186,15 @@ struct limine_entry_point_request { #define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee } -struct limine_module { - uint64_t base; - uint64_t length; - LIMINE_PTR(char *) path; - LIMINE_PTR(char *) cmdline; - LIMINE_PTR(struct limine_file_location *) file_location; - uint8_t reserved[256]; -}; - struct limine_module_response { uint64_t flags; - uint64_t modules_count; - LIMINE_PTR(struct limine_module *) modules; + uint64_t module_count; + LIMINE_PTR(uint64_t *) module_base; + LIMINE_PTR(uint64_t *) module_length; + LIMINE_PTR(LIMINE_PTR(char *) *) module_path; + LIMINE_PTR(LIMINE_PTR(char *) *) module_cmdline; + LIMINE_PTR(LIMINE_PTR(struct limine_file_location *) *) module_file_location; }; struct limine_module_request { diff --git a/common/protos/limine.c b/common/protos/limine.c index 3c1b8690..9d692a04 100644 --- a/common/protos/limine.c +++ b/common/protos/limine.c @@ -324,50 +324,55 @@ FEAT_START struct limine_module_response *module_response = ext_mem_alloc(sizeof(struct limine_module_response)); - struct limine_module *modules = ext_mem_alloc(module_count * sizeof(struct limine_module)); + uint64_t *module_base = ext_mem_alloc(sizeof(uint64_t) * module_count); + uint64_t *module_length = ext_mem_alloc(sizeof(uint64_t) * module_count); + uint64_t *module_path = ext_mem_alloc(sizeof(uint64_t) * module_count); + uint64_t *module_cmdline = ext_mem_alloc(sizeof(uint64_t) * module_count); + uint64_t *module_file_location = ext_mem_alloc(sizeof(uint64_t) * module_count); - modules[0].base = reported_addr(kernel); - modules[0].length = kernel_file_size; - modules[0].path = reported_addr(kernel_path); - modules[0].cmdline = reported_addr(cmdline); - - modules[0].file_location = reported_addr(kl); + module_base[0] = reported_addr(kernel); + module_length[0] = kernel_file_size; + module_path[0] = reported_addr(kernel_path); + module_cmdline[0] = reported_addr(cmdline); + module_file_location[0] = reported_addr(kl); for (size_t i = 1; i < module_count; i++) { struct conf_tuple conf_tuple = config_get_tuple(config, i - 1, "MODULE_PATH", "MODULE_CMDLINE"); - char *module_path = conf_tuple.value1; - char *module_cmdline = conf_tuple.value2; + char *m_path = conf_tuple.value1; + char *m_cmdline = conf_tuple.value2; - struct limine_module *m = &modules[i]; - - if (module_cmdline == NULL) { - module_cmdline = ""; + if (m_cmdline == NULL) { + m_cmdline = ""; } print("limine: Loading module `%s`...\n", module_path); struct file_handle *f; - if ((f = uri_open(module_path)) == NULL) + if ((f = uri_open(m_path)) == NULL) panic(true, "limine: Failed to open module with path `%s`. Is the path correct?", module_path); - m->base = reported_addr(freadall(f, MEMMAP_KERNEL_AND_MODULES)); - m->length = f->size; - m->path = reported_addr(module_path); - m->cmdline = reported_addr(module_cmdline); + module_base[i] = reported_addr(freadall(f, MEMMAP_KERNEL_AND_MODULES)); + module_length[i] = f->size; + module_path[i] = reported_addr(m_path); + module_cmdline[i] = reported_addr(m_cmdline); struct limine_file_location *l = ext_mem_alloc(sizeof(struct limine_file_location)); *l = get_file_loc(f); - m->file_location = reported_addr(l); + module_file_location[i] = reported_addr(l); fclose(f); } - module_response->modules_count = module_count; - module_response->modules = reported_addr(modules); + module_response->module_count = module_count; + module_response->module_base = reported_addr(module_base); + module_response->module_length = reported_addr(module_length); + module_response->module_path = reported_addr(module_path); + module_response->module_cmdline = reported_addr(module_cmdline); + module_response->module_file_location = reported_addr(module_file_location); module_request->response = reported_addr(module_response); FEAT_END diff --git a/test/limine.c b/test/limine.c index 9a78e4f8..2ca18019 100644 --- a/test/limine.c +++ b/test/limine.c @@ -182,16 +182,14 @@ FEAT_START } e9_printf(""); struct limine_module_response *module_response = module_request.response; - e9_printf("%d module(s)", module_response->modules_count); - for (size_t i = 0; i < module_response->modules_count; i++) { - struct limine_module *m = &module_response->modules[i]; + e9_printf("%d module(s)", module_response->module_count); + for (size_t i = 0; i < module_response->module_count; i++) { + e9_printf("Base: %x", module_response->module_base[i]); + e9_printf("Length: %x", module_response->module_length[i]); + e9_printf("Path: %s", module_response->module_path[i]); + e9_printf("Cmdline: %s", module_response->module_cmdline[i]); - e9_printf("Base: %x", m->base); - e9_printf("Length: %x", m->length); - e9_printf("Path: %s", m->path); - e9_printf("Cmdline: %s", m->cmdline); - - print_file_loc(m->file_location); + print_file_loc(module_response->module_file_location[i]); } FEAT_END