summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BasePeCoffLib
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2008-09-18 14:27:39 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2008-09-18 14:27:39 +0000
commit2bfb60098f608dc32ff5d22b0fd087c1636b0881 (patch)
tree8ed7f5c784caa4bc38690e0adef5504a1cf070ea /MdePkg/Library/BasePeCoffLib
parent66df25318672baf41db5b2d640020e61cca97a35 (diff)
downloadedk2-platforms-2bfb60098f608dc32ff5d22b0fd087c1636b0881.tar.xz
1. Change 0 == Length style to Length == 0
2. Clean BasePeCoff library instance, only keep one copy PeCoffLoaderEx.c file for IA32, X64 and IPF arch 3. Clean the confused comments git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5927 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/BasePeCoffLib')
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c39
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf16
-rw-r--r--MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c90
-rw-r--r--MdePkg/Library/BasePeCoffLib/PeCoffLoaderEx.c (renamed from MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c)4
-rw-r--r--MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c90
5 files changed, 26 insertions, 213 deletions
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index ea45ff745d..f975754516 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1,10 +1,8 @@
/** @file
- Tiano PE/COFF loader.
-
- This PE/COFF loader supports loading any PE32 or PE32+ image type, but
+ Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but
only supports relocating IA32, X64, IPF, and EBC images.
- Copyright (c) 2006, Intel Corporation
+ Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
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
@@ -15,9 +13,6 @@
**/
-
-
-
#include "BasePeCoffLibInternals.h"
/**
@@ -120,8 +115,12 @@ PeCoffLoaderGetPeHeader (
ImageContext->IsTeImage = TRUE;
ImageContext->Machine = Hdr.Te->Machine;
ImageContext->ImageType = (UINT16)(Hdr.Te->Subsystem);
+ //
+ // For TeImage, SectionAlignment is undefined to be set to Zero
+ // ImageSize can be calculated.
+ //
ImageContext->ImageSize = 0;
- ImageContext->SectionAlignment = 4096;
+ ImageContext->SectionAlignment = 0;
ImageContext->SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
@@ -173,9 +172,9 @@ PeCoffLoaderGetPeHeader (
/**
Retrieves information about a PE/COFF image.
- Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
- PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
- fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, RelocationsStripped,
+ SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva fields of the ImageContext structure.
+ If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
computing the fields of ImageContext, then the error status is returned in the ImageError field of
@@ -209,7 +208,7 @@ PeCoffLoaderGetImageInfo (
UINT32 NumberOfRvaAndSizes;
UINT16 Magic;
- if (NULL == ImageContext) {
+ if (ImageContext == NULL) {
return RETURN_INVALID_PARAMETER;
}
//
@@ -412,11 +411,10 @@ PeCoffLoaderGetImageInfo (
// section headers in the Section Table must appear in order of the RVA
// values for the corresponding sections. So the ImageSize can be determined
// by the RVA and the VirtualSize of the last section header in the
- // Section Table.
+ // Section Table.
//
if ((++Index) == (UINTN)Hdr.Te->NumberOfSections) {
- ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize +
- ImageContext->SectionAlignment - 1) & ~(ImageContext->SectionAlignment - 1);
+ ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize);
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
@@ -908,7 +906,7 @@ PeCoffLoaderLoadImage (
Size = (UINTN) Section->SizeOfRawData;
}
- if (Section->SizeOfRawData) {
+ if (Section->SizeOfRawData > 0) {
if (!(ImageContext->IsTeImage)) {
Status = ImageContext->ImageRead (
ImageContext->Handle,
@@ -1213,12 +1211,15 @@ PeCoffLoaderRelocateImageForRuntime (
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress + RelocDir->Size);
} else {
//
- // Cannot find relocations, cannot continue
+ // Cannot find relocations, cannot continue to relocate the image, ASSERT for this invalid image.
//
ASSERT (FALSE);
return ;
}
-
+
+ //
+ // ASSERT for the invalid image when RelocBase and RelocBaseEnd are both NULL.
+ //
ASSERT (RelocBase != NULL && RelocBaseEnd != NULL);
//
@@ -1286,7 +1287,7 @@ PeCoffLoaderRelocateImageForRuntime (
case EFI_IMAGE_REL_BASED_HIGHADJ:
//
- // Not implemented, but not used in UEFI 2.0
+ // Not valid Relocation type for UEFI image, ASSERT
//
ASSERT (FALSE);
break;
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
index e681f0ebd6..f5272aad5c 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
@@ -1,8 +1,8 @@
#/** @file
# Component description file for Base PE/COFF Library
#
-# PE/COFF Loader Library implementation.
-# Copyright (c) 2006, Intel Corporation.
+# Base PE/COFF Loader Library implementation.
+# Copyright (c) 2006 - 2008, Intel Corporation.
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -33,23 +33,15 @@
BasePeCoffLibInternals.h
BasePeCoff.c
-[Sources.Ia32]
- Ia32/PeCoffLoaderEx.c
-
-[Sources.X64]
- x64/PeCoffLoaderEx.c
+[Sources.Ia32, Sources.X64, Sources.EBC]
+ PeCoffLoaderEx.c
[Sources.IPF]
Ipf/PeCoffLoaderEx.c
-[Sources.EBC]
- Ebc/PeCoffLoaderEx.c
-
-
[Packages]
MdePkg/MdePkg.dec
-
[LibraryClasses]
DebugLib
BaseMemoryLib
diff --git a/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c
deleted file mode 100644
index b9ac46b0d6..0000000000
--- a/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/** @file
- EBC Specific relocation fixups.
-
- Copyright (c) 2006, Intel Corporation
- All rights reserved. This program and the accompanying materials
- 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
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "BasePeCoffLibInternals.h"
-
-/**
- Performs an EBC specific relocation fixup.
-
- @param Reloc Pointer to the relocation record.
- @param Fixup Pointer to the address to fix up.
- @param FixupData Pointer to a buffer to log the fixups.
- @param Adjust The offset to adjust the fixup.
-
- @retval EFI_UNSUPPORTED Unsupported now.
-
-**/
-RETURN_STATUS
-PeCoffLoaderRelocateImageEx (
- IN UINT16 *Reloc,
- IN OUT CHAR8 *Fixup,
- IN OUT CHAR8 **FixupData,
- IN UINT64 Adjust
- )
-{
- return RETURN_UNSUPPORTED;
-}
-
-/**
- Returns TRUE if the machine type of PE/COFF image is supported. Supported
- does not mean the image can be executed it means the PE/COFF loader supports
- loading and relocating of the image type. It's up to the caller to support
- the entry point.
-
- This function implies the basic PE/COFF loader/relocator supports IA32, EBC,
- & X64 images. Calling the entry point in a correct mannor is up to the
- consumer of this library.
-
- @param Machine Machine type from the PE Header.
-
- @return TRUE if this PE/COFF loader can load the image
-
-**/
-BOOLEAN
-PeCoffLoaderImageFormatSupported (
- IN UINT16 Machine
- )
-{
- if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) ||
- (Machine == EFI_IMAGE_MACHINE_EBC)) {
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-/**
- Performs an Itanium-based specific re-relocation fixup and is a no-op on other
- instruction sets. This is used to re-relocated the image into the EFI virtual
- space for runtime calls.
-
- @param Reloc Pointer to the relocation record.
- @param Fixup Pointer to the address to fix up.
- @param FixupData Pointer to a buffer to log the fixups.
- @param Adjust The offset to adjust the fixup.
-
- @return Always return UNSUPPORTED.
-
-**/
-RETURN_STATUS
-PeHotRelocateImageEx (
- IN UINT16 *Reloc,
- IN OUT CHAR8 *Fixup,
- IN OUT CHAR8 **FixupData,
- IN UINT64 Adjust
- )
-{
- return RETURN_UNSUPPORTED;
-}
diff --git a/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/PeCoffLoaderEx.c
index ee118bfef8..987937b23f 100644
--- a/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c
+++ b/MdePkg/Library/BasePeCoffLib/PeCoffLoaderEx.c
@@ -1,7 +1,7 @@
/** @file
- IA-32 Specific relocation fixups.
+ Specific relocation fixups for none Itanium architecture.
- Copyright (c) 2006, Intel Corporation<BR>
+ Copyright (c) 2006 - 2008, Intel Corporation<BR>
All rights reserved. This program and the accompanying materials
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
diff --git a/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c
deleted file mode 100644
index 937d103d78..0000000000
--- a/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/** @file
- x64 Specific relocation fixups.
-
-Copyright (c) 2005 - 2006 Intel Corporation. <BR>
-All rights reserved. This program and the accompanying materials
-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
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "BasePeCoffLibInternals.h"
-
-/**
- Performs an x64 specific relocation fixup.
-
- @param Reloc Pointer to the relocation record
- @param Fixup Pointer to the address to fix up
- @param FixupData Pointer to a buffer to log the fixups
- @param Adjust The offset to adjust the fixup
-
- @retval RETURN_SUCCESS Success to perform relocation
- @retval RETURN_UNSUPPORTED Unsupported.
-**/
-RETURN_STATUS
-PeCoffLoaderRelocateImageEx (
- IN UINT16 *Reloc,
- IN OUT CHAR8 *Fixup,
- IN OUT CHAR8 **FixupData,
- IN UINT64 Adjust
- )
-{
- return RETURN_UNSUPPORTED;
-}
-
-/**
- Returns TRUE if the machine type of PE/COFF image is supported. Supported
- does not mean the image can be executed it means the PE/COFF loader supports
- loading and relocating of the image type. It's up to the caller to support
- the entry point.
-
- This function implies the basic PE/COFF loader/relocator supports IA32, EBC,
- & X64 images. Calling the entry point in a correct mannor is up to the
- consumer of this library.
-
- @param Machine Machine type from the PE Header.
-
- @return TRUE if this PE/COFF loader can load the image
-
-**/
-BOOLEAN
-PeCoffLoaderImageFormatSupported (
- IN UINT16 Machine
- )
-{
- if ((Machine == EFI_IMAGE_MACHINE_IA32) || (Machine == EFI_IMAGE_MACHINE_X64) ||
- (Machine == EFI_IMAGE_MACHINE_EBC)) {
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-/**
- Performs an X64 specific re-relocation fixup and is a no-op on other
- instruction sets. This is used to re-relocated the image into the EFI virtual
- space for runtime calls.
-
- @param Reloc Pointer to the relocation record.
- @param Fixup Pointer to the address to fix up.
- @param FixupData Pointer to a buffer to log the fixups.
- @param Adjust The offset to adjust the fixup.
-
- @return EFI_UNSUPPORTED.
-
-**/
-RETURN_STATUS
-PeHotRelocateImageEx (
- IN UINT16 *Reloc,
- IN OUT CHAR8 *Fixup,
- IN OUT CHAR8 **FixupData,
- IN UINT64 Adjust
- )
-{
- return RETURN_UNSUPPORTED;
-}