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