]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / BasePeCoffGetEntryPointLib / PeCoffGetEntryPoint.c
1 /** @file
2 Tiano PE/COFF loader.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: PeCoffGetEntryPoint.c
14
15 **/
16
17
18
19 /**
20 Loads a PE/COFF image into memory.
21
22 @param Pe32Data Pointer to a PE/COFF Image
23
24 @param EntryPoint Pointer to the entry point of the PE/COFF image
25
26 @retval EFI_SUCCESS if the EntryPoint was returned
27 @retval EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data
28
29 **/
30 RETURN_STATUS
31 EFIAPI
32 PeCoffLoaderGetEntryPoint (
33 IN VOID *Pe32Data,
34 IN OUT VOID **EntryPoint
35 )
36 {
37 EFI_IMAGE_DOS_HEADER *DosHeader;
38 EFI_IMAGE_NT_HEADERS *PeHeader;
39
40 DosHeader = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
41 if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
42 //
43 // DOS image header is present, so read the PE header after the DOS image header
44 //
45 PeHeader = (EFI_IMAGE_NT_HEADERS *) ((UINTN) Pe32Data + (UINTN) ((DosHeader->e_lfanew) & 0x0ffff));
46 } else {
47 //
48 // DOS image header is not present, so PE header is at the image base
49 //
50 PeHeader = (EFI_IMAGE_NT_HEADERS *) Pe32Data;
51 }
52 *EntryPoint = (VOID *) ((UINTN) Pe32Data + (UINTN) (PeHeader->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
53 return RETURN_SUCCESS;
54 }