Cannot understand why unreal mode works
Posted: Sun Oct 28, 2007 3:35 pm
Ok, I need to enter unreal mode to access more than 64kb's above 1MB (right?).
A20 needs to be enabled, of course, (though you can access every odd MB without it, I guess).
First of all, does it matter WHEN I enter unreal mode with respect to when I enable A20? (from the wiki example, it appears A20 is not enabled to enter unreal mode, but can it be beforehand?)
In the example code on http://www.osdev.org/wiki/Unreal_Mode, why are these things necessary?:
First,
("save real mode"? what??)
The above causes the processor to load the information for descriptor 1 in the GDT, right?
Do I need to also "mov es, bx" if I want to access above 1MB with es?
So then when we switch back to real mode, why this??
Doesn't that cause the CPU to NOT use the information from descriptor 1? since (ds&0xF8)!=0x08? (i.e, descriptor 1 is NOT selected??)
When I searched the forums I found this post which confused me even more!
Also, maybe I'm missing something in the Intel Manual... How does the processor use segment registers when you try to access a 32-bit offset? (or, why does unreal mode allow 32-bit offsets to be used?)
A20 needs to be enabled, of course, (though you can access every odd MB without it, I guess).
First of all, does it matter WHEN I enter unreal mode with respect to when I enable A20? (from the wiki example, it appears A20 is not enabled to enter unreal mode, but can it be beforehand?)
In the example code on http://www.osdev.org/wiki/Unreal_Mode, why are these things necessary?:
First,
Code: Select all
push ds ; save real mode
Code: Select all
mov bx, 0x08 ; select descriptor 1
mov ds, bx ; 8h = 1000b
Do I need to also "mov es, bx" if I want to access above 1MB with es?
So then when we switch back to real mode, why this??
Code: Select all
pop ds ; get back old segment
When I searched the forums I found this post which confused me even more!
So, it sounds like after switching back to real mode, touching any segment registers ruins my ability to access the extra memory??? Which goes back to my question about the wiki code...Candy wrote:It's the theory behind unreal mode by the way - you load the segment registers in pmode (loading the second unwritable half with the pmode-valid information) which is never changed back - so if you index with eax or ecx in realmode the offsets aren't invalid (since it checks the pmode-style register just without reloading them for realmode values, so you keep the old limit and base) and you can access 4GB of information. Which also explains the BIOS warning - if your BIOS functions reload the segment register, you're screwed. They also don't use 32-bit offsets.
Also, maybe I'm missing something in the Intel Manual... How does the processor use segment registers when you try to access a 32-bit offset? (or, why does unreal mode allow 32-bit offsets to be used?)