blob: 52056469beb9ead8afa0191412aed06809ae8759 [file] [log] [blame]
Simon Glass61378fd2016-11-07 08:47:11 -07001/*
2 * crt0-efi-aarch64.S - PE/COFF header for aarch64 EFI applications
3 *
4 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
5 *
6 * SPDX-License-Identifier: GPL-2.0+ BSD-2-Clause
7 *
8 * This file is taken and modified from the gnu-efi project.
9 */
10
11 .section .text.head
12
13 /*
14 * Magic "MZ" signature for PE/COFF
15 */
16 .globl ImageBase
17ImageBase:
18 .ascii "MZ"
19 .skip 58 /* 'MZ' + pad + offset == 64 */
20 .long pe_header - ImageBase /* Offset to the PE header */
21pe_header:
22 .ascii "PE"
23 .short 0
24coff_header:
25 .short 0xaa64 /* AArch64 */
26 .short 2 /* nr_sections */
27 .long 0 /* TimeDateStamp */
28 .long 0 /* PointerToSymbolTable */
29 .long 1 /* NumberOfSymbols */
30 .short section_table - optional_header /* SizeOfOptionalHeader */
31 /*
32 * Characteristics: IMAGE_FILE_DEBUG_STRIPPED |
33 * IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LINE_NUMS_STRIPPED
34 */
35 .short 0x206
36optional_header:
37 .short 0x20b /* PE32+ format */
38 .byte 0x02 /* MajorLinkerVersion */
39 .byte 0x14 /* MinorLinkerVersion */
40 .long _edata - _start /* SizeOfCode */
41 .long 0 /* SizeOfInitializedData */
42 .long 0 /* SizeOfUninitializedData */
43 .long _start - ImageBase /* AddressOfEntryPoint */
44 .long _start - ImageBase /* BaseOfCode */
45
46extra_header_fields:
47 .quad 0 /* ImageBase */
48 .long 0x20 /* SectionAlignment */
49 .long 0x8 /* FileAlignment */
50 .short 0 /* MajorOperatingSystemVersion */
51 .short 0 /* MinorOperatingSystemVersion */
52 .short 0 /* MajorImageVersion */
53 .short 0 /* MinorImageVersion */
54 .short 0 /* MajorSubsystemVersion */
55 .short 0 /* MinorSubsystemVersion */
56 .long 0 /* Win32VersionValue */
57
58 .long _edata - ImageBase /* SizeOfImage */
59
60 /*
61 * Everything before the kernel image is considered part of the header
62 */
63 .long _start - ImageBase /* SizeOfHeaders */
64 .long 0 /* CheckSum */
65 .short EFI_SUBSYSTEM /* Subsystem */
66 .short 0 /* DllCharacteristics */
67 .quad 0 /* SizeOfStackReserve */
68 .quad 0 /* SizeOfStackCommit */
69 .quad 0 /* SizeOfHeapReserve */
70 .quad 0 /* SizeOfHeapCommit */
71 .long 0 /* LoaderFlags */
72 .long 0x6 /* NumberOfRvaAndSizes */
73
74 .quad 0 /* ExportTable */
75 .quad 0 /* ImportTable */
76 .quad 0 /* ResourceTable */
77 .quad 0 /* ExceptionTable */
78 .quad 0 /* CertificationTable */
79 .quad 0 /* BaseRelocationTable */
80
81 /* Section table */
82section_table:
83
84 /*
85 * The EFI application loader requires a relocation section
86 * because EFI applications must be relocatable. This is a
87 * dummy section as far as we are concerned.
88 */
89 .ascii ".reloc"
90 .byte 0
91 .byte 0 /* end of 0 padding of section name */
92 .long 0
93 .long 0
94 .long 0 /* SizeOfRawData */
95 .long 0 /* PointerToRawData */
96 .long 0 /* PointerToRelocations */
97 .long 0 /* PointerToLineNumbers */
98 .short 0 /* NumberOfRelocations */
99 .short 0 /* NumberOfLineNumbers */
100 .long 0x42100040 /* Characteristics (section flags) */
101
102
103 .ascii ".text"
104 .byte 0
105 .byte 0
106 .byte 0 /* end of 0 padding of section name */
107 .long _edata - _start /* VirtualSize */
108 .long _start - ImageBase /* VirtualAddress */
109 .long _edata - _start /* SizeOfRawData */
110 .long _start - ImageBase /* PointerToRawData */
111
112 .long 0 /* PointerToRelocations (0 for executables) */
113 .long 0 /* PointerToLineNumbers (0 for executables) */
114 .short 0 /* NumberOfRelocations (0 for executables) */
115 .short 0 /* NumberOfLineNumbers (0 for executables) */
116 .long 0xe0500020 /* Characteristics (section flags) */
117
118_start:
119 stp x29, x30, [sp, #-32]!
120 mov x29, sp
121
122 stp x0, x1, [sp, #16]
123 mov x2, x0
124 mov x3, x1
125 adr x0, ImageBase
126 adrp x1, _DYNAMIC
127 add x1, x1, #:lo12:_DYNAMIC
128 bl _relocate
129 cbnz x0, 0f
130
131 ldp x0, x1, [sp, #16]
132 bl efi_main
133
1340: ldp x29, x30, [sp], #32
135 ret