grub multiboot

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

grub multiboot

Post 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.
User avatar
Steve the Pirate
Member
Member
Posts: 152
Joined: Fri Dec 15, 2006 7:01 am
Location: Brisbane, Australia
Contact:

Re: grub multiboot

Post by Steve the Pirate »

Add those values together and you should have the total amount of system memory (RAM)...
My Site | My Blog
Symmetry - My operating system.
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Re: grub multiboot

Post by Laksen »

lower is the amount of usable mem under 1mb
and upper is the amount of physical mem over 1mb
http://j-software.dk | JPasKernel - My Object Pascal kernel
User avatar
Karatorian
Posts: 4
Joined: Sat Sep 13, 2008 9:36 am
Location: Rindge NH USA
Contact:

Re: grub multiboot

Post 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_*.
Post Reply