EFI_HANDLE Handle;\r
} PEIM_FILE_HANDLE_EXTENDED_DATA;\r
\r
-STATIC\r
-VOID\r
-InvokePeiCore (\r
- VOID *Context1,\r
- VOID *Context2\r
- );\r
-\r
VOID\r
DiscoverPeimsAndOrderWithApriori (\r
IN PEI_CORE_INSTANCE *Private,\r
\r
NONE\r
\r
---*/ \r
+--*/\r
{\r
EFI_STATUS Status;\r
EFI_PEI_FV_HANDLE FileHandle;\r
//\r
for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
Status = PeiFindFileEx (\r
- VolumeHandle, \r
- NULL, \r
- PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r
+ VolumeHandle,\r
+ NULL,\r
+ PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,\r
&FileHandle,\r
&AprioriFileHandle\r
);\r
if (Status != EFI_SUCCESS) {\r
break;\r
}\r
- \r
+\r
Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
}\r
\r
- Private->AprioriCount = 0; \r
+ Private->AprioriCount = 0;\r
if (AprioriFileHandle != NULL) {\r
//\r
// Read the Apriori file\r
// Calculate the number of PEIMs in the A Priori list\r
//\r
Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r
- Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER); \r
+ Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);\r
Private->AprioriCount /= sizeof (EFI_GUID);\r
- \r
+\r
SetMem (FileGuid, sizeof (FileGuid), 0);\r
for (Index = 0; Index < PeimCount; Index++) {\r
//\r
// Make an array of file name guids that matches the FileHandle array so we can convert\r
// quickly from file name to file handle\r
//\r
- CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID)); \r
+ CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));\r
}\r
\r
//\r
// Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r
- // Add avalible PEIMs in Apriori file into TempFileHandles array at first. \r
+ // Add avalible PEIMs in Apriori file into TempFileHandles array at first.\r
//\r
Index2 = 0;\r
for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r
}\r
}\r
if (Guid == NULL) {\r
- break; \r
+ break;\r
}\r
PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r
TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r
// Update valid Aprioricount\r
//\r
Private->AprioriCount = Index;\r
- \r
+\r
//\r
// Add in any PEIMs not in the Apriori file\r
//\r
//Index the end of array contains re-range Pei moudle.\r
//\r
TempFileHandles[Index] = NULL;\r
- \r
+\r
//\r
// Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r
- // We need to update it to start with files in the A Priori list and \r
- // then the remaining files in PEIM order. \r
+ // We need to update it to start with files in the A Priori list and\r
+ // then the remaining files in PEIM order.\r
//\r
CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r
}\r
//\r
Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
- \r
+\r
+}\r
+\r
+VOID*\r
+ShadowPeiCore(\r
+ EFI_PEI_SERVICES **PeiServices,\r
+ PEI_CORE_INSTANCE *PrivateInMem\r
+ )\r
+{\r
+ EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r
+ EFI_PHYSICAL_ADDRESS EntryPoint;\r
+ EFI_STATUS Status;\r
+ UINT32 AuthenticationState;\r
+\r
+ PeiCoreFileHandle = NULL;\r
+\r
+ //\r
+ // Find the PEI Core in the BFV\r
+ //\r
+ Status = PeiFindFileEx (\r
+ (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r
+ NULL,\r
+ EFI_FV_FILETYPE_PEI_CORE,\r
+ &PeiCoreFileHandle,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Shadow PEI Core into memory so it will run faster\r
+ //\r
+ Status = PeiLoadImage (\r
+ PeiServices,\r
+ *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+ &EntryPoint,\r
+ &AuthenticationState\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r
}\r
\r
VOID\r
UINT32 Index1;\r
UINT32 Index2;\r
EFI_PEI_SERVICES **PeiServices;\r
- VOID *PrivateInMem;\r
- EFI_PEI_FV_HANDLE VolumeHandle; \r
- EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r
+ EFI_PEI_FV_HANDLE VolumeHandle;\r
+ //EFI_PHYSICAL_ADDRESS PeiCoreFileHandle;\r
EFI_PEI_FILE_HANDLE PeimFileHandle;\r
UINTN FvCount;\r
UINTN PeimCount;\r
UINTN SaveCurrentPeimCount;\r
UINTN SaveCurrentFvCount;\r
EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r
- VOID *TopOfStack;\r
- PEI_CORE_PARAMETERS PeiCoreParameters;\r
PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;\r
+ EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase;\r
+ TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r
+ EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable;\r
+ EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable;\r
+ INTN Offset;\r
+ PEI_CORE_INSTANCE *PrivateInMem;\r
+ UINT64 NewPeiStackSize;\r
+ UINT64 OldPeiStackSize;\r
+ UINT64 StackGap;\r
EFI_FV_FILE_INFO FvFileInfo;\r
+ UINTN OldCheckingTop;\r
+ UINTN OldCheckingBottom;\r
\r
\r
PeiServices = &Private->PS;\r
for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
- PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; \r
+ PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
Status = PeiLoadImage (\r
- &Private->PS, \r
- PeimFileHandle, \r
- &EntryPoint, \r
+ &Private->PS,\r
+ PeimFileHandle,\r
+ &EntryPoint,\r
&AuthenticationState\r
);\r
if (Status == EFI_SUCCESS) {\r
//\r
Private->Fv[Index1].PeimState[Index2]++;\r
Private->CurrentFileHandle = PeimFileHandle;\r
- Private->CurrentPeimFvCount = Index1; \r
- Private->CurrentPeimCount = Index2; \r
+ Private->CurrentPeimFvCount = Index1;\r
+ Private->CurrentPeimCount = Index2;\r
//\r
// Call the PEIM entry point\r
//\r
PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
- \r
+\r
PERF_START (0, "PEIM", NULL, 0);\r
PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS);\r
PERF_END (0, "PEIM", NULL, 0);\r
- } \r
- \r
+ }\r
+\r
//\r
// Process the Notify list and dispatch any notifies for\r
// newly installed PPIs.\r
}\r
}\r
}\r
- Private->CurrentFileHandle = SaveCurrentFileHandle; \r
- Private->CurrentPeimFvCount = SaveCurrentFvCount; \r
- Private->CurrentPeimCount = SaveCurrentPeimCount; \r
+ Private->CurrentFileHandle = SaveCurrentFileHandle;\r
+ Private->CurrentPeimFvCount = SaveCurrentFvCount;\r
+ Private->CurrentPeimCount = SaveCurrentPeimCount;\r
}\r
\r
//\r
if (Private->CurrentPeimCount == 0) {\r
//\r
// When going through each FV, at first, search Apriori file to\r
- // reorder all PEIMs to ensure the PEIMs in Apriori file to get \r
+ // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r
// dispatch at first.\r
//\r
DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r
//\r
// Start to dispatch all modules within the current Fv.\r
//\r
- for (PeimCount = Private->CurrentPeimCount; \r
- (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); \r
+ for (PeimCount = Private->CurrentPeimCount;\r
+ (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
PeimCount++) {\r
Private->CurrentPeimCount = PeimCount;\r
PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
// For PEIM driver, Load its entry point\r
//\r
Status = PeiLoadImage (\r
- PeiServices, \r
- PeimFileHandle, \r
- &EntryPoint, \r
+ PeiServices,\r
+ PeimFileHandle,\r
+ &EntryPoint,\r
&AuthenticationState\r
);\r
}\r
\r
if ((Status == EFI_SUCCESS)) {\r
//\r
- // The PEIM has its dependencies satisfied, and is processed.\r
+ // The PEIM has its dependencies satisfied, and its entry point\r
+ // has been found, so invoke it.\r
//\r
PERF_START (0, "PEIM", NULL, 0);\r
\r
// PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
//\r
Private->Fv[FvCount].PeimState[PeimCount]++;\r
- \r
+\r
if (FvFileInfo.FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
//\r
// Call the PEIM entry point for PEIM driver\r
);\r
PERF_END (0, "PEIM", NULL, 0);\r
\r
- } else {\r
+ }\r
+\r
+ if (Private->SwitchStackSignal) {\r
+\r
//\r
- // If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready,\r
- // we flag that more Peims need to be dispatched.\r
+ // Reserve the size of new stack at bottom of physical memory\r
//\r
- PeimNeedingDispatch = TRUE;\r
- }\r
+ OldPeiStackSize = Private->StackSize;\r
+ NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
+ if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {\r
+ Private->StackSize = NewPeiStackSize;\r
+ } else {\r
+ Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);\r
+ }\r
\r
- //\r
- // Process the Notify list and dispatch any notifies for\r
- // newly installed PPIs.\r
- //\r
- ProcessNotifyList (Private);\r
+ //\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
- // If permanent memory was discovered and installed by this\r
- // PEIM, shadow PEI Core and switch the stacks to the new memory. \r
- //\r
- if (Private->SwitchStackSignal) {\r
+ //\r
+ // Update HandOffHob for new installed permenent memory\r
+ //\r
+ OldHandOffTable = Private->HobList.HandoffInformationTable;\r
+ OldCheckingBottom = (UINTN)OldHandOffTable;\r
+ OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);\r
\r
//\r
- // Make sure we don't retry the same PEIM that added memory\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
- Private->CurrentPeimCount++;\r
+ NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r
+ Offset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->TemporaryRamBase;\r
+ NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + Offset);\r
+ PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + Offset);\r
\r
//\r
- // Migrate IDT from CAR into real memory, so after stack switches to\r
- // the new memory, the caller can get memory version PeiServiceTable. \r
+ // TemporaryRamSupportPpi is produced by platform's SEC\r
//\r
- MigrateIdtTable (PeiServices);\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
+ 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
+ CopyMem (\r
+ (VOID*)(UINTN) NewPermenentMemoryBase,\r
+ SecCoreData->TemporaryRamBase,\r
+ SecCoreData->TemporaryRamSize\r
+ );\r
+ }\r
+\r
+\r
+ //\r
//\r
- // Since we are at dispatch level, only the Core's private data \r
- // is preserved, nobody else should have any data on the stack. \r
- // So we need to copy PEI core instance data to memory.\r
+ // Fixup the PeiCore's private data\r
//\r
- PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r
- ASSERT (PrivateInMem != NULL);\r
+ PrivateInMem->PS = &PrivateInMem->ServiceTableShadow;\r
+ PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo;\r
+ PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset);\r
+ PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);\r
+\r
+ PeiServices = &PrivateInMem->PS;\r
+\r
+ //\r
+ // Fixup for PeiService's address\r
+ //\r
+ SetPeiServicesTablePointer(PeiServices);\r
+\r
+ //\r
+ // Update HandOffHob for new installed permenent memory\r
+ //\r
+ NewHandOffTable->EfiEndOfHobList =\r
+ (EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset);\r
+ NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin +\r
+ PrivateInMem->PhysicalMemoryLength;\r
+ NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin;\r
+ NewHandOffTable->EfiFreeMemoryTop = PrivateInMem->FreePhysicalMemoryTop;\r
+ NewHandOffTable->EfiFreeMemoryBottom = NewHandOffTable->EfiEndOfHobList +\r
+ sizeof (EFI_HOB_GENERIC_HEADER);\r
+\r
+ //\r
+ // We need convert the PPI desciptor's pointer\r
+ //\r
+ ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices, \r
+ OldCheckingBottom, \r
+ OldCheckingTop, \r
+ NewHandOffTable);\r
+\r
+ DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",\r
+ (UINTN)PrivateInMem->StackBase,\r
+ PrivateInMem->StackSize));\r
+ BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);\r
+\r
+ //\r
+ // After the whole temporary memory is migrated, then we can allocate page in\r
+ // permenent memory.\r
+ //\r
+ PrivateInMem->PeiMemoryInstalled = TRUE;\r
+\r
+ //\r
+ // Make sure we don't retry the same PEIM that added memory\r
+ //\r
+ PrivateInMem->CurrentPeimCount++;\r
\r
//\r
// Shadow PEI Core. When permanent memory is avaiable, shadow\r
// PEI Core and PEIMs to get high performance.\r
//\r
- PeiCoreFileHandle = NULL;\r
+ //PeiCoreFileHandle = 0;\r
//\r
// Find the PEI Core in the BFV\r
//\r
- Status = PeiFindFileEx (\r
- (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r
- NULL, \r
- EFI_FV_FILETYPE_PEI_CORE, \r
- &PeiCoreFileHandle,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- \r
+ //Status = PeiFindFileEx (\r
+ // (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r
+ // NULL,\r
+ // EFI_FV_FILETYPE_PEI_CORE,\r
+ // (EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle,\r
+ // NULL\r
+ // );\r
+ //ASSERT_EFI_ERROR (Status);\r
+\r
//\r
// Shadow PEI Core into memory so it will run faster\r
//\r
- Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r
- ASSERT_EFI_ERROR (Status);\r
- \r
+ //Status = PeiLoadImage (\r
+ // PeiServices,\r
+ // *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+ // &EntryPoint,\r
+ // &AuthenticationState\r
+ // );\r
+ //ASSERT_EFI_ERROR (Status);\r
+\r
+ //PrivateInMem->ShadowedPeiCore = (VOID*) ((UINTN) EntryPoint +\r
+ // (UINTN) PeiCore -\r
+ // (UINTN) _ModuleEntryPoint);\r
+ PrivateInMem->ShadowedPeiCore = ShadowPeiCore (\r
+ PeiServices,\r
+ PrivateInMem\r
+ );\r
//\r
- // Switch to memory based stack and reenter PEI Core that has been\r
- // shadowed to memory.\r
+ // Process the Notify list and dispatch any notifies for\r
+ // newly installed PPIs.\r
//\r
+ ProcessNotifyList (PrivateInMem);\r
+\r
//\r
- // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
+ // Entry PEI Phase 2\r
//\r
- TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r
- TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
- \r
- PeiCoreParameters.SecCoreData = SecCoreData;\r
- PeiCoreParameters.PpiList = NULL;\r
- PeiCoreParameters.Data = PrivateInMem;\r
- ASSERT (PeiCoreParameters.Data != 0);\r
+ PeiCore (SecCoreData, NULL, PrivateInMem);\r
\r
- PeiSwitchStacks (\r
- InvokePeiCore,\r
- (VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),\r
- (VOID*) &PeiCoreParameters, \r
- TopOfStack,\r
- (VOID*)(UINTN)Private->StackBase\r
- );\r
+ //((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) (\r
+ // SecCoreData,\r
+ // NULL,\r
+ // PrivateInMem\r
+ // );\r
+\r
+ //\r
+ // Code should not come here\r
+ //\r
+ ASSERT_EFI_ERROR(FALSE);\r
}\r
\r
+ //\r
+ // Process the Notify list and dispatch any notifies for\r
+ // newly installed PPIs.\r
+ //\r
+ ProcessNotifyList (Private);\r
+\r
if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
(Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
//\r
- // If memory is availble we shadow images by default for performance reasons. \r
- // We call the entry point a 2nd time so the module knows it's shadowed. \r
+ // If memory is availble we shadow images by default for performance reasons.\r
+ // We call the entry point a 2nd time so the module knows it's shadowed.\r
//\r
//PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
//PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
- \r
+\r
//\r
// PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
//\r
}\r
\r
//\r
- // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r
+ // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r
// through all the FV.\r
//\r
Private->CurrentPeimFvCount = 0;\r
\r
//\r
- // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r
+ // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r
// dispatched. So we need to make another pass\r
//\r
- // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r
+ // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r
// pass. If we did not dispatch a PEIM there is no point in trying again\r
// as it will fail the next time too (nothing has changed).\r
//\r
//\r
return TRUE;\r
}\r
- \r
+\r
//\r
- // Depex section not in the encapsulated section. \r
+ // Depex section not in the encapsulated section.\r
//\r
Status = PeiServicesFfsFindSectionData (\r
EFI_SECTION_PEI_DEPEX,\r
- FileHandle, \r
+ FileHandle,\r
(VOID **)&DepexData\r
);\r
\r
discovery permanent memory.\r
\r
@param FileHandle File handle of a PEIM.\r
- \r
+\r
@retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
@retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
@retval EFI_SUCCESS Successfully to register itself.\r
\r
-**/ \r
+**/\r
EFI_STATUS\r
EFIAPI\r
PeiRegisterForShadow (\r
//\r
return EFI_ALREADY_STARTED;\r
}\r
- \r
+\r
Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
\r
return EFI_SUCCESS;\r
}\r
\r
\r
-/**\r
- This routine invoke the PeiCore's entry in new stack environment.\r
-\r
- @param Context1 The first context parameter is entry of PeiCore\r
- @param Context2 The second context parameter is parameter structure point for PeiCore\r
-\r
-**/ \r
-STATIC\r
-VOID\r
-InvokePeiCore (\r
- VOID *Context1,\r
- VOID *Context2\r
- )\r
-{\r
- PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r
- PEI_CORE_PARAMETERS *PeiCoreParameters;\r
-\r
- //\r
- // Running on new stack in SEC Core\r
- //\r
-\r
- PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r
- PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r
-\r
- //\r
- // Call PEI Core using new stack\r
- //\r
- PeiCoreEntryPoint (\r
- PeiCoreParameters->SecCoreData,\r
- PeiCoreParameters->PpiList,\r
- PeiCoreParameters->Data\r
- );\r
-\r
- //\r
- // Never returns\r
- //\r
- ASSERT (FALSE);\r
- CpuDeadLoop ();\r
-}\r
\r
/**\r
Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r
@param FileHandle File handle of a Fv type file.\r
@param AuthenticationState Pointer to attestation authentication state of image.\r
\r
- \r
+\r
@retval EFI_NOT_FOUND FV image can't be found.\r
@retval EFI_SUCCESS Successfully to process it.\r
\r
UINT32 FvAlignment;\r
VOID *FvBuffer;\r
EFI_PEI_HOB_POINTERS HobFv2;\r
- \r
+\r
FvBuffer = NULL;\r
*AuthenticationState = 0;\r
\r
//\r
- // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already \r
+ // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
// been extracted.\r
//\r
HobFv2.Raw = GetHobList ();\r
}\r
HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r
}\r
- \r
+\r
//\r
// Find FvImage in FvFile\r
//\r
FvFileHandle,\r
(VOID **)&FvImageHandle\r
);\r
- \r
+\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
if (FvAlignment < 8) {\r
FvAlignment = 8;\r
}\r
- // \r
+ //\r
// Check FvImage\r
//\r
if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r
//\r
PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r
}\r
- \r
+\r
//\r
// Install FvPpi and Build FvHob\r
//\r
&FvImageInfo.FvName,\r
&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)\r
);\r
- \r
+\r
return EFI_SUCCESS;\r
}\r
\r
#include <PeiMain.h>\r
\r
+static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+ &gEfiPeiMemoryDiscoveredPpiGuid,\r
+ NULL\r
+};\r
+\r
VOID\r
InitializeMemoryServices (\r
IN PEI_CORE_INSTANCE *PrivateData,\r
\r
--*/\r
{\r
- PrivateData->SwitchStackSignal = FALSE;\r
+ \r
+ PrivateData->SwitchStackSignal = FALSE;\r
\r
if (OldCoreData == NULL) {\r
\r
PrivateData->PeiMemoryInstalled = FALSE;\r
\r
- PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase; \r
- PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);\r
- \r
+ PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase; \r
+ PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);\r
+ PrivateData->SizeOfTemporaryMemory = SecCoreData->TemporaryRamSize;\r
+ PrivateData->StackSize = (UINT64) SecCoreData->StackSize;\r
+ \r
DEBUG_CODE_BEGIN ();\r
PrivateData->SizeOfCacheAsRam = SecCoreData->PeiTemporaryRamSize + SecCoreData->StackSize;\r
PrivateData->MaxTopOfCarHeap = (VOID *) ((UINTN) PrivateData->BottomOfCarHeap + (UINTN) PrivateData->SizeOfCacheAsRam);\r
EFI_STATUS\r
EFIAPI\r
PeiInstallPeiMemory (\r
- IN CONST EFI_PEI_SERVICES **PeiServices,\r
- IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
- IN UINT64 MemoryLength\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
+ IN UINT64 MemoryLength\r
)\r
/*++\r
\r
--*/\r
{\r
PEI_CORE_INSTANCE *PrivateData;\r
- EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob;\r
- EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob;\r
- UINT64 PeiStackSize;\r
- UINT64 EfiFreeMemorySize;\r
- EFI_PHYSICAL_ADDRESS PhysicalAddressOfOldHob;\r
-\r
- if (MemoryLength > (MAX_ADDRESS - MemoryBegin + 1))\r
- return EFI_INVALID_PARAMETER;\r
- \r
- \r
+\r
DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));\r
- \r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
\r
- PrivateData->SwitchStackSignal = TRUE;\r
- PrivateData->PeiMemoryInstalled = TRUE;\r
- \r
- //\r
- // Ensure the stack base is in page alignment \r
- //\r
- PrivateData->StackBase = ((UINTN)MemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
- PeiStackSize = (RShiftU64 (MemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
- \r
- if (PEI_STACK_SIZE > PeiStackSize) {\r
- PrivateData->StackSize = PeiStackSize;\r
- } else {\r
- PrivateData->StackSize = PEI_STACK_SIZE;\r
- }\r
-\r
- OldHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
-\r
- PrivateData->HobList.Raw = (VOID *)((UINTN)(PrivateData->StackBase + PrivateData->StackSize));\r
- NewHandOffHob = PrivateData->HobList.HandoffInformationTable;\r
- PhysicalAddressOfOldHob = (EFI_PHYSICAL_ADDRESS) (UINTN) OldHandOffHob;\r
-\r
- EfiFreeMemorySize = OldHandOffHob->EfiFreeMemoryBottom - PhysicalAddressOfOldHob;\r
- \r
- DEBUG ((EFI_D_INFO, "HOBLIST address before memory init = 0x%p\n", OldHandOffHob));\r
- DEBUG ((EFI_D_INFO, "HOBLIST address after memory init = 0x%p\n", NewHandOffHob));\r
-\r
- CopyMem (\r
- NewHandOffHob,\r
- OldHandOffHob,\r
- (UINTN)EfiFreeMemorySize\r
- );\r
-\r
- NewHandOffHob->EfiMemoryTop = MemoryBegin + MemoryLength;\r
- NewHandOffHob->EfiFreeMemoryTop = NewHandOffHob->EfiMemoryTop;\r
- NewHandOffHob->EfiMemoryBottom = MemoryBegin;\r
- \r
- NewHandOffHob->EfiFreeMemoryBottom = (UINTN)NewHandOffHob + EfiFreeMemorySize; \r
- \r
- NewHandOffHob->EfiEndOfHobList = (UINTN)NewHandOffHob +\r
- (OldHandOffHob->EfiEndOfHobList -\r
- PhysicalAddressOfOldHob);\r
- \r
- //\r
- // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
- // the 63-bit of address is set to 1.\r
- //\r
- SWITCH_TO_CACHE_MODE (PrivateData);\r
- \r
- ConvertPpiPointers (PeiServices, OldHandOffHob, NewHandOffHob);\r
-\r
- BuildStackHob (PrivateData->StackBase, PrivateData->StackSize);\r
- \r
+ PrivateData->PhysicalMemoryBegin = MemoryBegin;\r
+ PrivateData->PhysicalMemoryLength = MemoryLength;\r
+ PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;\r
+ \r
+ PrivateData->SwitchStackSignal = TRUE;\r
\r
return EFI_SUCCESS; \r
}\r
PEI_CORE_INSTANCE *PrivateData;\r
EFI_PEI_HOB_POINTERS Hob;\r
EFI_PHYSICAL_ADDRESS Offset;\r
+ EFI_PHYSICAL_ADDRESS *FreeMemoryTop;\r
+ EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;\r
\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
-\r
+ Hob.Raw = PrivateData->HobList.Raw;\r
+ \r
//\r
// Check if Hob already available\r
//\r
if (!PrivateData->PeiMemoryInstalled) {\r
- return EFI_NOT_AVAILABLE_YET;\r
+ //\r
+ // When PeiInstallMemory is called but CAR has *not* been moved to temporary memory,\r
+ // the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure.\r
+ //\r
+ if (!PrivateData->SwitchStackSignal) {\r
+ return EFI_NOT_AVAILABLE_YET;\r
+ } else {\r
+ FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop);\r
+ FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);\r
+ }\r
+ } else {\r
+ FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);\r
+ FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
}\r
\r
- Hob.Raw = PrivateData->HobList.Raw;\r
+ \r
\r
//\r
// Check to see if on 4k boundary\r
//\r
- Offset = Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF;\r
-\r
+ Offset = *(FreeMemoryTop) & 0xFFF;\r
+ \r
//\r
// If not aligned, make the allocation aligned.\r
//\r
if (Offset != 0) {\r
- Hob.HandoffInformationTable->EfiFreeMemoryTop -= Offset;\r
+ *(FreeMemoryTop) -= Offset;\r
}\r
-\r
- ASSERT (Hob.HandoffInformationTable->EfiFreeMemoryTop >= Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
+ \r
//\r
// Verify that there is sufficient memory to satisfy the allocation\r
//\r
- if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
- Hob.HandoffInformationTable->EfiFreeMemoryBottom) {\r
+ if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
+ *(FreeMemoryBottom)) {\r
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages));\r
DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \\r
- EFI_SIZE_TO_PAGES ((UINTN) (Hob.HandoffInformationTable->EfiFreeMemoryTop - Hob.HandoffInformationTable->EfiFreeMemoryBottom))));\r
+ EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));\r
return EFI_OUT_OF_RESOURCES;\r
} else {\r
//\r
// Update the PHIT to reflect the memory usage\r
//\r
- Hob.HandoffInformationTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE;\r
+ *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE;\r
\r
//\r
// Update the value for the caller\r
//\r
- *Memory = Hob.HandoffInformationTable->EfiFreeMemoryTop;\r
+ *Memory = *(FreeMemoryTop);\r
\r
//\r
// Create a memory allocation HOB.\r
//\r
BuildMemoryAllocationHob (\r
- Hob.HandoffInformationTable->EfiFreeMemoryTop,\r
+ *(FreeMemoryTop),\r
Pages * EFI_PAGE_SIZE,\r
MemoryType\r
);\r
#include <Ppi/GuidedSectionExtraction.h>\r
#include <Ppi/LoadFile.h>\r
#include <Ppi/Security2.h>\r
+#include <Ppi/TemporaryRamSupport.h>\r
#include <Library/DebugLib.h>\r
#include <Library/PeiCoreEntryPoint.h>\r
#include <Library/BaseLib.h>\r
VOID *Raw;\r
} PEI_PPI_LIST_POINTERS;\r
\r
-#define PEI_STACK_SIZE 0x20000\r
-\r
-#define MAX_PPI_DESCRIPTORS 128\r
+#define MAX_PPI_DESCRIPTORS 64\r
\r
typedef struct {\r
INTN PpiListEnd;\r
VOID *CpuIo;\r
EFI_PEI_SECURITY2_PPI *PrivateSecurityPpi;\r
EFI_PEI_SERVICES ServiceTableShadow;\r
+ UINTN SizeOfTemporaryMemory;\r
UINTN SizeOfCacheAsRam;\r
VOID *MaxTopOfCarHeap;\r
EFI_PEI_PPI_DESCRIPTOR *XipLoadFile;\r
+ EFI_PHYSICAL_ADDRESS PhysicalMemoryBegin;\r
+ UINT64 PhysicalMemoryLength;\r
+ EFI_PHYSICAL_ADDRESS FreePhysicalMemoryTop;\r
+ VOID* ShadowedPeiCore;\r
CACHE_SECTION_DATA CacheSection;\r
} PEI_CORE_INSTANCE;\r
\r
;\r
\r
\r
+EFI_STATUS\r
+FindNextPeim (\r
+ IN EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
+ IN OUT EFI_FFS_FILE_HEADER **PeimFileHeader\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Given the input file pointer, search for the next matching file in the\r
+ FFS volume. The search starts from FileHeader inside\r
+ the Firmware Volume defined by FwVolHeader.\r
+\r
+Arguments:\r
+ PeiServices - Pointer to the PEI Core Services Table.\r
+\r
+ FwVolHeader - Pointer to the FV header of the volume to search.\r
+ This parameter must point to a valid FFS volume.\r
+\r
+ PeimFileHeader - Pointer to the current file from which to begin searching.\r
+ This pointer will be updated upon return to reflect the file found.\r
+\r
+Returns:\r
+ EFI_NOT_FOUND - No files matching the search criteria were found\r
+ EFI_SUCCESS\r
+\r
+--*/\r
+;\r
+\r
BOOLEAN\r
Dispatched (\r
IN UINT8 CurrentPeim,\r
\r
VOID\r
ConvertPpiPointers (\r
- IN CONST EFI_PEI_SERVICES **PeiServices,\r
- IN EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN UINTN OldCheckingBottom,\r
+ IN UINTN OldCheckingTop,\r
IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob\r
)\r
/*++\r
\r
Arguments:\r
\r
- PeiServices - The PEI core services table.\r
- OldHandOffHob - The old handoff HOB list.\r
- NewHandOffHob - The new handoff HOB list.\r
+ PeiServices - The PEI core services table.\r
+ OldCheckingBottom - The old checking bottom.\r
+ OldCheckingTop - The old checking top.\r
+ NewHandOffHob - The new handoff HOB list.\r
\r
Returns:\r
\r
gEfiPeiFirmwareVolumeInfoPpiGuid\r
gEfiPeiLoadFilePpiGuid\r
gEfiPeiSecurity2PpiGuid\r
+ gEfiTemporaryRamSupportPpiGuid\r
\r
[FixedPcd.common]\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv\r
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeimDispatch\r
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeiCoreEntry\r
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize\r
+\r
\r
[FeaturePcd.common]\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst\r
+\r
+[BuildOptions.common]\r
+ MSFT:*_*_*_CC_FLAGS = /Fa$* /FAsc /FR$(@R).SBR\r
PEI_CORE_INSTANCE *OldCoreData;\r
EFI_PEI_CPU_IO_PPI *CpuIo;\r
EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
+ PEI_CORE_ENTRY_POINT ShadowedPeiCore;\r
\r
mTick = 0;\r
OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
}\r
\r
if (OldCoreData != NULL) {\r
+ ShadowedPeiCore = (PEI_CORE_ENTRY_POINT) (UINTN) OldCoreData->ShadowedPeiCore;\r
+ if (ShadowedPeiCore != NULL) {\r
+ OldCoreData->ShadowedPeiCore = NULL;\r
+ ShadowedPeiCore (\r
+ SecCoreData,\r
+ PpiList,\r
+ OldCoreData\r
+ );\r
+ }\r
+\r
CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
\r
CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
UINTN StackValue;\r
\r
StackValue = INIT_CAR_VALUE;\r
- for (StackPointer = (UINTN *) OldCoreData->TopOfCarHeap;\r
- ((UINTN) StackPointer < ((UINTN) OldCoreData->MaxTopOfCarHeap))\r
+ for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
+ ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
&& StackValue == INIT_CAR_VALUE;\r
StackPointer++) {\r
StackValue = *StackPointer;\r
\r
DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
- ((UINTN) OldCoreData->MaxTopOfCarHeap - (UINTN) StackPointer)\r
+ ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
));\r
DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
/*++\r
\r
-Copyright (c) 2006, Intel Corporation \r
-All rights reserved. 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
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
\r
Module Name:\r
\r
PrivateData->PpiData.DispatchListEnd = MAX_PPI_DESCRIPTORS-1;\r
PrivateData->PpiData.LastDispatchedNotify = MAX_PPI_DESCRIPTORS-1;\r
}\r
- \r
- return; \r
+\r
+ return;\r
}\r
\r
VOID\r
ConvertPpiPointers (\r
IN CONST EFI_PEI_SERVICES **PeiServices,\r
- IN EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob,\r
+ IN UINTN OldCheckingBottom,\r
+ IN UINTN OldCheckingTop,\r
IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob\r
)\r
/*++\r
\r
Arguments:\r
\r
- PeiServices - The PEI core services table.\r
- OldHandOffHob - The old handoff HOB list.\r
- NewHandOffHob - The new handoff HOB list.\r
+ PeiServices - The PEI core services table.\r
+ OldCheckingBottom - The old checking bottom.\r
+ OldCheckingTop - The old checking top.\r
+ NewHandOffHob - The new handoff HOB list.\r
\r
Returns:\r
- \r
+\r
--*/\r
{\r
PEI_CORE_INSTANCE *PrivateData;\r
\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
\r
- Fixup = (UINTN)NewHandOffHob - (UINTN)OldHandOffHob;\r
- \r
+ Fixup = (UINTN)NewHandOffHob - OldCheckingBottom;\r
+\r
for (Index = 0; Index < MAX_PPI_DESCRIPTORS; Index++) {\r
if (Index < PrivateData->PpiData.PpiListEnd ||\r
Index > PrivateData->PpiData.NotifyListEnd) {\r
PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];\r
- \r
- if (((UINTN)PpiPointer->Raw < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && \r
- ((UINTN)PpiPointer->Raw >= (UINTN)OldHandOffHob)) {\r
+\r
+ if (((UINTN)PpiPointer->Raw < OldCheckingTop) &&\r
+ ((UINTN)PpiPointer->Raw >= OldCheckingBottom)) {\r
//\r
// Convert the pointer to the PEIM descriptor from the old HOB heap\r
// to the relocated HOB heap.\r
// Only when the PEIM descriptor is in the old HOB should it be necessary\r
// to try to convert the pointers in the PEIM descriptor\r
//\r
- \r
- if (((UINTN)PpiPointer->Ppi->Guid < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && \r
- ((UINTN)PpiPointer->Ppi->Guid >= (UINTN)OldHandOffHob)) {\r
+\r
+ if (((UINTN)PpiPointer->Ppi->Guid < OldCheckingTop) &&\r
+ ((UINTN)PpiPointer->Ppi->Guid >= OldCheckingBottom)) {\r
//\r
// Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
// from the old HOB heap to the relocated HOB heap.\r
// the notification function in the NOTIFY descriptor needs not be converted.\r
//\r
if (Index < PrivateData->PpiData.PpiListEnd &&\r
- (UINTN)PpiPointer->Ppi->Ppi < (UINTN)OldHandOffHob->EfiFreeMemoryBottom &&\r
- (UINTN)PpiPointer->Ppi->Ppi >= (UINTN)OldHandOffHob) {\r
+ (UINTN)PpiPointer->Ppi->Ppi < OldCheckingTop &&\r
+ (UINTN)PpiPointer->Ppi->Ppi >= OldCheckingBottom) {\r
//\r
// Convert the pointer to the PPI interface structure in the PPI descriptor\r
// from the old HOB heap to the relocated HOB heap.\r
//\r
- PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi+ Fixup); \r
+ PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi+ Fixup);\r
}\r
}\r
}\r
// by the EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST being set in the last\r
// EFI_PEI_PPI_DESCRIPTOR in the list.\r
//\r
- \r
+\r
for (;;) {\r
//\r
// Since PpiData is used for NotifyList and InstallList, max resource\r
return EFI_OUT_OF_RESOURCES;\r
}\r
//\r
- // Check if it is a valid PPI. \r
+ // Check if it is a valid PPI.\r
// If not, rollback list to exclude all in this list.\r
// Try to indicate which item failed.\r
//\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid)); \r
- PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR*) PpiList; \r
+ DEBUG((EFI_D_INFO, "Install PPI: %g\n", PpiList->Guid));\r
+ PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR*) PpiList;\r
PrivateData->PpiData.PpiListEnd++;\r
- \r
+\r
//\r
// Continue until the end of the PPI List.\r
//\r
- if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == \r
+ if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {\r
break;\r
}\r
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
LastCallbackInstall,\r
PrivateData->PpiData.PpiListEnd,\r
- PrivateData->PpiData.DispatchListEnd, \r
+ PrivateData->PpiData.DispatchListEnd,\r
PrivateData->PpiData.NotifyListEnd\r
);\r
\r
\r
//\r
// Remove the old PPI from the database, add the new one.\r
- // \r
+ //\r
DEBUG((EFI_D_INFO, "Reinstall PPI: %g\n", NewPpi->Guid));\r
PrivateData->PpiData.PpiListPtrs[Index].Ppi = (EFI_PEI_PPI_DESCRIPTOR *) NewPpi;\r
\r
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK,\r
Index,\r
Index+1,\r
- PrivateData->PpiData.DispatchListEnd, \r
+ PrivateData->PpiData.DispatchListEnd,\r
PrivateData->PpiData.NotifyListEnd\r
);\r
\r
\r
Returns:\r
\r
- Status - EFI_SUCCESS if the PPI is in the database \r
+ Status - EFI_SUCCESS if the PPI is in the database\r
EFI_NOT_FOUND if the PPI is not in the database\r
--*/\r
{\r
EFI_GUID *CheckGuid;\r
EFI_PEI_PPI_DESCRIPTOR *TempPtr;\r
\r
- \r
+\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
\r
//\r
if (Index == PrivateData->PpiData.PpiListEnd - 1) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
- \r
+\r
//\r
// If some of the PPI data is invalid restore original Notify PPI database value\r
//\r
DEBUG((EFI_D_ERROR, "ERROR -> InstallNotify: %g %x\n", NotifyList->Guid, NotifyList->Notify));\r
return EFI_INVALID_PARAMETER;\r
}\r
- \r
+\r
if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
- NotifyDispatchCount ++; \r
- } \r
- \r
- PrivateData->PpiData.PpiListPtrs[Index].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList; \r
- \r
+ NotifyDispatchCount ++;\r
+ }\r
+\r
+ PrivateData->PpiData.PpiListPtrs[Index].Notify = (EFI_PEI_NOTIFY_DESCRIPTOR *) NotifyList;\r
+\r
PrivateData->PpiData.NotifyListEnd--;\r
DEBUG((EFI_D_INFO, "Register PPI Notify: %g\n", NotifyList->Guid));\r
if ((NotifyList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) ==\r
NotifyList++;\r
Index--;\r
}\r
- \r
+\r
//\r
- // If there is Dispatch Notify PPI installed put them on the bottom \r
+ // If there is Dispatch Notify PPI installed put them on the bottom\r
//\r
if (NotifyDispatchCount > 0) {\r
- for (NotifyIndex = LastCallbackNotify; NotifyIndex > PrivateData->PpiData.NotifyListEnd; NotifyIndex--) { \r
+ for (NotifyIndex = LastCallbackNotify; NotifyIndex > PrivateData->PpiData.NotifyListEnd; NotifyIndex--) {\r
if ((PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify->Flags & EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH) != 0) {\r
NotifyPtr = PrivateData->PpiData.PpiListPtrs[NotifyIndex].Notify;\r
- \r
+\r
for (Index = NotifyIndex; Index < PrivateData->PpiData.DispatchListEnd; Index++){\r
PrivateData->PpiData.PpiListPtrs[Index].Notify = PrivateData->PpiData.PpiListPtrs[Index + 1].Notify;\r
}\r
PrivateData->PpiData.PpiListPtrs[Index].Notify = NotifyPtr;\r
- PrivateData->PpiData.DispatchListEnd--; \r
+ PrivateData->PpiData.DispatchListEnd--;\r
}\r
}\r
- \r
- LastCallbackNotify -= NotifyDispatchCount; \r
+\r
+ LastCallbackNotify -= NotifyDispatchCount;\r
}\r
- \r
+\r
//\r
// Dispatch any callback level notifies for all previously installed PPIs.\r
//\r
LastCallbackNotify,\r
PrivateData->PpiData.NotifyListEnd\r
);\r
- \r
- \r
+\r
+\r
return EFI_SUCCESS;\r
}\r
\r
\r
{\r
INTN TempValue;\r
- \r
+\r
while (TRUE) {\r
//\r
// Check if the PEIM that was just dispatched resulted in any\r
// Notifies getting installed. If so, go process any dispatch\r
// level Notifies that match the previouly installed PPIs.\r
- // Use "while" instead of "if" since DispatchNotify can modify \r
+ // Use "while" instead of "if" since DispatchNotify can modify\r
// DispatchListEnd (with NotifyPpi) so we have to iterate until the same.\r
//\r
while (PrivateData->PpiData.LastDispatchedNotify != PrivateData->PpiData.DispatchListEnd) {\r
);\r
PrivateData->PpiData.LastDispatchedNotify = TempValue;\r
}\r
- \r
- \r
+\r
+\r
//\r
// Check if the PEIM that was just dispatched resulted in any\r
// PPIs getting installed. If so, go process any dispatch\r
// level Notifies that match the installed PPIs.\r
- // Use "while" instead of "if" since DispatchNotify can modify \r
+ // Use "while" instead of "if" since DispatchNotify can modify\r
// PpiListEnd (with InstallPpi) so we have to iterate until the same.\r
//\r
while (PrivateData->PpiData.LastDispatchedInstall != PrivateData->PpiData.PpiListEnd) {\r
);\r
PrivateData->PpiData.LastDispatchedInstall = TempValue;\r
}\r
- \r
+\r
if (PrivateData->PpiData.LastDispatchedNotify == PrivateData->PpiData.DispatchListEnd) {\r
break;\r
}\r
- } \r
+ }\r
return;\r
}\r
\r
(((INT32 *)SearchGuid)[1] == ((INT32 *)CheckGuid)[1]) &&\r
(((INT32 *)SearchGuid)[2] == ((INT32 *)CheckGuid)[2]) &&\r
(((INT32 *)SearchGuid)[3] == ((INT32 *)CheckGuid)[3])) {\r
- DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %x\n", \r
- SearchGuid, \r
+ DEBUG ((EFI_D_INFO, "Notify: PPI Guid: %g, Peim notify entry point: %x\n",\r
+ SearchGuid,\r
NotifyDescriptor->Notify\r
));\r
NotifyDescriptor->Notify (\r
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries|40|UINT8|0x0001002f\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6|UINT32|0x00010030\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32|UINT32|0x00010031\r
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000|UINT32|0x00010032\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|0x30000002\r
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400|UINT32|0x30000003\r
\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6\r
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32\r
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000\r
\r
\r
[PcdsFixedAtBuild.IPF]\r
EFI_STATUS\r
EFIAPI\r
PeiServicesTablePointerLibConstructor (\r
- IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN EFI_PEI_FILE_HANDLE *FfsHeader,\r
IN EFI_PEI_SERVICES **PeiServices\r
)\r
{\r
return EFI_SUCCESS;\r
}\r
\r
-/**\r
- After memory initialization in PEI phase, the IDT table in temporary memory should \r
- be migrated to memory, and the address of PeiServicesPointer also need to be updated \r
- immediately preceding the new IDT table.\r
- \r
- @param PeiServices The address of PeiServices pointer.\r
-**/\r
-VOID\r
-MigrateIdtTable (\r
- IN EFI_PEI_SERVICES **PeiServices\r
- )\r
-{\r
-}\r
\r
EFI_PEI_SERVICES ** PeiServicesTablePointer\r
)\r
{\r
+ AsmWriteKr7 ((UINT64)(UINTN)PeiServicesTablePointer);\r
}\r
\r
-/**\r
- After memory initialization in PEI phase, the IDT table in temporary memory should \r
- be migrated to memory, and the address of PeiServicesPointer also need to be updated \r
- immediately preceding the new IDT table.\r
- \r
- @param PeiServices The address of PeiServices pointer.\r
-**/\r
-VOID\r
-MigrateIdtTable (\r
- IN EFI_PEI_SERVICES **PeiServices\r
- )\r
-{\r
-}\r
+\r
\r
\r
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverEnd|0x3040003|UINT32|0x30001014 # EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END\r
\r
[PcdsFixedAtBuild.IPF]\r
- gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f\r
+ gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f # comments\r
\r
[PcdsPatchableInModule.common]\r
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000|UINT64|0x0000000a\r
-/*++\r
+/*! \addtogroup Library EdkGenericBdsLib */\r
+/*@{ */\r
+/**@file \r
+ BDS library definition, include the file and data structure\r
\r
Copyright (c) 2006 - 2007, Intel Corporation\r
All rights reserved. This program and the accompanying materials \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
\r
-Module Name:\r
-\r
- BdsLib.h\r
-\r
-Abstract:\r
-\r
- BDS library definition, include the file and data structure\r
-\r
---*/\r
+**/\r
\r
#ifndef _BDS_LIB_H_\r
#define _BDS_LIB_H_\r
VOID\r
);\r
\r
+/*!\r
+ \fn BdsLibBootViaBootOption\r
+ \param BDS_COMMON_OPTION\r
+ \param EFI_DEVICE_PATH_PROTOCOL\r
+*/\r
EFI_STATUS\r
BdsLibBootViaBootOption (\r
IN BDS_COMMON_OPTION * Option,\r
);\r
\r
#endif // _BDS_LIB_H_\r
+/*@} */
\ No newline at end of file
#\r
#**/\r
\r
+\r
################################################################################\r
#\r
# Defines Section - statements that will be processed to create a Makefile.\r
################################################################################\r
\r
[Defines]\r
+\r
DEC_SPECIFICATION = 0x00010005\r
PACKAGE_NAME = Nt32Pkg\r
PACKAGE_GUID = 0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3\r
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE\r
\r
[PcdsFixedAtBuild.IA32]\r
+ #gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000\r
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1\r
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128\r
gEfiNt32PkgTokenSpaceGuid.PcdWinNtMemorySizeForSecMain|L"64!64"|VOID*|12\r
INF Nt32Pkg/BootModePei/BootModePei.inf\r
INF Nt32Pkg/WinNtFlashMapPei/WinNtFlashMapPei.inf\r
INF MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf\r
-INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
INF Nt32Pkg/WinNtAutoScanPei/WinNtAutoScanPei.inf\r
INF Nt32Pkg/WinNtFirmwareVolumePei/WinNtFirmwareVolumePei.inf\r
+INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
INF Nt32Pkg/WinNtThunkPPIToProtocolPei/WinNtThunkPPIToProtocolPei.inf\r
INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
\r
\r
NT_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress };\r
\r
+TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};\r
\r
EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {\r
{\r
&gEfiPeiStatusCodePpiGuid,\r
&mSecStatusCodePpi\r
},\r
+ {\r
+ EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+ &gEfiTemporaryRamSupportPpiGuid,\r
+ &mSecTemporaryRamSupportPpi\r
+ },\r
{\r
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,\r
&gNtFwhPpiGuid,\r
PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL;\r
\r
\r
-\r
+VOID\r
+EFIAPI\r
+SecSwitchStack (\r
+ UINT32 TemporaryMemoryBase,\r
+ UINT32 PermenentMemoryBase\r
+ );\r
\r
INTN\r
EFIAPI\r
EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint;\r
EFI_PHYSICAL_ADDRESS PeiImageAddress;\r
EFI_SEC_PEI_HAND_OFF *SecCoreData;\r
+ UINTN PeiStackSize;\r
\r
//\r
// Compute Top Of Memory for Stack and PEI Core Allocations\r
//\r
- TopOfMemory = LargestRegion + LargestRegionSize;\r
+ TopOfMemory = LargestRegion + LargestRegionSize;\r
+ PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
\r
//\r
- // Allocate 128KB for the Stack\r
+ // |-----------| <---- TemporaryRamBase + TemporaryRamSize\r
+ // | Heap |\r
+ // | |\r
+ // |-----------| <---- StackBase / PeiTemporaryMemoryBase\r
+ // | |\r
+ // | Stack |\r
+ // |-----------| <---- TemporaryRamBase\r
+ // \r
+ TopOfStack = (VOID *)(LargestRegion + PeiStackSize);\r
+ TopOfMemory = LargestRegion + PeiStackSize;\r
+\r
//\r
- TopOfStack = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);\r
+ // Reservet space for storing PeiCore's parament in stack.\r
+ // \r
+ TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);\r
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
- TopOfMemory = TopOfMemory - STACK_SIZE;\r
\r
//\r
// Patch value in dispatch table values\r
SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);\r
SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;\r
SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize);\r
- SecCoreData->TemporaryRamBase = (VOID*)(UINTN)TopOfMemory; \r
+ SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion; \r
SecCoreData->TemporaryRamSize = STACK_SIZE;\r
- SecCoreData->PeiTemporaryRamBase = SecCoreData->TemporaryRamBase;\r
- SecCoreData->PeiTemporaryRamSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
- SecCoreData->StackBase = (VOID*)((UINTN)SecCoreData->TemporaryRamBase + (UINTN)SecCoreData->TemporaryRamSize);\r
- SecCoreData->StackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);\r
+ SecCoreData->StackBase = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);\r
+ SecCoreData->StackSize = PeiStackSize;\r
+ SecCoreData->PeiTemporaryRamBase = SecCoreData->StackBase;\r
+ SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize;\r
\r
//\r
// Load the PEI Core from a Firmware Volume\r
{\r
}\r
\r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
+ IN UINTN CopySize\r
+ )\r
+{\r
+ //\r
+ // Migrate the whole temporary memory to permenent memory.\r
+ // \r
+ CopyMem (\r
+ (VOID*)(UINTN)PermanentMemoryBase, \r
+ (VOID*)(UINTN)TemporaryMemoryBase, \r
+ CopySize\r
+ );\r
+\r
+ //\r
+ // SecSwitchStack function must be invoked after the memory migration\r
+ // immediatly, also we need fixup the stack change caused by new call into \r
+ // permenent memory.\r
+ // \r
+ SecSwitchStack (\r
+ (UINT32) TemporaryMemoryBase,\r
+ (UINT32) PermanentMemoryBase\r
+ );\r
+\r
+ //\r
+ // We need *not* fix the return address because currently, \r
+ // The PeiCore is excuted in flash.\r
+ //\r
+\r
+ //\r
+ // Simulate to invalid CAR, terminate CAR\r
+ // \r
+ //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);\r
+ \r
+ return EFI_SUCCESS;\r
+}\r
+\r
#include <Ppi/NtThunk.h>\r
#include <Ppi/StatusCode.h>\r
#include <Ppi/NtFwh.h>\r
+#include <Ppi/TemporaryRamSupport.h>\r
#include <Library/PcdLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/PrintLib.h>\r
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
);\r
\r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+ IN CONST EFI_PEI_SERVICES **PeiServices,\r
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
+ IN UINTN CopySize\r
+ );\r
\r
typedef struct {\r
EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;\r
WinNtThunk.c\r
FwVol.c\r
SecMain.c\r
+ Stack.asm\r
\r
[Packages]\r
MdePkg/MdePkg.dec\r
gNtFwhPpiGuid # PPI ALWAYS_PRODUCED\r
gPeiNtAutoScanPpiGuid # PPI ALWAYS_PRODUCED\r
gPeiNtThunkPpiGuid # PPI ALWAYS_PRODUCED\r
+ gEfiTemporaryRamSupportPpiGuid\r
\r
\r
[FixedPcd.common]\r
[BuildOptions.common]\r
MSFT:*_*_IA32_DLINK_FLAGS = /out:"$(BIN_DIR)\SecMain.exe" /base:0x10000000 /pdb:"$(BIN_DIR)\SecMain.pdb" /LIBPATH:"$(VCINSTALLDIR)\Lib" /LIBPATH:"$(VCINSTALLDIR)\PlatformSdk\Lib" /NOLOGO /SUBSYSTEM:CONSOLE /NODEFAULTLIB /IGNORE:4086 /MAP /OPT:REF /DEBUG /MACHINE:I386 /LTCG Kernel32.lib MSVCRTD.lib Gdi32.lib User32.lib Winmm.lib\r
MSFT:*_*_IA32_CC_FLAGS = /nologo /W4 /WX /Gy /c /D UNICODE /Od /FI$(DEST_DIR_DEBUG)/AutoGen.h /EHs-c- /GF /Gs8192 /Zi /Gm /D _CRT_SECURE_NO_WARNINGS /D _CRT_SECURE_NO_DEPRECATE\r
-\r
+ MSFT:*_*_IA32_PP_FLAGS = /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h\r
+ MSFT:*_*_IA32_ASM_FLAGS = /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi\r
+ MSFT:*_*_IA32_ASMLINK_FLAGS = /link /nologo /tiny\r
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2007, Intel Corporation\r
+; All rights reserved. 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
+;\r
+; Module Name:\r
+;\r
+; Stack.asm\r
+;\r
+; Abstract:\r
+;\r
+; Switch the stack from temporary memory to permenent memory.\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+ .586p\r
+ .model flat,C\r
+ .code\r
+ \r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; SecSwitchStack (\r
+; UINT32 TemporaryMemoryBase,\r
+; UINT32 PermenentMemoryBase\r
+; );\r
+;------------------------------------------------------------------------------ \r
+SecSwitchStack PROC\r
+ ;\r
+ ; Save three register: eax, ebx, ecx\r
+ ;\r
+ push eax\r
+ push ebx\r
+ push ecx\r
+ push edx\r
+ \r
+ ;\r
+ ; !!CAUTION!! this function address's is pushed into stack after\r
+ ; migration of whole temporary memory, so need save it to permenent\r
+ ; memory at first!\r
+ ;\r
+ \r
+ mov ebx, [esp + 20] ; Save the first parameter\r
+ mov ecx, [esp + 24] ; Save the second parameter\r
+ \r
+ ;\r
+ ; Save this function's return address into permenent memory at first.\r
+ ; Then, Fixup the esp point to permenent memory\r
+ ;\r
+ mov eax, esp\r
+ sub eax, ebx\r
+ add eax, ecx\r
+ mov edx, dword ptr [esp] ; copy pushed register's value to permenent memory\r
+ mov dword ptr [eax], edx \r
+ mov edx, dword ptr [esp + 4]\r
+ mov dword ptr [eax + 4], edx \r
+ mov edx, dword ptr [esp + 8]\r
+ mov dword ptr [eax + 8], edx \r
+ mov edx, dword ptr [esp + 12]\r
+ mov dword ptr [eax + 12], edx \r
+ mov edx, dword ptr [esp + 16] ; Update this function's return address into permenent memory\r
+ mov dword ptr [eax + 16], edx \r
+ mov esp, eax ; From now, esp is pointed to permenent memory\r
+ \r
+ ;\r
+ ; Fixup the ebp point to permenent memory\r
+ ;\r
+ mov eax, ebp\r
+ sub eax, ebx\r
+ add eax, ecx\r
+ mov ebp, eax ; From now, ebp is pointed to permenent memory\r
+ \r
+ ;\r
+ ; Fixup callee's ebp point for PeiDispatch\r
+ ;\r
+ mov eax, dword ptr [ebp]\r
+ sub eax, ebx\r
+ add eax, ecx\r
+ mov dword ptr [ebp], eax ; From now, Temporary's PPI caller's stack is in permenent memory\r
+ \r
+ pop edx\r
+ pop ecx\r
+ pop ebx\r
+ pop eax\r
+ ret\r
+SecSwitchStack ENDP\r
+\r
+ END\r