Best way to detect the size of EBDA

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
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Best way to detect the size of EBDA

Post 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
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: Best way to detect the size of EBDA

Post 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.
Carpe diem!
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Best way to detect the size of EBDA

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Best way to detect the size of EBDA

Post 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 :)
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Best way to detect the size of EBDA

Post 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. :P

INT 0x12 returns the contents of address 0x413.
Post Reply