]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/EbcInt.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcInt.c
index d75d91a727a2d2d06888caed77562f53efbdcd08..a511e938e95bd3b9705c84f4898593cb812d99d0 100644 (file)
@@ -3,19 +3,14 @@
   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. <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
-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
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \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 +186,7 @@ InitEbcVmTestProtocol (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EbcVmTestUnsupported (\r
   VOID\r
   );\r
@@ -336,7 +332,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 +492,8 @@ InitializeEbcDriver (
     InitEbcVmTestProtocol (&ImageHandle);\r
   DEBUG_CODE_END ();\r
 \r
+  EbcDebuggerHookInit (ImageHandle, EbcDebugProtocol);\r
+\r
   return EFI_SUCCESS;\r
 \r
 ErrorExit:\r
@@ -747,7 +744,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 +764,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 +871,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 +987,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 +1091,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 +1381,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 +1396,7 @@ InitEbcVmTestProtocol (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EbcVmTestUnsupported (\r
   VOID\r
   )\r
@@ -1350,3 +1404,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