]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkUnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
1. PEI core needs to check image machine type
[mirror_edk2.git] / EdkUnixPkg / Library / EdkUnixPeiPeCoffGetEntryPointLib / PeCoffGetEntryPoint.c
index c0d0a01d3ef532a893a6b67fbe6e2d634b485afb..c5f2453b3d77091caecd9ff0dcb900dbeb48cd3f 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 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
@@ -32,7 +32,9 @@ PeCoffLoaderGetEntryPoint (
 \r
 Routine Description:\r
 \r
-  Loads a PE/COFF image into memory\r
+  Loads a PE/COFF image into memory, this is not follow the original purpose of \r
+  PeCoffGetEntryPoint library class.  But it's ok that Unix package not run on a real \r
+  platform and this is for source level debug.\r
 \r
 Arguments:\r
 \r
@@ -72,4 +74,40 @@ Returns:
                            );\r
   *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
   return Status;\r
-}
+}\r
+\r
+/**\r
+  Returns the machine type of PE/COFF image. \r
+  This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
+  The reason is Unix package needs to load the image to memory to support source\r
+  level debug.\r
+   \r
+\r
+  @param  Image   Pointer to a PE/COFF header\r
+\r
+  @return         Machine type or zero if not a valid iamge\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+PeCoffLoaderGetMachineType (\r
+  IN  VOID  *Pe32Data\r
+  )\r
+{  \r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
+  EFI_IMAGE_DOS_HEADER                 *DosHdr;\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
+  } else {\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
+  }\r
+\r
+  if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+    return Hdr.Pe32->FileHeader.Machine;\r
+  }\r
+\r
+  return 0x0000;\r
+}\r
+\r