The main piece of memory after the 0x100000

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
mrjbom
Member
Member
Posts: 315
Joined: Sun Jul 21, 2019 7:34 am

The main piece of memory after the 0x100000

Post by mrjbom »

Some memory is required to initialize my buddy allocator, I am looking for a way to find this memory for initialization.
I want to use this method: just allocate memory after the end of the kernel.
I will need about a few kilobytes to 24 megabytes depending on the size of the total RAM.
Is it possible to use this method? On the memory maps that I have met, it is indicated that the main piece of memory will be located from 0x100000 and it will probably be large enough to meet my needs, is that so?
thewrongchristian
Member
Member
Posts: 426
Joined: Tue Apr 03, 2018 2:44 am

Re: The main piece of memory after the 0x100000

Post by thewrongchristian »

mrjbom wrote:Some memory is required to initialize my buddy allocator, I am looking for a way to find this memory for initialization.
I want to use this method: just allocate memory after the end of the kernel.
I will need about a few kilobytes to 24 megabytes depending on the size of the total RAM.
Is it possible to use this method? On the memory maps that I have met, it is indicated that the main piece of memory will be located from 0x100000 and it will probably be large enough to meet my needs, is that so?
If you're using multiboot, you'll get the address map, which on a PC, will generally include extended memory from 1MB up to the amount of RAM installed or about 3.5GB, whichever is lower. Any memory beyond the 3.5GB is mapped beyond the 32-bit physical memory address, and so needs PAE to access.

So, from the memory map, you'll know how much memory you have to play with for the region starting at 1MB. Once your kernel is loaded, you'll also want to check for any modules loaded along with your kernel, which will most likely be loaded after your kernel.

So, you can set a pointer to the end of your BSS section, then for each loaded module, advance the pointer over the module. At the end of that, your pointer will point to unallocated physical memory, which you can co-opt as a bootstrap bump allocator to make the basis of your buddy allocator to manage the remaining memory.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: The main piece of memory after the 0x100000

Post by Octocontrabass »

mrjbom wrote:On the memory maps that I have met, it is indicated that the main piece of memory will be located from 0x100000 and it will probably be large enough to meet my needs, is that so?
I don't think that's guaranteed. You should always check the memory map to make sure there's enough memory.
Post Reply