UefiCpuPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the UefiCpuPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
committed by
mergify[bot]
parent
91415a36ae
commit
053e878bfb
@@ -14,15 +14,15 @@
|
||||
//
|
||||
// 1 means an error code will be pushed, otherwise 0
|
||||
//
|
||||
CONST UINT32 mErrorCodeFlag = 0x20227d00;
|
||||
CONST UINT32 mErrorCodeFlag = 0x20227d00;
|
||||
|
||||
//
|
||||
// Define the maximum message length
|
||||
//
|
||||
#define MAX_DEBUG_MESSAGE_LENGTH 0x100
|
||||
|
||||
CONST CHAR8 mExceptionReservedStr[] = "Reserved";
|
||||
CONST CHAR8 *mExceptionNameStr[] = {
|
||||
CONST CHAR8 mExceptionReservedStr[] = "Reserved";
|
||||
CONST CHAR8 *mExceptionNameStr[] = {
|
||||
"#DE - Divide Error",
|
||||
"#DB - Debug",
|
||||
"NMI Interrupt",
|
||||
@@ -66,10 +66,10 @@ CONST CHAR8 *mExceptionNameStr[] = {
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
GetExceptionNameStr (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType
|
||||
)
|
||||
{
|
||||
if ((UINTN) ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {
|
||||
if ((UINTN)ExceptionType < EXCEPTION_KNOWN_NAME_NUM) {
|
||||
return mExceptionNameStr[ExceptionType];
|
||||
} else {
|
||||
return mExceptionReservedStr;
|
||||
@@ -115,13 +115,13 @@ InternalPrintMessage (
|
||||
**/
|
||||
VOID
|
||||
DumpModuleImageInfo (
|
||||
IN UINTN CurrentEip
|
||||
IN UINTN CurrentEip
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Pe32Data;
|
||||
VOID *PdbPointer;
|
||||
VOID *EntryPoint;
|
||||
EFI_STATUS Status;
|
||||
UINTN Pe32Data;
|
||||
VOID *PdbPointer;
|
||||
VOID *EntryPoint;
|
||||
|
||||
Pe32Data = PeCoffSearchImageBase (CurrentEip);
|
||||
if (Pe32Data == 0) {
|
||||
@@ -130,20 +130,22 @@ DumpModuleImageInfo (
|
||||
//
|
||||
// Find Image Base entry point
|
||||
//
|
||||
Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, &EntryPoint);
|
||||
Status = PeCoffLoaderGetEntryPoint ((VOID *)Pe32Data, &EntryPoint);
|
||||
if (EFI_ERROR (Status)) {
|
||||
EntryPoint = NULL;
|
||||
}
|
||||
|
||||
InternalPrintMessage ("!!!! Find image based on IP(0x%x) ", CurrentEip);
|
||||
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);
|
||||
PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)Pe32Data);
|
||||
if (PdbPointer != NULL) {
|
||||
InternalPrintMessage ("%a", PdbPointer);
|
||||
} else {
|
||||
InternalPrintMessage ("(No PDB) " );
|
||||
InternalPrintMessage ("(No PDB) ");
|
||||
}
|
||||
|
||||
InternalPrintMessage (
|
||||
" (ImageBase=%016lp, EntryPoint=%016p) !!!!\n",
|
||||
(VOID *) Pe32Data,
|
||||
(VOID *)Pe32Data,
|
||||
EntryPoint
|
||||
);
|
||||
}
|
||||
@@ -162,9 +164,9 @@ DumpModuleImageInfo (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ReadAndVerifyVectorInfo (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
|
||||
OUT RESERVED_VECTORS_DATA *ReservedVector,
|
||||
IN UINTN VectorCount
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
|
||||
OUT RESERVED_VECTORS_DATA *ReservedVector,
|
||||
IN UINTN VectorCount
|
||||
)
|
||||
{
|
||||
while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {
|
||||
@@ -174,10 +176,13 @@ ReadAndVerifyVectorInfo (
|
||||
//
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (VectorInfo->VectorNumber < VectorCount) {
|
||||
ReservedVector[VectorInfo->VectorNumber].Attribute = VectorInfo->Attribute;
|
||||
}
|
||||
VectorInfo ++;
|
||||
|
||||
VectorInfo++;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
@@ -20,21 +20,21 @@
|
||||
#include <Library/SynchronizationLib.h>
|
||||
#include <Library/CpuExceptionHandlerLib.h>
|
||||
|
||||
#define CPU_EXCEPTION_NUM 32
|
||||
#define CPU_INTERRUPT_NUM 256
|
||||
#define HOOKAFTER_STUB_SIZE 16
|
||||
#define CPU_EXCEPTION_NUM 32
|
||||
#define CPU_INTERRUPT_NUM 256
|
||||
#define HOOKAFTER_STUB_SIZE 16
|
||||
|
||||
//
|
||||
// Exception Error Code of Page-Fault Exception
|
||||
//
|
||||
#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 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
|
||||
|
||||
#include "ArchInterruptDefs.h"
|
||||
|
||||
@@ -47,26 +47,26 @@
|
||||
#define CPU_KNOWN_GOOD_STACK_SIZE \
|
||||
FixedPcdGet32 (PcdCpuKnownGoodStackSize)
|
||||
|
||||
#define CPU_TSS_GDT_SIZE (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)
|
||||
#define CPU_TSS_GDT_SIZE (SIZE_2KB + CPU_TSS_DESC_SIZE + CPU_TSS_SIZE)
|
||||
|
||||
//
|
||||
// Record exception handler information
|
||||
//
|
||||
typedef struct {
|
||||
UINTN ExceptionStart;
|
||||
UINTN ExceptionStubHeaderSize;
|
||||
UINTN HookAfterStubHeaderStart;
|
||||
UINTN ExceptionStart;
|
||||
UINTN ExceptionStubHeaderSize;
|
||||
UINTN HookAfterStubHeaderStart;
|
||||
} EXCEPTION_HANDLER_TEMPLATE_MAP;
|
||||
|
||||
typedef struct {
|
||||
UINTN IdtEntryCount;
|
||||
SPIN_LOCK DisplayMessageSpinLock;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
UINTN IdtEntryCount;
|
||||
SPIN_LOCK DisplayMessageSpinLock;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
} EXCEPTION_HANDLER_DATA;
|
||||
|
||||
extern CONST UINT32 mErrorCodeFlag;
|
||||
extern CONST UINTN mDoFarReturnFlag;
|
||||
extern CONST UINT32 mErrorCodeFlag;
|
||||
extern CONST UINTN mDoFarReturnFlag;
|
||||
|
||||
/**
|
||||
Return address map of exception handler template so that C code can generate
|
||||
@@ -77,7 +77,7 @@ extern CONST UINTN mDoFarReturnFlag;
|
||||
VOID
|
||||
EFIAPI
|
||||
AsmGetTemplateAddressMap (
|
||||
OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
|
||||
OUT EXCEPTION_HANDLER_TEMPLATE_MAP *AddressMap
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -90,8 +90,8 @@ AsmGetTemplateAddressMap (
|
||||
**/
|
||||
VOID
|
||||
ArchUpdateIdtEntry (
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ ArchUpdateIdtEntry (
|
||||
**/
|
||||
UINTN
|
||||
ArchGetIdtHandler (
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -128,7 +128,7 @@ InternalPrintMessage (
|
||||
**/
|
||||
VOID
|
||||
DumpModuleImageInfo (
|
||||
IN UINTN CurrentEip
|
||||
IN UINTN CurrentEip
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -139,8 +139,8 @@ DumpModuleImageInfo (
|
||||
**/
|
||||
VOID
|
||||
DumpImageAndCpuContent (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -157,8 +157,8 @@ DumpImageAndCpuContent (
|
||||
**/
|
||||
EFI_STATUS
|
||||
InitializeCpuExceptionHandlersWorker (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -180,9 +180,9 @@ InitializeCpuExceptionHandlersWorker (
|
||||
**/
|
||||
EFI_STATUS
|
||||
RegisterCpuInterruptHandlerWorker (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -210,9 +210,9 @@ UpdateIdtTable (
|
||||
**/
|
||||
VOID
|
||||
ArchSaveExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -224,9 +224,9 @@ ArchSaveExceptionContext (
|
||||
**/
|
||||
VOID
|
||||
ArchRestoreExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -240,9 +240,9 @@ ArchRestoreExceptionContext (
|
||||
VOID
|
||||
EFIAPI
|
||||
AsmVectorNumFixup (
|
||||
IN VOID *NewVectorAddr,
|
||||
IN UINT8 VectorNum,
|
||||
IN VOID *OldVectorAddr
|
||||
IN VOID *NewVectorAddr,
|
||||
IN UINT8 VectorNum,
|
||||
IN VOID *OldVectorAddr
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -258,9 +258,9 @@ AsmVectorNumFixup (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ReadAndVerifyVectorInfo (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
|
||||
OUT RESERVED_VECTORS_DATA *ReservedVector,
|
||||
IN UINTN VectorCount
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo,
|
||||
OUT RESERVED_VECTORS_DATA *ReservedVector,
|
||||
IN UINTN VectorCount
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -272,7 +272,7 @@ ReadAndVerifyVectorInfo (
|
||||
**/
|
||||
CONST CHAR8 *
|
||||
GetExceptionNameStr (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -284,9 +284,9 @@ GetExceptionNameStr (
|
||||
**/
|
||||
VOID
|
||||
CommonExceptionHandlerWorker (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -301,7 +301,7 @@ CommonExceptionHandlerWorker (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ArchSetupExceptionStack (
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -318,4 +318,3 @@ AsmGetTssTemplateMap (
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -12,17 +12,17 @@
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
|
||||
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
|
||||
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
|
||||
UINTN mEnabledInterruptNum = 0;
|
||||
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
|
||||
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
|
||||
UINTN mEnabledInterruptNum = 0;
|
||||
|
||||
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
|
||||
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
|
||||
|
||||
UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *
|
||||
CPU_KNOWN_GOOD_STACK_SIZE];
|
||||
UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
|
||||
UINT8 mNewStack[CPU_STACK_SWITCH_EXCEPTION_NUMBER *
|
||||
CPU_KNOWN_GOOD_STACK_SIZE];
|
||||
UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
|
||||
|
||||
/**
|
||||
Common exception handler.
|
||||
@@ -33,8 +33,8 @@ UINT8 mNewGdt[CPU_TSS_GDT_SIZE];
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
|
||||
@@ -59,7 +59,7 @@ CommonExceptionHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
|
||||
@@ -87,19 +87,19 @@ InitializeCpuExceptionHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuInterruptHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
UINTN Index;
|
||||
UINTN InterruptEntry;
|
||||
UINT8 *InterruptEntryCode;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
EFI_STATUS Status;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
UINTN Index;
|
||||
UINTN InterruptEntry;
|
||||
UINT8 *InterruptEntryCode;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
|
||||
Status = gBS->AllocatePool (
|
||||
EfiBootServicesCode,
|
||||
@@ -107,7 +107,7 @@ InitializeCpuInterruptHandlers (
|
||||
(VOID **)&ReservedVectors
|
||||
);
|
||||
ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);
|
||||
SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);
|
||||
SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM, 0xff);
|
||||
if (VectorInfo != NULL) {
|
||||
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_INTERRUPT_NUM);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -127,6 +127,7 @@ InitializeCpuInterruptHandlers (
|
||||
if (IdtEntryCount > CPU_INTERRUPT_NUM) {
|
||||
IdtEntryCount = CPU_INTERRUPT_NUM;
|
||||
}
|
||||
|
||||
//
|
||||
// Create Interrupt Descriptor Table and Copy the old IDT table in
|
||||
//
|
||||
@@ -144,18 +145,18 @@ InitializeCpuInterruptHandlers (
|
||||
);
|
||||
ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);
|
||||
|
||||
InterruptEntry = (UINTN) InterruptEntryCode;
|
||||
for (Index = 0; Index < CPU_INTERRUPT_NUM; Index ++) {
|
||||
InterruptEntry = (UINTN)InterruptEntryCode;
|
||||
for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {
|
||||
CopyMem (
|
||||
(VOID *) InterruptEntry,
|
||||
(VOID *) TemplateMap.ExceptionStart,
|
||||
(VOID *)InterruptEntry,
|
||||
(VOID *)TemplateMap.ExceptionStart,
|
||||
TemplateMap.ExceptionStubHeaderSize
|
||||
);
|
||||
AsmVectorNumFixup ((VOID *) InterruptEntry, (UINT8) Index, (VOID *) TemplateMap.ExceptionStart);
|
||||
AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID *)TemplateMap.ExceptionStart);
|
||||
InterruptEntry += TemplateMap.ExceptionStubHeaderSize;
|
||||
}
|
||||
|
||||
TemplateMap.ExceptionStart = (UINTN) InterruptEntryCode;
|
||||
TemplateMap.ExceptionStart = (UINTN)InterruptEntryCode;
|
||||
mExceptionHandlerData.IdtEntryCount = CPU_INTERRUPT_NUM;
|
||||
mExceptionHandlerData.ReservedVectors = ReservedVectors;
|
||||
mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;
|
||||
@@ -166,9 +167,9 @@ InitializeCpuInterruptHandlers (
|
||||
//
|
||||
// Load Interrupt Descriptor Table
|
||||
//
|
||||
IdtDescriptor.Base = (UINTN) IdtTable;
|
||||
IdtDescriptor.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *) &IdtDescriptor);
|
||||
IdtDescriptor.Base = (UINTN)IdtTable;
|
||||
IdtDescriptor.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
|
||||
AsmWriteIdtr ((IA32_DESCRIPTOR *)&IdtDescriptor);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -199,8 +200,8 @@ InitializeCpuInterruptHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RegisterCpuInterruptHandler (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
)
|
||||
{
|
||||
return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
|
||||
@@ -230,14 +231,14 @@ RegisterCpuInterruptHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlersEx (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CPU_EXCEPTION_INIT_DATA EssData;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
EFI_STATUS Status;
|
||||
CPU_EXCEPTION_INIT_DATA EssData;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
|
||||
//
|
||||
// To avoid repeat initialization of default handlers, the caller should pass
|
||||
@@ -246,7 +247,7 @@ InitializeCpuExceptionHandlersEx (
|
||||
// version instead; or this method must be implemented as a simple wrapper of
|
||||
// non-ex version of it, if this version has to be called.
|
||||
//
|
||||
if (InitData == NULL || InitData->X64.InitDefaultHandlers) {
|
||||
if ((InitData == NULL) || InitData->X64.InitDefaultHandlers) {
|
||||
Status = InitializeCpuExceptionHandlers (VectorInfo);
|
||||
} else {
|
||||
Status = EFI_SUCCESS;
|
||||
@@ -263,25 +264,26 @@ InitializeCpuExceptionHandlersEx (
|
||||
AsmReadIdtr (&Idtr);
|
||||
AsmReadGdtr (&Gdtr);
|
||||
|
||||
EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;
|
||||
EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);
|
||||
EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;
|
||||
EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;
|
||||
EssData.X64.Revision = CPU_EXCEPTION_INIT_DATA_REV;
|
||||
EssData.X64.KnownGoodStackTop = (UINTN)mNewStack + sizeof (mNewStack);
|
||||
EssData.X64.KnownGoodStackSize = CPU_KNOWN_GOOD_STACK_SIZE;
|
||||
EssData.X64.StackSwitchExceptions = CPU_STACK_SWITCH_EXCEPTION_LIST;
|
||||
EssData.X64.StackSwitchExceptionNumber = CPU_STACK_SWITCH_EXCEPTION_NUMBER;
|
||||
EssData.X64.IdtTable = (VOID *)Idtr.Base;
|
||||
EssData.X64.IdtTableSize = Idtr.Limit + 1;
|
||||
EssData.X64.GdtTable = mNewGdt;
|
||||
EssData.X64.GdtTableSize = sizeof (mNewGdt);
|
||||
EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;
|
||||
EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;
|
||||
EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
|
||||
EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;
|
||||
EssData.X64.IdtTable = (VOID *)Idtr.Base;
|
||||
EssData.X64.IdtTableSize = Idtr.Limit + 1;
|
||||
EssData.X64.GdtTable = mNewGdt;
|
||||
EssData.X64.GdtTableSize = sizeof (mNewGdt);
|
||||
EssData.X64.ExceptionTssDesc = mNewGdt + Gdtr.Limit + 1;
|
||||
EssData.X64.ExceptionTssDescSize = CPU_TSS_DESC_SIZE;
|
||||
EssData.X64.ExceptionTss = mNewGdt + Gdtr.Limit + 1 + CPU_TSS_DESC_SIZE;
|
||||
EssData.X64.ExceptionTssSize = CPU_TSS_SIZE;
|
||||
|
||||
InitData = &EssData;
|
||||
}
|
||||
|
||||
Status = ArchSetupExceptionStack (InitData);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
return Status;
|
||||
}
|
||||
|
@@ -18,13 +18,13 @@
|
||||
**/
|
||||
VOID
|
||||
ArchUpdateIdtEntry (
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
)
|
||||
{
|
||||
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry->Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry->Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
IdtEntry->Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
|
||||
IdtEntry->Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ ArchUpdateIdtEntry (
|
||||
**/
|
||||
UINTN
|
||||
ArchGetIdtHandler (
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
)
|
||||
{
|
||||
return (UINTN)IdtEntry->Bits.OffsetLow + (((UINTN)IdtEntry->Bits.OffsetHigh) << 16);
|
||||
@@ -50,13 +50,13 @@ ArchGetIdtHandler (
|
||||
**/
|
||||
VOID
|
||||
ArchSaveExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
IA32_EFLAGS32 Eflags;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
//
|
||||
@@ -71,13 +71,13 @@ ArchSaveExceptionContext (
|
||||
//
|
||||
// Clear IF flag to avoid old IDT handler enable interrupt by IRET
|
||||
//
|
||||
Eflags.UintN = SystemContext.SystemContextIa32->Eflags;
|
||||
Eflags.Bits.IF = 0;
|
||||
Eflags.UintN = SystemContext.SystemContextIa32->Eflags;
|
||||
Eflags.Bits.IF = 0;
|
||||
SystemContext.SystemContextIa32->Eflags = Eflags.UintN;
|
||||
//
|
||||
// Modify the EIP in stack, then old IDT handler will return to HookAfterStubBegin.
|
||||
//
|
||||
SystemContext.SystemContextIa32->Eip = (UINTN) ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
|
||||
SystemContext.SystemContextIa32->Eip = (UINTN)ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,14 +89,14 @@ ArchSaveExceptionContext (
|
||||
**/
|
||||
VOID
|
||||
ArchRestoreExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
SystemContext.SystemContextIa32->Eflags = ReservedVectors[ExceptionType].OldFlags;
|
||||
SystemContext.SystemContextIa32->Cs = ReservedVectors[ExceptionType].OldCs;
|
||||
SystemContext.SystemContextIa32->Eip = ReservedVectors[ExceptionType].OldIp;
|
||||
@@ -116,32 +116,33 @@ ArchRestoreExceptionContext (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ArchSetupExceptionStack (
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
)
|
||||
{
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_TSS_DESCRIPTOR *TssDesc;
|
||||
IA32_TASK_STATE_SEGMENT *Tss;
|
||||
UINTN StackTop;
|
||||
UINTN Index;
|
||||
UINTN Vector;
|
||||
UINTN TssBase;
|
||||
UINTN GdtSize;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_TSS_DESCRIPTOR *TssDesc;
|
||||
IA32_TASK_STATE_SEGMENT *Tss;
|
||||
UINTN StackTop;
|
||||
UINTN Index;
|
||||
UINTN Vector;
|
||||
UINTN TssBase;
|
||||
UINTN GdtSize;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
|
||||
if (StackSwitchData == NULL ||
|
||||
StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV ||
|
||||
StackSwitchData->Ia32.KnownGoodStackTop == 0 ||
|
||||
StackSwitchData->Ia32.KnownGoodStackSize == 0 ||
|
||||
StackSwitchData->Ia32.StackSwitchExceptions == NULL ||
|
||||
StackSwitchData->Ia32.StackSwitchExceptionNumber == 0 ||
|
||||
StackSwitchData->Ia32.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM ||
|
||||
StackSwitchData->Ia32.GdtTable == NULL ||
|
||||
StackSwitchData->Ia32.IdtTable == NULL ||
|
||||
StackSwitchData->Ia32.ExceptionTssDesc == NULL ||
|
||||
StackSwitchData->Ia32.ExceptionTss == NULL) {
|
||||
if ((StackSwitchData == NULL) ||
|
||||
(StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV) ||
|
||||
(StackSwitchData->Ia32.KnownGoodStackTop == 0) ||
|
||||
(StackSwitchData->Ia32.KnownGoodStackSize == 0) ||
|
||||
(StackSwitchData->Ia32.StackSwitchExceptions == NULL) ||
|
||||
(StackSwitchData->Ia32.StackSwitchExceptionNumber == 0) ||
|
||||
(StackSwitchData->Ia32.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM) ||
|
||||
(StackSwitchData->Ia32.GdtTable == NULL) ||
|
||||
(StackSwitchData->Ia32.IdtTable == NULL) ||
|
||||
(StackSwitchData->Ia32.ExceptionTssDesc == NULL) ||
|
||||
(StackSwitchData->Ia32.ExceptionTss == NULL))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -159,7 +160,8 @@ ArchSetupExceptionStack (
|
||||
}
|
||||
|
||||
if ((UINTN)StackSwitchData->Ia32.ExceptionTssDesc + StackSwitchData->Ia32.ExceptionTssDescSize >
|
||||
((UINTN)(StackSwitchData->Ia32.GdtTable) + StackSwitchData->Ia32.GdtTableSize)) {
|
||||
((UINTN)(StackSwitchData->Ia32.GdtTable) + StackSwitchData->Ia32.GdtTableSize))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -168,11 +170,14 @@ ArchSetupExceptionStack (
|
||||
// specified.
|
||||
//
|
||||
if (StackSwitchData->Ia32.ExceptionTssDescSize <
|
||||
sizeof (IA32_TSS_DESCRIPTOR) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1)) {
|
||||
sizeof (IA32_TSS_DESCRIPTOR) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (StackSwitchData->Ia32.ExceptionTssSize <
|
||||
sizeof (IA32_TASK_STATE_SEGMENT) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1)) {
|
||||
sizeof (IA32_TASK_STATE_SEGMENT) * (StackSwitchData->Ia32.StackSwitchExceptionNumber + 1))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -191,13 +196,14 @@ ArchSetupExceptionStack (
|
||||
(UINTN)(StackSwitchData->Ia32.GdtTable);
|
||||
if ((UINTN)StackSwitchData->Ia32.GdtTable != Gdtr.Base) {
|
||||
CopyMem (StackSwitchData->Ia32.GdtTable, (VOID *)Gdtr.Base, Gdtr.Limit + 1);
|
||||
Gdtr.Base = (UINTN)StackSwitchData->Ia32.GdtTable;
|
||||
Gdtr.Base = (UINTN)StackSwitchData->Ia32.GdtTable;
|
||||
Gdtr.Limit = (UINT16)GdtSize - 1;
|
||||
}
|
||||
|
||||
if ((UINTN)StackSwitchData->Ia32.IdtTable != Idtr.Base) {
|
||||
Idtr.Base = (UINTN)StackSwitchData->Ia32.IdtTable;
|
||||
}
|
||||
|
||||
if (StackSwitchData->Ia32.IdtTableSize > 0) {
|
||||
Idtr.Limit = (UINT16)(StackSwitchData->Ia32.IdtTableSize - 1);
|
||||
}
|
||||
@@ -208,14 +214,14 @@ ArchSetupExceptionStack (
|
||||
//
|
||||
TssBase = (UINTN)Tss;
|
||||
|
||||
TssDesc->Uint64 = 0;
|
||||
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.BaseLow = (UINT16)TssBase;
|
||||
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
|
||||
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
|
||||
TssDesc->Bits.P = 1;
|
||||
TssDesc->Bits.LimitHigh = 0;
|
||||
TssDesc->Bits.BaseHigh = (UINT8)(TssBase >> 24);
|
||||
TssDesc->Uint64 = 0;
|
||||
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.BaseLow = (UINT16)TssBase;
|
||||
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
|
||||
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
|
||||
TssDesc->Bits.P = 1;
|
||||
TssDesc->Bits.LimitHigh = 0;
|
||||
TssDesc->Bits.BaseHigh = (UINT8)(TssBase >> 24);
|
||||
|
||||
//
|
||||
// Fixup exception task descriptor and task-state segment
|
||||
@@ -234,7 +240,7 @@ ArchSetupExceptionStack (
|
||||
TssBase = (UINTN)Tss;
|
||||
|
||||
TssDesc->Uint64 = 0;
|
||||
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.BaseLow = (UINT16)TssBase;
|
||||
TssDesc->Bits.BaseMid = (UINT8)(TssBase >> 16);
|
||||
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
|
||||
@@ -246,14 +252,15 @@ ArchSetupExceptionStack (
|
||||
// Fixup TSS
|
||||
//
|
||||
Vector = StackSwitchData->Ia32.StackSwitchExceptions[Index];
|
||||
if (Vector >= CPU_EXCEPTION_NUM ||
|
||||
Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)) {
|
||||
if ((Vector >= CPU_EXCEPTION_NUM) ||
|
||||
(Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ZeroMem (Tss, sizeof (*Tss));
|
||||
Tss->EIP = (UINT32)(TemplateMap.ExceptionStart
|
||||
+ Vector * TemplateMap.ExceptionStubHeaderSize);
|
||||
Tss->EIP = (UINT32)(TemplateMap.ExceptionStart
|
||||
+ Vector * TemplateMap.ExceptionStubHeaderSize);
|
||||
Tss->EFLAGS = 0x2;
|
||||
Tss->ESP = StackTop;
|
||||
Tss->CR3 = AsmReadCr3 ();
|
||||
@@ -264,7 +271,7 @@ ArchSetupExceptionStack (
|
||||
Tss->FS = AsmReadFs ();
|
||||
Tss->GS = AsmReadGs ();
|
||||
|
||||
StackTop -= StackSwitchData->Ia32.KnownGoodStackSize;
|
||||
StackTop -= StackSwitchData->Ia32.KnownGoodStackSize;
|
||||
|
||||
//
|
||||
// Update IDT to use Task Gate for given exception
|
||||
@@ -303,8 +310,8 @@ ArchSetupExceptionStack (
|
||||
VOID
|
||||
EFIAPI
|
||||
DumpCpuContext (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
InternalPrintMessage (
|
||||
@@ -331,8 +338,10 @@ DumpCpuContext (
|
||||
(SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_SGX) != 0
|
||||
);
|
||||
}
|
||||
|
||||
InternalPrintMessage ("\n");
|
||||
}
|
||||
|
||||
InternalPrintMessage (
|
||||
"EIP - %08x, CS - %08x, EFLAGS - %08x\n",
|
||||
SystemContext.SystemContextIa32->Eip,
|
||||
@@ -406,8 +415,8 @@ DumpCpuContext (
|
||||
**/
|
||||
VOID
|
||||
DumpImageAndCpuContent (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
DumpCpuContext (ExceptionType, SystemContext);
|
||||
@@ -415,7 +424,8 @@ DumpImageAndCpuContent (
|
||||
// Dump module image base and module entry point by EIP
|
||||
//
|
||||
if ((ExceptionType == EXCEPT_IA32_PAGE_FAULT) &&
|
||||
((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0)) {
|
||||
((SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID) != 0))
|
||||
{
|
||||
//
|
||||
// The EIP in SystemContext could not be used
|
||||
// if it is page fault with I/D set.
|
||||
|
@@ -10,29 +10,29 @@
|
||||
#define _ARCH_CPU_INTERRUPT_DEFS_H_
|
||||
|
||||
typedef struct {
|
||||
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
|
||||
BOOLEAN ExceptionDataFlag;
|
||||
UINTN OldIdtHandler;
|
||||
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
|
||||
BOOLEAN ExceptionDataFlag;
|
||||
UINTN OldIdtHandler;
|
||||
} EXCEPTION_HANDLER_CONTEXT;
|
||||
|
||||
//
|
||||
// Register Structure Definitions
|
||||
//
|
||||
typedef struct {
|
||||
EFI_STATUS_CODE_DATA Header;
|
||||
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
|
||||
EFI_STATUS_CODE_DATA Header;
|
||||
EFI_SYSTEM_CONTEXT_IA32 SystemContext;
|
||||
} CPU_STATUS_CODE_TEMPLATE;
|
||||
|
||||
typedef struct {
|
||||
SPIN_LOCK SpinLock;
|
||||
UINT32 ApicId;
|
||||
UINT32 Attribute;
|
||||
UINTN ExceptonHandler;
|
||||
UINTN OldFlags;
|
||||
UINTN OldCs;
|
||||
UINTN OldIp;
|
||||
UINTN ExceptionData;
|
||||
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
|
||||
SPIN_LOCK SpinLock;
|
||||
UINT32 ApicId;
|
||||
UINT32 Attribute;
|
||||
UINTN ExceptonHandler;
|
||||
UINTN OldFlags;
|
||||
UINTN OldCs;
|
||||
UINTN OldIp;
|
||||
UINTN ExceptionData;
|
||||
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
|
||||
} RESERVED_VECTORS_DATA;
|
||||
|
||||
#define CPU_TSS_DESC_SIZE \
|
||||
|
@@ -13,11 +13,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
|
||||
typedef struct {
|
||||
UINT8 ExceptionStubHeader[HOOKAFTER_STUB_SIZE];
|
||||
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
|
||||
UINT8 ExceptionStubHeader[HOOKAFTER_STUB_SIZE];
|
||||
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
|
||||
} EXCEPTION0_STUB_HEADER;
|
||||
|
||||
/**
|
||||
@@ -34,9 +34,9 @@ GetExceptionHandlerData (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
|
||||
|
||||
AsmReadIdtr (&IdtDescriptor);
|
||||
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
@@ -56,12 +56,13 @@ GetExceptionHandlerData (
|
||||
**/
|
||||
VOID
|
||||
SetExceptionHandlerData (
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
EXCEPTION0_STUB_HEADER *Exception0StubHeader;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
|
||||
//
|
||||
// Duplicate the exception #0 stub header in pool and cache the ExceptionHandlerData just after the stub header.
|
||||
// So AP can get the ExceptionHandlerData by reading the IDT[0].
|
||||
@@ -89,8 +90,8 @@ SetExceptionHandlerData (
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
|
||||
@@ -120,12 +121,12 @@ CommonExceptionHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_STATUS Status;
|
||||
EXCEPTION_HANDLER_DATA *ExceptionHandlerData;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM);
|
||||
ASSERT (ReservedVectors != NULL);
|
||||
@@ -166,7 +167,7 @@ InitializeCpuExceptionHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuInterruptHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
@@ -198,8 +199,8 @@ InitializeCpuInterruptHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RegisterCpuInterruptHandler (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
@@ -230,11 +231,11 @@ RegisterCpuInterruptHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlersEx (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// To avoid repeat initialization of default handlers, the caller should pass
|
||||
@@ -243,7 +244,7 @@ InitializeCpuExceptionHandlersEx (
|
||||
// version instead; or this method must be implemented as a simple wrapper of
|
||||
// non-ex version of it, if this version has to be called.
|
||||
//
|
||||
if (InitData == NULL || InitData->Ia32.InitDefaultHandlers) {
|
||||
if ((InitData == NULL) || InitData->Ia32.InitDefaultHandlers) {
|
||||
Status = InitializeCpuExceptionHandlers (VectorInfo);
|
||||
} else {
|
||||
Status = EFI_SUCCESS;
|
||||
@@ -253,10 +254,10 @@ InitializeCpuExceptionHandlersEx (
|
||||
//
|
||||
// Initializing stack switch is only necessary for Stack Guard functionality.
|
||||
//
|
||||
if (PcdGetBool (PcdCpuStackGuard) && InitData != NULL) {
|
||||
if (PcdGetBool (PcdCpuStackGuard) && (InitData != NULL)) {
|
||||
Status = ArchSetupExceptionStack (InitData);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
return Status;
|
||||
}
|
||||
|
@@ -19,14 +19,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
VOID
|
||||
CommonExceptionHandlerWorker (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
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;
|
||||
EXCEPTION_HANDLER_CONTEXT *ExceptionHandlerContext;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
|
||||
if (ExceptionType == VC_EXCEPTION) {
|
||||
EFI_STATUS Status;
|
||||
@@ -45,68 +45,72 @@ CommonExceptionHandlerWorker (
|
||||
}
|
||||
}
|
||||
|
||||
ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (SystemContext.SystemContextIa32);
|
||||
ExceptionHandlerContext = (EXCEPTION_HANDLER_CONTEXT *)(UINTN)(SystemContext.SystemContextIa32);
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;
|
||||
|
||||
switch (ReservedVectors[ExceptionType].Attribute) {
|
||||
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
|
||||
//
|
||||
// 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;
|
||||
break;
|
||||
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
|
||||
while (TRUE) {
|
||||
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
|
||||
//
|
||||
// If spin-lock can be acquired, it's the first time entering here.
|
||||
// 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.
|
||||
//
|
||||
if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {
|
||||
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
|
||||
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
|
||||
break;
|
||||
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
|
||||
while (TRUE) {
|
||||
//
|
||||
// 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.
|
||||
// If spin-lock can be acquired, it's the first time entering here.
|
||||
//
|
||||
ReservedVectors[ExceptionType].ApicId = GetApicId ();
|
||||
ArchSaveExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
|
||||
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
|
||||
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
|
||||
return;
|
||||
if (AcquireSpinLockOrFail (&ReservedVectors[ExceptionType].SpinLock)) {
|
||||
//
|
||||
// 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);
|
||||
ExceptionHandlerContext->ExceptionDataFlag = (mErrorCodeFlag & (1 << ExceptionType)) ? TRUE : FALSE;
|
||||
ExceptionHandlerContext->OldIdtHandler = ReservedVectors[ExceptionType].ExceptonHandler;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// 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 ()) {
|
||||
//
|
||||
// Old IDT handler has been executed, then restore CPU exception content to
|
||||
// run new exception handler.
|
||||
//
|
||||
ArchRestoreExceptionContext (ExceptionType, SystemContext, ExceptionHandlerData);
|
||||
//
|
||||
// Release spin lock for ApicId
|
||||
//
|
||||
ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock);
|
||||
break;
|
||||
}
|
||||
|
||||
CpuPause ();
|
||||
}
|
||||
|
||||
break;
|
||||
case 0xffffffff:
|
||||
break;
|
||||
default:
|
||||
//
|
||||
// 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.
|
||||
// It should never reach here
|
||||
//
|
||||
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);
|
||||
//
|
||||
// Release spin lock for ApicId
|
||||
//
|
||||
ReleaseSpinLock (&ReservedVectors[ExceptionType].SpinLock);
|
||||
break;
|
||||
}
|
||||
CpuPause ();
|
||||
}
|
||||
break;
|
||||
case 0xffffffff:
|
||||
break;
|
||||
default:
|
||||
//
|
||||
// It should never reach here
|
||||
//
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
CpuDeadLoop ();
|
||||
break;
|
||||
}
|
||||
|
||||
if (ExternalInterruptHandler != NULL &&
|
||||
ExternalInterruptHandler[ExceptionType] != NULL) {
|
||||
(ExternalInterruptHandler[ExceptionType]) (ExceptionType, SystemContext);
|
||||
if ((ExternalInterruptHandler != NULL) &&
|
||||
(ExternalInterruptHandler[ExceptionType] != NULL))
|
||||
{
|
||||
(ExternalInterruptHandler[ExceptionType])(ExceptionType, SystemContext);
|
||||
} else if (ExceptionType < CPU_EXCEPTION_NUM) {
|
||||
//
|
||||
// Get Spinlock to display CPU information
|
||||
@@ -114,6 +118,7 @@ CommonExceptionHandlerWorker (
|
||||
while (!AcquireSpinLockOrFail (&ExceptionHandlerData->DisplayMessageSpinLock)) {
|
||||
CpuPause ();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize the serial port before dumping.
|
||||
//
|
||||
@@ -151,10 +156,10 @@ UpdateIdtTable (
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
UINT16 CodeSegment;
|
||||
UINTN Index;
|
||||
UINTN InterruptHandler;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
UINT16 CodeSegment;
|
||||
UINTN Index;
|
||||
UINTN InterruptHandler;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
//
|
||||
@@ -162,47 +167,47 @@ UpdateIdtTable (
|
||||
//
|
||||
CodeSegment = AsmReadCs ();
|
||||
|
||||
for (Index = 0; Index < ExceptionHandlerData->IdtEntryCount; Index ++) {
|
||||
for (Index = 0; Index < ExceptionHandlerData->IdtEntryCount; Index++) {
|
||||
IdtTable[Index].Bits.Selector = CodeSegment;
|
||||
//
|
||||
// Check reserved vectors attributes
|
||||
//
|
||||
switch (ReservedVectors[Index].Attribute) {
|
||||
case EFI_VECTOR_HANDOFF_DO_NOT_HOOK:
|
||||
//
|
||||
// Keep original IDT entry
|
||||
//
|
||||
continue;
|
||||
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
|
||||
InitializeSpinLock (&ReservedVectors[Index].SpinLock);
|
||||
CopyMem (
|
||||
(VOID *) ReservedVectors[Index].HookAfterStubHeaderCode,
|
||||
(VOID *) TemplateMap->HookAfterStubHeaderStart,
|
||||
TemplateMap->ExceptionStubHeaderSize
|
||||
);
|
||||
AsmVectorNumFixup (
|
||||
(VOID *) ReservedVectors[Index].HookAfterStubHeaderCode,
|
||||
(UINT8) Index,
|
||||
(VOID *) TemplateMap->HookAfterStubHeaderStart
|
||||
);
|
||||
case EFI_VECTOR_HANDOFF_DO_NOT_HOOK:
|
||||
//
|
||||
// Keep original IDT entry
|
||||
//
|
||||
continue;
|
||||
case EFI_VECTOR_HANDOFF_HOOK_AFTER:
|
||||
InitializeSpinLock (&ReservedVectors[Index].SpinLock);
|
||||
CopyMem (
|
||||
(VOID *)ReservedVectors[Index].HookAfterStubHeaderCode,
|
||||
(VOID *)TemplateMap->HookAfterStubHeaderStart,
|
||||
TemplateMap->ExceptionStubHeaderSize
|
||||
);
|
||||
AsmVectorNumFixup (
|
||||
(VOID *)ReservedVectors[Index].HookAfterStubHeaderCode,
|
||||
(UINT8)Index,
|
||||
(VOID *)TemplateMap->HookAfterStubHeaderStart
|
||||
);
|
||||
//
|
||||
// Go on the following code
|
||||
//
|
||||
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
|
||||
//
|
||||
// Save original IDT handler address
|
||||
//
|
||||
ReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]);
|
||||
case EFI_VECTOR_HANDOFF_HOOK_BEFORE:
|
||||
//
|
||||
// Save original IDT handler address
|
||||
//
|
||||
ReservedVectors[Index].ExceptonHandler = ArchGetIdtHandler (&IdtTable[Index]);
|
||||
//
|
||||
// Go on the following code
|
||||
//
|
||||
default:
|
||||
//
|
||||
// Update new IDT entry
|
||||
//
|
||||
InterruptHandler = TemplateMap->ExceptionStart + Index * TemplateMap->ExceptionStubHeaderSize;
|
||||
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
|
||||
break;
|
||||
default:
|
||||
//
|
||||
// Update new IDT entry
|
||||
//
|
||||
InterruptHandler = TemplateMap->ExceptionStart + Index * TemplateMap->ExceptionStubHeaderSize;
|
||||
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,19 +226,19 @@ UpdateIdtTable (
|
||||
**/
|
||||
EFI_STATUS
|
||||
InitializeCpuExceptionHandlersWorker (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN OUT EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_STATUS Status;
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
|
||||
SetMem ((VOID *)ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
|
||||
if (VectorInfo != NULL) {
|
||||
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, CPU_EXCEPTION_NUM);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -253,7 +258,7 @@ InitializeCpuExceptionHandlersWorker (
|
||||
IdtEntryCount = CPU_EXCEPTION_NUM;
|
||||
}
|
||||
|
||||
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base;
|
||||
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
AsmGetTemplateAddressMap (&TemplateMap);
|
||||
ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
|
||||
|
||||
@@ -282,33 +287,33 @@ InitializeCpuExceptionHandlersWorker (
|
||||
**/
|
||||
EFI_STATUS
|
||||
RegisterCpuInterruptHandlerWorker (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
UINTN EnabledInterruptNum;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
UINTN EnabledInterruptNum;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler;
|
||||
|
||||
EnabledInterruptNum = ExceptionHandlerData->IdtEntryCount;
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
ExternalInterruptHandler = ExceptionHandlerData->ExternalInterruptHandler;
|
||||
|
||||
if (InterruptType < 0 || InterruptType >= (EFI_EXCEPTION_TYPE)EnabledInterruptNum ||
|
||||
ReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {
|
||||
if ((InterruptType < 0) || (InterruptType >= (EFI_EXCEPTION_TYPE)EnabledInterruptNum) ||
|
||||
(ReservedVectors[InterruptType].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK))
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (InterruptHandler == NULL && ExternalInterruptHandler[InterruptType] == NULL) {
|
||||
if ((InterruptHandler == NULL) && (ExternalInterruptHandler[InterruptType] == NULL)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (InterruptHandler != NULL && ExternalInterruptHandler[InterruptType] != NULL) {
|
||||
if ((InterruptHandler != NULL) && (ExternalInterruptHandler[InterruptType] != NULL)) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
ExternalInterruptHandler[InterruptType] = InterruptHandler;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#include <Library/VmgExitLib.h>
|
||||
#include "CpuExceptionCommon.h"
|
||||
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
CONST UINTN mDoFarReturnFlag = 0;
|
||||
|
||||
/**
|
||||
Common exception handler.
|
||||
@@ -21,8 +21,8 @@ CONST UINTN mDoFarReturnFlag = 0;
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
if (ExceptionType == VC_EXCEPTION) {
|
||||
@@ -79,26 +79,27 @@ CommonExceptionHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
UINT16 CodeSegment;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
UINTN Index;
|
||||
UINTN InterruptHandler;
|
||||
EFI_STATUS Status;
|
||||
RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
|
||||
IA32_DESCRIPTOR IdtDescriptor;
|
||||
UINTN IdtEntryCount;
|
||||
UINT16 CodeSegment;
|
||||
EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
UINTN Index;
|
||||
UINTN InterruptHandler;
|
||||
|
||||
if (VectorInfo != NULL) {
|
||||
SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
|
||||
SetMem ((VOID *)ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
|
||||
Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read IDT descriptor and calculate IDT size
|
||||
//
|
||||
@@ -110,6 +111,7 @@ InitializeCpuExceptionHandlers (
|
||||
//
|
||||
IdtEntryCount = CPU_EXCEPTION_NUM;
|
||||
}
|
||||
|
||||
//
|
||||
// Use current CS as the segment selector of interrupt gate in IDT
|
||||
//
|
||||
@@ -117,7 +119,7 @@ InitializeCpuExceptionHandlers (
|
||||
|
||||
AsmGetTemplateAddressMap (&TemplateMap);
|
||||
IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
|
||||
for (Index = 0; Index < IdtEntryCount; Index ++) {
|
||||
for (Index = 0; Index < IdtEntryCount; Index++) {
|
||||
IdtTable[Index].Bits.Selector = CodeSegment;
|
||||
//
|
||||
// Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK
|
||||
@@ -128,12 +130,14 @@ InitializeCpuExceptionHandlers (
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Update IDT entry
|
||||
//
|
||||
InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;
|
||||
ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -156,7 +160,7 @@ InitializeCpuExceptionHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuInterruptHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
@@ -188,8 +192,8 @@ InitializeCpuInterruptHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RegisterCpuInterruptHandler (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
@@ -220,8 +224,8 @@ RegisterCpuInterruptHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlersEx (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
)
|
||||
{
|
||||
return InitializeCpuExceptionHandlers (VectorInfo);
|
||||
|
@@ -9,16 +9,17 @@
|
||||
#include <PiSmm.h>
|
||||
#include "CpuExceptionCommon.h"
|
||||
|
||||
CONST UINTN mDoFarReturnFlag = 1;
|
||||
CONST UINTN mDoFarReturnFlag = 1;
|
||||
|
||||
//
|
||||
// Spin lock for CPU information display
|
||||
//
|
||||
SPIN_LOCK mDisplayMessageSpinLock;
|
||||
SPIN_LOCK mDisplayMessageSpinLock;
|
||||
|
||||
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
|
||||
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
|
||||
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
|
||||
|
||||
RESERVED_VECTORS_DATA mReservedVectorsData[CPU_EXCEPTION_NUM];
|
||||
EFI_CPU_INTERRUPT_HANDLER mExternalInterruptHandlerTable[CPU_EXCEPTION_NUM];
|
||||
EXCEPTION_HANDLER_DATA mExceptionHandlerData;
|
||||
/**
|
||||
Common exception handler.
|
||||
|
||||
@@ -28,8 +29,8 @@ EXCEPTION_HANDLER_DATA mExceptionHandlerData;
|
||||
VOID
|
||||
EFIAPI
|
||||
CommonExceptionHandler (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
CommonExceptionHandlerWorker (ExceptionType, SystemContext, &mExceptionHandlerData);
|
||||
@@ -54,7 +55,7 @@ CommonExceptionHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
mExceptionHandlerData.ReservedVectors = mReservedVectorsData;
|
||||
@@ -82,7 +83,7 @@ InitializeCpuExceptionHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuInterruptHandlers (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
|
||||
)
|
||||
{
|
||||
return EFI_UNSUPPORTED;
|
||||
@@ -114,8 +115,8 @@ InitializeCpuInterruptHandlers (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
RegisterCpuInterruptHandler (
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
IN EFI_EXCEPTION_TYPE InterruptType,
|
||||
IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
|
||||
)
|
||||
{
|
||||
return RegisterCpuInterruptHandlerWorker (InterruptType, InterruptHandler, &mExceptionHandlerData);
|
||||
@@ -146,8 +147,8 @@ RegisterCpuInterruptHandler (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InitializeCpuExceptionHandlersEx (
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL,
|
||||
IN CPU_EXCEPTION_INIT_DATA *InitData OPTIONAL
|
||||
)
|
||||
{
|
||||
return InitializeCpuExceptionHandlers (VectorInfo);
|
||||
|
@@ -17,8 +17,8 @@
|
||||
**/
|
||||
VOID
|
||||
ArchUpdateIdtEntry (
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
OUT IA32_IDT_GATE_DESCRIPTOR *IdtEntry,
|
||||
IN UINTN InterruptHandler
|
||||
)
|
||||
{
|
||||
IdtEntry->Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
|
||||
@@ -35,11 +35,11 @@ ArchUpdateIdtEntry (
|
||||
**/
|
||||
UINTN
|
||||
ArchGetIdtHandler (
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
IN IA32_IDT_GATE_DESCRIPTOR *IdtEntry
|
||||
)
|
||||
{
|
||||
return IdtEntry->Bits.OffsetLow + (((UINTN) IdtEntry->Bits.OffsetHigh) << 16) +
|
||||
(((UINTN) IdtEntry->Bits.OffsetUpper) << 32);
|
||||
return IdtEntry->Bits.OffsetLow + (((UINTN)IdtEntry->Bits.OffsetHigh) << 16) +
|
||||
(((UINTN)IdtEntry->Bits.OffsetUpper) << 32);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,13 +51,13 @@ ArchGetIdtHandler (
|
||||
**/
|
||||
VOID
|
||||
ArchSaveExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
IA32_EFLAGS32 Eflags;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
IA32_EFLAGS32 Eflags;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
//
|
||||
@@ -74,13 +74,13 @@ ArchSaveExceptionContext (
|
||||
//
|
||||
// Clear IF flag to avoid old IDT handler enable interrupt by IRET
|
||||
//
|
||||
Eflags.UintN = SystemContext.SystemContextX64->Rflags;
|
||||
Eflags.Bits.IF = 0;
|
||||
Eflags.UintN = SystemContext.SystemContextX64->Rflags;
|
||||
Eflags.Bits.IF = 0;
|
||||
SystemContext.SystemContextX64->Rflags = Eflags.UintN;
|
||||
//
|
||||
// Modify the EIP in stack, then old IDT handler will return to HookAfterStubBegin.
|
||||
//
|
||||
SystemContext.SystemContextX64->Rip = (UINTN) ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
|
||||
SystemContext.SystemContextX64->Rip = (UINTN)ReservedVectors[ExceptionType].HookAfterStubHeaderCode;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,14 +92,14 @@ ArchSaveExceptionContext (
|
||||
**/
|
||||
VOID
|
||||
ArchRestoreExceptionContext (
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
IN UINTN ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext,
|
||||
IN EXCEPTION_HANDLER_DATA *ExceptionHandlerData
|
||||
)
|
||||
{
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
RESERVED_VECTORS_DATA *ReservedVectors;
|
||||
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
ReservedVectors = ExceptionHandlerData->ReservedVectors;
|
||||
SystemContext.SystemContextX64->Ss = ReservedVectors[ExceptionType].OldSs;
|
||||
SystemContext.SystemContextX64->Rsp = ReservedVectors[ExceptionType].OldSp;
|
||||
SystemContext.SystemContextX64->Rflags = ReservedVectors[ExceptionType].OldFlags;
|
||||
@@ -121,31 +121,32 @@ ArchRestoreExceptionContext (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ArchSetupExceptionStack (
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
IN CPU_EXCEPTION_INIT_DATA *StackSwitchData
|
||||
)
|
||||
{
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_TSS_DESCRIPTOR *TssDesc;
|
||||
IA32_TASK_STATE_SEGMENT *Tss;
|
||||
UINTN StackTop;
|
||||
UINTN Index;
|
||||
UINTN Vector;
|
||||
UINTN TssBase;
|
||||
UINTN GdtSize;
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
IA32_DESCRIPTOR Idtr;
|
||||
IA32_IDT_GATE_DESCRIPTOR *IdtTable;
|
||||
IA32_TSS_DESCRIPTOR *TssDesc;
|
||||
IA32_TASK_STATE_SEGMENT *Tss;
|
||||
UINTN StackTop;
|
||||
UINTN Index;
|
||||
UINTN Vector;
|
||||
UINTN TssBase;
|
||||
UINTN GdtSize;
|
||||
|
||||
if (StackSwitchData == NULL ||
|
||||
StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV ||
|
||||
StackSwitchData->X64.KnownGoodStackTop == 0 ||
|
||||
StackSwitchData->X64.KnownGoodStackSize == 0 ||
|
||||
StackSwitchData->X64.StackSwitchExceptions == NULL ||
|
||||
StackSwitchData->X64.StackSwitchExceptionNumber == 0 ||
|
||||
StackSwitchData->X64.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM ||
|
||||
StackSwitchData->X64.GdtTable == NULL ||
|
||||
StackSwitchData->X64.IdtTable == NULL ||
|
||||
StackSwitchData->X64.ExceptionTssDesc == NULL ||
|
||||
StackSwitchData->X64.ExceptionTss == NULL) {
|
||||
if ((StackSwitchData == NULL) ||
|
||||
(StackSwitchData->Ia32.Revision != CPU_EXCEPTION_INIT_DATA_REV) ||
|
||||
(StackSwitchData->X64.KnownGoodStackTop == 0) ||
|
||||
(StackSwitchData->X64.KnownGoodStackSize == 0) ||
|
||||
(StackSwitchData->X64.StackSwitchExceptions == NULL) ||
|
||||
(StackSwitchData->X64.StackSwitchExceptionNumber == 0) ||
|
||||
(StackSwitchData->X64.StackSwitchExceptionNumber > CPU_EXCEPTION_NUM) ||
|
||||
(StackSwitchData->X64.GdtTable == NULL) ||
|
||||
(StackSwitchData->X64.IdtTable == NULL) ||
|
||||
(StackSwitchData->X64.ExceptionTssDesc == NULL) ||
|
||||
(StackSwitchData->X64.ExceptionTss == NULL))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -163,7 +164,8 @@ ArchSetupExceptionStack (
|
||||
}
|
||||
|
||||
if (((UINTN)StackSwitchData->X64.ExceptionTssDesc + StackSwitchData->X64.ExceptionTssDescSize) >
|
||||
((UINTN)(StackSwitchData->X64.GdtTable) + StackSwitchData->X64.GdtTableSize)) {
|
||||
((UINTN)(StackSwitchData->X64.GdtTable) + StackSwitchData->X64.GdtTableSize))
|
||||
{
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -173,6 +175,7 @@ ArchSetupExceptionStack (
|
||||
if (StackSwitchData->X64.ExceptionTssDescSize < sizeof (IA32_TSS_DESCRIPTOR)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (StackSwitchData->X64.ExceptionTssSize < sizeof (IA32_TASK_STATE_SEGMENT)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -196,13 +199,14 @@ ArchSetupExceptionStack (
|
||||
(UINTN)(StackSwitchData->X64.GdtTable);
|
||||
if ((UINTN)StackSwitchData->X64.GdtTable != Gdtr.Base) {
|
||||
CopyMem (StackSwitchData->X64.GdtTable, (VOID *)Gdtr.Base, Gdtr.Limit + 1);
|
||||
Gdtr.Base = (UINTN)StackSwitchData->X64.GdtTable;
|
||||
Gdtr.Base = (UINTN)StackSwitchData->X64.GdtTable;
|
||||
Gdtr.Limit = (UINT16)GdtSize - 1;
|
||||
}
|
||||
|
||||
if ((UINTN)StackSwitchData->X64.IdtTable != Idtr.Base) {
|
||||
Idtr.Base = (UINTN)StackSwitchData->X64.IdtTable;
|
||||
}
|
||||
|
||||
if (StackSwitchData->X64.IdtTableSize > 0) {
|
||||
Idtr.Limit = (UINT16)(StackSwitchData->X64.IdtTableSize - 1);
|
||||
}
|
||||
@@ -213,16 +217,16 @@ ArchSetupExceptionStack (
|
||||
//
|
||||
TssBase = (UINTN)Tss;
|
||||
|
||||
TssDesc->Uint128.Uint64 = 0;
|
||||
TssDesc->Uint128.Uint64_1= 0;
|
||||
TssDesc->Bits.LimitLow = sizeof(IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.BaseLow = (UINT16)TssBase;
|
||||
TssDesc->Bits.BaseMidl = (UINT8)(TssBase >> 16);
|
||||
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
|
||||
TssDesc->Bits.P = 1;
|
||||
TssDesc->Bits.LimitHigh = 0;
|
||||
TssDesc->Bits.BaseMidh = (UINT8)(TssBase >> 24);
|
||||
TssDesc->Bits.BaseHigh = (UINT32)(TssBase >> 32);
|
||||
TssDesc->Uint128.Uint64 = 0;
|
||||
TssDesc->Uint128.Uint64_1 = 0;
|
||||
TssDesc->Bits.LimitLow = sizeof (IA32_TASK_STATE_SEGMENT) - 1;
|
||||
TssDesc->Bits.BaseLow = (UINT16)TssBase;
|
||||
TssDesc->Bits.BaseMidl = (UINT8)(TssBase >> 16);
|
||||
TssDesc->Bits.Type = IA32_GDT_TYPE_TSS;
|
||||
TssDesc->Bits.P = 1;
|
||||
TssDesc->Bits.LimitHigh = 0;
|
||||
TssDesc->Bits.BaseMidh = (UINT8)(TssBase >> 24);
|
||||
TssDesc->Bits.BaseHigh = (UINT32)(TssBase >> 32);
|
||||
|
||||
//
|
||||
// Fixup exception task descriptor and task-state segment
|
||||
@@ -236,16 +240,18 @@ ArchSetupExceptionStack (
|
||||
// Fixup IST
|
||||
//
|
||||
Tss->IST[Index] = StackTop;
|
||||
StackTop -= StackSwitchData->X64.KnownGoodStackSize;
|
||||
StackTop -= StackSwitchData->X64.KnownGoodStackSize;
|
||||
|
||||
//
|
||||
// Set the IST field to enable corresponding IST
|
||||
//
|
||||
Vector = StackSwitchData->X64.StackSwitchExceptions[Index];
|
||||
if (Vector >= CPU_EXCEPTION_NUM ||
|
||||
Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)) {
|
||||
if ((Vector >= CPU_EXCEPTION_NUM) ||
|
||||
(Vector >= (Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IdtTable[Vector].Bits.Reserved_0 = (UINT8)(Index + 1);
|
||||
}
|
||||
|
||||
@@ -276,8 +282,8 @@ ArchSetupExceptionStack (
|
||||
VOID
|
||||
EFIAPI
|
||||
DumpCpuContext (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
InternalPrintMessage (
|
||||
@@ -304,8 +310,10 @@ DumpCpuContext (
|
||||
(SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_SGX) != 0
|
||||
);
|
||||
}
|
||||
|
||||
InternalPrintMessage ("\n");
|
||||
}
|
||||
|
||||
InternalPrintMessage (
|
||||
"RIP - %016lx, CS - %016lx, RFLAGS - %016lx\n",
|
||||
SystemContext.SystemContextX64->Rip,
|
||||
@@ -406,8 +414,8 @@ DumpCpuContext (
|
||||
**/
|
||||
VOID
|
||||
DumpImageAndCpuContent (
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN EFI_EXCEPTION_TYPE ExceptionType,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
DumpCpuContext (ExceptionType, SystemContext);
|
||||
@@ -415,7 +423,8 @@ DumpImageAndCpuContent (
|
||||
// Dump module image base and module entry point by RIP
|
||||
//
|
||||
if ((ExceptionType == EXCEPT_IA32_PAGE_FAULT) &&
|
||||
((SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID) != 0)) {
|
||||
((SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID) != 0))
|
||||
{
|
||||
//
|
||||
// The RIP in SystemContext could not be used
|
||||
// if it is page fault with I/D set.
|
||||
|
@@ -10,9 +10,9 @@
|
||||
#define _ARCH_CPU_INTERRUPT_DEFS_H_
|
||||
|
||||
typedef struct {
|
||||
EFI_SYSTEM_CONTEXT_X64 SystemContext;
|
||||
BOOLEAN ExceptionDataFlag;
|
||||
UINTN OldIdtHandler;
|
||||
EFI_SYSTEM_CONTEXT_X64 SystemContext;
|
||||
BOOLEAN ExceptionDataFlag;
|
||||
UINTN OldIdtHandler;
|
||||
} EXCEPTION_HANDLER_CONTEXT;
|
||||
|
||||
//
|
||||
@@ -24,20 +24,20 @@ typedef struct {
|
||||
} CPU_STATUS_CODE_TEMPLATE;
|
||||
|
||||
typedef struct {
|
||||
SPIN_LOCK SpinLock;
|
||||
UINT32 ApicId;
|
||||
UINT32 Attribute;
|
||||
UINTN ExceptonHandler;
|
||||
UINTN OldSs;
|
||||
UINTN OldSp;
|
||||
UINTN OldFlags;
|
||||
UINTN OldCs;
|
||||
UINTN OldIp;
|
||||
UINTN ExceptionData;
|
||||
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
|
||||
SPIN_LOCK SpinLock;
|
||||
UINT32 ApicId;
|
||||
UINT32 Attribute;
|
||||
UINTN ExceptonHandler;
|
||||
UINTN OldSs;
|
||||
UINTN OldSp;
|
||||
UINTN OldFlags;
|
||||
UINTN OldCs;
|
||||
UINTN OldIp;
|
||||
UINTN ExceptionData;
|
||||
UINT8 HookAfterStubHeaderCode[HOOKAFTER_STUB_SIZE];
|
||||
} RESERVED_VECTORS_DATA;
|
||||
|
||||
#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
|
||||
#define CPU_TSS_SIZE sizeof (IA32_TASK_STATE_SEGMENT)
|
||||
#define CPU_TSS_DESC_SIZE sizeof (IA32_TSS_DESCRIPTOR)
|
||||
#define CPU_TSS_SIZE sizeof (IA32_TASK_STATE_SEGMENT)
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user