+++ /dev/null
-/** @file\r
- IPF specific functions to support Debug Support protocol.\r
-\r
-Copyright (c) 2006 - 2010, 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
-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 "PlDebugSupport.h"\r
-\r
-BOOLEAN mInHandler = FALSE;\r
-\r
-//\r
-// number of bundles to swap in ivt\r
-//\r
-#define NUM_BUNDLES_IN_STUB 5\r
-#define NUM_IVT_ENTRIES 64\r
-\r
-typedef struct {\r
- BUNDLE OrigBundles[NUM_BUNDLES_IN_STUB];\r
- CALLBACK_FUNC RegisteredCallback;\r
-} IVT_ENTRY;\r
-\r
-IVT_ENTRY IvtEntryTable[NUM_IVT_ENTRIES];\r
-\r
-//\r
-// IPF context record is overallocated by 512 bytes to guarantee a 512 byte alignment exists\r
-// within the buffer and still have a large enough buffer to hold a whole IPF context record.\r
-//\r
-UINT8 IpfContextBuf[sizeof (EFI_SYSTEM_CONTEXT_IPF) + 512];\r
-\r
-//\r
-// The PatchSaveBuffer is used to store the original bundles from the IVT where it is patched\r
-// with the common handler.\r
-//\r
-UINT8 PatchSaveBuffer[0x400];\r
-UINTN ExternalInterruptCount;\r
-\r
-\r
-/**\r
- IPF specific DebugSupport driver initialization.\r
-\r
- Must be public because it's referenced from DebugSupport.c\r
-\r
- @retval EFI_SUCCESS Always.\r
-\r
-**/\r
-EFI_STATUS\r
-PlInitializeDebugSupportDriver (\r
- VOID\r
- )\r
-{\r
- ZeroMem (IvtEntryTable, sizeof (IvtEntryTable));\r
- ExternalInterruptCount = 0;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Unload handler that is called during UnloadImage() - deallocates pool memory\r
- used by the driver.\r
-\r
- Must be public because it's referenced from DebugSuport.c\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_IVT_ENTRIES; ExceptionType++) {\r
- ManageIvtEntryTable (ExceptionType, NULL, NULL);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- C routine that is called for all registered exceptions. This is the main\r
- exception dispatcher.\r
-\r
- Must be public because it's referenced from AsmFuncs.s.\r
-\r
- @param ExceptionType Specifies which processor exception.\r
- @param Context System Context.\r
-**/\r
-VOID\r
-CommonHandler (\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN EFI_SYSTEM_CONTEXT Context\r
- )\r
-{\r
- DEBUG_CODE_BEGIN ();\r
- if (mInHandler) {\r
- DEBUG ((EFI_D_INFO, "ERROR: Re-entered debugger!\n"\r
- " ExceptionType == %X\n"\r
- " Context == %X\n"\r
- " Context.SystemContextIpf->CrIip == %LX\n"\r
- " Context.SystemContextIpf->CrIpsr == %LX\n"\r
- " mInHandler == %X\n",\r
- (INT32)ExceptionType,\r
- Context,\r
- Context.SystemContextIpf->CrIip,\r
- Context.SystemContextIpf->CrIpsr,\r
- mInHandler));\r
- }\r
- DEBUG_CODE_END ();\r
-\r
- ASSERT (!mInHandler);\r
- mInHandler = TRUE;\r
- if (IvtEntryTable[ExceptionType].RegisteredCallback != NULL) {\r
- if (ExceptionType != EXCEPT_IPF_EXTERNAL_INTERRUPT) {\r
- IvtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, Context.SystemContextIpf);\r
- } else {\r
- IvtEntryTable[ExceptionType].RegisteredCallback (Context.SystemContextIpf);\r
- }\r
- } else {\r
- ASSERT (0);\r
- }\r
-\r
- mInHandler = FALSE;\r
-}\r
-\r
-/**\r
- Given an integer number, return the physical address of the entry point in the IFT.\r
-\r
- @param HandlerIndex Index of the Handler\r
- @param EntryPoint IFT Entrypoint\r
-\r
-**/\r
-VOID\r
-GetHandlerEntryPoint (\r
- UINTN HandlerIndex,\r
- VOID **EntryPoint\r
- )\r
-{\r
- UINT8 *TempPtr;\r
-\r
- //\r
- // get base address of IVT\r
- //\r
- TempPtr = GetIva ();\r
-\r
- if (HandlerIndex < 20) {\r
- //\r
- // first 20 provide 64 bundles per vector\r
- //\r
- TempPtr += 0x400 * HandlerIndex;\r
- } else {\r
- //\r
- // the rest provide 16 bundles per vector\r
- //\r
- TempPtr += 0x5000 + 0x100 * (HandlerIndex - 20);\r
- }\r
-\r
- *EntryPoint = (VOID *) TempPtr;\r
-}\r
-\r
-/**\r
- This is the worker function that uninstalls and removes all handlers.\r
-\r
- @param ExceptionType Specifies which processor exception.\r
- @param NewBundles New Boundles.\r
- @param NewCallback A pointer to the new function to be registered.\r
-\r
- @retval EFI_ALEADY_STARTED Ivt already hooked.\r
- @retval EFI_SUCCESS Successfully uninstalled.\r
-\r
-**/\r
-EFI_STATUS\r
-ManageIvtEntryTable (\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN BUNDLE NewBundles[NUM_BUNDLES_IN_STUB],\r
- IN CALLBACK_FUNC NewCallback\r
- )\r
-{\r
- BUNDLE *B0Ptr;\r
- UINT64 InterruptFlags;\r
- EFI_TPL OldTpl;\r
-\r
- //\r
- // Get address of bundle 0\r
- //\r
- GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);\r
-\r
- if (IvtEntryTable[ExceptionType].RegisteredCallback != NULL) {\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
- return EFI_ALREADY_STARTED;\r
- } else {\r
- //\r
- // else remove the previously installed handler\r
- //\r
- OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
- InterruptFlags = ProgramInterruptFlags (DISABLE_INTERRUPTS);\r
- if (ExceptionType == EXCEPT_IPF_EXTERNAL_INTERRUPT) {\r
- UnchainExternalInterrupt ();\r
- } else {\r
- UnhookEntry (ExceptionType);\r
- }\r
-\r
- ProgramInterruptFlags (InterruptFlags);\r
- gBS->RestoreTPL (OldTpl);\r
- //\r
- // re-init IvtEntryTable\r
- //\r
- ZeroMem (&IvtEntryTable[ExceptionType], sizeof (IVT_ENTRY));\r
- }\r
- } else {\r
- //\r
- // no user handler installed on this vector\r
- //\r
- if (NewCallback != NULL) {\r
- OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
- InterruptFlags = ProgramInterruptFlags (DISABLE_INTERRUPTS);\r
- if (ExceptionType == EXCEPT_IPF_EXTERNAL_INTERRUPT) {\r
- ChainExternalInterrupt (NewCallback);\r
- } else {\r
- HookEntry (ExceptionType, NewBundles, NewCallback);\r
- }\r
-\r
- ProgramInterruptFlags (InterruptFlags);\r
- gBS->RestoreTPL (OldTpl);\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Saves original IVT contents and inserts a few new bundles which are fixed up\r
- to store the ExceptionType and then call the common handler.\r
-\r
- @param ExceptionType Specifies which processor exception.\r
- @param NewBundles New Boundles.\r
- @param NewCallback A pointer to the new function to be hooked.\r
-\r
-**/\r
-VOID\r
-HookEntry (\r
- IN EFI_EXCEPTION_TYPE ExceptionType,\r
- IN BUNDLE NewBundles[4],\r
- IN CALLBACK_FUNC NewCallback\r
- )\r
-{\r
- BUNDLE *FixupBundle;\r
- BUNDLE *B0Ptr;\r
-\r
- //\r
- // Get address of bundle 0\r
- //\r
- GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);\r
-\r
- //\r
- // copy original bundles from IVT to IvtEntryTable so we can restore them later\r
- //\r
- CopyMem (\r
- IvtEntryTable[ExceptionType].OrigBundles,\r
- B0Ptr,\r
- sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB\r
- );\r
- //\r
- // insert new B0\r
- //\r
- CopyMem (B0Ptr, NewBundles, sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB);\r
-\r
- //\r
- // fixup IVT entry so it stores its index and whether or not to chain...\r
- //\r
- FixupBundle = B0Ptr + 2;\r
- FixupBundle->High |= ExceptionType << 36;\r
-\r
- InstructionCacheFlush (B0Ptr, 5);\r
- IvtEntryTable[ExceptionType].RegisteredCallback = NewCallback;\r
-}\r
-\r
-/**\r
- Restores original IVT contents when unregistering a callback function.\r
-\r
- @param ExceptionType Specifies which processor exception.\r
-\r
-**/\r
-VOID\r
-UnhookEntry (\r
- IN EFI_EXCEPTION_TYPE ExceptionType\r
- )\r
-{\r
- BUNDLE *B0Ptr;\r
-\r
- //\r
- // Get address of bundle 0\r
- //\r
- GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);\r
- //\r
- // restore original bundles in IVT\r
- //\r
- CopyMem (\r
- B0Ptr,\r
- IvtEntryTable[ExceptionType].OrigBundles,\r
- sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB\r
- );\r
- InstructionCacheFlush (B0Ptr, 5);\r
-}\r
-\r
-/**\r
- Sets up cache flush and calls assembly function to chain external interrupt.\r
-\r
- Records new callback in IvtEntryTable.\r
-\r
- @param NewCallback A pointer to the interrupt handle.\r
-\r
-**/\r
-VOID\r
-ChainExternalInterrupt (\r
- IN CALLBACK_FUNC NewCallback\r
- )\r
-{\r
- VOID *Start;\r
-\r
- Start = (VOID *) ((UINT8 *) GetIva () + 0x400 * EXCEPT_IPF_EXTERNAL_INTERRUPT + 0x400);\r
- IvtEntryTable[EXCEPT_IPF_EXTERNAL_INTERRUPT].RegisteredCallback = NewCallback;\r
- ChainHandler ();\r
- InstructionCacheFlush (Start, 0x400);\r
-}\r
-\r
-/**\r
- Sets up cache flush and calls assembly function to restore external interrupt.\r
- Removes registered callback from IvtEntryTable.\r
-\r
-**/\r
-VOID\r
-UnchainExternalInterrupt (\r
- VOID\r
- )\r
-{\r
- VOID *Start;\r
-\r
- Start = (VOID *) ((UINT8 *) GetIva () + 0x400 * EXCEPT_IPF_EXTERNAL_INTERRUPT + 0x400);\r
- UnchainHandler ();\r
- InstructionCacheFlush (Start, 0x400);\r
- IvtEntryTable[EXCEPT_IPF_EXTERNAL_INTERRUPT].RegisteredCallback = NULL;\r
-}\r
-\r
-/**\r
- Returns the maximum value that may be used for the ProcessorIndex parameter in\r
- RegisterPeriodicCallback() and RegisterExceptionCallback().\r
-\r
- Hard coded to support only 1 processor for now.\r
-\r
- @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
- @param MaxProcessorIndex Pointer to a caller-allocated UINTN in which the maximum supported\r
- processor index is returned. Always 0 returned.\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
- Registers a function to be called back periodically in interrupt context.\r
-\r
- @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
- @param ProcessorIndex Specifies which processor the callback function applies to.\r
- @param PeriodicCallback A pointer to a function of type PERIODIC_CALLBACK that is the main\r
- periodic entry point of the debug agent.\r
-\r
- @retval EFI_SUCCESS The function completed successfully.\r
- @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
- function was previously registered.\r
- @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
- function.\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 ManageIvtEntryTable (EXCEPT_IPF_EXTERNAL_INTERRUPT, NULL, PeriodicCallback);\r
-}\r
-\r
-/**\r
- Registers a function to be called when a given processor exception occurs.\r
-\r
- This code executes in boot services context.\r
-\r
- @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
- @param ProcessorIndex Specifies which processor the callback function applies to.\r
- @param ExceptionCallback A pointer to a function of type EXCEPTION_CALLBACK that is called\r
- when the processor exception specified by ExceptionType occurs.\r
- @param ExceptionType Specifies which processor exception to hook.\r
-\r
- @retval EFI_SUCCESS The function completed successfully.\r
- @retval EFI_ALREADY_STARTED Non-NULL PeriodicCallback parameter when a callback\r
- function was previously registered.\r
- @retval EFI_OUT_OF_RESOURCES System has insufficient memory resources to register new callback\r
- function.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-RegisterExceptionCallback (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN EFI_EXCEPTION_CALLBACK ExceptionCallback,\r
- IN EFI_EXCEPTION_TYPE ExceptionType\r
- )\r
-{\r
- return ManageIvtEntryTable (\r
- ExceptionType,\r
- (BUNDLE *) ((EFI_PLABEL *) HookStub)->EntryPoint,\r
- ExceptionCallback\r
- );\r
-}\r
-\r
-/**\r
- Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
- causes a fresh memory fetch to retrieve code to be executed.\r
-\r
- @param This A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
- @param ProcessorIndex Specifies which processor's instruction cache is to be invalidated.\r
- @param Start Specifies the physical base of the memory range to be invalidated.\r
- @param Length Specifies the minimum number of bytes in the processor's instruction\r
- 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 UINTN Length\r
- )\r
-{\r
- InstructionCacheFlush (Start, Length);\r
- return EFI_SUCCESS;\r
-}\r