A20 clarification

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
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

A20 clarification

Post by Zacariaz »

I just wrote an essay about my troubles and then realized that i didnt make any sence so here goes again.

Why do we need the A20 gate?
Do we allso need it in protected and long mode?

from www.brokenthorn.com
In the previus tutorial, we looked at how to switch the processor into a 32 bit mode. We also learned how we can access up to 4 GB of memory.
the PC boots into real mode, which has the limitation of 16 bit registers. And, hence, 16 bit segment addressing. This limits the amount of memory you can access in real mode. Because of this, we still cannot access even up to 1 GB of memory yet. Heck, we cannot even go passed the 1 MB barrier yet! What to do? We have to enable the 20th address line.
As i understand this we have access to 4gb of memory as soon as we get to protected mode, if this is correct, we then only need to enable the A20 gate if we need to access more that 1mb of memory while in real mode, but surely 1mb of memory is more that enough to get to protected mode, so why do we need to bother?

Im sure you realize by now that im no expert on the subject, but still i would very much appreciate some clarification.

Thanks.
This was supposed to be a cool signature...
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post by Zenith »

I'm not an expert either, but I'll take a stab at it:

The A20 line has to be enabled to prevent the PC from wrapping around the first 64kb after every MB back to the MB's beginning. The A20 line is usually disabled since some really ancient programs relied on this wraparound to work back in the days of 16-bit processors and nobody had more than 1MB RAM.

Its needed in protected and long mode since if it wasn't enabled, it would still wrap around, since the A20 line is not related to real mode in anyway.

See: http://en.wikipedia.org/wiki/A20_line

Hope this helps!
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
liquid.silver
Member
Member
Posts: 46
Joined: Sat Jun 30, 2007 12:07 pm
Location: South Africa
Contact:

Post by liquid.silver »

As far as i understand protected mode and the A20 lines are independent. In other words, you can be in protected mode and only have access to the first mb. Some bioses might not require you to fix the A20 line, but you can't rely on that.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

Well i got the important part of my question answered.
Thanks
This was supposed to be a cool signature...
Post Reply