From 60aaf5cdd925e9920d71851e2e69a496ce578c1c Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Fri, 11 Oct 2024 21:51:07 -0400 Subject: [PATCH] move far jump setup in EnterUnrealMode to right after we save CS --- src/stage2/stage2.nasm | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index ae61946..1f119f4 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -284,33 +284,33 @@ EnterUnrealMode: push gs push ss - push cs ; save real mode code selector - lgdt [unreal_gdt_info] + push cs ; save real mode code selector + pop ax ; save cs to ax to setup far jump + mov word [ds:__UNREAL_SEGMENT], ax - mov eax, cr0 ; switch to pmode - or al,1 ; set pmode bit - mov cr0, eax - jmp $+2 + lgdt [unreal_gdt_info] + mov eax, cr0 + or al,1 ; set pmode bit + mov cr0, eax ; switch to pmode + jmp $+2 ; clear instruction cache ;jmp far 0x0008:EnterUnrealMode.load_cs db 0xEA ; jmp far imm16:imm16 dw EnterUnrealMode.load_cs ; error_far_ptr dw 0x0008 ; error_far_seg .load_cs: - mov bx, 0x10 ; select descriptor 2 - mov ds, bx ; 10h = 0001_0000b + mov bx, 0x10 ; select descriptor 2 + mov ds, bx ; 10h = 0001_0000b mov ss, bx mov es, 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 - mov cr0, eax ; by toggling bit again - jmp $+2 + and al,0xFE ; toggle bit 1 of cr0 + mov cr0, eax ; back to realmode + 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 db 0xEA ; jmp far imm16:imm16 dw EnterUnrealMode.unload_cs ; error_far_ptr