Can someone expain how I use this C data structure that comes from grub? I don't understand hi mem and lo mem
Question
Grub is a multiboot compliant boot loader. When it boots an operating system it creates a structure defining the available memory and leaves a pointer to that structure in memory.
I got that information here:
http://wiki.osdev.org/Detecting_Memory_(x86)#Memory_Map_Via_GRUB
This is the structure that I think I'm interested in:
typedef struct memory_map
{
unsigned long size;
unsigned long base_addr_low;
unsigned long base_addr_high;
unsigned long length_low;
unsigned long length_high;
unsigned long type;
} memory_map_t;
So I've got a collection of memory map structures. As the above page mentions, you can see the memory map by typing "displaymem" at the grub prompt. This is my output
But I don't fully understand the structure....
Why are the lengths set to 0 (0x0)? Do I have to combine low memory and high memory?
It says the values are in 64 bit so did it push together "low mem and high mem" together like this:
__int64 full_address = (low_mem_addr + high_mem_addr);
or am I getting 1 list containing both low and high addresses exclusively in them?
and since I'm using a 32bit machine do I basically refer to each unique address with both values?
I was expecting one single list of addresses, like displaymem
shows but with actual length fields populated but I'm not seeing that. Is there something I don't understand?
Solution
Ok, basically it's just two variables...that are 64 bit numbers, so what is above and what is below are IDENTICAL!
typedef struct memory_map
{
unsigned long size;
//unsigned long base_addr_low;
//unsigned long base_addr_high;
unsigned long long base_addr;
// unsigned long length_low;
// unsigned long length_high;
unsigned long long length; //holds both halves.
unsigned long type;
} memory_map_t;
You can get the two halves out like this:
unsigned long base_addr_low = base_addr
unsigned long base_addr_high = base_addr >> 32
The question was just that simple. :-s