Ring3: Defined SysCallBootService() for AARCH64.

This commit is contained in:
Mikhail Krichanov 2024-05-21 15:12:24 +03:00
parent 3fc05b0473
commit d03b93be3d
12 changed files with 66 additions and 29 deletions

View File

@ -71,6 +71,7 @@
#define AARCH64_ESR_ISS(Ecr) ((0x1FFFFFF) & (Ecr))
#define AARCH64_ESR_EC_SMC32 (0x13 << 26)
#define AARCH64_ESR_EC_SVC64 (0x15 << 26)
#define AARCH64_ESR_EC_SMC64 (0x17 << 26)
// AArch64 Exception Level

View File

@ -16,7 +16,8 @@
@param SystemContext Register state at the time of the Exception
**/
VOID
EFI_STATUS
EFIAPI
DefaultExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN OUT EFI_SYSTEM_CONTEXT SystemContext

View File

@ -332,7 +332,18 @@ ASM_PFX(CommonExceptionEntry):
ldp x22, x23, [sp, #0xb0]
ldp x24, x25, [sp, #0xc0]
ldp x26, x27, [sp, #0xd0]
// Preserve return value for SVC.
mrs x1, esr_el1
lsr x1, x1, #26
and x1, x1, #0x3F
cmp x1, #0x15
b.eq is_SVC
ldp x0, x1, [sp], #0xe0
b continue
is_SVC:
ldr x1, [sp, #0x8]
continue:
// Pop FP regs from Stack.
ldp q2, q3, [x28, #0x20]

View File

@ -266,7 +266,7 @@ RegisterExceptionHandler (
return RegisterCpuInterruptHandler (ExceptionType, InterruptHandler);
}
VOID
EFI_STATUS
EFIAPI
CommonCExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
@ -276,14 +276,14 @@ CommonCExceptionHandler (
if (ExceptionType <= gMaxExceptionNumber) {
if (gExceptionHandlers[ExceptionType]) {
gExceptionHandlers[ExceptionType](ExceptionType, SystemContext);
return;
return EFI_SUCCESS;
}
} else {
DEBUG ((DEBUG_ERROR, "Unknown exception type %d\n", ExceptionType));
ASSERT (FALSE);
}
DefaultExceptionHandler (ExceptionType, SystemContext);
return DefaultExceptionHandler (ExceptionType, SystemContext);
}
/**

View File

@ -186,7 +186,8 @@ BaseName (
@param SystemContext Register state at the time of the Exception
**/
VOID
EFI_STATUS
EFIAPI
DefaultExceptionHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN OUT EFI_SYSTEM_CONTEXT SystemContext
@ -197,6 +198,14 @@ DefaultExceptionHandler (
UINTN CharCount;
INT32 Offset;
if (AARCH64_ESR_EC (SystemContext.SystemContextAArch64->ESR) == AARCH64_ESR_EC_SVC64) {
return gBS->SysCallBootService (
SystemContext.SystemContextAArch64->X0,
&(SystemContext.SystemContextAArch64->X1),
&(SystemContext.SystemContextAArch64->X0)
);
}
if (mRecursiveException) {
STATIC CHAR8 CONST Message[] = "\nRecursive exception occurred while dumping the CPU state\n";
SerialPortWrite ((UINT8 *)Message, sizeof Message - 1);
@ -344,4 +353,6 @@ DefaultExceptionHandler (
ASSERT (FALSE);
CpuDeadLoop ();
return EFI_SUCCESS;
}

View File

@ -2722,6 +2722,14 @@ CoreBootServices (
...
);
EFI_STATUS
EFIAPI
SysCallBootService (
IN UINT8 Type,
IN VOID *CoreRbp,
IN VOID *UserRsp
);
EFI_STATUS
EFIAPI
CallRing3 (

View File

@ -89,7 +89,8 @@ EFI_BOOT_SERVICES mBootServices = {
(EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3, // CalculateCrc32
(EFI_COPY_MEM)CopyMem, // CopyMem
(EFI_SET_MEM)SetMem, // SetMem
(EFI_CREATE_EVENT_EX)CoreCreateEventEx // CreateEventEx
(EFI_CREATE_EVENT_EX)CoreCreateEventEx, // CreateEventEx
(EFI_SYS_CALL_BOOT_SERVICE)SysCallBootService
};
EFI_DXE_SERVICES mDxeServices = {

View File

@ -16,7 +16,7 @@
// );
//------------------------------------------------------------------------------
ASM_FUNC(SysCall)
svc #0
ret
//------------------------------------------------------------------------------

View File

@ -20,26 +20,6 @@
ASM_FUNC(CallInstallMultipleProtocolInterfaces)
ret
//------------------------------------------------------------------------------
// EFI_STATUS
// EFIAPI
// CoreBootServices (
// IN UINT8 Type,
// ...
// );
//
// (rcx) RIP of the next instruction saved by SYSCALL in SysCall().
// (rdx) Argument 1 of the called function.
// (r8) Argument 2 of the called function.
// (r9) Argument 3 of the called function.
// (r10) Type.
// (r11) RFLAGS saved by SYSCALL in SysCall().
//
// (On User Stack) Argument 4, 5, ...
//------------------------------------------------------------------------------
ASM_FUNC(CoreBootServices)
ret
//------------------------------------------------------------------------------
// EFI_STATUS
// EFIAPI

View File

@ -1391,3 +1391,18 @@ CallBootService (
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
SysCallBootService (
IN UINT8 Type,
IN VOID *CoreRbp,
IN VOID *UserRsp
)
{
return CallBootService (
Type,
(CORE_STACK *)CoreRbp,
(RING3_STACK *)UserRsp
);
}

View File

@ -322,7 +322,7 @@ CoreFileSetPosition (
File = (RING3_EFI_FILE_PROTOCOL *)This;
#if defined (MDE_CPU_X64)
#if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64)
return GoToRing3 (
2,
(VOID *)mRing3FileProtocol.SetPosition,
@ -602,7 +602,7 @@ CoreFileOpen (
return Status;
}
#if defined (MDE_CPU_X64)
#if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64)
Status = GoToRing3 (
5,
(VOID *)mRing3FileProtocol.Open,

View File

@ -1831,6 +1831,14 @@ EFI_STATUS
OUT UINT64 *MaximumVariableSize
);
typedef
EFI_STATUS
(EFIAPI *EFI_SYS_CALL_BOOT_SERVICE)(
IN UINT8 Type,
IN VOID *CoreRbp,
IN VOID *UserRsp
);
//
// Firmware should stop at a firmware user interface on next boot
//
@ -2011,6 +2019,7 @@ typedef struct {
EFI_COPY_MEM CopyMem;
EFI_SET_MEM SetMem;
EFI_CREATE_EVENT_EX CreateEventEx;
EFI_SYS_CALL_BOOT_SERVICE SysCallBootService;
} EFI_BOOT_SERVICES;
typedef enum {