]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/EbcExecute.c
MdeModulePkg/EbcDxe: prepare support for EBC Debugger
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcExecute.c
index 07e2f0a9f7fcdf0ca7038a2f07bf388068359c53..a4c51e9b0f614c73a16f2fdbaa75a876ad5ac822 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Contains code that implements the virtual machine.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -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
@@ -1827,6 +1833,7 @@ ExecuteBREAK (
   UINT64      U64EbcEntryPoint;\r
   INT32       Offset;\r
 \r
+  Thunk = NULL;\r
   Operands = GETOPERANDS (VmPtr);\r
   switch (Operands) {\r
   //\r
@@ -1975,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
@@ -2014,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
@@ -2064,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
@@ -2084,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
@@ -2128,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
@@ -2140,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
@@ -2546,9 +2567,9 @@ ExecuteMOVsnw (
   //\r
   // Get the data from the source.\r
   //\r
-  Op2 = (UINT64) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
+  Op2 = (UINT64)(INT64)(INTN)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
   if (OPERAND2_INDIRECT (Operands)) {\r
-    Op2 = (UINT64) VmReadMemN (VmPtr, (UINTN) Op2);\r
+    Op2 = (UINT64)(INT64)(INTN)VmReadMemN (VmPtr, (UINTN) Op2);\r
   }\r
   //\r
   // Now write back the result.\r
@@ -2639,9 +2660,9 @@ ExecuteMOVsnd (
   //\r
   // Get the data from the source.\r
   //\r
-  Op2 = (UINT64) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
+  Op2 = (UINT64)(INT64)(INTN)(INT64)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
   if (OPERAND2_INDIRECT (Operands)) {\r
-    Op2 = (UINT64) VmReadMemN (VmPtr, (UINTN) Op2);\r
+    Op2 = (UINT64)(INT64)(INTN)(INT64)VmReadMemN (VmPtr, (UINTN) Op2);\r
   }\r
   //\r
   // Now write back the result.\r
@@ -2965,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
@@ -3066,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
@@ -3086,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
@@ -3113,6 +3150,9 @@ ExecuteRET (
     VmPtr->Gpr[0] += 8;\r
   }\r
 \r
+\r
+  EbcDebuggerHookRETEnd (VmPtr);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -3268,7 +3308,7 @@ ExecuteCMP (
   if (Flag != 0) {\r
     VMFLAG_SET (VmPtr, VMFLAGS_CC);\r
   } else {\r
-    VMFLAG_CLEAR (VmPtr, VMFLAGS_CC);\r
+    VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC);\r
   }\r
   //\r
   // Advance the IP\r
@@ -3447,7 +3487,7 @@ ExecuteCMPI (
   if (Flag != 0) {\r
     VMFLAG_SET (VmPtr, VMFLAGS_CC);\r
   } else {\r
-    VMFLAG_CLEAR (VmPtr, VMFLAGS_CC);\r
+    VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC);\r
   }\r
   //\r
   // Advance the IP\r
@@ -4215,7 +4255,7 @@ ExecuteDataManip (
   //\r
   DataManipDispatchTableIndex = (Opcode & OPCODE_M_OPCODE) - OPCODE_NOT;\r
   if ((DataManipDispatchTableIndex < 0) ||\r
-      (DataManipDispatchTableIndex >= sizeof (mDataManipDispatchTable) / sizeof (mDataManipDispatchTable[0]))) {\r
+      (DataManipDispatchTableIndex >= ARRAY_SIZE (mDataManipDispatchTable))) {\r
     EbcDebugSignalException (\r
       EXCEPT_EBC_INVALID_OPCODE,\r
       EXCEPTION_FLAG_ERROR,\r