summaryrefslogtreecommitdiffstats
path: root/arch/x86_64/boot/limine/memorymap.c
blob: ec0f545ac9f84483843733af3e3afbb001bb970f (plain) (blame)
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
#include "boot.h"
#include "limine.h"
#include "object.h"
#include "print.h"
#include "jove.h"
#include "arch/x86_64/page.h"

static struct jove_ObjectDirectory s_untyped_dir = {
    .self = { .type = KO_OBJECT_DIRECTORY, .data = 1 },
};

static volatile struct limine_memmap_request s_memmap_req = {
    .id = LIMINE_MEMMAP_REQUEST
};

void
boot_populate_untyped(void)
{
    _initDirectory.entries[INIT_OBJECT_UNTYPED_DIR] = (objdir_entry_t) {
        .type = KO_OBJECT_DIRECTORY,
        .data = (uintptr_t)&s_untyped_dir
    };

    if(s_memmap_req.response == NULL) {
        klogf("Failed to load physical memory map");
        hcf();
    }
    struct limine_memmap_response *response = s_memmap_req.response;
    for(size_t i = 0; i < response->entry_count; i++) {
        struct limine_memmap_entry *entry = response->entries[i];
        if(entry->type != LIMINE_MEMMAP_USABLE) continue;

        size_t table_index = s_untyped_dir.self.data++;
        uintmax_t *untyped_data = vmem_phys_tovirt(entry->base);
        objdir_entry_t *table_entry = &s_untyped_dir.entries[table_index];

        table_entry->type = KO_MEMORY_UNTYPED;
        table_entry->data = (uintptr_t)entry->base;
        *untyped_data = entry->length;

        klogf("New untyped block %i at %p:%p\n",
                table_index, entry->base, entry->length);
    }
}