TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuExceptionCommon.h File Reference

Go to the source code of this file.

Data Structures

struct  EXCEPTION_HANDLER_TEMPLATE_MAP
 
struct  EXCEPTION_HANDLER_DATA
 

Macros

#define CPU_EXCEPTION_NUM   32
 
#define CPU_INTERRUPT_NUM   256
 
#define HOOKAFTER_STUB_SIZE   18
 
#define IA32_PF_EC_P   BIT0
 
#define IA32_PF_EC_WR   BIT1
 
#define IA32_PF_EC_US   BIT2
 
#define IA32_PF_EC_RSVD   BIT3
 
#define IA32_PF_EC_ID   BIT4
 
#define IA32_PF_EC_PK   BIT5
 
#define IA32_PF_EC_SS   BIT6
 
#define IA32_PF_EC_SGX   BIT15
 
#define CPU_STACK_SWITCH_EXCEPTION_NUMBER    FixedPcdGetSize (PcdCpuStackSwitchExceptionList)
 
#define CPU_STACK_SWITCH_EXCEPTION_LIST    FixedPcdGetPtr (PcdCpuStackSwitchExceptionList)
 
#define CPU_KNOWN_GOOD_STACK_SIZE    FixedPcdGet32 (PcdCpuKnownGoodStackSize)
 
#define CPU_TSS_GDT_SIZE   (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)
 

Functions

VOID EFIAPI AsmGetTemplateAddressMap (OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap)
 
VOID ArchUpdateIdtEntry (OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry, IN UINTN InterruptHandler)
 
UINTN ArchGetIdtHandler (IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry)
 
VOID EFIAPI InternalPrintMessage (IN CONST CHAR8 *Format,...)
 
VOID DumpModuleImageInfo (IN UINTN CurrentEip)
 
VOID DumpImageAndCpuContent (IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext)
 
