move far jump setup in EnterUnrealMode to right after we save CS

This commit is contained in:
2024-10-11 21:51:07 -04:00
parent daa6337285
commit 96de8cd9c7

View File

@@ -284,33 +284,33 @@ EnterUnrealMode:
push gs push gs
push ss push ss
push cs ; save real mode code selector push cs ; save real mode code selector
lgdt [unreal_gdt_info] pop ax ; save cs to ax to setup far jump
mov word [ds:__UNREAL_SEGMENT], ax
mov eax, cr0 ; switch to pmode lgdt [unreal_gdt_info]
or al,1 ; set pmode bit mov eax, cr0
mov cr0, eax or al,1 ; set pmode bit
jmp $+2 mov cr0, eax ; switch to pmode
jmp $+2 ; clear instruction cache
;jmp far 0x0008:EnterUnrealMode.load_cs ;jmp far 0x0008:EnterUnrealMode.load_cs
db 0xEA ; jmp far imm16:imm16 db 0xEA ; jmp far imm16:imm16
dw EnterUnrealMode.load_cs ; error_far_ptr dw EnterUnrealMode.load_cs ; error_far_ptr
dw 0x0008 ; error_far_seg dw 0x0008 ; error_far_seg
.load_cs: .load_cs:
mov bx, 0x10 ; select descriptor 2 mov bx, 0x10 ; select descriptor 2
mov ds, bx ; 10h = 0001_0000b mov ds, bx ; 10h = 0001_0000b
mov ss, bx mov ss, bx
mov es, bx mov es, bx
mov fs, bx mov fs, bx
mov gs, bx ; other data/stack to desc. 2 mov gs, bx ; other data/stack to index 2 (off 0x10)
and al,0xFE ; back to realmode and al,0xFE ; toggle bit 1 of cr0
mov cr0, eax ; by toggling bit again mov cr0, eax ; back to realmode
jmp $+2 jmp $+2 ; clear instruction cache again
pop ax ; save cs to ax to setup far jump
mov word [ds:__UNREAL_SEGMENT], ax
;jmp far 0x0008:EnterUnrealMode.unload_cs ;jmp far 0x0008:EnterUnrealMode.unload_cs
db 0xEA ; jmp far imm16:imm16 db 0xEA ; jmp far imm16:imm16
dw EnterUnrealMode.unload_cs ; error_far_ptr dw EnterUnrealMode.unload_cs ; error_far_ptr