]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Replace PeCoffLoader library by PeCoff lib for PeiCore, DxeIpl and DxeMain.
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 28 Sep 2007 08:14:30 +0000 (08:14 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 28 Sep 2007 08:14:30 +0000 (08:14 +0000)
2. Add three PeCoff library instances for NT32 PeImage load.
3. Update PeCoffGetEntryPointLib to support TeImage.

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

21 files changed:
MdeModulePkg/Core/Dxe/DxeMain.h
MdeModulePkg/Core/Dxe/DxeMain.inf
MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
MdeModulePkg/Core/Dxe/Image/Image.c
MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
MdeModulePkg/Core/DxeIplPeim/DxeLoad.c
MdeModulePkg/Core/Pei/Image/Image.c
MdeModulePkg/Core/Pei/PeiMain.h
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/MdeModulePkg.dsc
MdePkg/Include/Library/PeCoffLib.h
MdePkg/Library/BasePeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c [new file with mode: 0644]
Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf [new file with mode: 0644]
Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c [new file with mode: 0644]
Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf [new file with mode: 0644]
Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c [new file with mode: 0644]
Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf [new file with mode: 0644]
Nt32Pkg/Nt32Pkg.dsc

index c5c4f34c49602a9aa05fdad57749f421c221fbb7..ed531f7bcc6b060c6a17844643751e0085416406 100644 (file)
@@ -82,6 +82,7 @@ Revision History
 #include <Library/PeCoffLoaderLib.h>\r
 #include <Library/CacheMaintenanceLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/PeCoffLib.h>\r
 \r
 #include "DebugImageInfo.h"\r
 #include "Library.h"\r
index 3b8519b6dbfe4e3f7fdd3954f3a6fd6525ccb9fa..9d6ecd0fba468c315176d3d1619327e253521aca 100644 (file)
@@ -78,7 +78,6 @@
 [LibraryClasses]\r
   BaseMemoryLib\r
   CacheMaintenanceLib\r
-  PeCoffLoaderLib\r
   UefiDecompressLib\r
   CustomDecompressLib\r
   PerformanceLib\r
@@ -87,6 +86,7 @@
   UefiLib\r
   DebugLib\r
   DxeCoreEntryPoint\r
+  PeCoffLib\r
 \r
 [Guids]\r
   gEfiEventLegacyBootGuid                       # ALWAYS_CONSUMED\r
index 26bc94c13ffd4fee2e22ae78145d81fe575b4b0f..53f1d5f594c0c2a4f58175eb56d802a8af1ecdbe 100644 (file)
@@ -25,7 +25,6 @@ Abstract:
 // DXE Core Global Variables for Protocols from PEI\r
 //\r
 EFI_HANDLE                                mDecompressHandle = NULL;\r
-EFI_PEI_PE_COFF_LOADER_PROTOCOL           *gEfiPeiPeCoffLoader          = NULL;\r
 \r
 //\r
 // DXE Core globals for Architecture Protocols\r
@@ -370,9 +369,6 @@ Returns:
               );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  gEfiPeiPeCoffLoader = GetPeCoffLoaderProtocol ();\r
-  ASSERT (gEfiPeiPeCoffLoader != NULL);\r
-\r
   //\r
   // Register for the GUIDs of the Architectural Protocols, so the rest of the\r
   // EFI Boot Services and EFI Runtime Services tables can be filled in.\r
index e227f3a6bfc961bd22822221954484fb28cfdae6..9232cabcef78cf5d21ae1d7ead4f43ad072643a9 100644 (file)
@@ -213,7 +213,7 @@ Returns:
   //\r
   // Get information about the image being loaded\r
   //\r
