/** The constructor function caches the pointer to PEI services. The constructor function caches the pointer to PEI services. It will always return EFI_SUCCESS. @param FileHandle The handle of FFS header the loaded driver. @param PeiServices The pointer to the PEI services. @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. **/ EFI_STATUS EFIAPI PeiServicesTablePointerLibConstructor ( IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices ) { SetPeiServicesTablePointer (PeiServices); return EFI_SUCCESS; }
VOID MigrateIdtTable ( IN EFI_PEI_SERVICES **PeiServices ) /*++ Routine Description: Migrate IDT from temporary memory to real memory where preceded with 4 bytes for storing PeiService pointer. Arguments: PeiServices - The direct pointer to PeiServiceTable. Returns: NONE. --*/ { #ifndef EFI_NT_EMULATOR UINT16 IdtEntrySize; UINTN OldIdtBase; UINTN Size; VOID *NewIdtBase; EFI_STATUS Status; IdtEntrySize = ReadIdtLimit(); OldIdtBase = ReadIdtBase(); Size = sizeof(PEI_IDT_TABLE) + (IdtEntrySize + 1); Status = (*PeiServices)->AllocatePool (PeiServices, Size, &NewIdtBase); ASSERT_PEI_ERROR (PeiServices, Status); (*PeiServices)->CopyMem ((VOID*)((UINTN)NewIdtBase + sizeof(PEI_IDT_TABLE)), (VOID*)OldIdtBase, (IdtEntrySize + 1)); SetIdtBase(((UINTN)NewIdtBase + sizeof(PEI_IDT_TABLE)), IdtEntrySize); SetPeiServicesTablePointer(PeiServices); #endif }
/** This routine is invoked by main entry of PeiMain module during transition from SEC to PEI. After switching stack in the PEI core, it will restart with the old core data. @param SecCoreDataPtr Points to a data structure containing information about the PEI core's operating environment, such as the size and location of temporary RAM, the stack location and the BFV location. @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core. An empty PPI list consists of a single descriptor with the end-tag EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such that both the PEI Foundation and any modules can leverage the associated service calls and/or code in these early PPIs @param Data Pointer to old core data that is used to initialize the core's data areas. If NULL, it is first PeiCore entering. **/ VOID EFIAPI PeiCore ( IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, IN VOID *Data ) { PEI_CORE_INSTANCE PrivateData; EFI_SEC_PEI_HAND_OFF *SecCoreData; EFI_SEC_PEI_HAND_OFF NewSecCoreData; EFI_STATUS Status; PEI_CORE_TEMP_POINTERS TempPtr; PEI_CORE_INSTANCE *OldCoreData; EFI_PEI_CPU_IO_PPI *CpuIo; EFI_PEI_PCI_CFG2_PPI *PciCfg; EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable; EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi; // // Retrieve context passed into PEI Core // OldCoreData = (PEI_CORE_INSTANCE *) Data; SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr; // // Perform PEI Core phase specific actions. // if (OldCoreData == NULL) { // // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available. // ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE)); PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE; CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs)); } else { // // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet. // if (OldCoreData->ShadowedPeiCore == NULL) { // // Fixup the PeiCore's private data // OldCoreData->Ps = &OldCoreData->ServiceTableShadow; OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo; if (OldCoreData->HeapOffsetPositive) { OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset); } else { OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset); } // // Initialize libraries that the PEI Core is linked against // ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps); // // Fixup for PeiService's address // SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps); // // Update HandOffHob for new installed permenent memory // HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable; if (OldCoreData->HeapOffsetPositive) { HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset; } else { HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset; } HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength; HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin; HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop; HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER); // // We need convert the PPI descriptor's pointer // ConvertPpiPointers (SecCoreData, OldCoreData); // // After the whole temporary memory is migrated, then we can allocate page in // permenent memory. // OldCoreData->PeiMemoryInstalled = TRUE; // // Indicate that PeiCore reenter // OldCoreData->PeimDispatcherReenter = TRUE; if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) { // // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array. // Every bit in the array indicate the status of the corresponding memory page available or not // OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64)); } // // Shadow PEI Core. When permanent memory is avaiable, shadow // PEI Core and PEIMs to get high performance. // OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData); // // PEI Core has now been shadowed to memory. Restart PEI Core in memory. // OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData); // // Should never reach here. // ASSERT (FALSE); CpuDeadLoop(); }