I need help with memory management

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
Teln0
Posts: 11
Joined: Thu Feb 28, 2019 6:50 am
Libera.chat IRC: Teln0

I need help with memory management

Post by Teln0 »

I was reading this entry on the wiki and I'm struggling a little bit. My os uses grub to get all the information he may need and I got some information that looks like this :

Code: Select all

// Available memory from BIOS
uint32_t mem_lower;
uint32_t mem_upper;
// Memory Mapping buffer
uint32_t mmap_length;
uint32_t mmap_addr;
First, mem_lower equals to 639 and mem_upper (approximately) equals the amount of ram I gave qemu / 1000. And I'd like to know why is this like that, is the size in blocks ?
Then, I can't really understand what to do with those headers. What I thought is that you have a header at the beginning of each block that describes it, but I'm not sure.

Can somebody help me with that ?
Thanks in advance :) !
User avatar
zity
Member
Member
Posts: 99
Joined: Mon Jul 13, 2009 5:52 am
Location: Denmark

Re: I need help with memory management

Post by zity »

The answer to your question can be found in the multiboot specs: https://www.gnu.org/software/grub/manua ... iboot.html

The two fields mem_lower and mem_upper is the memory in KBs.

The variable mmap_addr points to an array of "structs" of the form:

Code: Select all

             +-------------------+
     -4      | size              |
             +-------------------+
     0       | base_addr         |
     8       | length            |
     16      | type              |
             +-------------------+
Teln0
Posts: 11
Joined: Thu Feb 28, 2019 6:50 am
Libera.chat IRC: Teln0

Re: I need help with memory management

Post by Teln0 »

but why isn't mem_lower equals to zero and mem_upper to the memory if mem_upper - mem_lower = to the size of the ram in kb ?
And what do I do with those headers ?
Edit : just checked I apparently has nothing to do with this thanks for answering !
MichaelPetch
Member
Member
Posts: 798
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: I need help with memory management

Post by MichaelPetch »

In Multiboot Upper memory is the memory above 1mb (>= 0x100000) and historically Lower memory was the region between 0x00000-0xA0000. mem_lower and mem_upper represent the SIZE (not the starting address of these regions of memory). There is 640KiB (655360 bytes) between 0x00000 and 0xA0000. Why then is 639KiB reported? The Extended BIOS Data Area (EBDA) should be considered unusable ram since System Management Mode (SMM) can overwrite it at any time (or may rely on the data there). The EBDA area sits just below the video memory at 0xA0000. On many systems it is 1KiB (640-639) however it is possible to be larger than that. The memory area between 640-mem_lower and mem_lower should not be overwritten.
Last edited by MichaelPetch on Mon May 13, 2019 2:12 pm, edited 1 time in total.
Teln0
Posts: 11
Joined: Thu Feb 28, 2019 6:50 am
Libera.chat IRC: Teln0

Re: I need help with memory management

Post by Teln0 »

Alight, thanks !
Post Reply