1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "boot/boot.h"
#include "limine.h"
#include "hal/obj.h"
#include "hal/memory.h"
#include "lib/printf.h"
#include "lib/string.h"
#include "proc/init.h"
#include "panic/panic.h"
static jove_objdir_t s_kmodules_objdir;
extern struct limine_module_response *_limine_module_resp;
static struct kernel_module s_modules[BOOT_MAX_MODULES];
jove_owned_obj_t*
boot_getmodule(const char *key) {
for(size_t i = 0; i < BOOT_MAX_MODULES; i++) {
if(strncmp(s_modules[i].path, key, 128) == 0)
return obj_take(s_modules[i].shmem);
}
errno = ENOTFOUND;
return NULL;
}
void
mem_setup_modules(void)
{
jove_owned_obj_t *modules_objdir = objdir_getlocal(_rootdir_obj, INIT_ROOTDIR_MODULES_I);
obj_settype(modules_objdir, JOVE_OBJ_OBJDIR);
obj_setvalue(modules_objdir, (uintptr_t)&s_kmodules_objdir);
jove_obj_t *modules_objdir_obj = obj_release(modules_objdir);
if(_limine_module_resp == NULL) {
kpanic("Limine failed to provide modules.\n");
}
kprintf("%s: Modules provided by Limine:\n", __func__);
for(size_t i = 0; i < _limine_module_resp->module_count; i++) {
struct limine_file *module = _limine_module_resp->modules[i];
if(i >= BOOT_MAX_MODULES) {
klogf("Maximum number of modules exceeded (%i). Some modules will be inaccessable\n", BOOT_MAX_MODULES);
return;
}
klogf("%p File %s at %p size %x\n", module, module->path, module->address, module->size);
physaddr_t module_base = phys_fromvirt((virtaddr_t)module->address);
size_t module_pages = (module->size + 0xFFF) / 0x1000;
if(module_pages > SHMEMORY_MAX_PAGES) {
klogf("Module exceeds length maximum (%i vs %i). Some data will be non-addressable\n",
module_pages, SHMEMORY_MAX_PAGES);
module_pages = 0xFFF;
}
jove_owned_obj_t *module_shmem = objdir_getlocal(modules_objdir_obj, i);
obj_settype(module_shmem, JOVE_OBJ_SHMEMORY);
obj_setvalue(module_shmem, module_base | module_pages);
s_modules[i] = (struct kernel_module) {
.shmem = obj_release(module_shmem)
};
strncpy(128, s_modules[i].path, module->path);
}
}
|