]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/BasePeCoff.c
1) Update PE/COFF file alignment to 4KB to match 4KB section alignment.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoff.c
index 3ecc015eaca271148efb1f85be6afeb2344a3950..5be6e9037979c4df871305f99f970ca751190eb6 100644 (file)
@@ -2,7 +2,8 @@
   Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but\r
   only supports relocating IA32, x64, IPF, and EBC images.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation\r
+  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
+  Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -67,7 +68,7 @@ PeCoffLoaderGetPeHeader (
   UINT16                Magic;\r
 \r
   //\r
-  // Read the DOS image header to check for it's existance\r
+  // Read the DOS image header to check for its existence\r
   //\r
   Size = sizeof (EFI_IMAGE_DOS_HEADER);\r
   Status = ImageContext->ImageRead (\r
@@ -254,10 +255,11 @@ PeCoffLoaderGetImageInfo (
   ImageContext->DestinationAddress = 0;\r
 \r
   //\r
-  // Initialize the codeview pointer.\r
+  // Initialize the debug codeview pointer.\r
   //\r
-  ImageContext->CodeView    = NULL;\r
-  ImageContext->PdbPointer  = NULL;\r
+  ImageContext->DebugDirectoryEntryRva = 0;\r
+  ImageContext->CodeView               = NULL;\r
+  ImageContext->PdbPointer             = NULL;\r
 \r
   //\r
   // Three cases with regards to relocations:\r
@@ -494,6 +496,10 @@ PeCoffLoaderImageAddress (
     \r
   If ImageContext is NULL, then ASSERT().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
                               image that is being relocated.\r
 \r
@@ -542,7 +548,7 @@ PeCoffLoaderRelocateImage (
   if (ImageContext->RelocationsStripped) {\r
     // Applies additional environment specific actions to relocate fixups \r
     // to a PE/COFF image if needed\r
-    PeCoffLoaderRelocateImageExtraAction (ImageContext);       \r
+    PeCoffLoaderRelocateImageExtraAction (ImageContext);  \r
     return RETURN_SUCCESS;\r
   }\r
 \r
@@ -760,6 +766,10 @@ PeCoffLoaderRelocateImage (
   \r
   If ImageContext is NULL, then ASSERT().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
                                     image that is being loaded.\r
 \r
@@ -1143,6 +1153,10 @@ PeCoffLoaderLoadImage (
           ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
           break;\r
 \r
+        case CODEVIEW_SIGNATURE_MTOC:\r
+          ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY);\r
+          break;\r
+\r
         default:\r
           break;\r
         }\r
@@ -1169,49 +1183,49 @@ PeCoffLoaderLoadImage (
 \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
+      if (Base != NULL) {\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
-              // Move to next level - resource Name\r
+              // Resource Type "HII" found\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
+                // 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
-            //\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
+              // 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
+          ResourceDirectoryEntry++;\r
         }\r
-\r
-        ResourceDirectoryEntry++;\r
       }\r
     }\r
   }\r
@@ -1230,6 +1244,10 @@ PeCoffLoaderLoadImage (
   to the FiuxupData buffer from the PE_COFF_LOADER_IMAGE_CONTEXT structure \r
   after this PE/COFF image was relocated with PeCoffLoaderRelocateImage().\r
 \r
+  Note that if the platform does not maintain coherency between the instruction cache(s) and the data\r
+  cache(s) in hardware, then the caller is responsible for performing cache maintenance operations\r
+  prior to transferring control to a PE/COFF image that is loaded using this library.\r
+\r
   @param  ImageBase          Base address of a PE/COFF image that has been loaded \r
                              and relocated into system memory.\r
   @param  VirtImageBase      The request virtual address that the PE/COFF image is to\r