Multiboot 2 memory map
Posted: Fri Aug 11, 2017 1:31 am
Hello, I am trying to get the memory map from GRUB using Multiboot 2 structure. I've succeeded to read the memory info tags, but there is something strange about it. Even if I give only 256 MiBs of memory to Qemu, it shows me some region of reserved memory at 0xFFFC0000, and that's outside of physical memory for sure. What's it's purpose and why do GRUB infrom me about it if it doesn't physically exist?
Here is some code
Here is some code
Code: Select all
// Iterate over tags and collect info
uint32 memoryEnd = 0x0;
struct reservedArea {
uint32 addr;
uint32 len;
} areasToReserve[256];
uint32 areasNumber = 0;
struct multiboot_tag *tag;
for (tag = (struct multiboot_tag*) (mboot2Addr + 8);
tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag*) ((multiboot_uint8_t *) tag
+ ((tag->size + 7) & ~7)))
{
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: ;
struct multiboot_tag_basic_meminfo *mem = (struct multiboot_tag_basic_meminfo*) tag;
//kprintf("Basic memory area %x - %x\n",
// mem->mem_lower,
// mem->mem_upper);
break;
case MULTIBOOT_TAG_TYPE_MMAP: ;
multiboot_memory_map_t *mmap;
struct multiboot_tag_mmap *mmapTag = (struct multiboot_tag_mmap*) tag;
for (mmap = mmapTag->entries;
(multiboot_uint8_t*) mmap < (multiboot_uint8_t*) tag + tag->size;
mmap = (multiboot_memory_map_t *) ((unsigned long) mmap
+ mmapTag->entry_size))
{
kprintf("Memory area starting at %x with "
"length of %x and type %x",
(unsigned) (mmap->addr),
(unsigned) (mmap->len),
(unsigned) mmap->type);
memoryEnd += (uint32) mmap->len;
if (mmap->type == MULTIBOOT_MEMORY_RESERVED)
{
areasToReserve[areasNumber].addr = mmap->addr;
areasToReserve[areasNumber].len = mmap->len;
kprintf("%x %x\n", areasToReserve[areasNumber].addr , areasToReserve[areasNumber].len);
areasNumber++;
}
}
break;
default:
//kprintf("Unkown tag %x, size %x\n", tag->type, tag->size);
break;
}
}