Page 1 of 1

A20 clarification

Posted: Thu Dec 06, 2007 7:32 pm
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.

Posted: Thu Dec 06, 2007 7:59 pm
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!

Posted: Fri Dec 07, 2007 6:38 am
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.

Posted: Fri Dec 07, 2007 7:50 am
by Zacariaz
Well i got the important part of my question answered.
Thanks