1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2013 - 2017 Linaro, Ltd.
4 * Copyright (C) 2013, 2014 Red Hat, Inc.
8 #include <linux/sizes.h>
10 .macro efi_signature_nop
14 * This ccmp instruction has no meaningful effect except that
15 * its opcode forms the magic "MZ" signature required by UEFI.
17 ccmp x18, #0, #0xd, pl
20 * Bootloaders may inspect the opcode at the start of the kernel
21 * image to decide if the kernel is capable of booting via UEFI.
22 * So put an ordinary NOP here, not the "MZ.." pseudo-nop above.
28 .macro __EFI_PE_HEADER
30 .set .Lpe_header_offset, . - .L_head
32 .short IMAGE_FILE_MACHINE_ARM64 // Machine
33 .short .Lsection_count // NumberOfSections
34 .long 0 // TimeDateStamp
35 .long 0 // PointerToSymbolTable
36 .long 0 // NumberOfSymbols
37 .short .Lsection_table - .Loptional_header // SizeOfOptionalHeader
38 .short IMAGE_FILE_DEBUG_STRIPPED | \
39 IMAGE_FILE_EXECUTABLE_IMAGE | \
40 IMAGE_FILE_LINE_NUMS_STRIPPED // Characteristics
43 .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
44 .byte 0x02 // MajorLinkerVersion
45 .byte 0x14 // MinorLinkerVersion
46 .long __initdata_begin - .Lefi_header_end // SizeOfCode
47 .long __pecoff_data_size // SizeOfInitializedData
48 .long 0 // SizeOfUninitializedData
49 .long __efistub_efi_pe_entry - .L_head // AddressOfEntryPoint
50 .long .Lefi_header_end - .L_head // BaseOfCode
53 .long SEGMENT_ALIGN // SectionAlignment
54 .long PECOFF_FILE_ALIGNMENT // FileAlignment
55 .short 0 // MajorOperatingSystemVersion
56 .short 0 // MinorOperatingSystemVersion
57 .short LINUX_EFISTUB_MAJOR_VERSION // MajorImageVersion
58 .short LINUX_EFISTUB_MINOR_VERSION // MinorImageVersion
59 .short 0 // MajorSubsystemVersion
60 .short 0 // MinorSubsystemVersion
61 .long 0 // Win32VersionValue
63 .long _end - .L_head // SizeOfImage
65 // Everything before the kernel image is considered part of the header
66 .long .Lefi_header_end - .L_head // SizeOfHeaders
68 .short IMAGE_SUBSYSTEM_EFI_APPLICATION // Subsystem
69 .short IMAGE_DLL_CHARACTERISTICS_NX_COMPAT // DllCharacteristics
70 .quad 0 // SizeOfStackReserve
71 .quad 0 // SizeOfStackCommit
72 .quad 0 // SizeOfHeapReserve
73 .quad 0 // SizeOfHeapCommit
74 .long 0 // LoaderFlags
75 .long (.Lsection_table - .) / 8 // NumberOfRvaAndSizes
77 .quad 0 // ExportTable
78 .quad 0 // ImportTable
79 .quad 0 // ResourceTable
80 .quad 0 // ExceptionTable
81 .quad 0 // CertificationTable
82 .quad 0 // BaseRelocationTable
84 #if defined(CONFIG_DEBUG_EFI) || defined(CONFIG_ARM64_BTI_KERNEL)
85 .long .Lefi_debug_table - .L_head // DebugTable
86 .long .Lefi_debug_table_size
89 * The debug table is referenced via its Relative Virtual Address (RVA),
90 * which is only defined for those parts of the image that are covered
91 * by a section declaration. Since this header is not covered by any
92 * section, the debug table must be emitted elsewhere. So stick it in
93 * the .init.rodata section instead.
95 * Note that the payloads themselves are permitted to have zero RVAs,
96 * which means we can simply put those right after the section headers.
102 #ifdef CONFIG_DEBUG_EFI
103 // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
104 .long 0 // Characteristics
105 .long 0 // TimeDateStamp
106 .short 0 // MajorVersion
107 .short 0 // MinorVersion
108 .long IMAGE_DEBUG_TYPE_CODEVIEW // Type
109 .long .Lefi_debug_entry_size // SizeOfData
111 .long .Lefi_debug_entry - .L_head // FileOffset
113 #ifdef CONFIG_ARM64_BTI_KERNEL
114 .long 0 // Characteristics
115 .long 0 // TimeDateStamp
116 .short 0 // MajorVersion
117 .short 0 // MinorVersion
118 .long IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS // Type
119 .long 4 // SizeOfData
121 .long .Lefi_dll_characteristics_ex - .L_head // FileOffset
123 .set .Lefi_debug_table_size, . - .Lefi_debug_table
130 .long __initdata_begin - .Lefi_header_end // VirtualSize
131 .long .Lefi_header_end - .L_head // VirtualAddress
132 .long __initdata_begin - .Lefi_header_end // SizeOfRawData
133 .long .Lefi_header_end - .L_head // PointerToRawData
135 .long 0 // PointerToRelocations
136 .long 0 // PointerToLineNumbers
137 .short 0 // NumberOfRelocations
138 .short 0 // NumberOfLineNumbers
139 .long IMAGE_SCN_CNT_CODE | \
140 IMAGE_SCN_MEM_READ | \
141 IMAGE_SCN_MEM_EXECUTE // Characteristics
144 .long __pecoff_data_size // VirtualSize
145 .long __initdata_begin - .L_head // VirtualAddress
146 .long __pecoff_data_rawsize // SizeOfRawData
147 .long __initdata_begin - .L_head // PointerToRawData
149 .long 0 // PointerToRelocations
150 .long 0 // PointerToLineNumbers
151 .short 0 // NumberOfRelocations
152 .short 0 // NumberOfLineNumbers
153 .long IMAGE_SCN_CNT_INITIALIZED_DATA | \
154 IMAGE_SCN_MEM_READ | \
155 IMAGE_SCN_MEM_WRITE // Characteristics
157 .set .Lsection_count, (. - .Lsection_table) / 40
159 #ifdef CONFIG_DEBUG_EFI
161 // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
162 .ascii "NB10" // Signature
169 .set .Lefi_debug_entry_size, . - .Lefi_debug_entry
171 #ifdef CONFIG_ARM64_BTI_KERNEL
172 .Lefi_dll_characteristics_ex:
173 .long IMAGE_DLLCHARACTERISTICS_EX_FORWARD_CFI_COMPAT
176 .balign SEGMENT_ALIGN
179 .set .Lpe_header_offset, 0x0