summaryrefslogtreecommitdiff
path: root/kernel/mboot/mmap.c
blob: c17d5109413f58645d9ae83508832d137f20c343 (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
42
43
44
45
46
47
48
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;
}