summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c')
-rw-r--r--MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c182
1 files changed, 94 insertions, 88 deletions
diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c
index a9512bd851..6622eace98 100644
--- a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c
+++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c
@@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Amount of space that is not used in the stack
//
-#define STACK_REMAIN_SIZE (1024 * 4)
+#define STACK_REMAIN_SIZE (1024 * 4)
#pragma pack(1)
typedef struct {
@@ -28,7 +28,7 @@ typedef struct {
} EBC_INSTRUCTION_BUFFER;
#pragma pack()
-extern CONST EBC_INSTRUCTION_BUFFER mEbcInstructionBufferTemplate;
+extern CONST EBC_INSTRUCTION_BUFFER mEbcInstructionBufferTemplate;
/**
Begin executing an EBC image.
@@ -65,20 +65,19 @@ EbcLLExecuteEbcImageEntryPoint (
**/
VOID
PushU64 (
- IN VM_CONTEXT *VmPtr,
- IN UINT64 Arg
+ IN VM_CONTEXT *VmPtr,
+ IN UINT64 Arg
)
{
//
// Advance the VM stack down, and then copy the argument to the stack.
// Hope it's aligned.
//
- VmPtr->Gpr[0] -= sizeof (UINT64);
- *(UINT64 *) VmPtr->Gpr[0] = Arg;
+ VmPtr->Gpr[0] -= sizeof (UINT64);
+ *(UINT64 *)VmPtr->Gpr[0] = Arg;
return;
}
-
/**
Begin executing an EBC image.
@@ -129,12 +128,12 @@ EbcInterpret (
//
// Now clear out our context
//
- ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT));
+ ZeroMem ((VOID *)&VmContext, sizeof (VM_CONTEXT));
//
// Set the VM instruction pointer to the correct location in memory.
//
- VmContext.Ip = (VMIP) Addr;
+ VmContext.Ip = (VMIP)Addr;
//
// Initialize the stack pointer for the EBC. Get the current system stack
@@ -145,14 +144,15 @@ EbcInterpret (
// Adjust the VM's stack pointer down.
//
- Status = GetEBCStack((EFI_HANDLE)(UINTN)-1, &VmContext.StackPool, &StackIndex);
- if (EFI_ERROR(Status)) {
+ Status = GetEBCStack ((EFI_HANDLE)(UINTN)-1, &VmContext.StackPool, &StackIndex);
+ if (EFI_ERROR (Status)) {
return Status;
}
- VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);
- VmContext.Gpr[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);
- VmContext.HighStackBottom = (UINTN) VmContext.Gpr[0];
- VmContext.Gpr[0] -= sizeof (UINTN);
+
+ VmContext.StackTop = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);
+ VmContext.Gpr[0] = (UINT64)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);
+ VmContext.HighStackBottom = (UINTN)VmContext.Gpr[0];
+ VmContext.Gpr[0] -= sizeof (UINTN);
//
// Align the stack on a natural boundary.
@@ -162,46 +162,46 @@ EbcInterpret (
//
// Put a magic value in the stack gap, then adjust down again.
//
- *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) VM_STACK_KEY_VALUE;
- VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.Gpr[0];
+ *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)VM_STACK_KEY_VALUE;
+ VmContext.StackMagicPtr = (UINTN *)(UINTN)VmContext.Gpr[0];
//
// The stack upper to LowStackTop is belong to the VM.
//
- VmContext.LowStackTop = (UINTN) VmContext.Gpr[0];
+ VmContext.LowStackTop = (UINTN)VmContext.Gpr[0];
//
// For the worst case, assume there are 4 arguments passed in registers, store
// them to VM's stack.
//
- PushU64 (&VmContext, (UINT64) Args9_16[7]);
- PushU64 (&VmContext, (UINT64) Args9_16[6]);
- PushU64 (&VmContext, (UINT64) Args9_16[5]);
- PushU64 (&VmContext, (UINT64) Args9_16[4]);
- PushU64 (&VmContext, (UINT64) Args9_16[3]);
- PushU64 (&VmContext, (UINT64) Args9_16[2]);
- PushU64 (&VmContext, (UINT64) Args9_16[1]);
- PushU64 (&VmContext, (UINT64) Args9_16[0]);
- PushU64 (&VmContext, (UINT64) Arg8);
- PushU64 (&VmContext, (UINT64) Arg7);
- PushU64 (&VmContext, (UINT64) Arg6);
- PushU64 (&VmContext, (UINT64) Arg5);
- PushU64 (&VmContext, (UINT64) Arg4);
- PushU64 (&VmContext, (UINT64) Arg3);
- PushU64 (&VmContext, (UINT64) Arg2);
- PushU64 (&VmContext, (UINT64) Arg1);
+ PushU64 (&VmContext, (UINT64)Args9_16[7]);
+ PushU64 (&VmContext, (UINT64)Args9_16[6]);
+ PushU64 (&VmContext, (UINT64)Args9_16[5]);
+ PushU64 (&VmContext, (UINT64)Args9_16[4]);
+ PushU64 (&VmContext, (UINT64)Args9_16[3]);
+ PushU64 (&VmContext, (UINT64)Args9_16[2]);
+ PushU64 (&VmContext, (UINT64)Args9_16[1]);
+ PushU64 (&VmContext, (UINT64)Args9_16[0]);
+ PushU64 (&VmContext, (UINT64)Arg8);
+ PushU64 (&VmContext, (UINT64)Arg7);
+ PushU64 (&VmContext, (UINT64)Arg6);
+ PushU64 (&VmContext, (UINT64)Arg5);
+ PushU64 (&VmContext, (UINT64)Arg4);
+ PushU64 (&VmContext, (UINT64)Arg3);
+ PushU64 (&VmContext, (UINT64)Arg2);
+ PushU64 (&VmContext, (UINT64)Arg1);
//
// Interpreter assumes 64-bit return address is pushed on the stack.
// AArch64 does not do this so pad the stack accordingly.
//
- PushU64 (&VmContext, (UINT64) 0);
- PushU64 (&VmContext, (UINT64) 0x1234567887654321ULL);
+ PushU64 (&VmContext, (UINT64)0);
+ PushU64 (&VmContext, (UINT64)0x1234567887654321ULL);
//
// For AArch64, this is where we say our return address is
//
- VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0];
+ VmContext.StackRetAddr = (UINT64)VmContext.Gpr[0];
//
// We need to keep track of where the EBC stack starts. This way, if the EBC
@@ -226,11 +226,10 @@ EbcInterpret (
//
// Return the value in R[7] unless there was an error
//
- ReturnEBCStack(StackIndex);
- return (UINT64) VmContext.Gpr[7];
+ ReturnEBCStack (StackIndex);
+ return (UINT64)VmContext.Gpr[7];
}
-
/**
Begin executing an EBC image.
@@ -245,9 +244,9 @@ EbcInterpret (
UINT64
EFIAPI
ExecuteEbcImageEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable,
- IN UINTN EntryPoint
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable,
+ IN UINTN EntryPoint
)
{
//
@@ -266,7 +265,7 @@ ExecuteEbcImageEntryPoint (
//
// Now clear out our context
//
- ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT));
+ ZeroMem ((VOID *)&VmContext, sizeof (VM_CONTEXT));
//
// Save the image handle so we can track the thunks created for this image
@@ -277,52 +276,52 @@ ExecuteEbcImageEntryPoint (
//
// Set the VM instruction pointer to the correct location in memory.
//
- VmContext.Ip = (VMIP) Addr;
+ VmContext.Ip = (VMIP)Addr;
//
// Initialize the stack pointer for the EBC. Get the current system stack
// pointer and adjust it down by the max needed for the interpreter.
//
- Status = GetEBCStack(ImageHandle, &VmContext.StackPool, &StackIndex);
- if (EFI_ERROR(Status)) {
+ Status = GetEBCStack (ImageHandle, &VmContext.StackPool, &StackIndex);
+ if (EFI_ERROR (Status)) {
return Status;
}
- VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);
- VmContext.Gpr[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);
- VmContext.HighStackBottom = (UINTN) VmContext.Gpr[0];
- VmContext.Gpr[0] -= sizeof (UINTN);
+ VmContext.StackTop = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);
+ VmContext.Gpr[0] = (UINT64)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);
+ VmContext.HighStackBottom = (UINTN)VmContext.Gpr[0];
+ VmContext.Gpr[0] -= sizeof (UINTN);
//
// Put a magic value in the stack gap, then adjust down again
//
- *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) VM_STACK_KEY_VALUE;
- VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.Gpr[0];
+ *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)VM_STACK_KEY_VALUE;
+ VmContext.StackMagicPtr = (UINTN *)(UINTN)VmContext.Gpr[0];
//
// Align the stack on a natural boundary
- VmContext.Gpr[0] &= ~(VM_REGISTER)(sizeof(UINTN) - 1);
+ VmContext.Gpr[0] &= ~(VM_REGISTER)(sizeof (UINTN) - 1);
//
- VmContext.LowStackTop = (UINTN) VmContext.Gpr[0];
+ VmContext.LowStackTop = (UINTN)VmContext.Gpr[0];
//
// Simply copy the image handle and system table onto the EBC stack.
// Greatly simplifies things by not having to spill the args.
//
- PushU64 (&VmContext, (UINT64) SystemTable);
- PushU64 (&VmContext, (UINT64) ImageHandle);
+ PushU64 (&VmContext, (UINT64)SystemTable);
+ PushU64 (&VmContext, (UINT64)ImageHandle);
//
// VM pushes 16-bytes for return address. Simulate that here.
//
- PushU64 (&VmContext, (UINT64) 0);
- PushU64 (&VmContext, (UINT64) 0x1234567887654321ULL);
+ PushU64 (&VmContext, (UINT64)0);
+ PushU64 (&VmContext, (UINT64)0x1234567887654321ULL);
//
// For AArch64, this is where we say our return address is
//
- VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0];
+ VmContext.StackRetAddr = (UINT64)VmContext.Gpr[0];
//
// Entry function needn't access high stack context, simply
@@ -338,11 +337,10 @@ ExecuteEbcImageEntryPoint (
//
// Return the value in R[7] unless there was an error
//
- ReturnEBCStack(StackIndex);
- return (UINT64) VmContext.Gpr[7];
+ ReturnEBCStack (StackIndex);
+ return (UINT64)VmContext.Gpr[7];
}
-
/**
Create thunks for an EBC image entry point, or an EBC protocol service.
@@ -362,18 +360,18 @@ ExecuteEbcImageEntryPoint (
**/
EFI_STATUS
EbcCreateThunks (
- IN EFI_HANDLE ImageHandle,
- IN VOID *EbcEntryPoint,
- OUT VOID **Thunk,
- IN UINT32 Flags
+ IN EFI_HANDLE ImageHandle,
+ IN VOID *EbcEntryPoint,
+ OUT VOID **Thunk,
+ IN UINT32 Flags
)
{
- EBC_INSTRUCTION_BUFFER *InstructionBuffer;
+ EBC_INSTRUCTION_BUFFER *InstructionBuffer;
//
// Check alignment of pointer to EBC code
//
- if ((UINT32) (UINTN) EbcEntryPoint & 0x01) {
+ if ((UINT32)(UINTN)EbcEntryPoint & 0x01) {
return EFI_INVALID_PARAMETER;
}
@@ -390,8 +388,11 @@ EbcCreateThunks (
//
// Copy whole thunk instruction buffer template
//
- CopyMem (InstructionBuffer, &mEbcInstructionBufferTemplate,
- sizeof (EBC_INSTRUCTION_BUFFER));
+ CopyMem (
+ InstructionBuffer,
+ &mEbcInstructionBufferTemplate,
+ sizeof (EBC_INSTRUCTION_BUFFER)
+ );
//
// Patch EbcEntryPoint and EbcLLEbcInterpret
@@ -407,13 +408,15 @@ EbcCreateThunks (
// Add the thunk to the list for this image. Do this last since the add
// function flushes the cache for us.
//
- EbcAddImageThunk (ImageHandle, InstructionBuffer,
- sizeof (EBC_INSTRUCTION_BUFFER));
+ EbcAddImageThunk (
+ ImageHandle,
+ InstructionBuffer,
+ sizeof (EBC_INSTRUCTION_BUFFER)
+ );
return EFI_SUCCESS;
}
-
/**
This function is called to execute an EBC CALLEX instruction.
The function check the callee's content to see whether it is common native
@@ -431,34 +434,38 @@ EbcCreateThunks (
**/
VOID
EbcLLCALLEX (
- IN VM_CONTEXT *VmPtr,
- IN UINTN FuncAddr,
- IN UINTN NewStackPointer,
- IN VOID *FramePtr,
- IN UINT8 Size
+ IN VM_CONTEXT *VmPtr,
+ IN UINTN FuncAddr,
+ IN UINTN NewStackPointer,
+ IN VOID *FramePtr,
+ IN UINT8 Size
)
{
- CONST EBC_INSTRUCTION_BUFFER *InstructionBuffer;
+ CONST EBC_INSTRUCTION_BUFFER *InstructionBuffer;
//
// Processor specific code to check whether the callee is a thunk to EBC.
//
InstructionBuffer = (EBC_INSTRUCTION_BUFFER *)FuncAddr;
- if (CompareMem (InstructionBuffer, &mEbcInstructionBufferTemplate,
- sizeof(EBC_INSTRUCTION_BUFFER) - 2 * sizeof (UINT64)) == 0) {
+ if (CompareMem (
+ InstructionBuffer,
+ &mEbcInstructionBufferTemplate,
+ sizeof (EBC_INSTRUCTION_BUFFER) - 2 * sizeof (UINT64)
+ ) == 0)
+ {
//
// The callee is a thunk to EBC, adjust the stack pointer down 16 bytes and
// put our return address and frame pointer on the VM stack.
// Then set the VM's IP to new EBC code.
//
VmPtr->Gpr[0] -= 8;
- VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], (UINTN) FramePtr);
- VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->Gpr[0];
- VmPtr->Gpr[0] -= 8;
- VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], (UINT64) (UINTN) (VmPtr->Ip + Size));
+ VmWriteMemN (VmPtr, (UINTN)VmPtr->Gpr[0], (UINTN)FramePtr);
+ VmPtr->FramePtr = (VOID *)(UINTN)VmPtr->Gpr[0];
+ VmPtr->Gpr[0] -= 8;
+ VmWriteMem64 (VmPtr, (UINTN)VmPtr->Gpr[0], (UINT64)(UINTN)(VmPtr->Ip + Size));
- VmPtr->Ip = (VMIP) InstructionBuffer->EbcEntryPoint;
+ VmPtr->Ip = (VMIP)InstructionBuffer->EbcEntryPoint;
} else {
//
// The callee is not a thunk to EBC, call native code,
@@ -472,4 +479,3 @@ EbcLLCALLEX (
VmPtr->Ip += Size;
}
}
-