]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/Ebc/Dxe/x64/EbcSupport.c
1. Advance IP in case of Break(3) in breakpoint exception
[mirror_edk2.git] / EdkModulePkg / Universal / Ebc / Dxe / x64 / EbcSupport.c
index cad5c6a43bf27df296115631420d3c0511c6ae45..bec82d67c519fd8cdd9fef0ec346cf029386b2a1 100644 (file)
@@ -32,6 +32,8 @@ Abstract:
 #define VM_STACK_SIZE   (1024 * 8)\r
 #define EBC_THUNK_SIZE  64\r
 \r
+#define STACK_REMAIN_SIZE (1024 * 4)\r
+\r
 STATIC\r
 VOID\r
 PushU64 (\r
@@ -71,7 +73,18 @@ EbcInterpret (
   UINTN      Arg2,\r
   UINTN      Arg3,\r
   UINTN      Arg4,\r
-  UINTN      Arg5\r
+  UINTN      Arg5,\r
+  UINTN      Arg6,\r
+  UINTN      Arg7,\r
+  UINTN      Arg8,\r
+  UINTN      Arg9,\r
+  UINTN      Arg10,\r
+  UINTN      Arg11,\r
+  UINTN      Arg12,\r
+  UINTN      Arg13,\r
+  UINTN      Arg14,\r
+  UINTN      Arg15,\r
+  UINTN      Arg16\r
   )\r
 /*++\r
 \r
@@ -98,6 +111,8 @@ Returns:
   //\r
   VM_CONTEXT  VmContext;\r
   UINTN       Addr;\r
+  EFI_STATUS  Status;\r
+  UINTN       StackIndex;\r
 \r
   //\r
   // Get the EBC entry point from the processor register.\r
@@ -125,8 +140,15 @@ Returns:
   //\r
   // Adjust the VM's stack pointer down.\r
   //\r
-  VmContext.R[0]  = (UINT64) Addr;\r
-  VmContext.R[0] -= VM_STACK_SIZE;\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
 \r
   //\r
   // Align the stack on a natural boundary.\r
@@ -148,6 +170,18 @@ Returns:
   // For the worst case, assume there are 4 arguments passed in registers, store\r
   // them to VM's stack.\r
   //\r
+  PushU64 (&VmContext, (UINT64) Arg16);\r
+  PushU64 (&VmContext, (UINT64) Arg15);\r
+  PushU64 (&VmContext, (UINT64) Arg14);\r
+  PushU64 (&VmContext, (UINT64) Arg13);\r
+  PushU64 (&VmContext, (UINT64) Arg12);\r
+  PushU64 (&VmContext, (UINT64) Arg11);\r
+  PushU64 (&VmContext, (UINT64) Arg10);\r
+  PushU64 (&VmContext, (UINT64) Arg9);\r
+  PushU64 (&VmContext, (UINT64) Arg8);\r
+  PushU64 (&VmContext, (UINT64) Arg7);\r
+  PushU64 (&VmContext, (UINT64) Arg6);\r
+  PushU64 (&VmContext, (UINT64) Arg5);\r
   PushU64 (&VmContext, (UINT64) Arg4);\r
   PushU64 (&VmContext, (UINT64) Arg3);\r
   PushU64 (&VmContext, (UINT64) Arg2);\r
@@ -178,7 +212,6 @@ Returns:
   // the stack too, so adjust accordingly.\r
   //  VmContext.HighStackBottom = (UINTN)(Addr + sizeof (VmContext) + sizeof (Addr));\r
   //\r
-  VmContext.HighStackBottom = (UINTN) &Arg5;\r
 \r
   //\r
   // Begin executing the EBC code\r
@@ -188,6 +221,7 @@ Returns:
   //\r
   // Return the value in R[7] unless there was an error\r
   //\r
+  ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.R[7];\r
 }\r
 \r
@@ -221,6 +255,8 @@ Returns:
   //\r
   VM_CONTEXT  VmContext;\r
   UINTN       Addr;\r
+  EFI_STATUS  Status;\r
+  UINTN       StackIndex;\r
 \r
   //\r
   // Get the EBC entry point from the processor register. Make sure you don't\r
@@ -250,8 +286,16 @@ Returns:
   // pointer and adjust it down by the max needed for the interpreter.\r
   //\r
   Addr            = EbcLLGetStackPointer ();\r
-  VmContext.R[0]  = (UINT64) Addr;\r
-  VmContext.R[0] -= VM_STACK_SIZE;\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
+\r
 \r
   //\r
   // Put a magic value in the stack gap, then adjust down again\r
@@ -287,7 +331,6 @@ Returns:
   // Entry function needn't access high stack context, simply\r
   // put the stack pointer here.\r
   //\r
-  VmContext.HighStackBottom = (UINTN) Addr;\r
 \r
   //\r
   // Begin executing the EBC code\r
@@ -297,6 +340,7 @@ Returns:
   //\r
   // Return the value in R[7] unless there was an error\r
   //\r
+  ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.R[7];\r
 }\r
 \r