EFI_STATUS InitializeCpuExceptionHandlersWorker (IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL, IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
EFI_STATUS RegisterCpuInterruptHandlerWorker (IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
VOID UpdateIdtTable (IN IA32_IDT_GATE_DESCRIPTOR *IdtTable, IN EXCEPTION_HANDLER_TEMPLATE_MAP *TemplateMap, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
VOID ArchSaveExceptionContext (IN UINTN ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
VOID ArchRestoreExceptionContext (IN UINTN ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
VOID EFIAPI AsmVectorNumFixup (IN VOID *NewVectorAddr, IN UINT8 VectorNum, IN VOID *OldVectorAddr)
 
EFI_STATUS ReadAndVerifyVectorInfo (IN EFI_VECTOR_HANDOFF_INFO *VectorInfo, OUT RESERVED_VECTORS_DATA *ReservedVector, IN UINTN VectorCount)
 
CONST CHAR8 * GetExceptionNameStr (IN EFI_EXCEPTION_TYPE ExceptionType)
 
VOID CommonExceptionHandlerWorker (IN EFI_EXCEPTION_TYPE ExceptionType, IN EFI_SYSTEM_CONTEXT SystemContext, IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData)
 
EFI_STATUS ArchSetupExceptionStack (IN VOID *Buffer, IN OUT UINTN *BufferSize)
 
VOID EFIAPI AsmGetTssTemplateMap (OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap)
 

Variables

CONST UINT32 mErrorCodeFlag
 
CONST UINTN mDoFarReturnFlag
 

Detailed Description

Common header file for CPU Exception Handler Library.

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

Definition in file CpuExceptionCommon.h.

Macro Definition Documentation

◆ CPU_EXCEPTION_NUM

#define CPU_EXCEPTION_NUM   32

Definition at line 23 of file CpuExceptionCommon.h.

◆ CPU_INTERRUPT_NUM

#define CPU_INTERRUPT_NUM   256

Definition at line 24 of file CpuExceptionCommon.h.

◆ CPU_KNOWN_GOOD_STACK_SIZE

#define CPU_KNOWN_GOOD_STACK_SIZE    FixedPcdGet32 (PcdCpuKnownGoodStackSize)

Definition at line 47 of file CpuExceptionCommon.h.

◆ CPU_STACK_SWITCH_EXCEPTION_LIST

#define CPU_STACK_SWITCH_EXCEPTION_LIST    FixedPcdGetPtr (PcdCpuStackSwitchExceptionList)

Definition at line 44 of file CpuExceptionCommon.h.

◆ CPU_STACK_SWITCH_EXCEPTION_NUMBER

#define CPU_STACK_SWITCH_EXCEPTION_NUMBER    FixedPcdGetSize (PcdCpuStackSwitchExceptionList)

Definition at line 41 of file CpuExceptionCommon.h.

◆ CPU_TSS_GDT_SIZE

#define CPU_TSS_GDT_SIZE   (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)

Definition at line 50 of file CpuExceptionCommon.h.

◆ HOOKAFTER_STUB_SIZE

#define HOOKAFTER_STUB_SIZE   18

Definition at line 25 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_ID

#define IA32_PF_EC_ID   BIT4

Definition at line 34 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_P

#define IA32_PF_EC_P   BIT0

Definition at line 30 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_PK

#define IA32_PF_EC_PK   BIT5

Definition at line 35 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_RSVD

#define IA32_PF_EC_RSVD   BIT3

Definition at line 33 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_SGX

#define IA32_PF_EC_SGX   BIT15

Definition at line 37 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_SS

#define IA32_PF_EC_SS   BIT6

Definition at line 36 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_US

#define IA32_PF_EC_US   BIT2

Definition at line 32 of file CpuExceptionCommon.h.

◆ IA32_PF_EC_WR

#define IA32_PF_EC_WR   BIT1

Definition at line 31 of file CpuExceptionCommon.h.

Function Documentation

◆ ArchGetIdtHandler()

UINTN ArchGetIdtHandler ( IN IA32_IDT_GATE_DESCRIPTOR *  IdtEntry)

Read IDT handler value from IDT entry.

Parameters
IdtEntryPointer to IDT entry to be read.

Definition at line 37 of file ArchExceptionHandler.c.

◆ ArchRestoreExceptionContext()

VOID ArchRestoreExceptionContext ( IN UINTN  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext,
IN EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Restore CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.

Parameters
[in]ExceptionTypeException type.
[in]SystemContextPointer to EFI_SYSTEM_CONTEXT.
[in]ExceptionHandlerDataPointer to exception handler data.

Definition at line 91 of file ArchExceptionHandler.c.

◆ ArchSaveExceptionContext()

VOID ArchSaveExceptionContext ( IN UINTN  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext,
IN EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Save CPU exception context when handling EFI_VECTOR_HANDOFF_HOOK_AFTER case.

Parameters
[in]ExceptionTypeException type.
[in]SystemContextPointer to EFI_SYSTEM_CONTEXT.
[in]ExceptionHandlerDataPointer to exception handler data.

Definition at line 52 of file ArchExceptionHandler.c.

◆ ArchSetupExceptionStack()

EFI_STATUS ArchSetupExceptionStack ( IN VOID *  Buffer,
IN OUT UINTN BufferSize 
)

Setup separate stacks for certain exception handlers.

Parameters
[in]BufferPoint to buffer used to separate exception stack.
[in,out]BufferSizeOn input, it indicates the byte size of Buffer. If the size is not enough, the return status will be EFI_BUFFER_TOO_SMALL, and output BufferSize will be the size it needs.
Return values
EFI_SUCCESSThe stacks are assigned successfully.
EFI_BUFFER_TOO_SMALLThis BufferSize is too small.
EFI_UNSUPPORTEDThis function is not supported.

Setup separate stacks for certain exception handlers.

Parameters
[in]BufferPoint to buffer used to separate exception stack.
[in,out]BufferSizeOn input, it indicates the byte size of Buffer. If the size is not enough, the return status will be EFI_BUFFER_TOO_SMALL, and output BufferSize will be the size it needs.
Return values
EFI_SUCCESSThe stacks are assigned successfully.
EFI_BUFFER_TOO_SMALLThis BufferSize is too small.

Definition at line 119 of file ArchExceptionHandler.c.

◆ ArchUpdateIdtEntry()

VOID ArchUpdateIdtEntry ( OUT IA32_IDT_GATE_DESCRIPTOR *  IdtEntry,
IN UINTN  InterruptHandler 
)

Return address map of exception handler template so that C code can generate exception tables.

Parameters
IdtEntryPointer to IDT entry to be updated.
InterruptHandlerIDT handler value.

Definition at line 20 of file ArchExceptionHandler.c.

◆ AsmGetTemplateAddressMap()

VOID EFIAPI AsmGetTemplateAddressMap ( OUT EXCEPTION_HANDLER_TEMPLATE_MAP AddressMap)

Return address map of exception handler template so that C code can generate exception tables.

Parameters
AddressMapPointer to a buffer where the address map is returned.

◆ AsmGetTssTemplateMap()

VOID EFIAPI AsmGetTssTemplateMap ( OUT EXCEPTION_HANDLER_TEMPLATE_MAP AddressMap)

Return address map of exception handler template so that C code can generate exception tables. The template is only for exceptions using task gate instead of interrupt gate.

Parameters
AddressMapPointer to a buffer where the address map is returned.

◆ AsmVectorNumFixup()

VOID EFIAPI AsmVectorNumFixup ( IN VOID *  NewVectorAddr,
IN UINT8  VectorNum,
IN VOID *  OldVectorAddr 
)

Fix up the vector number and function address in the vector code.

Parameters
[in]NewVectorAddrNew vector handler address.
[in]VectorNumIndex of vector.
[in]OldVectorAddrOld vector handler address.

◆ CommonExceptionHandlerWorker()

VOID CommonExceptionHandlerWorker ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext,
IN EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Internal worker function for common exception handler.

Parameters
ExceptionTypeException type.
SystemContextPointer to EFI_SYSTEM_CONTEXT.
ExceptionHandlerDataPointer to exception handler data.

Definition at line 21 of file PeiDxeSmmCpuException.c.

◆ DumpImageAndCpuContent()

VOID DumpImageAndCpuContent ( IN EFI_EXCEPTION_TYPE  ExceptionType,
IN EFI_SYSTEM_CONTEXT  SystemContext 
)

Display CPU information.

Parameters
ExceptionTypeException type.
SystemContextPointer to EFI_SYSTEM_CONTEXT.

Definition at line 403 of file ArchExceptionHandler.c.

◆ DumpModuleImageInfo()

VOID DumpModuleImageInfo ( IN UINTN  CurrentEip)

Find and display image base address and return image base and its entry point.

Parameters
CurrentEipCurrent instruction pointer.

Definition at line 117 of file CpuExceptionCommon.c.

◆ GetExceptionNameStr()

CONST CHAR8 * GetExceptionNameStr ( IN EFI_EXCEPTION_TYPE  ExceptionType)

Get ASCII format string exception name by exception type.

Parameters
ExceptionTypeException type.
Returns
ASCII format string exception name.

Definition at line 105 of file CpuExceptionHandlerLib.c.

◆ InitializeCpuExceptionHandlersWorker()

EFI_STATUS InitializeCpuExceptionHandlersWorker ( IN EFI_VECTOR_HANDOFF_INFO *VectorInfo  OPTIONAL,
IN OUT EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Internal worker function to initialize exception handler.

Parameters
[in]VectorInfoPointer to reserved vector list.
[in,out]ExceptionHandlerDataPointer to exception handler data.
Return values
EFI_SUCCESSCPU Exception Entries have been successfully initialized with default exception handlers.
EFI_INVALID_PARAMETERVectorInfo includes the invalid content if VectorInfo is not NULL.
EFI_UNSUPPORTEDThis function is not supported.

Definition at line 251 of file PeiDxeSmmCpuException.c.

◆ InternalPrintMessage()

VOID EFIAPI InternalPrintMessage ( IN CONST CHAR8 *  Format,
  ... 
)

Prints a message to the serial port.

Parameters
FormatFormat string for the message to print.
...Variable argument list whose contents are accessed based on the format string specified by Format.

Definition at line 75 of file CpuExceptionHandlerLib.c.

◆ ReadAndVerifyVectorInfo()

EFI_STATUS ReadAndVerifyVectorInfo ( IN EFI_VECTOR_HANDOFF_INFO VectorInfo,
OUT RESERVED_VECTORS_DATA ReservedVector,
IN UINTN  VectorCount 
)

Read and save reserved vector information

Parameters
[in]VectorInfoPointer to reserved vector list.
[out]ReservedVectorPointer to reserved vector data buffer.
[in]VectorCountVector number to be updated.
Returns
EFI_SUCCESS Read and save vector info successfully.
Return values
EFI_INVALID_PARAMETERVectorInfo includes the invalid content if VectorInfo is not NULL.

Definition at line 166 of file CpuExceptionCommon.c.

◆ RegisterCpuInterruptHandlerWorker()

EFI_STATUS RegisterCpuInterruptHandlerWorker ( IN EFI_EXCEPTION_TYPE  InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler,
IN EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Registers a function to be called from the processor interrupt handler.

Parameters
[in]InterruptTypeDefines which interrupt or exception to hook.
[in]InterruptHandlerA pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs. If this parameter is NULL, then the handler will be uninstalled
[in]ExceptionHandlerDataPointer to exception handler data.
Return values
EFI_SUCCESSThe handler for the processor interrupt was successfully installed or uninstalled.
EFI_ALREADY_STARTEDInterruptHandler is not NULL, and a handler for InterruptType was previously installed.
EFI_INVALID_PARAMETERInterruptHandler is NULL, and a handler for InterruptType was not previously installed.
EFI_UNSUPPORTEDThe interrupt specified by InterruptType is not supported, or this function is not supported.

Definition at line 307 of file PeiDxeSmmCpuException.c.

◆ UpdateIdtTable()

VOID UpdateIdtTable ( IN IA32_IDT_GATE_DESCRIPTOR *  IdtTable,
IN EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap,
IN EXCEPTION_HANDLER_DATA ExceptionHandlerData 
)

Internal worker function to update IDT entries accordling to vector attributes.

Parameters
[in]IdtTablePointer to IDT table.
[in]TemplateMapPointer to a buffer where the address map is returned.
[in]ExceptionHandlerDataPointer to exception handler data.

Definition at line 176 of file PeiDxeSmmCpuException.c.

Variable Documentation

◆ mDoFarReturnFlag

CONST UINTN mDoFarReturnFlag
extern

Definition at line 15 of file DxeException.c.

◆ mErrorCodeFlag

CONST UINT32 mErrorCodeFlag
extern

Definition at line 17 of file CpuExceptionCommon.c.