+++ /dev/null
-/** @file\r
-\r
- Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r
- \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
-/** @file\r
- DXE Cpu Driver.\r
- \r
- May need some porting work for platform specifics.\r
-\r
- Copyright (c) 2008, Apple Inc \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 "CpuDxe.h"\r
-\r
-EFI_PERIODIC_CALLBACK gPeriodicCallBack = (EFI_PERIODIC_CALLBACK)NULL;\r
-\r
-EFI_DEBUG_SUPPORT_PERIODIC_CALLBACK_PROTOCOL *gDebugSupportCallback = NULL;\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportGetMaximumProcessorIndex (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- OUT UINTN *MaxProcessorIndex\r
- )\r
-/*++\r
-\r
-Routine Description: This is a DebugSupport protocol member function.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- MaxProcessorIndex - The maximuim supported processor index\r
-\r
-Returns:\r
- Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
-\r
---*/\r
-{\r
- *MaxProcessorIndex = 0;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportRegisterPeriodicCallback (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN EFI_PERIODIC_CALLBACK PeriodicCallback\r
- )\r
-/*++\r
-\r
-Routine Description: This is a DebugSupport protocol member function.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- PeriodicCallback - Callback function\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS\r
- EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
- no handler registered for it\r
- EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.\r
-\r
- Other possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if ((gPeriodicCallBack != (EFI_PERIODIC_CALLBACK)NULL) && (PeriodicCallback != (EFI_PERIODIC_CALLBACK)NULL)) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
- \r
- gPeriodicCallBack = PeriodicCallback;\r
- \r
- if (gDebugSupportCallback != NULL) {\r
- //\r
- // We can only update this protocol if the Register Protocol Notify has fired. If it fires \r
- // after this call it will update with gPeriodicCallBack value.\r
- //\r
- gDebugSupportCallback->PeriodicCallback = gPeriodicCallBack;\r
- }\r
- \r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportRegisterExceptionCallback (\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
-Routine Description:\r
- This is a DebugSupport protocol member function.\r
-\r
- This code executes in boot services context.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- NewCallback - Callback function\r
- ExceptionType - Which exception to hook\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS\r
- EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
- no handler registered for it\r
- EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.\r
-\r
- Other possible return values are passed through from UnHookEntry and HookEntry.\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return RegisterDebuggerInterruptHandler (ExceptionType, NewCallback);\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-DebugSupportInvalidateInstructionCache (\r
- IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
- IN UINTN ProcessorIndex,\r
- IN VOID *Start,\r
- IN UINT64 Length\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is a DebugSupport protocol member function.\r
- Calls assembly routine to flush cache.\r
-\r
-Arguments:\r
- This - The DebugSupport instance\r
- ProcessorIndex - Which processor the callback applies to.\r
- Start - Physical base of the memory range to be invalidated\r
- Length - mininum number of bytes in instruction cache to invalidate\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - always return success\r
-\r
---*/\r
-{\r
- if (ProcessorIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- InvalidateInstructionCache();\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-//\r
-// This is a global that is the actual interface\r
-//\r
-EFI_DEBUG_SUPPORT_PROTOCOL gDebugSupportProtocolInterface = {\r
- IsaArm, // Fixme to be more generic\r
- DebugSupportGetMaximumProcessorIndex,\r
- DebugSupportRegisterPeriodicCallback,\r
- DebugSupportRegisterExceptionCallback,\r
- DebugSupportInvalidateInstructionCache\r
-};\r
-\r
-\r
-VOID\r
-EFIAPI\r
-DebugSupportPeriodicCallbackEventProtocolNotify (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- EFI_STATUS Status;\r
- \r
- Status = gBS->LocateProtocol (&gEfiDebugSupportPeriodicCallbackProtocolGuid, NULL, (VOID **)&gDebugSupportCallback);\r
- if (!EFI_ERROR (Status)) {\r
- gDebugSupportCallback->PeriodicCallback = gPeriodicCallBack;\r
- }\r
-}\r
-\r
-VOID *gRegistration = NULL;\r
-\r
-\r
-EFI_DEBUG_SUPPORT_PROTOCOL *\r
-InitilaizeDebugSupport (\r
- VOID\r
- )\r
-{\r
- // RPN gEfiDebugSupportPeriodicCallbackProtocolGuid\r
- EFI_STATUS Status;\r
- EFI_EVENT Event;\r
-\r
- if (!FeaturePcdGet (PcdCpuDxeProduceDebugSupport)) {\r
- // Don't include this code unless Feature Flag is set\r
- return NULL;\r
- }\r
- \r
-\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL, \r
- TPL_CALLBACK, \r
- DebugSupportPeriodicCallbackEventProtocolNotify, \r
- NULL, \r
- &Event\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = gBS->RegisterProtocolNotify (&gEfiDebugSupportPeriodicCallbackProtocolGuid, Event, &gRegistration);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // We assume the Timer must depend on our driver to register interrupts so we don't need to do\r
- // a gBS->SignalEvent (Event) here to check to see if the protocol allready exists\r
- //\r
-\r
- return &gDebugSupportProtocolInterface;\r
-}\r
}\r
\r
\r
-/**\r
- This function registers and enables the handler specified by InterruptHandler for a processor \r
- interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the \r
- handler for the processor interrupt or exception type specified by InterruptType is uninstalled. \r
- The installed handler is called once for each processor interrupt or exception.\r
-\r
- @param InterruptType A pointer to the processor's current interrupt state. Set to TRUE if interrupts\r
- are enabled and FALSE if interrupts are disabled.\r
- @param InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called\r
- when a processor interrupt occurs. If this parameter is NULL, then the handler\r
- will be uninstalled.\r
-\r
- @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.\r
- @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was\r
- previously installed.\r
- @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not\r
- previously installed.\r
- @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported.\r
-\r
-**/\r
-EFI_STATUS\r
-RegisterDebuggerInterruptHandler (\r
- IN EFI_EXCEPTION_TYPE InterruptType,\r
- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
- )\r
-{\r
- if (InterruptType > MAX_ARM_EXCEPTION) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if ((InterruptHandler != NULL) && (gDebuggerExceptionHandlers[InterruptType] != NULL)) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- gDebuggerExceptionHandlers[InterruptType] = InterruptHandler;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
\r
\r
VOID\r
IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
)\r
{\r
- BOOLEAN Dispatched = FALSE;\r
- \r
- \r
+\r
if (ExceptionType <= MAX_ARM_EXCEPTION) {\r
- if (gDebuggerExceptionHandlers[ExceptionType]) {\r
- //\r
- // If DebugSupport hooked the interrupt call the handler. This does not disable \r
- // the normal handler.\r
- //\r
- gDebuggerExceptionHandlers[ExceptionType] (ExceptionType, SystemContext);\r
- Dispatched = TRUE;\r
- }\r
if (gExceptionHandlers[ExceptionType]) {\r
gExceptionHandlers[ExceptionType] (ExceptionType, SystemContext);\r
- Dispatched = TRUE;\r
+ return;\r
}\r
} else {\r
DEBUG ((EFI_D_ERROR, "Unknown exception type %d from %08x\n", ExceptionType, SystemContext.SystemContextArm->PC));\r
ASSERT (FALSE);\r
}\r
-\r
- if (Dispatched) {\r
- //\r
- // We did work so this was an expected ExceptionType\r
- //\r
- return;\r
- }\r
\r
if (ExceptionType == EXCEPT_ARM_SOFTWARE_INTERRUPT) {\r
//\r
// Save existing vector table, in case debugger is already hooked in\r
CopyMem ((VOID *)gDebuggerExceptionHandlers, (VOID *)VectorBase, sizeof (gDebuggerExceptionHandlers));\r
\r
- //\r
- // Initialize the C entry points for interrupts\r
- //\r
- for (Index = 0; Index <= MAX_ARM_EXCEPTION; Index++) {\r
- Status = RegisterInterruptHandler (Index, NULL);\r
- ASSERT_EFI_ERROR (Status);\r
- \r
- if (VectorBase[Index] == 0xEAFFFFFE) {\r
- // Exception handler contains branch to vector location (jmp $) so no handler\r
- // NOTE: This code assumes vectors are ARM and not Thumb code\r
- gDebuggerExceptionHandlers[Index] = NULL;\r
- }\r
- }\r
-\r
// Copy our assembly code into the page that contains the exception vectors. \r
CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length);\r
\r
Offset = (UINTN)CommonExceptionEntry - (UINTN)ExceptionHandlersStart;\r
*(UINTN *) ((UINT8 *)(UINTN)PcdGet32 (PcdCpuVectorBaseAddress) + Offset) = (UINTN)AsmCommonExceptionEntry;\r
\r
+ //\r
+ // Initialize the C entry points for interrupts\r
+ //\r
+ for (Index = 0; Index <= MAX_ARM_EXCEPTION; Index++) {\r
+ if ((gDebuggerExceptionHandlers[Index] == 0) || (gDebuggerExceptionHandlers[Index] == (VOID *)(UINTN)0xEAFFFFFE)) {\r
+ // Exception handler contains branch to vector location (jmp $) so no handler\r
+ // NOTE: This code assumes vectors are ARM and not Thumb code\r
+ Status = RegisterInterruptHandler (Index, NULL);\r
+ ASSERT_EFI_ERROR (Status);\r
+ } else {\r
+ // If the debugger has alread hooked put its vector back\r
+ VectorBase[Index] = (UINT32)(UINTN)gDebuggerExceptionHandlers[Index];\r
+ }\r
+ }\r
+\r
// Flush Caches since we updated executable stuff\r
InvalidateInstructionCacheRange ((VOID *)PcdGet32(PcdCpuVectorBaseAddress), Length);\r
\r