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
20 #define SAVE_LONG(reg, idx) sw reg, (idx*SIZE_LONG)(sp)
21 #define LOAD_LONG(reg, idx) lw reg, (idx*SIZE_LONG)(sp)
22 #define PE_MACHINE IMAGE_FILE_MACHINE_RISCV32
29 * Magic "MZ" signature for PE/COFF
33 .short IMAGE_DOS_SIGNATURE /* 'MZ' */
34 .skip 58 /* 'MZ' + pad + offset == 64 */
35 .long pe_header - ImageBase /* Offset to the PE header */
37 .long IMAGE_NT_SIGNATURE /* 'PE' */
39 .short PE_MACHINE /* RISC-V 64/32-bit */
40 .short 2 /* nr_sections */
41 .long 0 /* TimeDateStamp */
42 .long 0 /* PointerToSymbolTable */
43 .long 0 /* NumberOfSymbols */
44 .short section_table - optional_header /* SizeOfOptionalHeader */
46 .short (IMAGE_FILE_EXECUTABLE_IMAGE | \
47 IMAGE_FILE_LINE_NUMS_STRIPPED | \
48 IMAGE_FILE_LOCAL_SYMS_STRIPPED | \
49 IMAGE_FILE_DEBUG_STRIPPED)
51 .short IMAGE_NT_OPTIONAL_HDR64_MAGIC /* PE32+ format */
52 .byte 0x02 /* MajorLinkerVersion */
53 .byte 0x14 /* MinorLinkerVersion */
54 .long _edata - _start /* SizeOfCode */
55 .long 0 /* SizeOfInitializedData */
56 .long 0 /* SizeOfUninitializedData */
57 .long _start - ImageBase /* AddressOfEntryPoint */
58 .long _start - ImageBase /* BaseOfCode */
61 .quad 0 /* ImageBase */
62 .long 0x20 /* SectionAlignment */
63 .long 0x8 /* FileAlignment */
64 .short 0 /* MajorOperatingSystemVersion */
65 .short 0 /* MinorOperatingSystemVersion */
66 .short 0 /* MajorImageVersion */
67 .short 0 /* MinorImageVersion */
68 .short 0 /* MajorSubsystemVersion */
69 .short 0 /* MinorSubsystemVersion */
70 .long 0 /* Win32VersionValue */
72 .long _edata - ImageBase /* SizeOfImage */
75 * Everything before the kernel image is considered part of the header
77 .long _start - ImageBase /* SizeOfHeaders */
78 .long 0 /* CheckSum */
79 .short IMAGE_SUBSYSTEM_EFI_APPLICATION /* Subsystem */
80 .short 0 /* DllCharacteristics */
81 .quad 0 /* SizeOfStackReserve */
82 .quad 0 /* SizeOfStackCommit */
83 .quad 0 /* SizeOfHeapReserve */
84 .quad 0 /* SizeOfHeapCommit */
85 .long 0 /* LoaderFlags */
86 .long 0x6 /* NumberOfRvaAndSizes */
88 .quad 0 /* ExportTable */
89 .quad 0 /* ImportTable */
90 .quad 0 /* ResourceTable */
91 .quad 0 /* ExceptionTable */
92 .quad 0 /* CertificationTable */
93 .quad 0 /* BaseRelocationTable */
99 * The EFI application loader requires a relocation section
100 * because EFI applications must be relocatable. This is a
101 * dummy section as far as we are concerned.
105 .byte 0 /* end of 0 padding of section name */
108 .long 0 /* SizeOfRawData */
109 .long 0 /* PointerToRawData */
110 .long 0 /* PointerToRelocations */
111 .long 0 /* PointerToLineNumbers */
112 .short 0 /* NumberOfRelocations */
113 .short 0 /* NumberOfLineNumbers */
114 .long 0x42100040 /* Characteristics (section flags) */
120 .byte 0 /* end of 0 padding of section name */
121 .long _edata - _start /* VirtualSize */
122 .long _start - ImageBase /* VirtualAddress */
123 .long _edata - _start /* SizeOfRawData */
124 .long _start - ImageBase /* PointerToRawData */
126 .long 0 /* PointerToRelocations (0 for executables) */
127 .long 0 /* PointerToLineNumbers (0 for executables) */
128 .short 0 /* NumberOfRelocations (0 for executables) */
129 .short 0 /* NumberOfLineNumbers (0 for executables) */
130 .long 0xe0500020 /* Characteristics (section flags) */
133 addi sp, sp, -(SIZE_LONG * 3)
149 0: addi sp, sp, (SIZE_LONG * 3)