11extern UINT64 gTaskGateDescriptor;
16extern BOOLEAN mCetSupported;
18X86_ASSEMBLY_PATCH_LABEL mPatchCetPl0Ssp;
19X86_ASSEMBLY_PATCH_LABEL mPatchCetInterruptSsp;
21UINT32 mCetInterruptSsp;
33 IA32_IDT_GATE_DESCRIPTOR *IdtGate;
40 IdtGate = (IA32_IDT_GATE_DESCRIPTOR *)gcSmiIdtr.Base;
41 IdtGate += EXCEPT_IA32_PAGE_FAULT;
42 IdtGate->Uint64 = gTaskGateDescriptor;
61 IA32_SEGMENT_DESCRIPTOR *GdtDescriptor;
63 UINTN GdtTssTableSize;
65 UINTN GdtTableStepSize;
66 UINTN InterruptShadowStack;
78 gcSmiGdtr.Limit += (UINT16)(2 *
sizeof (IA32_SEGMENT_DESCRIPTOR));
80 GdtTssTableSize = (gcSmiGdtr.Limit + 1 + TSS_SIZE + EXCEPTION_TSS_SIZE + 7) & ~7;
81 mGdtBufferSize = GdtTssTableSize * gSmmCpuPrivate->SmmCoreEntryContext.
NumberOfCpus;
88 ASSERT (GdtTssTables !=
NULL);
89 mGdtBuffer = (
UINTN)GdtTssTables;
90 GdtTableStepSize = GdtTssTableSize;
92 for (Index = 0; Index < gSmmCpuPrivate->SmmCoreEntryContext.
NumberOfCpus; Index++) {
93 CopyMem (GdtTssTables + GdtTableStepSize * Index, (VOID *)(
UINTN)gcSmiGdtr.Base, gcSmiGdtr.Limit + 1 + TSS_SIZE + EXCEPTION_TSS_SIZE);
97 TssBase = (
UINTN)(GdtTssTables + GdtTableStepSize * Index + gcSmiGdtr.Limit + 1);
98 GdtDescriptor = (IA32_SEGMENT_DESCRIPTOR *)(TssBase) - 2;
99 GdtDescriptor->Bits.BaseLow = (UINT16)TssBase;
100 GdtDescriptor->Bits.BaseMid = (UINT8)(TssBase >> 16);
101 GdtDescriptor->Bits.BaseHigh = (UINT8)(TssBase >> 24);
105 GdtDescriptor->Bits.BaseLow = (UINT16)TssBase;
106 GdtDescriptor->Bits.BaseMid = (UINT8)(TssBase >> 16);
107 GdtDescriptor->Bits.BaseHigh = (UINT8)(TssBase >> 24);
113 *(
UINTN *)(TssBase + TSS_IA32_ESP_OFFSET) = mSmmStackArrayBase + EFI_PAGE_SIZE + Index * mSmmStackSize;
114 *(UINT32 *)(TssBase + TSS_IA32_CR3_OFFSET) = Cr3;
119 if ((
PcdGet32 (PcdControlFlowEnforcementPropertyMask) != 0) && mCetSupported) {
120 InterruptShadowStack = (
UINTN)(mSmmStackArrayBase + mSmmStackSize +
EFI_PAGES_TO_SIZE (1) -
sizeof (UINT64) + (mSmmStackSize + mSmmShadowStackSize) * Index);
121 *(UINT32 *)(TssBase + TSS_IA32_SSP_OFFSET) = (UINT32)InterruptShadowStack;
128 GdtTssTableSize = gcSmiGdtr.Limit + 1;
129 mGdtBufferSize = GdtTssTableSize * gSmmCpuPrivate->SmmCoreEntryContext.
NumberOfCpus;
131 ASSERT (GdtTssTables !=
NULL);
132 mGdtBuffer = (
UINTN)GdtTssTables;
133 GdtTableStepSize = GdtTssTableSize;
135 for (Index = 0; Index < gSmmCpuPrivate->SmmCoreEntryContext.
NumberOfCpus; Index++) {
136 CopyMem (GdtTssTables + GdtTableStepSize * Index, (VOID *)(
UINTN)gcSmiGdtr.Base, gcSmiGdtr.Limit + 1);
140 *GdtStepSize = GdtTableStepSize;
156 UINTN SmmShadowStackSize;
158 if ((
PcdGet32 (PcdControlFlowEnforcementPropertyMask) != 0) && mCetSupported) {
164 mCetPl0Ssp = (UINT32)((
UINTN)ShadowStack + SmmShadowStackSize -
sizeof (UINT64));
166 DEBUG ((DEBUG_INFO,
"mCetPl0Ssp - 0x%x\n", mCetPl0Ssp));
167 DEBUG ((DEBUG_INFO,
"ShadowStack - 0x%x\n", ShadowStack));
168 DEBUG ((DEBUG_INFO,
" SmmShadowStackSize - 0x%x\n", SmmShadowStackSize));
173 DEBUG ((DEBUG_INFO,
"mCetInterruptSsp - 0x%x\n", mCetInterruptSsp));
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI InitializeIDTSmmStackGuard(VOID)
VOID InitShadowStack(IN UINTN CpuIndex, IN VOID *ShadowStack)
VOID * InitGdt(IN UINTN Cr3, OUT UINTN *GdtStepSize)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
#define FeaturePcdGet(TokenName)
STATIC VOID *EFIAPI AllocateCodePages(IN UINTN Pages)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
VOID EFIAPI PatchInstructionX86(OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd, IN UINT64 PatchValue, IN UINTN ValueSize)