]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Merger generic functions into one file.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 11 Dec 2008 05:28:12 +0000 (05:28 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 11 Dec 2008 05:28:12 +0000 (05:28 +0000)
2. Use the basic definitions in BaseLib.h, instead of local definitions

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6986 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
MdeModulePkg/Universal/DebugSupportDxe/Ia32/AsmFuncs.asm
MdeModulePkg/Universal/DebugSupportDxe/Ia32/DebugSupport.h [new file with mode: 0644]
MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c
MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.h
MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupportIa32.c [new file with mode: 0644]
MdeModulePkg/Universal/DebugSupportDxe/Ipf/PlDebugSupport.h
MdeModulePkg/Universal/DebugSupportDxe/X64/AsmFuncs.asm
MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupport.c [deleted file]
MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupport.h
MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c [new file with mode: 0644]

index c36ee518b09692632bd5c0efd22f404495a7465c..d303847c75640d3cc12ef471d2b94aaa1e5df5ef 100644 (file)
   DebugSupport.c\r
 \r
 [Sources.Ia32]\r
+  Ia32/DebugSupport.h\r
   Ia32/PlDebugSupport.c\r
   Ia32/PlDebugSupport.h\r
+  Ia32/PlDebugSupportIa32.c\r
   Ia32/AsmFuncs.S\r
   Ia32/AsmFuncs.asm\r
 \r
 [Sources.X64]\r
-  X64/PlDebugSupport.c\r
+  Ia32/DebugSupport.h\r
+  Ia32/PlDebugSupport.c\r
   X64/PlDebugSupport.h\r
+  X64/PlDebugSupportX64.c\r
   X64/AsmFuncs.S\r
   X64/AsmFuncs.asm\r
 \r
index 315120ef9472d6db7f00dab1519115e7fe92b9a9..cc776c867e093fe2ab7fa084bd0276ed343ef3a8 100644 (file)
@@ -132,21 +132,6 @@ FxStorSupport   PROC    C PUBLIC
 FxStorSupport   ENDP\r
 \r
 \r
-;------------------------------------------------------------------------------\r
-; DESCRIPTOR *\r
-; GetIdtr (\r
-;   void\r
-;   )\r
-;\r
-; Abstract: Returns physical address of IDTR\r
-;\r
-GetIdtr         PROC    C PUBLIC\r
-                LOCAL   IdtrBuf:FWORD\r
-\r
-                sidt    IdtrBuf\r
-                mov     eax, DWORD PTR IdtrBuf + 2\r
-                ret\r
-GetIdtr         ENDP\r
 \r
 \r
 ;------------------------------------------------------------------------------\r
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/Ia32/DebugSupport.h b/MdeModulePkg/Universal/DebugSupportDxe/Ia32/DebugSupport.h
new file mode 100644 (file)
index 0000000..7276550
--- /dev/null
@@ -0,0 +1,308 @@
+/** @file\r
+  Generic debug support macros, typedefs and prototypes for IA32/x64.\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation                                                         \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
+\r
+**/\r
+\r
+#ifndef _DEBUG_SUPPORT_H_\r
+#define _DEBUG_SUPPORT_H_\r
+\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/DebugSupport.h>\r
+#include <Protocol/LoadedImage.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+#define NUM_IDT_ENTRIES                 0x78\r
+#define SYSTEM_TIMER_VECTOR             0x68\r
+#define VECTOR_ENTRY_PAGES              1\r
+\r
+#define FF_FXSR                         (1 << 24)\r
+\r
+typedef\r
+VOID\r
+(*DEBUG_PROC) (\r
+  VOID\r
+  );\r
+\r
+typedef struct {\r
+  IA32_IDT_GATE_DESCRIPTOR  OrigDesc;\r
+  DEBUG_PROC                OrigVector;\r
+  IA32_IDT_GATE_DESCRIPTOR  NewDesc;\r
+  DEBUG_PROC                StubEntry;\r
+  VOID (*RegisteredCallback) ();\r
+} IDT_ENTRY;\r
+\r
+extern EFI_SYSTEM_CONTEXT SystemContext;\r
+extern UINT8              InterruptEntryStub[];\r
+extern UINT32             StubSize;\r
+extern VOID              (*OrigVector) (VOID);\r
+extern IDT_ENTRY         *IdtEntryTable;\r
+extern IA32_IDT_GATE_DESCRIPTOR  NullDesc;\r
+\r
+/**\r
+  Generic IDT entry.\r
+\r
+**/\r
+VOID\r
+CommonIdtEntry (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Check whether FXSTOR is supported\r
+\r
+  @retval TRUE   FXSTOR is supported.\r
+  @retval FALSE  FXSTOR is not supported.\r
+\r
+**/\r
+BOOLEAN\r
+FxStorSupport (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Encodes an IDT descriptor with the given physical address.\r
+\r
+  @param  DestDesc    The IDT descriptor address.\r
+  @param  Vecotr      The interrupt vector entry.\r
+\r
+**/\r
+VOID\r
+Vect2Desc (\r
+  IA32_IDT_GATE_DESCRIPTOR * DestDesc,\r
+  VOID (*Vector) (VOID)\r
+  );\r
+\r
+/**\r
+  Programs interrupt flag to the requested state and returns previous\r
+  state.\r
+\r
+  @param  NewState    New interrupt status.\r
+\r
+  @retval TRUE     Old interrupt status is TRUE.\r
+  @retval FALSE    Old interrupt status is FALSE\r
+\r
+**/\r
+BOOLEAN\r
+WriteInterruptFlag (\r
+  BOOLEAN NewState\r
+  );\r
+\r
+/**\r
+  Initializes driver's handler registration databas. \r
+  \r
+  This code executes in boot services context\r
+  Must be public because it's referenced from DebugSupport.c\r
+\r
+  @retval  EFI_UNSUPPORTED      If IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
+                                the context save will fail, so these processor's are not supported.\r
+  @retval  EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
+  @retval  EFI_SUCCESS          Initializes successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+PlInitializeDebugSupportDriver (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  This is the callback that is written to the LoadedImage protocol instance\r
+  on the image handle. It uninstalls all registered handlers and frees all entry\r
+  stub memory.\r
+\r
+  @param  ImageHandle    The firmware allocated handle for the EFI image.\r
+\r
+  @retval EFI_SUCCESS    Always.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PlUnloadDebugSupportDriver (\r
+  IN EFI_HANDLE                       ImageHandle\r
+  );\r
+\r
+/**\r
+  This is a DebugSupport protocol member function, hard\r
+  coded to support only 1 processor for now.\r
+\r
+  @param  This                The DebugSupport instance\r
+  @param  MaxProcessorIndex   The maximuim supported processor index\r
+\r
+  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetMaximumProcessorIndex (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  OUT UINTN                           *MaxProcessorIndex\r
+  );\r
+\r
+/**\r
+  DebugSupport protocol member function.\r
+\r
+  @param  This               The DebugSupport instance\r
+  @param  ProcessorIndex     Which processor the callback applies to.\r
+  @param  PeriodicCallback   Callback function\r
+\r
+  @retval EFI_SUCCESS        Indicates the callback was registered.\r
+  @retval others             Callback was not registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterPeriodicCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN EFI_PERIODIC_CALLBACK            PeriodicCallback\r
+  );\r
+\r
+/**\r
+  DebugSupport protocol member function.\r
+\r
+  This code executes in boot services context.\r
+\r
+  @param  This              The DebugSupport instance\r
+  @param  ProcessorIndex    Which processor the callback applies to.\r
+  @param  NewCallback       Callback function\r
+  @param  ExceptionType     Which exception to hook\r
+\r
+  @retval EFI_SUCCESS        Indicates the callback was registered.\r
+  @retval others             Callback was not registered.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterExceptionCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN EFI_EXCEPTION_CALLBACK           NewCallback,\r
+  IN EFI_EXCEPTION_TYPE               ExceptionType\r
+  );\r
+\r
+/**\r
+  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
+\r
+  @param  This              The DebugSupport instance\r
+  @param  ProcessorIndex    Which processor the callback applies to.\r
+  @param  Start             Physical base of the memory range to be invalidated\r
+  @param  Length            mininum number of bytes in instruction cache to invalidate\r
+\r
+  @retval EFI_SUCCESS       Always returned.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN VOID                             *Start,\r
+  IN UINT64                           Length\r
+  );\r
+\r
+/**\r
+  Allocate pool for a new IDT entry stub.\r
+\r
+  Copy the generic stub into the new buffer and fixup the vector number\r
+  and jump target address.\r
+\r
+  @param  ExceptionType   This is the exception type that the new stub will be created\r
+                          for.\r
+  @param  Stub            On successful exit, *Stub contains the newly allocated entry stub.\r
+\r
+  @retval EFI_SUCCESS     Always.\r
+\r
+**/\r
+EFI_STATUS\r
+CreateEntryStub (\r
+  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
+  OUT VOID                  **Stub\r
+  );\r
+\r
+/**\r
+  Get Procedure Entry Point from IDT Gate Descriptor.\r
+\r
+  @param  IdtGateDecriptor  IDT Gate Descriptor.\r
+\r
+  @return Procedure Entry Point located in IDT Gate Descriptor.\r
+\r
+**/\r
+UINTN GetProcedureEntryPoint (\r
+  IN IA32_IDT_GATE_DESCRIPTOR  *IdtGateDecriptor\r
+  );\r
+\r
+/**\r
+  This is the main worker function that manages the state of the interrupt\r
+  handlers.  It both installs and uninstalls interrupt handlers based on the\r
+  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
+  If NewCallback is non-NULL, then install is indicated.\r
+\r
+  @param  NewCallback   If non-NULL, NewCallback specifies the new handler to register.\r
+                        If NULL, specifies that the previously registered handler should\r
+                        be uninstalled.\r
+  @param  ExceptionType Indicates which entry to manage.\r
+\r
+  @retval EFI_SUCCESS            Process is ok.\r
+  @retval EFI_INVALID_PARAMETER  Requested uninstalling a handler from a vector that has\r
+                                 no handler registered for it\r
+  @retval EFI_ALREADY_STARTED    Requested install to a vector that already has a handler registered.\r
+  @retval others                 Possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+**/\r
+EFI_STATUS\r
+ManageIdtEntryTable (\r
+  VOID (*NewCallback)(),\r
+  EFI_EXCEPTION_TYPE ExceptionType\r
+  );\r
+\r
+/**\r
+  Creates a nes entry stub.  Then saves the current IDT entry and replaces it\r
+  with an interrupt gate for the new entry point.  The IdtEntryTable is updated\r
+  with the new registered function.\r
+\r
+  This code executes in boot services context.  The stub entry executes in interrupt\r
+  context.\r
+\r
+  @param  ExceptionType      Specifies which vector to hook.\r
+  @param  NewCallback        A pointer to the new function to be registered.\r
+\r
+  @retval EFI_SUCCESS        Always.\r
+\r
+**/\r
+EFI_STATUS\r
+HookEntry (\r
+  IN EFI_EXCEPTION_TYPE            ExceptionType,\r
+  IN VOID                         (*NewCallback) ()\r
+  );\r
+\r
+/**\r
+  Undoes HookEntry. This code executes in boot services context.\r
+\r
+  @param  ExceptionType   Specifies which entry to unhook\r
+\r
+  @retval EFI_SUCCESS     Always.\r
+\r
+**/\r
+EFI_STATUS\r
+UnhookEntry (\r
+  IN EFI_EXCEPTION_TYPE           ExceptionType\r
+  );\r
+\r
+#endif\r
index c650e6391fd7fe52a38fa75abc2e5b270f512d81..932e923eaa11bd41e334c7df98da8916402b14c1 100644 (file)
@@ -15,63 +15,56 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 // private header files\r
 //\r
-#include "PlDebugSupport.h"\r
+#include "DebugSupport.h"\r
 \r
 //\r
 // This the global main table to keep track of the interrupts\r
 //\r
 IDT_ENTRY   *IdtEntryTable  = NULL;\r
-DESCRIPTOR  NullDesc        = 0;\r
+IA32_IDT_GATE_DESCRIPTOR  NullDesc        = {0};\r
 \r
 /**\r
-  Allocate pool for a new IDT entry stub.\r
+  Read IDT Gate Descriptor from IDT Table.\r
 \r
-  Copy the generic stub into the new buffer and fixup the vector number\r
-  and jump target address.\r
-\r
-  @param  ExceptionType   This is the exception type that the new stub will be created\r
-                          for.\r
-  @param  Stub            On successful exit, *Stub contains the newly allocated entry stub.\r
-\r
-  @retval EFI_SUCCESS     Always.\r
+  @param  Vector            Specifies vector number.\r
+  @param  IdtGateDecriptor  Pointer to IDT Gate Descriptor read from IDT Table.\r
 \r
 **/\r
-EFI_STATUS\r
-CreateEntryStub (\r
-  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
-  OUT VOID                  **Stub\r
+VOID ReadIdtGateDecriptor (\r
+  IN  EFI_EXCEPTION_TYPE        Vector,\r
+  OUT IA32_IDT_GATE_DESCRIPTOR  *IdtGateDecriptor\r
   )\r
 {\r
-  UINT8       *StubCopy;\r
+ IA32_DESCRIPTOR            IdtrValue;\r
+ IA32_IDT_GATE_DESCRIPTOR   *IdtTable;\r
 \r
-  StubCopy = *Stub;\r
+ AsmReadIdtr (&IdtrValue);\r
+ IdtTable = (IA32_IDT_GATE_DESCRIPTOR *) IdtrValue.Base;\r
 \r
-  //\r
-  // Fixup the stub code for this vector\r
-  //\r
+ CopyMem ((VOID *) IdtGateDecriptor, (VOID *) &(IdtTable)[Vector], sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
+}\r
+/**\r
+  Write IDT Gate Descriptor into IDT Table.\r
 \r
-  // The stub code looks like this:\r
-  //\r
-  //    00000000  89 25 00000004 R  mov     AppEsp, esp             ; save stack top\r
-  //    00000006  BC 00008014 R     mov     esp, offset DbgStkBot   ; switch to debugger stack\r
-  //    0000000B  6A 00             push    0                       ; push vector number - will be modified before installed\r
-  //    0000000D  E9                db      0e9h                    ; jump rel32\r
-  //    0000000E  00000000          dd      0                       ; fixed up to relative address of CommonIdtEntry\r
-  //\r
+  @param  Vector            Specifies vector number.\r
+  @param  IdtGateDecriptor  Pointer to IDT Gate Descriptor written into IDT Table.\r
 \r
-  //\r
-  // poke in the exception type so the second push pushes the exception type\r
-  //\r
-  StubCopy[0x0c] = (UINT8) ExceptionType;\r
+**/\r
+VOID WriteIdtGateDecriptor (\r
+  EFI_EXCEPTION_TYPE        Vector,\r
+  IA32_IDT_GATE_DESCRIPTOR  *IdtGateDecriptor\r
+  )\r
+{\r
+ IA32_DESCRIPTOR            IdtrValue;\r
+ IA32_IDT_GATE_DESCRIPTOR   *IdtTable;\r
 \r
-  //\r
-  // fixup the jump target to point to the common entry\r
-  //\r
-  *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];\r
+ AsmReadIdtr (&IdtrValue);\r
+ IdtTable = (IA32_IDT_GATE_DESCRIPTOR *) IdtrValue.Base;\r
 \r
 return EFI_SUCCESS;\r
CopyMem ((VOID *) &(IdtTable)[Vector], (VOID *) IdtGateDecriptor, sizeof (IA32_IDT_GATE_DESCRIPTOR));\r
 }\r
 \r
+\r
 /**\r
   Creates a nes entry stub.  Then saves the current IDT entry and replaces it\r
   with an interrupt gate for the new entry point.  The IdtEntryTable is updated\r
@@ -98,14 +91,13 @@ HookEntry (
   Status = CreateEntryStub (ExceptionType, (VOID **) &IdtEntryTable[ExceptionType].StubEntry);\r
   if (Status == EFI_SUCCESS) {\r
     OldIntFlagState = WriteInterruptFlag (0);\r
-    READ_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
+    ReadIdtGateDecriptor (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
 \r
-    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[0]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[0];\r
-    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[3];\r
+    IdtEntryTable[ExceptionType].OrigVector = (DEBUG_PROC) GetProcedureEntryPoint (&(IdtEntryTable[ExceptionType].OrigDesc));\r
 \r
     Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);\r
     IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;\r
-    WRITE_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));\r
+    WriteIdtGateDecriptor (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));\r
     WriteInterruptFlag (OldIntFlagState);\r
   }\r
 \r
@@ -128,71 +120,12 @@ UnhookEntry (
   BOOLEAN     OldIntFlagState;\r
 \r
   OldIntFlagState = WriteInterruptFlag (0);\r
-  WRITE_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
+  WriteIdtGateDecriptor (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
   WriteInterruptFlag (OldIntFlagState);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  This is the main worker function that manages the state of the interrupt\r
-  handlers.  It both installs and uninstalls interrupt handlers based on the\r
-  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
-  If NewCallback is non-NULL, then install is indicated.\r
-\r
-  @param  NewCallback   If non-NULL, NewCallback specifies the new handler to register.\r
-                        If NULL, specifies that the previously registered handler should\r
-                        be uninstalled.\r
-  @param  ExceptionType Indicates which entry to manage.\r
-\r
-  @retval EFI_SUCCESS            Process is ok.\r
-  @retval EFI_INVALID_PARAMETER  Requested uninstalling a handler from a vector that has\r
-                                 no handler registered for it\r
-  @retval EFI_ALREADY_STARTED    Requested install to a vector that already has a handler registered.\r
-  @retval others                 Possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
-**/\r
-EFI_STATUS\r
-ManageIdtEntryTable (\r
-  VOID (*NewCallback)(),\r
-  EFI_EXCEPTION_TYPE ExceptionType\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EFI_SUCCESS;\r
-\r
-  if (!FeaturePcdGet (PcdNtEmulatorEnable)) {\r
-    if (COMPARE_DESCRIPTOR (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc)) {\r
-      //\r
-      // we've already installed to this vector\r
-      //\r
-      if (NewCallback != NULL) {\r
-        //\r
-        // if the input handler is non-null, error\r
-        //\r
-        Status = EFI_ALREADY_STARTED;\r
-      } else {\r
-        Status = UnhookEntry (ExceptionType);\r
-      }\r
-    } else {\r
-      //\r
-      // no user handler installed on this vector\r
-      //\r
-      if (NewCallback == NULL) {\r
-        //\r
-        // if the input handler is null, error\r
-        //\r
-        Status = EFI_INVALID_PARAMETER;\r
-      } else {\r
-        Status = HookEntry (ExceptionType, NewCallback);\r
-      }\r
-    }\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
 /**\r
   This is a DebugSupport protocol member function, hard\r
   coded to support only 1 processor for now.\r
index 1566f3e8b7601c3a84a0f617ff1af19c7eee37a4..525ae8b3d7f50911a5e7ff7d78f6bf132e1f5486 100644 (file)
@@ -15,221 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _PLDEBUG_SUPPORT_H_\r
 #define _PLDEBUG_SUPPORT_H_\r
 \r
+#include "Ia32/DebugSupport.h"\r
 \r
-#include <Uefi.h>\r
-\r
-#include <Protocol/DebugSupport.h>\r
-#include <Protocol/LoadedImage.h>\r
-\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/PcdLib.h>\r
-\r
-#define NUM_IDT_ENTRIES                 0x78\r
-#define SYSTEM_TIMER_VECTOR             0x68\r
-#define VECTOR_ENTRY_PAGES              1\r
-#define COPY_DESCRIPTOR(Dest, Src)       CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))\r
-#define READ_IDT(Vector, Dest)           COPY_DESCRIPTOR ((Dest), &((GetIdtr ())[(Vector)]))\r
-#define WRITE_IDT(Vector, Src)           COPY_DESCRIPTOR (&((GetIdtr ())[(Vector)]), (Src))\r
-#define COMPARE_DESCRIPTOR(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))\r
 #define EFI_ISA                         IsaIa32\r
-#define FF_FXSR                         (1 << 24)\r
-\r
-typedef UINT64  DESCRIPTOR;\r
-\r
-typedef\r
-VOID\r
-(*DEBUG_PROC) (\r
-  VOID\r
-  );\r
-\r
-typedef struct {\r
-  DESCRIPTOR  OrigDesc;\r
-  DEBUG_PROC  OrigVector;\r
-  DESCRIPTOR  NewDesc;\r
-  DEBUG_PROC  StubEntry;\r
-  VOID (*RegisteredCallback) ();\r
-} IDT_ENTRY;\r
-\r
-extern EFI_SYSTEM_CONTEXT SystemContext;\r
-extern UINT8              InterruptEntryStub[];\r
-extern UINT32             StubSize;\r
-extern VOID (*OrigVector) (VOID);\r
-\r
-/**\r
-  Generic IDT entry.\r
-\r
-**/\r
-VOID\r
-CommonIdtEntry (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Check whether FXSTOR is supported\r
-\r
-  @retval TRUE   FXSTOR is supported.\r
-  @retval FALSE  FXSTOR is not supported.\r
-\r
-**/\r
-BOOLEAN\r
-FxStorSupport (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Return the physical address of IDTR.\r
-\r
-  @return The physical address of IDTR.\r
-\r
-**/\r
-DESCRIPTOR  *\r
-GetIdtr (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Encodes an IDT descriptor with the given physical address.\r
-\r
-  @param  DestDesc    The IDT descriptor address.\r
-  @param  Vecotr      The interrupt vector entry.\r
-\r
-**/\r
-VOID\r
-Vect2Desc (\r
-  DESCRIPTOR * DestDesc,\r
-  VOID (*Vector) (VOID)\r
-  );\r
-\r
-/**\r
-  Programs interrupt flag to the requested state and returns previous\r
-  state.\r
-\r
-  @param  NewState    New interrupt status.\r
-\r
-  @retval TRUE     Old interrupt status is TRUE.\r
-  @retval FALSE    Old interrupt status is FALSE\r
-\r
-**/\r
-BOOLEAN\r
-WriteInterruptFlag (\r
-  BOOLEAN NewState\r
-  );\r
-\r
-/**\r
-  Initializes driver's handler registration databas. \r
-  \r
-  This code executes in boot services context\r
-  Must be public because it's referenced from DebugSupport.c\r
-\r
-  @retval  EFI_UNSUPPORTED      If IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
-                                the context save will fail, so these processor's are not supported.\r
-  @retval  EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
-  @retval  EFI_SUCCESS          Initializes successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-PlInitializeDebugSupportDriver (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  This is the callback that is written to the LoadedImage protocol instance\r
-  on the image handle. It uninstalls all registered handlers and frees all entry\r
-  stub memory.\r
-\r
-  @param  ImageHandle    The firmware allocated handle for the EFI image.\r
-\r
-  @retval EFI_SUCCESS    Always.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlUnloadDebugSupportDriver (\r
-  IN EFI_HANDLE                       ImageHandle\r
-  );\r
-\r
-/**\r
-  This is a DebugSupport protocol member function, hard\r
-  coded to support only 1 processor for now.\r
-\r
-  @param  This                The DebugSupport instance\r
-  @param  MaxProcessorIndex   The maximuim supported processor index\r
-\r
-  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetMaximumProcessorIndex (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  OUT UINTN                           *MaxProcessorIndex\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This               The DebugSupport instance\r
-  @param  ProcessorIndex     Which processor the callback applies to.\r
-  @param  PeriodicCallback   Callback function\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterPeriodicCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN EFI_PERIODIC_CALLBACK            PeriodicCallback\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  This code executes in boot services context.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  NewCallback       Callback function\r
-  @param  ExceptionType     Which exception to hook\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterExceptionCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN EFI_EXCEPTION_CALLBACK           NewCallback,\r
-  IN EFI_EXCEPTION_TYPE               ExceptionType\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  Start             Physical base of the memory range to be invalidated\r
-  @param  Length            mininum number of bytes in instruction cache to invalidate\r
-\r
-  @retval EFI_SUCCESS       Always returned.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InvalidateInstructionCache (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN VOID                             *Start,\r
-  IN UINT64                           Length\r
-  );\r
 \r
 #endif\r
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupportIa32.c b/MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupportIa32.c
new file mode 100644 (file)
index 0000000..47e4e0e
--- /dev/null
@@ -0,0 +1,143 @@
+/** @file\r
+  IA32 specific debug support functions\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation\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
+\r
+**/\r
+\r
+#include "DebugSupport.h"\r
+\r
+/**\r
+  Get Procedure Entry Point from IDT Gate Descriptor.\r
+\r
+  @param  IdtGateDecriptor  IDT Gate Descriptor.\r
+\r
+  @return Procedure Entry Point located in IDT Gate Descriptor.\r
+\r
+**/\r
+UINTN GetProcedureEntryPoint (\r
+  IN IA32_IDT_GATE_DESCRIPTOR  *IdtGateDecriptor\r
+  )\r
+{\r
+  UINTN      ProcedureEntryPoint;\r
\r
+  ((UINT16 *) &ProcedureEntryPoint)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow;\r
+  ((UINT16 *) &ProcedureEntryPoint)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh;\r
+\r
+  return ProcedureEntryPoint;\r
+}\r
+\r
+/**\r
+  Allocate pool for a new IDT entry stub.\r
+\r
+  Copy the generic stub into the new buffer and fixup the vector number\r
+  and jump target address.\r
+\r
+  @param  ExceptionType   This is the exception type that the new stub will be created\r
+                          for.\r
+  @param  Stub            On successful exit, *Stub contains the newly allocated entry stub.\r
+\r
+  @retval EFI_SUCCESS     Always.\r
+\r
+**/\r
+EFI_STATUS\r
+CreateEntryStub (\r
+  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
+  OUT VOID                  **Stub\r
+  )\r
+{\r
+  UINT8       *StubCopy;\r
+\r
+  StubCopy = *Stub;\r
+\r
+  //\r
+  // Fixup the stub code for this vector\r
+  //\r
+\r
+  // The stub code looks like this:\r
+  //\r
+  //    00000000  89 25 00000004 R  mov     AppEsp, esp             ; save stack top\r
+  //    00000006  BC 00008014 R     mov     esp, offset DbgStkBot   ; switch to debugger stack\r
+  //    0000000B  6A 00             push    0                       ; push vector number - will be modified before installed\r
+  //    0000000D  E9                db      0e9h                    ; jump rel32\r
+  //    0000000E  00000000          dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+  //\r
+\r
+  //\r
+  // poke in the exception type so the second push pushes the exception type\r
+  //\r
+  StubCopy[0x0c] = (UINT8) ExceptionType;\r
+\r
+  //\r
+  // fixup the jump target to point to the common entry\r
+  //\r
+  *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This is the main worker function that manages the state of the interrupt\r
+  handlers.  It both installs and uninstalls interrupt handlers based on the\r
+  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
+  If NewCallback is non-NULL, then install is indicated.\r
+\r
+  @param  NewCallback   If non-NULL, NewCallback specifies the new handler to register.\r
+                        If NULL, specifies that the previously registered handler should\r
+                        be uninstalled.\r
+  @param  ExceptionType Indicates which entry to manage.\r
+\r
+  @retval EFI_SUCCESS            Process is ok.\r
+  @retval EFI_INVALID_PARAMETER  Requested uninstalling a handler from a vector that has\r
+                                 no handler registered for it\r
+  @retval EFI_ALREADY_STARTED    Requested install to a vector that already has a handler registered.\r
+  @retval others                 Possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+**/\r
+EFI_STATUS\r
+ManageIdtEntryTable (\r
+  VOID (*NewCallback)(),\r
+  EFI_EXCEPTION_TYPE ExceptionType\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (!FeaturePcdGet (PcdNtEmulatorEnable)) {\r
+    if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {\r
+      //\r
+      // we've already installed to this vector\r
+      //\r
+      if (NewCallback != NULL) {\r
+        //\r
+        // if the input handler is non-null, error\r
+        //\r
+        Status = EFI_ALREADY_STARTED;\r
+      } else {\r
+        Status = UnhookEntry (ExceptionType);\r
+      }\r
+    } else {\r
+      //\r
+      // no user handler installed on this vector\r
+      //\r
+      if (NewCallback == NULL) {\r
+        //\r
+        // if the input handler is null, error\r
+        //\r
+        Status = EFI_INVALID_PARAMETER;\r
+      } else {\r
+        Status = HookEntry (ExceptionType, NewCallback);\r
+      }\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
index cd5bb8e0387f473f9da82ece044a15a3122d4c36..f8f5532de7c663272172043133e4691b5b0377fa 100644 (file)
@@ -26,8 +26,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/PcdLib.h>\r
 \r
 #define DISABLE_INTERRUPTS  0UL\r
 \r
index 5cc3e52bfe7a29535106f0b109f74ed4842c40e2..f486bd32b55457d7d37f23ae49e61bc63c875e88 100644 (file)
@@ -108,19 +108,6 @@ text SEGMENT
 \r
 externdef InterruptDistrubutionHub:near\r
 \r
-;------------------------------------------------------------------------------\r
-;  VOID\r
-;  EfiWbinvd (\r
-;    VOID\r
-;    )\r
-;\r
-; Abstract: Writeback and invalidate cache\r
-;\r
-EfiWbinvd PROC    PUBLIC\r
-    wbinvd\r
-    ret\r
-EfiWbinvd ENDP\r
-\r
 ;------------------------------------------------------------------------------\r
 ; BOOLEAN\r
 ; FxStorSupport (\r
@@ -145,25 +132,6 @@ FxStorSupport   PROC    PUBLIC
 FxStorSupport   ENDP\r
 \r
 \r
-;------------------------------------------------------------------------------\r
-; DESCRIPTOR *\r
-; GetIdtr (\r
-;   void\r
-;   )\r
-;\r
-; Abstract: Returns physical address of IDTR\r
-;\r
-GetIdtr         PROC    PUBLIC\r
-                push    rbp\r
-                mov     rbp, rsp\r
-\r
-                sidt    QWORD PTR [rbp - 0ah]\r
-                mov     rax, QWORD PTR [rbp - 8h]\r
-\r
-                mov     rsp, rbp\r
-                pop     rbp\r
-                ret\r
-GetIdtr         ENDP\r
 \r
 \r
 ;------------------------------------------------------------------------------\r
@@ -196,7 +164,7 @@ WriteInterruptFlag  ENDP
 ;------------------------------------------------------------------------------\r
 ; void\r
 ; Vect2Desc (\r
-;   DESCRIPTOR * DestDesc,  // rcx\r
+;   IA32_IDT_GATE_DESCRIPTOR * DestDesc,  // rcx\r
 ;   void (*Vector) (void)   // rdx\r
 ;   )\r
 ;\r
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupport.c b/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupport.c
deleted file mode 100644 (file)
index 24e5acc..0000000
+++ /dev/null
@@ -1,385 +0,0 @@
-/** @file\r
-  X64 specific debug support functions\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\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
-\r
-**/\r
-\r
-//\r
-// private header files\r
-//\r
-#include "PlDebugSupport.h"\r
-\r
-//\r
-// This the global main table to keep track of the interrupts\r
-//\r
-IDT_ENTRY   *IdtEntryTable  = NULL;\r
-DESCRIPTOR  NullDesc        = {0, 0};\r
-\r
-/**\r
-  Allocate pool for a new IDT entry stub.\r
-\r
-  Copy the generic stub into the new buffer and fixup the vector number\r
-  and jump target address.\r
-\r
-  @param  ExceptionType   This is the exception type that the new stub will be created\r
-                          for.\r
-  @param  Stub            On successful exit, *Stub contains the newly allocated entry stub.\r
-\r
-  @retval EFI_SUCCESS     Always.\r
-\r
-**/\r
-EFI_STATUS\r
-CreateEntryStub (\r
-  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
-  OUT VOID                  **Stub\r
-  )\r
-{\r
-  UINT8       *StubCopy;\r
-\r
-  StubCopy = *Stub;\r
-\r
-  //\r
-  // Fixup the stub code for this vector\r
-  //\r
-\r
-  // The stub code looks like this:\r
-  //\r
-  //    00000000  6A 00               push    0                       ; push vector number - will be modified before installed\r
-  //    00000002  E9                  db      0e9h                    ; jump rel32\r
-  //    00000003  00000000            dd      0                       ; fixed up to relative address of CommonIdtEntry\r
-  //\r
-\r
-  //\r
-  // poke in the exception type so the second push pushes the exception type\r
-  //\r
-  StubCopy[0x1] = (UINT8) ExceptionType;\r
-\r
-  //\r
-  // fixup the jump target to point to the common entry\r
-  //\r
-  *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Creates a nes entry stub.  Then saves the current IDT entry and replaces it\r
-  with an interrupt gate for the new entry point.  The IdtEntryTable is updated\r
-  with the new registered function.\r
-\r
-  This code executes in boot services context.  The stub entry executes in interrupt\r
-  context.\r
-\r
-  @param  ExceptionType      Specifies which vector to hook.\r
-  @param  NewCallback        A pointer to the new function to be registered.\r
-\r
-  @retval EFI_SUCCESS        Always.\r
-\r
-**/\r
-EFI_STATUS\r
-HookEntry (\r
-  IN EFI_EXCEPTION_TYPE            ExceptionType,\r
-  IN VOID                         (*NewCallback) ()\r
-  )\r
-{\r
-  BOOLEAN     OldIntFlagState;\r
-  EFI_STATUS  Status;\r
-\r
-  Status = CreateEntryStub (ExceptionType, (VOID **) &IdtEntryTable[ExceptionType].StubEntry);\r
-  if (Status == EFI_SUCCESS) {\r
-    OldIntFlagState = WriteInterruptFlag (0);\r
-    READ_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
-\r
-    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[0]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc.Low)[0];\r
-    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc.Low)[3];\r
-    ((UINT32 *) &IdtEntryTable[ExceptionType].OrigVector)[1]  = ((UINT32 *) &IdtEntryTable[ExceptionType].OrigDesc.High)[0];\r
-\r
-    Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);\r
-    IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;\r
-    WRITE_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));\r
-    WriteInterruptFlag (OldIntFlagState);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Undoes HookEntry. This code executes in boot services context.\r
-\r
-  @param  ExceptionType   Specifies which entry to unhook\r
-\r
-  @retval EFI_SUCCESS     Always.\r
-\r
-**/\r
-EFI_STATUS\r
-UnhookEntry (\r
-  IN EFI_EXCEPTION_TYPE           ExceptionType\r
-  )\r
-{\r
-  BOOLEAN     OldIntFlagState;\r
-\r
-  OldIntFlagState = WriteInterruptFlag (0);\r
-  WRITE_IDT (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
-  WriteInterruptFlag (OldIntFlagState);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  This is the main worker function that manages the state of the interrupt\r
-  handlers.  It both installs and uninstalls interrupt handlers based on the\r
-  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
-  If NewCallback is non-NULL, then install is indicated.\r
-\r
-  @param  NewCallback   If non-NULL, NewCallback specifies the new handler to register.\r
-                        If NULL, specifies that the previously registered handler should\r
-                        be uninstalled.\r
-  @param  ExceptionType Indicates which entry to manage.\r
-\r
-  @retval EFI_SUCCESS            Process is ok.\r
-  @retval EFI_INVALID_PARAMETER  Requested uninstalling a handler from a vector that has\r
-                                 no handler registered for it\r
-  @retval EFI_ALREADY_STARTED    Requested install to a vector that already has a handler registered.\r
-  @retval others                 Possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
-**/\r
-EFI_STATUS\r
-ManageIdtEntryTable (\r
-  VOID (*NewCallback)(),\r
-  EFI_EXCEPTION_TYPE ExceptionType\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  Status = EFI_SUCCESS;\r
-\r
-  if (COMPARE_DESCRIPTOR (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc)) {\r
-    //\r
-    // we've already installed to this vector\r
-    //\r
-    if (NewCallback != NULL) {\r
-      //\r
-      // if the input handler is non-null, error\r
-      //\r
-      Status = EFI_ALREADY_STARTED;\r
-    } else {\r
-      Status = UnhookEntry (ExceptionType);\r
-    }\r
-  } else {\r
-    //\r
-    // no user handler installed on this vector\r
-    //\r
-    if (NewCallback == NULL) {\r
-      //\r
-      // if the input handler is null, error\r
-      //\r
-      Status = EFI_INVALID_PARAMETER;\r
-    } else {\r
-      Status = HookEntry (ExceptionType, NewCallback);\r
-    }\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  This is a DebugSupport protocol member function, hard\r
-  coded to support only 1 processor for now.\r
-\r
-  @param  This                The DebugSupport instance\r
-  @param  MaxProcessorIndex   The maximuim supported processor index\r
-\r
-  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetMaximumProcessorIndex (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  OUT UINTN                           *MaxProcessorIndex\r
-  )\r
-{\r
-  *MaxProcessorIndex = 0;\r
-  return (EFI_SUCCESS);\r
-}\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This               The DebugSupport instance\r
-  @param  ProcessorIndex     Which processor the callback applies to.\r
-  @param  PeriodicCallback   Callback function\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterPeriodicCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
-  IN UINTN                      ProcessorIndex,\r
-  IN EFI_PERIODIC_CALLBACK      PeriodicCallback\r
-  )\r
-{\r
-  return ManageIdtEntryTable (PeriodicCallback, SYSTEM_TIMER_VECTOR);\r
-}\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  This code executes in boot services context.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  NewCallback       Callback function\r
-  @param  ExceptionType     Which exception to hook\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterExceptionCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
-  IN UINTN                      ProcessorIndex,\r
-  IN EFI_EXCEPTION_CALLBACK     NewCallback,\r
-  IN EFI_EXCEPTION_TYPE         ExceptionType\r
-  )\r
-{\r
-  return ManageIdtEntryTable (NewCallback, ExceptionType);\r
-}\r
-\r
-/**\r
-  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  Start             Physical base of the memory range to be invalidated\r
-  @param  Length            mininum number of bytes in instruction cache to invalidate\r
-\r
-  @retval EFI_SUCCESS       Always returned.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InvalidateInstructionCache (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN VOID                             *Start,\r
-  IN UINT64                           Length\r
-  )\r
-{\r
-  AsmWbinvd ();\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Initializes driver's handler registration databas. \r
-  \r
-  This code executes in boot services context\r
-  Must be public because it's referenced from DebugSupport.c\r
-\r
-  @retval  EFI_UNSUPPORTED      If x64 processor does not support FXSTOR/FXRSTOR instructions,\r
-                                the context save will fail, so these processor's are not supported.\r
-  @retval  EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
-  @retval  EFI_SUCCESS          Initializes successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-PlInitializeDebugSupportDriver (\r
-  VOID\r
-  )\r
-{\r
-  EFI_EXCEPTION_TYPE  ExceptionType;\r
-\r
-  if (!FxStorSupport ()) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);\r
-  if (IdtEntryTable == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
-    IdtEntryTable[ExceptionType].StubEntry = (DEBUG_PROC) (UINTN) AllocatePool (StubSize);\r
-    if (IdtEntryTable[ExceptionType].StubEntry == NULL) {\r
-      goto ErrorCleanup;\r
-    }\r
-\r
-    CopyMem ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry, InterruptEntryStub, StubSize);\r
-  }\r
-  return EFI_SUCCESS;\r
-\r
-ErrorCleanup:\r
-\r
-  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
-    if (IdtEntryTable[ExceptionType].StubEntry != NULL) {\r
-      FreePool ((VOID *)(UINTN)IdtEntryTable[ExceptionType].StubEntry);\r
-    }\r
-  }\r
-  FreePool (IdtEntryTable);\r
-\r
-  return EFI_OUT_OF_RESOURCES;\r
-}\r
-\r
-/**\r
-  This is the callback that is written to the LoadedImage protocol instance\r
-  on the image handle. It uninstalls all registered handlers and frees all entry\r
-  stub memory.\r
-\r
-  @param  ImageHandle    The firmware allocated handle for the EFI image.\r
-\r
-  @retval EFI_SUCCESS    Always.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlUnloadDebugSupportDriver (\r
-  IN EFI_HANDLE ImageHandle\r
-  )\r
-{\r
-  EFI_EXCEPTION_TYPE  ExceptionType;\r
-\r
-  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
-    ManageIdtEntryTable (NULL, ExceptionType);\r
-  }\r
-\r
-  FreePool (IdtEntryTable);\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Common piece of code that invokes the registered handlers.\r
-\r
-  This code executes in exception context so no efi calls are allowed.\r
-\r
-  @param  ExceptionType     Exception type\r
-  @param  ContextRecord     System context\r
-\r
-**/\r
-VOID\r
-InterruptDistrubutionHub (\r
-  EFI_EXCEPTION_TYPE      ExceptionType,\r
-  EFI_SYSTEM_CONTEXT_IA32 *ContextRecord\r
-  )\r
-{\r
-  if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {\r
-    if (ExceptionType != SYSTEM_TIMER_VECTOR) {\r
-      IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);\r
-    } else {\r
-      OrigVector = IdtEntryTable[ExceptionType].OrigVector;\r
-      IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);\r
-    }\r
-  }\r
-}\r
index eb04f1a88c4ecabc2f131540ab262785c6f8e399..3a9b9030c29bbbb8602878ba7e61cae53c03b75d 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-  X64 specific debug support macros, typedefs and prototypes.\r
+  X64 specific debug support macros.\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -15,224 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #ifndef _PLDEBUG_SUPPORT_H_\r
 #define _PLDEBUG_SUPPORT_H_\r
 \r
+#include "Ia32/DebugSupport.h"\r
 \r
-#include <Uefi.h>\r
-\r
-#include <Protocol/DebugSupport.h>\r
-#include <Protocol/LoadedImage.h>\r
-\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-\r
-#include <Library/PcdLib.h>\r
-#define NUM_IDT_ENTRIES                 0x78\r
-#define SYSTEM_TIMER_VECTOR             0x68\r
-#define VECTOR_ENTRY_PAGES              1\r
-#define COPY_DESCRIPTOR(Dest, Src)       CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))\r
-#define READ_IDT(Vector, Dest)           COPY_DESCRIPTOR ((Dest), &((GetIdtr ())[(Vector)]))\r
-#define WRITE_IDT(Vector, Src)           COPY_DESCRIPTOR (&((GetIdtr ())[(Vector)]), (Src))\r
-#define COMPARE_DESCRIPTOR(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))\r
 #define EFI_ISA                         IsaX64\r
-#define FF_FXSR                         (1 << 24)\r
-\r
-typedef struct {\r
-  UINT64 Low;\r
-  UINT64 High;\r
-} DESCRIPTOR;\r
-\r
-typedef\r
-VOID\r
-(*DEBUG_PROC) (\r
-  VOID\r
-  );\r
-\r
-typedef struct {\r
-  DESCRIPTOR  OrigDesc;\r
-  DEBUG_PROC  OrigVector;\r
-  DESCRIPTOR  NewDesc;\r
-  DEBUG_PROC  StubEntry;\r
-  VOID (*RegisteredCallback) ();\r
-} IDT_ENTRY;\r
-\r
-extern EFI_SYSTEM_CONTEXT SystemContext;\r
-extern UINT8              InterruptEntryStub[];\r
-extern UINT32             StubSize;\r
-extern VOID (*OrigVector) (VOID);\r
-\r
-/**\r
-  Generic IDT entry.\r
-\r
-**/\r
-VOID\r
-CommonIdtEntry (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Check whether FXSTOR is supported\r
-\r
-  @retval TRUE   FXSTOR is supported.\r
-  @retval FALSE  FXSTOR is not supported.\r
-\r
-**/\r
-BOOLEAN\r
-FxStorSupport (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Return the physical address of IDTR.\r
-\r
-  @return The physical address of IDTR.\r
-\r
-**/\r
-DESCRIPTOR  *\r
-GetIdtr (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  Encodes an IDT descriptor with the given physical address.\r
-\r
-  @param  DestDesc    The IDT descriptor address.\r
-  @param  Vecotr      The interrupt vector entry.\r
-\r
-**/\r
-VOID\r
-Vect2Desc (\r
-  DESCRIPTOR * DestDesc,\r
-  VOID (*Vector) (VOID)\r
-  );\r
-\r
-/**\r
-  Programs interrupt flag to the requested state and returns previous\r
-  state.\r
-\r
-  @param  NewState    New interrupt status.\r
-\r
-  @retval TRUE     Old interrupt status is TRUE.\r
-  @retval FALSE    Old interrupt status is FALSE\r
-\r
-**/\r
-BOOLEAN\r
-WriteInterruptFlag (\r
-  BOOLEAN NewState\r
-  );\r
-\r
-/**\r
-  Initializes driver's handler registration databas. \r
-  \r
-  This code executes in boot services context\r
-  Must be public because it's referenced from DebugSupport.c\r
-\r
-  @retval  EFI_UNSUPPORTED      If x64 processor does not support FXSTOR/FXRSTOR instructions,\r
-                                the context save will fail, so these processor's are not supported.\r
-  @retval  EFI_OUT_OF_RESOURCES Fails to allocate memory.\r
-  @retval  EFI_SUCCESS          Initializes successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-PlInitializeDebugSupportDriver (\r
-  VOID\r
-  );\r
-\r
-/**\r
-  This is the callback that is written to the LoadedImage protocol instance\r
-  on the image handle. It uninstalls all registered handlers and frees all entry\r
-  stub memory.\r
-\r
-  @param  ImageHandle    The firmware allocated handle for the EFI image.\r
-\r
-  @retval EFI_SUCCESS    Always.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-PlUnloadDebugSupportDriver (\r
-  IN EFI_HANDLE                       ImageHandle\r
-  );\r
-\r
-/**\r
-  This is a DebugSupport protocol member function, hard\r
-  coded to support only 1 processor for now.\r
-\r
-  @param  This                The DebugSupport instance\r
-  @param  MaxProcessorIndex   The maximuim supported processor index\r
-\r
-  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetMaximumProcessorIndex (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  OUT UINTN                           *MaxProcessorIndex\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This               The DebugSupport instance\r
-  @param  ProcessorIndex     Which processor the callback applies to.\r
-  @param  PeriodicCallback   Callback function\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterPeriodicCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN EFI_PERIODIC_CALLBACK            PeriodicCallback\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.\r
-\r
-  This code executes in boot services context.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  NewCallback       Callback function\r
-  @param  ExceptionType     Which exception to hook\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterExceptionCallback (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN EFI_EXCEPTION_CALLBACK           NewCallback,\r
-  IN EFI_EXCEPTION_TYPE               ExceptionType\r
-  );\r
-\r
-/**\r
-  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  Start             Physical base of the memory range to be invalidated\r
-  @param  Length            mininum number of bytes in instruction cache to invalidate\r
-\r
-  @retval EFI_SUCCESS       Always returned.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InvalidateInstructionCache (\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
-  IN UINTN                            ProcessorIndex,\r
-  IN VOID                             *Start,\r
-  IN UINT64                           Length\r
-  );\r
 \r
 #endif\r
diff --git a/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c b/MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c
new file mode 100644 (file)
index 0000000..943d2c6
--- /dev/null
@@ -0,0 +1,143 @@
+/** @file\r
+  X64 specific debug support functions\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\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
+\r
+**/\r
+\r
+//\r
+// private header files\r
+//\r
+#include "DebugSupport.h"\r
+\r
+/**\r
+  Get Procedure Entry Point from IDT Gate Descriptor.\r
+\r
+  @param  IdtGateDecriptor  IDT Gate Descriptor.\r
+\r
+  @return Procedure Entry Point located in IDT Gate Descriptor.\r
+\r
+**/\r
+UINTN GetProcedureEntryPoint (\r
+  IN IA32_IDT_GATE_DESCRIPTOR  *IdtGateDecriptor\r
+  )\r
+{\r
+  UINTN      ProcedureEntryPoint;\r
\r
+  ((UINT16 *) &ProcedureEntryPoint)[0] = (UINT16) IdtGateDecriptor->Bits.OffsetLow;\r
+  ((UINT16 *) &ProcedureEntryPoint)[1] = (UINT16) IdtGateDecriptor->Bits.OffsetHigh;\r
+  ((UINT32 *) &ProcedureEntryPoint)[1] = (UINT32) IdtGateDecriptor->Bits.OffsetUpper;\r
+\r
+  return ProcedureEntryPoint;\r
+}\r
+\r
+/**\r
+  Allocate pool for a new IDT entry stub.\r
+\r
+  Copy the generic stub into the new buffer and fixup the vector number\r
+  and jump target address.\r
+\r
+  @param  ExceptionType   This is the exception type that the new stub will be created\r
+                          for.\r
+  @param  Stub            On successful exit, *Stub contains the newly allocated entry stub.\r
+\r
+  @retval EFI_SUCCESS     Always.\r
+\r
+**/\r
+EFI_STATUS\r
+CreateEntryStub (\r
+  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
+  OUT VOID                  **Stub\r
+  )\r
+{\r
+  UINT8       *StubCopy;\r
+\r
+  StubCopy = *Stub;\r
+\r
+  //\r
+  // Fixup the stub code for this vector\r
+  //\r
+\r
+  // The stub code looks like this:\r
+  //\r
+  //    00000000  6A 00               push    0                       ; push vector number - will be modified before installed\r
+  //    00000002  E9                  db      0e9h                    ; jump rel32\r
+  //    00000003  00000000            dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+  //\r
+\r
+  //\r
+  // poke in the exception type so the second push pushes the exception type\r
+  //\r
+  StubCopy[0x1] = (UINT8) ExceptionType;\r
+\r
+  //\r
+  // fixup the jump target to point to the common entry\r
+  //\r
+  *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This is the main worker function that manages the state of the interrupt\r
+  handlers.  It both installs and uninstalls interrupt handlers based on the\r
+  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
+  If NewCallback is non-NULL, then install is indicated.\r
+\r
+  @param  NewCallback   If non-NULL, NewCallback specifies the new handler to register.\r
+                        If NULL, specifies that the previously registered handler should\r
+                        be uninstalled.\r
+  @param  ExceptionType Indicates which entry to manage.\r
+\r
+  @retval EFI_SUCCESS            Process is ok.\r
+  @retval EFI_INVALID_PARAMETER  Requested uninstalling a handler from a vector that has\r
+                                 no handler registered for it\r
+  @retval EFI_ALREADY_STARTED    Requested install to a vector that already has a handler registered.\r
+  @retval others                 Possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+**/\r
+EFI_STATUS\r
+ManageIdtEntryTable (\r
+  VOID (*NewCallback)(),\r
+  EFI_EXCEPTION_TYPE ExceptionType\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (CompareMem (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc, sizeof (IA32_IDT_GATE_DESCRIPTOR)) != 0) {\r
+    //\r
+    // we've already installed to this vector\r
+    //\r
+    if (NewCallback != NULL) {\r
+      //\r
+      // if the input handler is non-null, error\r
+      //\r
+      Status = EFI_ALREADY_STARTED;\r
+    } else {\r
+      Status = UnhookEntry (ExceptionType);\r
+    }\r
+  } else {\r
+    //\r
+    // no user handler installed on this vector\r
+    //\r
+    if (NewCallback == NULL) {\r
+      //\r
+      // if the input handler is null, error\r
+      //\r
+      Status = EFI_INVALID_PARAMETER;\r
+    } else {\r
+      Status = HookEntry (ExceptionType, NewCallback);\r
+    }\r
+  }\r
\r
+  return Status;\r
+}\r