X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=IntelFsp2Pkg%2FFspSecCore%2FSecMain.c;h=c7caa3e7f927d23fb0284eaad0c2c6a501d30e75;hb=12a0a80b4aeeb9a8435ee785e685e33eb7ee451c;hp=5a43ba1967143e2fc8849424bf8af32deaef1eff;hpb=e37bb20c7b4e63de1664edae19afc7c1a95853fa;p=mirror_edk2.git diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/SecMain.c index 5a43ba1967..c7caa3e7f9 100644 --- a/IntelFsp2Pkg/FspSecCore/SecMain.c +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -19,6 +19,11 @@ EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI gSecTemporaryRamSupportPpi = { }; EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gFspInApiModePpiGuid, + NULL + }, { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiTemporaryRamSupportPpiGuid, @@ -65,6 +70,7 @@ SecStartup ( UINT32 Index; FSP_GLOBAL_DATA PeiFspData; UINT64 ExceptionHandler; + UINTN IdtSize; // // Process all libraries constructor function linked to SecCore. @@ -77,7 +83,29 @@ SecStartup ( // InitializeFloatingPointUnits (); + // + // Scenario 1 memory map when running on bootloader stack + // + // |-------------------|----> + // |Idt Table | + // |-------------------| + // |PeiService Pointer | + // |-------------------| + // | | + // | | + // | Heap | + // | | + // | | + // |-------------------|----> TempRamBase + // + // + // |-------------------| + // |Bootloader stack |----> somewhere in memory, FSP will share this stack. + // |-------------------| + // + // Scenario 2 memory map when running FSP on a separate stack + // // |-------------------|----> // |Idt Table | // |-------------------| @@ -93,13 +121,26 @@ SecStartup ( // | | // |-------------------|----> TempRamBase IdtTableInStack.PeiService = NULL; - ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate); - for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { - CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64)); + AsmReadIdtr (&IdtDescriptor); + if (IdtDescriptor.Base == 0) { + ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate); + for (Index = 0; Index < FixedPcdGet8(PcdFspMaxInterruptSupported); Index ++) { + CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&ExceptionHandler, sizeof (UINT64)); + } + IdtSize = sizeof (IdtTableInStack.IdtTable); + } else { + IdtSize = IdtDescriptor.Limit + 1; + if (IdtSize > sizeof (IdtTableInStack.IdtTable)) { + // + // ERROR: IDT table size from boot loader is larger than FSP can support, DeadLoop here! + // + CpuDeadLoop(); + } else { + CopyMem ((VOID *) (UINTN) &IdtTableInStack.IdtTable, (VOID *) IdtDescriptor.Base, IdtSize); + } } - IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable; - IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); + IdtDescriptor.Limit = (UINT16)(IdtSize - 1); AsmWriteIdtr (&IdtDescriptor); @@ -116,11 +157,19 @@ SecStartup ( SecCoreData.BootFirmwareVolumeSize = (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *)BootFirmwareVolume)->FvLength; SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase; - SecCoreData.TemporaryRamSize = SizeOfRam; - SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase; - SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize * PcdGet8 (PcdFspHeapSizePercentage) / 100; - SecCoreData.StackBase = (VOID*)(UINTN)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize); - SecCoreData.StackSize = SecCoreData.TemporaryRamSize - SecCoreData.PeiTemporaryRamSize; + if (PcdGet8 (PcdFspHeapSizePercentage) == 0) { + SecCoreData.TemporaryRamSize = SizeOfRam; // stack size that is going to be copied to the permanent memory + SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase; + SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize; + SecCoreData.StackBase = (VOID *)GetFspEntryStack(); // Share the same boot loader stack + SecCoreData.StackSize = 0; + } else { + SecCoreData.TemporaryRamSize = SizeOfRam; + SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase; + SecCoreData.PeiTemporaryRamSize = SecCoreData.TemporaryRamSize * PcdGet8 (PcdFspHeapSizePercentage) / 100; + SecCoreData.StackBase = (VOID*)(UINTN)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize); + SecCoreData.StackSize = SecCoreData.TemporaryRamSize - SecCoreData.PeiTemporaryRamSize; + } DEBUG ((DEBUG_INFO, "Fsp BootFirmwareVolumeBase - 0x%x\n", SecCoreData.BootFirmwareVolumeBase)); DEBUG ((DEBUG_INFO, "Fsp BootFirmwareVolumeSize - 0x%x\n", SecCoreData.BootFirmwareVolumeSize)); @@ -175,15 +224,37 @@ SecTemporaryRamSupport ( UINTN HeapSize; UINTN StackSize; - HeapSize = CopySize * PcdGet8 (PcdFspHeapSizePercentage) / 100 ; - StackSize = CopySize - HeapSize; + UINTN CurrentStack; + UINTN FspStackBase; - OldHeap = (VOID*)(UINTN)TemporaryMemoryBase; - NewHeap = (VOID*)((UINTN)PermanentMemoryBase + StackSize); + if (PcdGet8 (PcdFspHeapSizePercentage) == 0) { - OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize); - NewStack = (VOID*)(UINTN)PermanentMemoryBase; + CurrentStack = AsmReadEsp(); + FspStackBase = (UINTN)GetFspEntryStack(); + StackSize = FspStackBase - CurrentStack; + HeapSize = CopySize; + + OldHeap = (VOID*)(UINTN)TemporaryMemoryBase; + NewHeap = (VOID*)((UINTN)PermanentMemoryBase); + + OldStack = (VOID*)CurrentStack; + // + //The old stack is copied at the end of the stack region because stack grows down. + // + NewStack = (VOID*)((UINTN)PermanentMemoryBase - StackSize); + + } else { + HeapSize = CopySize * PcdGet8 (PcdFspHeapSizePercentage) / 100 ; + StackSize = CopySize - HeapSize; + + OldHeap = (VOID*)(UINTN)TemporaryMemoryBase; + NewHeap = (VOID*)((UINTN)PermanentMemoryBase + StackSize); + + OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize); + NewStack = (VOID*)(UINTN)PermanentMemoryBase; + + } // // Migrate Heap //