mirror of https://github.com/acidanthera/audk.git
Apply changes(Unix Type to Windows Type) to the rest of the 2 files:
edk2\EdkModulePkg\Core\Pei\Image\Image.c edk2\EdkModulePkg\Core\Pei\PeiMain\Peimain.c git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@431 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
6652e7be38
commit
a0b7c09f23
|
@ -1,239 +1,243 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2006, Intel Corporation
|
Copyright (c) 2006, Intel Corporation
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
http://opensource.org/licenses/bsd-license.php
|
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:
|
Module Name:
|
||||||
|
|
||||||
Image.c
|
Image.c
|
||||||
|
|
||||||
Abstract:
|
Abstract:
|
||||||
|
|
||||||
Pei Core Load Image Support
|
Pei Core Load Image Support
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
#include <PeiMain.h>
|
#include <PeiMain.h>
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
PeiLoadImage (
|
PeiLoadImage (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_FFS_FILE_HEADER *PeimFileHeader,
|
IN EFI_FFS_FILE_HEADER *PeimFileHeader,
|
||||||
OUT VOID **EntryPoint
|
OUT VOID **EntryPoint
|
||||||
)
|
)
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
Routine for loading file image.
|
Routine for loading file image.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
PeiServices - The PEI core services table.
|
PeiServices - The PEI core services table.
|
||||||
PeimFileHeader - Pointer to the FFS file header of the image.
|
PeimFileHeader - Pointer to the FFS file header of the image.
|
||||||
EntryPoint - Pointer to entry point of specified image file for output.
|
EntryPoint - Pointer to entry point of specified image file for output.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
Status - EFI_SUCCESS - Image is successfully loaded.
|
Status - EFI_SUCCESS - Image is successfully loaded.
|
||||||
EFI_NOT_FOUND - Fail to locate necessary PPI
|
EFI_NOT_FOUND - Fail to locate necessary PPI
|
||||||
Others - Fail to load file.
|
Others - Fail to load file.
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
VOID *Pe32Data;
|
VOID *Pe32Data;
|
||||||
EFI_PEI_FV_FILE_LOADER_PPI *FvLoadFilePpi;
|
EFI_PEI_FV_FILE_LOADER_PPI *FvLoadFilePpi;
|
||||||
EFI_PHYSICAL_ADDRESS ImageAddress;
|
//#ifdef EFI_NT_EMULATOR
|
||||||
UINT64 ImageSize;
|
// EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
|
||||||
EFI_PHYSICAL_ADDRESS ImageEntryPoint;
|
// NT_PEI_LOAD_FILE_PPI *PeiNtService;
|
||||||
EFI_TE_IMAGE_HEADER *TEImageHeader;
|
//#endif
|
||||||
|
EFI_PHYSICAL_ADDRESS ImageAddress;
|
||||||
*EntryPoint = NULL;
|
UINT64 ImageSize;
|
||||||
TEImageHeader = NULL;
|
EFI_PHYSICAL_ADDRESS ImageEntryPoint;
|
||||||
|
EFI_TE_IMAGE_HEADER *TEImageHeader;
|
||||||
//
|
|
||||||
// Try to find a PE32 section.
|
*EntryPoint = NULL;
|
||||||
//
|
TEImageHeader = NULL;
|
||||||
Status = PeiCoreFfsFindSectionData (
|
|
||||||
EFI_SECTION_PE32,
|
//
|
||||||
PeimFileHeader,
|
// Try to find a PE32 section.
|
||||||
&Pe32Data
|
//
|
||||||
);
|
Status = PeiCoreFfsFindSectionData (
|
||||||
//
|
EFI_SECTION_PE32,
|
||||||
// If we didn't find a PE32 section, try to find a TE section.
|
PeimFileHeader,
|
||||||
//
|
&Pe32Data
|
||||||
if (EFI_ERROR (Status)) {
|
);
|
||||||
Status = PeiCoreFfsFindSectionData (
|
//
|
||||||
EFI_SECTION_TE,
|
// If we didn't find a PE32 section, try to find a TE section.
|
||||||
PeimFileHeader,
|
//
|
||||||
(VOID **) &TEImageHeader
|
if (EFI_ERROR (Status)) {
|
||||||
);
|
Status = PeiCoreFfsFindSectionData (
|
||||||
if (EFI_ERROR (Status) || TEImageHeader == NULL) {
|
EFI_SECTION_TE,
|
||||||
//
|
PeimFileHeader,
|
||||||
// There was not a PE32 or a TE section, so assume that it's a Compressed section
|
(VOID **) &TEImageHeader
|
||||||
// and use the LoadFile
|
);
|
||||||
//
|
if (EFI_ERROR (Status) || TEImageHeader == NULL) {
|
||||||
Status = PeiCoreLocatePpi (
|
//
|
||||||
&gEfiPeiFvFileLoaderPpiGuid,
|
// There was not a PE32 or a TE section, so assume that it's a Compressed section
|
||||||
0,
|
// and use the LoadFile
|
||||||
NULL,
|
//
|
||||||
(VOID **)&FvLoadFilePpi
|
Status = PeiCoreLocatePpi (
|
||||||
);
|
&gEfiPeiFvFileLoaderPpiGuid,
|
||||||
if (EFI_ERROR (Status)) {
|
0,
|
||||||
return EFI_NOT_FOUND;
|
NULL,
|
||||||
}
|
(VOID **)&FvLoadFilePpi
|
||||||
|
);
|
||||||
Status = FvLoadFilePpi->FvLoadFile (
|
if (EFI_ERROR (Status)) {
|
||||||
FvLoadFilePpi,
|
return EFI_NOT_FOUND;
|
||||||
PeimFileHeader,
|
}
|
||||||
&ImageAddress,
|
|
||||||
&ImageSize,
|
Status = FvLoadFilePpi->FvLoadFile (
|
||||||
&ImageEntryPoint
|
FvLoadFilePpi,
|
||||||
);
|
PeimFileHeader,
|
||||||
|
&ImageAddress,
|
||||||
if (EFI_ERROR (Status)) {
|
&ImageSize,
|
||||||
return EFI_NOT_FOUND;
|
&ImageEntryPoint
|
||||||
}
|
);
|
||||||
|
|
||||||
//
|
if (EFI_ERROR (Status)) {
|
||||||
// Retrieve the entry point from the PE/COFF image header
|
return EFI_NOT_FOUND;
|
||||||
//
|
}
|
||||||
Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageAddress, EntryPoint);
|
|
||||||
if (EFI_ERROR (Status)) {
|
//
|
||||||
return EFI_NOT_FOUND;
|
// Retrieve the entry point from the PE/COFF image header
|
||||||
}
|
//
|
||||||
} else {
|
Status = PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)ImageAddress, EntryPoint);
|
||||||
//
|
if (EFI_ERROR (Status)) {
|
||||||
// Retrieve the entry point from the TE image header
|
return EFI_NOT_FOUND;
|
||||||
//
|
}
|
||||||
ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) TEImageHeader;
|
} else {
|
||||||
*EntryPoint = (VOID *)((UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) +
|
//
|
||||||
TEImageHeader->AddressOfEntryPoint - TEImageHeader->StrippedSize);
|
// Retrieve the entry point from the TE image header
|
||||||
}
|
//
|
||||||
} else {
|
ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) TEImageHeader;
|
||||||
//
|
*EntryPoint = (VOID *)((UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) +
|
||||||
// Retrieve the entry point from the PE/COFF image header
|
TEImageHeader->AddressOfEntryPoint - TEImageHeader->StrippedSize);
|
||||||
//
|
}
|
||||||
ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;
|
} else {
|
||||||
Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
|
//
|
||||||
if (EFI_ERROR (Status)) {
|
// Retrieve the entry point from the PE/COFF image header
|
||||||
return EFI_NOT_FOUND;
|
//
|
||||||
}
|
ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;
|
||||||
}
|
Status = PeCoffLoaderGetEntryPoint (Pe32Data, EntryPoint);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
//
|
return EFI_NOT_FOUND;
|
||||||
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
|
}
|
||||||
//
|
}
|
||||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", Pe32Data, *EntryPoint));
|
|
||||||
DEBUG_CODE (
|
//
|
||||||
EFI_IMAGE_DATA_DIRECTORY * DirectoryEntry;
|
// Print debug message: Loading PEIM at 0x12345678 EntryPoint=0x12345688 Driver.efi
|
||||||
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY * DebugEntry;
|
//
|
||||||
UINTN DirCount;
|
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", Pe32Data, *EntryPoint));
|
||||||
UINTN Index;
|
DEBUG_CODE (
|
||||||
UINTN Index1;
|
EFI_IMAGE_DATA_DIRECTORY * DirectoryEntry;
|
||||||
BOOLEAN FileNameFound;
|
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY * DebugEntry;
|
||||||
CHAR8 *AsciiString;
|
UINTN DirCount;
|
||||||
CHAR8 AsciiBuffer[512];
|
UINTN Index;
|
||||||
VOID *CodeViewEntryPointer;
|
UINTN Index1;
|
||||||
INTN TEImageAdjust;
|
BOOLEAN FileNameFound;
|
||||||
EFI_IMAGE_DOS_HEADER *DosHeader;
|
CHAR8 *AsciiString;
|
||||||
EFI_IMAGE_NT_HEADERS *PeHeader;
|
CHAR8 AsciiBuffer[512];
|
||||||
|
VOID *CodeViewEntryPointer;
|
||||||
//
|
INTN TEImageAdjust;
|
||||||
// Pe32Data is NULL when load TE image
|
EFI_IMAGE_DOS_HEADER *DosHeader;
|
||||||
//
|
EFI_IMAGE_NT_HEADERS *PeHeader;
|
||||||
PeHeader = NULL;
|
|
||||||
if (TEImageHeader == NULL) {
|
//
|
||||||
DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
|
// Pe32Data is NULL when load TE image
|
||||||
if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
//
|
||||||
//
|
PeHeader = NULL;
|
||||||
// DOS image header is present, so read the PE header after the DOS image header
|
if (TEImageHeader == NULL) {
|
||||||
//
|
DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
|
||||||
PeHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));
|
if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||||
} else {
|
//
|
||||||
//
|
// DOS image header is present, so read the PE header after the DOS image header
|
||||||
// DOS image header is not present, so PE header is at the image base
|
//
|
||||||
//
|
PeHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));
|
||||||
PeHeader = (EFI_IMAGE_NT_HEADERS *) Pe32Data;
|
} else {
|
||||||
}
|
//
|
||||||
}
|
// DOS image header is not present, so PE header is at the image base
|
||||||
|
//
|
||||||
//
|
PeHeader = (EFI_IMAGE_NT_HEADERS *) Pe32Data;
|
||||||
// Find the codeview info in the image and display the file name
|
}
|
||||||
// being loaded.
|
}
|
||||||
//
|
|
||||||
// Per the PE/COFF spec, you can't assume that a given data directory
|
//
|
||||||
// is present in the image. You have to check the NumberOfRvaAndSizes in
|
// Find the codeview info in the image and display the file name
|
||||||
// the optional header to verify a desired directory entry is there.
|
// being loaded.
|
||||||
//
|
//
|
||||||
DebugEntry = NULL;
|
// Per the PE/COFF spec, you can't assume that a given data directory
|
||||||
DirectoryEntry = NULL;
|
// is present in the image. You have to check the NumberOfRvaAndSizes in
|
||||||
TEImageAdjust = 0;
|
// the optional header to verify a desired directory entry is there.
|
||||||
if (TEImageHeader == NULL) {
|
//
|
||||||
if (PeHeader->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
|
DebugEntry = NULL;
|
||||||
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(PeHeader->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
DirectoryEntry = NULL;
|
||||||
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) ImageAddress + DirectoryEntry->VirtualAddress);
|
TEImageAdjust = 0;
|
||||||
}
|
if (TEImageHeader == NULL) {
|
||||||
} else {
|
if (PeHeader->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
|
||||||
if (TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
|
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(PeHeader->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
||||||
DirectoryEntry = &TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
|
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) ImageAddress + DirectoryEntry->VirtualAddress);
|
||||||
TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize;
|
}
|
||||||
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) TEImageHeader +
|
} else {
|
||||||
TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
|
if (TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
|
||||||
TEImageAdjust);
|
DirectoryEntry = &TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
|
||||||
}
|
TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize;
|
||||||
}
|
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) TEImageHeader +
|
||||||
|
TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
|
||||||
if (DebugEntry != NULL && DirectoryEntry != NULL) {
|
TEImageAdjust);
|
||||||
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount++, DebugEntry++) {
|
}
|
||||||
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
|
}
|
||||||
if (DebugEntry->SizeOfData > 0) {
|
|
||||||
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageAddress + (UINTN)TEImageAdjust);
|
if (DebugEntry != NULL && DirectoryEntry != NULL) {
|
||||||
switch (* (UINT32 *) CodeViewEntryPointer) {
|
for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount++, DebugEntry++) {
|
||||||
case CODEVIEW_SIGNATURE_NB10:
|
if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
|
||||||
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
|
if (DebugEntry->SizeOfData > 0) {
|
||||||
break;
|
CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageAddress + (UINTN)TEImageAdjust);
|
||||||
|
switch (* (UINT32 *) CodeViewEntryPointer) {
|
||||||
case CODEVIEW_SIGNATURE_RSDS:
|
case CODEVIEW_SIGNATURE_NB10:
|
||||||
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
|
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case CODEVIEW_SIGNATURE_RSDS:
|
||||||
AsciiString = NULL;
|
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (AsciiString != NULL) {
|
default:
|
||||||
FileNameFound = FALSE;
|
AsciiString = NULL;
|
||||||
for (Index = 0, Index1 = 0; AsciiString[Index] != 0; Index++) {
|
break;
|
||||||
if (AsciiString[Index] == '\\') {
|
}
|
||||||
Index1 = Index;
|
if (AsciiString != NULL) {
|
||||||
FileNameFound = TRUE;
|
FileNameFound = FALSE;
|
||||||
}
|
for (Index = 0, Index1 = 0; AsciiString[Index] != 0; Index++) {
|
||||||
}
|
if (AsciiString[Index] == '\\') {
|
||||||
|
Index1 = Index;
|
||||||
if (FileNameFound) {
|
FileNameFound = TRUE;
|
||||||
for (Index = Index1 + 1; AsciiString[Index] != '.'; Index++) {
|
}
|
||||||
AsciiBuffer[Index - (Index1 + 1)] = AsciiString[Index];
|
}
|
||||||
}
|
|
||||||
AsciiBuffer[Index - (Index1 + 1)] = 0;
|
if (FileNameFound) {
|
||||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));
|
for (Index = Index1 + 1; AsciiString[Index] != '.'; Index++) {
|
||||||
break;
|
AsciiBuffer[Index - (Index1 + 1)] = AsciiString[Index];
|
||||||
}
|
}
|
||||||
}
|
AsciiBuffer[Index - (Index1 + 1)] = 0;
|
||||||
}
|
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
}
|
||||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));
|
}
|
||||||
|
}
|
||||||
return EFI_SUCCESS;
|
);
|
||||||
}
|
|
||||||
|
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));
|
||||||
|
|
||||||
|
return EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -1,241 +1,242 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2006, Intel Corporation
|
Copyright (c) 2006, Intel Corporation
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
http://opensource.org/licenses/bsd-license.php
|
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:
|
Module Name:
|
||||||
|
|
||||||
PeiMain.c
|
PeiMain.c
|
||||||
|
|
||||||
Abstract:
|
Abstract:
|
||||||
|
|
||||||
Pei Core Main Entry Point
|
Pei Core Main Entry Point
|
||||||
|
|
||||||
Revision History
|
Revision History
|
||||||
|
|
||||||
--*/
|
--*/
|
||||||
|
|
||||||
#include <PeiMain.h>
|
#include <PeiMain.h>
|
||||||
|
|
||||||
//
|
//
|
||||||
//CAR is filled with this initial value during SEC phase
|
//CAR is filled with this initial value during SEC phase
|
||||||
//
|
//
|
||||||
#define INIT_CAR_VALUE 0x5AA55AA5
|
#define INIT_CAR_VALUE 0x5AA55AA5
|
||||||
|
|
||||||
static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
|
static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
|
||||||
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
|
||||||
&gEfiPeiMemoryDiscoveredPpiGuid,
|
&gEfiPeiMemoryDiscoveredPpiGuid,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pei Core Module Variables
|
// Pei Core Module Variables
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
static EFI_PEI_SERVICES mPS = {
|
static EFI_PEI_SERVICES mPS = {
|
||||||
{
|
{
|
||||||
PEI_SERVICES_SIGNATURE,
|
PEI_SERVICES_SIGNATURE,
|
||||||
PEI_SERVICES_REVISION,
|
PEI_SERVICES_REVISION,
|
||||||
sizeof (EFI_PEI_SERVICES),
|
sizeof (EFI_PEI_SERVICES),
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
PeiInstallPpi,
|
PeiInstallPpi,
|
||||||
PeiReInstallPpi,
|
PeiReInstallPpi,
|
||||||
PeiLocatePpi,
|
PeiLocatePpi,
|
||||||
PeiNotifyPpi,
|
PeiNotifyPpi,
|
||||||
|
|
||||||
PeiGetBootMode,
|
PeiGetBootMode,
|
||||||
PeiSetBootMode,
|
PeiSetBootMode,
|
||||||
|
|
||||||
PeiGetHobList,
|
PeiGetHobList,
|
||||||
PeiCreateHob,
|
PeiCreateHob,
|
||||||
|
|
||||||
PeiFvFindNextVolume,
|
PeiFvFindNextVolume,
|
||||||
PeiFfsFindNextFile,
|
PeiFfsFindNextFile,
|
||||||
PeiFfsFindSectionData,
|
PeiFfsFindSectionData,
|
||||||
|
|
||||||
PeiInstallPeiMemory,
|
PeiInstallPeiMemory,
|
||||||
PeiAllocatePages,
|
PeiAllocatePages,
|
||||||
PeiAllocatePool,
|
PeiAllocatePool,
|
||||||
(EFI_PEI_COPY_MEM)CopyMem,
|
(EFI_PEI_COPY_MEM)CopyMem,
|
||||||
(EFI_PEI_SET_MEM)SetMem,
|
(EFI_PEI_SET_MEM)SetMem,
|
||||||
|
|
||||||
PeiReportStatusCode,
|
PeiReportStatusCode,
|
||||||
|
|
||||||
PeiResetSystem
|
PeiResetSystem
|
||||||
};
|
};
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
PeiCore (
|
PeiCore (
|
||||||
IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,
|
IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,
|
||||||
IN PEI_CORE_INSTANCE *OldCoreData
|
IN PEI_CORE_INSTANCE *OldCoreData
|
||||||
)
|
)
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Routine Description:
|
Routine Description:
|
||||||
|
|
||||||
Main entry point to Pei Core. After switching stack in the PEI core,
|
The entry routine to Pei Core, invoked by PeiMain during transition
|
||||||
it will restart with the old core data.
|
from SEC to PEI. After switching stack in the PEI core, it will restart
|
||||||
|
with the old core data.
|
||||||
Arguments:
|
|
||||||
|
Arguments:
|
||||||
PeiStartupDescriptor - Information and services provided by SEC phase.
|
|
||||||
OldCoreData - Pointer to old core data that is used to initialize the
|
PeiStartupDescriptor - Information and services provided by SEC phase.
|
||||||
core's data areas.
|
OldCoreData - Pointer to old core data that is used to initialize the
|
||||||
|
core's data areas.
|
||||||
Returns:
|
|
||||||
|
Returns:
|
||||||
This function never returns
|
|
||||||
EFI_NOT_FOUND - Never reach
|
This function never returns
|
||||||
|
EFI_NOT_FOUND - Never reach
|
||||||
--*/
|
|
||||||
{
|
--*/
|
||||||
PEI_CORE_INSTANCE PrivateData;
|
{
|
||||||
EFI_STATUS Status;
|
PEI_CORE_INSTANCE PrivateData;
|
||||||
PEI_CORE_TEMP_POINTERS TempPtr;
|
EFI_STATUS Status;
|
||||||
PEI_CORE_DISPATCH_DATA *DispatchData;
|
PEI_CORE_TEMP_POINTERS TempPtr;
|
||||||
UINT64 mTick;
|
PEI_CORE_DISPATCH_DATA *DispatchData;
|
||||||
|
UINT64 mTick;
|
||||||
mTick = 0;
|
|
||||||
|
mTick = 0;
|
||||||
#ifdef EFI_PEI_PERFORMANCE
|
|
||||||
if (OldCoreData == NULL) {
|
#ifdef EFI_PEI_PERFORMANCE
|
||||||
mTick = GetPerformanceCounter ();
|
if (OldCoreData == NULL) {
|
||||||
}
|
mTick = GetPerformanceCounter ();
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
//
|
|
||||||
// For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
|
//
|
||||||
// the 63-bit of address is set to 1.
|
// 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 (OldCoreData);
|
//
|
||||||
|
SWITCH_TO_CACHE_MODE (OldCoreData);
|
||||||
if (OldCoreData != NULL) {
|
|
||||||
CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
|
if (OldCoreData != NULL) {
|
||||||
} else {
|
CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
|
||||||
ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
|
} else {
|
||||||
}
|
ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
|
||||||
|
}
|
||||||
PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
|
|
||||||
PrivateData.PS = &mPS;
|
PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
|
||||||
|
PrivateData.PS = &mPS;
|
||||||
//
|
|
||||||
// Initialize libraries that the PeiCore is linked against
|
//
|
||||||
// BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
|
// Initialize libraries that the PeiCore is linked against
|
||||||
//
|
// BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
|
||||||
ProcessLibraryConstructorList (NULL, &PrivateData.PS);
|
//
|
||||||
|
ProcessLibraryConstructorList (NULL, &PrivateData.PS);
|
||||||
InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);
|
|
||||||
|
InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);
|
||||||
InitializePpiServices (&PrivateData.PS, OldCoreData);
|
|
||||||
|
InitializePpiServices (&PrivateData.PS, OldCoreData);
|
||||||
InitializeSecurityServices (&PrivateData.PS, OldCoreData);
|
|
||||||
|
InitializeSecurityServices (&PrivateData.PS, OldCoreData);
|
||||||
InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);
|
|
||||||
|
InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);
|
||||||
if (OldCoreData != NULL) {
|
|
||||||
|
if (OldCoreData != NULL) {
|
||||||
PERF_END (NULL,"PreMem", NULL, 0);
|
|
||||||
PERF_START (NULL,"PostMem", NULL, 0);
|
PERF_END (NULL,"PreMem", NULL, 0);
|
||||||
|
PERF_START (NULL,"PostMem", NULL, 0);
|
||||||
//
|
|
||||||
// The following code dumps out interesting cache as RAM usage information
|
//
|
||||||
// so we can keep tabs on how the cache as RAM is being utilized. The
|
// The following code dumps out interesting cache as RAM usage information
|
||||||
// DEBUG_CODE macro is used to prevent this code from being compiled
|
// so we can keep tabs on how the cache as RAM is being utilized. The
|
||||||
// on a debug build.
|
// DEBUG_CODE macro is used to prevent this code from being compiled
|
||||||
//
|
// on a debug build.
|
||||||
DEBUG_CODE (
|
//
|
||||||
UINTN *StackPointer;
|
DEBUG_CODE (
|
||||||
UINTN StackValue;
|
UINTN *StackPointer;
|
||||||
|
UINTN StackValue;
|
||||||
StackValue = INIT_CAR_VALUE;
|
|
||||||
for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
|
StackValue = INIT_CAR_VALUE;
|
||||||
((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
|
for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
|
||||||
&& StackValue == INIT_CAR_VALUE;
|
((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
|
||||||
StackPointer++) {
|
&& StackValue == INIT_CAR_VALUE;
|
||||||
StackValue = *StackPointer;
|
StackPointer++) {
|
||||||
}
|
StackValue = *StackPointer;
|
||||||
|
}
|
||||||
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, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
|
||||||
((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
|
DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
|
||||||
));
|
((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
|
||||||
DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
|
));
|
||||||
((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
|
DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
|
||||||
(UINTN) OldCoreData->HobList.Raw)
|
((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
|
||||||
));
|
(UINTN) OldCoreData->HobList.Raw)
|
||||||
);
|
));
|
||||||
|
);
|
||||||
//
|
|
||||||
// Alert any listeners that there is permanent memory available
|
//
|
||||||
//
|
// Alert any listeners that there is permanent memory available
|
||||||
PERF_START (NULL,"DisMem", NULL, 0);
|
//
|
||||||
Status = PeiCoreInstallPpi (&mMemoryDiscoveredPpi);
|
PERF_START (NULL,"DisMem", NULL, 0);
|
||||||
PERF_END (NULL,"DisMem", NULL, 0);
|
Status = PeiCoreInstallPpi (&mMemoryDiscoveredPpi);
|
||||||
|
PERF_END (NULL,"DisMem", NULL, 0);
|
||||||
} else {
|
|
||||||
|
} else {
|
||||||
//
|
|
||||||
// Report Status Code EFI_SW_PC_INIT
|
//
|
||||||
//
|
// Report Status Code EFI_SW_PC_INIT
|
||||||
REPORT_STATUS_CODE (
|
//
|
||||||
EFI_PROGRESS_CODE,
|
REPORT_STATUS_CODE (
|
||||||
EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
|
EFI_PROGRESS_CODE,
|
||||||
);
|
EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
|
||||||
|
);
|
||||||
//
|
|
||||||
// If first pass, start performance measurement.
|
//
|
||||||
//
|
// If first pass, start performance measurement.
|
||||||
PERF_START (NULL,"PreMem", NULL, mTick);
|
//
|
||||||
|
PERF_START (NULL,"PreMem", NULL, mTick);
|
||||||
//
|
|
||||||
// If SEC provided any PPI services to PEI, install them.
|
//
|
||||||
//
|
// If SEC provided any PPI services to PEI, install them.
|
||||||
if (PeiStartupDescriptor->DispatchTable != NULL) {
|
//
|
||||||
Status = PeiCoreInstallPpi (PeiStartupDescriptor->DispatchTable);
|
if (PeiStartupDescriptor->DispatchTable != NULL) {
|
||||||
ASSERT_EFI_ERROR (Status);
|
Status = PeiCoreInstallPpi (PeiStartupDescriptor->DispatchTable);
|
||||||
}
|
ASSERT_EFI_ERROR (Status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DispatchData = &PrivateData.DispatchData;
|
|
||||||
|
DispatchData = &PrivateData.DispatchData;
|
||||||
//
|
|
||||||
// Call PEIM dispatcher
|
//
|
||||||
//
|
// Call PEIM dispatcher
|
||||||
PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);
|
//
|
||||||
|
PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);
|
||||||
//
|
|
||||||
// Check if InstallPeiMemory service was called.
|
//
|
||||||
//
|
// Check if InstallPeiMemory service was called.
|
||||||
ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
|
//
|
||||||
|
ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
|
||||||
PERF_END (NULL, "PostMem", NULL, 0);
|
|
||||||
|
PERF_END (NULL, "PostMem", NULL, 0);
|
||||||
Status = PeiCoreLocatePpi (
|
|
||||||
&gEfiDxeIplPpiGuid,
|
Status = PeiCoreLocatePpi (
|
||||||
0,
|
&gEfiDxeIplPpiGuid,
|
||||||
NULL,
|
0,
|
||||||
(VOID **)&TempPtr.DxeIpl
|
NULL,
|
||||||
);
|
(VOID **)&TempPtr.DxeIpl
|
||||||
ASSERT_EFI_ERROR (Status);
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
|
|
||||||
Status = TempPtr.DxeIpl->Entry (
|
DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
|
||||||
TempPtr.DxeIpl,
|
Status = TempPtr.DxeIpl->Entry (
|
||||||
&PrivateData.PS,
|
TempPtr.DxeIpl,
|
||||||
PrivateData.HobList
|
&PrivateData.PS,
|
||||||
);
|
PrivateData.HobList
|
||||||
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
return EFI_NOT_FOUND;
|
|
||||||
}
|
return EFI_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue