OSDev.org
https://forum.osdev.org/

The main piece of memory after the 0x100000
https://forum.osdev.org/viewtopic.php?f=1&t=57172
Page 1 of 1

Author:  mrjbom [ Tue Mar 19, 2024 4:20 pm ]
Post subject:  The main piece of memory after the 0x100000

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?

Author:  thewrongchristian [ Tue Mar 19, 2024 5:44 pm ]
Post subject:  Re: The main piece of memory after the 0x100000

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.

Author:  Octocontrabass [ Tue Mar 19, 2024 8:55 pm ]
Post subject:  Re: The main piece of memory after the 0x100000

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/