1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2020 Western Digital Corporation or its affiliates.
4 * Adapted from arch/arm64/kernel/efi-header.S
8 #include <linux/sizes.h>
10 .macro __EFI_PE_HEADER
14 .short IMAGE_FILE_MACHINE_RISCV64 // Machine
16 .short IMAGE_FILE_MACHINE_RISCV32 // Machine
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
29 .short PE_OPT_MAGIC_PE32PLUS // PE32+ format
31 .short PE_OPT_MAGIC_PE32 // PE32 format
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
41 .long __pecoff_text_end - _start // BaseOfData
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
56 .long _end - _start // SizeOfImage
58 // Everything before the kernel image is considered part of the header
59 .long efi_header_end - _start // SizeOfHeaders
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
70 .quad 0 // ExportTable
71 .quad 0 // ImportTable
72 .quad 0 // ResourceTable
73 .quad 0 // ExceptionTable
74 .quad 0 // CertificationTable
75 .quad 0 // BaseRelocationTable
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
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
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
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
107 .set section_count, (. - section_table) / 40