]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Adjust might be 64bit, so we need to typecast it to UINT32 firstly.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 06:35:47 +0000 (06:35 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Aug 2006 06:35:47 +0000 (06:35 +0000)
2. Synchronization modification described in Tracker EDKT182 to all dependent files.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1270 6f19259b-4bc3-4df7-8a09-765794883524

EdkModulePkg/Library/EdkPeCoffLoaderX64Lib/EdkPeCoffLoaderX64.c
MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Tools/Source/TianoTools/PeCoffLoader/BasePeCoff.c

index a2862576fa10e2784af1ffa555d729d1c0cefd41..6adc4bf29eefb89dca870cffc243709148f4d691 100644 (file)
@@ -536,7 +536,7 @@ Returns:
         break;\r
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16 = (UINT16 *) Fixup;\r
-        *F16 = (UINT16)((*F16 << 16) + (UINT16) Adjust);\r
+        *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         if (FixupData != NULL) {\r
           *(UINT16 *) FixupData = *F16;\r
           FixupData = FixupData + sizeof(UINT16);\r
index eee4dc713fe746684f080a2ae07eab64be272f9f..2ecd76eab47f9481372fee7197dedc3d8912d14d 100644 (file)
@@ -62,10 +62,10 @@ PeHotRelocateImageEx (
 \r
 \r
 /**\r
-  Returns TRUE if the machine type of PE/COFF image is supported. Supported \r
+  Returns TRUE if the machine type of PE/COFF image is supported. Supported\r
   does not mean the image can be executed it means the PE/COFF loader supports\r
   loading and relocating of the image type. It's up to the caller to support\r
-  the entry point. \r
+  the entry point.\r
 \r
   @param  Machine   Machine type from the PE Header.\r
 \r
@@ -117,16 +117,16 @@ PeCoffLoaderGetPeHeader (
   ImageContext->PeCoffHeaderOffset = 0;\r
   if (DosHdr.e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
     //\r
-    // DOS image header is present, so read the PE header after the DOS image \r
+    // DOS image header is present, so read the PE header after the DOS image\r
     // header\r
     //\r
     ImageContext->PeCoffHeaderOffset = DosHdr.e_lfanew;\r
   }\r
 \r
   //\r
-  // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much \r
+  // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much\r
   // data, but that should not hurt anythine. Hdr.Pe32->OptionalHeader.Magic\r
-  // determins if this is a PE32 or PE32+ image. The magic is in the same \r
+  // determins if this is a PE32 or PE32+ image. The magic is in the same\r
   // location in both images.\r
   //\r
   Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
@@ -155,7 +155,7 @@ PeCoffLoaderGetPeHeader (
   } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
     ImageContext->IsTeImage = FALSE;\r
     ImageContext->Machine = Hdr.Pe32->FileHeader.Machine;\r
-    \r
+\r
     if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
@@ -175,7 +175,7 @@ PeCoffLoaderGetPeHeader (
       ImageContext->SizeOfHeaders     = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders;\r
     } else {\r
       ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
-      return RETURN_UNSUPPORTED;    \r
+      return RETURN_UNSUPPORTED;\r
     }\r
   } else {\r
     ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE;\r
@@ -187,7 +187,7 @@ PeCoffLoaderGetPeHeader (
     // If the PE/COFF loader does not support the image type return\r
     // unsupported. This library can suport lots of types of images\r
     // this does not mean the user of this library can call the entry\r
-    // point of the image. \r
+    // point of the image.\r
     //\r
     return RETURN_UNSUPPORTED;\r
   }\r
@@ -205,7 +205,7 @@ PeCoffLoaderGetPeHeader (
   If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
   a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
   computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
-  ImageContext. \r
+  ImageContext.\r
 \r
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that needs to be examined by this function.\r
@@ -298,19 +298,19 @@ PeCoffLoaderGetImageInfo (
 \r
   if (!(ImageContext->IsTeImage)) {\r
     if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-      //     \r
+      //\r
       // Use PE32 offset\r
       //\r
       NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
       DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
     } else {\r
-      //     \r
+      //\r
       // Use PE32+ offset\r
       //\r
       NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
       DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-    }    \r
-    \r
+    }\r
+\r
     if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
 \r
       DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress;\r
@@ -324,8 +324,8 @@ PeCoffLoaderGetImageInfo (
 \r
       SectionHeaderOffset = (UINTN)(\r
                                ImageContext->PeCoffHeaderOffset +\r
-                               sizeof (UINT32) + \r
-                               sizeof (EFI_IMAGE_FILE_HEADER) + \r
+                               sizeof (UINT32) +\r
+                               sizeof (EFI_IMAGE_FILE_HEADER) +\r
                                Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
                                );\r
 \r
@@ -428,8 +428,8 @@ PeCoffLoaderGetImageInfo (
 \r
       //\r
       // In Te image header there is not a field to describe the ImageSize.\r
-      // Actually, the ImageSize equals the RVA plus the VirtualSize of \r
-      // the last section mapped into memory (Must be rounded up to \r
+      // Actually, the ImageSize equals the RVA plus the VirtualSize of\r
+      // the last section mapped into memory (Must be rounded up to\r
       // a mulitple of Section Alignment). Per the PE/COFF specification, the\r
       // section headers in the Section Table must appear in order of the RVA\r
       // values for the corresponding sections. So the ImageSize can be determined\r
@@ -489,7 +489,7 @@ PeCoffLoaderImageAddress (
   )\r
 {\r
   //\r
-  // @bug Check to make sure ImageSize is correct for the relocated image. \r
+  // @bug Check to make sure ImageSize is correct for the relocated image.\r
   //      it may only work for the file we start with and not the relocated image\r
   //\r
   if (Address >= ImageContext->ImageSize) {\r
@@ -506,7 +506,7 @@ PeCoffLoaderImageAddress (
   If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
   ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
   of ImageContext as the relocation base address.  The caller must allocate the relocation\r
-  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.\r
   If ImageContext is NULL, then ASSERT().\r
 \r
   @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
@@ -537,7 +537,7 @@ PeCoffLoaderRelocateImage (
   CHAR8                                 *Fixup;\r
   CHAR8                                 *FixupBase;\r
   UINT16                                *F16;\r
-  UINT32                                *F32;  \r
+  UINT32                                *F32;\r
   UINT64                                *F64;\r
   CHAR8                                 *FixupData;\r
   PHYSICAL_ADDRESS                      BaseAddress;\r
@@ -575,7 +575,7 @@ PeCoffLoaderRelocateImage (
       //\r
       Adjust = (UINT64)BaseAddress - Hdr.Pe32->OptionalHeader.ImageBase;\r
       Hdr.Pe32->OptionalHeader.ImageBase = (UINT32)BaseAddress;\r
-  \r
+\r
       NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
       RelocDir  = &Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
     } else {\r
@@ -618,14 +618,14 @@ PeCoffLoaderRelocateImage (
     //\r
     RelocDir = &Hdr.Te->DataDirectory[0];\r
     RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(\r
-                                    ImageContext->ImageAddress + \r
+                                    ImageContext->ImageAddress +\r
                                     RelocDir->VirtualAddress +\r
-                                    sizeof(EFI_TE_IMAGE_HEADER) - \r
+                                    sizeof(EFI_TE_IMAGE_HEADER) -\r
                                     Hdr.Te->StrippedSize\r
                                     );\r
     RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1);\r
   }\r
-  \r
+\r
   //\r
   // Run the relocation information and apply the fixups\r
   //\r
@@ -639,13 +639,13 @@ PeCoffLoaderRelocateImage (
     } else {\r
       FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
                     RelocBase->VirtualAddress +\r
-                    sizeof(EFI_TE_IMAGE_HEADER) - \r
+                    sizeof(EFI_TE_IMAGE_HEADER) -\r
                     Hdr.Te->StrippedSize\r
                     );\r
     }\r
 \r
     if ((CHAR8 *) RelocEnd < (CHAR8 *) ((UINTN) ImageContext->ImageAddress) ||\r
-        (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + \r
+        (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress +\r
           (UINTN)ImageContext->ImageSize)) {\r
       ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
       return RETURN_LOAD_ERROR;\r
@@ -663,7 +663,7 @@ PeCoffLoaderRelocateImage (
 \r
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16   = (UINT16 *) Fixup;\r
-        *F16  = (UINT16) ((*F16 << 16) + (UINT16) Adjust);\r
+        *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         if (FixupData != NULL) {\r
           *(UINT16 *) FixupData = *F16;\r
           FixupData             = FixupData + sizeof (UINT16);\r
@@ -852,8 +852,8 @@ PeCoffLoaderLoadImage (
     FirstSection = (EFI_IMAGE_SECTION_HEADER *) (\r
                       (UINTN)ImageContext->ImageAddress +\r
                       ImageContext->PeCoffHeaderOffset +\r
-                      sizeof(UINT32) + \r
-                      sizeof(EFI_IMAGE_FILE_HEADER) + \r
+                      sizeof(UINT32) +\r
+                      sizeof(EFI_IMAGE_FILE_HEADER) +\r
                       Hdr.Pe32->FileHeader.SizeOfOptionalHeader\r
       );\r
     NumberOfSections = (UINTN) (Hdr.Pe32->FileHeader.NumberOfSections);\r
@@ -965,7 +965,7 @@ PeCoffLoaderLoadImage (
     if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
       //\r
       // Use PE32 offset\r
-      //      \r
+      //\r
       ImageContext->EntryPoint = (PHYSICAL_ADDRESS)(UINTN)PeCoffLoaderImageAddress (\r
                                                             ImageContext,\r
                                                             (UINTN)Hdr.Pe32->OptionalHeader.AddressOfEntryPoint\r
@@ -1009,7 +1009,7 @@ PeCoffLoaderLoadImage (
       NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
       DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC];\r
     }\r
\r
+\r
     if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
       ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN);\r
     } else {\r
@@ -1124,8 +1124,8 @@ PeCoffLoaderLoadImage (
 \r
 /**\r
   Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
-  runtime. \r
-  \r
+  runtime.\r
+\r
   PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
   the fixups with a virtual mapping.\r
 \r
@@ -1134,7 +1134,7 @@ PeCoffLoaderLoadImage (
   @param  VirtImageBase      Virtual mapping for ImageBase\r
   @param  ImageSize          Size of the image to relocate\r
   @param  RelocationData     Location to place results of read\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1196,18 +1196,18 @@ PeCoffLoaderRelocateImageForRuntime (
   // Get some data from the PE type dependent data\r
   //\r
   if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-    //     \r
+    //\r
     // Use PE32 offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
     DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[0]);\r
   } else {\r
-    //     \r
+    //\r
     // Use PE32+ offset\r
     //\r
     NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
     DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[0]);\r
-  }    \r
+  }\r
 \r
   //\r
   // Find the relocation block\r
@@ -1215,7 +1215,7 @@ PeCoffLoaderRelocateImageForRuntime (
   // Per the PE/COFF spec, you can't assume that a given data directory\r
   // is present in the image. You have to check the NumberOfRvaAndSizes in\r
   // the optional header to verify a desired directory entry is there.\r
-  //    \r
+  //\r
   if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
     RelocDir      = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC;\r
     RelocBase     = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress);\r
@@ -1258,7 +1258,7 @@ PeCoffLoaderRelocateImageForRuntime (
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16 = (UINT16 *) Fixup;\r
         if (*(UINT16 *) FixupData == *F16) {\r
-          *F16 = (UINT16) (*F16 + ((UINT16)(Adjust >> 16)));\r
+          *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         }\r
 \r
         FixupData = FixupData + sizeof (UINT16);\r
@@ -1324,14 +1324,14 @@ PeCoffLoaderRelocateImageForRuntime (
 \r
 /**\r
   ImageRead function that operates on a memory buffer whos base is passed into\r
-  FileHandle. \r
+  FileHandle.\r
 \r
   @param  FileHandle        Ponter to baes of the input stream\r
   @param  FileOffset        Offset to the start of the buffer\r
   @param  ReadSize          Number of bytes to copy into the buffer\r
   @param  Buffer            Location to place results of read\r
 \r
-  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into\r
                             the buffer.\r
 **/\r
 RETURN_STATUS\r
index b90d7625f0c34f894f29ef371beab1fceb6b19c1..9c25e1f4b8f1162f7b60ae5b85efb606eed657b9 100644 (file)
@@ -643,7 +643,7 @@ Returns:
 \r
       case EFI_IMAGE_REL_BASED_HIGH:\r
         F16   = (UINT16 *) Fixup;\r
-        *F16  = (UINT16) ((*F16 << 16) + (UINT16) Adjust);\r
+        *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16)));\r
         if (FixupData != NULL) {\r
           *(UINT16 *) FixupData = *F16;\r
           FixupData             = FixupData + sizeof (UINT16);\r