]> git.proxmox.com Git - mirror_edk2.git/blame - EdkNt32Pkg/Library/EdkNt32PeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
EFI_FV_FILETYPE_ALL missing from PI specification. Will be added in an errata as...
[mirror_edk2.git] / EdkNt32Pkg / Library / EdkNt32PeiPeCoffGetEntryPointLib / PeCoffGetEntryPoint.c
CommitLineData
878ddf1f 1/*++\r
2\r
a8b194b9 3Copyright (c) 2006 - 2007, Intel Corporation\r
878ddf1f 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
24\r
25RETURN_STATUS\r
26EFIAPI\r
27PeCoffLoaderGetEntryPoint (\r
28 IN VOID *Pe32Data,\r
29 IN OUT VOID **EntryPoint\r
30 )\r
31/*++\r
32\r
33Routine Description:\r
34\r
a8b194b9 35 Loads a PE/COFF image into memory, this is not follow the original purpose of \r
36 PeCoffGetEntryPoint library class. But it's ok that Unix package not run on a real \r
37 platform and this is for source level debug.\r
878ddf1f 38\r
39Arguments:\r
40\r
41 Pe32Data - Pointer to a PE/COFF Image\r
42\r
43 EntryPoint - Pointer to the entry point of the PE/COFF image\r
44\r
45Returns:\r
46\r
47 EFI_SUCCESS if the EntryPoint was returned\r
48 EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data\r
49\r
50--*/\r
51{\r
52 EFI_STATUS Status;\r
53 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
54 NT_PEI_LOAD_FILE_PPI *PeiNtService;\r
55 EFI_PHYSICAL_ADDRESS ImageAddress;\r
56 UINT64 ImageSize;\r
57 EFI_PHYSICAL_ADDRESS ImageEntryPoint;\r
58\r
84a99d48 59 Status = PeiServicesLocatePpi (\r
878ddf1f 60 &gNtPeiLoadFilePpiGuid,\r
61 0,\r
62 &PpiDescriptor,\r
63 &PeiNtService\r
64 );\r
65 if (EFI_ERROR (Status)) {\r
66 return Status;\r
67 }\r
68\r
69 Status = PeiNtService->PeiLoadFileService (\r
70 Pe32Data,\r
71 &ImageAddress,\r
72 &ImageSize,\r
73 &ImageEntryPoint\r
74 );\r
75 *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
76 return Status;\r
a8b194b9 77}\r
78\r
79/**\r
80 Returns the machine type of PE/COFF image. \r
81 This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
82 The reason is NT32 package needs to load the image to memory to support source\r
83 level debug.\r
84 \r
85\r
86 @param Image Pointer to a PE/COFF header\r
87\r
88 @return Machine type or zero if not a valid iamge\r
89\r
90**/\r
91UINT16\r
92EFIAPI\r
93PeCoffLoaderGetMachineType (\r
94 IN VOID *Pe32Data\r
95 )\r
96{ \r
97 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
98 EFI_IMAGE_DOS_HEADER *DosHdr;\r
99\r
100 DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
101 if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
102 Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data + DosHdr->e_lfanew);\r
103 } else {\r
104 Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)Pe32Data);\r
105 }\r
106\r
107 if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
108 return Hdr.Pe32->FileHeader.Machine;\r
109 }\r
110\r
111 return 0x0000;\r
112}\r
113\r