0

I am trying to get the grub memory layout using the Multiboot Header. The code is like this

memory_map_t *getmmap(memory_map_t *memMap)
{
        uint32_t i = 0;
        multiboot_info_t *mbt;
        memory_map_t *mmap = (memory_map_t*)mbt->mmap_addr;
        uint32_t MapLim = mbt->mmap_addr + mbt->mmap_length;
        while((uint32_t)mmap < MapLim)
        {
            memMap[i].size = mmap->size;
            memMap[i].base_addr_low = mmap->base_addr_low;
            memMap[i].base_addr_high = mmap->base_addr_high;
            memMap[i].type = mmap->type;
            i++;
            mmap = (memory_map_t*)((uint32_t)mmap + mmap->size +     sizeof(uint32_t));
        }
        return (memory_map_t*)&memMap;

}

#if defined(__cplusplus)
extern "C" /* Use C linkage for kernel_main. */
#endif
int kernel_main()
{
    terminal_initialize();
    uint32_t i = 0;
    multiboot_info_t *mbt;
    memory_map_t *mmap = (memory_map_t*)mbt->mmap_addr;
    memory_map_t memMap;
    memMap = mbt->mmap_length / sizeof(memory_map_t);
    memory_map_t *ac = getmmap(&memMap);
    terminal_writestring("ADDRESS = 0x%x\n", (unsigned)ac->base_addr_low);
}

The memMap size if not static so I passed it as a pointer but I cannot get anything displayed in qemu.

Edit:- By passing the address of the multiboot header to kernel_main and initializing mbt to that address resolved the issue.

ashish
  • 150
  • 2
  • 11

0 Answers0