From 9db15f8148081688a0679b76a7258e9fc66107bc Mon Sep 17 00:00:00 2001 From: Jeff Fan Date: Tue, 24 May 2016 21:09:22 +0800 Subject: [PATCH] UefiCpuPkg/ExceptionLib: Update UpdateIdtTable() Add parameter CpuExceptionData for UpdateIdtTable(). Cc: Michael Kinney Cc: Jiewen Yao Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Feng Tian --- .../CpuExceptionCommon.h | 9 +++--- .../CpuExceptionHandlerLib/DxeException.c | 23 ++++++++++----- .../PeiDxeSmmCpuException.c | 29 +++++++++++-------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h index 812469babe..99be61f860 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h @@ -174,16 +174,17 @@ RegisterCpuInterruptHandlerWorker ( /** Internal worker function to update IDT entries accordling to vector attributes. - @param[in] IdtTable Pointer to IDT table. - @param[in] TemplateMap Pointer to a buffer where the address map is returned. - @param[in] IdtEntryCount IDT entries number to be updated. + @param[in] IdtTable Pointer to IDT table. + @param[in] TemplateMap Pointer to a buffer where the address map is + returned. + @param[in] ExceptionHandlerData Pointer to exception handler data. **/ VOID UpdateIdtTable ( IN IA32_IDT_GATE_DESCRIPTOR *IdtTable, IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap, - IN UINTN IdtEntryCount + IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData ); /** diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c index 92de04ce08..cffb13aea9 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c @@ -83,20 +83,22 @@ InitializeCpuInterruptHandlers ( UINTN Index; UINTN InterruptEntry; UINT8 *InterruptEntryCode; + RESERVED_VECTORS_DATA *ReservedVectors; + EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler; - mReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM); - ASSERT (mReservedVectors != NULL); - SetMem ((VOID *) mReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff); + ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM); + ASSERT (ReservedVectors != NULL); + SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff); if (VectorInfo != NULL) { - Status = ReadAndVerifyVectorInfo (VectorInfo, mReservedVectors, CPU_INTERRUPT_NUM); + Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_INTERRUPT_NUM); if (EFI_ERROR (Status)) { - FreePool (mReservedVectors); + FreePool (ReservedVectors); return EFI_INVALID_PARAMETER; } } InitializeSpinLock (&mDisplayMessageSpinLock); - mExternalInterruptHandler = AllocateZeroPool (sizeof (EFI_CPU_INTERRUPT_HANDLER) * CPU_INTERRUPT_NUM); - ASSERT (mExternalInterruptHandler != NULL); + ExternalInterruptHandler = AllocateZeroPool (sizeof (EFI_CPU_INTERRUPT_HANDLER) * CPU_INTERRUPT_NUM); + ASSERT (ExternalInterruptHandler != NULL); // // Read IDT descriptor and calculate IDT size @@ -130,7 +132,12 @@ InitializeCpuInterruptHandlers ( } TemplateMap.ExceptionStart = (UINTN) InterruptEntryCode; - UpdateIdtTable (IdtTable, &TemplateMap, CPU_INTERRUPT_NUM); + mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM; + mExceptionHandlerData.ReservedVectors = ReservedVectors; + mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler; + InitializeSpinLock (&mExceptionHandlerData.DisplayMessageSpinLock); + + UpdateIdtTable (IdtTable, &TemplateMap, &mExceptionHandlerData); // // Load Interrupt Descriptor Table diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 0b12b6d84f..4a3aad896d 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -127,47 +127,50 @@ CommonExceptionHandler ( /** Internal worker function to update IDT entries accordling to vector attributes. - @param[in] IdtTable Pointer to IDT table. - @param[in] TemplateMap Pointer to a buffer where the address map is returned. - @param[in] IdtEntryCount IDT entries number to be updated. + @param[in] IdtTable Pointer to IDT table. + @param[in] TemplateMap Pointer to a buffer where the address map is + returned. + @param[in] ExceptionHandlerData Pointer to exception handler data. **/ VOID UpdateIdtTable ( IN IA32_IDT_GATE_DESCRIPTOR *IdtTable, IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap, - IN UINTN IdtEntryCount + IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData ) { UINT16 CodeSegment; UINTN Index; UINTN InterruptHandler; + RESERVED_VECTORS_DATA *ReservedVectors; + ReservedVectors = ExceptionHandlerData->ReservedVectors; // // Use current CS as the segment selector of interrupt gate in IDT // CodeSegment = AsmReadCs (); - for (Index = 0; Index < IdtEntryCount; Index ++) { + for (Index = 0; Index < ExceptionHandlerData->IdtEntryCount; Index ++) { IdtTable[Index].Bits.Selector = CodeSegment; // // Check reserved vectors attributes // - switch (mReservedVectors[Index].Attribute) { + switch (ReservedVectors[Index].Attribute) { case EFI_VECTOR_HANDOFF_DO_NOT_HOOK: // // Keep original IDT entry // continue; case EFI_VECTOR_HANDOFF_HOOK_AFTER: - InitializeSpinLock (&mReservedVectors[Index].SpinLock); + InitializeSpinLock (&ReservedVectors[Index].SpinLock); CopyMem ( - (VOID *) mReservedVectors[Index].HookAfterStubHeaderCode, + (VOID *) ReservedVectors[Index].HookAfterStubHeaderCode, (VOID *) TemplateMap->HookAfterStubHeaderStart, TemplateMap->ExceptionStubHeaderSize ); AsmVectorNumFixup ( - (VOID *) mReservedVectors[Index].HookAfterStubHeaderCode, + (VOID *) ReservedVectors[Index].HookAfterStubHeaderCode, (UINT8) Index, (VOID *) TemplateMap->HookAfterStubHeaderStart ); @@ -178,7 +181,7 @@ UpdateIdtTable ( // // Save original IDT handler address // - mReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]); + ReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]); // // Go on the following code // @@ -195,7 +198,7 @@ UpdateIdtTable ( // // Save Interrupt number to global variable used for RegisterCpuInterruptHandler () // - mEnabledInterruptNum = IdtEntryCount; + mEnabledInterruptNum = ExceptionHandlerData->IdtEntryCount; } /** @@ -249,7 +252,9 @@ InitializeCpuExceptionHandlersWorker ( IdtTable = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; AsmGetTemplateAddressMap (&TemplateMap); ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE); - UpdateIdtTable (IdtTable, &TemplateMap, IdtEntryCount); + + ExceptionHandlerData->IdtEntryCount = IdtEntryCount; + UpdateIdtTable (IdtTable, &TemplateMap, ExceptionHandlerData); mEnabledInterruptNum = IdtEntryCount; return EFI_SUCCESS; } -- 2.39.2