Page 1 of 1

How to get meminfo from Grub?

Posted: Thu May 01, 2008 10:59 am
by crackcell
Hello,everyone.

I'm writing a kernel which can be booted by Grub.

Can U tell me how to get memory info(mem size etc.) from Grub.

I have placed the multiboot code in my kernel:

MBOOT_PAGE_ALIGN equ 1<<0
MBOOT_MEM_INFO equ 1<<1
MBOOT_HEADER_MAGIC equ 0x1BADB002
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)

Posted: Thu May 01, 2008 11:27 am
by nick8325
All the information is in the Multiboot specification: http://www.gnu.org/software/grub/manual ... ion-format.

When your kernel starts, [ebx+4] contains the amount of lower memory (which will normally be 640KB), and [ebx+8] contains the amount of upper memory (memory that starts at address 1MB). Both amounts are in kilobytes.

Posted: Thu May 01, 2008 4:58 pm
by Zenith
But also, I'd advise parsing the detailed memory map instead, to be wary about random holes in memory. :wink:
However, this may not be available on older computers, so the lower/upper memory option may be the only possible way.

Posted: Thu May 01, 2008 7:56 pm
by crackcell
nick8325 wrote:All the information is in the Multiboot specification: http://www.gnu.org/software/grub/manual ... ion-format.

When your kernel starts, [ebx+4] contains the amount of lower memory (which will normally be 640KB), and [ebx+8] contains the amount of upper memory (memory that starts at address 1MB). Both amounts are in kilobytes.
Thx for your reply, I think I've got what I want. :wink:

Posted: Thu May 01, 2008 8:00 pm
by crackcell
karekare0 wrote:But also, I'd advise parsing the detailed memory map instead, to be wary about random holes in memory. :wink:
However, this may not be available on older computers, so the lower/upper memory option may be the only possible way.
Can you tell me the details (or where can I get it) about parsing the memory map?

Thx..

Posted: Thu May 01, 2008 8:02 pm
by zerosum
It's provided on the page you were linked to before..... just scroll down ;)

Posted: Fri May 02, 2008 4:24 am
by jal
karekare0 wrote:But also, I'd advise parsing the detailed memory map instead, to be wary about random holes in memory. :wink:
Well, the values are up to the first memory hole, so the memory itself is guaranteed safe to use. It's however very well possible that there is more memory to use (and on modern machines it's almost certain).


JAL

Posted: Fri May 02, 2008 10:30 am
by crackcell
Thx everyone.

I've got it. :wink: