]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/Nt32PeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
Removed CommonHeader.h from NT32Pkg. Did not fix BDS as it will get re-written
[mirror_edk2.git] / Nt32Pkg / Library / Nt32PeiPeCoffGetEntryPointLib / PeCoffGetEntryPoint.c
CommitLineData
869f8e34 1/*++\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeCoffGetEntryPoint.c\r
15\r
16Abstract:\r
17\r
18 Tiano PE/COFF loader\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
f2569572
A
24#include <PiPei.h>\r
25#include <IndustryStandard/PeImage.h>\r
26#include <WinNtPeim.h>\r
27#include <Ppi/NtPeiLoadFile.h>\r
28#include <Library/PeCoffGetEntryPointLib.h>\r
29#include <Library/PeiServicesLib.h>\r
869f8e34 30\r
869f8e34 31\r
32RETURN_STATUS\r
33EFIAPI\r
34PeCoffLoaderGetEntryPoint (\r
35 IN VOID *Pe32Data,\r
36 IN OUT VOID **EntryPoint\r
37 )\r
38/*++\r
39\r
40Routine Description:\r
41\r
42 Loads a PE/COFF image into memory, this is not follow the original purpose of \r
43 PeCoffGetEntryPoint library class. But it's ok that Unix package not run on a real \r
44 platform and this is for source level debug.\r
45\r
46Arguments:\r
47\r
48 Pe32Data - Pointer to a PE/COFF Image\r
49\r
50 EntryPoint - Pointer to the entry point of the PE/COFF image\r
51\r
52Returns:\r
53\r
54 EFI_SUCCESS if the EntryPoint was returned\r
55 EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data\r
56\r
57--*/\r
58{\r
59 EFI_STATUS Status;\r
60 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
61 NT_PEI_LOAD_FILE_PPI *PeiNtService;\r
62 EFI_PHYSICAL_ADDRESS ImageAddress;\r
63 UINT64 ImageSize;\r
64 EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r
65\r
66 Status = PeiServicesLocatePpi (\r
67 &gNtPeiLoadFilePpiGuid,\r
68 0,\r
69 &PpiDescriptor,\r
70 &PeiNtService\r
71 );\r
72 if (EFI_ERROR (Status)) {\r
73 return Status;\r
74 }\r
75\r
76 Status = PeiNtService->PeiLoadFileService (\r
77 Pe32Data,\r
78 &ImageAddress,\r
79 &ImageSize,\r
80 &ImageEntryPoint\r
81 );\r
82 *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
83 return Status;\r
84}\r
85\r
86/**\r
87 Returns the machine type of PE/COFF image. \r
88 This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
89 The reason is NT32 package needs to load the image to memory to support source\r
90 level debug.\r
91 \r
92\r
93 @param Image Pointer to a PE/COFF header\r
94\r
95 @return Machine type or zero if not a valid iamge\r
96\r
97**/\r
98UINT16\r
99EFIAPI\r
100PeCoffLoaderGetMachineType (\r
101 IN VOID *Pe32Data\r
102 )\r
103{ \r
104 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
105 EFI_IMAGE_DOS_HEADER *DosHdr;\r
106\r
107 DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
108 if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
109 Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
110 } else {\r
111 Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
112 }\r
113\r
114 if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
115 return Hdr.Pe32->FileHeader.Machine;\r
116 }\r
117\r
118 return 0x0000;\r
119}\r
120\r