1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef _ASM_ASMMACRO_H
6 #define _ASM_ASMMACRO_H
7 
8 #include <asm/asm-offsets.h>
9 #include <asm/regdef.h>
10 #include <asm/fpregdef.h>
11 #include <asm/loongarch.h>
12 
13 	.macro	parse_v var val
14 	\var	= \val
15 	.endm
16 
17 	.macro	parse_r var r
18 	\var	= -1
19 	.ifc	\r, $r0
20 	\var	= 0
21 	.endif
22 	.ifc	\r, $r1
23 	\var	= 1
24 	.endif
25 	.ifc	\r, $r2
26 	\var	= 2
27 	.endif
28 	.ifc	\r, $r3
29 	\var	= 3
30 	.endif
31 	.ifc	\r, $r4
32 	\var	= 4
33 	.endif
34 	.ifc	\r, $r5
35 	\var	= 5
36 	.endif
37 	.ifc	\r, $r6
38 	\var	= 6
39 	.endif
40 	.ifc	\r, $r7
41 	\var	= 7
42 	.endif
43 	.ifc	\r, $r8
44 	\var	= 8
45 	.endif
46 	.ifc	\r, $r9
47 	\var	= 9
48 	.endif
49 	.ifc	\r, $r10
50 	\var	= 10
51 	.endif
52 	.ifc	\r, $r11
53 	\var	= 11
54 	.endif
55 	.ifc	\r, $r12
56 	\var	= 12
57 	.endif
58 	.ifc	\r, $r13
59 	\var	= 13
60 	.endif
61 	.ifc	\r, $r14
62 	\var	= 14
63 	.endif
64 	.ifc	\r, $r15
65 	\var	= 15
66 	.endif
67 	.ifc	\r, $r16
68 	\var	= 16
69 	.endif
70 	.ifc	\r, $r17
71 	\var	= 17
72 	.endif
73 	.ifc	\r, $r18
74 	\var	= 18
75 	.endif
76 	.ifc	\r, $r19
77 	\var	= 19
78 	.endif
79 	.ifc	\r, $r20
80 	\var	= 20
81 	.endif
82 	.ifc	\r, $r21
83 	\var	= 21
84 	.endif
85 	.ifc	\r, $r22
86 	\var	= 22
87 	.endif
88 	.ifc	\r, $r23
89 	\var	= 23
90 	.endif
91 	.ifc	\r, $r24
92 	\var	= 24
93 	.endif
94 	.ifc	\r, $r25
95 	\var	= 25
96 	.endif
97 	.ifc	\r, $r26
98 	\var	= 26
99 	.endif
100 	.ifc	\r, $r27
101 	\var	= 27
102 	.endif
103 	.ifc	\r, $r28
104 	\var	= 28
105 	.endif
106 	.ifc	\r, $r29
107 	\var	= 29
108 	.endif
109 	.ifc	\r, $r30
110 	\var	= 30
111 	.endif
112 	.ifc	\r, $r31
113 	\var	= 31
114 	.endif
115 	.iflt	\var
116 	.error	"Unable to parse register name \r"
117 	.endif
118 	.endm
119 
120 	.macro	cpu_save_nonscratch thread
121 	stptr.d	s0, \thread, THREAD_REG23
122 	stptr.d	s1, \thread, THREAD_REG24
123 	stptr.d	s2, \thread, THREAD_REG25
124 	stptr.d	s3, \thread, THREAD_REG26
125 	stptr.d	s4, \thread, THREAD_REG27
126 	stptr.d	s5, \thread, THREAD_REG28
127 	stptr.d	s6, \thread, THREAD_REG29
128 	stptr.d	s7, \thread, THREAD_REG30
129 	stptr.d	s8, \thread, THREAD_REG31
130 	stptr.d	sp, \thread, THREAD_REG03
131 	stptr.d	fp, \thread, THREAD_REG22
132 	.endm
133 
134 	.macro	cpu_restore_nonscratch thread
135 	ldptr.d	s0, \thread, THREAD_REG23
136 	ldptr.d	s1, \thread, THREAD_REG24
137 	ldptr.d	s2, \thread, THREAD_REG25
138 	ldptr.d	s3, \thread, THREAD_REG26
139 	ldptr.d	s4, \thread, THREAD_REG27
140 	ldptr.d	s5, \thread, THREAD_REG28
141 	ldptr.d	s6, \thread, THREAD_REG29
142 	ldptr.d	s7, \thread, THREAD_REG30
143 	ldptr.d	s8, \thread, THREAD_REG31
144 	ldptr.d	ra, \thread, THREAD_REG01
145 	ldptr.d	sp, \thread, THREAD_REG03
146 	ldptr.d	fp, \thread, THREAD_REG22
147 	.endm
148 
149 	.macro fpu_save_csr thread tmp
150 	movfcsr2gr	\tmp, fcsr0
151 	stptr.w	\tmp, \thread, THREAD_FCSR
152 	.endm
153 
154 	.macro fpu_restore_csr thread tmp
155 	ldptr.w	\tmp, \thread, THREAD_FCSR
156 	movgr2fcsr	fcsr0, \tmp
157 	.endm
158 
159 	.macro fpu_save_cc thread tmp0 tmp1
160 	movcf2gr	\tmp0, $fcc0
161 	move	\tmp1, \tmp0
162 	movcf2gr	\tmp0, $fcc1
163 	bstrins.d	\tmp1, \tmp0, 15, 8
164 	movcf2gr	\tmp0, $fcc2
165 	bstrins.d	\tmp1, \tmp0, 23, 16
166 	movcf2gr	\tmp0, $fcc3
167 	bstrins.d	\tmp1, \tmp0, 31, 24
168 	movcf2gr	\tmp0, $fcc4
169 	bstrins.d	\tmp1, \tmp0, 39, 32
170 	movcf2gr	\tmp0, $fcc5
171 	bstrins.d	\tmp1, \tmp0, 47, 40
172 	movcf2gr	\tmp0, $fcc6
173 	bstrins.d	\tmp1, \tmp0, 55, 48
174 	movcf2gr	\tmp0, $fcc7
175 	bstrins.d	\tmp1, \tmp0, 63, 56
176 	stptr.d		\tmp1, \thread, THREAD_FCC
177 	.endm
178 
179 	.macro fpu_restore_cc thread tmp0 tmp1
180 	ldptr.d	\tmp0, \thread, THREAD_FCC
181 	bstrpick.d	\tmp1, \tmp0, 7, 0
182 	movgr2cf	$fcc0, \tmp1
183 	bstrpick.d	\tmp1, \tmp0, 15, 8
184 	movgr2cf	$fcc1, \tmp1
185 	bstrpick.d	\tmp1, \tmp0, 23, 16
186 	movgr2cf	$fcc2, \tmp1
187 	bstrpick.d	\tmp1, \tmp0, 31, 24
188 	movgr2cf	$fcc3, \tmp1
189 	bstrpick.d	\tmp1, \tmp0, 39, 32
190 	movgr2cf	$fcc4, \tmp1
191 	bstrpick.d	\tmp1, \tmp0, 47, 40
192 	movgr2cf	$fcc5, \tmp1
193 	bstrpick.d	\tmp1, \tmp0, 55, 48
194 	movgr2cf	$fcc6, \tmp1
195 	bstrpick.d	\tmp1, \tmp0, 63, 56
196 	movgr2cf	$fcc7, \tmp1
197 	.endm
198 
199 	.macro	fpu_save_double thread tmp
200 	li.w	\tmp, THREAD_FPR0
201 	PTR_ADD \tmp, \tmp, \thread
202 	fst.d	$f0, \tmp, THREAD_FPR0  - THREAD_FPR0
203 	fst.d	$f1, \tmp, THREAD_FPR1  - THREAD_FPR0
204 	fst.d	$f2, \tmp, THREAD_FPR2  - THREAD_FPR0
205 	fst.d	$f3, \tmp, THREAD_FPR3  - THREAD_FPR0
206 	fst.d	$f4, \tmp, THREAD_FPR4  - THREAD_FPR0
207 	fst.d	$f5, \tmp, THREAD_FPR5  - THREAD_FPR0
208 	fst.d	$f6, \tmp, THREAD_FPR6  - THREAD_FPR0
209 	fst.d	$f7, \tmp, THREAD_FPR7  - THREAD_FPR0
210 	fst.d	$f8, \tmp, THREAD_FPR8  - THREAD_FPR0
211 	fst.d	$f9, \tmp, THREAD_FPR9  - THREAD_FPR0
212 	fst.d	$f10, \tmp, THREAD_FPR10 - THREAD_FPR0
213 	fst.d	$f11, \tmp, THREAD_FPR11 - THREAD_FPR0
214 	fst.d	$f12, \tmp, THREAD_FPR12 - THREAD_FPR0
215 	fst.d	$f13, \tmp, THREAD_FPR13 - THREAD_FPR0
216 	fst.d	$f14, \tmp, THREAD_FPR14 - THREAD_FPR0
217 	fst.d	$f15, \tmp, THREAD_FPR15 - THREAD_FPR0
218 	fst.d	$f16, \tmp, THREAD_FPR16 - THREAD_FPR0
219 	fst.d	$f17, \tmp, THREAD_FPR17 - THREAD_FPR0
220 	fst.d	$f18, \tmp, THREAD_FPR18 - THREAD_FPR0
221 	fst.d	$f19, \tmp, THREAD_FPR19 - THREAD_FPR0
222 	fst.d	$f20, \tmp, THREAD_FPR20 - THREAD_FPR0
223 	fst.d	$f21, \tmp, THREAD_FPR21 - THREAD_FPR0
224 	fst.d	$f22, \tmp, THREAD_FPR22 - THREAD_FPR0
225 	fst.d	$f23, \tmp, THREAD_FPR23 - THREAD_FPR0
226 	fst.d	$f24, \tmp, THREAD_FPR24 - THREAD_FPR0
227 	fst.d	$f25, \tmp, THREAD_FPR25 - THREAD_FPR0
228 	fst.d	$f26, \tmp, THREAD_FPR26 - THREAD_FPR0
229 	fst.d	$f27, \tmp, THREAD_FPR27 - THREAD_FPR0
230 	fst.d	$f28, \tmp, THREAD_FPR28 - THREAD_FPR0
231 	fst.d	$f29, \tmp, THREAD_FPR29 - THREAD_FPR0
232 	fst.d	$f30, \tmp, THREAD_FPR30 - THREAD_FPR0
233 	fst.d	$f31, \tmp, THREAD_FPR31 - THREAD_FPR0
234 	.endm
235 
236 	.macro	fpu_restore_double thread tmp
237 	li.w	\tmp, THREAD_FPR0
238 	PTR_ADD \tmp, \tmp, \thread
239 	fld.d	$f0, \tmp, THREAD_FPR0  - THREAD_FPR0
240 	fld.d	$f1, \tmp, THREAD_FPR1  - THREAD_FPR0
241 	fld.d	$f2, \tmp, THREAD_FPR2  - THREAD_FPR0
242 	fld.d	$f3, \tmp, THREAD_FPR3  - THREAD_FPR0
243 	fld.d	$f4, \tmp, THREAD_FPR4  - THREAD_FPR0
244 	fld.d	$f5, \tmp, THREAD_FPR5  - THREAD_FPR0
245 	fld.d	$f6, \tmp, THREAD_FPR6  - THREAD_FPR0
246 	fld.d	$f7, \tmp, THREAD_FPR7  - THREAD_FPR0
247 	fld.d	$f8, \tmp, THREAD_FPR8  - THREAD_FPR0
248 	fld.d	$f9, \tmp, THREAD_FPR9  - THREAD_FPR0
249 	fld.d	$f10, \tmp, THREAD_FPR10 - THREAD_FPR0
250 	fld.d	$f11, \tmp, THREAD_FPR11 - THREAD_FPR0
251 	fld.d	$f12, \tmp, THREAD_FPR12 - THREAD_FPR0
252 	fld.d	$f13, \tmp, THREAD_FPR13 - THREAD_FPR0
253 	fld.d	$f14, \tmp, THREAD_FPR14 - THREAD_FPR0
254 	fld.d	$f15, \tmp, THREAD_FPR15 - THREAD_FPR0
255 	fld.d	$f16, \tmp, THREAD_FPR16 - THREAD_FPR0
256 	fld.d	$f17, \tmp, THREAD_FPR17 - THREAD_FPR0
257 	fld.d	$f18, \tmp, THREAD_FPR18 - THREAD_FPR0
258 	fld.d	$f19, \tmp, THREAD_FPR19 - THREAD_FPR0
259 	fld.d	$f20, \tmp, THREAD_FPR20 - THREAD_FPR0
260 	fld.d	$f21, \tmp, THREAD_FPR21 - THREAD_FPR0
261 	fld.d	$f22, \tmp, THREAD_FPR22 - THREAD_FPR0
262 	fld.d	$f23, \tmp, THREAD_FPR23 - THREAD_FPR0
263 	fld.d	$f24, \tmp, THREAD_FPR24 - THREAD_FPR0
264 	fld.d	$f25, \tmp, THREAD_FPR25 - THREAD_FPR0
265 	fld.d	$f26, \tmp, THREAD_FPR26 - THREAD_FPR0
266 	fld.d	$f27, \tmp, THREAD_FPR27 - THREAD_FPR0
267 	fld.d	$f28, \tmp, THREAD_FPR28 - THREAD_FPR0
268 	fld.d	$f29, \tmp, THREAD_FPR29 - THREAD_FPR0
269 	fld.d	$f30, \tmp, THREAD_FPR30 - THREAD_FPR0
270 	fld.d	$f31, \tmp, THREAD_FPR31 - THREAD_FPR0
271 	.endm
272 
273 	.macro	lsx_save_data thread tmp
274 	li.w	\tmp, THREAD_FPR0
275 	PTR_ADD \tmp, \thread, \tmp
276 	vst	$vr0, \tmp, THREAD_FPR0  - THREAD_FPR0
277 	vst	$vr1, \tmp, THREAD_FPR1  - THREAD_FPR0
278 	vst	$vr2, \tmp, THREAD_FPR2  - THREAD_FPR0
279 	vst	$vr3, \tmp, THREAD_FPR3  - THREAD_FPR0
280 	vst	$vr4, \tmp, THREAD_FPR4  - THREAD_FPR0
281 	vst	$vr5, \tmp, THREAD_FPR5  - THREAD_FPR0
282 	vst	$vr6, \tmp, THREAD_FPR6  - THREAD_FPR0
283 	vst	$vr7, \tmp, THREAD_FPR7  - THREAD_FPR0
284 	vst	$vr8, \tmp, THREAD_FPR8  - THREAD_FPR0
285 	vst	$vr9, \tmp, THREAD_FPR9  - THREAD_FPR0
286 	vst	$vr10, \tmp, THREAD_FPR10 - THREAD_FPR0
287 	vst	$vr11, \tmp, THREAD_FPR11 - THREAD_FPR0
288 	vst	$vr12, \tmp, THREAD_FPR12 - THREAD_FPR0
289 	vst	$vr13, \tmp, THREAD_FPR13 - THREAD_FPR0
290 	vst	$vr14, \tmp, THREAD_FPR14 - THREAD_FPR0
291 	vst	$vr15, \tmp, THREAD_FPR15 - THREAD_FPR0
292 	vst	$vr16, \tmp, THREAD_FPR16 - THREAD_FPR0
293 	vst	$vr17, \tmp, THREAD_FPR17 - THREAD_FPR0
294 	vst	$vr18, \tmp, THREAD_FPR18 - THREAD_FPR0
295 	vst	$vr19, \tmp, THREAD_FPR19 - THREAD_FPR0
296 	vst	$vr20, \tmp, THREAD_FPR20 - THREAD_FPR0
297 	vst	$vr21, \tmp, THREAD_FPR21 - THREAD_FPR0
298 	vst	$vr22, \tmp, THREAD_FPR22 - THREAD_FPR0
299 	vst	$vr23, \tmp, THREAD_FPR23 - THREAD_FPR0
300 	vst	$vr24, \tmp, THREAD_FPR24 - THREAD_FPR0
301 	vst	$vr25, \tmp, THREAD_FPR25 - THREAD_FPR0
302 	vst	$vr26, \tmp, THREAD_FPR26 - THREAD_FPR0
303 	vst	$vr27, \tmp, THREAD_FPR27 - THREAD_FPR0
304 	vst	$vr28, \tmp, THREAD_FPR28 - THREAD_FPR0
305 	vst	$vr29, \tmp, THREAD_FPR29 - THREAD_FPR0
306 	vst	$vr30, \tmp, THREAD_FPR30 - THREAD_FPR0
307 	vst	$vr31, \tmp, THREAD_FPR31 - THREAD_FPR0
308 	.endm
309 
310 	.macro	lsx_restore_data thread tmp
311 	li.w	\tmp, THREAD_FPR0
312 	PTR_ADD	\tmp, \thread, \tmp
313 	vld	$vr0, \tmp, THREAD_FPR0  - THREAD_FPR0
314 	vld	$vr1, \tmp, THREAD_FPR1  - THREAD_FPR0
315 	vld	$vr2, \tmp, THREAD_FPR2  - THREAD_FPR0
316 	vld	$vr3, \tmp, THREAD_FPR3  - THREAD_FPR0
317 	vld	$vr4, \tmp, THREAD_FPR4  - THREAD_FPR0
318 	vld	$vr5, \tmp, THREAD_FPR5  - THREAD_FPR0
319 	vld	$vr6, \tmp, THREAD_FPR6  - THREAD_FPR0
320 	vld	$vr7, \tmp, THREAD_FPR7  - THREAD_FPR0
321 	vld	$vr8, \tmp, THREAD_FPR8  - THREAD_FPR0
322 	vld	$vr9, \tmp, THREAD_FPR9  - THREAD_FPR0
323 	vld	$vr10, \tmp, THREAD_FPR10 - THREAD_FPR0
324 	vld	$vr11, \tmp, THREAD_FPR11 - THREAD_FPR0
325 	vld	$vr12, \tmp, THREAD_FPR12 - THREAD_FPR0
326 	vld	$vr13, \tmp, THREAD_FPR13 - THREAD_FPR0
327 	vld	$vr14, \tmp, THREAD_FPR14 - THREAD_FPR0
328 	vld	$vr15, \tmp, THREAD_FPR15 - THREAD_FPR0
329 	vld	$vr16, \tmp, THREAD_FPR16 - THREAD_FPR0
330 	vld	$vr17, \tmp, THREAD_FPR17 - THREAD_FPR0
331 	vld	$vr18, \tmp, THREAD_FPR18 - THREAD_FPR0
332 	vld	$vr19, \tmp, THREAD_FPR19 - THREAD_FPR0
333 	vld	$vr20, \tmp, THREAD_FPR20 - THREAD_FPR0
334 	vld	$vr21, \tmp, THREAD_FPR21 - THREAD_FPR0
335 	vld	$vr22, \tmp, THREAD_FPR22 - THREAD_FPR0
336 	vld	$vr23, \tmp, THREAD_FPR23 - THREAD_FPR0
337 	vld	$vr24, \tmp, THREAD_FPR24 - THREAD_FPR0
338 	vld	$vr25, \tmp, THREAD_FPR25 - THREAD_FPR0
339 	vld	$vr26, \tmp, THREAD_FPR26 - THREAD_FPR0
340 	vld	$vr27, \tmp, THREAD_FPR27 - THREAD_FPR0
341 	vld	$vr28, \tmp, THREAD_FPR28 - THREAD_FPR0
342 	vld	$vr29, \tmp, THREAD_FPR29 - THREAD_FPR0
343 	vld	$vr30, \tmp, THREAD_FPR30 - THREAD_FPR0
344 	vld	$vr31, \tmp, THREAD_FPR31 - THREAD_FPR0
345 	.endm
346 
347 	.macro	lsx_save_all	thread tmp0 tmp1
348 	fpu_save_cc		\thread, \tmp0, \tmp1
349 	fpu_save_csr		\thread, \tmp0
350 	lsx_save_data		\thread, \tmp0
351 	.endm
352 
353 	.macro	lsx_restore_all	thread tmp0 tmp1
354 	lsx_restore_data	\thread, \tmp0
355 	fpu_restore_cc		\thread, \tmp0, \tmp1
356 	fpu_restore_csr		\thread, \tmp0
357 	.endm
358 
359 	.macro	lsx_save_upper vd base tmp off
360 	vpickve2gr.d	\tmp, \vd, 1
361 	st.d		\tmp, \base, (\off+8)
362 	.endm
363 
364 	.macro	lsx_save_all_upper thread base tmp
365 	li.w		\tmp, THREAD_FPR0
366 	PTR_ADD		\base, \thread, \tmp
367 	lsx_save_upper	$vr0,  \base, \tmp, (THREAD_FPR0-THREAD_FPR0)
368 	lsx_save_upper	$vr1,  \base, \tmp, (THREAD_FPR1-THREAD_FPR0)
369 	lsx_save_upper	$vr2,  \base, \tmp, (THREAD_FPR2-THREAD_FPR0)
370 	lsx_save_upper	$vr3,  \base, \tmp, (THREAD_FPR3-THREAD_FPR0)
371 	lsx_save_upper	$vr4,  \base, \tmp, (THREAD_FPR4-THREAD_FPR0)
372 	lsx_save_upper	$vr5,  \base, \tmp, (THREAD_FPR5-THREAD_FPR0)
373 	lsx_save_upper	$vr6,  \base, \tmp, (THREAD_FPR6-THREAD_FPR0)
374 	lsx_save_upper	$vr7,  \base, \tmp, (THREAD_FPR7-THREAD_FPR0)
375 	lsx_save_upper	$vr8,  \base, \tmp, (THREAD_FPR8-THREAD_FPR0)
376 	lsx_save_upper	$vr9,  \base, \tmp, (THREAD_FPR9-THREAD_FPR0)
377 	lsx_save_upper	$vr10, \base, \tmp, (THREAD_FPR10-THREAD_FPR0)
378 	lsx_save_upper	$vr11, \base, \tmp, (THREAD_FPR11-THREAD_FPR0)
379 	lsx_save_upper	$vr12, \base, \tmp, (THREAD_FPR12-THREAD_FPR0)
380 	lsx_save_upper	$vr13, \base, \tmp, (THREAD_FPR13-THREAD_FPR0)
381 	lsx_save_upper	$vr14, \base, \tmp, (THREAD_FPR14-THREAD_FPR0)
382 	lsx_save_upper	$vr15, \base, \tmp, (THREAD_FPR15-THREAD_FPR0)
383 	lsx_save_upper	$vr16, \base, \tmp, (THREAD_FPR16-THREAD_FPR0)
384 	lsx_save_upper	$vr17, \base, \tmp, (THREAD_FPR17-THREAD_FPR0)
385 	lsx_save_upper	$vr18, \base, \tmp, (THREAD_FPR18-THREAD_FPR0)
386 	lsx_save_upper	$vr19, \base, \tmp, (THREAD_FPR19-THREAD_FPR0)
387 	lsx_save_upper	$vr20, \base, \tmp, (THREAD_FPR20-THREAD_FPR0)
388 	lsx_save_upper	$vr21, \base, \tmp, (THREAD_FPR21-THREAD_FPR0)
389 	lsx_save_upper	$vr22, \base, \tmp, (THREAD_FPR22-THREAD_FPR0)
390 	lsx_save_upper	$vr23, \base, \tmp, (THREAD_FPR23-THREAD_FPR0)
391 	lsx_save_upper	$vr24, \base, \tmp, (THREAD_FPR24-THREAD_FPR0)
392 	lsx_save_upper	$vr25, \base, \tmp, (THREAD_FPR25-THREAD_FPR0)
393 	lsx_save_upper	$vr26, \base, \tmp, (THREAD_FPR26-THREAD_FPR0)
394 	lsx_save_upper	$vr27, \base, \tmp, (THREAD_FPR27-THREAD_FPR0)
395 	lsx_save_upper	$vr28, \base, \tmp, (THREAD_FPR28-THREAD_FPR0)
396 	lsx_save_upper	$vr29, \base, \tmp, (THREAD_FPR29-THREAD_FPR0)
397 	lsx_save_upper	$vr30, \base, \tmp, (THREAD_FPR30-THREAD_FPR0)
398 	lsx_save_upper	$vr31, \base, \tmp, (THREAD_FPR31-THREAD_FPR0)
399 	.endm
400 
401 	.macro	lsx_restore_upper vd base tmp off
402 	ld.d		\tmp, \base, (\off+8)
403 	vinsgr2vr.d	\vd,  \tmp, 1
404 	.endm
405 
406 	.macro	lsx_restore_all_upper thread base tmp
407 	li.w		  \tmp, THREAD_FPR0
408 	PTR_ADD		  \base, \thread, \tmp
409 	lsx_restore_upper $vr0,  \base, \tmp, (THREAD_FPR0-THREAD_FPR0)
410 	lsx_restore_upper $vr1,  \base, \tmp, (THREAD_FPR1-THREAD_FPR0)
411 	lsx_restore_upper $vr2,  \base, \tmp, (THREAD_FPR2-THREAD_FPR0)
412 	lsx_restore_upper $vr3,  \base, \tmp, (THREAD_FPR3-THREAD_FPR0)
413 	lsx_restore_upper $vr4,  \base, \tmp, (THREAD_FPR4-THREAD_FPR0)
414 	lsx_restore_upper $vr5,  \base, \tmp, (THREAD_FPR5-THREAD_FPR0)
415 	lsx_restore_upper $vr6,  \base, \tmp, (THREAD_FPR6-THREAD_FPR0)
416 	lsx_restore_upper $vr7,  \base, \tmp, (THREAD_FPR7-THREAD_FPR0)
417 	lsx_restore_upper $vr8,  \base, \tmp, (THREAD_FPR8-THREAD_FPR0)
418 	lsx_restore_upper $vr9,  \base, \tmp, (THREAD_FPR9-THREAD_FPR0)
419 	lsx_restore_upper $vr10, \base, \tmp, (THREAD_FPR10-THREAD_FPR0)
420 	lsx_restore_upper $vr11, \base, \tmp, (THREAD_FPR11-THREAD_FPR0)
421 	lsx_restore_upper $vr12, \base, \tmp, (THREAD_FPR12-THREAD_FPR0)
422 	lsx_restore_upper $vr13, \base, \tmp, (THREAD_FPR13-THREAD_FPR0)
423 	lsx_restore_upper $vr14, \base, \tmp, (THREAD_FPR14-THREAD_FPR0)
424 	lsx_restore_upper $vr15, \base, \tmp, (THREAD_FPR15-THREAD_FPR0)
425 	lsx_restore_upper $vr16, \base, \tmp, (THREAD_FPR16-THREAD_FPR0)
426 	lsx_restore_upper $vr17, \base, \tmp, (THREAD_FPR17-THREAD_FPR0)
427 	lsx_restore_upper $vr18, \base, \tmp, (THREAD_FPR18-THREAD_FPR0)
428 	lsx_restore_upper $vr19, \base, \tmp, (THREAD_FPR19-THREAD_FPR0)
429 	lsx_restore_upper $vr20, \base, \tmp, (THREAD_FPR20-THREAD_FPR0)
430 	lsx_restore_upper $vr21, \base, \tmp, (THREAD_FPR21-THREAD_FPR0)
431 	lsx_restore_upper $vr22, \base, \tmp, (THREAD_FPR22-THREAD_FPR0)
432 	lsx_restore_upper $vr23, \base, \tmp, (THREAD_FPR23-THREAD_FPR0)
433 	lsx_restore_upper $vr24, \base, \tmp, (THREAD_FPR24-THREAD_FPR0)
434 	lsx_restore_upper $vr25, \base, \tmp, (THREAD_FPR25-THREAD_FPR0)
435 	lsx_restore_upper $vr26, \base, \tmp, (THREAD_FPR26-THREAD_FPR0)
436 	lsx_restore_upper $vr27, \base, \tmp, (THREAD_FPR27-THREAD_FPR0)
437 	lsx_restore_upper $vr28, \base, \tmp, (THREAD_FPR28-THREAD_FPR0)
438 	lsx_restore_upper $vr29, \base, \tmp, (THREAD_FPR29-THREAD_FPR0)
439 	lsx_restore_upper $vr30, \base, \tmp, (THREAD_FPR30-THREAD_FPR0)
440 	lsx_restore_upper $vr31, \base, \tmp, (THREAD_FPR31-THREAD_FPR0)
441 	.endm
442 
443 	.macro	lsx_init_upper vd tmp
444 	vinsgr2vr.d	\vd, \tmp, 1
445 	.endm
446 
447 	.macro	lsx_init_all_upper tmp
448 	not		\tmp, zero
449 	lsx_init_upper	$vr0 \tmp
450 	lsx_init_upper	$vr1 \tmp
451 	lsx_init_upper	$vr2 \tmp
452 	lsx_init_upper	$vr3 \tmp
453 	lsx_init_upper	$vr4 \tmp
454 	lsx_init_upper	$vr5 \tmp
455 	lsx_init_upper	$vr6 \tmp
456 	lsx_init_upper	$vr7 \tmp
457 	lsx_init_upper	$vr8 \tmp
458 	lsx_init_upper	$vr9 \tmp
459 	lsx_init_upper	$vr10 \tmp
460 	lsx_init_upper	$vr11 \tmp
461 	lsx_init_upper	$vr12 \tmp
462 	lsx_init_upper	$vr13 \tmp
463 	lsx_init_upper	$vr14 \tmp
464 	lsx_init_upper	$vr15 \tmp
465 	lsx_init_upper	$vr16 \tmp
466 	lsx_init_upper	$vr17 \tmp
467 	lsx_init_upper	$vr18 \tmp
468 	lsx_init_upper	$vr19 \tmp
469 	lsx_init_upper	$vr20 \tmp
470 	lsx_init_upper	$vr21 \tmp
471 	lsx_init_upper	$vr22 \tmp
472 	lsx_init_upper	$vr23 \tmp
473 	lsx_init_upper	$vr24 \tmp
474 	lsx_init_upper	$vr25 \tmp
475 	lsx_init_upper	$vr26 \tmp
476 	lsx_init_upper	$vr27 \tmp
477 	lsx_init_upper	$vr28 \tmp
478 	lsx_init_upper	$vr29 \tmp
479 	lsx_init_upper	$vr30 \tmp
480 	lsx_init_upper	$vr31 \tmp
481 	.endm
482 
483 	.macro	lasx_save_data thread tmp
484 	li.w	\tmp, THREAD_FPR0
485 	PTR_ADD	\tmp, \thread, \tmp
486 	xvst	$xr0, \tmp, THREAD_FPR0  - THREAD_FPR0
487 	xvst	$xr1, \tmp, THREAD_FPR1  - THREAD_FPR0
488 	xvst	$xr2, \tmp, THREAD_FPR2  - THREAD_FPR0
489 	xvst	$xr3, \tmp, THREAD_FPR3  - THREAD_FPR0
490 	xvst	$xr4, \tmp, THREAD_FPR4  - THREAD_FPR0
491 	xvst	$xr5, \tmp, THREAD_FPR5  - THREAD_FPR0
492 	xvst	$xr6, \tmp, THREAD_FPR6  - THREAD_FPR0
493 	xvst	$xr7, \tmp, THREAD_FPR7  - THREAD_FPR0
494 	xvst	$xr8, \tmp, THREAD_FPR8  - THREAD_FPR0
495 	xvst	$xr9, \tmp, THREAD_FPR9  - THREAD_FPR0
496 	xvst	$xr10, \tmp, THREAD_FPR10 - THREAD_FPR0
497 	xvst	$xr11, \tmp, THREAD_FPR11 - THREAD_FPR0
498 	xvst	$xr12, \tmp, THREAD_FPR12 - THREAD_FPR0
499 	xvst	$xr13, \tmp, THREAD_FPR13 - THREAD_FPR0
500 	xvst	$xr14, \tmp, THREAD_FPR14 - THREAD_FPR0
501 	xvst	$xr15, \tmp, THREAD_FPR15 - THREAD_FPR0
502 	xvst	$xr16, \tmp, THREAD_FPR16 - THREAD_FPR0
503 	xvst	$xr17, \tmp, THREAD_FPR17 - THREAD_FPR0
504 	xvst	$xr18, \tmp, THREAD_FPR18 - THREAD_FPR0
505 	xvst	$xr19, \tmp, THREAD_FPR19 - THREAD_FPR0
506 	xvst	$xr20, \tmp, THREAD_FPR20 - THREAD_FPR0
507 	xvst	$xr21, \tmp, THREAD_FPR21 - THREAD_FPR0
508 	xvst	$xr22, \tmp, THREAD_FPR22 - THREAD_FPR0
509 	xvst	$xr23, \tmp, THREAD_FPR23 - THREAD_FPR0
510 	xvst	$xr24, \tmp, THREAD_FPR24 - THREAD_FPR0
511 	xvst	$xr25, \tmp, THREAD_FPR25 - THREAD_FPR0
512 	xvst	$xr26, \tmp, THREAD_FPR26 - THREAD_FPR0
513 	xvst	$xr27, \tmp, THREAD_FPR27 - THREAD_FPR0
514 	xvst	$xr28, \tmp, THREAD_FPR28 - THREAD_FPR0
515 	xvst	$xr29, \tmp, THREAD_FPR29 - THREAD_FPR0
516 	xvst	$xr30, \tmp, THREAD_FPR30 - THREAD_FPR0
517 	xvst	$xr31, \tmp, THREAD_FPR31 - THREAD_FPR0
518 	.endm
519 
520 	.macro	lasx_restore_data thread tmp
521 	li.w	\tmp, THREAD_FPR0
522 	PTR_ADD	\tmp, \thread, \tmp
523 	xvld	$xr0, \tmp, THREAD_FPR0  - THREAD_FPR0
524 	xvld	$xr1, \tmp, THREAD_FPR1  - THREAD_FPR0
525 	xvld	$xr2, \tmp, THREAD_FPR2  - THREAD_FPR0
526 	xvld	$xr3, \tmp, THREAD_FPR3  - THREAD_FPR0
527 	xvld	$xr4, \tmp, THREAD_FPR4  - THREAD_FPR0
528 	xvld	$xr5, \tmp, THREAD_FPR5  - THREAD_FPR0
529 	xvld	$xr6, \tmp, THREAD_FPR6  - THREAD_FPR0
530 	xvld	$xr7, \tmp, THREAD_FPR7  - THREAD_FPR0
531 	xvld	$xr8, \tmp, THREAD_FPR8  - THREAD_FPR0
532 	xvld	$xr9, \tmp, THREAD_FPR9  - THREAD_FPR0
533 	xvld	$xr10, \tmp, THREAD_FPR10 - THREAD_FPR0
534 	xvld	$xr11, \tmp, THREAD_FPR11 - THREAD_FPR0
535 	xvld	$xr12, \tmp, THREAD_FPR12 - THREAD_FPR0
536 	xvld	$xr13, \tmp, THREAD_FPR13 - THREAD_FPR0
537 	xvld	$xr14, \tmp, THREAD_FPR14 - THREAD_FPR0
538 	xvld	$xr15, \tmp, THREAD_FPR15 - THREAD_FPR0
539 	xvld	$xr16, \tmp, THREAD_FPR16 - THREAD_FPR0
540 	xvld	$xr17, \tmp, THREAD_FPR17 - THREAD_FPR0
541 	xvld	$xr18, \tmp, THREAD_FPR18 - THREAD_FPR0
542 	xvld	$xr19, \tmp, THREAD_FPR19 - THREAD_FPR0
543 	xvld	$xr20, \tmp, THREAD_FPR20 - THREAD_FPR0
544 	xvld	$xr21, \tmp, THREAD_FPR21 - THREAD_FPR0
545 	xvld	$xr22, \tmp, THREAD_FPR22 - THREAD_FPR0
546 	xvld	$xr23, \tmp, THREAD_FPR23 - THREAD_FPR0
547 	xvld	$xr24, \tmp, THREAD_FPR24 - THREAD_FPR0
548 	xvld	$xr25, \tmp, THREAD_FPR25 - THREAD_FPR0
549 	xvld	$xr26, \tmp, THREAD_FPR26 - THREAD_FPR0
550 	xvld	$xr27, \tmp, THREAD_FPR27 - THREAD_FPR0
551 	xvld	$xr28, \tmp, THREAD_FPR28 - THREAD_FPR0
552 	xvld	$xr29, \tmp, THREAD_FPR29 - THREAD_FPR0
553 	xvld	$xr30, \tmp, THREAD_FPR30 - THREAD_FPR0
554 	xvld	$xr31, \tmp, THREAD_FPR31 - THREAD_FPR0
555 	.endm
556 
557 	.macro	lasx_save_all	thread tmp0 tmp1
558 	fpu_save_cc		\thread, \tmp0, \tmp1
559 	fpu_save_csr		\thread, \tmp0
560 	lasx_save_data		\thread, \tmp0
561 	.endm
562 
563 	.macro	lasx_restore_all thread tmp0 tmp1
564 	lasx_restore_data	\thread, \tmp0
565 	fpu_restore_cc		\thread, \tmp0, \tmp1
566 	fpu_restore_csr		\thread, \tmp0
567 	.endm
568 
569 	.macro	lasx_save_upper xd base tmp off
570 	/* Nothing */
571 	.endm
572 
573 	.macro	lasx_save_all_upper thread base tmp
574 	/* Nothing */
575 	.endm
576 
577 	.macro	lasx_restore_upper xd base tmp0 tmp1 off
578 	vld		\tmp0, \base, (\off+16)
579 	xvpermi.q 	\xd,   \tmp1, 0x2
580 	.endm
581 
582 	.macro	lasx_restore_all_upper thread base tmp
583 	li.w		\tmp, THREAD_FPR0
584 	PTR_ADD		\base, \thread, \tmp
585 	/* Save $vr31 ($xr31 lower bits) with xvpickve2gr */
586 	xvpickve2gr.d	$r17, $xr31, 0
587 	xvpickve2gr.d	$r18, $xr31, 1
588 	lasx_restore_upper $xr0, \base, $vr31, $xr31, (THREAD_FPR0-THREAD_FPR0)
589 	lasx_restore_upper $xr1, \base, $vr31, $xr31, (THREAD_FPR1-THREAD_FPR0)
590 	lasx_restore_upper $xr2, \base, $vr31, $xr31, (THREAD_FPR2-THREAD_FPR0)
591 	lasx_restore_upper $xr3, \base, $vr31, $xr31, (THREAD_FPR3-THREAD_FPR0)
592 	lasx_restore_upper $xr4, \base, $vr31, $xr31, (THREAD_FPR4-THREAD_FPR0)
593 	lasx_restore_upper $xr5, \base, $vr31, $xr31, (THREAD_FPR5-THREAD_FPR0)
594 	lasx_restore_upper $xr6, \base, $vr31, $xr31, (THREAD_FPR6-THREAD_FPR0)
595 	lasx_restore_upper $xr7, \base, $vr31, $xr31, (THREAD_FPR7-THREAD_FPR0)
596 	lasx_restore_upper $xr8, \base, $vr31, $xr31, (THREAD_FPR8-THREAD_FPR0)
597 	lasx_restore_upper $xr9, \base, $vr31, $xr31, (THREAD_FPR9-THREAD_FPR0)
598 	lasx_restore_upper $xr10, \base, $vr31, $xr31, (THREAD_FPR10-THREAD_FPR0)
599 	lasx_restore_upper $xr11, \base, $vr31, $xr31, (THREAD_FPR11-THREAD_FPR0)
600 	lasx_restore_upper $xr12, \base, $vr31, $xr31, (THREAD_FPR12-THREAD_FPR0)
601 	lasx_restore_upper $xr13, \base, $vr31, $xr31, (THREAD_FPR13-THREAD_FPR0)
602 	lasx_restore_upper $xr14, \base, $vr31, $xr31, (THREAD_FPR14-THREAD_FPR0)
603 	lasx_restore_upper $xr15, \base, $vr31, $xr31, (THREAD_FPR15-THREAD_FPR0)
604 	lasx_restore_upper $xr16, \base, $vr31, $xr31, (THREAD_FPR16-THREAD_FPR0)
605 	lasx_restore_upper $xr17, \base, $vr31, $xr31, (THREAD_FPR17-THREAD_FPR0)
606 	lasx_restore_upper $xr18, \base, $vr31, $xr31, (THREAD_FPR18-THREAD_FPR0)
607 	lasx_restore_upper $xr19, \base, $vr31, $xr31, (THREAD_FPR19-THREAD_FPR0)
608 	lasx_restore_upper $xr20, \base, $vr31, $xr31, (THREAD_FPR20-THREAD_FPR0)
609 	lasx_restore_upper $xr21, \base, $vr31, $xr31, (THREAD_FPR21-THREAD_FPR0)
610 	lasx_restore_upper $xr22, \base, $vr31, $xr31, (THREAD_FPR22-THREAD_FPR0)
611 	lasx_restore_upper $xr23, \base, $vr31, $xr31, (THREAD_FPR23-THREAD_FPR0)
612 	lasx_restore_upper $xr24, \base, $vr31, $xr31, (THREAD_FPR24-THREAD_FPR0)
613 	lasx_restore_upper $xr25, \base, $vr31, $xr31, (THREAD_FPR25-THREAD_FPR0)
614 	lasx_restore_upper $xr26, \base, $vr31, $xr31, (THREAD_FPR26-THREAD_FPR0)
615 	lasx_restore_upper $xr27, \base, $vr31, $xr31, (THREAD_FPR27-THREAD_FPR0)
616 	lasx_restore_upper $xr28, \base, $vr31, $xr31, (THREAD_FPR28-THREAD_FPR0)
617 	lasx_restore_upper $xr29, \base, $vr31, $xr31, (THREAD_FPR29-THREAD_FPR0)
618 	lasx_restore_upper $xr30, \base, $vr31, $xr31, (THREAD_FPR30-THREAD_FPR0)
619 	lasx_restore_upper $xr31, \base, $vr31, $xr31, (THREAD_FPR31-THREAD_FPR0)
620 	/* Restore $vr31 ($xr31 lower bits) with xvinsgr2vr */
621 	xvinsgr2vr.d	$xr31, $r17, 0
622 	xvinsgr2vr.d	$xr31, $r18, 1
623 	.endm
624 
625 	.macro	lasx_init_upper xd tmp
626 	xvinsgr2vr.d	\xd, \tmp, 2
627 	xvinsgr2vr.d	\xd, \tmp, 3
628 	.endm
629 
630 	.macro	lasx_init_all_upper tmp
631 	not		\tmp, zero
632 	lasx_init_upper	$xr0 \tmp
633 	lasx_init_upper	$xr1 \tmp
634 	lasx_init_upper	$xr2 \tmp
635 	lasx_init_upper	$xr3 \tmp
636 	lasx_init_upper	$xr4 \tmp
637 	lasx_init_upper	$xr5 \tmp
638 	lasx_init_upper	$xr6 \tmp
639 	lasx_init_upper	$xr7 \tmp
640 	lasx_init_upper	$xr8 \tmp
641 	lasx_init_upper	$xr9 \tmp
642 	lasx_init_upper	$xr10 \tmp
643 	lasx_init_upper	$xr11 \tmp
644 	lasx_init_upper	$xr12 \tmp
645 	lasx_init_upper	$xr13 \tmp
646 	lasx_init_upper	$xr14 \tmp
647 	lasx_init_upper	$xr15 \tmp
648 	lasx_init_upper	$xr16 \tmp
649 	lasx_init_upper	$xr17 \tmp
650 	lasx_init_upper	$xr18 \tmp
651 	lasx_init_upper	$xr19 \tmp
652 	lasx_init_upper	$xr20 \tmp
653 	lasx_init_upper	$xr21 \tmp
654 	lasx_init_upper	$xr22 \tmp
655 	lasx_init_upper	$xr23 \tmp
656 	lasx_init_upper	$xr24 \tmp
657 	lasx_init_upper	$xr25 \tmp
658 	lasx_init_upper	$xr26 \tmp
659 	lasx_init_upper	$xr27 \tmp
660 	lasx_init_upper	$xr28 \tmp
661 	lasx_init_upper	$xr29 \tmp
662 	lasx_init_upper	$xr30 \tmp
663 	lasx_init_upper	$xr31 \tmp
664 	.endm
665 
666 .macro not dst src
667 	nor	\dst, \src, zero
668 .endm
669 
670 .macro la_abs reg, sym
671 #ifndef CONFIG_RELOCATABLE
672 	la.abs	\reg, \sym
673 #else
674 	766:
675 	lu12i.w	\reg, 0
676 	ori	\reg, \reg, 0
677 	lu32i.d	\reg, 0
678 	lu52i.d	\reg, \reg, 0
679 	.pushsection ".la_abs", "aw", %progbits
680 	768:
681 	.dword	768b-766b
682 	.dword	\sym
683 	.popsection
684 #endif
685 .endm
686 
687 #endif /* _ASM_ASMMACRO_H */
688