diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-03 22:19:32 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-03 22:19:32 -0400 |
commit | 876970bcfd69ed3742d1a47640aa551578f22919 (patch) | |
tree | 2dddbc00f9ffccf687f1e5f1055e19b3939a73a3 /kernel/mboot/mmap.c | |
parent | add 64-bit idt/pic and fix paging (diff) | |
download | comus-876970bcfd69ed3742d1a47640aa551578f22919.tar.gz comus-876970bcfd69ed3742d1a47640aa551578f22919.tar.bz2 comus-876970bcfd69ed3742d1a47640aa551578f22919.zip |
load multiboot memory map, heap is done!!!
Diffstat (limited to '')
-rw-r--r-- | kernel/mboot/mmap.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/kernel/mboot/mmap.c b/kernel/mboot/mmap.c new file mode 100644 index 0000000..c17d510 --- /dev/null +++ b/kernel/mboot/mmap.c @@ -0,0 +1,49 @@ +#include <lib.h> +#include <comus/mboot.h> + +#include "mboot.h" +#include <stdint.h> +#include <stdio.h> + +static const char *segment_type[] = { + "Reserved", + "Free", + "Reserved", + "ACPI Reserved", + "Hibernation", + "Defective", + "Unknown" +}; + +void mboot_load_mmap(volatile void *mboot, struct memory_map *res) +{ + void *tag = locate_mboot_table(mboot, MBOOT_MEMORY_MAP); + struct mboot_tag_mmap *mmap = (struct mboot_tag_mmap *) tag; + + int idx = 0; + uintptr_t i = (uintptr_t)mmap->entries; + printf("MEMORY MAP\n"); + char buf[20]; + for (; + i < (uintptr_t)mmap->entries + mmap->size; + i += mmap->entry_size, idx++ + ) { + struct mboot_mmap_entry *seg = (struct mboot_mmap_entry *) i; + const char *type = NULL; + if (seg->type > 6) + type = segment_type[6]; + else + type = segment_type[seg->type]; + printf("ADDR: %16p LEN: %4s TYPE: %s (%d)\n", + (void *)seg->addr, + btoa(seg->len, buf), + type, + seg->type + ); + if (seg->type != 1 || seg->len < 1) + continue; + res->entries[idx].addr = seg->addr; + res->entries[idx].len = seg->len; + } + res->entry_count = idx; +} |