SysCall: Refactored SysCallReturnToCore handling to fix CLANGDWARF NOOPT.

This commit is contained in:
Mikhail Krichanov 2024-09-09 11:48:53 +03:00
parent 0e8c250702
commit a29bd72a05
5 changed files with 34 additions and 18 deletions

View File

@ -45,6 +45,9 @@ SysCallBootService (
EFI_PHYSICAL_ADDRESS Physical; EFI_PHYSICAL_ADDRESS Physical;
if (Type == SysCallReturnToCore) { if (Type == SysCallReturnToCore) {
//
// TODO: Refactoring
//
ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp); ReturnToCore (*(EFI_STATUS *)CoreRbp, mCoreSp);
} }

View File

@ -65,6 +65,12 @@ CallInstallMultipleProtocolInterfaces (
IN VOID *Function IN VOID *Function
); );
VOID
EFIAPI
ReturnToCore (
IN EFI_STATUS Status
);
VOID VOID
EFIAPI EFIAPI
FreeProtocolsList ( FreeProtocolsList (
@ -318,6 +324,9 @@ CallBootService (
DEBUG ((DEBUG_VERBOSE, "Type: %a\n", SysCallNames[Type])); DEBUG ((DEBUG_VERBOSE, "Type: %a\n", SysCallNames[Type]));
switch (Type) { switch (Type) {
case SysCallReturnToCore:
ReturnToCore (CoreRbp->Argument1);
break;
case SysCallLocateProtocol: case SysCallLocateProtocol:
// //
// Argument 1: EFI_GUID *Protocol // Argument 1: EFI_GUID *Protocol

View File

@ -126,10 +126,6 @@ ASM_PFX(CoreBootServices):
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
; Special case for SysCallReturnToCore.
cmp ecx, 0
je coreReturnAddress
; Prepare CallBootService arguments. ; Prepare CallBootService arguments.
call ASM_PFX(AllowSupervisorAccessToUserMemory) call ASM_PFX(AllowSupervisorAccessToUserMemory)
mov eax, [edx + 4 * 4] ; User Argument 3 mov eax, [edx + 4 * 4] ; User Argument 3
@ -202,19 +198,23 @@ ASM_PFX(CallRing3):
sti sti
sysexit sysexit
coreReturnAddress: ;------------------------------------------------------------------------------
; VOID
; EFIAPI
; ReturnToCore (
; IN EFI_STATUS Status
; );
;------------------------------------------------------------------------------
global ASM_PFX(ReturnToCore)
ASM_PFX(ReturnToCore):
mov eax, [esp + 4]
mov esp, [ASM_PFX(CoreEsp)] mov esp, [ASM_PFX(CoreEsp)]
pop esi pop esi
pop edi pop edi
pop ebp pop ebp
pop ebx pop ebx
call ASM_PFX(AllowSupervisorAccessToUserMemory)
mov eax, [edx + 2 * 4] ; User Argument 1
push eax
call ASM_PFX(ForbidSupervisorAccessToUserMemory)
pop eax
sti sti
ret ret

View File

@ -132,10 +132,6 @@ ASM_PFX(CoreBootServices):
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
; Special case for SysCallReturnToCore.
cmp r10, 0
je coreReturnAddress
; Save User Stack pointers and switch to Core SysCall Stack. ; Save User Stack pointers and switch to Core SysCall Stack.
mov rax, [ASM_PFX(gCoreSysCallStackTop)] mov rax, [ASM_PFX(gCoreSysCallStackTop)]
sub rax, 8 sub rax, 8
@ -228,7 +224,15 @@ ASM_PFX(CallRing3):
; Pass control to user image ; Pass control to user image
o64 sysret o64 sysret
coreReturnAddress: ;------------------------------------------------------------------------------
; VOID
; EFIAPI
; ReturnToCore (
; IN EFI_STATUS Status
; );
;------------------------------------------------------------------------------
global ASM_PFX(ReturnToCore)
ASM_PFX(ReturnToCore):
mov rsp, [ASM_PFX(CoreRsp)] mov rsp, [ASM_PFX(CoreRsp)]
pop r15 pop r15
pop r14 pop r14
@ -239,7 +243,7 @@ coreReturnAddress:
pop rbp pop rbp
pop rbx pop rbx
mov rax, rdx mov rax, rcx
sti sti
ret ret

View File

@ -2017,7 +2017,7 @@ typedef enum {
// //
// BootServices // BootServices
// //
SysCallReturnToCore, // Must always be zero for CoreBootServices.nasm. SysCallReturnToCore,
SysCallLocateProtocol, SysCallLocateProtocol,
SysCallOpenProtocol, SysCallOpenProtocol,
SysCallInstallMultipleProtocolInterfaces, SysCallInstallMultipleProtocolInterfaces,