grub multiboot.h structures

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
Poseidon

grub multiboot.h structures

Post by Poseidon »

from the multiboot.h what I use for the grub multiboot header I use also the memory_map_t structure to get the memory map, but do I have length_low and base_low, length_high and base_high or both (add low address to high address and same with length)?

thanks.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:grub multiboot.h structures

Post by Solar »

From the Multiboot documentation:
If bit 6 in the flags word is set, then the mmap_* fields are valid, and indicate the address and length of a buffer containing a memory map of the machine provided by the BIOS. mmap_addr is the address, and mmap_length is the total size of the buffer. The buffer consists of one or more of the following size/structure pairs (size is really used for skipping to the next pair):

[tt]
+-------------------+
-4 | size |
+-------------------+
0 | base_addr_low |
4 | base_addr_high |
8 | length_low |
12 | length_high |
16 | type |
+-------------------+
[/tt]

where size is the size of the associated structure in bytes, which can be greater than the minimum of 20 bytes. base_addr_low is the lower 32 bits of the starting address, and base_addr_high is the upper 32 bits, for a total of a 64-bit starting address. length_low is the lower 32 bits of the size of the memory region in bytes, and length_high is the upper 32 bits, for a total of a 64-bit length. type is the variety of address range represented, where a value of 1 indicates available RAM, and all other values currently indicated a reserved area.
Does this answer your question?
Every good solution is obvious once you've found it.
dh

Re:grub multiboot.h structures

Post by dh »

If you don't mind, could you post your structures and the code to utialize them? I'm having a hard time finding C code for the purpose. Thanks Ahead!!

Cheers, DH.
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:grub multiboot.h structures

Post by durand »

The memory map given by GRUB is able to support 64 bit memory ranges. But it splits up the 64 bit address into 2 32 bit unsigned integers.

So, according to the memory_map_t structure, each range will start at:

(base_high << 32) | (base_low)

giving you a 64 bit memory address.

The length of that memory range will be:

(length_high << 32 ) | ( length_low )


If you are only running a 32 bit machine and you have less than 4GB of memory, then it's kind of safe to ignore the high bits. So, your memory range will start at base_low and will be length_low bytes long.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:grub multiboot.h structures

Post by Pype.Clicker »

durand wrote: If you are only running a 32 bit machine and you have less than 4GB of memory, then it's kind of safe to ignore the high bits. So, your memory range will start at base_low and will be length_low bytes long.
hm. not quite. What about a region starting at 0x0000,0001,FF00,0000 and ending at 0x0000,0001,FFFF,FFFF, for instance ? ignoring the highest bits will lead to errors if those bits aren't 0. If your OS doesn't support memory above 4GB, it should rather ignore regions with "base.high>0" and truncate regions with "limit.high>0" to limit=0x0000,0000,FFFF,FFFF, imho.
Poseidon

Re:grub multiboot.h structures

Post by Poseidon »

thanks :)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:grub multiboot.h structures

Post by Solar »

Dragon_Hilord wrote: I'm having a hard time finding C code for the purpose.
IIRC, the GRUB source tarball contains example code for basic Multiboot usage?
Every good solution is obvious once you've found it.
mystran

Re:grub multiboot.h structures

Post by mystran »

Well, it contains what is known as a "Hello World" kernel. In fact, the GRUB hello world is quite sophisticated for a hello world kernel, as it also prints stuff like memory map information that GRUB gave it. So.. basicly it has example code for all multiboot stuff there is.
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:grub multiboot.h structures

Post by durand »

hm. not quite. What about a region starting at 0x0000,0001,FF00,0000 and ending at 0x0000,0001,FFFF,FFFF, for instance ? ignoring the highest bits will lead to errors if those bits aren't 0. If your OS doesn't support memory above 4GB, it should rather ignore regions with "base.high>0" and truncate regions with "limit.high>0" to limit=0x0000,0000,FFFF,FFFF, imho.
Oh yeah. true. Always good to check for that. But I mentioned 32 bits. Wouldn't that then mean that the machine has something that's sitting at +- 8GB of RAM in 32 bits? When would that occur?

Perhaps that would happen if PAE was enabled...and the machine was in 36 bit mode or whatever. Otherwise, I don't see how the CPU could reference that high up. What am I missing?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:grub multiboot.h structures

Post by Candy »

since it's possible with PAE you can end up in such situations where you don't support it.
dh

Re:grub multiboot.h structures

Post by dh »

;P. I never looked at the source. :-[

Cheers, DH.
dh

Re:grub multiboot.h structures

Post by dh »

I just found the structures and all. Takes a bit of work to make the structures the way I liked it so it worked.

For thoes don't who don't know, it's located in grub/docs/*
Post Reply