Here is the process that I use in my kernel (note that this is 32 bits). In my bootstrap build file, I tell GRUB to provide me a memory card:
.set MEMINFO, 1 << 1
Then GRUB loads the address of the multiboot information structure into ebx for you (this structure contains the address of the memory card). Then I call the C code to handle the actual iteration and process the memory card. I am doing something similar to iterate over a map:
#define MMAP_NEXT(m) \ (multiboot_memory_map_t*)((uint32_t)m + m->size + sizeof(uint32_t)) void read_mmap(multiboot_info_t* mbt){ multiboot_memory_map_t* mmap = (multiboot_memory_map_t*) mbt->mmap_addr; while((uint32_t)mmap < mbt->mmap_addr + mbt->mmap_length) { // process the current memory map entry mmap = MMAP_NEXT(mmap); } }
where multiboot_info_t and multiboot_memory_map_t defined as in the Gnu multiboot.h file. As Andrew Medico noted in the comments, here is a great link to get started with this.
source share