/** Common exception handler. @param ExceptionType Exception type. @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. **/ VOID EFIAPI CommonExceptionHandler ( IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext ) { // // Display ExceptionType, CPU information and Image information // DumpCpuContent (ExceptionType, SystemContext); // // Enter a dead loop. // CpuDeadLoop (); }
/** Internal worker function for common exception handler. @param ExceptionType Exception type. @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. @param ExceptionHandlerData Pointer to exception handler data. **/ VOID CommonExceptionHandlerWorker ( IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData ) { EXCEPTION_HANDLER_CONTEXT *ExceptionHandlerContext; RESERVED_VECTORS_DATA *ReservedVectors; EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler; ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (SystemContext.SystemContextIa32); ReservedVectors = ExceptionHandlerData->ReservedVectors; ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler; switch (ReservedVectors[ExceptionType].Attribute) { case EFI_VECTOR_HANDOFF_HOOK_BEFORE: // // Need to jmp to old IDT handler after this exception handler // ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE; ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler; break; case EFI_VECTOR_HANDOFF_HOOK_AFTER: while (TRUE) { // // If if anyone has gotten SPIN_LOCK for owner running hook after // if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) { // // Need to execute old IDT handler before running this exception handler // ReservedVectors[ExceptionType].ApicId = GetApicId (); ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData); ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE; ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler; return; } // // If failed to acquire SPIN_LOCK, check if it was locked by processor itself // if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) { // // Old IDT handler has been executed, then restore CPU exception content to // run new exception handler. // ArchRestoreExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData); // // Rlease spin lock for ApicId // ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock); break; } CpuPause (); } break; case 0xffffffff: break; default: // // It should never reach here // CpuDeadLoop (); break; } if (ExternalInterruptHandler != NULL && ExternalInterruptHandler[ExceptionType] != NULL) { (ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext); } else if (ExceptionType < CPU_EXCEPTION_NUM) { // // Get Spinlock to display CPU information // while (!AcquireSpinLockOrFail (&ExceptionHandlerData->DisplayMessageSpinLock)) { CpuPause (); } // // Display ExceptionType, CPU information and Image information // DumpCpuContent (ExceptionType, SystemContext); // // Release Spinlock of output message // ReleaseSpinLock (&ExceptionHandlerData->DisplayMessageSpinLock); // // Enter a dead loop if needn't to execute old IDT handler further // if (ReservedVectors[ExceptionType].Attribute != EFI_VECTOR_HANDOFF_HOOK_BEFORE) { CpuDeadLoop (); } } }