TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuExceptionHandlerTestCommon.c File Reference

Go to the source code of this file.

Functions

VOID EFIAPI INTnExceptionHandler (IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
 
VOID EFIAPI RestoreRegistersPerCpu (IN VOID *Buffer)
 
VOID RestoreAllCpuRegisters (MP_SERVICES *MpServices, OPTIONAL CPU_REGISTER_BUFFER *CpuOriginalRegisterBuffer, UINTN BspProcessorNum)
 
VOID EFIAPI SaveRegisterPerCpu (IN VOID *Buffer)
 
CPU_REGISTER_BUFFERSaveAllCpuRegisters (MP_SERVICES *MpServices, OPTIONAL UINTN BspProcessorNum)
 
VOID EFIAPI InitializeIdtPerAp (IN VOID *Buffer)
 
VOID InitializeApIdt (MP_SERVICES MpServices, VOID *BspIdtr)
 
UNIT_TEST_STATUS EFIAPI TestRegisterHandlerForNoErrorCodeException (IN UNIT_TEST_CONTEXT Context)
 
VOID GetBspStackBase (OUT UINTN *StackBase)
 
VOID EFIAPI GetStackBasePerAp (OUT VOID *ApStackBase)
 
UINTNGetAllCpuStackBase (MP_SERVICES *MpServices, UINTN BspProcessorNum)
 
BOOLEAN FindPFAddressInPageTable (OUT UINTN *PFAddress)
 
UNIT_TEST_STATUS EFIAPI TestRegisterHandlerForGPAndPF (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI TestCpuContextConsistency (IN UNIT_TEST_CONTEXT Context)
 
VOID EFIAPI InitializeExceptionStackSwitchHandlersPerAp (IN OUT VOID *Buffer)
 
EXCEPTION_STACK_SWITCH_CONTEXTInitializeMpExceptionStackSwitchHandlers (MP_SERVICES MpServices, UINTN BspProcessorNum)
 
UNIT_TEST_STATUS EFIAPI TestCpuStackGuardInBspAndAp (IN UNIT_TEST_CONTEXT Context)
 
EFI_STATUS AddCommonTestCase (IN UNIT_TEST_FRAMEWORK_HANDLE Framework)
 

Variables

UINTN mFaultInstructionLength = 0
 
EFI_EXCEPTION_TYPE mExceptionType = 256
 
UINTN mNumberOfProcessors = 1
 
UINTN mRspAddress [2] = { 0 }
 
CONST UINT32 mErrorCodeExceptionFlag = 0x20227d00
 

Detailed Description

Unit tests of the CpuExceptionHandlerLib.

Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CpuExceptionHandlerTestCommon.c.

Function Documentation

◆ AddCommonTestCase()

EFI_STATUS AddCommonTestCase ( IN UNIT_TEST_FRAMEWORK_HANDLE  Framework)

Create CpuExceptionLibUnitTestSuite and add test case.

Parameters
[in]FrameworkHandleUnit test framework.
Returns
EFI_SUCCESS The unit test suite was created.
Return values
EFI_OUT_OF_RESOURCESThere are not enough resources available to initialize the unit test suite.

Definition at line 828 of file CpuExceptionHandlerTestCommon.c.

◆ FindPFAddressInPageTable()

BOOLEAN FindPFAddressInPageTable ( OUT UINTN PFAddress)

Find not present or ReadOnly address in page table.

Parameters
[out]PFAddressAccess to the address which is not permitted will trigger PF exceptions.
Return values
TRUEFound not present or ReadOnly address in page table.
FALSEFailed to found PFAddress in page table.

Definition at line 382 of file CpuExceptionHandlerTestCommon.c.

◆ GetAllCpuStackBase()

UINTN * GetAllCpuStackBase ( MP_SERVICES MpServices,
UINTN  BspProcessorNum 
)

Get all Cpu stack base.

Parameters
[in]MpServicesMpServices.
[in]BspProcessorNumBsp processor number.
Returns
Pointer to the allocated CpuStackBaseBuffer.

Definition at line 340 of file CpuExceptionHandlerTestCommon.c.

◆ GetBspStackBase()

VOID GetBspStackBase ( OUT UINTN StackBase)

Get Bsp stack base.

Parameters
[out]StackBasePointer to stack base of BSP.

Definition at line 277 of file CpuExceptionHandlerTestCommon.c.

◆ GetStackBasePerAp()

VOID EFIAPI GetStackBasePerAp ( OUT VOID *  ApStackBase)

Get Ap stack base procedure.

Parameters
[out]ApStackBasePointer to Ap stack base.

Definition at line 321 of file CpuExceptionHandlerTestCommon.c.

◆ InitializeApIdt()

VOID InitializeApIdt ( MP_SERVICES  MpServices,
VOID *  BspIdtr 
)

Initialize all Ap Idt.

Parameters
[in]MpServicesMpServices.
[in]BspIdtrPointer to IA32_DESCRIPTOR allocated by Bsp.

Definition at line 199 of file CpuExceptionHandlerTestCommon.c.

◆ InitializeExceptionStackSwitchHandlersPerAp()

VOID EFIAPI InitializeExceptionStackSwitchHandlersPerAp ( IN OUT VOID *  Buffer)

Initializes CPU exceptions handlers for the sake of stack switch requirement.

This function is a wrapper of InitializeSeparateExceptionStacks. It's mainly for the sake of AP's init because of EFI_AP_PROCEDURE API requirement.

Parameters
[in,out]BufferThe pointer to private data buffer.

Definition at line 595 of file CpuExceptionHandlerTestCommon.c.

◆ InitializeIdtPerAp()

VOID EFIAPI InitializeIdtPerAp ( IN VOID *  Buffer)

Initialize Ap Idt Procedure.

Parameters
[in]BufferArgument of the procedure.

Definition at line 185 of file CpuExceptionHandlerTestCommon.c.

◆ InitializeMpExceptionStackSwitchHandlers()

EXCEPTION_STACK_SWITCH_CONTEXT * InitializeMpExceptionStackSwitchHandlers ( MP_SERVICES  MpServices,
UINTN  BspProcessorNum 
)

Initializes MP exceptions handlers for the sake of stack switch requirement.

This function will allocate required resources required to setup stack switch and pass them through SwitchStackData to each logic processor.

Parameters
[in,out]MpServicesMpServices.
[in,out]BspProcessorNumBsp processor number.
Returns
Pointer to the allocated SwitchStackData.

Definition at line 624 of file CpuExceptionHandlerTestCommon.c.

◆ INTnExceptionHandler()

VOID EFIAPI INTnExceptionHandler ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

Special handler for exception triggered by INTn instruction. This hanlder only modifies a global variable for check.

Parameters
ExceptionTypeException type.
SystemContextPointer to EFI_SYSTEM_CONTEXT.

Definition at line 36 of file CpuExceptionHandlerTestCommon.c.

◆ RestoreAllCpuRegisters()

VOID RestoreAllCpuRegisters ( MP_SERVICES MpServices,
OPTIONAL CPU_REGISTER_BUFFER CpuOriginalRegisterBuffer,
UINTN  BspProcessorNum 
)

Restore cpu original registers before exit test case.

Parameters
[in]MpServicesMpServices.
[in]CpuOriginalRegisterBufferAddress of CpuOriginalRegisterBuffer.
[in]BspProcessorNumBsp processor number.

Definition at line 84 of file CpuExceptionHandlerTestCommon.c.

◆ RestoreRegistersPerCpu()

VOID EFIAPI RestoreRegistersPerCpu ( IN VOID *  Buffer)

Restore cpu original registers before exit test case.

Parameters
[in]BufferArgument of the procedure.

Definition at line 51 of file CpuExceptionHandlerTestCommon.c.

◆ SaveAllCpuRegisters()

CPU_REGISTER_BUFFER * SaveAllCpuRegisters ( MP_SERVICES MpServices,
OPTIONAL UINTN  BspProcessorNum 
)

Store cpu registers before the test case starts.

Parameters
[in]MpServicesMpServices.
[in]BspProcessorNumBsp processor number.
Returns
Pointer to the allocated CPU_REGISTER_BUFFER.

Definition at line 146 of file CpuExceptionHandlerTestCommon.c.

◆ SaveRegisterPerCpu()

VOID EFIAPI SaveRegisterPerCpu ( IN VOID *  Buffer)

Store cpu registers before the test case starts.

Parameters
[in]BufferArgument of the procedure.

Definition at line 118 of file CpuExceptionHandlerTestCommon.c.

◆ TestCpuContextConsistency()

UNIT_TEST_STATUS EFIAPI TestCpuContextConsistency ( IN UNIT_TEST_CONTEXT  Context)

Test if Cpu Context is consistent before and after exception.

Parameters
[in]Context[Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it.
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 536 of file CpuExceptionHandlerTestCommon.c.

◆ TestCpuStackGuardInBspAndAp()

UNIT_TEST_STATUS EFIAPI TestCpuStackGuardInBspAndAp ( IN UNIT_TEST_CONTEXT  Context)

Test if stack overflow is captured by CpuStackGuard in both Bsp and AP.

Parameters
[in]Context[Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it.
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 728 of file CpuExceptionHandlerTestCommon.c.

◆ TestRegisterHandlerForGPAndPF()

UNIT_TEST_STATUS EFIAPI TestRegisterHandlerForGPAndPF ( IN UNIT_TEST_CONTEXT  Context)

Test if exception handler can registered/unregistered for GP and PF.

Parameters
[in]Context[Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it.
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 471 of file CpuExceptionHandlerTestCommon.c.

◆ TestRegisterHandlerForNoErrorCodeException()

UNIT_TEST_STATUS EFIAPI TestRegisterHandlerForNoErrorCodeException ( IN UNIT_TEST_CONTEXT  Context)

Check if exception handler can registered/unregistered for no error code exception.

Parameters
[in]Context[Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it.
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 233 of file CpuExceptionHandlerTestCommon.c.

Variable Documentation

◆ mErrorCodeExceptionFlag

CONST UINT32 mErrorCodeExceptionFlag = 0x20227d00

Definition at line 25 of file CpuExceptionHandlerTestCommon.c.

◆ mExceptionType

EFI_EXCEPTION_TYPE mExceptionType = 256

Definition at line 15 of file CpuExceptionHandlerTestCommon.c.

◆ mFaultInstructionLength

UINTN mFaultInstructionLength = 0

Definition at line 14 of file CpuExceptionHandlerTestCommon.c.

◆ mNumberOfProcessors

UINTN mNumberOfProcessors = 1

Definition at line 16 of file CpuExceptionHandlerTestCommon.c.

◆ mRspAddress

UINTN mRspAddress[2] = { 0 }

Definition at line 17 of file CpuExceptionHandlerTestCommon.c.