From bffd652c16e62c80711be1a8a322092cd8bd1a81 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 23 Oct 2020 00:47:19 -0400 Subject: [PATCH] walk multiboot2 memory map --- src/mbinfo.c | 26 ++++++++++++++++++++++++++ src/multiboot2.h | 19 +++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/mbinfo.c b/src/mbinfo.c index 48712f6..b3739f2 100644 --- a/src/mbinfo.c +++ b/src/mbinfo.c @@ -26,6 +26,32 @@ static void mbinfo_process_tag(const multiboot2_info_tag_t * tag) } break; + case MULTIBOOT2_INFO_MEMORY_MAP: + { + multiboot2_info_memory_map_t * mmap_info = + (multiboot2_info_memory_map_t *)tag; + size_t sz = sizeof(mmap_info->header) + + sizeof(mmap_info->entry_size) + + sizeof(mmap_info->entry_version); + multiboot2_info_memory_map_entry_t * entry = &mmap_info->entries[0]; + for (;;) + { + sz += mmap_info->entry_size; + if (sz > mmap_info->header.size) + { + break; + } + if (entry->type == MULTIBOOT2_MEMORY_MAP_TYPE_RAM) + { + klog_printf("Memory region %16lx : %16lx\n", + entry->base_addr, + entry->length); + } + entry = (multiboot2_info_memory_map_entry_t *)((uintptr_t)entry + mmap_info->entry_size); + } + } + break; + case MULTIBOOT2_INFO_FRAMEBUFFER_INFO: { multiboot2_info_framebuffer_info_t * fbinfo = diff --git a/src/multiboot2.h b/src/multiboot2.h index 3881bb9..f39f8a5 100644 --- a/src/multiboot2.h +++ b/src/multiboot2.h @@ -84,16 +84,23 @@ typedef struct { uint32_t mem_upper; } multiboot2_info_basic_memory_info_t; +#define MULTIBOOT2_MEMORY_MAP_TYPE_RAM 1u +#define MULTIBOOT2_MEMORY_MAP_TYPE_ACPI 3u +#define MULTIBOOT2_MEMORY_MAP_TYPE_PRESERVE 4u +#define MULTIBOOT2_MEMORY_MAP_TYPE_DEFECTIVE 5u + +typedef struct { + uint64_t base_addr; + uint64_t length; + uint32_t type; + uint32_t _reserved; +} multiboot2_info_memory_map_entry_t; + typedef struct { multiboot2_info_tag_t header; uint32_t entry_size; uint32_t entry_version; - struct { - uint64_t base_addr; - uint64_t length; - uint32_t type; - uint32_t _reserved; - } entries[]; + multiboot2_info_memory_map_entry_t entries[]; } multiboot2_info_memory_map_t; typedef struct {