Page 1 of 1
Best way to detect the size of EBDA
Posted: Thu Aug 19, 2021 12:03 pm
by nexos
I am currently working on a bootloader for my operating system. In one part of it, I need to know what the highest usable address of conventional memory is, which also is the base of the EBDA from based on what I've seen. My only issue is that I know that the size of EBDA can vary from BIOS to BIOS. So my question is: What is the most reliable method to obtain the base address of the EBDA / highest usable conventional memory address. I know the BDA can have the EBDA base in it, but it isn't the most reliable way to find it from what I've heard.
Thanks,
nexos
Re: Best way to detect the size of EBDA
Posted: Thu Aug 19, 2021 1:16 pm
by nullplan
On a BIOS system, just ask E820. The memory map returned that way will not list the EBDA as usable memory. Funnily enough, it will usually list the IVT and BDA as usable, which I guess is true if you don't want to return to BIOS mode. Else, touching either of them is a good way to get the system to crash or misbehave.
There is also a BIOS function somewhere to return the size of conventional memory, though I failed to find it, glancing through RBIL just now. I remember that some DOS TSRs would actually hook that function to return a lower value to reserve some memory to themselves.
Re: Best way to detect the size of EBDA
Posted: Thu Aug 19, 2021 3:22 pm
by Octocontrabass
nexos wrote:I need to know what the highest usable address of conventional memory is,
Use
INT 0x12 or
INT 0x15 EAX=0x0000E801.
nexos wrote:which also is the base of the EBDA from based on what I've seen.
Use
INT 0x15 AH=0xC1. There can be memory reserved for other purposes between the conventional memory and the EBDA.
nexos wrote:I know the BDA can have the EBDA base in it, but it isn't the most reliable way to find it from what I've heard.
It's only unreliable if your bootloader might run on a PC that predates the widespread use of an EBDA.
Re: Best way to detect the size of EBDA
Posted: Thu Aug 19, 2021 3:32 pm
by nexos
Thank you all for the help. I decided to use BDA address 0x413 to detect the size of conventional memory, as that makes the most sense to me. That works on all my machines, so I guess that must be pretty reliable, right?
nullplan wrote:There is also a BIOS function somewhere to return the size of conventional memory
It is INT 0x12
Re: Best way to detect the size of EBDA
Posted: Thu Aug 19, 2021 5:11 pm
by Octocontrabass
nexos wrote:That works on all my machines, so I guess that must be pretty reliable, right?
It actually is reliable, but I wouldn't take "it works for me" as confirmation.
INT 0x12 returns the contents of address 0x413.