]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ia32 / EbcSupport.c
index a25139536f635b449db9f8bc48076135cc0dcc20..d53e94ebf9c52089ee05d0e93ab395b740be9c49 100644 (file)
@@ -17,21 +17,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 //       based on whether or not a debugger is present, and other\r
 //       platform-specific configurations.\r
 //\r
-#define VM_STACK_SIZE   (1024 * 4)\r
+#define VM_STACK_SIZE  (1024 * 4)\r
 \r
-#define STACK_REMAIN_SIZE (1024 * 4)\r
+#define STACK_REMAIN_SIZE  (1024 * 4)\r
 \r
 //\r
 // This is instruction buffer used to create EBC thunk\r
 //\r
-#define EBC_ENTRYPOINT_SIGNATURE           0xAFAFAFAF\r
-#define EBC_LL_EBC_ENTRYPOINT_SIGNATURE    0xFAFAFAFA\r
+#define EBC_ENTRYPOINT_SIGNATURE         0xAFAFAFAF\r
+#define EBC_LL_EBC_ENTRYPOINT_SIGNATURE  0xFAFAFAFA\r
 UINT8  mInstructionBufferTemplate[] = {\r
   //\r
   // Add a magic code here to help the VM recognize the thunk..\r
   // mov eax, 0xca112ebc  => B8 BC 2E 11 CA\r
   //\r
-  0xB8, 0xBC, 0x2E, 0x11, 0xCA,\r
+  0xB8,                                                    0xBC, 0x2E, 0x11, 0xCA,\r
   //\r
   // Add code bytes to load up a processor register with the EBC entry point.\r
   //  mov eax, EbcEntryPoint  => B8 XX XX XX XX (To be fixed at runtime)\r
@@ -39,24 +39,24 @@ UINT8  mInstructionBufferTemplate[] = {
   // entry point.\r
   //\r
   0xB8,\r
-    (UINT8)(EBC_ENTRYPOINT_SIGNATURE & 0xFF),\r
-    (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),\r
-    (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),\r
-    (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),\r
+  (UINT8)(EBC_ENTRYPOINT_SIGNATURE & 0xFF),\r
+  (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),\r
+  (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),\r
+  (UINT8)((EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),\r
   //\r
   // Stick in a load of ecx with the address of appropriate VM function.\r
   //  mov ecx, EbcLLEbcInterpret  => B9 XX XX XX XX (To be fixed at runtime)\r
   //\r
   0xB9,\r
-    (UINT8)(EBC_LL_EBC_ENTRYPOINT_SIGNATURE & 0xFF),\r
-    (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),\r
-    (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),\r
-    (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),\r
+  (UINT8)(EBC_LL_EBC_ENTRYPOINT_SIGNATURE & 0xFF),\r
+  (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 8) & 0xFF),\r
+  (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 16) & 0xFF),\r
+  (UINT8)((EBC_LL_EBC_ENTRYPOINT_SIGNATURE >> 24) & 0xFF),\r
   //\r
   // Stick in jump opcode bytes\r
   //  jmp ecx => FF E1\r
   //\r
-  0xFF, 0xE1,\r
+  0xFF,                                                    0xE1,\r
 };\r
 \r
 /**\r
@@ -102,60 +102,62 @@ EbcLLExecuteEbcImageEntryPoint (
 **/\r
 VOID\r
 EbcLLCALLEX (\r
-  IN VM_CONTEXT   *VmPtr,\r
-  IN UINTN        FuncAddr,\r
-  IN UINTN        NewStackPointer,\r
-  IN VOID         *FramePtr,\r
-  IN UINT8        Size\r
+  IN VM_CONTEXT  *VmPtr,\r
+  IN UINTN       FuncAddr,\r
+  IN UINTN       NewStackPointer,\r
+  IN VOID        *FramePtr,\r
+  IN UINT8       Size\r
   )\r
 {\r
-  UINTN    IsThunk;\r
-  UINTN    TargetEbcAddr;\r
-  UINT8    InstructionBuffer[sizeof(mInstructionBufferTemplate)];\r
-  UINTN    Index;\r
-  UINTN    IndexOfEbcEntrypoint;\r
-\r
-  IsThunk       = 1;\r
-  TargetEbcAddr = 0;\r
+  UINTN  IsThunk;\r
+  UINTN  TargetEbcAddr;\r
+  UINT8  InstructionBuffer[sizeof (mInstructionBufferTemplate)];\r
+  UINTN  Index;\r
+  UINTN  IndexOfEbcEntrypoint;\r
+\r
+  IsThunk              = 1;\r
+  TargetEbcAddr        = 0;\r
   IndexOfEbcEntrypoint = 0;\r
 \r
   //\r
   // Processor specific code to check whether the callee is a thunk to EBC.\r
   //\r
-  CopyMem (InstructionBuffer, (VOID *)FuncAddr, sizeof(InstructionBuffer));\r
+  CopyMem (InstructionBuffer, (VOID *)FuncAddr, sizeof (InstructionBuffer));\r
   //\r
   // Fill the signature according to mInstructionBufferTemplate\r
   //\r
-  for (Index = 0; Index < sizeof(mInstructionBufferTemplate) - sizeof(UINTN); Index++) {\r
+  for (Index = 0; Index < sizeof (mInstructionBufferTemplate) - sizeof (UINTN); Index++) {\r
     if (*(UINTN *)&mInstructionBufferTemplate[Index] == EBC_ENTRYPOINT_SIGNATURE) {\r
       *(UINTN *)&InstructionBuffer[Index] = EBC_ENTRYPOINT_SIGNATURE;\r
-      IndexOfEbcEntrypoint = Index;\r
+      IndexOfEbcEntrypoint                = Index;\r
     }\r
+\r
     if (*(UINTN *)&mInstructionBufferTemplate[Index] == EBC_LL_EBC_ENTRYPOINT_SIGNATURE) {\r
       *(UINTN *)&InstructionBuffer[Index] = EBC_LL_EBC_ENTRYPOINT_SIGNATURE;\r
     }\r
   }\r
+\r
   //\r
   // Check if we need thunk to native\r
   //\r
-  if (CompareMem (InstructionBuffer, mInstructionBufferTemplate, sizeof(mInstructionBufferTemplate)) != 0) {\r
+  if (CompareMem (InstructionBuffer, mInstructionBufferTemplate, sizeof (mInstructionBufferTemplate)) != 0) {\r
     IsThunk = 0;\r
   }\r
 \r
-  if (IsThunk == 1){\r
+  if (IsThunk == 1) {\r
     //\r
     // The callee is a thunk to EBC, adjust the stack pointer down 16 bytes and\r
     // put our return address and frame pointer on the VM stack.\r
     // Then set the VM's IP to new EBC code.\r
     //\r
     VmPtr->Gpr[0] -= 8;\r
-    VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], (UINTN) FramePtr);\r
-    VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->Gpr[0];\r
-    VmPtr->Gpr[0] -= 8;\r
-    VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], (UINT64) (UINTN) (VmPtr->Ip + Size));\r
+    VmWriteMemN (VmPtr, (UINTN)VmPtr->Gpr[0], (UINTN)FramePtr);\r
+    VmPtr->FramePtr = (VOID *)(UINTN)VmPtr->Gpr[0];\r
+    VmPtr->Gpr[0]  -= 8;\r
+    VmWriteMem64 (VmPtr, (UINTN)VmPtr->Gpr[0], (UINT64)(UINTN)(VmPtr->Ip + Size));\r
 \r
-    CopyMem (&TargetEbcAddr, (UINT8 *)FuncAddr + IndexOfEbcEntrypoint, sizeof(UINTN));\r
-    VmPtr->Ip = (VMIP) (UINTN) TargetEbcAddr;\r
+    CopyMem (&TargetEbcAddr, (UINT8 *)FuncAddr + IndexOfEbcEntrypoint, sizeof (UINTN));\r
+    VmPtr->Ip = (VMIP)(UINTN)TargetEbcAddr;\r
   } else {\r
     //\r
     // The callee is not a thunk to EBC, call native code,\r
@@ -170,7 +172,6 @@ EbcLLCALLEX (
   }\r
 }\r
 \r
