Detecting Memory (x86): Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
m rename the grub mmap to explicitly say "entry", since it's an entry rather than a whole map.
Line 348: Line 348:


<source lang="c">
<source lang="c">
typedef struct multiboot_memory_map {
typedef struct mmap_entry {
unsigned int size;
unsigned int size;
unsigned int base_addr_low,base_addr_high;
unsigned int base_addr_low,base_addr_high;
Line 355: Line 355:
// You can also use: unsigned long long int length; if supported.
// You can also use: unsigned long long int length; if supported.
unsigned int type;
unsigned int type;
} mmap_entry_t;
} multiboot_memory_map_t;


int main(multiboot_info* mbt, unsigned int magic) {
int main(multiboot_info* mbt, unsigned int magic) {
...
...
multiboot_memory_map_t* mmap = mbt->mmap_addr;
mmap_entry_t* entry = mbt->mmap_addr;
while(mmap < mbt->mmap_addr + mbt->mmap_length) {
while(entry < mbt->mmap_addr + mbt->mmap_length) {
// do something with the entry
...
mmap = (multiboot_memory_map_t*) ( (unsigned int)mmap + mmap->size + sizeof(mmap->size) );
entry = (mmap_entry_t*) ((unsigned int) entry + entry->size + sizeof(entry->size));
}
}
...
...