]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
b5f4a214 AB |
2 | /* |
3 | * Copyright (C) 2013 - 2017 Linaro, Ltd. | |
4 | * Copyright (C) 2013, 2014 Red Hat, Inc. | |
b5f4a214 AB |
5 | */ |
6 | ||
f1eb542f AB |
7 | #include <linux/pe.h> |
8 | #include <linux/sizes.h> | |
9 | ||
b5f4a214 | 10 | .macro __EFI_PE_HEADER |
f1eb542f | 11 | .long PE_MAGIC |
b5f4a214 | 12 | coff_header: |
f1eb542f AB |
13 | .short IMAGE_FILE_MACHINE_ARM64 // Machine |
14 | .short section_count // NumberOfSections | |
b5f4a214 AB |
15 | .long 0 // TimeDateStamp |
16 | .long 0 // PointerToSymbolTable | |
f328ba47 | 17 | .long 0 // NumberOfSymbols |
b5f4a214 | 18 | .short section_table - optional_header // SizeOfOptionalHeader |
f1eb542f AB |
19 | .short IMAGE_FILE_DEBUG_STRIPPED | \ |
20 | IMAGE_FILE_EXECUTABLE_IMAGE | \ | |
21 | IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics | |
22 | ||
b5f4a214 | 23 | optional_header: |
f1eb542f | 24 | .short PE_OPT_MAGIC_PE32PLUS // PE32+ format |
b5f4a214 AB |
25 | .byte 0x02 // MajorLinkerVersion |
26 | .byte 0x14 // MinorLinkerVersion | |
cad27ef2 AB |
27 | .long __initdata_begin - efi_header_end // SizeOfCode |
28 | .long __pecoff_data_size // SizeOfInitializedData | |
b5f4a214 | 29 | .long 0 // SizeOfUninitializedData |
6e99d321 | 30 | .long __efistub_efi_pe_entry - _head // AddressOfEntryPoint |
b5f4a214 AB |
31 | .long efi_header_end - _head // BaseOfCode |
32 | ||
33 | extra_header_fields: | |
34 | .quad 0 // ImageBase | |
f1eb542f | 35 | .long SZ_4K // SectionAlignment |
b5f4a214 AB |
36 | .long PECOFF_FILE_ALIGNMENT // FileAlignment |
37 | .short 0 // MajorOperatingSystemVersion | |
38 | .short 0 // MinorOperatingSystemVersion | |
148d3f71 AB |
39 | .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion |
40 | .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion | |
b5f4a214 AB |
41 | .short 0 // MajorSubsystemVersion |
42 | .short 0 // MinorSubsystemVersion | |
43 | .long 0 // Win32VersionValue | |
44 | ||
45 | .long _end - _head // SizeOfImage | |
46 | ||
47 | // Everything before the kernel image is considered part of the header | |
48 | .long efi_header_end - _head // SizeOfHeaders | |
49 | .long 0 // CheckSum | |
f1eb542f | 50 | .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem |
b5f4a214 AB |
51 | .short 0 // DllCharacteristics |
52 | .quad 0 // SizeOfStackReserve | |
53 | .quad 0 // SizeOfStackCommit | |
54 | .quad 0 // SizeOfHeapReserve | |
55 | .quad 0 // SizeOfHeapCommit | |
56 | .long 0 // LoaderFlags | |
57 | .long (section_table - .) / 8 // NumberOfRvaAndSizes | |
58 | ||
59 | .quad 0 // ExportTable | |
60 | .quad 0 // ImportTable | |
61 | .quad 0 // ResourceTable | |
62 | .quad 0 // ExceptionTable | |
63 | .quad 0 // CertificationTable | |
64 | .quad 0 // BaseRelocationTable | |
65 | ||
66 | #ifdef CONFIG_DEBUG_EFI | |
67 | .long efi_debug_table - _head // DebugTable | |
68 | .long efi_debug_table_size | |
69 | #endif | |
70 | ||
71 | // Section table | |
72 | section_table: | |
f1eb542f | 73 | .ascii ".text\0\0\0" |
cad27ef2 | 74 | .long __initdata_begin - efi_header_end // VirtualSize |
b5f4a214 | 75 | .long efi_header_end - _head // VirtualAddress |
cad27ef2 | 76 | .long __initdata_begin - efi_header_end // SizeOfRawData |
b5f4a214 AB |
77 | .long efi_header_end - _head // PointerToRawData |
78 | ||
79 | .long 0 // PointerToRelocations | |
80 | .long 0 // PointerToLineNumbers | |
81 | .short 0 // NumberOfRelocations | |
82 | .short 0 // NumberOfLineNumbers | |
f1eb542f | 83 | .long IMAGE_SCN_CNT_CODE | \ |
cad27ef2 AB |
84 | IMAGE_SCN_MEM_READ | \ |
85 | IMAGE_SCN_MEM_EXECUTE // Characteristics | |
86 | ||
87 | .ascii ".data\0\0\0" | |
88 | .long __pecoff_data_size // VirtualSize | |
89 | .long __initdata_begin - _head // VirtualAddress | |
90 | .long __pecoff_data_rawsize // SizeOfRawData | |
91 | .long __initdata_begin - _head // PointerToRawData | |
92 | ||
93 | .long 0 // PointerToRelocations | |
94 | .long 0 // PointerToLineNumbers | |
95 | .short 0 // NumberOfRelocations | |
96 | .short 0 // NumberOfLineNumbers | |
97 | .long IMAGE_SCN_CNT_INITIALIZED_DATA | \ | |
f1eb542f AB |
98 | IMAGE_SCN_MEM_READ | \ |
99 | IMAGE_SCN_MEM_WRITE // Characteristics | |
100 | ||
101 | .set section_count, (. - section_table) / 40 | |
b5f4a214 AB |
102 | |
103 | #ifdef CONFIG_DEBUG_EFI | |
104 | /* | |
105 | * The debug table is referenced via its Relative Virtual Address (RVA), | |
106 | * which is only defined for those parts of the image that are covered | |
107 | * by a section declaration. Since this header is not covered by any | |
108 | * section, the debug table must be emitted elsewhere. So stick it in | |
109 | * the .init.rodata section instead. | |
110 | * | |
111 | * Note that the EFI debug entry itself may legally have a zero RVA, | |
112 | * which means we can simply put it right after the section headers. | |
113 | */ | |
114 | __INITRODATA | |
115 | ||
116 | .align 2 | |
117 | efi_debug_table: | |
118 | // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY | |
119 | .long 0 // Characteristics | |
120 | .long 0 // TimeDateStamp | |
121 | .short 0 // MajorVersion | |
122 | .short 0 // MinorVersion | |
f1eb542f | 123 | .long IMAGE_DEBUG_TYPE_CODEVIEW // Type |
b5f4a214 AB |
124 | .long efi_debug_entry_size // SizeOfData |
125 | .long 0 // RVA | |
126 | .long efi_debug_entry - _head // FileOffset | |
127 | ||
128 | .set efi_debug_table_size, . - efi_debug_table | |
129 | .previous | |
130 | ||
131 | efi_debug_entry: | |
132 | // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY | |
133 | .ascii "NB10" // Signature | |
134 | .long 0 // Unknown | |
135 | .long 0 // Unknown2 | |
136 | .long 0 // Unknown3 | |
137 | ||
138 | .asciz VMLINUX_PATH | |
139 | ||
140 | .set efi_debug_entry_size, . - efi_debug_entry | |
141 | #endif | |
142 | ||
143 | /* | |
144 | * EFI will load .text onwards at the 4k section alignment | |
145 | * described in the PE/COFF header. To ensure that instruction | |
146 | * sequences using an adrp and a :lo12: immediate will function | |
147 | * correctly at this alignment, we must ensure that .text is | |
148 | * placed at a 4k boundary in the Image to begin with. | |
149 | */ | |
150 | .align 12 | |
151 | efi_header_end: | |
152 | .endm |