]>
Commit | Line | Data |
---|---|---|
4549e789 | 1 | /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */ |
c65d76ed SG |
2 | /* |
3 | * crt0-efi-aarch64.S - PE/COFF header for aarch64 EFI applications | |
4 | * | |
5 | * Copright (C) 2014 Linaro Ltd. <[email protected]> | |
6 | * | |
c65d76ed SG |
7 | * |
8 | * This file is taken and modified from the gnu-efi project. | |
9 | */ | |
10 | ||
268ec6e0 HS |
11 | #include <asm-generic/pe.h> |
12 | ||
c65d76ed SG |
13 | .section .text.head |
14 | ||
15 | /* | |
16 | * Magic "MZ" signature for PE/COFF | |
17 | */ | |
18 | .globl ImageBase | |
19 | ImageBase: | |
a35c33c0 | 20 | .short IMAGE_DOS_SIGNATURE /* 'MZ' */ |
18dd984c HS |
21 | .skip 54 /* 'MZ' + pad + offset == 64 */ |
22 | .long LINUX_ARM64_MAGIC /* For GRUB's linux command */ | |
c65d76ed SG |
23 | .long pe_header - ImageBase /* Offset to the PE header */ |
24 | pe_header: | |
a35c33c0 | 25 | .long IMAGE_NT_SIGNATURE /* 'PE' */ |
c65d76ed | 26 | coff_header: |
a35c33c0 | 27 | .short IMAGE_FILE_MACHINE_ARM64 /* AArch64 */ |
d7ddeb66 | 28 | .short 3 /* nr_sections */ |
c65d76ed SG |
29 | .long 0 /* TimeDateStamp */ |
30 | .long 0 /* PointerToSymbolTable */ | |
fb8ebf52 | 31 | .long 0 /* NumberOfSymbols */ |
c65d76ed | 32 | .short section_table - optional_header /* SizeOfOptionalHeader */ |
fb8ebf52 BM |
33 | /* Characteristics */ |
34 | .short (IMAGE_FILE_EXECUTABLE_IMAGE | \ | |
35 | IMAGE_FILE_LINE_NUMS_STRIPPED | \ | |
36 | IMAGE_FILE_LOCAL_SYMS_STRIPPED | \ | |
3ec07c99 | 37 | IMAGE_FILE_LARGE_ADDRESS_AWARE | \ |
fb8ebf52 | 38 | IMAGE_FILE_DEBUG_STRIPPED) |
c65d76ed | 39 | optional_header: |
a35c33c0 | 40 | .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */ |
c65d76ed SG |
41 | .byte 0x02 /* MajorLinkerVersion */ |
42 | .byte 0x14 /* MinorLinkerVersion */ | |
d7ddeb66 | 43 | .long _etext - _start /* SizeOfCode */ |
c65d76ed SG |
44 | .long 0 /* SizeOfInitializedData */ |
45 | .long 0 /* SizeOfUninitializedData */ | |
46 | .long _start - ImageBase /* AddressOfEntryPoint */ | |
47 | .long _start - ImageBase /* BaseOfCode */ | |
48 | ||
49 | extra_header_fields: | |
50 | .quad 0 /* ImageBase */ | |
d7ddeb66 | 51 | .long 0x1000 /* SectionAlignment */ |
9ef5ccaa | 52 | .long 0x200 /* FileAlignment */ |
c65d76ed SG |
53 | .short 0 /* MajorOperatingSystemVersion */ |
54 | .short 0 /* MinorOperatingSystemVersion */ | |
55 | .short 0 /* MajorImageVersion */ | |
56 | .short 0 /* MinorImageVersion */ | |
57 | .short 0 /* MajorSubsystemVersion */ | |
58 | .short 0 /* MinorSubsystemVersion */ | |
59 | .long 0 /* Win32VersionValue */ | |
60 | ||
61 | .long _edata - ImageBase /* SizeOfImage */ | |
62 | ||
63 | /* | |
64 | * Everything before the kernel image is considered part of the header | |
65 | */ | |
66 | .long _start - ImageBase /* SizeOfHeaders */ | |
67 | .long 0 /* CheckSum */ | |
268ec6e0 | 68 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */ |
c9f368b5 | 69 | #if CONFIG_VENDOR_EFI |
c65d76ed | 70 | .short 0 /* DllCharacteristics */ |
c9f368b5 HS |
71 | #else |
72 | .short IMAGE_DLLCHARACTERISTICS_NX_COMPAT | |
73 | #endif | |
c65d76ed SG |
74 | .quad 0 /* SizeOfStackReserve */ |
75 | .quad 0 /* SizeOfStackCommit */ | |
76 | .quad 0 /* SizeOfHeapReserve */ | |
77 | .quad 0 /* SizeOfHeapCommit */ | |
78 | .long 0 /* LoaderFlags */ | |
79 | .long 0x6 /* NumberOfRvaAndSizes */ | |
80 | ||
81 | .quad 0 /* ExportTable */ | |
82 | .quad 0 /* ImportTable */ | |
83 | .quad 0 /* ResourceTable */ | |
84 | .quad 0 /* ExceptionTable */ | |
85 | .quad 0 /* CertificationTable */ | |
86 | .quad 0 /* BaseRelocationTable */ | |
87 | ||
88 | /* Section table */ | |
89 | section_table: | |
90 | ||
91 | /* | |
92 | * The EFI application loader requires a relocation section | |
93 | * because EFI applications must be relocatable. This is a | |
94 | * dummy section as far as we are concerned. | |
95 | */ | |
96 | .ascii ".reloc" | |
97 | .byte 0 | |
98 | .byte 0 /* end of 0 padding of section name */ | |
99 | .long 0 | |
100 | .long 0 | |
101 | .long 0 /* SizeOfRawData */ | |
102 | .long 0 /* PointerToRawData */ | |
103 | .long 0 /* PointerToRelocations */ | |
104 | .long 0 /* PointerToLineNumbers */ | |
105 | .short 0 /* NumberOfRelocations */ | |
106 | .short 0 /* NumberOfLineNumbers */ | |
d7ddeb66 HS |
107 | /* Characteristics (section flags) */ |
108 | .long (IMAGE_SCN_MEM_READ | \ | |
109 | IMAGE_SCN_MEM_DISCARDABLE | \ | |
110 | IMAGE_SCN_CNT_INITIALIZED_DATA) | |
c65d76ed SG |
111 | |
112 | .ascii ".text" | |
113 | .byte 0 | |
114 | .byte 0 | |
115 | .byte 0 /* end of 0 padding of section name */ | |
d7ddeb66 | 116 | .long _etext - _start /* VirtualSize */ |
c65d76ed | 117 | .long _start - ImageBase /* VirtualAddress */ |
d7ddeb66 | 118 | .long _etext - _start /* SizeOfRawData */ |
c65d76ed | 119 | .long _start - ImageBase /* PointerToRawData */ |
d7ddeb66 HS |
120 | .long 0 /* PointerToRelocations */ |
121 | .long 0 /* PointerToLineNumbers */ | |
122 | .short 0 /* NumberOfRelocations */ | |
123 | .short 0 /* NumberOfLineNumbers */ | |
124 | /* Characteristics (section flags) */ | |
125 | .long (IMAGE_SCN_MEM_READ | \ | |
126 | IMAGE_SCN_MEM_EXECUTE | \ | |
127 | IMAGE_SCN_CNT_CODE) | |
c65d76ed | 128 | |
d7ddeb66 HS |
129 | .ascii ".data" |
130 | .byte 0 | |
131 | .byte 0 | |
132 | .byte 0 /* end of 0 padding of section name */ | |
133 | .long _data_size /* VirtualSize */ | |
134 | .long _data - ImageBase /* VirtualAddress */ | |
135 | .long _data_size /* SizeOfRawData */ | |
136 | .long _data - ImageBase /* PointerToRawData */ | |
137 | .long 0 /* PointerToRelocations */ | |
138 | .long 0 /* PointerToLineNumbers */ | |
139 | .short 0 /* NumberOfRelocations */ | |
140 | .short 0 /* NumberOfLineNumbers */ | |
141 | /* Characteristics (section flags) */ | |
142 | .long (IMAGE_SCN_MEM_WRITE | \ | |
143 | IMAGE_SCN_MEM_READ | \ | |
144 | IMAGE_SCN_CNT_INITIALIZED_DATA) | |
c65d76ed | 145 | |
d7ddeb66 | 146 | .align 12 |
c65d76ed SG |
147 | _start: |
148 | stp x29, x30, [sp, #-32]! | |
149 | mov x29, sp | |
150 | ||
151 | stp x0, x1, [sp, #16] | |
c65d76ed SG |
152 | adr x0, ImageBase |
153 | adrp x1, _DYNAMIC | |
154 | add x1, x1, #:lo12:_DYNAMIC | |
155 | bl _relocate | |
156 | cbnz x0, 0f | |
157 | ||
158 | ldp x0, x1, [sp, #16] | |
159 | bl efi_main | |
160 | ||
161 | 0: ldp x29, x30, [sp], #32 | |
162 | ret |