+ // Perform PEI Core phase specific actions.\r
+ //\r
+ if (OldCoreData == NULL) {\r
+ //\r
+ // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.\r
+ //\r
+ ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
+ PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
+ CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
+ } else {\r
+ //\r
+ // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet.\r
+ //\r
+ if (OldCoreData->ShadowedPeiCore == NULL) {\r
+ //\r
+ // Fixup the PeiCore's private data\r
+ //\r
+ OldCoreData->Ps = &OldCoreData->ServiceTableShadow;\r
+ OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;\r
+ if (OldCoreData->HeapOffsetPositive) {\r
+ OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);\r
+ } else {\r
+ OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);\r
+ }\r
+\r
+ //\r
+ // Initialize libraries that the PEI Core is linked against\r
+ //\r
+ ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
+ \r
+ //\r
+ // Fixup for PeiService's address\r
+ //\r
+ SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
+\r
+ //\r
+ // Update HandOffHob for new installed permenent memory\r
+ //\r
+ HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r
+ if (OldCoreData->HeapOffsetPositive) {\r
+ HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;\r
+ } else {\r
+ HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;\r
+ }\r
+ HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;\r
+ HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin;\r
+ HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop;\r
+ HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r
+\r
+ //\r
+ // We need convert the PPI descriptor's pointer\r
+ //\r
+ ConvertPpiPointers (SecCoreData, OldCoreData);\r
+\r
+ //\r
+ // After the whole temporary memory is migrated, then we can allocate page in\r
+ // permenent memory.\r
+ //\r
+ OldCoreData->PeiMemoryInstalled = TRUE;\r
+\r
+ //\r
+ // Indicate that PeiCore reenter\r
+ //\r
+ OldCoreData->PeimDispatcherReenter = TRUE;\r
+ \r
+ if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
+ //\r
+ // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.\r
+ // Every bit in the array indicate the status of the corresponding memory page available or not\r
+ //\r
+ OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));\r
+ }\r
+\r
+ //\r
+ // Shadow PEI Core. When permanent memory is avaiable, shadow\r
+ // PEI Core and PEIMs to get high performance.\r
+ //\r
+ OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r
+ \r
+ //\r
+ // PEI Core has now been shadowed to memory. Restart PEI Core in memory.\r
+ //\r
+ OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData);\r
+ \r
+ //\r
+ // Should never reach here.\r
+ //\r
+ ASSERT (FALSE);\r
+ CpuDeadLoop();\r