2

I am writing a higher-half 32-bit kernel loaded at 0xC0000000 (3GByte) virtual address and I am using multiboot_info struct to get the physical memory map. When I use #1, the first mmap_addr I'm getting is 0x9000 but I'm not able to examine the address using gdb. By hit and trail, I wrote #2 and it works perfectly. May I know if what I did was correct? And how exactly is it correct? Thank you.

#1
void get_mbmmap(void){
    memory_map_t* mmap = (memory_map_t*)(mbinfo_addr -> mmap_addr);
    while((uint32_t)mmap < mbinfo_addr->mmap_addr + mbinfo_addr->mmap_length)
        mmap = (memory_map_t*)((uint32_t)mmap + mmap->size + sizeof(mmap->size));}

#2
void get_mbmmap(void){
    memory_map_t* mmap = (memory_map_t*)(mbinfo_addr -> mmap_addr + 0xC0000000);
    while((uint32_t)mmap < mbinfo_addr->mmap_addr + 0xC0000000 + mbinfo_addr->mmap_length)
        mmap = (memory_map_t*)((uint32_t)mmap + mmap->size + sizeof(mmap->size));
}
rithvikp
  • 133
  • 1
  • 11

1 Answers1

0

Answering my own question:

I feel silly now for the answer is pretty simple and I realised my mistake. When I was moving my kernel to higher half, I made two page tables. One, that identity maps the first 4MB and one that maps the first 4MB(Physical) to 3GB(Virtual). But after the mapping is done, I'm un-mapping the first 4MB and thus creating a problem accessing the Grub memory map.

rithvikp
  • 133
  • 1
  • 11