]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/EbcDxe: prepare support for EBC Debugger
authorPete Batard <pete@akeo.ie>
Wed, 16 Nov 2016 13:24:08 +0000 (21:24 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Wed, 23 Nov 2016 02:20:25 +0000 (10:20 +0800)
* This patch introduces EbcDebuggerHook.c/h and inserts the required
  EBCDebugger references into the existing EBC source files.
* With all the hooks defined to their empty version in EbcDebuggerHook.c
  the existing EBC VM behaviour is left unaffected.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c
MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
MdeModulePkg/Universal/EbcDxe/EbcExecute.c
MdeModulePkg/Universal/EbcDxe/EbcInt.c
MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c
MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c
MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c

index c5cc76d7bdcb8bdad9203c4c6a800f4040cc12dd..ade47c4d0622148d77df63a3de9b89583faa41ae 100644 (file)
@@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 //\r
 // Amount of space that is not used in the stack\r
@@ -225,6 +226,7 @@ EbcInterpret (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookEbcInterpret (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
@@ -336,6 +338,7 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.c b/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.c
new file mode 100644 (file)
index 0000000..88a43f2
--- /dev/null
@@ -0,0 +1,158 @@
+/** @file\r
+  Contains the empty version of the EBC Debugger hooks, to be used when\r
+  compiling the regular EBC VM module.\r
+  As debugging is not needed for the standard EBC VM, all calls are left empty.\r
+\r
+  The EBC Debugger defines its own version for these calls in EbdHooks.c.\r
+\r
+  Copyright (c) 2006 - 2016, 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 <Uefi.h>\r
+#include <Protocol/DebugSupport.h>\r
+#include <Protocol/EbcVmTest.h>\r
+\r
+VOID\r
+EbcDebuggerHookInit (\r
+  IN EFI_HANDLE                  Handle,\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL  *EbcDebugProtocol\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookUnload (\r
+  VOID\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookEbcUnloadImage (\r
+  IN EFI_HANDLE                  Handle\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteEbcImageEntryPoint (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookEbcInterpret (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookRETStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookRETEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMPStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMPEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMP8Start (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMP8End (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+{\r
+  return;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h b/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h
new file mode 100644 (file)
index 0000000..f4dd5cf
--- /dev/null
@@ -0,0 +1,113 @@
+/** @file\r
+  Prototypes for the EBC Debugger hooks.\r
+\r
+  Copyright (c) 2006 - 2016, 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
+#ifndef _EFI_EBC_DEBUGGER_HOOK_H_\r
+#define _EFI_EBC_DEBUGGER_HOOK_H_\r
+\r
+//\r
+// Hooks in EbcInt.c\r
+//\r
+VOID\r
+EbcDebuggerHookInit (\r
+  IN EFI_HANDLE                  Handle,\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL  *EbcDebugProtocol\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookUnload (\r
+  VOID\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookEbcUnloadImage (\r
+  IN EFI_HANDLE                  Handle\r
+  );\r
+\r
+//\r
+// Hooks in EbcSupport.c\r
+//\r
+VOID\r
+EbcDebuggerHookExecuteEbcImageEntryPoint (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookEbcInterpret (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+//\r
+// Hooks in EbcExecute.c\r
+//\r
+VOID\r
+EbcDebuggerHookExecuteStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookExecuteEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookCALLStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookCALLEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookRETStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookRETEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookJMPStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookJMPEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookJMP8Start (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+VOID\r
+EbcDebuggerHookJMP8End (\r
+  IN VM_CONTEXT *VmPtr\r
+  );\r
+\r
+#endif\r
index e9a0b28c40747bded5711ff486b3ab1683c46847..d11888e25f920085954a13523abee80d429d555f 100644 (file)
@@ -33,6 +33,8 @@
 #\r
 \r
 [Sources]\r
+  EbcDebuggerHook.h\r
+  EbcDebuggerHook.c\r
   EbcExecute.h\r
   EbcExecute.c\r
   EbcInt.h\r
@@ -88,4 +90,4 @@
 # EVENT_TYPE_PERIODIC_TIMER ## CONSUMES\r
 \r
 [UserExtensions.TianoCore."ExtraFiles"]\r
-  EbcDxeExtra.uni
\ No newline at end of file
+  EbcDxeExtra.uni\r
index d9c17f48a0388cffb8ff507c1def29ff1bf815ed..a4c51e9b0f614c73a16f2fdbaa75a876ad5ac822 100644 (file)
@@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 \r
 //\r
@@ -1488,6 +1489,9 @@ EbcExecute (
       Status = EFI_UNSUPPORTED;\r
       goto Done;\r
     }\r
+\r
+    EbcDebuggerHookExecuteStart (VmPtr);\r
+\r
     //\r
     // The EBC VM is a strongly ordered processor, so perform a fence operation before\r
     // and after each instruction is executed.\r
@@ -1498,6 +1502,8 @@ EbcExecute (
 \r
     MemoryFence ();\r
 \r
+    EbcDebuggerHookExecuteEnd (VmPtr);\r
+\r
     //\r
     // If the step flag is set, signal an exception and continue. We don't\r
     // clear it here. Assuming the debugger is responsible for clearing it.\r
@@ -1976,7 +1982,9 @@ ExecuteJMP (
   ConditionFlag = (UINT8) VMFLAG_ISSET (VmPtr, VMFLAGS_CC);\r
   if ((Operand & CONDITION_M_CONDITIONAL) != 0) {\r
     if (CompareSet != ConditionFlag) {\r
+      EbcDebuggerHookJMPStart (VmPtr);\r
       VmPtr->Ip += Size;\r
+      EbcDebuggerHookJMPEnd (VmPtr);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -2015,11 +2023,13 @@ ExecuteJMP (
     //\r
     // Take jump -- relative or absolute\r
     //\r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Data64 + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) (UINTN) Data64;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
 \r
     return EFI_SUCCESS;\r
   }\r
@@ -2065,11 +2075,14 @@ ExecuteJMP (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Addr + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) Addr;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
+\r
   } else {\r
     //\r
     // Form: JMP32 Rx {Immed32}\r
@@ -2085,11 +2098,14 @@ ExecuteJMP (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Addr + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) Addr;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
+\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2129,7 +2145,9 @@ ExecuteJMP8 (
   //\r
   if ((Opcode & CONDITION_M_CONDITIONAL) != 0) {\r
     if (CompareSet != ConditionFlag) {\r
+      EbcDebuggerHookJMP8Start (VmPtr);\r
       VmPtr->Ip += 2;\r
+      EbcDebuggerHookJMP8End (VmPtr);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -2141,7 +2159,9 @@ ExecuteJMP8 (
   //\r
   // Want to check for offset == -2 and then raise an exception?\r
   //\r
+  EbcDebuggerHookJMP8Start (VmPtr);\r
   VmPtr->Ip += (Offset * 2) + 2;\r
+  EbcDebuggerHookJMP8End (VmPtr);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2966,6 +2986,13 @@ ExecuteCALL (
   //\r
   Opcode    = GETOPCODE (VmPtr);\r
   Operands  = GETOPERANDS (VmPtr);\r
+\r
+  if (Operands & OPERAND_M_NATIVE_CALL) {\r
+    EbcDebuggerHookCALLEXStart (VmPtr);\r
+  } else {\r
+    EbcDebuggerHookCALLStart (VmPtr);\r
+  }\r
+\r
   //\r
   // Assign these as well to avoid compiler warnings\r
   //\r
@@ -3067,6 +3094,12 @@ ExecuteCALL (
     }\r
   }\r
 \r
+  if (Operands & OPERAND_M_NATIVE_CALL) {\r
+    EbcDebuggerHookCALLEXEnd (VmPtr);\r
+  } else {\r
+    EbcDebuggerHookCALLEnd (VmPtr);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -3087,6 +3120,9 @@ ExecuteRET (
   IN VM_CONTEXT *VmPtr\r
   )\r
 {\r
+\r
+  EbcDebuggerHookRETStart (VmPtr);\r
+\r
   //\r
   // If we're at the top of the stack, then simply set the done\r
   // flag and return\r
@@ -3114,6 +3150,9 @@ ExecuteRET (
     VmPtr->Gpr[0] += 8;\r
   }\r
 \r
+\r
+  EbcDebuggerHookRETEnd (VmPtr);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index 549e0dd8dc1c9c1395ef253f56d18a393d7abb37..6fd2aaf5af276fdc469caf8a775fd3dc0c190663 100644 (file)
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 //\r
 // We'll keep track of all thunks we create in a linked list. Each\r
@@ -497,6 +498,8 @@ InitializeEbcDriver (
     InitEbcVmTestProtocol (&ImageHandle);\r
   DEBUG_CODE_END ();\r
 \r
+  EbcDebuggerHookInit (ImageHandle, EbcDebugProtocol);\r
+\r
   return EFI_SUCCESS;\r
 \r
 ErrorExit:\r
@@ -1094,6 +1097,9 @@ EbcUnloadImage (
   // Now free up the image list element\r
   //\r
   FreePool (ImageList);\r
+\r
+  EbcDebuggerHookEbcUnloadImage (ImageHandle);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index bddfbf630d7303353f834f456c373bea03b9f999..8e660b93ad640e42af23ec4dec0b3c01590c0be3 100644 (file)
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 //\r
 // NOTE: This is the stack size allocated for the interpreter\r
@@ -332,10 +333,11 @@ EbcInterpret (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookEbcInterpret (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r
@@ -432,10 +434,11 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r
index 23b6c1bd84724cd6dd3f2dd9aa4b6d7ff0c49408..95837cb678658811ae913a1098e286dd19f7ffcf 100644 (file)
@@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
 #include "EbcSupport.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 /**\r
   Given raw bytes of Itanium based code, format them into a bundle and\r
@@ -214,12 +215,15 @@ EbcInterpret (
   PushU64 (&VmContext, 0);\r
   PushU64 (&VmContext, 0xDEADBEEFDEADBEEF);\r
   VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0];\r
+\r
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookEbcInterpret (&VmContext);\r
   EbcExecute (&VmContext);\r
+\r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r
@@ -334,10 +338,11 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r
index bdde5e41fad80d7f7730d85638013f0872d6f2b3..4325e2e52710ea3aeeb9f9c95bcea8dcb3cff056 100644 (file)
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 //\r
 // NOTE: This is the stack size allocated for the interpreter\r
@@ -278,10 +279,11 @@ EbcInterpret (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookEbcInterpret (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r
@@ -389,10 +391,11 @@ ExecuteEbcImageEntryPoint (
   //\r
   // Begin executing the EBC code\r
   //\r
+  EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext);\r
   EbcExecute (&VmContext);\r
 \r
   //\r
-  // Return the value in R[7] unless there was an error\r
+  // Return the value in Gpr[7] unless there was an error\r
   //\r
   ReturnEBCStack(StackIndex);\r
   return (UINT64) VmContext.Gpr[7];\r