/** @file\r
CPU Exception Library provides PEI/DXE/SMM CPU common exception handler.\r
\r
-Copyright (c) 2012 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials are licensed and made available under\r
the terms and conditions of the BSD License that accompanies this distribution.\r
The full text of the license may be found at\r
#include "CpuExceptionCommon.h"\r
#include <Library/DebugLib.h>\r
\r
-//\r
-// Spinlock for CPU information display\r
-//\r
-SPIN_LOCK mDisplayMessageSpinLock;\r
-\r
-//\r
-// Image align size for DXE/SMM\r
-//\r
-CONST UINTN mImageAlignSize = SIZE_4KB;\r
-\r
-RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];\r
-EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];\r
-EFI_CPU_INTERRUPT_HANDLER *mExternalInterruptHandler = NULL;\r
-UINTN mEnabledInterruptNum = 0;\r
-\r
/**\r
- Common exception handler.\r
+ Internal worker function for common exception handler.\r
\r
- @param ExceptionType Exception type.\r
- @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
+ @param ExceptionType Exception type.\r
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.\r
+ @param ExceptionHandlerData Pointer to exception handler data.\r
**/\r
VOID\r
-EFIAPI\r
-CommonExceptionHandler (\r
- IN EFI_EXCEPTION_TYPE ExceptionType, \r
- IN EFI_SYSTEM_CONTEXT SystemContext\r
+CommonExceptionHandlerWorker (\r
+ IN EFI_EXCEPTION_TYPE ExceptionType,\r
+ IN EFI_SYSTEM_CONTEXT SystemContext,\r
+ IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
)\r
{\r
EXCEPTION_HANDLER_CONTEXT *ExceptionHandlerContext;\r
+ RESERVED_VECTORS_DATA *ReservedVectors;\r
+ EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;\r
\r
- ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (SystemContext.SystemContextIa32);\r
+ ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (SystemContext.SystemContextIa32);\r
+ ReservedVectors = ExceptionHandlerData->ReservedVectors;\r
+ ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;\r
\r
- switch (mReservedVectors[ExceptionType].Attribute) {\r
+ switch (ReservedVectors[ExceptionType].Attribute) {\r
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:\r
//\r
// Need to jmp to old IDT handler after this exception handler\r
//\r
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;\r
- ExceptionHandlerContext->OldIdtHandler = mReservedVectors[ExceptionType].ExceptonHandler;\r
+ ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;\r
break;\r
case EFI_VECTOR_HANDOFF_HOOK_AFTER:\r
while (TRUE) {\r
//\r
// If if anyone has gotten SPIN_LOCK for owner running hook after\r
//\r
- if (AcquireSpinLockOrFail (&mReservedVectors[ExceptionType].SpinLock)) {\r
+ if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {\r
//\r
// Need to execute old IDT handler before running this exception handler\r
//\r
- mReservedVectors[ExceptionType].ApicId = GetApicId ();\r
- ArchSaveExceptionContext (ExceptionType, SystemContext);\r
+ ReservedVectors[ExceptionType].ApicId = GetApicId ();\r
+ ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);\r
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;\r
- ExceptionHandlerContext->OldIdtHandler = mReservedVectors[ExceptionType].ExceptonHandler;\r
+ ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;\r
return;\r
}\r
//\r
// If failed to acquire SPIN_LOCK, check if it was locked by processor itself\r
//\r
- if (mReservedVectors[ExceptionType].ApicId == GetApicId ()) {\r
+ if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) {\r
//\r
- // Old IDT handler has been executed, then retore CPU exception content to\r
+ // Old IDT handler has been executed, then restore CPU exception content to\r
// run new exception handler.\r
//\r
- ArchRestoreExceptionContext (ExceptionType, SystemContext);\r
+ ArchRestoreExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);\r
//\r
// Rlease spin lock for ApicId\r
//\r
- ReleaseSpinLock (&mReservedVectors[ExceptionType].SpinLock);\r
+ ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock);\r
break;\r
}\r
CpuPause ();\r
CpuDeadLoop ();\r
break;\r
}\r
- \r
- if (mExternalInterruptHandler[ExceptionType] != NULL) {\r
- (mExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext);\r
+\r
+ if (ExternalInterruptHandler != NULL &&\r
+ ExternalInterruptHandler[ExceptionType] != NULL) {\r
+ (ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext);\r
} else if (ExceptionType < CPU_EXCEPTION_NUM) {\r
//\r
// Get Spinlock to display CPU information\r
//\r
- while (!AcquireSpinLockOrFail (&mDisplayMessageSpinLock)) {\r
+ while (!AcquireSpinLockOrFail (&ExceptionHandlerData->DisplayMessageSpinLock)) {\r
CpuPause ();\r
}\r
//\r
// Display ExceptionType, CPU information and Image information\r
- // \r
- DumpCpuContent (ExceptionType, SystemContext);\r
+ //\r
+ DumpImageAndCpuContent (ExceptionType, SystemContext);\r
//\r
// Release Spinlock of output message\r
//\r
- ReleaseSpinLock (&mDisplayMessageSpinLock);\r
+ ReleaseSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock);\r
//\r
// Enter a dead loop if needn't to execute old IDT handler further\r
//\r
- if (mReservedVectors[ExceptionType].Attribute != EFI_VECTOR_HANDOFF_HOOK_BEFORE) {\r
+ if (ReservedVectors[ExceptionType].Attribute != EFI_VECTOR_HANDOFF_HOOK_BEFORE) {\r
CpuDeadLoop ();\r
}\r
}\r
break;\r
}\r
}\r
- \r
- //\r
- // Save Interrupt number to global variable used for RegisterCpuInterruptHandler ()\r
- //\r
- mEnabledInterruptNum = ExceptionHandlerData->IdtEntryCount;\r
}\r
\r
/**\r
\r
@param[in] VectorInfo Pointer to reserved vector list.\r
@param[in, out] ExceptionHandlerData Pointer to exception handler data.\r
- \r
- @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized \r
+\r
+ @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized\r
with default exception handlers.\r
@retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.\r
@retval EFI_UNSUPPORTED This function is not supported.\r
return EFI_INVALID_PARAMETER;\r
}\r
}\r
- InitializeSpinLock (&mDisplayMessageSpinLock);\r
\r
- mExternalInterruptHandler = mExternalInterruptHandlerTable;\r
//\r
// Read IDT descriptor and calculate IDT size\r
//\r
\r
ExceptionHandlerData->IdtEntryCount = IdtEntryCount;\r
UpdateIdtTable (IdtTable, &TemplateMap, ExceptionHandlerData);\r
- mEnabledInterruptNum = IdtEntryCount;\r
+\r
return EFI_SUCCESS;\r
}\r
\r
/**\r
Registers a function to be called from the processor interrupt handler.\r
\r
- @param[in] InterruptType Defines which interrupt or exception to hook.\r
- @param[in] 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
+ @param[in] InterruptType Defines which interrupt or exception to hook.\r
+ @param[in] 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
+ @param[in] ExceptionHandlerData Pointer to exception handler data.\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
EFI_STATUS\r
RegisterCpuInterruptHandlerWorker (\r
IN EFI_EXCEPTION_TYPE InterruptType,\r
- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,\r
+ IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData\r
)\r
{\r
- if (InterruptType < 0 || InterruptType >= (EFI_EXCEPTION_TYPE)mEnabledInterruptNum ||\r
- mReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {\r
+ UINTN EnabledInterruptNum;\r
+ RESERVED_VECTORS_DATA *ReservedVectors;\r
+ EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;\r
+\r
+ EnabledInterruptNum = ExceptionHandlerData->IdtEntryCount;\r
+ ReservedVectors = ExceptionHandlerData->ReservedVectors;\r
+ ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;\r
+\r
+ if (InterruptType < 0 || InterruptType >= (EFI_EXCEPTION_TYPE)EnabledInterruptNum ||\r
+ ReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
- if (InterruptHandler == NULL && mExternalInterruptHandler[InterruptType] == NULL) {\r
+ if (InterruptHandler == NULL && ExternalInterruptHandler[InterruptType] == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (InterruptHandler != NULL && mExternalInterruptHandler[InterruptType] != NULL) {\r
+ if (InterruptHandler != NULL && ExternalInterruptHandler[InterruptType] != NULL) {\r
return EFI_ALREADY_STARTED;\r
}\r
\r
- mExternalInterruptHandler[InterruptType] = InterruptHandler;\r
+ ExternalInterruptHandler[InterruptType] = InterruptHandler;\r
return EFI_SUCCESS;\r
}\r
\r