summaryrefslogtreecommitdiffstats
path: root/EdkModulePkg/Core/Pei/Image/Image.c
diff options
context:
space:
mode:
Diffstat (limited to 'EdkModulePkg/Core/Pei/Image/Image.c')
-rw-r--r--EdkModulePkg/Core/Pei/Image/Image.c119
1 files changed, 25 insertions, 94 deletions
diff --git a/EdkModulePkg/Core/Pei/Image/Image.c b/EdkModulePkg/Core/Pei/Image/Image.c
index 5edc8479eb..9df12f8ab3 100644
--- a/EdkModulePkg/Core/Pei/Image/Image.c
+++ b/EdkModulePkg/Core/Pei/Image/Image.c
@@ -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"));