]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ipf / EbcSupport.c
index 3647a12fae6e602f0f02da82b419749a5363462a..23b6c1bd84724cd6dd3f2dd9aa4b6d7ff0c49408 100644 (file)
@@ -1,30 +1,39 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-Module Name:\r
-\r
-  EbcSupport.c\r
-\r
-Abstract:\r
-\r
+/** @file\r
   This module contains EBC support routines that are customized based on\r
   the target processor.\r
 \r
---*/\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
 #include "EbcSupport.h"\r
 \r
-STATIC\r
+/**\r
+  Given raw bytes of Itanium based code, format them into a bundle and\r
+  write them out.\r
+\r
+  @param  MemPtr                 pointer to memory location to write the bundles\r
+                                 to.\r
+  @param  Template               5-bit template.\r
+  @param  Slot0                  Instruction slot 0 data for the bundle.\r
+  @param  Slot1                  Instruction slot 1 data for the bundle.\r
+  @param  Slot2                  Instruction slot 2 data for the bundle.\r
+\r
+  @retval EFI_INVALID_PARAMETER  Pointer is not aligned\r
+  @retval EFI_INVALID_PARAMETER  No more than 5 bits in template\r
+  @retval EFI_INVALID_PARAMETER  More than 41 bits used in code\r
+  @retval EFI_SUCCESS            All data is written.\r
+\r
+**/\r
 EFI_STATUS\r
 WriteBundle (\r
   IN    VOID    *MemPtr,\r
@@ -34,23 +43,44 @@ WriteBundle (
   IN    UINT64  Slot2\r
   );\r
 \r
-STATIC\r
+/**\r
+  Pushes a 64 bit unsigned value to the VM stack.\r
+\r
+  @param VmPtr  The pointer to current VM context.\r
+  @param Arg    The value to be pushed.\r
+\r
+**/\r
 VOID\r
 PushU64 (\r
-  VM_CONTEXT *VmPtr,\r
-  UINT64     Arg\r
+  IN VM_CONTEXT *VmPtr,\r
+  IN UINT64     Arg\r
   )\r
 {\r
   //\r
   // Advance the VM stack down, and then copy the argument to the stack.\r
   // Hope it's aligned.\r
   //\r
-  VmPtr->R[0] -= sizeof (UINT64);\r
-  *(UINT64 *) VmPtr->R[0] = Arg;\r
+  VmPtr->Gpr[0] -= sizeof (UINT64);\r
+  *(UINT64 *) VmPtr->Gpr[0] = Arg;\r
 }\r
 \r
-STATIC\r
+/**\r
+  Begin executing an EBC image. The address of the entry point is passed\r
+  in via a processor register, so we'll need to make a call to get the\r
+  value.\r
+\r
+  This is a thunk function. Microsoft x64 compiler only provide fast_call\r
+  calling convention, so the first four arguments are passed by rcx, rdx,\r
+  r8, and r9, while other arguments are passed in stack.\r
+\r
+  @param  Arg1                  The 1st argument.\r
+  @param  ...                   The variable arguments list.\r
+\r
+  @return The value returned by the EBC application we're going to run.\r
+\r
+**/\r
 UINT64\r
+EFIAPI\r
 EbcInterpret (\r
   UINT64      Arg1,\r
   ...\r
@@ -104,6 +134,7 @@ EbcInterpret (
   Arg14     = VA_ARG (List, UINT64);\r
   Arg15     = VA_ARG (List, UINT64);\r
   Arg16     = VA_ARG (List, UINT64);\r
+  VA_END (List);\r
   //\r
   // Now clear out our context\r
   //\r
@@ -141,20 +172,20 @@ EbcInterpret (
   // Now adjust the EBC stack pointer down to leave a gap for interpreter\r
   // execution. Then stuff a magic value there.\r
   //\r
-  \r
+\r
   Status = GetEBCStack((EFI_HANDLE)(UINTN)-1, &VmContext.StackPool, &StackIndex);\r
   if (EFI_ERROR(Status)) {\r
     return Status;\r
   }\r
   VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
-  VmContext.R[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
-  VmContext.HighStackBottom = (UINTN) VmContext.R[0];\r
-  VmContext.R[0] -= sizeof (UINTN);\r
+  VmContext.Gpr[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+  VmContext.HighStackBottom = (UINTN) VmContext.Gpr[0];\r
+  VmContext.Gpr[0] -= sizeof (UINTN);\r
+\r
 \r
-  \r
   PushU64 (&VmContext, (UINT64) VM_STACK_KEY_VALUE);\r
-  VmContext.StackMagicPtr = (UINTN *) VmContext.R[0];\r
-  VmContext.LowStackTop   = (UINTN) VmContext.R[0];\r
+  VmContext.StackMagicPtr = (UINTN *) VmContext.Gpr[0];\r
+  VmContext.LowStackTop   = (UINTN) VmContext.Gpr[0];\r
   //\r
   // Push the EBC arguments on the stack. Does not matter that they may not\r
   // all be valid.\r
@@ -182,7 +213,7 @@ EbcInterpret (
   //\r
   PushU64 (&VmContext, 0);\r
   PushU64 (&VmContext, 0xDEADBEEFDEADBEEF);\r
-  VmContext.StackRetAddr = (UINT64) VmContext.R[0];\r
+  VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0];\r
   //\r
   // Begin executing the EBC code\r
   //\r
@@ -191,35 +222,28 @@ EbcInterpret (
   // Return the value in R[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
-  return (UINT64) VmContext.R[7];\r
+  return (UINT64) VmContext.Gpr[7];\r
 }\r
 \r
-STATIC\r
-UINT64\r
-ExecuteEbcImageEntryPoint (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  IPF implementation.\r
 \r
+/**\r
   Begin executing an EBC image. The address of the entry point is passed\r
   in via a processor register, so we'll need to make a call to get the\r
   value.\r
-  \r
-Arguments:\r
 \r
-  ImageHandle   - image handle for the EBC application we're executing\r
-  SystemTable   - standard system table passed into an driver's entry point\r
+  @param  ImageHandle      image handle for the EBC application we're executing\r
+  @param  SystemTable      standard system table passed into an driver's entry\r
+                           point\r
 \r
-Returns:\r
+  @return The value returned by the EBC application we're going to run.\r
 \r
-  The value returned by the EBC application we're going to run.\r
-\r
---*/\r
+**/\r
+UINT64\r
+EFIAPI\r
+ExecuteEbcImageEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
 {\r
   //\r
   // Create a new VM context on the stack\r
@@ -255,24 +279,23 @@ Returns:
   //\r
   // Get the stack pointer. This is the bottom of the upper stack.\r
   //\r
-  Addr                      = EbcLLGetStackPointer ();\r
-  \r
+\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.R[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
-  VmContext.HighStackBottom = (UINTN) VmContext.R[0];\r
-  VmContext.R[0] -= sizeof (UINTN);\r
+  VmContext.Gpr[0] = (UINT64) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
+  VmContext.HighStackBottom = (UINTN) VmContext.Gpr[0];\r
+  VmContext.Gpr[0] -= sizeof (UINTN);\r
+\r
 \r
-  \r
   //\r
   // Allocate stack space for the interpreter. Then put a magic value\r
   // at the bottom so we can detect stack corruption.\r
   //\r
   PushU64 (&VmContext, (UINT64) VM_STACK_KEY_VALUE);\r
-  VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.R[0];\r
+  VmContext.StackMagicPtr = (UINTN *) (UINTN) VmContext.Gpr[0];\r
 \r
   //\r
   // When we thunk to external native code, we copy the last 8 qwords from\r
@@ -283,15 +306,15 @@ Returns:
   // Therefore, leave another gap below the magic value. Pick 10 qwords down,\r
   // just as a starting point.\r
   //\r
-  VmContext.R[0] -= 10 * sizeof (UINT64);\r
+  VmContext.Gpr[0] -= 10 * sizeof (UINT64);\r
 \r
   //\r
   // Align the stack pointer such that after pushing the system table,\r
   // image handle, and return address on the stack, it's aligned on a 16-byte\r
   // boundary as required for IPF.\r
   //\r
-  VmContext.R[0] &= (INT64)~0x0f;\r
-  VmContext.LowStackTop = (UINTN) VmContext.R[0];\r
+  VmContext.Gpr[0] &= (INT64)~0x0f;\r
+  VmContext.LowStackTop = (UINTN) VmContext.Gpr[0];\r
   //\r
   // Simply copy the image handle and system table onto the EBC stack.\r
   // Greatly simplifies things by not having to spill the args\r
@@ -306,7 +329,7 @@ Returns:
   //\r
   PushU64 (&VmContext, (UINT64) 0);\r
   PushU64 (&VmContext, (UINT64) 0x1234567887654321);\r
-  VmContext.StackRetAddr = (UINT64) VmContext.R[0];\r
+  VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0];\r
 \r
   //\r
   // Begin executing the EBC code\r
@@ -317,46 +340,45 @@ Returns:
   // Return the value in R[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
-  return (UINT64) VmContext.R[7];\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
+  @param  ImageHandle           Image handle for the EBC image. If not null, then\r
+                                we're creating a thunk for an image entry point.\r
+  @param  EbcEntryPoint         Address of the EBC code that the thunk is to call\r
+  @param  Thunk                 Returned thunk we create here\r
+  @param  Flags                 Flags indicating options for creating the thunk\r
+\r
+  @retval EFI_SUCCESS           The thunk was created successfully.\r
+  @retval EFI_INVALID_PARAMETER The parameter of EbcEntryPoint is not 16-bit\r
+                                aligned.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough memory to created the EBC\r
+                                Thunk.\r
+  @retval EFI_BUFFER_TOO_SMALL  EBC_THUNK_SIZE is not larger enough.\r
+\r
+**/\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
-\r
-Routine Description:\r
-\r
-  Create thunks for an EBC image entry point, or an EBC protocol service.\r
-  \r
-Arguments:\r
-\r
-  ImageHandle     - Image handle for the EBC image. If not null, then we're\r
-                    creating a thunk for an image entry point.\r
-  EbcEntryPoint   - Address of the EBC code that the thunk is to call\r
-  Thunk           - Returned thunk we create here\r
-  Flags           - Flags indicating options for creating the thunk\r
-  \r
-Returns:\r
-\r
-  Standard EFI status.\r
-  \r
---*/\r
 {\r
   UINT8       *Ptr;\r
   UINT8       *ThunkBase;\r
   UINT64      Addr;\r
   UINT64      Code[3];    // Code in a bundle\r
   UINT64      RegNum;     // register number for MOVL\r
-  UINT64      I;          // bits of MOVL immediate data\r
-  UINT64      Ic;         // bits of MOVL immediate data\r
-  UINT64      Imm5c;      // bits of MOVL immediate data\r
-  UINT64      Imm9d;      // bits of MOVL immediate data\r
-  UINT64      Imm7b;      // bits of MOVL immediate data\r
+  UINT64      BitI;       // bits of MOVL immediate data\r
+  UINT64      BitIc;         // bits of MOVL immediate data\r
+  UINT64      BitImm5c;      // bits of MOVL immediate data\r
+  UINT64      BitImm9d;      // bits of MOVL immediate data\r
+  UINT64      BitImm7b;      // bits of MOVL immediate data\r
   UINT64      Br;         // branch register for loading and jumping\r
   UINT64      *Data64Ptr;\r
   UINT32      ThunkSize;\r
@@ -454,23 +476,23 @@ Returns:
   // Extract bits from the address for insertion into the instruction\r
   // i = Addr[63:63]\r
   //\r
-  I = RShiftU64 (Addr, 63) & 0x01;\r
+  BitI = RShiftU64 (Addr, 63) & 0x01;\r
   //\r
   // ic = Addr[21:21]\r
   //\r
-  Ic = RShiftU64 (Addr, 21) & 0x01;\r
+  BitIc = RShiftU64 (Addr, 21) & 0x01;\r
   //\r
   // imm5c = Addr[20:16] for 5 bits\r
   //\r
-  Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+  BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
   //\r
   // imm9d = Addr[15:7] for 9 bits\r
   //\r
-  Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+  BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
   //\r
   // imm7b = Addr[6:0] for 7 bits\r
   //\r
-  Imm7b = Addr & 0x7F;\r
+  BitImm7b = Addr & 0x7F;\r
 \r
   //\r
   // The EBC entry point will be put into r8, so r8 can be used here\r
@@ -481,12 +503,12 @@ Returns:
   //\r
   // Next is jumbled data, including opcode and rest of address\r
   //\r
-  Code[2] = LShiftU64 (Imm7b, 13);\r
+  Code[2] = LShiftU64 (BitImm7b, 13);\r
   Code[2] = Code[2] | LShiftU64 (0x00, 20);   // vc\r
-  Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
-  Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
-  Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
-  Code[2] = Code[2] | LShiftU64 (I, 36);\r
+  Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+  Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
   Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
   Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
 \r
@@ -519,23 +541,23 @@ Returns:
   // Extract bits from the address for insertion into the instruction\r
   // i = Addr[63:63]\r
   //\r
-  I = RShiftU64 (Addr, 63) & 0x01;\r
+  BitI = RShiftU64 (Addr, 63) & 0x01;\r
   //\r
   // ic = Addr[21:21]\r
   //\r
-  Ic = RShiftU64 (Addr, 21) & 0x01;\r
+  BitIc = RShiftU64 (Addr, 21) & 0x01;\r
   //\r
   // imm5c = Addr[20:16] for 5 bits\r
   //\r
-  Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+  BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
   //\r
   // imm9d = Addr[15:7] for 9 bits\r
   //\r
-  Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+  BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
   //\r
   // imm7b = Addr[6:0] for 7 bits\r
   //\r
-  Imm7b = Addr & 0x7F;\r
+  BitImm7b = Addr & 0x7F;\r
 \r
   //\r
   // Put the EBC entry point in r8, which is the location of the return value\r
@@ -546,12 +568,12 @@ Returns:
   //\r
   // Next is jumbled data, including opcode and rest of address\r
   //\r
-  Code[2] = LShiftU64 (Imm7b, 13);\r
+  Code[2] = LShiftU64 (BitImm7b, 13);\r
   Code[2] = Code[2] | LShiftU64 (0x00, 20);   // vc\r
-  Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
-  Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
-  Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
-  Code[2] = Code[2] | LShiftU64 (I, 36);\r
+  Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+  Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
   Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
   Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
 \r
@@ -567,7 +589,7 @@ Returns:
   // to the address of the entry point of the interpreter.\r
   //\r
   Ptr += 16;\r
-  if (Flags & FLAG_THUNK_ENTRY_POINT) {\r
+  if ((Flags & FLAG_THUNK_ENTRY_POINT) != 0) {\r
     Addr = (UINT64) ExecuteEbcImageEntryPoint;\r
   } else {\r
     Addr = (UINT64) EbcInterpret;\r
@@ -591,23 +613,23 @@ Returns:
   // Extract bits from the address for insertion into the instruction\r
   // i = Addr[63:63]\r
   //\r
-  I = RShiftU64 (Addr, 63) & 0x01;\r
+  BitI = RShiftU64 (Addr, 63) & 0x01;\r
   //\r
   // ic = Addr[21:21]\r
   //\r
-  Ic = RShiftU64 (Addr, 21) & 0x01;\r
+  BitIc = RShiftU64 (Addr, 21) & 0x01;\r
   //\r
   // imm5c = Addr[20:16] for 5 bits\r
   //\r
-  Imm5c = RShiftU64 (Addr, 16) & 0x1F;\r
+  BitImm5c = RShiftU64 (Addr, 16) & 0x1F;\r
   //\r
   // imm9d = Addr[15:7] for 9 bits\r
   //\r
-  Imm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
+  BitImm9d = RShiftU64 (Addr, 7) & 0x1FF;\r
   //\r
   // imm7b = Addr[6:0] for 7 bits\r
   //\r
-  Imm7b = Addr & 0x7F;\r
+  BitImm7b = Addr & 0x7F;\r
 \r
   //\r
   // Put it in r31, a scratch register\r
@@ -617,12 +639,12 @@ Returns:
   //\r
   // Next is jumbled data, including opcode and rest of address\r
   //\r
-  Code[2] =   LShiftU64(Imm7b, 13);\r
+  Code[2] =   LShiftU64(BitImm7b, 13);\r
   Code[2] = Code[2] | LShiftU64 (0x00, 20);   // vc\r
-  Code[2] = Code[2] | LShiftU64 (Ic, 21);\r
-  Code[2] = Code[2] | LShiftU64 (Imm5c, 22);\r
-  Code[2] = Code[2] | LShiftU64 (Imm9d, 27);\r
-  Code[2] = Code[2] | LShiftU64 (I, 36);\r
+  Code[2] = Code[2] | LShiftU64 (BitIc, 21);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm5c, 22);\r
+  Code[2] = Code[2] | LShiftU64 (BitImm9d, 27);\r
+  Code[2] = Code[2] | LShiftU64 (BitI, 36);\r
   Code[2] = Code[2] | LShiftU64 ((UINT64)MOVL_OPCODE, 37);\r
   Code[2] = Code[2] | LShiftU64 ((RegNum & 0x7F), 6);\r
 \r
@@ -680,7 +702,24 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Given raw bytes of Itanium based code, format them into a bundle and\r
+  write them out.\r
+\r
+  @param  MemPtr                 pointer to memory location to write the bundles\r
+                                 to.\r
+  @param  Template               5-bit template.\r
+  @param  Slot0                  Instruction slot 0 data for the bundle.\r
+  @param  Slot1                  Instruction slot 1 data for the bundle.\r
+  @param  Slot2                  Instruction slot 2 data for the bundle.\r
+\r
+  @retval EFI_INVALID_PARAMETER  Pointer is not aligned\r
+  @retval EFI_INVALID_PARAMETER  No more than 5 bits in template\r
+  @retval EFI_INVALID_PARAMETER  More than 41 bits used in code\r
+  @retval EFI_SUCCESS            All data is written.\r
+\r
+**/\r
 EFI_STATUS\r
 WriteBundle (\r
   IN    VOID    *MemPtr,\r
@@ -689,27 +728,6 @@ WriteBundle (
   IN    UINT64  Slot1,\r
   IN    UINT64  Slot2\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Given raw bytes of Itanium based code, format them into a bundle and\r
-  write them out.\r
-  \r
-Arguments:\r
-\r
-  MemPtr    - pointer to memory location to write the bundles to\r
-  Template  - 5-bit template\r
-  Slot0-2   - instruction slot data for the bundle\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER - Pointer is not aligned\r
-                        - No more than 5 bits in template\r
-                        - More than 41 bits used in code\r
-  EFI_SUCCESS           - All data is written.\r
-\r
---*/\r
 {\r
   UINT8   *BPtr;\r
   UINT32  Index;\r
@@ -725,13 +743,13 @@ Returns:
   //\r
   // Verify no more than 5 bits in template\r
   //\r
-  if (Template &~0x1F) {\r
+  if ((Template &~0x1F) != 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   //\r
   // Verify max of 41 bits used in code\r
   //\r
-  if ((Slot0 | Slot1 | Slot2) &~0x1ffffffffff) {\r
+  if (((Slot0 | Slot1 | Slot2) &~0x1ffffffffff) != 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -760,38 +778,30 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \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
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
-  This function is called to execute an EBC CALLEX instruction. \r
+/**\r
+  This function is called to execute an EBC CALLEX instruction.\r
   The function check the callee's content to see whether it is common native\r
   code or a thunk to another piece of EBC code.\r
   If the callee is common native code, use EbcLLCAllEXASM to manipulate,\r
   otherwise, set the VM->IP to target EBC code directly to avoid another VM\r
   be startup which cost time and stack space.\r
-  \r
-Arguments:\r
 \r
-  VmPtr             - Pointer to a VM context.\r
-  FuncAddr          - Callee's address\r
-  NewStackPointer   - New stack pointer after the call\r
-  FramePtr          - New frame pointer after the call\r
-  Size              - The size of call instruction\r
+  @param  VmPtr            Pointer to a VM context.\r
+  @param  FuncAddr         Callee's address\r
+  @param  NewStackPointer  New stack pointer after the call\r
+  @param  FramePtr         New frame pointer after the call\r
+  @param  Size             The size of call instruction\r
 \r
-Returns:\r
-\r
-  None.\r
-  \r
---*/\r
+**/\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
+  )\r
 {\r
   UINTN    IsThunk;\r
   UINTN    TargetEbcAddr;\r
@@ -847,23 +857,23 @@ Action:
     // 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->R[0] -= 8;\r
-    VmWriteMemN (VmPtr, (UINTN) VmPtr->R[0], (UINTN) FramePtr);\r
-    VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->R[0];\r
-    VmPtr->R[0] -= 8;\r
-    VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[0], (UINT64) (VmPtr->Ip + Size));\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) (VmPtr->Ip + Size));\r
 \r
     VmPtr->Ip = (VMIP) (UINTN) TargetEbcAddr;\r
   } else {\r
     //\r
-    // The callee is not a thunk to EBC, call native code.\r
+    // The callee is not a thunk to EBC, call native code,\r
+    // and get return value.\r
     //\r
-    EbcLLCALLEXNative (FuncAddr, NewStackPointer, FramePtr);\r
+    VmPtr->Gpr[7] = EbcLLCALLEXNative (FuncAddr, NewStackPointer, FramePtr);\r
 \r
     //\r
-    // Get return value and advance the IP.\r
+    // Advance the IP.\r
     //\r
-    VmPtr->R[7] = EbcLLGetReturnValue ();\r
     VmPtr->Ip += Size;\r
   }\r
 }\r