20#define VM_STACK_SIZE (1024 * 4)
22#define STACK_REMAIN_SIZE (1024 * 4)
27#define EBC_ENTRYPOINT_SIGNATURE 0xAFAFAFAF
28#define EBC_LL_EBC_ENTRYPOINT_SIGNATURE 0xFAFAFAFA
29UINT8 mInstructionBufferTemplate[] = {
34 0xB8, 0xBC, 0x2E, 0x11, 0xCA,
42 (UINT8)(EBC_ENTRYPOINT_SIGNATURE & 0xFF),
43 (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),
44 (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),
45 (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),
51 (UINT8)(EBC_LL_EBC_ENTRYPOINT_SIGNATURE & 0xFF),
52 (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),
53 (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),
54 (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),
114 UINT8 InstructionBuffer[
sizeof (mInstructionBufferTemplate)];
116 UINTN IndexOfEbcEntrypoint;
120 IndexOfEbcEntrypoint = 0;
125 CopyMem (InstructionBuffer, (VOID *)FuncAddr,
sizeof (InstructionBuffer));
129 for (Index = 0; Index <
sizeof (mInstructionBufferTemplate) -
sizeof (
UINTN); Index++) {
130 if (*(
UINTN *)&mInstructionBufferTemplate[Index] == EBC_ENTRYPOINT_SIGNATURE) {
131 *(
UINTN *)&InstructionBuffer[Index] = EBC_ENTRYPOINT_SIGNATURE;
132 IndexOfEbcEntrypoint = Index;
135 if (*(
UINTN *)&mInstructionBufferTemplate[Index] == EBC_LL_EBC_ENTRYPOINT_SIGNATURE) {
136 *(
UINTN *)&InstructionBuffer[Index] = EBC_LL_EBC_ENTRYPOINT_SIGNATURE;
143 if (
CompareMem (InstructionBuffer, mInstructionBufferTemplate,
sizeof (mInstructionBufferTemplate)) != 0) {
155 VmPtr->FramePtr = (VOID *)(
UINTN)VmPtr->Gpr[0];
159 CopyMem (&TargetEbcAddr, (UINT8 *)FuncAddr + IndexOfEbcEntrypoint,
sizeof (
UINTN));
246 VmContext.
Ip = (
VMIP)Addr;
260 if (EFI_ERROR (Status)) {
264 VmContext.StackTop = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);
265 VmContext.
Gpr[0] = (UINT64)(
UINTN)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);
267 VmContext.
Gpr[0] &= ~((VM_REGISTER)(
sizeof (
UINTN) - 1));
312 VmContext.
Gpr[0] -= 16;
339 return (UINT64)VmContext.
Gpr[7];
388 VmContext.
Ip = (
VMIP)Addr;
398 Status =
GetEBCStack (ImageHandle, &VmContext.StackPool, &StackIndex);
399 if (EFI_ERROR (Status)) {
403 VmContext.StackTop = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);
404 VmContext.
Gpr[0] = (UINT64)(
UINTN)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);
424 VmContext.
Gpr[0] -= 16;
440 return (UINT64)VmContext.
Gpr[7];
463 IN VOID *EbcEntryPoint,
476 if ((UINT32)(
UINTN)EbcEntryPoint & 0x01) {
477 return EFI_INVALID_PARAMETER;
480 ThunkSize =
sizeof (mInstructionBufferTemplate);
485 return EFI_OUT_OF_RESOURCES;
498 *Thunk = (VOID *)Ptr;
503 CopyMem (Ptr, mInstructionBufferTemplate,
sizeof (mInstructionBufferTemplate));
508 for (Index = 0; Index <
sizeof (mInstructionBufferTemplate) -
sizeof (
UINTN); Index++) {
509 if (*(
UINTN *)&Ptr[Index] == EBC_ENTRYPOINT_SIGNATURE) {
513 if (*(
UINTN *)&Ptr[Index] == EBC_LL_EBC_ENTRYPOINT_SIGNATURE) {
514 if ((Flags & FLAG_THUNK_ENTRY_POINT) != 0) {
UINT64 EFIAPI ExecuteEbcImageEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN UINTN EntryPoint)
UINT64 EFIAPI EbcLLExecuteEbcImageEntryPoint(VOID)
VOID EbcLLCALLEX(IN VM_CONTEXT *VmPtr, IN UINTN FuncAddr, IN UINTN NewStackPointer, IN VOID *FramePtr, IN UINT8 Size)
UINT64 EFIAPI EbcInterpret(IN UINTN Arg1, IN UINTN Arg2, IN UINTN Arg3, IN UINTN Arg4, IN UINTN Arg5, IN UINTN Arg6, IN UINTN Arg7, IN UINTN Arg8, IN UINTN EntryPoint, IN CONST UINTN Args9_16[])
UINT64 EFIAPI EbcLLEbcInterpret(VOID)
EFI_STATUS EbcCreateThunks(IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk, IN UINT32 Flags)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EbcExecute(IN VM_CONTEXT *VmPtr)
EFI_STATUS VmWriteMemN(IN VM_CONTEXT *VmPtr, IN UINTN Addr, IN UINTN Data)
EFI_STATUS VmWriteMem64(IN VM_CONTEXT *VmPtr, IN UINTN Addr, IN UINT64 Data)
EFI_STATUS EbcAddImageThunk(IN EFI_HANDLE ImageHandle, IN VOID *ThunkBuffer, IN UINT32 ThunkSize)
VOID *EFIAPI EbcAllocatePoolForThunk(IN UINTN AllocationSize)
EFI_STATUS ReturnEBCStack(IN UINTN Index)
EFI_STATUS GetEBCStack(IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
INT64 EFIAPI EbcLLCALLEXNative(IN UINTN CallAddr, IN UINTN EbcSp, IN VOID *FramePtr)
VOID EbcDebuggerHookEbcInterpret(IN VM_CONTEXT *VmPtr)
VOID EbcDebuggerHookExecuteEbcImageEntryPoint(IN VM_CONTEXT *VmPtr)
UINT64 StackRetAddr
location of final return address on stack
UINTN HighStackBottom
bottom of the upper stack
UINTN * StackMagicPtr
pointer to magic value on stack to detect corruption
UINTN LowStackTop
top of the lower stack
VMIP Ip
Instruction pointer.
EFI_HANDLE ImageHandle
for this EBC driver
EFI_SYSTEM_TABLE * SystemTable
for debugging only