mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-27 15:44:04 +02:00
Ring3: Refactored exception handling.
This commit is contained in:
parent
eba7b947da
commit
cf3bb4d68b
@ -1691,13 +1691,18 @@ InitializeRing3 (
|
|||||||
DEBUG ((DEBUG_ERROR, "Core: gRing3CallStackTop = %p\n", gRing3CallStackTop));
|
DEBUG ((DEBUG_ERROR, "Core: gRing3CallStackTop = %p\n", gRing3CallStackTop));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize MSR_IA32_STAR and MSR_IA32_LSTAR for SYSCALL and SYSRET.
|
// Initialize MSR_IA32_STAR, MSR_IA32_LSTAR and MSR_IA32_FMASK for SYSCALL and SYSRET.
|
||||||
//
|
//
|
||||||
Msr = (((((UINT64)RING3_CODE64_SEL - 16) | 3) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
|
Msr = (((((UINT64)RING3_CODE64_SEL - 16) | 3) << 16) | (UINT64)RING0_CODE64_SEL) << 32;
|
||||||
AsmWriteMsr64 (MSR_IA32_STAR, Msr);
|
AsmWriteMsr64 (MSR_IA32_STAR, Msr);
|
||||||
|
|
||||||
Msr = (UINT64)(UINTN)CoreBootServices;
|
Msr = (UINT64)(UINTN)CoreBootServices;
|
||||||
AsmWriteMsr64 (MSR_IA32_LSTAR, Msr);
|
AsmWriteMsr64 (MSR_IA32_LSTAR, Msr);
|
||||||
|
//
|
||||||
|
// Disable maskable interrupts at SYSCALL.
|
||||||
|
//
|
||||||
|
Msr = (UINT64)BIT9;
|
||||||
|
AsmWriteMsr64 (MSR_IA32_FMASK, Msr);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,6 @@ copy:
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
global ASM_PFX(CoreBootServices)
|
global ASM_PFX(CoreBootServices)
|
||||||
ASM_PFX(CoreBootServices):
|
ASM_PFX(CoreBootServices):
|
||||||
cli
|
|
||||||
; Switch from User to Core data segment selectors.
|
; Switch from User to Core data segment selectors.
|
||||||
mov ax, ss
|
mov ax, ss
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
@ -160,10 +159,8 @@ ASM_PFX(CoreBootServices):
|
|||||||
mov r8, [rbp + 8*6]
|
mov r8, [rbp + 8*6]
|
||||||
|
|
||||||
sti
|
sti
|
||||||
|
|
||||||
call ASM_PFX(CallBootService)
|
call ASM_PFX(CallBootService)
|
||||||
push rax
|
push rax
|
||||||
|
|
||||||
cli
|
cli
|
||||||
|
|
||||||
SetRing3DataSegmentSelectors
|
SetRing3DataSegmentSelectors
|
||||||
@ -181,8 +178,6 @@ ASM_PFX(CoreBootServices):
|
|||||||
pop rbp
|
pop rbp
|
||||||
pop rsp
|
pop rsp
|
||||||
|
|
||||||
sti
|
|
||||||
|
|
||||||
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
; SYSCALL saves RFLAGS into R11 and the RIP of the next instruction into RCX.
|
||||||
o64 sysret
|
o64 sysret
|
||||||
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
; SYSRET copies the value in RCX into RIP and loads RFLAGS from R11.
|
||||||
@ -198,7 +193,10 @@ o64 sysret
|
|||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
global ASM_PFX(CallRing3)
|
global ASM_PFX(CallRing3)
|
||||||
ASM_PFX(CallRing3):
|
ASM_PFX(CallRing3):
|
||||||
|
pushfq
|
||||||
|
pop r11
|
||||||
cli
|
cli
|
||||||
|
|
||||||
; Save input Arguments.
|
; Save input Arguments.
|
||||||
push rcx
|
push rcx
|
||||||
|
|
||||||
@ -207,8 +205,6 @@ ASM_PFX(CallRing3):
|
|||||||
; Prepare SYSRET arguments.
|
; Prepare SYSRET arguments.
|
||||||
mov rcx, [gRing3EntryPoint]
|
mov rcx, [gRing3EntryPoint]
|
||||||
pop rdx
|
pop rdx
|
||||||
pushfq
|
|
||||||
pop r11
|
|
||||||
|
|
||||||
; Save Core Stack pointers and switch to User Stack.
|
; Save Core Stack pointers and switch to User Stack.
|
||||||
mov [ASM_PFX(CoreRsp)], rsp
|
mov [ASM_PFX(CoreRsp)], rsp
|
||||||
@ -216,8 +212,6 @@ ASM_PFX(CallRing3):
|
|||||||
mov rsp, [ASM_PFX(gRing3CallStackTop)]
|
mov rsp, [ASM_PFX(gRing3CallStackTop)]
|
||||||
mov rbp, rsp
|
mov rbp, rsp
|
||||||
|
|
||||||
sti
|
|
||||||
|
|
||||||
; Pass control to user image
|
; Pass control to user image
|
||||||
o64 sysret
|
o64 sysret
|
||||||
|
|
||||||
|
@ -207,6 +207,15 @@ HasErrorCode:
|
|||||||
mov rax, gs
|
mov rax, gs
|
||||||
push rax
|
push rax
|
||||||
|
|
||||||
|
; Check whether Ring3 process was interrupted.
|
||||||
|
and rax, 3
|
||||||
|
cmp rax, 3
|
||||||
|
jne SkipHook
|
||||||
|
mov rax, cr2
|
||||||
|
cmp rax, 0xFFFFFFFFFFFFFFF8
|
||||||
|
jne SkipHook
|
||||||
|
mov rcx, 32
|
||||||
|
SkipHook:
|
||||||
mov rax, ss
|
mov rax, ss
|
||||||
mov ds, rax
|
mov ds, rax
|
||||||
mov es, rax
|
mov es, rax
|
||||||
@ -433,14 +442,12 @@ CetDone:
|
|||||||
pop r15
|
pop r15
|
||||||
|
|
||||||
; Check whether Ring3 process was interrupted.
|
; Check whether Ring3 process was interrupted.
|
||||||
push rax
|
|
||||||
mov rax, ss
|
|
||||||
push rcx
|
push rcx
|
||||||
mov rcx, ds
|
mov rcx, ds
|
||||||
cmp rax, rcx
|
and rcx, 3
|
||||||
jne ReturnToRing3
|
cmp rcx, 3
|
||||||
pop rcx
|
pop rcx
|
||||||
pop rax
|
je ReturnToRing3
|
||||||
|
|
||||||
mov rsp, rbp
|
mov rsp, rbp
|
||||||
pop rbp
|
pop rbp
|
||||||
@ -469,8 +476,6 @@ DoReturn:
|
|||||||
DoIret:
|
DoIret:
|
||||||
iretq
|
iretq
|
||||||
ReturnToRing3:
|
ReturnToRing3:
|
||||||
pop rcx
|
|
||||||
pop rax
|
|
||||||
mov rsp, rbp
|
mov rsp, rbp
|
||||||
pop rbp
|
pop rbp
|
||||||
add rsp, 16
|
add rsp, 16
|
||||||
|
Loading…
x
Reference in New Issue
Block a user