1/* SPDX-License-Identifier: GPL-2.0 */
2
3#include <linux/pe.h>
4
5#ifdef CONFIG_64BIT
6	.set		.Lextra_characteristics, 0x0
7	.set		.Lpe_opt_magic, PE_OPT_MAGIC_PE32PLUS
8#else
9	.set		.Lextra_characteristics, IMAGE_FILE_32BIT_MACHINE
10	.set		.Lpe_opt_magic, PE_OPT_MAGIC_PE32
11#endif
12
13	.section	".head", "a"
14	.globl		__efistub_efi_zboot_header
15__efistub_efi_zboot_header:
16.Ldoshdr:
17	.long		MZ_MAGIC
18	.ascii		"zimg"					// image type
19	.long		__efistub__gzdata_start - .Ldoshdr	// payload offset
20	.long		__efistub__gzdata_size - 12		// payload size
21	.long		0, 0					// reserved
22	.asciz		COMP_TYPE				// compression type
23	.org		.Ldoshdr + 0x38
24	.long		LINUX_PE_MAGIC
25	.long		.Lpehdr - .Ldoshdr			// PE header offset
26
27.Lpehdr:
28	.long		PE_MAGIC
29	.short		MACHINE_TYPE
30	.short		.Lsection_count
31	.long		0
32	.long		0
33	.long		0
34	.short		.Lsection_table - .Loptional_header
35	.short		IMAGE_FILE_DEBUG_STRIPPED | \
36			IMAGE_FILE_EXECUTABLE_IMAGE | \
37			IMAGE_FILE_LINE_NUMS_STRIPPED |\
38			.Lextra_characteristics
39
40.Loptional_header:
41	.short		.Lpe_opt_magic
42	.byte		0, 0
43	.long		_etext - .Lefi_header_end
44	.long		__data_size
45	.long		0
46	.long		__efistub_efi_zboot_entry - .Ldoshdr
47	.long		.Lefi_header_end - .Ldoshdr
48
49#ifdef CONFIG_64BIT
50	.quad		0
51#else
52	.long		_etext - .Ldoshdr, 0x0
53#endif
54	.long		4096
55	.long		512
56	.short		0, 0
57	.short		LINUX_EFISTUB_MAJOR_VERSION	// MajorImageVersion
58	.short		LINUX_EFISTUB_MINOR_VERSION	// MinorImageVersion
59	.short		0, 0
60	.long		0
61	.long		_end - .Ldoshdr
62
63	.long		.Lefi_header_end - .Ldoshdr
64	.long		0
65	.short		IMAGE_SUBSYSTEM_EFI_APPLICATION
66	.short		0
67#ifdef CONFIG_64BIT
68	.quad		0, 0, 0, 0
69#else
70	.long		0, 0, 0, 0
71#endif
72	.long		0
73	.long		(.Lsection_table - .) / 8
74
75	.quad		0				// ExportTable
76	.quad		0				// ImportTable
77	.quad		0				// ResourceTable
78	.quad		0				// ExceptionTable
79	.quad		0				// CertificationTable
80	.quad		0				// BaseRelocationTable
81#ifdef CONFIG_DEBUG_EFI
82	.long		.Lefi_debug_table - .Ldoshdr	// DebugTable
83	.long		.Lefi_debug_table_size
84#endif
85
86.Lsection_table:
87	.ascii		".text\0\0\0"
88	.long		_etext - .Lefi_header_end
89	.long		.Lefi_header_end - .Ldoshdr
90	.long		_etext - .Lefi_header_end
91	.long		.Lefi_header_end - .Ldoshdr
92
93	.long		0, 0
94	.short		0, 0
95	.long		IMAGE_SCN_CNT_CODE | \
96			IMAGE_SCN_MEM_READ | \
97			IMAGE_SCN_MEM_EXECUTE
98
99	.ascii		".data\0\0\0"
100	.long		__data_size
101	.long		_etext - .Ldoshdr
102	.long		__data_rawsize
103	.long		_etext - .Ldoshdr
104
105	.long		0, 0
106	.short		0, 0
107	.long		IMAGE_SCN_CNT_INITIALIZED_DATA | \
108			IMAGE_SCN_MEM_READ | \
109			IMAGE_SCN_MEM_WRITE
110
111	.set		.Lsection_count, (. - .Lsection_table) / 40
112
113#ifdef CONFIG_DEBUG_EFI
114	.section	".rodata", "a"
115	.align		2
116.Lefi_debug_table:
117	// EFI_IMAGE_DEBUG_DIRECTORY_ENTRY
118	.long		0				// Characteristics
119	.long		0				// TimeDateStamp
120	.short		0				// MajorVersion
121	.short		0				// MinorVersion
122	.long		IMAGE_DEBUG_TYPE_CODEVIEW	// Type
123	.long		.Lefi_debug_entry_size		// SizeOfData
124	.long		0				// RVA
125	.long		.Lefi_debug_entry - .Ldoshdr	// FileOffset
126
127	.set		.Lefi_debug_table_size, . - .Lefi_debug_table
128	.previous
129
130.Lefi_debug_entry:
131	// EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY
132	.ascii		"NB10"				// Signature
133	.long		0				// Unknown
134	.long		0				// Unknown2
135	.long		0				// Unknown3
136
137	.asciz		ZBOOT_EFI_PATH
138
139	.set		.Lefi_debug_entry_size, . - .Lefi_debug_entry
140#endif
141
142	.p2align	12
143.Lefi_header_end:
144
145