summaryrefslogtreecommitdiffstats
path: root/src/arch/riscv/fp_asm.S
blob: 5961047aa9c0568520f593e405af54b9055e03a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */

/*
 * This file define some function used to swap value between memory
 * and float register. This will be used in misaligned access exception
 * handling.
 */

#if defined(__riscv_flen)
#if __riscv_flen >= 32

	.text

/* void read_f32(int regnum, uint32_t* v)
 *    regnum : which register want to read
 *    v : address to hold bits info of reading
 */
	.align	1
	.globl read_f32
read_f32:
	la	a2, .Lr32_t
	andi	a0, a0, 31
	slli	a0, a0, 1
	add	a0, a0, a2
	lbu	a0, 0(a0)
	add	a0, a0, a2
	jr	a0
	.align	2
.Lr32_t:
	.half	.Lr32_f0  - .Lr32_t
	.half	.Lr32_f1  - .Lr32_t
	.half	.Lr32_f2  - .Lr32_t
	.half	.Lr32_f3  - .Lr32_t
	.half	.Lr32_f4  - .Lr32_t
	.half	.Lr32_f5  - .Lr32_t
	.half	.Lr32_f6  - .Lr32_t
	.half	.Lr32_f7  - .Lr32_t
	.half	.Lr32_f8  - .Lr32_t
	.half	.Lr32_f9  - .Lr32_t
	.half	.Lr32_f10 - .Lr32_t
	.half	.Lr32_f11 - .Lr32_t
	.half	.Lr32_f12 - .Lr32_t
	.half	.Lr32_f13 - .Lr32_t
	.half	.Lr32_f14 - .Lr32_t
	.half	.Lr32_f15 - .Lr32_t
	.half	.Lr32_f16 - .Lr32_t
	.half	.Lr32_f17 - .Lr32_t
	.half	.Lr32_f18 - .Lr32_t
	.half	.Lr32_f19 - .Lr32_t
	.half	.Lr32_f20 - .Lr32_t
	.half	.Lr32_f21 - .Lr32_t
	.half	.Lr32_f22 - .Lr32_t
	.half	.Lr32_f23 - .Lr32_t
	.half	.Lr32_f24 - .Lr32_t
	.half	.Lr32_f25 - .Lr32_t
	.half	.Lr32_f26 - .Lr32_t
	.half	.Lr32_f27 - .Lr32_t
	.half	.Lr32_f28 - .Lr32_t
	.half	.Lr32_f29 - .Lr32_t
	.half	.Lr32_f30 - .Lr32_t
	.half	.Lr32_f31 - .Lr32_t
#define  read32(which)	.Lr32_##which: fsw which, 0(a1); ret
	read32(f0)
	read32(f1)
	read32(f2)
	read32(f3)
	read32(f4)
	read32(f5)
	read32(f6)
	read32(f7)
	read32(f8)
	read32(f9)
	read32(f10)
	read32(f11)
	read32(f12)
	read32(f13)
	read32(f14)
	read32(f15)
	read32(f16)
	read32(f17)
	read32(f18)
	read32(f19)
	read32(f20)
	read32(f21)
	read32(f22)
	read32(f23)
	read32(f24)
	read32(f25)
	read32(f26)
	read32(f27)
	read32(f28)
	read32(f29)
	read32(f30)
	read32(f31)

/* void write_f32(int regnum, uint32_t* v)
 *    regnum: which register want to write
 *    v : address to hold bits info of writing
 */
	.align	1
	.globl write_f32
write_f32:
	la	a2, .Lw32_t
	andi	a0, a0, 31
	slli	a0, a0, 1
	add	a0, a0, a2
	lbu	a0, 0(a0)
	add	a0, a0, a2
	jr	a0
	.align	2
