crt0-efi-riscv64.S revision 1.1.1.1 1 1.1 jmcneill /* $NetBSD: crt0-efi-riscv64.S,v 1.1.1.1 2021/09/30 18:50:09 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /* SPDX-License-Identifier: GPL-2.0+ */
4 1.1 jmcneill /*
5 1.1 jmcneill * Copright (C) 2014 Linaro Ltd. <ard.biesheuvel (at) linaro.org>
6 1.1 jmcneill * Copright (C) 2018 Alexander Graf <agraf (at) suse.de>
7 1.1 jmcneill *
8 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
9 1.1 jmcneill * modification, are permitted provided that the following conditions
10 1.1 jmcneill * are met:
11 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
12 1.1 jmcneill * notice and this list of conditions, without modification.
13 1.1 jmcneill * 2. The name of the author may not be used to endorse or promote products
14 1.1 jmcneill * derived from this software without specific prior written permission.
15 1.1 jmcneill *
16 1.1 jmcneill * Alternatively, this software may be distributed under the terms of the
17 1.1 jmcneill * GNU General Public License as published by the Free Software Foundation;
18 1.1 jmcneill * either version 2 of the License, or (at your option) any later version.
19 1.1 jmcneill */
20 1.1 jmcneill
21 1.1 jmcneill #ifndef EFI_SUBSYSTEM
22 1.1 jmcneill #define EFI_SUBSYSTEM 10
23 1.1 jmcneill #endif
24 1.1 jmcneill
25 1.1 jmcneill .section .text.head
26 1.1 jmcneill
27 1.1 jmcneill /*
28 1.1 jmcneill * Magic "MZ" signature for PE/COFF
29 1.1 jmcneill */
30 1.1 jmcneill .globl ImageBase
31 1.1 jmcneill ImageBase:
32 1.1 jmcneill .ascii "MZ"
33 1.1 jmcneill .skip 58 // 'MZ' + pad + offset == 64
34 1.1 jmcneill .long pe_header - ImageBase // Offset to the PE header.
35 1.1 jmcneill pe_header:
36 1.1 jmcneill .ascii "PE"
37 1.1 jmcneill .short 0
38 1.1 jmcneill coff_header:
39 1.1 jmcneill .short 0x5064 // riscv64
40 1.1 jmcneill .short 2 // nr_sections
41 1.1 jmcneill .long 0 // TimeDateStamp
42 1.1 jmcneill .long 0 // PointerToSymbolTable
43 1.1 jmcneill .long 0 // NumberOfSymbols
44 1.1 jmcneill .short section_table - optional_header // SizeOfOptionalHeader
45 1.1 jmcneill .short 0x206 // Characteristics.
46 1.1 jmcneill // IMAGE_FILE_DEBUG_STRIPPED |
47 1.1 jmcneill // IMAGE_FILE_EXECUTABLE_IMAGE |
48 1.1 jmcneill // IMAGE_FILE_LINE_NUMS_STRIPPED
49 1.1 jmcneill optional_header:
50 1.1 jmcneill .short 0x20b // PE32+ format
51 1.1 jmcneill .byte 0x02 // MajorLinkerVersion
52 1.1 jmcneill .byte 0x14 // MinorLinkerVersion
53 1.1 jmcneill .long _data - _start // SizeOfCode
54 1.1 jmcneill .long _data_size // SizeOfInitializedData
55 1.1 jmcneill .long 0 // SizeOfUninitializedData
56 1.1 jmcneill .long _start - ImageBase // AddressOfEntryPoint
57 1.1 jmcneill .long _start - ImageBase // BaseOfCode
58 1.1 jmcneill
59 1.1 jmcneill extra_header_fields:
60 1.1 jmcneill .quad 0 // ImageBase
61 1.1 jmcneill .long 0x1000 // SectionAlignment
62 1.1 jmcneill .long 0x200 // FileAlignment
63 1.1 jmcneill .short 0 // MajorOperatingSystemVersion
64 1.1 jmcneill .short 0 // MinorOperatingSystemVersion
65 1.1 jmcneill .short 0 // MajorImageVersion
66 1.1 jmcneill .short 0 // MinorImageVersion
67 1.1 jmcneill .short 0 // MajorSubsystemVersion
68 1.1 jmcneill .short 0 // MinorSubsystemVersion
69 1.1 jmcneill .long 0 // Win32VersionValue
70 1.1 jmcneill
71 1.1 jmcneill .long _edata - ImageBase // SizeOfImage
72 1.1 jmcneill
73 1.1 jmcneill // Everything before the kernel image is considered part of the header
74 1.1 jmcneill .long _start - ImageBase // SizeOfHeaders
75 1.1 jmcneill .long 0 // CheckSum
76 1.1 jmcneill .short EFI_SUBSYSTEM // Subsystem
77 1.1 jmcneill .short 0 // DllCharacteristics
78 1.1 jmcneill .quad 0 // SizeOfStackReserve
79 1.1 jmcneill .quad 0 // SizeOfStackCommit
80 1.1 jmcneill .quad 0 // SizeOfHeapReserve
81 1.1 jmcneill .quad 0 // SizeOfHeapCommit
82 1.1 jmcneill .long 0 // LoaderFlags
83 1.1 jmcneill .long 0x6 // NumberOfRvaAndSizes
84 1.1 jmcneill
85 1.1 jmcneill .quad 0 // ExportTable
86 1.1 jmcneill .quad 0 // ImportTable
87 1.1 jmcneill .quad 0 // ResourceTable
88 1.1 jmcneill .quad 0 // ExceptionTable
89 1.1 jmcneill .quad 0 // CertificationTable
90 1.1 jmcneill .quad 0 // BaseRelocationTable
91 1.1 jmcneill
92 1.1 jmcneill // Section table
93 1.1 jmcneill section_table:
94 1.1 jmcneill /*
95 1.1 jmcneill * The EFI application loader requires a relocation section
96 1.1 jmcneill * because EFI applications must be relocatable. This is a
97 1.1 jmcneill * dummy section as far as we are concerned.
98 1.1 jmcneill */
99 1.1 jmcneill .ascii ".reloc\0\0"
100 1.1 jmcneill .long 0
101 1.1 jmcneill .long 0
102 1.1 jmcneill .long 0 // SizeOfRawData
103 1.1 jmcneill .long 0 // PointerToRawData
104 1.1 jmcneill .long 0 // PointerToRelocations
105 1.1 jmcneill .long 0 // PointerToLineNumbers
106 1.1 jmcneill .short 0 // NumberOfRelocations
107 1.1 jmcneill .short 0 // NumberOfLineNumbers
108 1.1 jmcneill .long 0x42100040 // Characteristics (section flags)
109 1.1 jmcneill
110 1.1 jmcneill .ascii ".text\0\0\0"
111 1.1 jmcneill .long _edata - _start // VirtualSize
112 1.1 jmcneill .long _start - ImageBase // VirtualAddress
113 1.1 jmcneill .long _edata - _start // SizeOfRawData
114 1.1 jmcneill .long _start - ImageBase // PointerToRawData
115 1.1 jmcneill
116 1.1 jmcneill .long 0 // PointerToRelocations (0 for executables)
117 1.1 jmcneill .long 0 // PointerToLineNumbers (0 for executables)
118 1.1 jmcneill .short 0 // NumberOfRelocations (0 for executables)
119 1.1 jmcneill .short 0 // NumberOfLineNumbers (0 for executables)
120 1.1 jmcneill .long 0xe0500020 // Characteristics (section flags)
121 1.1 jmcneill
122 1.1 jmcneill .align 12
123 1.1 jmcneill .globl _start
124 1.1 jmcneill _start:
125 1.1 jmcneill addi sp, sp, -24
126 1.1 jmcneill sd a0, 0(sp)
127 1.1 jmcneill sd a1, 8(sp)
128 1.1 jmcneill sd ra, 16(sp)
129 1.1 jmcneill lla a0, ImageBase
130 1.1 jmcneill lla a1, _DYNAMIC
131 1.1 jmcneill call _relocate
132 1.1 jmcneill bne a0, zero, 0f
133 1.1 jmcneill ld a1, 8(sp)
134 1.1 jmcneill ld a0, 0(sp)
135 1.1 jmcneill call efi_main
136 1.1 jmcneill ld ra, 16(sp)
137 1.1 jmcneill 0: addi sp, sp, 24
138 1.1 jmcneill ret
139