]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/EbcInt.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcInt.c
index 9357dcd26e936200720f8a4169dea3d82ae6b66d..727ba8bcae44d65da091493ed05fcf0d37041a96 100644 (file)
@@ -3,7 +3,7 @@
   Provides auxiliary support routines for the VM. That is, routines\r
   that are not particularly related to VM execution of EBC instructions.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
@@ -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
@@ -191,6 +192,7 @@ InitEbcVmTestProtocol (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EbcVmTestUnsupported (\r
   VOID\r
   );\r
@@ -336,7 +338,6 @@ EBC_ICACHE_FLUSH       mEbcICacheFlush;
 //\r
 EFI_PERIODIC_CALLBACK  mDebugPeriodicCallback = NULL;\r
 EFI_EXCEPTION_CALLBACK mDebugExceptionCallback[MAX_EBC_EXCEPTION + 1] = {NULL};\r
-EFI_GUID               mEfiEbcVmTestProtocolGuid = EFI_EBC_VM_TEST_PROTOCOL_GUID;\r
 \r
 VOID                   *mStackBuffer[MAX_STACK_NUM];\r
 EFI_HANDLE             mStackBufferIndex[MAX_STACK_NUM];\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
@@ -747,7 +750,7 @@ EbcDebugSignalException (
   // Save the exception in the context passed in\r
   //\r
   VmPtr->ExceptionFlags |= ExceptionFlags;\r
-  VmPtr->LastException = ExceptionType;\r
+  VmPtr->LastException = (UINTN) ExceptionType;\r
   //\r
   // If it's a fatal exception, then flag it in the VM context in case an\r
   // attached debugger tries to return from it.\r
@@ -767,14 +770,14 @@ EbcDebugSignalException (
     //\r
     // Initialize the context structure\r
     //\r
-    EbcContext.R0                   = VmPtr->Gpr[0];\r
-    EbcContext.R1                   = VmPtr->Gpr[1];\r
-    EbcContext.R2                   = VmPtr->Gpr[2];\r
-    EbcContext.R3                   = VmPtr->Gpr[3];\r
-    EbcContext.R4                   = VmPtr->Gpr[4];\r
-    EbcContext.R5                   = VmPtr->Gpr[5];\r
-    EbcContext.R6                   = VmPtr->Gpr[6];\r
-    EbcContext.R7                   = VmPtr->Gpr[7];\r
+    EbcContext.R0                   = (UINT64) VmPtr->Gpr[0];\r
+    EbcContext.R1                   = (UINT64) VmPtr->Gpr[1];\r
+    EbcContext.R2                   = (UINT64) VmPtr->Gpr[2];\r
+    EbcContext.R3                   = (UINT64) VmPtr->Gpr[3];\r
+    EbcContext.R4                   = (UINT64) VmPtr->Gpr[4];\r
+    EbcContext.R5                   = (UINT64) VmPtr->Gpr[5];\r
+    EbcContext.R6                   = (UINT64) VmPtr->Gpr[6];\r
+    EbcContext.R7                   = (UINT64) VmPtr->Gpr[7];\r
     EbcContext.Ip                   = (UINT64)(UINTN)VmPtr->Ip;\r
     EbcContext.Flags                = VmPtr->Flags;\r
     EbcContext.ControlFlags         = 0;\r
@@ -874,10 +877,63 @@ CommonEbcExceptionHandler (
   IN EFI_SYSTEM_CONTEXT   SystemContext\r
   )\r
 {\r
+  //\r
+  // We print debug information to let user know what happen.\r
+  //\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "EBC Interrupter Version - 0x%016lx\n",\r
+    (UINT64) (((VM_MAJOR_VERSION & 0xFFFF) << 16) | ((VM_MINOR_VERSION & 0xFFFF)))\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "Exception Type - 0x%016lx\n",\r
+    (UINT64)(UINTN)InterruptType\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  R0 - 0x%016lx, R1 - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->R0,\r
+    SystemContext.SystemContextEbc->R1\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  R2 - 0x%016lx, R3 - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->R2,\r
+    SystemContext.SystemContextEbc->R3\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  R4 - 0x%016lx, R5 - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->R4,\r
+    SystemContext.SystemContextEbc->R5\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  R6 - 0x%016lx, R7 - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->R6,\r
+    SystemContext.SystemContextEbc->R7\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  Flags - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->Flags\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  ControlFlags - 0x%016lx\n",\r
+    SystemContext.SystemContextEbc->ControlFlags\r
+    ));\r
+  DEBUG ((\r
+    EFI_D_ERROR,\r
+    "  Ip - 0x%016lx\n\n",\r
+    SystemContext.SystemContextEbc->Ip\r
+    ));\r
+\r
   //\r
   // We deadloop here to make it easy to debug this issue.\r
   //\r
-  ASSERT (FALSE);\r
+  CpuDeadLoop ();\r
 \r
   return ;\r
 }\r
@@ -937,14 +993,14 @@ EbcDebugPeriodic (
     //\r
     // Initialize the context structure\r
     //\r
-    EbcContext.R0                   = VmPtr->Gpr[0];\r
-    EbcContext.R1                   = VmPtr->Gpr[1];\r
-    EbcContext.R2                   = VmPtr->Gpr[2];\r
-    EbcContext.R3                   = VmPtr->Gpr[3];\r
-    EbcContext.R4                   = VmPtr->Gpr[4];\r
-    EbcContext.R5                   = VmPtr->Gpr[5];\r
-    EbcContext.R6                   = VmPtr->Gpr[6];\r
-    EbcContext.R7                   = VmPtr->Gpr[7];\r
+    EbcContext.R0                   = (UINT64) VmPtr->Gpr[0];\r
+    EbcContext.R1                   = (UINT64) VmPtr->Gpr[1];\r
+    EbcContext.R2                   = (UINT64) VmPtr->Gpr[2];\r
+    EbcContext.R3                   = (UINT64) VmPtr->Gpr[3];\r
+    EbcContext.R4                   = (UINT64) VmPtr->Gpr[4];\r
+    EbcContext.R5                   = (UINT64) VmPtr->Gpr[5];\r
+    EbcContext.R6                   = (UINT64) VmPtr->Gpr[6];\r
+    EbcContext.R7                   = (UINT64) VmPtr->Gpr[7];\r
     EbcContext.Ip                   = (UINT64)(UINTN)VmPtr->Ip;\r
     EbcContext.Flags                = VmPtr->Flags;\r
     EbcContext.ControlFlags         = 0;\r
@@ -1041,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
@@ -1328,7 +1387,7 @@ InitEbcVmTestProtocol (
   // Publish the protocol\r
   //\r
   Handle  = NULL;\r
-  Status  = gBS->InstallProtocolInterface (&Handle, &mEfiEbcVmTestProtocolGuid, EFI_NATIVE_INTERFACE, EbcVmTestProtocol);\r
+  Status  = gBS->InstallProtocolInterface (&Handle, &gEfiEbcVmTestProtocolGuid, EFI_NATIVE_INTERFACE, EbcVmTestProtocol);\r
   if (EFI_ERROR (Status)) {\r
     FreePool (EbcVmTestProtocol);\r
   }\r
@@ -1343,6 +1402,7 @@ InitEbcVmTestProtocol (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EbcVmTestUnsupported (\r
   VOID\r
   )\r
@@ -1350,3 +1410,26 @@ EbcVmTestUnsupported (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+/**\r
+  Allocates a buffer of type EfiBootServicesCode.\r
+\r
+  @param  AllocationSize        The number of bytes to allocate.\r
+\r
+  @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+EbcAllocatePoolForThunk (\r
+  IN UINTN  AllocationSize\r
+  )\r
+{\r
+  VOID        *Buffer;\r
+  EFI_STATUS  Status;\r
+\r
+  Status = gBS->AllocatePool (EfiBootServicesCode, AllocationSize, &Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+  return Buffer;\r
+}\r