Merge Temporary Ram support patch.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4782 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
klu2 2008-02-29 18:24:43 +00:00
parent bc4cb041a3
commit 58dcdada56
19 changed files with 667 additions and 390 deletions

View File

@ -28,13 +28,6 @@ typedef struct {
EFI_HANDLE Handle; EFI_HANDLE Handle;
} PEIM_FILE_HANDLE_EXTENDED_DATA; } PEIM_FILE_HANDLE_EXTENDED_DATA;
STATIC
VOID
InvokePeiCore (
VOID *Context1,
VOID *Context2
);
VOID VOID
DiscoverPeimsAndOrderWithApriori ( DiscoverPeimsAndOrderWithApriori (
IN PEI_CORE_INSTANCE *Private, IN PEI_CORE_INSTANCE *Private,
@ -189,6 +182,45 @@ Returns:
} }
VOID*
ShadowPeiCore(
EFI_PEI_SERVICES **PeiServices,
PEI_CORE_INSTANCE *PrivateInMem
)
{
EFI_PEI_FILE_HANDLE PeiCoreFileHandle;
EFI_PHYSICAL_ADDRESS EntryPoint;
EFI_STATUS Status;
UINT32 AuthenticationState;
PeiCoreFileHandle = NULL;
//
// Find the PEI Core in the BFV
//
Status = PeiFindFileEx (
(EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,
NULL,
EFI_FV_FILETYPE_PEI_CORE,
&PeiCoreFileHandle,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Shadow PEI Core into memory so it will run faster
//
Status = PeiLoadImage (
PeiServices,
*((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),
&EntryPoint,
&AuthenticationState
);
ASSERT_EFI_ERROR (Status);
return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);
}
VOID VOID
PeiDispatcher ( PeiDispatcher (
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
@ -220,9 +252,8 @@ Returns:
UINT32 Index1; UINT32 Index1;
UINT32 Index2; UINT32 Index2;
EFI_PEI_SERVICES **PeiServices; EFI_PEI_SERVICES **PeiServices;
VOID *PrivateInMem;
EFI_PEI_FV_HANDLE VolumeHandle; EFI_PEI_FV_HANDLE VolumeHandle;
EFI_PEI_FILE_HANDLE PeiCoreFileHandle; //EFI_PHYSICAL_ADDRESS PeiCoreFileHandle;
EFI_PEI_FILE_HANDLE PeimFileHandle; EFI_PEI_FILE_HANDLE PeimFileHandle;
UINTN FvCount; UINTN FvCount;
UINTN PeimCount; UINTN PeimCount;
@ -234,10 +265,19 @@ Returns:
UINTN SaveCurrentPeimCount; UINTN SaveCurrentPeimCount;
UINTN SaveCurrentFvCount; UINTN SaveCurrentFvCount;
EFI_PEI_FILE_HANDLE SaveCurrentFileHandle; EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;
VOID *TopOfStack;
PEI_CORE_PARAMETERS PeiCoreParameters;
PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData; PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;
EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase;
TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;
EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable;
EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable;
INTN Offset;
PEI_CORE_INSTANCE *PrivateInMem;
UINT64 NewPeiStackSize;
UINT64 OldPeiStackSize;
UINT64 StackGap;
EFI_FV_FILE_INFO FvFileInfo; EFI_FV_FILE_INFO FvFileInfo;
UINTN OldCheckingTop;
UINTN OldCheckingBottom;
PeiServices = &Private->PS; PeiServices = &Private->PS;
@ -354,7 +394,8 @@ Returns:
if ((Status == EFI_SUCCESS)) { if ((Status == EFI_SUCCESS)) {
// //
// The PEIM has its dependencies satisfied, and is processed. // The PEIM has its dependencies satisfied, and its entry point
// has been found, so invoke it.
// //
PERF_START (0, "PEIM", NULL, 0); PERF_START (0, "PEIM", NULL, 0);
@ -393,12 +434,185 @@ Returns:
); );
PERF_END (0, "PEIM", NULL, 0); PERF_END (0, "PEIM", NULL, 0);
}
if (Private->SwitchStackSignal) {
//
// Reserve the size of new stack at bottom of physical memory
//
OldPeiStackSize = Private->StackSize;
NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {
Private->StackSize = NewPeiStackSize;
} else { } else {
Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);
}
// //
// If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready, // In theory, the size of new stack in permenent memory should large than
// we flag that more Peims need to be dispatched. // size of old stack in temporary memory.
// But if new stack is smaller than the size of old stack, we also reserve
// the size of old stack at bottom of permenent memory.
// //
PeimNeedingDispatch = TRUE; StackGap = 0;
if (Private->StackSize > OldPeiStackSize) {
StackGap = Private->StackSize - OldPeiStackSize;
}
//
// Update HandOffHob for new installed permenent memory
//
OldHandOffTable = Private->HobList.HandoffInformationTable;
OldCheckingBottom = (UINTN)OldHandOffTable;
OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);
//
// The whole temporary memory will be migrated to physical memory.
// CAUTION: The new base is computed accounding to gap of new stack.
//
NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;
Offset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->TemporaryRamBase;
NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + Offset);
PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + Offset);
//
// TemporaryRamSupportPpi is produced by platform's SEC
//
Status = PeiLocatePpi (
(CONST EFI_PEI_SERVICES **) PeiServices,
&gEfiTemporaryRamSupportPpiGuid,
0,
NULL,
(VOID**)&TemporaryRamSupportPpi
);
if (!EFI_ERROR (Status)) {
TemporaryRamSupportPpi->TemporaryRamMigration (
(CONST EFI_PEI_SERVICES **) PeiServices,
(EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,
(EFI_PHYSICAL_ADDRESS)(UINTN) NewPermenentMemoryBase,
SecCoreData->TemporaryRamSize
);
} else {
CopyMem (
(VOID*)(UINTN) NewPermenentMemoryBase,
SecCoreData->TemporaryRamBase,
SecCoreData->TemporaryRamSize
);
}
//
//
// Fixup the PeiCore's private data
//
PrivateInMem->PS = &PrivateInMem->ServiceTableShadow;
PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo;
PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + Offset);
PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);
PeiServices = &PrivateInMem->PS;
//
// Fixup for PeiService's address
//
SetPeiServicesTablePointer(PeiServices);
//
// Update HandOffHob for new installed permenent memory
//
NewHandOffTable->EfiEndOfHobList =
(EFI_PHYSICAL_ADDRESS)(VOID*)((UINTN) NewHandOffTable->EfiEndOfHobList + Offset);
NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin +
PrivateInMem->PhysicalMemoryLength;
NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin;
NewHandOffTable->EfiFreeMemoryTop = PrivateInMem->FreePhysicalMemoryTop;
NewHandOffTable->EfiFreeMemoryBottom = NewHandOffTable->EfiEndOfHobList +
sizeof (EFI_HOB_GENERIC_HEADER);
//
// We need convert the PPI desciptor's pointer
//
ConvertPpiPointers ((CONST EFI_PEI_SERVICES **)PeiServices,
OldCheckingBottom,
OldCheckingTop,
NewHandOffTable);
DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",
(UINTN)PrivateInMem->StackBase,
PrivateInMem->StackSize));
BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);
//
// After the whole temporary memory is migrated, then we can allocate page in
// permenent memory.
//
PrivateInMem->PeiMemoryInstalled = TRUE;
//
// Make sure we don't retry the same PEIM that added memory
//
PrivateInMem->CurrentPeimCount++;
//
// Shadow PEI Core. When permanent memory is avaiable, shadow
// PEI Core and PEIMs to get high performance.
//
//PeiCoreFileHandle = 0;
//
// Find the PEI Core in the BFV
//
//Status = PeiFindFileEx (
// (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,
// NULL,
// EFI_FV_FILETYPE_PEI_CORE,
// (EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle,
// NULL
// );
//ASSERT_EFI_ERROR (Status);
//
// Shadow PEI Core into memory so it will run faster
//
//Status = PeiLoadImage (
// PeiServices,
// *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),
// &EntryPoint,
// &AuthenticationState
// );
//ASSERT_EFI_ERROR (Status);
//PrivateInMem->ShadowedPeiCore = (VOID*) ((UINTN) EntryPoint +
// (UINTN) PeiCore -
// (UINTN) _ModuleEntryPoint);
PrivateInMem->ShadowedPeiCore = ShadowPeiCore (
PeiServices,
PrivateInMem
);
//
// Process the Notify list and dispatch any notifies for
// newly installed PPIs.
//
ProcessNotifyList (PrivateInMem);
//
// Entry PEI Phase 2
//
PeiCore (SecCoreData, NULL, PrivateInMem);
//((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) (
// SecCoreData,
// NULL,
// PrivateInMem
// );
//
// Code should not come here
//
ASSERT_EFI_ERROR(FALSE);
} }
// //
@ -407,78 +621,6 @@ Returns:
// //
ProcessNotifyList (Private); ProcessNotifyList (Private);
//
// If permanent memory was discovered and installed by this
// PEIM, shadow PEI Core and switch the stacks to the new memory.
//
if (Private->SwitchStackSignal) {
//
// Make sure we don't retry the same PEIM that added memory
//
Private->CurrentPeimCount++;
//
// Migrate IDT from CAR into real memory, so after stack switches to
// the new memory, the caller can get memory version PeiServiceTable.
//
MigrateIdtTable (PeiServices);
//
// Since we are at dispatch level, only the Core's private data
// is preserved, nobody else should have any data on the stack.
// So we need to copy PEI core instance data to memory.
//
PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);
ASSERT (PrivateInMem != NULL);
//
// Shadow PEI Core. When permanent memory is avaiable, shadow
// PEI Core and PEIMs to get high performance.
//
PeiCoreFileHandle = NULL;
//
// Find the PEI Core in the BFV
//
Status = PeiFindFileEx (
(EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader,
NULL,
EFI_FV_FILETYPE_PEI_CORE,
&PeiCoreFileHandle,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Shadow PEI Core into memory so it will run faster
//
Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);
ASSERT_EFI_ERROR (Status);
//
// Switch to memory based stack and reenter PEI Core that has been
// shadowed to memory.
//
//
// Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT
//
TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
PeiCoreParameters.SecCoreData = SecCoreData;
PeiCoreParameters.PpiList = NULL;
PeiCoreParameters.Data = PrivateInMem;
ASSERT (PeiCoreParameters.Data != 0);
PeiSwitchStacks (
InvokePeiCore,
(VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),
(VOID*) &PeiCoreParameters,
TopOfStack,
(VOID*)(UINTN)Private->StackBase
);
}
if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \ if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \
(Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) { (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {
// //
@ -665,45 +807,6 @@ PeiRegisterForShadow (
} }
/**
This routine invoke the PeiCore's entry in new stack environment.
@param Context1 The first context parameter is entry of PeiCore
@param Context2 The second context parameter is parameter structure point for PeiCore
**/
STATIC
VOID
InvokePeiCore (
VOID *Context1,
VOID *Context2
)
{
PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;
PEI_CORE_PARAMETERS *PeiCoreParameters;
//
// Running on new stack in SEC Core
//
PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;
PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;
//
// Call PEI Core using new stack
//
PeiCoreEntryPoint (
PeiCoreParameters->SecCoreData,
PeiCoreParameters->PpiList,
PeiCoreParameters->Data
);
//
// Never returns
//
ASSERT (FALSE);
CpuDeadLoop ();
}
/** /**
Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob. Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.

View File

@ -21,6 +21,12 @@ Abstract:
#include <PeiMain.h> #include <PeiMain.h>
static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
NULL
};
VOID VOID
InitializeMemoryServices ( InitializeMemoryServices (
IN PEI_CORE_INSTANCE *PrivateData, IN PEI_CORE_INSTANCE *PrivateData,
@ -49,6 +55,7 @@ Returns:
--*/ --*/
{ {
PrivateData->SwitchStackSignal = FALSE; PrivateData->SwitchStackSignal = FALSE;
if (OldCoreData == NULL) { if (OldCoreData == NULL) {
@ -57,6 +64,8 @@ Returns:
PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase; PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase;
PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize); PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);
PrivateData->SizeOfTemporaryMemory = SecCoreData->TemporaryRamSize;
PrivateData->StackSize = (UINT64) SecCoreData->StackSize;
DEBUG_CODE_BEGIN (); DEBUG_CODE_BEGIN ();
PrivateData->SizeOfCacheAsRam = SecCoreData->PeiTemporaryRamSize + SecCoreData->StackSize; PrivateData->SizeOfCacheAsRam = SecCoreData->PeiTemporaryRamSize + SecCoreData->StackSize;
@ -109,72 +118,15 @@ Returns:
--*/ --*/
{ {
PEI_CORE_INSTANCE *PrivateData; PEI_CORE_INSTANCE *PrivateData;
EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob;
EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob;
UINT64 PeiStackSize;
UINT64 EfiFreeMemorySize;
EFI_PHYSICAL_ADDRESS PhysicalAddressOfOldHob;
if (MemoryLength > (MAX_ADDRESS - MemoryBegin + 1))
return EFI_INVALID_PARAMETER;
DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength)); DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
PrivateData->PhysicalMemoryBegin = MemoryBegin;
PrivateData->PhysicalMemoryLength = MemoryLength;
PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;
PrivateData->SwitchStackSignal = TRUE; PrivateData->SwitchStackSignal = TRUE;
PrivateData->PeiMemoryInstalled = TRUE;
//
// Ensure the stack base is in page alignment
//
PrivateData->StackBase = ((UINTN)MemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
PeiStackSize = (RShiftU64 (MemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
if (PEI_STACK_SIZE > PeiStackSize) {
PrivateData->StackSize = PeiStackSize;
} else {
PrivateData->StackSize = PEI_STACK_SIZE;
}
OldHandOffHob = PrivateData->HobList.HandoffInformationTable;
PrivateData->HobList.Raw = (VOID *)((UINTN)(PrivateData->StackBase + PrivateData->StackSize));
NewHandOffHob = PrivateData->HobList.HandoffInformationTable;
PhysicalAddressOfOldHob = (EFI_PHYSICAL_ADDRESS) (UINTN) OldHandOffHob;
EfiFreeMemorySize = OldHandOffHob->EfiFreeMemoryBottom - PhysicalAddressOfOldHob;
DEBUG ((EFI_D_INFO, "HOBLIST address before memory init = 0x%p\n", OldHandOffHob));
DEBUG ((EFI_D_INFO, "HOBLIST address after memory init = 0x%p\n", NewHandOffHob));
CopyMem (
NewHandOffHob,
OldHandOffHob,
(UINTN)EfiFreeMemorySize
);
NewHandOffHob->EfiMemoryTop = MemoryBegin + MemoryLength;
NewHandOffHob->EfiFreeMemoryTop = NewHandOffHob->EfiMemoryTop;
NewHandOffHob->EfiMemoryBottom = MemoryBegin;
NewHandOffHob->EfiFreeMemoryBottom = (UINTN)NewHandOffHob + EfiFreeMemorySize;
NewHandOffHob->EfiEndOfHobList = (UINTN)NewHandOffHob +
(OldHandOffHob->EfiEndOfHobList -
PhysicalAddressOfOldHob);
//
// For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
// the 63-bit of address is set to 1.
//
SWITCH_TO_CACHE_MODE (PrivateData);
ConvertPpiPointers (PeiServices, OldHandOffHob, NewHandOffHob);
BuildStackHob (PrivateData->StackBase, PrivateData->StackSize);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -214,56 +166,70 @@ Returns:
PEI_CORE_INSTANCE *PrivateData; PEI_CORE_INSTANCE *PrivateData;
EFI_PEI_HOB_POINTERS Hob; EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS Offset; EFI_PHYSICAL_ADDRESS Offset;
EFI_PHYSICAL_ADDRESS *FreeMemoryTop;
EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
Hob.Raw = PrivateData->HobList.Raw;
// //
// Check if Hob already available // Check if Hob already available
// //
if (!PrivateData->PeiMemoryInstalled) { if (!PrivateData->PeiMemoryInstalled) {
//
// When PeiInstallMemory is called but CAR has *not* been moved to temporary memory,
// the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure.
//
if (!PrivateData->SwitchStackSignal) {
return EFI_NOT_AVAILABLE_YET; return EFI_NOT_AVAILABLE_YET;
} else {
FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop);
FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);
}
} else {
FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);
FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);
} }
Hob.Raw = PrivateData->HobList.Raw;
// //
// Check to see if on 4k boundary // Check to see if on 4k boundary
// //
Offset = Hob.HandoffInformationTable->EfiFreeMemoryTop & 0xFFF; Offset = *(FreeMemoryTop) & 0xFFF;
// //
// If not aligned, make the allocation aligned. // If not aligned, make the allocation aligned.
// //
if (Offset != 0) { if (Offset != 0) {
Hob.HandoffInformationTable->EfiFreeMemoryTop -= Offset; *(FreeMemoryTop) -= Offset;
} }
ASSERT (Hob.HandoffInformationTable->EfiFreeMemoryTop >= Hob.HandoffInformationTable->EfiFreeMemoryBottom);
// //
// Verify that there is sufficient memory to satisfy the allocation // Verify that there is sufficient memory to satisfy the allocation
// //
if (Hob.HandoffInformationTable->EfiFreeMemoryTop - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) <
Hob.HandoffInformationTable->EfiFreeMemoryBottom) { *(FreeMemoryBottom)) {
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages)); DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages));
DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \ DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \
EFI_SIZE_TO_PAGES ((UINTN) (Hob.HandoffInformationTable->EfiFreeMemoryTop - Hob.HandoffInformationTable->EfiFreeMemoryBottom)))); EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} else { } else {
// //
// Update the PHIT to reflect the memory usage // Update the PHIT to reflect the memory usage
// //
Hob.HandoffInformationTable->EfiFreeMemoryTop -= Pages * EFI_PAGE_SIZE; *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE;
// //
// Update the value for the caller // Update the value for the caller
// //
*Memory = Hob.HandoffInformationTable->EfiFreeMemoryTop; *Memory = *(FreeMemoryTop);
// //
// Create a memory allocation HOB. // Create a memory allocation HOB.
// //
BuildMemoryAllocationHob ( BuildMemoryAllocationHob (
Hob.HandoffInformationTable->EfiFreeMemoryTop, *(FreeMemoryTop),
Pages * EFI_PAGE_SIZE, Pages * EFI_PAGE_SIZE,
MemoryType MemoryType
); );

View File

@ -35,6 +35,7 @@ Revision History
#include <Ppi/GuidedSectionExtraction.h> #include <Ppi/GuidedSectionExtraction.h>
#include <Ppi/LoadFile.h> #include <Ppi/LoadFile.h>
#include <Ppi/Security2.h> #include <Ppi/Security2.h>
#include <Ppi/TemporaryRamSupport.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PeiCoreEntryPoint.h> #include <Library/PeiCoreEntryPoint.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
@ -66,9 +67,7 @@ typedef union {
VOID *Raw; VOID *Raw;
} PEI_PPI_LIST_POINTERS; } PEI_PPI_LIST_POINTERS;
#define PEI_STACK_SIZE 0x20000 #define MAX_PPI_DESCRIPTORS 64
#define MAX_PPI_DESCRIPTORS 128
typedef struct { typedef struct {
INTN PpiListEnd; INTN PpiListEnd;
@ -135,9 +134,14 @@ typedef struct{
VOID *CpuIo; VOID *CpuIo;
EFI_PEI_SECURITY2_PPI *PrivateSecurityPpi; EFI_PEI_SECURITY2_PPI *PrivateSecurityPpi;
EFI_PEI_SERVICES ServiceTableShadow; EFI_PEI_SERVICES ServiceTableShadow;
UINTN SizeOfTemporaryMemory;
UINTN SizeOfCacheAsRam; UINTN SizeOfCacheAsRam;
VOID *MaxTopOfCarHeap; VOID *MaxTopOfCarHeap;
EFI_PEI_PPI_DESCRIPTOR *XipLoadFile; EFI_PEI_PPI_DESCRIPTOR *XipLoadFile;
EFI_PHYSICAL_ADDRESS PhysicalMemoryBegin;
UINT64 PhysicalMemoryLength;
EFI_PHYSICAL_ADDRESS FreePhysicalMemoryTop;
VOID* ShadowedPeiCore;
CACHE_SECTION_DATA CacheSection; CACHE_SECTION_DATA CacheSection;
} PEI_CORE_INSTANCE; } PEI_CORE_INSTANCE;
@ -307,6 +311,35 @@ Returns:
; ;
EFI_STATUS
FindNextPeim (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
IN OUT EFI_FFS_FILE_HEADER **PeimFileHeader
)
/*++
Routine Description:
Given the input file pointer, search for the next matching file in the
FFS volume. The search starts from FileHeader inside
the Firmware Volume defined by FwVolHeader.
Arguments:
PeiServices - Pointer to the PEI Core Services Table.
FwVolHeader - Pointer to the FV header of the volume to search.
This parameter must point to a valid FFS volume.
PeimFileHeader - Pointer to the current file from which to begin searching.
This pointer will be updated upon return to reflect the file found.
Returns:
EFI_NOT_FOUND - No files matching the search criteria were found
EFI_SUCCESS
--*/
;
BOOLEAN BOOLEAN
Dispatched ( Dispatched (
IN UINT8 CurrentPeim, IN UINT8 CurrentPeim,
@ -440,7 +473,8 @@ Returns:
VOID VOID
ConvertPpiPointers ( ConvertPpiPointers (
IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob, IN UINTN OldCheckingBottom,
IN UINTN OldCheckingTop,
IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob
) )
/*++ /*++
@ -452,7 +486,8 @@ Routine Description:
Arguments: Arguments:
PeiServices - The PEI core services table. PeiServices - The PEI core services table.
OldHandOffHob - The old handoff HOB list. OldCheckingBottom - The old checking bottom.
OldCheckingTop - The old checking top.
NewHandOffHob - The new handoff HOB list. NewHandOffHob - The new handoff HOB list.
Returns: Returns:

View File

@ -96,12 +96,18 @@
gEfiPeiFirmwareVolumeInfoPpiGuid gEfiPeiFirmwareVolumeInfoPpiGuid
gEfiPeiLoadFilePpiGuid gEfiPeiLoadFilePpiGuid
gEfiPeiSecurity2PpiGuid gEfiPeiSecurity2PpiGuid
gEfiTemporaryRamSupportPpiGuid
[FixedPcd.common] [FixedPcd.common]
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeimDispatch gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeimDispatch
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeiCoreEntry gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValuePeiCoreEntry
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize
[FeaturePcd.common] [FeaturePcd.common]
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst
[BuildOptions.common]
MSFT:*_*_*_CC_FLAGS = /Fa$* /FAsc /FR$(@R).SBR

View File

@ -122,6 +122,7 @@ Returns:
PEI_CORE_INSTANCE *OldCoreData; PEI_CORE_INSTANCE *OldCoreData;
EFI_PEI_CPU_IO_PPI *CpuIo; EFI_PEI_CPU_IO_PPI *CpuIo;
EFI_PEI_PCI_CFG2_PPI *PciCfg; EFI_PEI_PCI_CFG2_PPI *PciCfg;
PEI_CORE_ENTRY_POINT ShadowedPeiCore;
mTick = 0; mTick = 0;
OldCoreData = (PEI_CORE_INSTANCE *) Data; OldCoreData = (PEI_CORE_INSTANCE *) Data;
@ -133,6 +134,16 @@ Returns:
} }
if (OldCoreData != NULL) { if (OldCoreData != NULL) {
ShadowedPeiCore = (PEI_CORE_ENTRY_POINT) (UINTN) OldCoreData->ShadowedPeiCore;
if (ShadowedPeiCore != NULL) {
OldCoreData->ShadowedPeiCore = NULL;
ShadowedPeiCore (
SecCoreData,
PpiList,
OldCoreData
);
}
CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE)); CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo; CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;
@ -181,8 +192,8 @@ Returns:
UINTN StackValue; UINTN StackValue;
StackValue = INIT_CAR_VALUE; StackValue = INIT_CAR_VALUE;
for (StackPointer = (UINTN *) OldCoreData->TopOfCarHeap; for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
((UINTN) StackPointer < ((UINTN) OldCoreData->MaxTopOfCarHeap)) ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
&& StackValue == INIT_CAR_VALUE; && StackValue == INIT_CAR_VALUE;
StackPointer++) { StackPointer++) {
StackValue = *StackPointer; StackValue = *StackPointer;
@ -190,7 +201,7 @@ Returns:
DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam)); DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n", DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
((UINTN) OldCoreData->MaxTopOfCarHeap - (UINTN) StackPointer) ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
)); ));
DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n", DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom - ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -

View File

@ -57,7 +57,8 @@ Returns:
VOID VOID
ConvertPpiPointers ( ConvertPpiPointers (
IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob, IN UINTN OldCheckingBottom,
IN UINTN OldCheckingTop,
IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob
) )
/*++ /*++
@ -69,7 +70,8 @@ Routine Description:
Arguments: Arguments:
PeiServices - The PEI core services table. PeiServices - The PEI core services table.
OldHandOffHob - The old handoff HOB list. OldCheckingBottom - The old checking bottom.
OldCheckingTop - The old checking top.
NewHandOffHob - The new handoff HOB list. NewHandOffHob - The new handoff HOB list.
Returns: Returns:
@ -83,15 +85,15 @@ Returns:
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
Fixup = (UINTN)NewHandOffHob - (UINTN)OldHandOffHob; Fixup = (UINTN)NewHandOffHob - OldCheckingBottom;
for (Index = 0; Index < MAX_PPI_DESCRIPTORS; Index++) { for (Index = 0; Index < MAX_PPI_DESCRIPTORS; Index++) {
if (Index < PrivateData->PpiData.PpiListEnd || if (Index < PrivateData->PpiData.PpiListEnd ||
Index > PrivateData->PpiData.NotifyListEnd) { Index > PrivateData->PpiData.NotifyListEnd) {
PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index]; PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];
if (((UINTN)PpiPointer->Raw < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && if (((UINTN)PpiPointer->Raw < OldCheckingTop) &&
((UINTN)PpiPointer->Raw >= (UINTN)OldHandOffHob)) { ((UINTN)PpiPointer->Raw >= OldCheckingBottom)) {
// //
// Convert the pointer to the PEIM descriptor from the old HOB heap // Convert the pointer to the PEIM descriptor from the old HOB heap
// to the relocated HOB heap. // to the relocated HOB heap.
@ -103,8 +105,8 @@ Returns:
// to try to convert the pointers in the PEIM descriptor // to try to convert the pointers in the PEIM descriptor
// //
if (((UINTN)PpiPointer->Ppi->Guid < (UINTN)OldHandOffHob->EfiFreeMemoryBottom) && if (((UINTN)PpiPointer->Ppi->Guid < OldCheckingTop) &&
((UINTN)PpiPointer->Ppi->Guid >= (UINTN)OldHandOffHob)) { ((UINTN)PpiPointer->Ppi->Guid >= OldCheckingBottom)) {
// //
// Convert the pointer to the GUID in the PPI or NOTIFY descriptor // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
// from the old HOB heap to the relocated HOB heap. // from the old HOB heap to the relocated HOB heap.
@ -117,8 +119,8 @@ Returns:
// the notification function in the NOTIFY descriptor needs not be converted. // the notification function in the NOTIFY descriptor needs not be converted.
// //
if (Index < PrivateData->PpiData.PpiListEnd && if (Index < PrivateData->PpiData.PpiListEnd &&
(UINTN)PpiPointer->Ppi->Ppi < (UINTN)OldHandOffHob->EfiFreeMemoryBottom && (UINTN)PpiPointer->Ppi->Ppi < OldCheckingTop &&
(UINTN)PpiPointer->Ppi->Ppi >= (UINTN)OldHandOffHob) { (UINTN)PpiPointer->Ppi->Ppi >= OldCheckingBottom) {
// //
// Convert the pointer to the PPI interface structure in the PPI descriptor // Convert the pointer to the PPI interface structure in the PPI descriptor
// from the old HOB heap to the relocated HOB heap. // from the old HOB heap to the relocated HOB heap.

View File

@ -136,6 +136,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries|40|UINT8|0x0001002f gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPerformanceLogEntries|40|UINT8|0x0001002f
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6|UINT32|0x00010030 gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6|UINT32|0x00010030
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32|UINT32|0x00010031 gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32|UINT32|0x00010031
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000|UINT32|0x00010032
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|0x30000002 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|0x30000002
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400|UINT32|0x30000003 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400|UINT32|0x30000003

View File

@ -239,6 +239,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6 gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32 gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32
gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000
[PcdsFixedAtBuild.IPF] [PcdsFixedAtBuild.IPF]

View File

@ -69,7 +69,7 @@ GetPeiServicesTablePointer (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
PeiServicesTablePointerLibConstructor ( PeiServicesTablePointerLibConstructor (
IN EFI_PEI_FILE_HANDLE FileHandle, IN EFI_PEI_FILE_HANDLE *FfsHeader,
IN EFI_PEI_SERVICES **PeiServices IN EFI_PEI_SERVICES **PeiServices
) )
{ {
@ -77,17 +77,4 @@ PeiServicesTablePointerLibConstructor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
}

View File

@ -74,20 +74,9 @@ SetPeiServicesTablePointer (
EFI_PEI_SERVICES ** PeiServicesTablePointer EFI_PEI_SERVICES ** PeiServicesTablePointer
) )
{ {
} AsmWriteKr7 ((UINT64)(UINTN)PeiServicesTablePointer);
/**
After memory initialization in PEI phase, the IDT table in temporary memory should
be migrated to memory, and the address of PeiServicesPointer also need to be updated
immediately preceding the new IDT table.
@param PeiServices The address of PeiServices pointer.
**/
VOID
MigrateIdtTable (
IN EFI_PEI_SERVICES **PeiServices
)
{
} }

View File

@ -360,7 +360,7 @@
gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverEnd|0x3040003|UINT32|0x30001014 # EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueDxeDriverEnd|0x3040003|UINT32|0x30001014 # EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END
[PcdsFixedAtBuild.IPF] [PcdsFixedAtBuild.IPF]
gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f gEfiMdePkgTokenSpaceGuid.PcdIoBlockBaseAddressForIpf|0x0ffffc000000|UINT64|0x0000000f # comments
[PcdsPatchableInModule.common] [PcdsPatchableInModule.common]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000|UINT64|0x0000000a gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xE0000000|UINT64|0x0000000a

View File

@ -1,4 +1,7 @@
/*++ /*! \addtogroup Library EdkGenericBdsLib */
/*@{ */
/**@file
BDS library definition, include the file and data structure
Copyright (c) 2006 - 2007, Intel Corporation Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
@ -9,15 +12,7 @@ http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name: **/
BdsLib.h
Abstract:
BDS library definition, include the file and data structure
--*/
#ifndef _BDS_LIB_H_ #ifndef _BDS_LIB_H_
#define _BDS_LIB_H_ #define _BDS_LIB_H_
@ -110,6 +105,11 @@ BdsLibBootNext (
VOID VOID
); );
/*!
\fn BdsLibBootViaBootOption
\param BDS_COMMON_OPTION
\param EFI_DEVICE_PATH_PROTOCOL
*/
EFI_STATUS EFI_STATUS
BdsLibBootViaBootOption ( BdsLibBootViaBootOption (
IN BDS_COMMON_OPTION * Option, IN BDS_COMMON_OPTION * Option,
@ -394,3 +394,4 @@ BdsLibGetHiiHandles (
); );
#endif // _BDS_LIB_H_ #endif // _BDS_LIB_H_
/*@} */

View File

@ -15,6 +15,7 @@
# #
#**/ #**/
################################################################################ ################################################################################
# #
# Defines Section - statements that will be processed to create a Makefile. # Defines Section - statements that will be processed to create a Makefile.
@ -22,6 +23,7 @@
################################################################################ ################################################################################
[Defines] [Defines]
DEC_SPECIFICATION = 0x00010005 DEC_SPECIFICATION = 0x00010005
PACKAGE_NAME = Nt32Pkg PACKAGE_NAME = Nt32Pkg
PACKAGE_GUID = 0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3 PACKAGE_GUID = 0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3

View File

@ -247,6 +247,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE
[PcdsFixedAtBuild.IA32] [PcdsFixedAtBuild.IA32]
#gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeiStackSize|0x20000
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1 gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128 gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128
gEfiNt32PkgTokenSpaceGuid.PcdWinNtMemorySizeForSecMain|L"64!64"|VOID*|12 gEfiNt32PkgTokenSpaceGuid.PcdWinNtMemorySizeForSecMain|L"64!64"|VOID*|12

View File

@ -162,9 +162,9 @@ INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf
INF Nt32Pkg/BootModePei/BootModePei.inf INF Nt32Pkg/BootModePei/BootModePei.inf
INF Nt32Pkg/WinNtFlashMapPei/WinNtFlashMapPei.inf INF Nt32Pkg/WinNtFlashMapPei/WinNtFlashMapPei.inf
INF MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf INF MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf
INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
INF Nt32Pkg/WinNtAutoScanPei/WinNtAutoScanPei.inf INF Nt32Pkg/WinNtAutoScanPei/WinNtAutoScanPei.inf
INF Nt32Pkg/WinNtFirmwareVolumePei/WinNtFirmwareVolumePei.inf INF Nt32Pkg/WinNtFirmwareVolumePei/WinNtFirmwareVolumePei.inf
INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
INF Nt32Pkg/WinNtThunkPPIToProtocolPei/WinNtThunkPPIToProtocolPei.inf INF Nt32Pkg/WinNtThunkPPIToProtocolPei/WinNtThunkPPIToProtocolPei.inf
INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

View File

@ -58,6 +58,7 @@ EFI_PEI_PROGRESS_CODE_PPI mSecStatusCodePpi = { SecPeiReport
NT_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress }; NT_FWH_PPI mSecFwhInformationPpi = { SecWinNtFdAddress };
TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};
EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = { EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
{ {
@ -85,6 +86,11 @@ EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
&gEfiPeiStatusCodePpiGuid, &gEfiPeiStatusCodePpiGuid,
&mSecStatusCodePpi &mSecStatusCodePpi
}, },
{
EFI_PEI_PPI_DESCRIPTOR_PPI,
&gEfiTemporaryRamSupportPpiGuid,
&mSecTemporaryRamSupportPpi
},
{ {
EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
&gNtFwhPpiGuid, &gNtFwhPpiGuid,
@ -116,7 +122,12 @@ UINTN mPdbNameModHandleArraySize = 0;
PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL; PDB_NAME_TO_MOD_HANDLE *mPdbNameModHandleArray = NULL;
VOID
EFIAPI
SecSwitchStack (
UINT32 TemporaryMemoryBase,
UINT32 PermenentMemoryBase
);
INTN INTN
EFIAPI EFIAPI
@ -566,18 +577,31 @@ Returns:
EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint; EFI_PHYSICAL_ADDRESS PeiCoreEntryPoint;
EFI_PHYSICAL_ADDRESS PeiImageAddress; EFI_PHYSICAL_ADDRESS PeiImageAddress;
EFI_SEC_PEI_HAND_OFF *SecCoreData; EFI_SEC_PEI_HAND_OFF *SecCoreData;
UINTN PeiStackSize;
// //
// Compute Top Of Memory for Stack and PEI Core Allocations // Compute Top Of Memory for Stack and PEI Core Allocations
// //
TopOfMemory = LargestRegion + LargestRegionSize; TopOfMemory = LargestRegion + LargestRegionSize;
PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
// //
// Allocate 128KB for the Stack // |-----------| <---- TemporaryRamBase + TemporaryRamSize
// | Heap |
// | |
// |-----------| <---- StackBase / PeiTemporaryMemoryBase
// | |
// | Stack |
// |-----------| <---- TemporaryRamBase
// //
TopOfStack = (VOID *)((UINTN)TopOfMemory - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT); TopOfStack = (VOID *)(LargestRegion + PeiStackSize);
TopOfMemory = LargestRegion + PeiStackSize;
//
// Reservet space for storing PeiCore's parament in stack.
//
TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
TopOfMemory = TopOfMemory - STACK_SIZE;
// //
// Patch value in dispatch table values // Patch value in dispatch table values
@ -591,12 +615,12 @@ Returns:
SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); SecCoreData->DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase; SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize); SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdWinNtFirmwareFdSize);
SecCoreData->TemporaryRamBase = (VOID*)(UINTN)TopOfMemory; SecCoreData->TemporaryRamBase = (VOID*)(UINTN)LargestRegion;
SecCoreData->TemporaryRamSize = STACK_SIZE; SecCoreData->TemporaryRamSize = STACK_SIZE;
SecCoreData->PeiTemporaryRamBase = SecCoreData->TemporaryRamBase; SecCoreData->StackBase = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);
SecCoreData->PeiTemporaryRamSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1); SecCoreData->StackSize = PeiStackSize;
SecCoreData->StackBase = (VOID*)((UINTN)SecCoreData->TemporaryRamBase + (UINTN)SecCoreData->TemporaryRamSize); SecCoreData->PeiTemporaryRamBase = SecCoreData->StackBase;
SecCoreData->StackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1); SecCoreData->PeiTemporaryRamSize = STACK_SIZE - PeiStackSize;
// //
// Load the PEI Core from a Firmware Volume // Load the PEI Core from a Firmware Volume
@ -1209,3 +1233,44 @@ _ModuleEntryPoint (
{ {
} }
EFI_STATUS
EFIAPI
SecTemporaryRamSupport (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
IN UINTN CopySize
)
{
//
// Migrate the whole temporary memory to permenent memory.
//
CopyMem (
(VOID*)(UINTN)PermanentMemoryBase,
(VOID*)(UINTN)TemporaryMemoryBase,
CopySize
);
//
// SecSwitchStack function must be invoked after the memory migration
// immediatly, also we need fixup the stack change caused by new call into
// permenent memory.
//
SecSwitchStack (
(UINT32) TemporaryMemoryBase,
(UINT32) PermanentMemoryBase
);
//
// We need *not* fix the return address because currently,
// The PeiCore is excuted in flash.
//
//
// Simulate to invalid CAR, terminate CAR
//
//ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
return EFI_SUCCESS;
}

View File

@ -31,6 +31,7 @@ Abstract:
#include <Ppi/NtThunk.h> #include <Ppi/NtThunk.h>
#include <Ppi/StatusCode.h> #include <Ppi/StatusCode.h>
#include <Ppi/NtFwh.h> #include <Ppi/NtFwh.h>
#include <Ppi/TemporaryRamSupport.h>
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
#include <Library/PrintLib.h> #include <Library/PrintLib.h>
@ -576,6 +577,14 @@ SecNt32PeCoffUnloadimage (
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
); );
EFI_STATUS
EFIAPI
SecTemporaryRamSupport (
IN CONST EFI_PEI_SERVICES **PeiServices,
IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
IN UINTN CopySize
);
typedef struct { typedef struct {
EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff; EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;

View File

@ -33,6 +33,7 @@
WinNtThunk.c WinNtThunk.c
FwVol.c FwVol.c
SecMain.c SecMain.c
Stack.asm
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
@ -58,6 +59,7 @@
gNtFwhPpiGuid # PPI ALWAYS_PRODUCED gNtFwhPpiGuid # PPI ALWAYS_PRODUCED
gPeiNtAutoScanPpiGuid # PPI ALWAYS_PRODUCED gPeiNtAutoScanPpiGuid # PPI ALWAYS_PRODUCED
gPeiNtThunkPpiGuid # PPI ALWAYS_PRODUCED gPeiNtThunkPpiGuid # PPI ALWAYS_PRODUCED
gEfiTemporaryRamSupportPpiGuid
[FixedPcd.common] [FixedPcd.common]
@ -69,4 +71,6 @@
[BuildOptions.common] [BuildOptions.common]
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 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
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 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
MSFT:*_*_IA32_PP_FLAGS = /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h
MSFT:*_*_IA32_ASM_FLAGS = /nologo /W3 /WX /c /coff /Cx /Zd /W0 /Zi
MSFT:*_*_IA32_ASMLINK_FLAGS = /link /nologo /tiny

94
Nt32Pkg/Sec/Stack.asm Normal file
View File

@ -0,0 +1,94 @@
;------------------------------------------------------------------------------
;
; Copyright (c) 2007, Intel Corporation
; All rights reserved. This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; Stack.asm
;
; Abstract:
;
; Switch the stack from temporary memory to permenent memory.
;
;------------------------------------------------------------------------------
.586p
.model flat,C
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; SecSwitchStack (
; UINT32 TemporaryMemoryBase,
; UINT32 PermenentMemoryBase
; );
;------------------------------------------------------------------------------
SecSwitchStack PROC
;
; Save three register: eax, ebx, ecx
;
push eax
push ebx
push ecx
push edx
;
; !!CAUTION!! this function address's is pushed into stack after
; migration of whole temporary memory, so need save it to permenent
; memory at first!
;
mov ebx, [esp + 20] ; Save the first parameter
mov ecx, [esp + 24] ; Save the second parameter
;
; Save this function's return address into permenent memory at first.
; Then, Fixup the esp point to permenent memory
;
mov eax, esp
sub eax, ebx
add eax, ecx
mov edx, dword ptr [esp] ; copy pushed register's value to permenent memory
mov dword ptr [eax], edx
mov edx, dword ptr [esp + 4]
mov dword ptr [eax + 4], edx
mov edx, dword ptr [esp + 8]
mov dword ptr [eax + 8], edx
mov edx, dword ptr [esp + 12]
mov dword ptr [eax + 12], edx
mov edx, dword ptr [esp + 16] ; Update this function's return address into permenent memory
mov dword ptr [eax + 16], edx
mov esp, eax ; From now, esp is pointed to permenent memory
;
; Fixup the ebp point to permenent memory
;
mov eax, ebp
sub eax, ebx
add eax, ecx
mov ebp, eax ; From now, ebp is pointed to permenent memory
;
; Fixup callee's ebp point for PeiDispatch
;
mov eax, dword ptr [ebp]
sub eax, ebx
add eax, ecx
mov dword ptr [ebp], eax ; From now, Temporary's PPI caller's stack is in permenent memory
pop edx
pop ecx
pop ebx
pop eax
ret
SecSwitchStack ENDP
END