.Lw32_t:
	.half	.Lw32_f0  - .Lw32_t
	.half	.Lw32_f1  - .Lw32_t
	.half	.Lw32_f2  - .Lw32_t
	.half	.Lw32_f3  - .Lw32_t
	.half	.Lw32_f4  - .Lw32_t
	.half	.Lw32_f5  - .Lw32_t
	.half	.Lw32_f6  - .Lw32_t
	.half	.Lw32_f7  - .Lw32_t
	.half	.Lw32_f8  - .Lw32_t
	.half	.Lw32_f9  - .Lw32_t
	.half	.Lw32_f10 - .Lw32_t
	.half	.Lw32_f11 - .Lw32_t
	.half	.Lw32_f12 - .Lw32_t
	.half	.Lw32_f13 - .Lw32_t
	.half	.Lw32_f14 - .Lw32_t
	.half	.Lw32_f15 - .Lw32_t
	.half	.Lw32_f16 - .Lw32_t
	.half	.Lw32_f17 - .Lw32_t
	.half	.Lw32_f18 - .Lw32_t
	.half	.Lw32_f19 - .Lw32_t
	.half	.Lw32_f20 - .Lw32_t
	.half	.Lw32_f21 - .Lw32_t
	.half	.Lw32_f22 - .Lw32_t
	.half	.Lw32_f23 - .Lw32_t
	.half	.Lw32_f24 - .Lw32_t
	.half	.Lw32_f25 - .Lw32_t
	.half	.Lw32_f26 - .Lw32_t
	.half	.Lw32_f27 - .Lw32_t
	.half	.Lw32_f28 - .Lw32_t
	.half	.Lw32_f29 - .Lw32_t
	.half	.Lw32_f30 - .Lw32_t
	.half	.Lw32_f31 - .Lw32_t
#define write32(which)	.Lw32_##which: flw which, 0(a1); ret
	write32(f0)
	write32(f1)
	write32(f2)
	write32(f3)
	write32(f4)
	write32(f5)
	write32(f6)
	write32(f7)
	write32(f8)
	write32(f9)
	write32(f10)
	write32(f11)
	write32(f12)
	write32(f13)
	write32(f14)
	write32(f15)
	write32(f16)
	write32(f17)
	write32(f18)
	write32(f19)
	write32(f20)
	write32(f21)
	write32(f22)
	write32(f23)
	write32(f24)
	write32(f25)
	write32(f26)
	write32(f27)
	write32(f28)
	write32(f29)
	write32(f30)
	write32(f31)
#endif // __riscv_flen >= 32

#if __riscv_flen >= 64

	.text

/* void read_f64(int regnum, uint64_t* v)
 *    regnum : which register want to read
 *    v : address to hold bits info of reading
 */
	.align	1
	.globl read_f64
read_f64:
	la	a2, .Lr64_t
	andi	a0, a0, 31
	slli	a0, a0, 1
	add	a0, a0, a2
	lbu	a0, 0(a0)
	add	a0, a0, a2
	jr	a0
	.align	2
.Lr64_t:
	.half	.Lr64_f0  - .Lr64_t
	.half	.Lr64_f1  - .Lr64_t
	.half	.Lr64_f2  - .Lr64_t
	.half	.Lr64_f3  - .Lr64_t
	.half	.Lr64_f4  - .Lr64_t
	.half	.Lr64_f5  - .Lr64_t
	.half	.Lr64_f6  - .Lr64_t
	.half	.Lr64_f7  - .Lr64_t
	.half	.Lr64_f8  - .Lr64_t
	.half	.Lr64_f9  - .Lr64_t
	.half	.Lr64_f10 - .Lr64_t
	.half	.Lr64_f11 - .Lr64_t
	.half	.Lr64_f12 - .Lr64_t
	.half	.Lr64_f13 - .Lr64_t
	.half	.Lr64_f14 - .Lr64_t
	.half	.Lr64_f15 - .Lr64_t
	.half	.Lr64_f16 - .Lr64_t
	.half	.Lr64_f17 - .Lr64_t
	.half	.Lr64_f18 - .Lr64_t
	.half	.Lr64_f19 - .Lr64_t
	.half	.Lr64_f20 - .Lr64_t
	.half	.Lr64_f21 - .Lr64_t
	.half	.Lr64_f22 - .Lr64_t
	.half	.Lr64_f23 - .Lr64_t
	.half	.Lr64_f24 - .Lr64_t
	.half	.Lr64_f25 - .Lr64_t
	.half	.Lr64_f26 - .Lr64_t
	.half	.Lr64_f27 - .Lr64_t
	.half	.Lr64_f28 - .Lr64_t
	.half	.Lr64_f29 - .Lr64_t
	.half	.Lr64_f30 - .Lr64_t
	.half	.Lr64_f31 - .Lr64_t
