CpuExceptionHandlerLib: Add comments to make code more readable

Today's implementation of handling HOOK_BEFORE and HOOK_AFTER is
a bit complex. More comments is better.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Fan Jeff <vanjeff_919@hotmail.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
This commit is contained in:
Ruiyu Ni
2018-08-31 15:30:26 +08:00
parent 4cf022f2f1
commit 87a9dd0d15
3 changed files with 18 additions and 10 deletions

View File

@@ -40,7 +40,8 @@ CommonExceptionHandlerWorker (
switch (ReservedVectors[ExceptionType].Attribute) {
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
//
// Need to jmp to old IDT handler after this exception handler
// The new exception handler registered by RegisterCpuInterruptHandler() is executed BEFORE original handler.
// Save the original handler to stack so the assembly code can jump to it instead of returning from handler.
//
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
@@ -48,11 +49,13 @@ CommonExceptionHandlerWorker (
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
while (TRUE) {
//
// If if anyone has gotten SPIN_LOCK for owner running hook after
// If spin-lock can be acquired, it's the first time entering here.
//
if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {
//
// Need to execute old IDT handler before running this exception handler
// The new exception handler registered by RegisterCpuInterruptHandler() is executed AFTER original handler.
// Save the original handler to stack but skip running the new handler so the original handler is executed
// firstly.
//
ReservedVectors[ExceptionType].ApicId = GetApicId ();
ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
@@ -61,7 +64,8 @@ CommonExceptionHandlerWorker (
return;
}
//
// If failed to acquire SPIN_LOCK, check if it was locked by processor itself
// If spin-lock cannot be acquired, it's the second time entering here.
// 'break' instead of 'return' is used so the new exception handler can be executed.
//
if (ReservedVectors[ExceptionType].ApicId == GetApicId ()) {
//