From 2ce311322c72857f73138c45358e722607a1e80c Mon Sep 17 00:00:00 2001 From: ajfish Date: Wed, 26 Jul 2006 15:23:35 +0000 Subject: Removed cross references from PciCf8Lib and PciExpressLib class to PciLib class. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c | 8 +- EdkModulePkg/Core/Dxe/Image/Image.c | 36 ++++---- EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 12 +-- EdkModulePkg/Core/Pei/Hob/Hob.c | 4 +- EdkModulePkg/Core/Pei/Image/Image.c | 119 ++++++-------------------- EdkModulePkg/Core/Pei/Memory/MemoryServices.c | 8 +- EdkModulePkg/Core/Pei/PeiMain.msa | 15 ++-- EdkModulePkg/Core/Pei/PeiMain/PeiMain.c | 6 +- 8 files changed, 67 insertions(+), 141 deletions(-) (limited to 'EdkModulePkg/Core') diff --git a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c index 24568ea334..9f5f2f1510 100644 --- a/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c +++ b/EdkModulePkg/Core/Dxe/DxeMain/DxeMain.c @@ -557,9 +557,9 @@ Returns: // // Display Architectural protocols that were not loaded if this is DEBUG build // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); CoreDisplayMissingArchProtocols (); - ); + DEBUG_CODE_END (); // // Assert if the Architectural Protocols are not present. @@ -574,9 +574,9 @@ Returns: // Display any drivers that were not dispatched because dependency expression // evaluated to false if this is a debug build // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); CoreDisplayDiscoveredNotDispatched (); - ); + DEBUG_CODE_END (); // // Transfer control to the BDS Architectural Protocol diff --git a/EdkModulePkg/Core/Dxe/Image/Image.c b/EdkModulePkg/Core/Dxe/Image/Image.c index c818cc2131..d77f4c4fca 100644 --- a/EdkModulePkg/Core/Dxe/Image/Image.c +++ b/EdkModulePkg/Core/Dxe/Image/Image.c @@ -268,6 +268,15 @@ Returns: return Status; } + if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) { + // + // The PE/COFF loader can support loading image types that can be executed. + // If we loaded an image type that we can not execute return EFI_UNSUPORTED. + // + return EFI_UNSUPPORTED; + } + + // // Allocate memory of the correct memory type aligned on the required image boundry // @@ -440,8 +449,8 @@ Returns: // Print the load address and the PDB file name if it is available // - DEBUG_CODE ( - { + DEBUG_CODE_BEGIN (); + UINTN Index; UINTN StartIndex; CHAR8 EfiFileName[256]; @@ -473,8 +482,8 @@ Returns: DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex])); } DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n")); - } - ); + + DEBUG_CODE_END (); return EFI_SUCCESS; @@ -924,22 +933,13 @@ Returns: // PERF_START (ImageHandle, START_IMAGE_TOK, NULL, 0); - if (sizeof (UINTN) == 4 && Image->Machine == EFI_IMAGE_MACHINE_X64) { - return EFI_UNSUPPORTED; - } else if (sizeof (UINTN) == 8 && Image->Machine == EFI_IMAGE_MACHINE_IA32) { - return EFI_UNSUPPORTED; - } else { - // - // For orther possible cases - // - } // // Push the current start image context, and // link the current image to the head. This is the // only image that can call Exit() // - HandleDatabaseKey = CoreGetHandleDatabaseKey(); + HandleDatabaseKey = CoreGetHandleDatabaseKey (); LastImage = mCurrentImage; mCurrentImage = Image; Image->Tpl = gEfiCurrentTpl; @@ -970,11 +970,11 @@ Returns: // This make the user aware and check if the driver image have already released // all the resource in this situation. // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); if (EFI_ERROR (Image->Status)) { DEBUG ((EFI_D_ERROR, "Error: Image at %08X start failed: %x\n", Image->Info.ImageBase, Image->Status)); } - ); + DEBUG_CODE_END (); // // If the image returns, exit it through Exit() @@ -1003,7 +1003,7 @@ Returns: // // Handle the image's returned ExitData // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); if (Image->ExitDataSize != 0 || Image->ExitData != NULL) { DEBUG ( @@ -1017,7 +1017,7 @@ Returns: } DEBUG ((EFI_D_LOAD, "\n")); } - ); + DEBUG_CODE_END (); // // Return the exit data to the caller diff --git a/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 1eb5a4a020..6d32368fb7 100644 --- a/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -105,7 +105,7 @@ Returns: // if (Status == EFI_SUCCESS) { - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); // // Fill list of found Peims for later list of those not installed @@ -116,7 +116,7 @@ Returns: sizeof (EFI_GUID) ); - ); + DEBUG_CODE_END (); if (!Dispatched ( DispatchData->CurrentPeim, @@ -320,7 +320,7 @@ Returns: DispatchData->CurrentFvAddress = DefaultFvAddress; } - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); // // Debug data for uninstalled Peim list // @@ -345,10 +345,10 @@ Returns: DebugFoundPeimPoint++; DebugNotDispatchedBitmap >>= 1; } + + DEBUG_CODE_END (); - ); - - return EFI_NOT_FOUND; + return EFI_NOT_FOUND; } VOID diff --git a/EdkModulePkg/Core/Pei/Hob/Hob.c b/EdkModulePkg/Core/Pei/Hob/Hob.c index 1eadf9458c..259d44b457 100644 --- a/EdkModulePkg/Core/Pei/Hob/Hob.c +++ b/EdkModulePkg/Core/Pei/Hob/Hob.c @@ -53,11 +53,11 @@ Returns: // Only check this parameter in debug mode // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); if (HobList == NULL) { return EFI_INVALID_PARAMETER; } - ); + DEBUG_CODE_END (); PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices); 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 + + 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")); diff --git a/EdkModulePkg/Core/Pei/Memory/MemoryServices.c b/EdkModulePkg/Core/Pei/Memory/MemoryServices.c index 3da3e53185..d49b7427b4 100644 --- a/EdkModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/EdkModulePkg/Core/Pei/Memory/MemoryServices.c @@ -65,10 +65,10 @@ Returns: SizeOfCarHeap = (UINT64) PeiStartupDescriptor->SizeOfCacheAsRam; SizeOfCarHeap = RShiftU64 (SizeOfCarHeap, 1); - DEBUG_CODE ( - PrivateData->SizeOfCacheAsRam = PeiStartupDescriptor->SizeOfCacheAsRam; - PrivateData->MaxTopOfCarHeap = (VOID *) ((UINTN) PrivateData->BottomOfCarHeap + (UINTN) SizeOfCarHeap); - ); + DEBUG_CODE_BEGIN (); + PrivateData->SizeOfCacheAsRam = PeiStartupDescriptor->SizeOfCacheAsRam; + PrivateData->MaxTopOfCarHeap = (VOID *) ((UINTN) PrivateData->BottomOfCarHeap + (UINTN) SizeOfCarHeap); + DEBUG_CODE_END (); PrivateData->HobList.Raw = PrivateData->BottomOfCarHeap; diff --git a/EdkModulePkg/Core/Pei/PeiMain.msa b/EdkModulePkg/Core/Pei/PeiMain.msa index 18ec53d665..549820ef87 100644 --- a/EdkModulePkg/Core/Pei/PeiMain.msa +++ b/EdkModulePkg/Core/Pei/PeiMain.msa @@ -1,13 +1,5 @@ - - - + + PeiMain PEI_CORE @@ -60,6 +52,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.--> TimerLib + + PeCoffLib + PeiMain.h diff --git a/EdkModulePkg/Core/Pei/PeiMain/PeiMain.c b/EdkModulePkg/Core/Pei/PeiMain/PeiMain.c index b6d57f96d5..c94331c010 100644 --- a/EdkModulePkg/Core/Pei/PeiMain/PeiMain.c +++ b/EdkModulePkg/Core/Pei/PeiMain/PeiMain.c @@ -150,10 +150,10 @@ Returns: // // 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 - // DEBUG_CODE macro is used to prevent this code from being compiled + // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled // on a debug build. // - DEBUG_CODE ( + DEBUG_CODE_BEGIN (); UINTN *StackPointer; UINTN StackValue; @@ -173,7 +173,7 @@ Returns: ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom - (UINTN) OldCoreData->HobList.Raw) )); - ); + DEBUG_CODE_END (); // // Alert any listeners that there is permanent memory available -- cgit v1.2.3