blob: 1b5f08be4b6eb1277c5610e3a866e26a3066d41c (
plain)
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
|
#include <lib.h>
#include <comus/mboot.h>
#include "mboot.h"
static const char *segment_type[] = { "Reserved", "Free",
"Reserved", "ACPI Reserved",
"Hibernation", "Defective",
"Unknown" };
int mboot_get_mmap(struct memory_map *res)
{
void *tag = locate_mboot_table(MBOOT_MEMORY_MAP);
if (tag == NULL)
return 1;
struct mboot_tag_mmap *mmap = (struct mboot_tag_mmap *)tag;
int idx = 0;
uintptr_t i = (uintptr_t)mmap->entries;
kprintf("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];
kprintf("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;
return 0;
}
|