How to get meminfo from Grub?

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
User avatar
crackcell
Posts: 7
Joined: Sat Mar 22, 2008 3:41 am
Location: Wuhan University

How to get meminfo from Grub?

Post 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)
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Post 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.
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post 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.
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
crackcell
Posts: 7
Joined: Sat Mar 22, 2008 3:41 am
Location: Wuhan University

Post 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:
User avatar
crackcell
Posts: 7
Joined: Sat Mar 22, 2008 3:41 am
Location: Wuhan University

Post 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..
zerosum
Member
Member
Posts: 63
Joined: Wed Apr 09, 2008 6:57 pm

Post by zerosum »

It's provided on the page you were linked to before..... just scroll down ;)
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post 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
User avatar
crackcell
Posts: 7
Joined: Sat Mar 22, 2008 3:41 am
Location: Wuhan University

Post by crackcell »

Thx everyone.

I've got it. :wink:
Post Reply