#include <sys/ioctl.h>
#include <sys/vfs.h>
#include <utime.h>
+#include <dlfcn.h>
#define EFI_UNIX_THUNK_PROTOCOL_GUID \
{ \
(*UnixTcsetattr) (int __fd, int __optional_actions,
__const struct termios *__termios_p);
+typedef
+VOID *
+(*UnixDlopen) (const char *FileName, int Flag);
+
+typedef
+char *
+(*UnixDlerror) (VOID);
+
+typedef
+VOID *
+(*UnixDlsym) (VOID* Handle, const char* Symbol);
+
+
//
//
//
UnixCfsetospeed Cfsetospeed;
UnixTcgetattr Tcgetattr;
UnixTcsetattr Tcsetattr;
+ UnixDlopen Dlopen;
+ UnixDlerror Dlerror;
+ UnixDlsym Dlsym;
} EFI_UNIX_THUNK_PROTOCOL;
extern EFI_GUID gEfiUnixThunkProtocolGuid;
--- /dev/null
+/**@file
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ PeiUnixPeCoffExtraActionLib.c
+
+Abstract:
+
+ Provides services to perform additional actions to relocate and unload
+ PE/Coff image for Unix environment specific purpose such as souce level debug.
+ This version only works for DXE phase
+
+
+**/
+
+#include <PiDxe.h>\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include <UnixDxe.h>
+#include <Library/PeCoffLib.h>
+#include <Library/PeiServicesLib.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+
+//\r
+// Cache of UnixThunk protocol \r
+//\r
+EFI_UNIX_THUNK_PROTOCOL *mUnix;
+
+
+/**
+ The constructor function gets the pointer of the WinNT thunk functions
+ It will ASSERT() if Unix thunk protocol is not installed.
+
+ @retval EFI_SUCCESS Unix thunk protocol is found and cached.
+
+**/
+EFI_STATUS
+EFIAPI
+DxeUnixPeCoffLibExtraActionConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;\r
+\r
+ //\r
+ // Retrieve UnixThunkProtocol from GUID'ed HOB\r
+ //\r
+ GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
+ ASSERT (GuidHob != NULL);\r
+ mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+ ASSERT (mUnix != NULL);\r
+\r
+ return EFI_SUCCESS;
+}
+
+/**
+ Applies additional actions to relocate fixups to a PE/COFF image.
+
+ Generally this function is called after sucessfully Applying relocation fixups
+ to a PE/COFF image for some specicial purpose.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ VOID * Handle;\r
+ VOID * Entry;\r
+\r
+ Handle = NULL;\r
+ Entry = NULL;
+
+ DEBUG ((EFI_D_ERROR, "Loading %s 0x%08lx - entry point 0x%08lx\n",\r
+ ImageContext->PdbPointer,\r
+ (UINTN)ImageContext->ImageAddress,\r
+ (UINTN)ImageContext->EntryPoint));\r
+\r
+ Handle = mUnix->Dlopen(ImageContext->PdbPointer, RTLD_NOW);\r
+ \r
+ if (Handle) {\r
+ Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint");\r
+ } else {
+ DEBUG ((EFI_D_ERROR, "%s\n", mUnix->Dlerror()));\r
+ }\r
+ \r
+ if (Entry != NULL) {\r
+ ImageContext->EntryPoint = Entry;
+ DEBUG ((EFI_D_ERROR, "Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));\r
+ }\r
+\r
+\r
+ return;
+ }
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ Releases any environment specific resources that were allocated when the image
+ specified by ImageContext was loaded using PeCoffLoaderLoadImage().
+
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderUnloadImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+}
\ No newline at end of file
--- /dev/null
+#/** @file
+# PeCoff extra action libary for DXE phase that run Unix emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeUnixPeCoffExtraActionLib
+ FILE_GUID = C6F96971-39D2-49a5-93FC-5D42FB4D7DD2
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffExtraActionLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ CONSTRUCTOR = DxeUnixPeCoffLibExtraActionConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ DxeUnixPeCoffExtraActionLib.c
+
+[Packages]
+ UnixPkg/UnixPkg.dec
+ MdePkg/MdePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+ BaseMemoryLib
+
+[Protocols]
+ gEfiUnixThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
+++ /dev/null
-/**@file\r
-\r
-Copyright (c) 2006 - 2008, 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
- DxeUnixPeCoffLib.c\r
-\r
-Abstract:\r
-\r
- Wrap the Unix 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
-DxeUnixPeCoffLibConstructor (\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 Unix 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
+++ /dev/null
-#/** @file\r
-# PeCoff libary for Dxe modules that run Unix emulator.\r
-#\r
-# Lib to provide memory journal status code reporting Routines\r
-# Copyright (c) 2007 - 2008, 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 = DxeUnixPeCoffLib\r
- FILE_GUID = 624571b0-4b69-40e3-bd13-78fae0e84270\r
- MODULE_TYPE = DXE_DRIVER\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 = DxeUnixPeCoffLibConstructor\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
- DxeUnixPeCoffLib.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
- UnixPkg/UnixPkg.dec\r
-\r
-[LibraryClasses]\r
- DebugLib\r
- HobLib\r
-\r
-[Guids]\r
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
-\r
+++ /dev/null
-/**@file\r
-\r
-Copyright (c) 2006 - 2008, 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
- PeiCoreUnixPeCoffLib.c\r
-\r
-Abstract:\r
-\r
- Wrap the Unix 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
- (VOID**) &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 Unix 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 OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- )\r
-{\r
- if (mPeiEfiPeiPeCoffLoader == NULL) {\r
- GetPeCoffLoaderStucture ();\r
- }\r
- return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
-}\r
+++ /dev/null
-#/** @file\r
-# PeCoff libary for PeiCore modules that run Unix emulator.\r
-#\r
-# Lib to provide memory journal status code reporting Routines\r
-# Copyright (c) 2007 - 2008, 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 = PeiCoreUnixPeCoffLib\r
- FILE_GUID = ef9fd7ee-3181-4b16-adc1-8615f88b58b8\r
- MODULE_TYPE = PEI_CORE\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
- PeiCoreUnixPeCoffLib.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
- UnixPkg/UnixPkg.dec\r
-\r
-[LibraryClasses]\r
- PeiServicesLib\r
- DebugLib\r
- HobLib\r
-\r
-[Guids]\r
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
-\r
--- /dev/null
+/**@file
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+ PeiUnixPeCoffExtraActionLib.c
+
+Abstract:
+
+ Provides services to perform additional actions to relocate and unload
+ PE/Coff image for UNIX environment specific purpose such as souce level debug.
+ This version only works for PEI phase
+
+
+**/
+#include <PiPei.h>
+#include <Ppi/UnixThunk.h>
+#include <FrameworkModuleBase.h>
+
+#include <Library/PeCoffLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+
+//
+// Cache of UnixThunk protocol
+//
+EFI_UNIX_THUNK_PROTOCOL *mUnix = NULL;
+
+/**
+ The function caches the pointer of the WinNT thunk functions
+ It will ASSERT() if Unix thunk ppi is not installed.
+
+ @retval EFI_SUCCESS WinNT thunk protocol is found and cached.
+
+**/
+EFI_STATUS
+EFIAPI
+UnixPeCoffGetUnixThunkStucture (
+ )
+{
+ PEI_UNIX_THUNK_PPI *UnixThunkPpi;
+ EFI_STATUS Status;
+
+
+ //
+ // Locate Unix ThunkPpi for retrieving standard output handle
+ //
+ Status = PeiServicesLocatePpi (
+ &gPeiUnixThunkPpiGuid,
+ 0,
+ NULL,
+ (VOID **) &UnixThunkPpi
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Applies additional actions to relocate fixups to a PE/COFF image.
+
+ Generally this function is called after sucessfully Applying relocation fixups
+ to a PE/COFF image for some specicial purpose.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ VOID * Handle;\r
+ VOID * Entry;\r
+\r
+ Handle = NULL;\r
+ Entry = NULL;
+
+ if (mUnix == NULL) {
+ UnixPeCoffGetUnixThunkStucture ();
+ }
+ DEBUG ((EFI_D_ERROR, "Loading %s 0x%08lx - entry point 0x%08lx\n",\r
+ ImageContext->PdbPointer,\r
+ (UINTN)ImageContext->ImageAddress,\r
+ (UINTN)ImageContext->EntryPoint));\r
+\r
+ Handle = mUnix->Dlopen (ImageContext->PdbPointer, RTLD_NOW);\r
+ \r
+ if (Handle) {\r
+ Entry = mUnix->Dlsym(Handle, "_ModuleEntryPoint");\r
+ } else {
+ DEBUG ((EFI_D_ERROR, "%s\n", mUnix->Dlerror()));\r
+ }\r
+ \r
+ if (Entry != NULL) {\r
+ ImageContext->EntryPoint = Entry;
+ DEBUG ((EFI_D_ERROR, "Change %s Entrypoint to :0x%08lx\n", ImageContext->PdbPointer, Entry));\r
+ }\r
+\r
+\r
+ return;
+ }
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ Releases any environment specific resources that were allocated when the image
+ specified by ImageContext was loaded using PeCoffLoaderLoadImage().
+
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderUnloadImageExtraAction (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+}
\ No newline at end of file
--- /dev/null
+#/** @file
+# PeCoff extra action libary for Pei phase that run UNIX emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiUnixPeCoffExtraActionLib
+ FILE_GUID = 1D0D29DE-A5EC-46aa-AE8A-1A5A1F71F202
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffExtraActionLib|PEI_CORE PEIM
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ PeiUnixPeCoffExtraActionLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ PeiServicesLib
+ DebugLib
+
+[Ppis]
+ gPeiUnixThunkPpiGuid # PPI ALWAYS_CONSUMED
+++ /dev/null
-/**@file\r
-\r
-Copyright (c) 2006 - 2008, 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
- PeiUnixPeCoffLib.c\r
-\r
-Abstract:\r
-\r
- Wrap the Unix 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;\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
-PeiUnixPeCoffLibConstructor (\r
- IN EFI_PEI_FILE_HANDLE FileHandle,\r
- IN CONST 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 = PeiServicesLocatePpi (\r
- &gEfiPeiPeCoffLoaderGuid,\r
- 0,\r
- NULL,\r
- (VOID **) &mPeiEfiPeiPeCoffLoader\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 Unix 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
+++ /dev/null
-#/** @file\r
-# PeCoff libary for PEIM modules that run Unix emulator.\r
-#\r
-# Lib to provide memory journal status code reporting Routines\r
-# Copyright (c) 2007 - 2008, 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 = PeiUnixPeCoffLib\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 = PeiUnixPeCoffLibConstructor\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
- PeiUnixPeCoffLib.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
- UnixPkg/UnixPkg.dec\r
-\r
-[LibraryClasses]\r
- DebugLib\r
- HobLib\r
- PeiServicesLib\r
-\r
-[Guids]\r
- gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED\r
-\r
//
// Globals
//
-EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE mPeiEfiPeiPeCoffLoaderInstance = {
- {
- SecNt32PeCoffGetImageInfo,
- SecNt32PeCoffLoadImage,
- SecNt32PeCoffRelocateImage,
- SecNt32PeCoffUnloadimage
- },
- NULL
-};
-
-
-
-EFI_PEI_PE_COFF_LOADER_PROTOCOL *gPeiEfiPeiPeCoffLoader = &mPeiEfiPeiPeCoffLoaderInstance.PeCoff;
UNIX_PEI_LOAD_FILE_PPI mSecNtLoadFilePpi = { SecWinNtPeiLoadFile };
TEMPORARY_RAM_SUPPORT_PPI mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};
EFI_PEI_PPI_DESCRIPTOR gPrivateDispatchTable[] = {
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
- &gEfiPeiPeCoffLoaderGuid,
- NULL
- },
{
EFI_PEI_PPI_DESCRIPTOR_PPI,
&gUnixPeiLoadFilePpiGuid,
IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
);
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffRelocateImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
INTN
TopOfStack = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
- //
- // Patch value in dispatch table values
- //
- gPrivateDispatchTable[0].Ppi = gPeiEfiPeiPeCoffLoader;
-
+
//
// Bind this information into the SEC hand-off state
//
ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE) SecImageRead;
- Status = gPeiEfiPeiPeCoffLoader->GetImageInfo (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);
- Status = gPeiEfiPeiPeCoffLoader->LoadImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = PeCoffLoaderLoadImage (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
- Status = gPeiEfiPeiPeCoffLoader->RelocateImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+ Status = SecNt32PeCoffRelocateImage(&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
}
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffGetImageInfo (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- EFI_STATUS Status;
-
- Status = PeCoffLoaderGetImageInfo (ImageContext);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- switch (ImageContext->ImageType) {
-
- case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
- ImageContext->ImageCodeMemoryType = EfiLoaderCode;
- ImageContext->ImageDataMemoryType = EfiLoaderData;
- break;
-
- case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
- ImageContext->ImageCodeMemoryType = EfiBootServicesCode;
- ImageContext->ImageDataMemoryType = EfiBootServicesData;
- break;
-
- case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
- case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
- ImageContext->ImageCodeMemoryType = EfiRuntimeServicesCode;
- ImageContext->ImageDataMemoryType = EfiRuntimeServicesData;
- break;
-
- default:
- ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
- return RETURN_UNSUPPORTED;
- }
-
- return Status;
-}
-
-EFI_STATUS
-EFIAPI
-SecNt32PeCoffLoadImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
- )
-{
- EFI_STATUS Status;
-
- Status = PeCoffLoaderLoadImage (ImageContext);
- return Status;
-}
-
VOID
SecUnixLoaderBreak (
VOID
EFI_STATUS
EFIAPI
SecNt32PeCoffRelocateImage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
EFI_STATUS
EFIAPI
SecNt32PeCoffUnloadimage (
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
\r
#include <Protocol/UnixThunk.h>\r
#include <Pi/PiFirmwareVolume.h>\r
-#include <Guid/PeiPeCoffLoader.h>\r
#include <Ppi/StatusCode.h>\r
\r
#include <Library/PeCoffLib.h>\r
--*/\r
;\r
\r
-EFI_STATUS\r
-EFIAPI\r
-SecNt32PeCoffGetImageInfo (\r
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,\r
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SecNt32PeCoffLoadImage (\r
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,\r
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SecNt32PeCoffRelocateImage (\r
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,\r
- IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-SecNt32PeCoffUnloadimage (\r
- IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,\r
- IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
- );\r
-\r
EFI_STATUS\r
EFIAPI\r
SecTemporaryRamSupport (\r
IN UINTN CopySize\r
);\r
\r
-typedef struct {\r
- EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;\r
- VOID *ModHandle;\r
-} EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE;\r
-\r
extern EFI_UNIX_THUNK_PROTOCOL *gUnix;\r
ReportStatusCodeLib\r
\r
\r
-[Guids]\r
- gEfiPeiPeCoffLoaderGuid # ALWAYS_PRODUCED\r
-\r
-\r
[Ppis]\r
gUnixPeiLoadFilePpiGuid # PPI ALWAYS_PRODUCED\r
gEfiPeiStatusCodePpiGuid # PPI ALWAYS_PRODUCED\r
#include <X11/extensions/XShm.h>
#include <X11/keysym.h>
-#include <Guid/PeiPeCoffLoader.h>
#include <Ppi/StatusCode.h>
#include <Library/PeCoffLib.h>
cfsetispeed,
cfsetospeed,
tcgetattr,
- tcsetattr
+ tcsetattr,
+ dlopen,
+ dlerror,
+ dlsym
};
# EFI/Framework Emulation Platform with UEFI HII interface supported.\r
#\r
# The Emulation Platform can be used to debug individual modules, prior to creating\r
-# a real platform. This also provides an example for how an FPD is created.\r
+# a real platform. This also provides an example for how an DSC is created.\r
# Copyright (c) 2006 - 2008, Intel Corporation\r
#\r
# All rights reserved. This program and the accompanying materials\r
\r
[LibraryClasses.common.USER_DEFINED]\r
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+ PeCoffExtraActionLib|MdePkg/Library/PeCoffExtraActionLibNull/PeCoffExtraActionLibNull.inf\r
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
OemHookStatusCodeLib|UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
- PeCoffLib|UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf\r
+ PeCoffExtraActionLib|UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf\r
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
\r
[LibraryClasses.common.DXE_SMM_DRIVER]\r
OemHookStatusCodeLib|UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf\r
PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
- PeCoffLib|UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf\r
+ PeCoffExtraActionLib|UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf\r
ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf\r
\r
[LibraryClasses.common.PEI_CORE]\r
PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf\r
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
- PeCoffLib|UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf\r
+ PeCoffExtraActionLib|UnixPkg/Library/PeiUnixPeCoffExtraActionLib/PeiUnixPeCoffExtraActionLib.inf\r
\r
[LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf\r
OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+ PeCoffExtraActionLib|UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf\r
\r
[LibraryClasses.common.UEFI_DRIVER]\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf\r
IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf\r
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
+ PeCoffExtraActionLib|UnixPkg/Library/DxeUnixPeCoffExtraActionLib/DxeUnixPeCoffExtraActionLib.inf\r
\r
[LibraryClasses.common.DXE_DRIVER]\r
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r