-  Status = gEfiPeiPeCoffLoader->GetImageInfo (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderGetImageInfo (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -305,7 +305,7 @@ Returns:
   //\r
   // Load the image from the file into the allocated memory\r
   //\r
-  Status = gEfiPeiPeCoffLoader->LoadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderLoadImage (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -328,7 +328,7 @@ Returns:
   //\r
   // Relocate the image in memory\r
   //\r
-  Status = gEfiPeiPeCoffLoader->RelocateImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  Status = PeCoffLoaderRelocateImage (&Image->ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
@@ -1085,7 +1085,7 @@ Returns:
   //\r
   // Unload image, free Image->ImageContext->ModHandle\r
   //\r
-  gEfiPeiPeCoffLoader->UnloadImage (gEfiPeiPeCoffLoader, &Image->ImageContext);\r
+  PeCoffLoaderUnloadImage (&Image->ImageContext);\r
 \r
   //\r
   // Free our references to the image handle\r
index 3267a8cba0d1cd92fd55e9532f746282528bb0c0..8115a4a31033dd498ae9cd0aba09e5ec79b87092 100644 (file)
@@ -67,7 +67,6 @@
   PeiServicesTablePointerLib\r
   CustomDecompressLib\r
   UefiDecompressLib\r
-  PeCoffLoaderLib\r
   CacheMaintenanceLib\r
   ReportStatusCodeLib\r
   PeiServicesLib\r
@@ -90,7 +89,6 @@
   gEfiPeiSectionExtractionPpiGuid               # PPI SOMETIMES_CONSUMED\r
   gEfiEndOfPeiSignalPpiGuid                     # PPI SOMETIMES_PRODUCED\r
   gEfiDxeIplPpiGuid                             # PPI SOMETIMES_PRODUCED\r
-  gEfiPeiPeCoffLoaderGuid                       \r
   gEfiPeiDecompressPpiGuid\r
   gEfiPeiFirmwareVolumeInfoPpiGuid\r
 \r
index a81475484f60e506032eee84c56860e3d688a819..cb13a7d4b08564b7318cc3ddf4bdf1cdc391f99c 100644 (file)
@@ -174,7 +174,6 @@ DxeLoadCore (
   EFI_PHYSICAL_ADDRESS                      DxeCoreAddress;\r
   UINT64                                    DxeCoreSize;\r
   EFI_PHYSICAL_ADDRESS                      DxeCoreEntryPoint;\r
-  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader;\r
   EFI_BOOT_MODE                             BootMode;\r
   EFI_PEI_FV_HANDLE                         VolumeHandle;\r
   EFI_PEI_FILE_HANDLE                       FileHandle;\r
@@ -200,12 +199,6 @@ DxeLoadCore (
     // Now should have a HOB with the DXE core w/ the old HOB destroyed\r
     //\r
   }\r
-\r
-  //\r
-  // Install the PEI Protocols that are shared between PEI and DXE\r
-  //\r
-  PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *) GetPeCoffLoaderProtocol ();\r
-  ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
   \r
   //\r
   // If any FV contains an encapsulated FV extract that FV\r
@@ -244,14 +237,6 @@ DxeLoadCore (
     );\r
 \r
   //\r
-  // Add HOB for the PE/COFF Loader Protocol\r
-  //\r
-  BuildGuidDataHob (\r
-    &gEfiPeiPeCoffLoaderGuid,\r
-    (VOID *)&PeiEfiPeiPeCoffLoader,\r
-    sizeof (VOID *)\r
-    );\r
-  //\r
   // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r
   //\r
   REPORT_STATUS_CODE (\r
@@ -456,9 +441,6 @@ PeiLoadFile (
   EFI_STATUS                        Status;\r
   PE_COFF_LOADER_IMAGE_CONTEXT      ImageContext;\r
   VOID                              *Pe32Data;\r
-  EFI_PEI_PE_COFF_LOADER_PROTOCOL   *PeiEfiPeiPeCoffLoader;\r
-\r
-  PeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)GetPeCoffLoaderProtocol ();\r
   //\r
   // First try to find the required section in this ffs file.\r
   //\r
@@ -489,7 +471,7 @@ PeiLoadFile (
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = PeiEfiPeiPeCoffLoader->GetImageInfo (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -502,14 +484,14 @@ PeiLoadFile (
   //\r
   // Load the image to our new buffer\r
   //\r
-  Status = PeiEfiPeiPeCoffLoader->LoadImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderLoadImage (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   //\r
   // Relocate the image in our new buffer\r
   //\r
-  Status = PeiEfiPeiPeCoffLoader->RelocateImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
index ebe79a6c50a05fd7ee013f4eacd6720bd910945a..a430d3ea7a78617f95b2047f019e9e7db6004139 100644 (file)
@@ -195,7 +195,6 @@ Returns:
 STATIC\r
 EFI_STATUS\r
 LoadAndRelocatePeCoffImage (\r
-  IN  EFI_PEI_PE_COFF_LOADER_PROTOCOL           *PeiEfiPeiPeCoffLoader,\r
   IN  VOID                                      *Pe32Data,\r
   OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
   OUT UINT64                                    *ImageSize,\r
@@ -209,8 +208,6 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  PeiEfiPeiPeCoffLoader - Pointer to a PE COFF loader protocol\r
-\r
   Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
 \r
   ImageAddress     - The base address of the relocated PE/COFF image\r
@@ -230,15 +227,13 @@ Returns:
   EFI_STATUS                            Status;\r
   PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
 \r
-  ASSERT (PeiEfiPeiPeCoffLoader != NULL);\r
-\r
   ZeroMem (&ImageContext, sizeof (ImageContext));\r
   ImageContext.Handle = Pe32Data;\r
   Status              = GetImageReadFunction (&ImageContext);\r
 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = PeiEfiPeiPeCoffLoader->GetImageInfo (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderGetImageInfo (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -251,14 +246,14 @@ Returns:
   //\r
   // Load the image to our new buffer\r
   //\r
-  Status = PeiEfiPeiPeCoffLoader->LoadImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderLoadImage (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   //\r
   // Relocate the image in our new buffer\r
   //\r
-  Status = PeiEfiPeiPeCoffLoader->RelocateImage (PeiEfiPeiPeCoffLoader, &ImageContext);\r
+  Status = PeCoffLoaderRelocateImage (&ImageContext);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -312,14 +307,12 @@ Returns:
   EFI_PHYSICAL_ADDRESS        ImageAddress;\r
   UINT64                      ImageSize;\r
   EFI_PHYSICAL_ADDRESS        ImageEntryPoint;\r
-  EFI_TE_IMAGE_HEADER         *TEImageHeader;\r
   UINT16                      Machine;\r
   PEI_CORE_INSTANCE           *Private;\r
   VOID                        *EntryPointArg;\r
 \r
-  *EntryPoint   = 0;\r
-  TEImageHeader = NULL;\r
-  ImageSize = 0;\r
+  *EntryPoint          = 0;\r
+  ImageSize            = 0;\r
   *AuthenticationState = 0;\r
 \r
   //\r
@@ -330,11 +323,8 @@ Returns:
              FileHandle,\r
              &Pe32Data\r
              );\r
-  if (!EFI_ERROR (Status)) {\r
-     TEImageHeader = (EFI_TE_IMAGE_HEADER *)Pe32Data;\r
-  }\r
   //\r
-  // If we didn't find a PE32 section, try to find a TE section.\r
+  // If we didn't find a TE section, try to find a PE32 section.\r
   //\r
   if (EFI_ERROR (Status)) {\r
     Status = PeiServicesFfsFindSectionData (\r
@@ -355,57 +345,38 @@ Returns:
 \r
   if (Private->PeiMemoryInstalled && \r
       (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
-    {\r
-      //\r
-      // If memory is installed, perform the shadow operations\r
-      //\r
-      Status = LoadAndRelocatePeCoffImage (\r
-        Private->PeCoffLoader,\r
-        Pe32Data,\r
-        &ImageAddress,\r
-        &ImageSize,\r
-        &ImageEntryPoint\r
-      );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        return EFI_NOT_FOUND;\r
-      }\r
+    //\r
+    // If memory is installed, perform the shadow operations\r
+    //\r
+    Status = LoadAndRelocatePeCoffImage (\r
+      Pe32Data,\r
+      &ImageAddress,\r
+      &ImageSize,\r
+      &ImageEntryPoint\r
+    );\r
 \r
-      //\r
-      // Got the entry point from ImageEntryPoint and ImageStartAddress\r
-      //\r
-      Pe32Data    = (VOID *) ((UINTN) ImageAddress);\r
-      *EntryPoint = ImageEntryPoint;\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
     }\r
+\r
+    //\r
+    // Got the entry point from the loaded Pe32Data\r
+    //\r
+    Pe32Data    = (VOID *) ((UINTN) ImageAddress);\r
+    *EntryPoint = ImageEntryPoint;\r
   } else {\r
-   if (TEImageHeader != NULL) {\r
-      //\r
-      // Retrieve the entry point from the TE image header\r
-      //\r
-      ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) TEImageHeader;\r
-      ImageSize = 0;\r
-      *EntryPoint  = (EFI_PHYSICAL_ADDRESS)((UINTN) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) +\r
-                    TEImageHeader->AddressOfEntryPoint - TEImageHeader->StrippedSize);\r
-    } else {\r
-      //\r
-      // Retrieve the entry point from the PE/COFF image header\r
-      //\r
-      ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;\r
-      ImageSize = 0;\r
-      Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);\r
-      *EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;\r
-      if (EFI_ERROR (Status)) {\r
-        return EFI_NOT_FOUND;\r
-      }\r
+    //\r
+    // Retrieve the entry point from the PE/COFF or TE image header\r
+    //\r
+    ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) Pe32Data;\r
+    Status = PeCoffLoaderGetEntryPoint (Pe32Data, &EntryPointArg);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
     }\r
+    *EntryPoint = (EFI_PHYSICAL_ADDRESS) (UINTN) EntryPointArg;\r
   }\r
-\r
-  if (((EFI_TE_IMAGE_HEADER *) (UINTN) ImageAddress)->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
-    TEImageHeader = (EFI_TE_IMAGE_HEADER *) (UINTN) ImageAddress;\r
-    Machine = TEImageHeader->Machine;\r
-  } else {\r
-    Machine = PeCoffLoaderGetMachineType (Pe32Data);\r
-  } \r
+  \r
+  Machine = PeCoffLoaderGetMachineType (Pe32Data);\r
   \r
   if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Machine)) {\r
     return EFI_UNSUPPORTED;  \r
@@ -424,120 +395,29 @@ Returns:
   //\r
   DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Loading PEIM at 0x%08x EntryPoint=0x%08x ", (UINTN) ImageAddress, *EntryPoint));\r
   DEBUG_CODE_BEGIN ();\r
-    EFI_IMAGE_DATA_DIRECTORY            *DirectoryEntry;\r
-    EFI_IMAGE_DEBUG_DIRECTORY_ENTRY     *DebugEntry;\r
-    UINTN                               DirCount;\r
-    UINTN                               Index;\r
-    UINTN                               Index1;\r
-    BOOLEAN                             FileNameFound;\r
-    CHAR8                               *AsciiString;\r
-    CHAR8                               AsciiBuffer[512];\r
-    VOID                                *CodeViewEntryPointer;\r
-    INTN                                TEImageAdjust;\r
-    EFI_IMAGE_DOS_HEADER                *DosHeader;\r
-    EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
-    UINT32                              NumberOfRvaAndSizes;\r
-\r
-    Hdr.Pe32 = NULL;\r
-    if (TEImageHeader == NULL) {\r
-      DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
-      if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-        //\r
-        // DOS image header is present, so read the PE header after the DOS image header\r
-        //\r
-        Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + (UINTN)((DosHeader->e_lfanew) & 0x0ffff));\r
-      } else {\r
-        //\r
-        // DOS image header is not present, so PE header is at the image base\r
-        //\r
-        Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Find the codeview info in the image and display the file name\r
-    // being loaded.\r
-    //\r
-    // 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
-    DebugEntry          = NULL;\r
-    DirectoryEntry      = NULL;\r
-    NumberOfRvaAndSizes = 0;\r
-    TEImageAdjust       = 0;\r
+    CHAR8                              *AsciiString;\r
+    CHAR8                              AsciiBuffer[512];\r
+    INT32                              Index;\r
+    INT32                              Index1;\r
     \r
-    if (TEImageHeader == NULL) {\r
-      if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
-        //     \r
-        // Use PE32 offset get Debug Directory Entry\r
-        //\r
-        NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
-        DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-        DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
-      } else if (Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
-        //     \r
-        // Use PE32+ offset get Debug Directory Entry\r
-        //\r
-        NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
-        DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
-        DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
-      }\r
-\r
-      if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
-        DirectoryEntry = NULL;\r
-        DebugEntry = NULL;\r
-      }\r
-    } else {\r
-      if (TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
-        DirectoryEntry  = &TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
-        TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize;\r
-        DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) TEImageHeader +\r
-                      TEImageHeader->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
-                      TEImageAdjust);\r
+    AsciiString = PeCoffLoaderGetPdbPointer (Pe32Data);\r
+    \r
+    if (AsciiString != NULL) {\r
+      for (Index = AsciiStrLen (AsciiString) - 1; Index >= 0; Index --) {\r
+        if (AsciiString[Index] == '\\') {\r
+          break;\r
+        }\r
       }\r
-    }\r
 \r
-    if (DebugEntry != NULL && DirectoryEntry != NULL) {\r
-      for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
-        if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
-          if (DebugEntry->SizeOfData > 0) {\r
-            CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageAddress + (UINTN)TEImageAdjust);\r
-            switch (* (UINT32 *) CodeViewEntryPointer) {\r
-              case CODEVIEW_SIGNATURE_NB10:\r
-                AsciiString = (CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);\r
-                break;\r
-\r
-              case CODEVIEW_SIGNATURE_RSDS:\r
-                AsciiString = (CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
-                break;\r
-\r
-              default:\r
-                AsciiString = NULL;\r
-                break;\r
-            }\r
-            if (AsciiString != NULL) {\r
-              FileNameFound = FALSE;\r
-              for (Index = 0, Index1 = 0; AsciiString[Index] != '\0'; Index++) {\r
-                if (AsciiString[Index] == '\\') {\r
-                  Index1 = Index;\r
-                  FileNameFound = TRUE;\r
-                }\r
-              }\r
-\r
-              if (FileNameFound) {\r
-                for (Index = Index1 + 1; AsciiString[Index] != '.'; Index++) {\r
-                  AsciiBuffer[Index - (Index1 + 1)] = AsciiString[Index];\r
-                }\r
-                AsciiBuffer[Index - (Index1 + 1)] = 0;\r
-                DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));\r
-                break;\r
-              }\r
-            }\r
-          }\r
+      if (Index != 0) {\r
+        for (Index1 = 0; AsciiString[Index + 1 + Index1] != '.'; Index1 ++) {\r
+          AsciiBuffer [Index1] = AsciiString[Index + 1 + Index1];\r
         }\r
+        AsciiBuffer [Index1] = '\0';\r
+        DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a.efi", AsciiBuffer));\r
       }\r
     }\r
+\r
   DEBUG_CODE_END ();\r
 \r
   DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n"));\r
@@ -691,12 +571,6 @@ Returns:
   \r
 --*/      \r
 {\r
-  //\r
-  // Always update PeCoffLoader pointer as PEI core itself may get \r
-  // shadowed into memory\r
-  //\r
-  PrivateData->PeCoffLoader = GetPeCoffLoaderProtocol ();\r
-  \r
   if (OldCoreData == NULL) {\r
     //\r
     // The first time we are XIP (running from FLASH). We need to remember the\r
index da0c0aa1af281d8fd46de5c6b459e2fd8c774a23..2d1e29d9f44c8d7b443175911ceca5ca9132fed4 100644 (file)
@@ -54,7 +54,6 @@ Revision History
 #include <Library/MemoryAllocationLib.h>\r
 #include <Guid/FirmwareFileSystem2.h>\r
 #include <Guid/AprioriFileName.h>\r
-#include <Guid/PeiPeCoffLoader.h>\r
 \r
 #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE   0xff\r
 \r
@@ -133,7 +132,6 @@ typedef struct{
   UINTN                              SizeOfCacheAsRam;\r
   VOID                               *MaxTopOfCarHeap;\r
   EFI_PEI_PPI_DESCRIPTOR             *XipLoadFile;\r
-  EFI_PEI_PE_COFF_LOADER_PROTOCOL    *PeCoffLoader; \r
 } PEI_CORE_INSTANCE;\r
 \r
 //\r
index 7701696850cc86173873551e27ad682af1884028..d8db002ea8ef2b7b19e882727a0863b60b6db2fc 100644 (file)
   DebugLib\r
   MemoryAllocationLib\r
   CacheMaintenanceLib\r
-  PeCoffLoaderLib\r
   PeCoffLib\r
 \r
 [Guids]\r
   gPeiAprioriFileNameGuid\r
   gEfiFirmwareFileSystem2Guid\r
-\r
+  gEfiPeiPeCoffLoaderGuid\r
 \r
 [Ppis]\r
   gEfiPeiSecurityPpiGuid                        # PPI_NOTIFY SOMETIMES_CONSUMED\r
index e80fa4240fa93d91a3a11644d7ffc4ab4d75a0f4..d06c02000b474056a80d033897cd0a3a29d6f10f 100644 (file)
@@ -41,7 +41,6 @@
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
   UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf\r
-  PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
   CustomDecompressLib|MdePkg/Library/BaseCustomDecompressLibNull/BaseCustomDecompressLibNull.inf\r
   S3Lib|MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf\r
   RecoveryLib|MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf\r
@@ -73,8 +72,6 @@
   ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
-  PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
-\r
 \r
 [LibraryClasses.common.PEIM]\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
@@ -96,7 +93,6 @@
   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
-  PeCoffLoaderLib|MdeModulePkg/Library/PeiDxePeCoffLoaderLib/PeCoffLoaderLib.inf\r
 \r
 [LibraryClasses.common.DXE_DRIVER]\r
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
index 93f8d06ad2e125481d1cfff61a0dfb3b4ca95f32..2b0050474be3e68cd24f3370e8eb619cc73fa0b9 100644 (file)
@@ -202,5 +202,22 @@ PeCoffLoaderRelocateImageForRuntime (
   )\r
 ;\r
 \r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
 \r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+;\r
 #endif\r
index 5e1f14d9a7f13082f29c895da08f29669b5dbc01..7ed8f078fc8ac5adc92385093074c7e58bb002d3 100644 (file)
@@ -45,31 +45,38 @@ PeCoffLoaderGetEntryPoint (
   OUT VOID  **EntryPoint\r
   )\r
 {\r
-  EFI_IMAGE_DOS_HEADER                  *DosHeader;\r
-  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Header;\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
 \r
   ASSERT (Pe32Data   != NULL);\r
   ASSERT (EntryPoint != NULL);\r
 \r
-  DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
-  if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\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 header.\r
     //\r
-    Header.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
   } else {\r
     //\r
     // DOS image header is not present, so PE header is at the image base.\r
     //\r
-    Header.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
   }\r
 \r
   //\r
   // Calculate the entry point relative to the start of the image.\r
   // AddressOfEntryPoint is common for PE32 & PE32+\r
   //\r
-  *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Header.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
-  return RETURN_SUCCESS;\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Te->AddressOfEntryPoint & 0x0ffffffff) + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize);\r
+    return RETURN_SUCCESS;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    *EntryPoint = (VOID *)((UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));\r
+    return RETURN_SUCCESS;\r
+  }\r
+\r
+  return RETURN_UNSUPPORTED;\r
 }\r
 \r
 \r
@@ -94,14 +101,24 @@ PeCoffLoaderGetMachineType (
   EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
   EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
 \r
-  DosHdr = (EFI_IMAGE_DOS_HEADER  *)Pe32Data;\r
+  ASSERT (Pe32Data != NULL);\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
   } else {\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
   }\r
 \r
-  if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    return Hdr.Te->Machine;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
     return Hdr.Pe32->FileHeader.Machine;\r
   }\r
 \r
@@ -133,7 +150,7 @@ PeCoffLoaderGetPdbPointer (
   IN VOID  *Pe32Data\r
   )\r
 {\r
-  EFI_IMAGE_DOS_HEADER                  *DosHeader;\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
   EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
   EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
@@ -150,12 +167,12 @@ PeCoffLoaderGetPdbPointer (
   DebugEntry          = NULL;\r
   NumberOfRvaAndSizes = 0;\r
 \r
-  DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
-  if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\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 header.\r
     //\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
   } else {\r
     //\r
     // DOS image header is not present, so PE header is at the image base.\r
@@ -226,7 +243,7 @@ PeCoffLoaderGetPdbPointer (
     return NULL;\r
   }\r
 \r
-  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount++, DebugEntry++) {\r
+  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
     if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
       if (DebugEntry->SizeOfData > 0) {\r
         CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
index c56011b24d00a177b4e8e429fc8d7c17e5ae05c1..fb78aefb8cd871720ca355e9e8400acb53a65a70 100644 (file)
@@ -1334,3 +1334,23 @@ PeCoffLoaderImageReadFromMemory (
   return RETURN_SUCCESS;\r
 }\r
 \r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c b/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.c
new file mode 100644 (file)
index 0000000..251af43
--- /dev/null
@@ -0,0 +1,225 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  DxeNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiDxe.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function gets the pointer to PeCofferLoader guid structure\r
+  from the guid data hob.\r
+\r
+  It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeNt32PeCoffLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+  \r
+  //\r
+  // Find guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+  ASSERT (GuidHob != NULL);\r
+\r
+  //\r
+  // Get PeCofferLoader guid structure from guid hob data.\r
+  //\r
+  mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  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
+\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
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\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
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @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
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf b/Nt32Pkg/Library/DxeNt32PeCoffLib/DxeNt32PeCoffLib.inf
new file mode 100644 (file)
index 0000000..d136b21
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for Dxe modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeNt32PeCoffLib\r
+  FILE_GUID                      = 624571b0-4b69-40e3-bd13-78fae0e84270\r
+  MODULE_TYPE                    = DXE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|DXE_CORE DXE_DRIVER\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DxeNt32PeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  DxeNt32PeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
index 4f3c505cdd964a9736993bfa514af7df7aa70ead..70647426faf873e582d7b5385a5235f8013db5bf 100644 (file)
@@ -27,6 +27,7 @@ Revision History
 #include <Ppi/NtPeiLoadFile.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 \r
 RETURN_STATUS\r
@@ -63,15 +64,16 @@ Returns:
   UINT64                  ImageSize;\r
   EFI_PHYSICAL_ADDRESS    ImageEntryPoint;\r
 \r
+  ASSERT (Pe32Data   != NULL);\r
+  ASSERT (EntryPoint != NULL);\r
+\r
   Status = PeiServicesLocatePpi (\r
              &gNtPeiLoadFilePpiGuid,\r
              0,\r
              &PpiDescriptor,\r
              &PeiNtService\r
              );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   Status = PeiNtService->PeiLoadFileService (\r
                            Pe32Data,\r
@@ -79,6 +81,10 @@ Returns:
                            &ImageSize,\r
                            &ImageEntryPoint\r
                            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
   return Status;\r
 }\r
@@ -90,9 +96,9 @@ Returns:
   level debug.\r
    \r
 \r
-  @param  Image   Pointer to a PE/COFF header\r
+  @param  Pe32Data   Pointer to a PE/COFF header\r
 \r
-  @return         Machine type or zero if not a valid iamge\r
+  @return            Machine type or zero if not a valid iamge\r
 \r
 **/\r
 UINT16\r
@@ -104,17 +110,163 @@ PeCoffLoaderGetMachineType (
   EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
   EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
 \r
+  ASSERT (Pe32Data   != NULL);\r
+\r
   DosHdr = (EFI_IMAGE_DOS_HEADER  *)Pe32Data;\r
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
   } else {\r
-    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
   }\r
 \r
-  if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    return Hdr.Te->Machine;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
     return Hdr.Pe32->FileHeader.Machine;\r
   }\r
 \r
   return 0x0000;\r
 }\r
 \r
+/**\r
+  Returns a pointer to the PDB file name for a PE/COFF image that has been\r
+  loaded into system memory with the PE/COFF Loader Library functions.\r
+\r
+  Returns the PDB file name for the PE/COFF image specified by Pe32Data.  If\r
+  the PE/COFF image specified by Pe32Data is not a valid, then NULL is\r
+  returned.  If the PE/COFF image specified by Pe32Data does not contain a\r
+  debug directory entry, then NULL is returned.  If the debug directory entry\r
+  in the PE/COFF image specified by Pe32Data does not contain a PDB file name,\r
+  then NULL is returned.\r
+  If Pe32Data is NULL, then ASSERT().\r
+\r
+  @param  Pe32Data   Pointer to the PE/COFF image that is loaded in system\r
+                     memory.\r
+\r
+  @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
+          if it cannot be retrieved.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+PeCoffLoaderGetPdbPointer (\r
+  IN VOID  *Pe32Data\r
+  )\r
+{\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
+  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
+  UINTN                                 DirCount;\r
+  VOID                                  *CodeViewEntryPointer;\r
+  INTN                                  TEImageAdjust;\r
+  UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  TEImageAdjust       = 0;\r
+  DirectoryEntry      = NULL;\r
+  DebugEntry          = NULL;\r
+  NumberOfRvaAndSizes = 0;\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\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 header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+  } else {\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
+      DirectoryEntry  = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+      TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+                    Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+                    TEImageAdjust);\r
+    }\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    //\r
+    // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
+    //       It is due to backward-compatibility, for some system might\r
+    //       generate PE32+ image with PE32 Magic.\r
+    //\r
+    switch (Hdr.Pe32->FileHeader.Machine) {\r
+    case EFI_IMAGE_MACHINE_IA32:\r
+      //\r
+      // Assume PE32 image with IA32 Machine field.\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+      break;\r
+    case EFI_IMAGE_MACHINE_X64:\r
+    case EFI_IMAGE_MACHINE_IPF:\r
+      //\r
+      // Assume PE32+ image with X64 or IPF Machine field\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+      break;\r
+    default:\r
+      //\r
+      // For unknow Machine field, use Magic in optional Header\r
+      //\r
+      Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+    }\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
+      // Use PE32 offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+      //\r
+      // Use PE32+ offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    }\r
+\r
+    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+      DirectoryEntry = NULL;\r
+      DebugEntry = NULL;\r
+    }\r
+  } else {\r
+    return NULL;\r
+  }\r
+\r
+  if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
+    if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+      if (DebugEntry->SizeOfData > 0) {\r
+        CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+        switch (* (UINT32 *) CodeViewEntryPointer) {\r
+        case CODEVIEW_SIGNATURE_NB10:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+        case CODEVIEW_SIGNATURE_RSDS:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+        default:\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
diff --git a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c b/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.c
new file mode 100644 (file)
index 0000000..45ccf84
--- /dev/null
@@ -0,0 +1,262 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  PeiCoreNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader = NULL;\r
+\r
+/**\r
+  The function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The funtion must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @retval EFI_SUCCESS   PeCofferLoader guid structure is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetPeCoffLoaderStucture (\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = PeiServicesLocatePpi (\r
+                &gEfiPeiPeCoffLoaderGuid,\r
+                0,\r
+                NULL,\r
+                &mPeiEfiPeiPeCoffLoader\r
+                );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  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
+\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
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\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
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @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
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf b/Nt32Pkg/Library/PeiCoreNt32PeCoffLib/PeiCoreNt32PeCoffLib.inf
new file mode 100644 (file)
index 0000000..26d69b8
--- /dev/null
@@ -0,0 +1,49 @@
+#/** @file\r
+# PeCoff libary for PeiCore modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiCoreNt32PeCoffLib\r
+  FILE_GUID                      = ef9fd7ee-3181-4b16-adc1-8615f88b58b8\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEI_CORE\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiCoreNt32PeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c b/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.c
new file mode 100644 (file)
index 0000000..733826f
--- /dev/null
@@ -0,0 +1,255 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  PeiNt32PeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Nt32 PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+--*/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The constructor must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @param  FfsHeader   Pointer to FFS header the loaded driver.\r
+  @param  PeiServices Pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiNt32PeCoffLibConstructor (\r
+  IN EFI_FFS_FILE_HEADER      *FfsHeader,\r
+  IN EFI_PEI_SERVICES         **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = (*PeiServices)->LocatePpi (\r
+                              PeiServices,\r
+                              &gEfiPeiPeCoffLoaderGuid,\r
+                              0,\r
+                              NULL,\r
+                              &mPeiEfiPeiPeCoffLoader\r
+                              );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  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
+\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
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  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
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\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
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @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
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For NT32 emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf b/Nt32Pkg/Library/PeiNt32PeCoffLib/PeiNt32PeCoffLib.inf
new file mode 100644 (file)
index 0000000..9bfadfd
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for PEIM modules that run NT32 emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation\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
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiNt32PeCoffLib\r
+  FILE_GUID                      = 91404129-c58a-40bb-8a2b-f05bc05a961c\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEIM\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PeiNt32PeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiNt32PeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  Nt32Pkg/Nt32Pkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
index 14286f9bf2c401b1114b20a2adf9246889f2a30b..a54ff4de2a65f0f53c933f48292386b7c2443716 100644 (file)
@@ -79,6 +79,7 @@
 [LibraryClasses.common.SEC]\r
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
   ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
 \r
 [LibraryClasses.common.DXE_CORE]\r
   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
   MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
   UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
   ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
-  PeCoffLoaderLib|MdeModulePkg/Library/DxePeCoffLoaderFromHobLib/DxePeCoffLoaderFromHobLib.inf\r
   UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
   DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PeCoffLib|Nt32Pkg/Library/DxeNT32PeCoffLib/DxeNT32PeCoffLib.inf\r
 \r
 [LibraryClasses.common.DXE_SMM_DRIVER]\r
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
   ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
-  PeCoffLoaderLib|Nt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
   OemHookStatusCodeLib|Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/PeiNt32OemHookStatusCodeLib.inf\r
   PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf\r
   DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  PeCoffLib|Nt32Pkg/Library/PeiNT32PeCoffLib/PeiNT32PeCoffLib.inf\r
 \r
 [LibraryClasses.common.PEI_CORE]\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeCoffGetEntryPointLib|Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/Nt32PeiPeCoffGetEntryPointLib.inf\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
   DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
-  PeCoffLoaderLib|Nt32Pkg/Library/Nt32PeCoffLoaderLib/Nt32PeCoffLoaderLib.inf\r
+  PeCoffLib|Nt32Pkg/Library/PeiCoreNT32PeCoffLib/PeiCoreNT32PeCoffLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r