]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c
Improve coding style in MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / Ia32 / EbcSupport.c
index 1d008ac7822bc3510c9f21b422a4545df2e371e2..d88b762ec25c84509faa471d21c0c86aa1b65754 100644 (file)
@@ -2,7 +2,7 @@
   This module contains EBC support routines that are customized based on\r
   the target processor.\r
 \r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2010, Intel Corporation. <BR>\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
@@ -36,13 +36,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   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
-  @parm VmPtr              Pointer to a VM context.\r
-  @parm FuncAddr           Callee's address\r
-  @parm NewStackPointer    New stack pointer after the call\r
-  @parm FramePtr           New frame pointer after the call\r
-  @parm Size               The size of call instruction\r
-\r
-  @return None.\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
 **/\r
 VOID\r
@@ -110,11 +108,11 @@ 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) (UINTN) (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) (UINTN) (VmPtr->Ip + Size));\r
 \r
     VmPtr->Ip = (VMIP) (UINTN) TargetEbcAddr;\r
   } else {\r
@@ -126,7 +124,7 @@ Action:
     //\r
     // Get return value and advance the IP.\r
     //\r
-    VmPtr->R[7] = EbcLLGetReturnValue ();\r
+    VmPtr->Gpr[7] = EbcLLGetReturnValue ();\r
     VmPtr->Ip += Size;\r
   }\r
 }\r
@@ -137,14 +135,30 @@ Action:
   in via a processor register, so we'll need to make a call to get the\r
   value.\r
 \r
-  None. Since we're called from a fixed up thunk (which we want to keep\r
-  small), our only so-called argument is the EBC entry point passed in\r
-  to us in a processor register.\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  Arg2                  The 2nd argument.\r
+  @param  Arg3                  The 3rd argument.\r
+  @param  Arg4                  The 4th argument.\r
+  @param  Arg5                  The 5th argument.\r
+  @param  Arg6                  The 6th argument.\r
+  @param  Arg7                  The 7th argument.\r
+  @param  Arg8                  The 8th argument.\r
+  @param  Arg9                  The 9th argument.\r
+  @param  Arg10                 The 10th argument.\r
+  @param  Arg11                 The 11th argument.\r
+  @param  Arg12                 The 12th argument.\r
+  @param  Arg13                 The 13th argument.\r
+  @param  Arg14                 The 14th argument.\r
+  @param  Arg15                 The 15th argument.\r
+  @param  Arg16                 The 16th argument.\r
 \r
   @return The value returned by the EBC application we're going to run.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 EbcInterpret (\r
   IN OUT UINTN      Arg1,\r
@@ -204,55 +218,55 @@ EbcInterpret (
     return Status;\r
   }\r
   VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
