Skip to content

Commit f121374

Browse files
LiuZhiguang001mergify[bot]
authored andcommitted
IntelFsp2Pkg: Migrate GDT in SecTemporaryRamSupport
FSP API mode is using a separate GDT, which may be in NEM or flash. Need to migrate it into permanent memory Signed-off-by: Zhiguang Liu <[email protected]>
1 parent 2fda942 commit f121374

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

IntelFsp2Pkg/FspSecCore/SecMain.c

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,43 @@ SecTemporaryRamSupport (
215215
IN UINTN CopySize
216216
)
217217
{
218-
IA32_DESCRIPTOR IdtDescriptor;
219-
VOID *OldHeap;
220-
VOID *NewHeap;
221-
VOID *OldStack;
222-
VOID *NewStack;
223-
UINTN HeapSize;
224-
UINTN StackSize;
225-
226-
UINTN CurrentStack;
227-
UINTN FspStackBase;
218+
IA32_DESCRIPTOR IdtDescriptor;
219+
VOID *OldHeap;
220+
VOID *NewHeap;
221+
VOID *OldStack;
222+
VOID *NewStack;
223+
UINTN HeapSize;
224+
UINTN StackSize;
225+
IA32_DESCRIPTOR Gdtr;
226+
EFI_PHYSICAL_ADDRESS GdtBuffer;
227+
EFI_STATUS Status;
228+
UINTN CurrentStack;
229+
UINTN FspStackBase;
230+
231+
//
232+
// Migrates the Global Descriptor Table (GDT) to permanent memory.
233+
//
234+
AsmReadGdtr (&Gdtr);
235+
236+
//
237+
// Allocate the permanent memory for GDT.
238+
//
239+
Status = (*PeiServices)->AllocatePages (
240+
PeiServices,
241+
EfiBootServicesCode,
242+
EFI_SIZE_TO_PAGES (Gdtr.Limit + 1),
243+
&GdtBuffer
244+
);
245+
246+
if (EFI_ERROR (Status)) {
247+
ASSERT_EFI_ERROR (Status);
248+
return EFI_OUT_OF_RESOURCES;
249+
}
250+
251+
ASSERT ((VOID *)(UINTN)GdtBuffer != NULL);
252+
CopyMem ((VOID *)(UINTN)GdtBuffer, (VOID *)Gdtr.Base, Gdtr.Limit + 1);
253+
Gdtr.Base = (UINTN)GdtBuffer;
254+
AsmWriteGdtr (&Gdtr);
228255

229256
//
230257
// Override OnSeparateStack to 1 because this function will switch stack to permanent memory

0 commit comments

Comments
 (0)