1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * crt0-efi-riscv.S - PE/COFF header for RISC-V EFI applications
5 * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
6 * Copright (C) 2018 Alexander Graf <agraf@suse.de>
8 * This file is inspired by arch/arm/lib/crt0_aarch64_efi.S
11 #include <asm-generic/pe.h>
13 #if __riscv_xlen == 64
15 #define SAVE_LONG(reg, idx) sd reg, (idx*SIZE_LONG)(sp)
16 #define LOAD_LONG(reg, idx) ld reg, (idx*SIZE_LONG)(sp)
17 #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV64
18 #define PE_MAGIC IMAGE_NT_OPTIONAL_HDR64_MAGIC
21 #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
22 #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
23 #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
24 #define PE_MAGIC IMAGE_NT_OPTIONAL_HDR32_MAGIC
31 * Magic "MZ" signature for PE/COFF
35 .short IMAGE_DOS_SIGNATURE /* 'MZ' */
36 .skip 46 /* 'MZ' + pad + offset == 64 */
37 .long 0x43534952 /* Linux magic "RISCV */
39 .long 0x05435352 /* Linux magic2 "RSC\x05*/
40 .long pe_header - ImageBase /* Offset to the PE header */
42 .long IMAGE_NT_SIGNATURE /* 'PE' */
44 .short PE_MACHINE /* RISC-V 64/32-bit */
45 .short 2 /* nr_sections */
46 .long 0 /* TimeDateStamp */
47 .long 0 /* PointerToSymbolTable */
48 .long 0 /* NumberOfSymbols */
49 .short section_table - optional_header /* SizeOfOptionalHeader */
51 .short (IMAGE_FILE_EXECUTABLE_IMAGE | \
52 IMAGE_FILE_LINE_NUMS_STRIPPED | \
53 IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
54 IMAGE_FILE_DEBUG_STRIPPED)
56 .short PE_MAGIC /* PE32(+) format */
57 .byte 0x02 /* MajorLinkerVersion */
58 .byte 0x14 /* MinorLinkerVersion */
59 .long _edata - _start /* SizeOfCode */
60 .long 0 /* SizeOfInitializedData */
61 .long 0 /* SizeOfUninitializedData */
62 .long _start - ImageBase /* AddressOfEntryPoint */
63 .long _start - ImageBase /* BaseOfCode */
64 #if __riscv_xlen == 32
65 .long 0 /* BaseOfData */
69 #if __riscv_xlen == 32
70 .long 0 /* ImageBase */
72 .quad 0 /* ImageBase */
74 .long 0x200 /* SectionAlignment */
75 .long 0x200 /* FileAlignment */
76 .short 0 /* MajorOperatingSystemVersion */
77 .short 0 /* MinorOperatingSystemVersion */
78 .short 1 /* MajorImageVersion */
79 .short 0 /* MinorImageVersion */
80 .short 0 /* MajorSubsystemVersion */
81 .short 0 /* MinorSubsystemVersion */
82 .long 0 /* Win32VersionValue */
84 .long _edata - ImageBase /* SizeOfImage */
87 * Everything before the kernel image is considered part of the header
89 .long _start - ImageBase /* SizeOfHeaders */
90 .long 0 /* CheckSum */
91 .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
92 .short 0 /* DllCharacteristics */
93 #if __riscv_xlen == 32
94 .long 0 /* SizeOfStackReserve */
95 .long 0 /* SizeOfStackCommit */
96 .long 0 /* SizeOfHeapReserve */
97 .long 0 /* SizeOfHeapCommit */
99 .quad 0 /* SizeOfStackReserve */
100 .quad 0 /* SizeOfStackCommit */
101 .quad 0 /* SizeOfHeapReserve */
102 .quad 0 /* SizeOfHeapCommit */
104 .long 0 /* LoaderFlags */
105 .long 0x6 /* NumberOfRvaAndSizes */
107 .quad 0 /* ExportTable */
108 .quad 0 /* ImportTable */
109 .quad 0 /* ResourceTable */
110 .quad 0 /* ExceptionTable */
111 .quad 0 /* CertificationTable */
112 .quad 0 /* BaseRelocationTable */
118 * The EFI application loader requires a relocation section
119 * because EFI applications must be relocatable. This is a
120 * dummy section as far as we are concerned.
124 .byte 0 /* end of 0 padding of section name */
127 .long 0 /* SizeOfRawData */
128 .long 0 /* PointerToRawData */
129 .long 0 /* PointerToRelocations */
130 .long 0 /* PointerToLineNumbers */
131 .short 0 /* NumberOfRelocations */
132 .short 0 /* NumberOfLineNumbers */
133 .long 0x42100040 /* Characteristics (section flags) */
139 .byte 0 /* end of 0 padding of section name */
140 .long _edata - _start /* VirtualSize */
141 .long _start - ImageBase /* VirtualAddress */
142 .long _edata - _start /* SizeOfRawData */
143 .long _start - ImageBase /* PointerToRawData */
145 .long 0 /* PointerToRelocations (0 for executables) */
146 .long 0 /* PointerToLineNumbers (0 for executables) */
147 .short 0 /* NumberOfRelocations (0 for executables) */
148 .short 0 /* NumberOfLineNumbers (0 for executables) */
149 .long 0xe0500020 /* Characteristics (section flags) */
153 addi sp, sp, -(SIZE_LONG * 3)
169 0: addi sp, sp, (SIZE_LONG * 3)