xref: /openbmc/linux/arch/arm64/kernel/efi-header.S (revision 15e3ae36)
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_PE_HEADER
11	.long	PE_MAGIC
12coff_header:
13	.short	IMAGE_FILE_MACHINE_ARM64		// Machine
14	.short	section_count				// NumberOfSections
15	.long	0 					// TimeDateStamp
16	.long	0					// PointerToSymbolTable
17	.long	0					// NumberOfSymbols
18	.short	section_table - optional_header		// SizeOfOptionalHeader
19	.short	IMAGE_FILE_DEBUG_STRIPPED | \
20		IMAGE_FILE_EXECUTABLE_IMAGE | \
21		IMAGE_FILE_LINE_NUMS_STRIPPED		// Characteristics
22
23optional_header:
24	.short	PE_OPT_MAGIC_PE32PLUS			// PE32+ format
25	.byte	0x02					// MajorLinkerVersion
26	.byte	0x14					// MinorLinkerVersion
27	.long	__initdata_begin - efi_header_end	// SizeOfCode
28	.long	__pecoff_data_size			// SizeOfInitializedData
29	.long	0					// SizeOfUninitializedData
30	.long	__efistub_efi_entry - _head		// AddressOfEntryPoint
31	.long	efi_header_end - _head			// BaseOfCode
32
33extra_header_fields:
34	.quad	0					// ImageBase
35	.long	SZ_4K					// SectionAlignment
36	.long	PECOFF_FILE_ALIGNMENT			// FileAlignment
37	.short	0					// MajorOperatingSystemVersion
38	.short	0					// MinorOperatingSystemVersion
39	.short	LINUX_EFISTUB_MAJOR_VERSION		// MajorImageVersion
40	.short	LINUX_EFISTUB_MINOR_VERSION		// MinorImageVersion
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
50	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION		// Subsystem
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
72section_table:
73	.ascii	".text\0\0\0"
74	.long	__initdata_begin - efi_header_end	// VirtualSize
75	.long	efi_header_end - _head			// VirtualAddress
76	.long	__initdata_begin - efi_header_end	// SizeOfRawData
77	.long	efi_header_end - _head			// PointerToRawData
78
79	.long	0					// PointerToRelocations
80	.long	0					// PointerToLineNumbers
81	.short	0					// NumberOfRelocations
82	.short	0					// NumberOfLineNumbers
83	.long	IMAGE_SCN_CNT_CODE | \
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 | \
98		IMAGE_SCN_MEM_READ | \
99		IMAGE_SCN_MEM_WRITE			// Characteristics
100
101	.set	section_count, (. - section_table) / 40
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
117efi_debug_table:
118	// EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
119	.long	0					// Characteristics
120	.long	0					// TimeDateStamp
121	.short	0					// MajorVersion
122	.short	0					// MinorVersion
123	.long	IMAGE_DEBUG_TYPE_CODEVIEW		// Type
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
131efi_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
151efi_header_end:
152	.endm
153