Unreal Mode: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
Line 1: Line 1:
'''Unreal mode''' consist of breaking the '64Kb' limit of real mode segments, but still keeping 16 bits instruction and <tt>segment*16+offset</tt> address formation by tweaking the [[Descriptor Cache|descriptor caches]].
'''Unreal mode''' consists of breaking the 64KiB limit of real mode segments (while retaining 16-bit instructions and the <tt>segment * 16 + offset</tt> addressing mode) by tweaking the [[Descriptor Cache|descriptor caches]].


==Usage==
==Usage==
Unreal mode is recommended in the two following cases :
Unreal mode is usually recommended in the two following cases:
* you're trying to extend a legacy 16-bits DOS program so that it can deal with larger data and neither vm86, nor xms is suitable for your needs
* you're trying to extend a legacy 16-bit DOS program so that it can deal with larger data and neither [[Virtual 8086 Mode]], nor xms are suitable for your needs.
* you're trying to load something that will run in 32 bits mode and which is larger than 640Kb (so you cannot load it in conventional memory) and you don't want to bother with a disk driver called from pmode yet, and you do not wish to switch between real and protected mode for copying chunks from the conventional memory buffer to the high memory areas...
* you're trying to load something that will run in 32-bit mode which is larger than 640K (therefore you cannot load it in conventional memory) and you don't want to bother writing a protected mode disk driver yet, but you also want to avoid switching between real and protected mode to copy chunks from the conventional memory buffer into extended memory.


You still will not have full access to all physical RAM if you do not have have the [[A20 Line]] enabled; all the "odd" 1-megabyte blocks will be unavailable.
You still will not have full access to all physical RAM if you do not have the [[A20 Line]] enabled; all the "odd" 1 MiB blocks will be unavailable.


==Implementation==
==Implementation==
To do this, you need to set the descriptor cache's limits for your segment register(s) to any value higher than 64KiB (usually a full 4GiB (<tt>0xffffffff</tt>)).
The reason for doing this is to enable 32-bit offsets in real mode. However, you won't be able to go past 1 meg quite yet.


In protected mode, the bits 3-15 in the segment register are an index into the descriptor table. That's why in this code 0x08 = 1000b gets you the 1 entry.
In protected mode, bits 3-15 in the segment registers represent an index into [[GDT|the global descriptor table]]. That's why in the following code 0x08 = 1000b gets you entry #1 (entry #0 is ALWAYS a null descriptor).


When this register given a "selector", a "segment descriptor cache register" is filled with the descriptor values, including the size (or limit). After the switch back to real mode, these values are not modified, regardless of what value is in the 16-bit segment register. So the 64k limit is no longer valid and 32-bit offsets can be used with the real-mode addressing rules (i.e. shift segment 4 bits, then add offset).
When (in protected mode) a segment register is loaded with a "selector", a "segment descriptor cache register" is filled with the descriptor's values, including the size (or limit). After the switch back to real mode, these values are not modified, regardless of what value is in the 16-bit segment register. So the 64KiB limit is no longer valid and 32-bit offsets can be used in Real Mode to actually access areas above 64KiB (<tt>segment * 16 + 32-bit offset</tt>).


===Big Unreal Mode===
===Big Unreal Mode===
These will not have affected CS. <br />
This won't touch CS. <br />
Therefore IP is unaffected by all this, so the code itself is still limited to 64 K.
Therefore IP is unaffected by all this, and the code itself is still limited to 64KiB.


<source lang="asm">
<source lang="asm">
Line 73: Line 73:


===Huge Unreal Mode===
===Huge Unreal Mode===
Huge Unreal Mode enables code over 64K. However, it is more difficult to implement as real mode interrupts do not automatically save the high 16 bits of EIP. Initialization is simple though, you just load a 32 bit code segment:
Huge Unreal Mode enables code over 64KiB. However, it is more difficult to implement as real mode interrupts do not automatically save the high 16 bits of EIP. Initialization is simple though, you just load a code segment with a 4GiB limit:


<source lang="asm">
<source lang="asm">
Line 114: Line 114:
</source>
</source>


WARNING: this may not work on some emulators or some hardware. This is because of direct 32 bit PMODE -> (Un)real mode.
WARNING: this may not work on some emulators or some hardware.


==Compiler Support==
==Compiler Support==