+ //\r
+ // In theory, the size of new stack in permenent memory should large than\r
+ // size of old stack in temporary memory.\r
+ // But if new stack is smaller than the size of old stack, we also reserve\r
+ // the size of old stack at bottom of permenent memory.\r
+ //\r
+ StackGap = 0;\r
+ if (Private->StackSize > OldPeiStackSize) {\r
+ StackGap = Private->StackSize - OldPeiStackSize;\r
+ }\r
+\r
+ //\r
+ // Update HandOffHob for new installed permenent memory\r
+ //\r
+ OldHandOffTable = Private->HobList.HandoffInformationTable;\r
+ OldCheckingBottom = (UINTN)(SecCoreData->TemporaryRamBase);\r
+ OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);\r
+\r
+ //\r
+ // The whole temporary memory will be migrated to physical memory.\r
+ // CAUTION: The new base is computed accounding to gap of new stack.\r
+ //\r
+ NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r
+ \r
+ //\r
+ // Caculate stack offset and heap offset between CAR and new permement \r
+ // memory seperately.\r
+ //\r
+ StackOffset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase;\r
+ HeapOffset = (INTN) ((UINTN) Private->PhysicalMemoryBegin + Private->StackSize - \\r
+ (UINTN) SecCoreData->PeiTemporaryRamBase);\r
+ DEBUG ((EFI_D_INFO, "Heap Offset = 0x%X Stack Offset = 0x%X\n", HeapOffset, StackOffset));\r
+ \r
+ //\r
+ // Caculate new HandOffTable and PrivateData address in permenet memory's stack\r
+ //\r
+ NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + HeapOffset);\r
+ PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + StackOffset);\r
+\r
+ //\r
+ // TemporaryRamSupportPpi is produced by platform's SEC\r
+ //\r
+ Status = PeiLocatePpi (\r
+ (CONST EFI_PEI_SERVICES **) PeiServices,\r
+ &gEfiTemporaryRamSupportPpiGuid,\r
+ 0,\r
+ NULL,\r
+ (VOID**)&TemporaryRamSupportPpi\r
+ );\r
+\r
+\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Temporary Ram support Ppi is provided by platform, it will copy \r
+ // temporary memory to permenent memory and do stack switching.\r
+ // After invoken temporary Ram support, following code's stack is in \r
+ // memory but not in CAR.\r
+ //\r
+ TemporaryRamSupportPpi->TemporaryRamMigration (\r
+ (CONST EFI_PEI_SERVICES **) PeiServices,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,\r
+ (EFI_PHYSICAL_ADDRESS)(UINTN) NewPermenentMemoryBase,\r
+ SecCoreData->TemporaryRamSize\r
+ );\r
+\r
+ } else {\r
+ //\r
+ // In IA32/x64/Itanium architecture, we need platform provide\r
+ // TEMPORAY_RAM_MIGRATION_PPI.\r
+ //\r
+ ASSERT (FALSE);\r
+ }\r