]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add HiiResourceData field to PeCoffLib library class. PeCoffLoaderLoadImage () will...
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 22 Apr 2009 02:04:16 +0000 (02:04 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 22 Apr 2009 02:04:16 +0000 (02:04 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8141 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/Library/PeCoffLib.h
MdePkg/Library/BasePeCoffLib/BasePeCoff.c

index c02e75169e8ecfbcf16af5a70e54b315462fbcea..9dab2e453a4ba55cd566b9b370a2a6cb391e5321 100644 (file)
@@ -185,6 +185,12 @@ typedef struct {
   /// Initialization Core Interface Specification.\r
   ///\r
   BOOLEAN                           IsTeImage;\r
+  ///\r
+  /// Set by PeCoffLoaderLoadImage() to the HII resource offset\r
+  /// if the image contains a custom PE/COFF resource with the type 'HII';\r
+  /// otherwise, the entry remains to be 0.\r
+  ///\r
+  PHYSICAL_ADDRESS                  HiiResourceData;\r
 } PE_COFF_LOADER_IMAGE_CONTEXT;\r
 \r
 /**\r
@@ -254,7 +260,7 @@ PeCoffLoaderRelocateImage (
   Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
   specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
   the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
-  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed.\r
   The ImageRead, Handle, PeCoffHeaderOffset,  IsTeImage,  Machine, ImageType, ImageAddress, ImageSize, \r
   DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva \r
   fields of the ImageContext structure must be valid prior to invoking this service.\r
index 9274f31aa22d15b0b1351bc9356be0e8c940b830..3ecc015eaca271148efb1f85be6afeb2344a3950 100644 (file)
@@ -92,8 +92,8 @@ PeCoffLoaderGetPeHeader (
 \r
   //\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
+  // data, but that should not hurt anything. Hdr.Pe32->OptionalHeader.Magic\r
+  // determines 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
@@ -158,7 +158,7 @@ PeCoffLoaderGetPeHeader (
   if (!PeCoffLoaderImageFormatSupported (ImageContext->Machine)) {\r
     //\r
     // If the PE/COFF loader does not support the image type return\r
-    // unsupported. This library can suport lots of types of images\r
+    // unsupported. This library can support 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
     //\r
@@ -411,7 +411,7 @@ PeCoffLoaderGetImageInfo (
       // 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
-      // a mulitple of Section Alignment). Per the PE/COFF specification, the\r
+      // a multiple 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
       // by the RVA and the VirtualSize of the last section header in the\r
@@ -540,9 +540,9 @@ PeCoffLoaderRelocateImage (
   // If there are no relocation entries, then we are done\r
   //\r
   if (ImageContext->RelocationsStripped) {\r
-       // Applies additional environment specific actions to relocate fixups \r
-       // to a PE/COFF image if needed\r
-       PeCoffLoaderRelocateImageExtraAction (ImageContext);    \r
+    // Applies additional environment specific actions to relocate fixups \r
+    // to a PE/COFF image if needed\r
+    PeCoffLoaderRelocateImageExtraAction (ImageContext);       \r
     return RETURN_SUCCESS;\r
   }\r
 \r
@@ -710,8 +710,8 @@ PeCoffLoaderRelocateImage (
       default:\r
         //\r
         // The common code does not handle some of the stranger IPF relocations\r
-        // PeCoffLoaderRelocateImageEx () addes support for these complex fixups\r
-        // on IPF and is a No-Op on other archtiectures.\r
+        // PeCoffLoaderRelocateImageEx () adds support for these complex fixups\r
+        // on IPF and is a No-Op on other architectures.\r
         //\r
         Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust);\r
         if (RETURN_ERROR (Status)) {\r
@@ -753,7 +753,7 @@ PeCoffLoaderRelocateImage (
   Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
   specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
   the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
-  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  The EntryPoint, FixupDataSize, CodeView, PdbPointer and HiiResourceData fields of ImageContext are computed.\r
   The ImageRead, Handle, PeCoffHeaderOffset,  IsTeImage,  Machine, ImageType, ImageAddress, ImageSize, \r
   DestinationAddress, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva \r
   fields of the ImageContext structure must be valid prior to invoking this service.\r
@@ -796,6 +796,11 @@ PeCoffLoaderLoadImage (
   UINT32                                TempDebugEntryRva;\r
   UINT32                                NumberOfRvaAndSizes;\r
   UINT16                                Magic;\r
+  EFI_IMAGE_RESOURCE_DIRECTORY          *ResourceDirectory;\r
+  EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;\r
+  EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;\r
+  EFI_IMAGE_RESOURCE_DATA_ENTRY         *ResourceDataEntry;\r
+\r
 \r
   ASSERT (ImageContext != NULL);\r
 \r
@@ -968,7 +973,7 @@ PeCoffLoaderLoadImage (
     }\r
 \r
     //\r
-    // If raw size is less then virt size, zero fill the remaining\r
+    // If raw size is less then virtual size, zero fill the remaining\r
     //\r
 \r
     if (Size < Section->Misc.VirtualSize) {\r
@@ -1145,6 +1150,72 @@ PeCoffLoaderLoadImage (
     }\r
   }\r
 \r
+  //\r
+  // Get Image's HII resource section\r
+  //\r
+  ImageContext->HiiResourceData = 0;\r
+  if (!(ImageContext->IsTeImage)) {\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
+      // Use PE32 offset\r
+      //\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE];\r
+    } else {\r
+      //\r
+      // Use PE32+ offset\r
+      //\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_RESOURCE];\r
+    }\r
+\r
+    if (DirectoryEntry->Size != 0) {\r
+      Base = PeCoffLoaderImageAddress (ImageContext, DirectoryEntry->VirtualAddress);\r
+\r
+      ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) Base;\r
+      ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);\r
+\r
+      for (Index = 0; Index < ResourceDirectory->NumberOfNamedEntries; Index++) {\r
+        if (ResourceDirectoryEntry->u1.s.NameIsString) {\r
+          ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);\r
+\r
+          if (ResourceDirectoryString->Length == 3 &&\r
+              ResourceDirectoryString->String[0] == L'H' &&\r
+              ResourceDirectoryString->String[1] == L'I' &&\r
+              ResourceDirectoryString->String[2] == L'I') {\r
+            //\r
+            // Resource Type "HII" found\r
+            //\r
+            if (ResourceDirectoryEntry->u2.s.DataIsDirectory) {\r
+              //\r
+              // Move to next level - resource Name\r
+              //\r
+              ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);\r
+              ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);\r
+\r
+              if (ResourceDirectoryEntry->u2.s.DataIsDirectory) {\r
+                //\r
+                // Move to next level - resource Language\r
+                //\r
+                ResourceDirectory = (EFI_IMAGE_RESOURCE_DIRECTORY *) (Base + ResourceDirectoryEntry->u2.s.OffsetToDirectory);\r
+                ResourceDirectoryEntry = (EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY *) (ResourceDirectory + 1);\r
+              }\r
+            }\r
+\r
+            //\r
+            // Now it ought to be resource Data\r
+            //\r
+            if (!ResourceDirectoryEntry->u2.s.DataIsDirectory) {\r
+              ResourceDataEntry = (EFI_IMAGE_RESOURCE_DATA_ENTRY *) (Base + ResourceDirectoryEntry->u2.OffsetToData);\r
+              ImageContext->HiiResourceData = (PHYSICAL_ADDRESS) (UINTN) PeCoffLoaderImageAddress (ImageContext, ResourceDataEntry->OffsetToData);\r
+              break;\r
+            }\r
+          }\r
+        }\r
+\r
+        ResourceDirectoryEntry++;\r
+      }\r
+    }\r
+  }\r
\r
   return Status;\r
 }\r
 \r
@@ -1419,8 +1490,10 @@ PeCoffLoaderUnloadImage (
   IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
   )\r
 {\r
+  //\r
   // Applies additional environment specific actions to unload a \r
   // PE/COFF image if needed\r
+  //\r
   PeCoffLoaderUnloadImageExtraAction (ImageContext);\r
   return RETURN_SUCCESS;\r
 }\r