Removed cross references from PciCf8Lib and PciExpressLib class to PciLib class.
Added PeCoffLoaderGetMachineType to the PeCoffGetEntryPointLibrary Class. Document to be updated. Added the PeCoffLoaderImageReadFromMemory() and PeCoffLoaderRelocateImageForRuntime () to the PcCoffLib. Updated EfiImage.h and removed EFI_IMAGE_OPTIONAL_HEADER and EFI_IMAGE_NT_HEADERS as they were replaced with checking the MachineType. PeCoffLib – Added checks for MachineType so the PeCoff lib can load any PE32 or PE32+ image. The relocations are still limited to IA32, X64, IPF, and EBC. I also added a re-relocator function to remove PeLoader Code from Runtime Lib. Even though there is only one instance of the re-relocator I wanted to get all the PeCoff loader code together. Replaced DEBUG_CODE() macro with DEBUG_CODE_START() and DEBUG_CODE_END() so you can debug through the DEBUG_CODE() macros. Also removed PE/COFF code and replaced with library usage. I also updated the IO Instrinsic lib to use _ReadWriteBarrior() to help with sync problems git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1103 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -21,6 +21,8 @@ Abstract:
|
||||
|
||||
#include <PeiMain.h>
|
||||
|
||||
|
||||
|
||||
EFI_STATUS
|
||||
PeiLoadImage (
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
@ -130,106 +132,35 @@ Returns:
|
||||
// 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;
|
||||
EFI_IMAGE_DEBUG_DIRECTORY_ENTRY * DebugEntry;
|
||||
UINTN DirCount;
|
||||
UINTN Index;
|
||||
UINTN Index1;
|
||||
BOOLEAN FileNameFound;
|
||||
CHAR8 *AsciiString;
|
||||
CHAR8 AsciiBuffer[512];
|
||||
VOID *CodeViewEntryPointer;
|
||||
INTN TEImageAdjust;
|
||||
EFI_IMAGE_DOS_HEADER *DosHeader;
|
||||
EFI_IMAGE_NT_HEADERS *PeHeader;
|
||||
DEBUG_CODE_BEGIN ();
|
||||
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
|
||||
UINTN Index;
|
||||
CHAR8 *PdbStr;
|
||||
CHAR8 AsciiBuffer[512];
|
||||
|
||||
//
|
||||
// Pe32Data is NULL when load TE image
|
||||
//
|
||||
PeHeader = NULL;
|
||||
if (TEImageHeader == NULL) {
|
||||
DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
|
||||
if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||
//
|
||||
// DOS image header is present, so read the PE header after the DOS image header
|
||||
//
|
||||
PeHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));
|
||||
} 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
|
||||
// the optional header to verify a desired directory entry is there.
|
||||
//
|
||||
DebugEntry = NULL;
|
||||
DirectoryEntry = NULL;
|
||||
TEImageAdjust = 0;
|
||||
if (TEImageHeader == NULL) {
|
||||
if (PeHeader->OptionalHeader.NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
|
||||
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *) &(PeHeader->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
||||
DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) ImageAddress + DirectoryEntry->VirtualAddress);
|
||||
}
|
||||
} else {
|
||||
if (TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
|
||||
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 +
|
||||
TEImageAdjust);
|
||||
}
|
||||
}
|
||||
ZeroMem (&ImageContext, sizeof (ImageContext));
|
||||
ImageContext.Handle = Pe32Data;
|
||||
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
||||
|
||||
if (DebugEntry != NULL && DirectoryEntry != NULL) {
|
||||
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);
|
||||
switch (* (UINT32 *) CodeViewEntryPointer) {
|
||||
case CODEVIEW_SIGNATURE_NB10:
|
||||
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);
|
||||
break;
|
||||
|
||||
case CODEVIEW_SIGNATURE_RSDS:
|
||||
AsciiString = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);
|
||||
break;
|
||||
|
||||
default:
|
||||
AsciiString = NULL;
|
||||
break;
|
||||
}
|
||||
if (AsciiString != NULL) {
|
||||
FileNameFound = FALSE;
|
||||
for (Index = 0, Index1 = 0; AsciiString[Index] != 0; Index++) {
|
||||
if (AsciiString[Index] == '\\') {
|
||||
Index1 = Index;
|
||||
FileNameFound = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (FileNameFound) {
|
||||
for (Index = Index1 + 1; AsciiString[Index] != '.'; Index++) {
|
||||
AsciiBuffer[Index - (Index1 + 1)] = AsciiString[Index];
|
||||
}
|
||||
AsciiBuffer[Index - (Index1 + 1)] = 0;
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PeCoffLoaderGetImageInfo (&ImageContext);
|
||||
|
||||
if (ImageContext.PdbPointer != NULL) {
|
||||
//
|
||||
// Copy PDB pointer to AsciiBuffer and replace .PDB with .EFI
|
||||
//
|
||||
PdbStr = ImageContext.PdbPointer;
|
||||
for (Index = 0; PdbStr != 0; Index++, PdbStr++) {
|
||||
AsciiBuffer[Index] = *PdbStr;
|
||||
if (*PdbStr == '.') {
|
||||
AsciiBuffer[Index] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));
|
||||
}
|
||||
);
|
||||
|
||||
DEBUG_CODE_END ();
|
||||
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));
|
||||
|
||||
|
Reference in New Issue
Block a user