]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkNt32Pkg/Library/EdkNt32PeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
Rename Protocol/FrameworkHii.h to Protocol/HiiFramework.h to follow the naming conven...
[mirror_edk2.git] / EdkNt32Pkg / Library / EdkNt32PeiPeCoffGetEntryPointLib / PeCoffGetEntryPoint.c
index e2cfd352b2d03af186f43a5cc5e8642f48f3f32b..da2f8e94eb222c1624d7421c85fe406ad2de381a 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
-}
\ No newline at end of file
+}\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 NT32 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