Ring3: Fixed interrupts handling for IA32.

This commit is contained in:
Mikhail Krichanov 2024-03-25 19:26:12 +03:00
parent accdbd58ec
commit 755baf7951
3 changed files with 47 additions and 4 deletions

View File

@ -24,7 +24,6 @@ ASM_PFX(SysCall):
sysenter sysenter
userReturnAddress: userReturnAddress:
; sti
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -39,6 +38,5 @@ userReturnAddress:
global ASM_PFX(Ring3EntryPoint) global ASM_PFX(Ring3EntryPoint)
ASM_PFX(Ring3EntryPoint): ASM_PFX(Ring3EntryPoint):
push eax push eax
; sti
call ASM_PFX(Ring3Call) call ASM_PFX(Ring3Call)

View File

@ -161,6 +161,7 @@ ASM_PFX(CoreBootServices):
pop ebp pop ebp
pop ecx ; User Stack Pointer. pop ecx ; User Stack Pointer.
sti
sysexit sysexit
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
@ -194,6 +195,7 @@ ASM_PFX(CallRing3):
mov ebp, ecx mov ebp, ecx
; Pass control to user image ; Pass control to user image
sti
sysexit sysexit
coreReturnAddress: coreReturnAddress:

View File

@ -167,6 +167,10 @@ ErrorCodeAndVectorOnStack:
; ;
; Stack: ; Stack:
; +---------------------+ ; +---------------------+
; + Old SS + on CPL change
; +---------------------+
; + Old ESP + on CPL change
; +---------------------+
; + EFlags + ; + EFlags +
; +---------------------+ ; +---------------------+
; + CS + ; + CS +
@ -198,6 +202,12 @@ ErrorCodeAndVectorOnStack:
push edx push edx
push ebx push ebx
lea ecx, [ebp + 6 * 4] lea ecx, [ebp + 6 * 4]
; Check whether Ring0 process was interrupted.
mov eax, ds
and eax, 3
jz sameCPL_0
mov ecx, [ecx]
sameCPL_0:
push ecx ; ESP push ecx ; ESP
push dword [ebp] ; EBP push dword [ebp] ; EBP
push esi push esi
@ -205,9 +215,15 @@ ErrorCodeAndVectorOnStack:
;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; ;; UINT32 Gs, Fs, Es, Ds, Cs, Ss;
mov eax, ss mov eax, ss
push eax ; Check whether Ring0 process was interrupted.
mov ecx, ds
and ecx, 3
jz sameCPL_1
movzx eax, word [ebp + 7 * 4]
sameCPL_1:
push eax ; for ss
movzx eax, word [ebp + 4 * 4] movzx eax, word [ebp + 4 * 4]
push eax push eax ; for cs
mov eax, ds mov eax, ds
push eax push eax
mov eax, es mov eax, es
@ -217,6 +233,12 @@ ErrorCodeAndVectorOnStack:
mov eax, gs mov eax, gs
push eax push eax
mov eax, ss
mov ds, eax
mov es, eax
mov fs, eax
mov gs, eax
;; UINT32 Eip; ;; UINT32 Eip;
mov eax, [ebp + 3 * 4] mov eax, [ebp + 3 * 4]
push eax push eax
@ -367,7 +389,15 @@ ErrorCodeAndVectorOnStack:
pop es pop es
pop ds pop ds
pop dword [ebp + 4 * 4] pop dword [ebp + 4 * 4]
; Check whether Ring0 process was interrupted.
mov ecx, ss
and ecx, 3
jz sameCPL_2
pop dword [ebp + 7 * 4]
jmp continue
sameCPL_2:
pop ss pop ss
continue:
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax; ;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
pop edi pop edi
@ -379,6 +409,14 @@ ErrorCodeAndVectorOnStack:
pop ecx pop ecx
pop eax pop eax
; Check whether Ring3 process was interrupted.
push ecx
mov ecx, ds
and ecx, 3
cmp ecx, 3
pop ecx
je ReturnToRing3
pop dword [ebp - 8] pop dword [ebp - 8]
pop dword [ebp - 4] pop dword [ebp - 4]
mov esp, ebp mov esp, ebp
@ -406,6 +444,11 @@ DoReturn:
DoIret: DoIret:
iretd iretd
ReturnToRing3:
mov esp, ebp
pop ebp
add esp, 8
iretd
;---------------------------------------; ;---------------------------------------;
; _AsmGetTemplateAddressMap ; ; _AsmGetTemplateAddressMap ;