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