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