-  VmContext.R[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
-  VmContext.HighStackBottom = (UINTN)VmContext.R[0];\r
-  VmContext.R[0] &= ~(sizeof (UINTN) - 1);\r
-  VmContext.R[0] -= sizeof (UINTN);\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) - 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.R[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
-  VmContext.StackMagicPtr             = (UINTN *) (UINTN) VmContext.R[0];\r
-  VmContext.LowStackTop   = (UINTN) VmContext.R[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.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg16;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg15;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg14;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg13;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg12;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg11;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg10;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg9;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg8;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg7;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg6;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg5;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg4;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg3;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg2;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) Arg1;\r
-  VmContext.R[0] -= 16;\r
-  VmContext.StackRetAddr  = (UINT64) VmContext.R[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
@@ -277,7 +291,7 @@ 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
 \r
@@ -286,13 +300,13 @@ EbcInterpret (
   in via a processor register, so we'll need to make a call to get the\r
   value.\r
 \r
-  @param  ImageHandle    image handle for the EBC application we're executing\r
-  @param  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
   @return The value returned by the EBC application we're going to run.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEbcImageEntryPoint (\r
   IN EFI_HANDLE           ImageHandle,\r
@@ -346,28 +360,28 @@ ExecuteEbcImageEntryPoint (
     return Status;\r
   }\r
   VmContext.StackTop = (UINT8*)VmContext.StackPool + (STACK_REMAIN_SIZE);\r
-  VmContext.R[0] = (UINT64)(UINTN) ((UINT8*)VmContext.StackPool + STACK_POOL_SIZE);\r
-  VmContext.HighStackBottom = (UINTN)VmContext.R[0];\r
-  VmContext.R[0] -= sizeof (UINTN);\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
 \r
   //\r
   // Put a magic value in the stack gap, then adjust down again\r
   //\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) VM_STACK_KEY_VALUE;\r
-  VmContext.StackMagicPtr             = (UINTN *) (UINTN) VmContext.R[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.R[0] &= ~(sizeof(UINTN) - 1);\r
+  //  VmContext.Gpr[0] &= ~(sizeof(UINTN) - 1);\r
   //\r
-  VmContext.LowStackTop   = (UINTN) VmContext.R[0];\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[0]) = (UINTN) SystemTable;\r
-  VmContext.R[0] -= sizeof (UINTN);\r
-  *(UINTN *) (UINTN) (VmContext.R[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.R[0] -= 16;\r
-  VmContext.StackRetAddr  = (UINT64) VmContext.R[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
@@ -380,18 +394,25 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Return the value in R[7] unless there was an error\r
   //\r
-  return (UINT64) VmContext.R[7];\r
+  return (UINT64) VmContext.Gpr[7];\r
 }\r
 \r
 \r
 /**\r
-  Create an IA32 thunk for the given EBC entry point.\r
+  Create thunks for an EBC image entry point, or an EBC protocol service.\r
 \r
-  @param  ImageHandle    Handle of image for which this thunk is being created\r
-  @param  EbcEntryPoint  Address of the EBC code that the thunk is to call\r
-  @param  Thunk          Returned thunk we create here\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
-  @return Standard EFI status.\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
@@ -404,7 +425,7 @@ EbcCreateThunks (
 {\r
   UINT8       *Ptr;\r
   UINT8       *ThunkBase;\r
-  UINT32      I;\r
+  UINT32      Index;\r
   UINT32      Addr;\r
   INT32       Size;\r
   INT32       ThunkSize;\r
@@ -444,7 +465,7 @@ EbcCreateThunks (
   Ptr++;\r
   Size--;\r
   Addr = (UINT32) 0xCA112EBC;\r
-  for (I = 0; I < sizeof (Addr); I++) {\r
+  for (Index = 0; Index < sizeof (Addr); Index++) {\r
     *Ptr = (UINT8) (UINTN) Addr;\r
     Addr >>= 8;\r
     Ptr++;\r
@@ -461,7 +482,7 @@ EbcCreateThunks (
   Ptr++;\r
   Size--;\r
   Addr = (UINT32) EbcEntryPoint;\r
-  for (I = 0; I < sizeof (Addr); I++) {\r
+  for (Index = 0; Index < sizeof (Addr); Index++) {\r
     *Ptr = (UINT8) (UINTN) Addr;\r
     Addr >>= 8;\r
     Ptr++;\r
@@ -471,7 +492,7 @@ EbcCreateThunks (
   // Stick in a load of ecx with the address of appropriate VM function.\r
   //  mov ecx 12345678h  => 0xB9 0x78 0x56 0x34 0x12\r
   //\r
-  if (Flags & FLAG_THUNK_ENTRY_POINT) {\r
+  if ((Flags & FLAG_THUNK_ENTRY_POINT) != 0) {\r
     Addr = (UINT32) (UINTN) ExecuteEbcImageEntryPoint;\r
   } else {\r
     Addr = (UINT32) (UINTN) EbcInterpret;\r
@@ -483,7 +504,7 @@ EbcCreateThunks (
   *Ptr = 0xB9;\r
   Ptr++;\r
   Size--;\r
-  for (I = 0; I < sizeof (Addr); I++) {\r
+  for (Index = 0; Index < sizeof (Addr); Index++) {\r
     *Ptr = (UINT8) Addr;\r
     Addr >>= 8;\r
     Ptr++;\r