-\r
 /**\r
   Begin executing an EBC image.\r
 \r
@@ -202,23 +203,23 @@ EbcLLCALLEX (
 UINT64\r
 EFIAPI\r
 EbcInterpret (\r
-  IN UINTN      EntryPoint,\r
-  IN UINTN      Arg1,\r
-  IN UINTN      Arg2,\r
-  IN UINTN      Arg3,\r
-  IN UINTN      Arg4,\r
-  IN UINTN      Arg5,\r
-  IN UINTN      Arg6,\r
-  IN UINTN      Arg7,\r
-  IN UINTN      Arg8,\r
-  IN UINTN      Arg9,\r
-  IN UINTN      Arg10,\r
-  IN UINTN      Arg11,\r
-  IN UINTN      Arg12,\r
-  IN UINTN      Arg13,\r
-  IN UINTN      Arg14,\r
-  IN UINTN      Arg15,\r
-  IN UINTN      Arg16\r
+  IN UINTN  EntryPoint,\r
+  IN UINTN  Arg1,\r
+  IN UINTN  Arg2,\r
+  IN UINTN  Arg3,\r
+  IN UINTN  Arg4,\r
+  IN UINTN  Arg5,\r
+  IN UINTN  Arg6,\r
+  IN UINTN  Arg7,\r
+  IN UINTN  Arg8,\r
+  IN UINTN  Arg9,\r
+  IN UINTN  Arg10,\r
+  IN UINTN  Arg11,\r
+  IN UINTN  Arg12,\r
+  IN UINTN  Arg13,\r
+  IN UINTN  Arg14,\r
+  IN UINTN  Arg15,\r
+  IN UINTN  Arg16\r
   )\r
 {\r
   //\r
@@ -237,12 +238,12 @@ EbcInterpret (
   //\r
   // Now clear out our context\r
   //\r
-  ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT));\r
+  ZeroMem ((VOID *)&VmContext, sizeof (VM_CONTEXT));\r
 \r
   //\r
   // Set the VM instruction pointer to the correct location in memory.\r
   //\r
-  VmContext.Ip = (VMIP) Addr;\r
+  VmContext.Ip = (VMIP)Addr;\r
   //\r
   // Initialize the stack pointer for the EBC. Get the current system stack\r
   // pointer and adjust it down by the max needed for the interpreter.\r
@@ -255,60 +256,61 @@ EbcInterpret (
   //\r
   // Allocate stack pool\r
   //\r
-  Status = GetEBCStack((EFI_HANDLE)-1, &VmContext.StackPool, &StackIndex);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = GetEBCStack ((EFI_HANDLE)-1, &VmContext.StackPool, &StackIndex);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
-  VmContext.Gpr[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+\r
+  VmContext.StackTop        = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
+  VmContext.Gpr[0]          = (UINT64)(UINTN)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);\r
   VmContext.HighStackBottom = (UINTN)VmContext.Gpr[0];\r
-  VmContext.Gpr[0] &= ~((VM_REGISTER)(sizeof (UINTN) - 1));\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
+  VmContext.Gpr[0]         &= ~((VM_REGISTER)(sizeof (UINTN) - 1));\r
+  VmContext.Gpr[0]         -= sizeof (UINTN);\r
 \r
   //\r
   // Put a magic value in the stack gap, then adjust down again\r
   //\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
-  VmContext.StackMagicPtr             = (UINTN *) (UINTN) VmContext.Gpr[0];\r
-  VmContext.LowStackTop   = (UINTN) VmContext.Gpr[0];\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)VM_STACK_KEY_VALUE;\r
+  VmContext.StackMagicPtr             = (UINTN *)(UINTN)VmContext.Gpr[0];\r
+  VmContext.LowStackTop               = (UINTN)VmContext.Gpr[0];\r
 \r
   //\r
   // For IA32, this is where we say our return address is\r
   //\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg16;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg15;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg14;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg13;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg12;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg11;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg10;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg9;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg8;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg7;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg6;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg5;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg4;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg3;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg2;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) Arg1;\r
-  VmContext.Gpr[0] -= 16;\r
-  VmContext.StackRetAddr  = (UINT64) VmContext.Gpr[0];\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg16;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg15;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg14;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg13;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg12;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg11;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg10;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg9;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg8;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg7;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg6;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg5;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg4;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg3;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg2;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)Arg1;\r
+  VmContext.Gpr[0]                   -= 16;\r
+  VmContext.StackRetAddr              = (UINT64)VmContext.Gpr[0];\r
 \r
   //\r
   // We need to keep track of where the EBC stack starts. This way, if the EBC\r
@@ -333,11 +335,10 @@ EbcInterpret (
   //\r
   // Return the value in Gpr[7] unless there was an error\r
   //\r
-  ReturnEBCStack(StackIndex);\r
-  return (UINT64) VmContext.Gpr[7];\r
+  ReturnEBCStack (StackIndex);\r
+  return (UINT64)VmContext.Gpr[7];\r
 }\r
 \r
-\r
 /**\r
   Begin executing an EBC image.\r
 \r
@@ -352,9 +353,9 @@ EbcInterpret (
 UINT64\r
 EFIAPI\r
 ExecuteEbcImageEntryPoint (\r
-  IN UINTN                EntryPoint,\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  IN UINTN             EntryPoint,\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   //\r
@@ -373,7 +374,7 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Now clear out our context\r
   //\r
-  ZeroMem ((VOID *) &VmContext, sizeof (VM_CONTEXT));\r
+  ZeroMem ((VOID *)&VmContext, sizeof (VM_CONTEXT));\r
 \r
   //\r
   // Save the image handle so we can track the thunks created for this image\r
@@ -384,7 +385,7 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Set the VM instruction pointer to the correct location in memory.\r
   //\r
-  VmContext.Ip = (VMIP) Addr;\r
+  VmContext.Ip = (VMIP)Addr;\r
 \r
   //\r
   // Initialize the stack pointer for the EBC. Get the current system stack\r
@@ -394,33 +395,34 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Allocate stack pool\r
   //\r
-  Status = GetEBCStack(ImageHandle, &VmContext.StackPool, &StackIndex);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = GetEBCStack (ImageHandle, &VmContext.StackPool, &StackIndex);\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
-  VmContext.Gpr[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+\r
+  VmContext.StackTop        = (UINT8 *)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
+  VmContext.Gpr[0]          = (UINT64)(UINTN)((UINT8 *)VmContext.StackPool + STACK_POOL_SIZE);\r
   VmContext.HighStackBottom = (UINTN)VmContext.Gpr[0];\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
+  VmContext.Gpr[0]         -= sizeof (UINTN);\r
 \r
   //\r
   // Put a magic value in the stack gap, then adjust down again\r
   //\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
-  VmContext.StackMagicPtr             = (UINTN *) (UINTN) VmContext.Gpr[0];\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)VM_STACK_KEY_VALUE;\r
+  VmContext.StackMagicPtr             = (UINTN *)(UINTN)VmContext.Gpr[0];\r
 \r
   //\r
   // Align the stack on a natural boundary\r
   //  VmContext.Gpr[0] &= ~(sizeof(UINTN) - 1);\r
   //\r
-  VmContext.LowStackTop   = (UINTN) VmContext.Gpr[0];\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) SystemTable;\r
-  VmContext.Gpr[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.Gpr[0]) = (UINTN) ImageHandle;\r
+  VmContext.LowStackTop               = (UINTN)VmContext.Gpr[0];\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)SystemTable;\r
+  VmContext.Gpr[0]                   -= sizeof (UINTN);\r
+  *(UINTN *)(UINTN)(VmContext.Gpr[0]) = (UINTN)ImageHandle;\r
 \r
-  VmContext.Gpr[0] -= 16;\r
-  VmContext.StackRetAddr  = (UINT64) VmContext.Gpr[0];\r
+  VmContext.Gpr[0]      -= 16;\r
+  VmContext.StackRetAddr = (UINT64)VmContext.Gpr[0];\r
   //\r
   // VM pushes 16-bytes for return address. Simulate that here.\r
   //\r
@@ -434,11 +436,10 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Return the value in Gpr[7] unless there was an error\r
   //\r
-  ReturnEBCStack(StackIndex);\r
-  return (UINT64) VmContext.Gpr[7];\r
+  ReturnEBCStack (StackIndex);\r
+  return (UINT64)VmContext.Gpr[7];\r
 }\r
 \r
-\r
 /**\r
   Create thunks for an EBC image entry point, or an EBC protocol service.\r
 \r
@@ -458,31 +459,32 @@ ExecuteEbcImageEntryPoint (
 **/\r
 EFI_STATUS\r
 EbcCreateThunks (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN VOID                 *EbcEntryPoint,\r
-  OUT VOID                **Thunk,\r
-  IN  UINT32              Flags\r
+  IN EFI_HANDLE  ImageHandle,\r
+  IN VOID        *EbcEntryPoint,\r
+  OUT VOID       **Thunk,\r
+  IN  UINT32     Flags\r
   )\r
 {\r
-  UINT8       *Ptr;\r
-  UINT8       *ThunkBase;\r
-  UINT32      Index;\r
-  INT32       ThunkSize;\r
+  UINT8   *Ptr;\r
+  UINT8   *ThunkBase;\r
+  UINT32  Index;\r
+  INT32   ThunkSize;\r
 \r
   //\r
   // Check alignment of pointer to EBC code\r
   //\r
-  if ((UINT32) (UINTN) EbcEntryPoint & 0x01) {\r
+  if ((UINT32)(UINTN)EbcEntryPoint & 0x01) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  ThunkSize = sizeof(mInstructionBufferTemplate);\r
+  ThunkSize = sizeof (mInstructionBufferTemplate);\r
 \r
-  Ptr = EbcAllocatePoolForThunk (sizeof(mInstructionBufferTemplate));\r
+  Ptr = EbcAllocatePoolForThunk (sizeof (mInstructionBufferTemplate));\r
 \r
   if (Ptr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   //  Print(L"Allocate TH: 0x%X\n", (UINT32)Ptr);\r
   //\r
@@ -493,20 +495,21 @@ EbcCreateThunks (
   //\r
   // Give them the address of our buffer we're going to fix up\r
   //\r
-  *Thunk = (VOID *) Ptr;\r
+  *Thunk = (VOID *)Ptr;\r
 \r
   //\r
   // Copy whole thunk instruction buffer template\r
   //\r
-  CopyMem (Ptr, mInstructionBufferTemplate, sizeof(mInstructionBufferTemplate));\r
+  CopyMem (Ptr, mInstructionBufferTemplate, sizeof (mInstructionBufferTemplate));\r
 \r
   //\r
   // Patch EbcEntryPoint and EbcLLEbcInterpret\r
   //\r
-  for (Index = 0; Index < sizeof(mInstructionBufferTemplate) - sizeof(UINTN); Index++) {\r
+  for (Index = 0; Index < sizeof (mInstructionBufferTemplate) - sizeof (UINTN); Index++) {\r
     if (*(UINTN *)&Ptr[Index] == EBC_ENTRYPOINT_SIGNATURE) {\r
       *(UINTN *)&Ptr[Index] = (UINTN)EbcEntryPoint;\r
     }\r
+\r
     if (*(UINTN *)&Ptr[Index] == EBC_LL_EBC_ENTRYPOINT_SIGNATURE) {\r
       if ((Flags & FLAG_THUNK_ENTRY_POINT) != 0) {\r
         *(UINTN *)&Ptr[Index] = (UINTN)EbcLLExecuteEbcImageEntryPoint;\r
@@ -520,7 +523,7 @@ EbcCreateThunks (
   // Add the thunk to the list for this image. Do this last since the add\r
   // function flushes the cache for us.\r
   //\r
-  EbcAddImageThunk (ImageHandle, (VOID *) ThunkBase, ThunkSize);\r
+  EbcAddImageThunk (ImageHandle, (VOID *)ThunkBase, ThunkSize);\r
 \r
   return EFI_SUCCESS;\r
 }\r