Code: Select all
realmode:
mov ebx, msgRealMode
call DisplayMessage
mov ebx, msgNWLN
call DisplayMessage
cli
jmp 0x28:switchrealmode
realidtr:
dw 0x3FF
dq 0
BITS 16
switchrealmode:
mov eax, 0x30
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
mov ss, eax
lidt [realidtr]
mov eax, cr0
and eax, 0
mov cr0, eax
jmp 0:gorealmode
gorealmode:
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0xFFFF
sti
ret
Code: Select all
NULL_DESC:
dd 0
dd 0
CODE_DESC:
dw 0xFFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_DESC:
dw 0xFFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
USERCODE_DESC:
dw 0xFFFF
dw 0
db 0
db 11111010b
db 11001111b
db 0
USERDATA_DESC:
dw 0xFFFF
dw 0
db 0
db 11110010b
db 11001111b
db 0
SIXTEENCODE_DESC:
dw 0xFFFF
dw 0
db 0
db 10011010b
db 00001111b
db 0
SIXTEENDATA_DESC:
dw 0xFFFF
dw 0
db 0
db 10010010b
db 00001111b
db 0
gdtend:
gdtr:
Limit dw gdtend-NULL_DESC-1
Base dd NULL_DESC