mirror of https://github.com/acidanthera/audk.git
Reverted back to Old style not using the library and fixed the code to do PE32 and PE32+.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1109 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
236877a6a7
commit
ec412251c4
|
@ -133,33 +133,113 @@ Returns:
|
|||
//
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", Pe32Data, *EntryPoint));
|
||||
DEBUG_CODE_BEGIN ();
|
||||
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
|
||||
UINTN Index;
|
||||
CHAR8 *PdbStr;
|
||||
CHAR8 AsciiBuffer[512];
|
||||
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_OPTIONAL_HEADER_PTR_UNION Hdr;
|
||||
UINT32 NumberOfRvaAndSizes;
|
||||
|
||||
|
||||
ZeroMem (&ImageContext, sizeof (ImageContext));
|
||||
ImageContext.Handle = Pe32Data;
|
||||
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
||||
|
||||
PeCoffLoaderGetImageInfo (&ImageContext);
|
||||
|
||||
if (ImageContext.PdbPointer != NULL) {
|
||||
DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
|
||||
if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
|
||||
//
|
||||
// Copy PDB pointer to AsciiBuffer and replace .PDB with .EFI
|
||||
// DOS image header is present, so read the PE header after the DOS image header
|
||||
//
|
||||
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));
|
||||
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHeader->e_lfanew) & 0x0ffff));
|
||||
} else {
|
||||
//
|
||||
// DOS image header is not present, so PE header is at the image base
|
||||
//
|
||||
Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)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 (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
|
||||
//
|
||||
// Use PE32 offset
|
||||
//
|
||||
NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
|
||||
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
||||
} else {
|
||||
//
|
||||
// Use PE32+ offset
|
||||
//
|
||||
NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
|
||||
DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
|
||||
}
|
||||
|
||||
if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
|
||||
DirectoryEntry = NULL;
|
||||
DebugEntry = NULL;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
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 < sizeof (AsciiString)); 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_CODE_END ();
|
||||
|
||||
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));
|
||||
|
|
Loading…
Reference in New Issue