C functions in SEC\r
\r
Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
}\r
};\r
\r
+/**\r
+ Migrates the Global Descriptor Table (GDT) to permanent memory.\r
+\r
+ @retval EFI_SUCCESS The GDT was migrated successfully.\r
+ @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lack of available memory.\r
+\r
+**/\r
+EFI_STATUS\r
+MigrateGdt (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN GdtBufferSize;\r
+ IA32_DESCRIPTOR Gdtr;\r
+ VOID *GdtBuffer;\r
+\r
+ AsmReadGdtr ((IA32_DESCRIPTOR *) &Gdtr);\r
+ GdtBufferSize = sizeof (IA32_SEGMENT_DESCRIPTOR) -1 + Gdtr.Limit + 1;\r
+\r
+ Status = PeiServicesAllocatePool (\r
+ GdtBufferSize,\r
+ &GdtBuffer\r
+ );\r
+ ASSERT (GdtBuffer != NULL);\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ GdtBuffer = ALIGN_POINTER (GdtBuffer, sizeof (IA32_SEGMENT_DESCRIPTOR));\r
+ CopyMem (GdtBuffer, (VOID *) Gdtr.Base, Gdtr.Limit + 1);\r
+ Gdtr.Base = (UINTN) GdtBuffer;\r
+ AsmWriteGdtr (&Gdtr);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
//\r
// These are IDT entries pointing to 10:FFFFFFE4h.\r
//\r
\r
PeiCoreEntryPoint = NULL;\r
SecCoreData = (EFI_SEC_PEI_HAND_OFF *) Context;\r
- AllSecPpiList = (EFI_PEI_PPI_DESCRIPTOR *) SecCoreData->PeiTemporaryRamBase;\r
\r
//\r
// Perform platform specific initialization before entering PeiCore.\r
// is enabled.\r
//\r
if (PpiList != NULL) {\r
- for (Index = 0;\r
- (PpiList[Index].Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
- Index++) {\r
+ Index = 0;\r
+ do {\r
if (CompareGuid (PpiList[Index].Guid, &gEfiPeiCoreFvLocationPpiGuid) &&\r
(((EFI_PEI_CORE_FV_LOCATION_PPI *) PpiList[Index].Ppi)->PeiCoreFvLocation != 0)\r
) {\r
break;\r
} else {\r
//\r
- // PeiCore not found\r
+ // Invalid PeiCore FV provided by platform\r
//\r
CpuDeadLoop ();\r
}\r
}\r
- }\r
+ } while ((PpiList[Index++].Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r
}\r
//\r
// If EFI_PEI_CORE_FV_LOCATION_PPI not found, try to locate PeiCore from BFV.\r
}\r
\r
if (PpiList != NULL) {\r
+ AllSecPpiList = (EFI_PEI_PPI_DESCRIPTOR *) SecCoreData->PeiTemporaryRamBase;\r
+\r
//\r
// Remove the terminal flag from the terminal PPI\r
//\r
VOID\r
)\r
{\r
- BOOLEAN State;\r
+ EFI_STATUS Status;\r
+ EFI_STATUS Status2;\r
+ UINTN Index;\r
+ BOOLEAN State;\r
+ EFI_PEI_PPI_DESCRIPTOR *PeiPpiDescriptor;\r
+ REPUBLISH_SEC_PPI_PPI *RepublishSecPpiPpi;\r
\r
//\r
// Republish Sec Platform Information(2) PPI\r
//\r
RepublishSecPlatformInformationPpi ();\r
\r
+ //\r
+ // Re-install SEC PPIs using a PEIM produced service if published\r
+ //\r
+ for (Index = 0, Status = EFI_SUCCESS; Status == EFI_SUCCESS; Index++) {\r
+ Status = PeiServicesLocatePpi (\r
+ &gRepublishSecPpiPpiGuid,\r
+ Index,\r
+ &PeiPpiDescriptor,\r
+ (VOID **) &RepublishSecPpiPpi\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_INFO, "Calling RepublishSecPpi instance %d.\n", Index));\r
+ Status2 = RepublishSecPpiPpi->RepublishSecPpis ();\r
+ ASSERT_EFI_ERROR (Status2);\r
+ }\r
+ }\r
+\r
//\r
// Migrate DebugAgentContext.\r
//\r
//\r
// Disable interrupts and save current interrupt state\r
//\r
- State = SaveAndDisableInterrupts();\r
+ State = SaveAndDisableInterrupts ();\r
+\r
+ //\r
+ // Migrate GDT before NEM near down\r
+ //\r
+ if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes)) {\r
+ Status = MigrateGdt ();\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
\r
//\r
// Disable Temporary RAM after Stack and Heap have been migrated at this point.\r