Page 1 of 1

grub multiboot

Posted: Sun Sep 14, 2008 4:55 am
by huxuelei
Hi, I use grub to load my kernel into memory.
I follow the instructions which from http://www.gnu.org/software/grub/manual ... techniques
to get memory information.
as it says, the Multiboot information structure have two field mem_lower and mem_upper, these indicate the amount of lower and upper memory, respectively, in kilobytes.
But I can not fully understand what is this suppose to mean.And I don't know how to use these two fields.
Please give me some help.

Re: grub multiboot

Posted: Sun Sep 14, 2008 5:31 am
by Steve the Pirate
Add those values together and you should have the total amount of system memory (RAM)...

Re: grub multiboot

Posted: Sun Sep 14, 2008 7:08 am
by Laksen
lower is the amount of usable mem under 1mb
and upper is the amount of physical mem over 1mb

Re: grub multiboot

Posted: Sun Sep 14, 2008 6:09 pm
by Karatorian
The numbers provided by mem_lower and mem_upper are usefull, but are not guaranteed to provide the full details of the amount of memory in the system. According to the multiboot spec, mem_upper is
maximally the address of the first upper memory hole minus 1 megabyte. It is not guaranteed to be this value.
In other words, if there are any gaps in the memory (which, somewhat surprizingly, does happen) then you will not know about memory above them. Furthermore, it's not required to even go to the first gap (although, I belive grub is accurate in this regard).

mem_lower is the traditional low memory and will proably be 640k on any boxen not made in the stone age. There's a gap between this and 1m that you may or may not be able to use, depending on the motherboard, installed cards, etc. Therefore, simply adding mem_upper and mem_lower together won't provide an entirely accurate picture of the installed memory. There are various reasons to treat low memory differently, which may or may not be relevant to your project. (My current code ignores it completely, but that's probably a waste.)

If you want to know how much memory is installed in the machine (rather than what's usable), adding 1m to mem_upper will provide the right number, provided there are no gaps. While not particularly useful to the OS itself, this is the number a user will expect to see if you provide some sort of total memory size during boot-up or from some utility.

For the full nitty gritty details about the memory layout, the multiboot info structure also provides the mmap_* fields. They point to a strutcture that provides more information, such as if you can regain the memory between 640k and 1m, any memory holes, and the memory beyond them, if any. (See the spec and [wiki]Detecting_Memory_(x86)[/wiki] for the full details.)

However, using this info is more complicated than just using mem_* and may not be worth the effort. (My current code doesn't use it at all.)

Finally, before using any of these structures, be sure to check if the proper flags are set. While grub can be depended on to provide the full features of the multiboot spec, it's probably better to be safe.

P.S. The multiboot spec has some example code that shows how to use the various info provided, including mem_* and mmap_*.