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