Page 1 of 1

Getting memory map from grub

Posted: Tue Jun 10, 2014 10:59 am
by songziming
I'm getting the memory map from GRUB via multiboot_info structure, the information I got is in the attachment.

the 4 columns are: size, addr, length, type. As of in the multiboot spec.

But where is the info about memory range 0xA0000~0xEFFFF? it's missing from the mmap.

Re: Getting memory map from grub

Posted: Tue Jun 10, 2014 11:15 am
by Combuster
Would you expect "memory" in that area?

Re: Getting memory map from grub

Posted: Tue Jun 10, 2014 11:49 am
by SpyderTL
According to the OSDev Wiki Page: http://wiki.osdev.org/Detecting_Memory_(x86)
Treat unlisted regions as Type 2 -- reserved.
Apparently GRUB doesn't do this for you. You'll have to detect these and actively avoid them.

Re: Getting memory map from grub

Posted: Tue Jun 10, 2014 1:19 pm
by SpyderTL
Also, from the same page:
GRUB simply uses INT 15h, EAX=E820 to get the detailed memory map, and does not verify the "sanity" of the map. It also will not sort the entries, retrieve any available ACPI 3.0 extended DWORD (with the "ignore this entry" bit), or clean up the table in any other way.
Another problem is that the "type" field is defined as "1 = usable RAM" and "anything else is unusable". Despite what the multi-boot specification says, lots of people assume that the type field is taken directly from INT 15h, EAX=E820 (and in older versions of GRUB it is). However GRUB2 supports booting from UEFI/EFI (and other sources) and code that assumes the type field is taken directly from INT 15h, EAX=E820 will become broken. This means that (until a new multi-boot specification is released) you shouldn't make assumptions about the type, and can't do things like reclaiming the "ACPI reclaimable" areas or supporting S4/hibernate states (as an OS needs to save/restore areas marked as "ACPI NVS" to do that). Fortunately a new version of the multi-boot specification should be released soon which hopefully fixes this problem (but unfortunately, you won't be able to tell if your OS was started from "GRUB-legacy" or "GRUB2", unless it adopts the new multi-boot header and becomes incompatible with GRUB-legacy).