Page 1 of 1

Max. no. entries that can be returned by 0xE820

Posted: Fri Mar 18, 2016 3:17 pm
by BrightLight
My OS uses BIOS function 0xE820 to detect memory. Before the function starts, I simply have 1024 bytes reserved in my kernel to make space for the memory map. Assuming each entry size is 24 bytes, what is the maximum number of entries that this function can return? I am asking for the sake of keeping my kernel's binary as small as possible.

Re: Max. no. entries that can be returned by 0xE820

Posted: Fri Mar 18, 2016 4:06 pm
by alexg
On the systems you will be testing it probably won't exceed 1024 bytes. On huge servers, with TBs of RAM you can expect to have more entries than you can fit in 1024 bytes (I've seen such a machine to have an entry for 8 bytes of memory :)).

If you really want to be able to collect all the entries without increasing the kernel binary too much why don't you 'dynamically' allocate this data? In this stage I guest you don't have a memory allocator, but you could pick any unused memory area in the first MB of physical space.

Re: Max. no. entries that can be returned by 0xE820

Posted: Sat Mar 19, 2016 6:47 am
by BrightLight
alexg wrote:On the systems you will be testing it probably won't exceed 1024 bytes. On huge servers, with TBs of RAM you can expect to have more entries than you can fit in 1024 bytes (I've seen such a machine to have an entry for 8 bytes of memory :)).

If you really want to be able to collect all the entries without increasing the kernel binary too much why don't you 'dynamically' allocate this data? In this stage I guest you don't have a memory allocator, but you could pick any unused memory area in the first MB of physical space.
My kernel is loaded in the first MB of physical space. It lives in low memory and cannot grow more than 512 KB in size. I will fix this some day when my kernel must get bigger than this limit, but now it's just because I am lazy to write a full 64-bit boot loader for my file system that I am constantly redesigning.

Re: Max. no. entries that can be returned by 0xE820

Posted: Sat Mar 19, 2016 10:20 am
by madanra
The space you store the entries shouldn't be in the kernel, otherwise you're loading zeros that you're just going to overwrite.