xref: /linux/arch/riscv/kernel/efi-header.S (revision 87c9c16317882dd6dbbc07e349bc3223e14f3244)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2020 Western Digital Corporation or its affiliates.
4 * Adapted from arch/arm64/kernel/efi-header.S
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#ifdef CONFIG_64BIT
14	.short	IMAGE_FILE_MACHINE_RISCV64		// Machine
15#else
16	.short	IMAGE_FILE_MACHINE_RISCV32		// Machine
17#endif
18	.short	section_count				// NumberOfSections
19	.long	0 					// TimeDateStamp
20	.long	0					// PointerToSymbolTable
21	.long	0					// NumberOfSymbols
22	.short	section_table - optional_header		// SizeOfOptionalHeader
23	.short	IMAGE_FILE_DEBUG_STRIPPED | \
24		IMAGE_FILE_EXECUTABLE_IMAGE | \
25		IMAGE_FILE_LINE_NUMS_STRIPPED		// Characteristics
26
27optional_header:
28#ifdef CONFIG_64BIT
29	.short	PE_OPT_MAGIC_PE32PLUS			// PE32+ format
30#else
31	.short	PE_OPT_MAGIC_PE32			// PE32 format
32#endif
33	.byte	0x02					// MajorLinkerVersion
34	.byte	0x14					// MinorLinkerVersion
35	.long	__pecoff_text_end - efi_header_end	// SizeOfCode
36	.long	__pecoff_data_virt_size			// SizeOfInitializedData
37	.long	0					// SizeOfUninitializedData
38	.long	__efistub_efi_pe_entry - _start		// AddressOfEntryPoint
39	.long	efi_header_end - _start			// BaseOfCode
40#ifdef CONFIG_32BIT
41	.long  __pecoff_text_end - _start		// BaseOfData
42#endif
43
44extra_header_fields:
45	.quad	0					// ImageBase
46	.long	PECOFF_SECTION_ALIGNMENT		// SectionAlignment
47	.long	PECOFF_FILE_ALIGNMENT			// FileAlignment
48	.short	0					// MajorOperatingSystemVersion
49	.short	0					// MinorOperatingSystemVersion
50	.short	LINUX_EFISTUB_MAJOR_VERSION		// MajorImageVersion
51	.short	LINUX_EFISTUB_MINOR_VERSION		// MinorImageVersion
52	.short	0					// MajorSubsystemVersion
53	.short	0					// MinorSubsystemVersion
54	.long	0					// Win32VersionValue
55
56	.long	_end - _start				// SizeOfImage
57
58	// Everything before the kernel image is considered part of the header
59	.long	efi_header_end - _start			// SizeOfHeaders
60	.long	0					// CheckSum
61	.short	IMAGE_SUBSYSTEM_EFI_APPLICATION		// Subsystem
62	.short	0					// DllCharacteristics
63	.quad	0					// SizeOfStackReserve
64	.quad	0					// SizeOfStackCommit
65	.quad	0					// SizeOfHeapReserve
66	.quad	0					// SizeOfHeapCommit
67	.long	0					// LoaderFlags
68	.long	(section_table - .) / 8			// NumberOfRvaAndSizes
69
70	.quad	0					// ExportTable
71	.quad	0					// ImportTable
72	.quad	0					// ResourceTable
73	.quad	0					// ExceptionTable
74	.quad	0					// CertificationTable
75	.quad	0					// BaseRelocationTable
76
77	// Section table
78section_table:
79	.ascii	".text\0\0\0"
80	.long	__pecoff_text_end - efi_header_end	// VirtualSize
81	.long	efi_header_end - _start			// VirtualAddress
82	.long	__pecoff_text_end - efi_header_end	// SizeOfRawData
83	.long	efi_header_end - _start			// PointerToRawData
84
85	.long	0					// PointerToRelocations
86	.long	0					// PointerToLineNumbers
87	.short	0					// NumberOfRelocations
88	.short	0					// NumberOfLineNumbers
89	.long	IMAGE_SCN_CNT_CODE | \
90		IMAGE_SCN_MEM_READ | \
91		IMAGE_SCN_MEM_EXECUTE			// Characteristics
92
93	.ascii	".data\0\0\0"
94	.long	__pecoff_data_virt_size			// VirtualSize
95	.long	__pecoff_text_end - _start		// VirtualAddress
96	.long	__pecoff_data_raw_size			// SizeOfRawData
97	.long	__pecoff_text_end - _start		// PointerToRawData
98
99	.long	0					// PointerToRelocations
100	.long	0					// PointerToLineNumbers
101	.short	0					// NumberOfRelocations
102	.short	0					// NumberOfLineNumbers
103	.long	IMAGE_SCN_CNT_INITIALIZED_DATA | \
104		IMAGE_SCN_MEM_READ | \
105		IMAGE_SCN_MEM_WRITE			// Characteristics
106
107	.set	section_count, (. - section_table) / 40
108
109	.balign	0x1000
110efi_header_end:
111	.endm
112