Unreal Mode: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(2 intermediate revisions by 2 users not shown)
Line 19:
Therefore IP is unaffected by all this, and the code itself is still limited to 64KiB.
 
<sourcesyntaxhighlight lang="asm">
; Assembly example
 
Line 25:
; partcopy boot.bin 0 200 -f0
 
[ORG 0x7c00] ; add to offsets
 
start:
start: xor ax, ax ; make it zero
mov ds, ax ; DS=0
mov ss, ax ; stack starts at seg 0
Line 41 ⟶ 42:
or al,1 ; set pmode bit
mov cr0, eax
jmp 0x8:pmode
 
pmode:
jmp $+2 ; tell 386/486 to not crash
mov dsbx, bx 0x10 ; 8hselect =descriptor 1000b2
 
mov bxds, 0x08bx ; select10h descriptor= 110000b
mov ds, bx ; 8h = 1000b
 
and al,0xFE ; back to realmode
mov cr0, eax ; by toggling bit again
jmp 0x0:unreal
 
unreal:
pop ds ; get back old segment
sti
Line 63 ⟶ 66:
dd gdt ;start of table
 
gdt : dd 0,0 ; entry 0 is always unused
flatdesc codedesc: db 0xff, 0xff, 0, 0, 0, 10010010b10011010b, 11001111b00000000b, 0
flatdesc: db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0
gdt_end:
 
times 510-($-$$) db 0 ; fill sector w/ 0's
dw 0xAA55 ; Required by some BIOSes
</syntaxhighlight>
</source>
* At least on the 486SL the jmp $+2 instruction is needed after toggling the PM bit off, not just on. - BASICFreak
 
===Huge Unreal Mode===
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:
 
<sourcesyntaxhighlight lang="asm">
; Assembly example
 
Line 81 ⟶ 84:
; partcopy boot.bin 0 200 -f0
 
[ ORG 0x7c00] ; add to offsets
 
start: xor ax, ax ; make it zero
Line 111 ⟶ 114:
times 510-($-$$) db 0 ; fill sector w/ 0's
dw 0xAA55 ; Required by some BIOSes
</syntaxhighlight>
</source>
 
WARNING: this may not work on some emulators or some hardware.
Line 127 ⟶ 130:
For an example of an Unreal Mode [[bootloader]] implementation with Smaller C, look at [https://github.com/fysnet/FYSOS/tree/master/loader FYSOS].
[[Category:X86 CPU]]
[[Category:Operating Modes]]
[[Category:FAQ]]