--- /dev/null
+/** @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