#define  read64(which)	.Lr64_##which: fsd which, 0(a1); ret
	read64(f0)
	read64(f1)
	read64(f2)
	read64(f3)
	read64(f4)
	read64(f5)
	read64(f6)
	read64(f7)
	read64(f8)
	read64(f9)
	read64(f10)
	read64(f11)
	read64(f12)
	read64(f13)
	read64(f14)
	read64(f15)
	read64(f16)
	read64(f17)
	read64(f18)
	read64(f19)
	read64(f20)
	read64(f21)
	read64(f22)
	read64(f23)
	read64(f24)
	read64(f25)
	read64(f26)
	read64(f27)
	read64(f28)
	read64(f29)
	read64(f30)
	read64(f31)

/* void write_f64(int regnum, uint64_t* v)
 *    regnum: which register want to write
 *    v : address to hold bits info of writing
 */
	.align	1
	.globl write_f64
write_f64:
	la	a2, .Lw64_t
	andi	a0, a0, 31
	slli	a0, a0, 1
	add	a0, a0, a2
	lbu	a0, 0(a0)
	add	a0, a0, a2
	jr	a0
	.align	2
.Lw64_t:
	.half	.Lw64_f0  - .Lw64_t
	.half	.Lw64_f1  - .Lw64_t
	.half	.Lw64_f2  - .Lw64_t
	.half	.Lw64_f3  - .Lw64_t
	.half	.Lw64_f4  - .Lw64_t
	.half	.Lw64_f5  - .Lw64_t
	.half	.Lw64_f6  - .Lw64_t
	.half	.Lw64_f7  - .Lw64_t
	.half	.Lw64_f8  - .Lw64_t
	.half	.Lw64_f9  - .Lw64_t
	.half	.Lw64_f10 - .Lw64_t
	.half	.Lw64_f11 - .Lw64_t
	.half	.Lw64_f12 - .Lw64_t
	.half	.Lw64_f13 - .Lw64_t
	.half	.Lw64_f14 - .Lw64_t
	.half	.Lw64_f15 - .Lw64_t
	.half	.Lw64_f16 - .Lw64_t
	.half	.Lw64_f17 - .Lw64_t
	.half	.Lw64_f18 - .Lw64_t
	.half	.Lw64_f19 - .Lw64_t
	.half	.Lw64_f20 - .Lw64_t
	.half	.Lw64_f21 - .Lw64_t
	.half	.Lw64_f22 - .Lw64_t
	.half	.Lw64_f23 - .Lw64_t
	.half	.Lw64_f24 - .Lw64_t
	.half	.Lw64_f25 - .Lw64_t
	.half	.Lw64_f26 - .Lw64_t
	.half	.Lw64_f27 - .Lw64_t
	.half	.Lw64_f28 - .Lw64_t
	.half	.Lw64_f29 - .Lw64_t
	.half	.Lw64_f30 - .Lw64_t
	.half	.Lw64_f31 - .Lw64_t
#define write64(which)	.Lw64_##which: fld which, 0(a1); ret
	write64(f0)
	write64(f1)
	write64(f2)
	write64(f3)
	write64(f4)
	write64(f5)
	write64(f6)
	write64(f7)
	write64(f8)
	write64(f9)
	write64(f10)
	write64(f11)
	write64(f12)
	write64(f13)
	write64(f14)
	write64(f15)
	write64(f16)
	write64(f17)
	write64(f18)
	write64(f19)
	write64(f20)
	write64(f21)
	write64(f22)
	write64(f23)
	write64(f24)
	write64(f25)
	write64(f26)
	write64(f27)
	write64(f28)
	write64(f29)
	write64(f30)
	write64(f31)

#endif // __riscv_flen >= 64

#endif // defined(__riscv_flen)