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?
The main piece of memory after the 0x100000
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: The main piece of memory after the 0x100000
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.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?
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.
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: The main piece of memory after the 0x100000
I don't think that's guaranteed. You should always check the memory map to make sure there's enough memory.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?