HOWTO: Setting up Unreal Mode...
Posted: Sat Jun 30, 2007 3:23 pm
If anyone here needs help setting up unreal mode, here is the basic idea:
(It's in FASM syntax)
JJ
(It's in FASM syntax)
Code: Select all
start:
call enter_unreal_mode
mov [gs:0x100000], dword 0xdeadbeef ;Now, this won't cause a GPF...
jmp $
enter_unreal_mode:
cli
push dword gdt+0x10000
push word gdt.limit
movzx esp, sp
lgdt [esp]
mov eax, cr0
or eax, 1
mov cr0, eax
mov ax, 8
mov gs, ax ;Add here any other registers with which you want to access over 1MB
mov eax, cr0
and eax, not 1
mov cr0, eax
xor ax, ax
mov gs, ax
add sp, 6
sti
ret
macro gdt_entry base,limit,flags {
dw limit and 0xFFFF
dw base and 0xFFFF
db (base shr 16) and 0xFF
db flags
db ((limit shr 16) and 0xF) or 0xC0
db (base shr 24) and 0xFF
}
gdt:
dd 0,0 ;NULL entry
gdt_entry 0x00000000, 0xFFFFF, 10010010b ;Ring 0, data, expand-up, r/w
.limit = $-gdt-1