blob: f7db79a846bb42b2d945a3cd22f3c6ad7aef8636 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2003 Ralf Baechle
7 */
8#ifndef _ASM_ASMMACRO_H
9#define _ASM_ASMMACRO_H
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/hazards.h>
Jim Quinlan71ca7582013-11-27 15:34:50 -050012#include <asm/asm-offsets.h>
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070013
Ralf Baechle875d43e2005-09-03 15:56:16 -070014#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/asmmacro-32.h>
16#endif
Ralf Baechle875d43e2005-09-03 15:56:16 -070017#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/asmmacro-64.h>
19#endif
20
Ralf Baechleb6336482014-05-23 16:29:44 +020021#ifdef CONFIG_CPU_MIPSR2
David Daneyb6354db2008-12-10 08:37:25 -080022 .macro local_irq_enable reg=t0
23 ei
24 irq_enable_hazard
25 .endm
26
27 .macro local_irq_disable reg=t0
28 di
29 irq_disable_hazard
30 .endm
Ralf Baechle41c594a2006-04-05 09:45:45 +010031#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 .macro local_irq_enable reg=t0
33 mfc0 \reg, CP0_STATUS
34 ori \reg, \reg, 1
35 mtc0 \reg, CP0_STATUS
36 irq_enable_hazard
37 .endm
38
39 .macro local_irq_disable reg=t0
Jim Quinlan71ca7582013-11-27 15:34:50 -050040#ifdef CONFIG_PREEMPT
41 lw \reg, TI_PRE_COUNT($28)
42 addi \reg, \reg, 1
43 sw \reg, TI_PRE_COUNT($28)
44#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 mfc0 \reg, CP0_STATUS
46 ori \reg, \reg, 1
47 xori \reg, \reg, 1
48 mtc0 \reg, CP0_STATUS
49 irq_disable_hazard
Jim Quinlan71ca7582013-11-27 15:34:50 -050050#ifdef CONFIG_PREEMPT
51 lw \reg, TI_PRE_COUNT($28)
52 addi \reg, \reg, -1
53 sw \reg, TI_PRE_COUNT($28)
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 .endm
Ralf Baechleb6336482014-05-23 16:29:44 +020056#endif /* CONFIG_CPU_MIPSR2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Paul Burton597ce172013-11-22 13:12:07 +000058 .macro fpu_save_16even thread tmp=t0
59 cfc1 \tmp, fcr31
Paul Burton02987632014-01-27 15:23:08 +000060 sdc1 $f0, THREAD_FPR0_LS64(\thread)
61 sdc1 $f2, THREAD_FPR2_LS64(\thread)
62 sdc1 $f4, THREAD_FPR4_LS64(\thread)
63 sdc1 $f6, THREAD_FPR6_LS64(\thread)
64 sdc1 $f8, THREAD_FPR8_LS64(\thread)
65 sdc1 $f10, THREAD_FPR10_LS64(\thread)
66 sdc1 $f12, THREAD_FPR12_LS64(\thread)
67 sdc1 $f14, THREAD_FPR14_LS64(\thread)
68 sdc1 $f16, THREAD_FPR16_LS64(\thread)
69 sdc1 $f18, THREAD_FPR18_LS64(\thread)
70 sdc1 $f20, THREAD_FPR20_LS64(\thread)
71 sdc1 $f22, THREAD_FPR22_LS64(\thread)
72 sdc1 $f24, THREAD_FPR24_LS64(\thread)
73 sdc1 $f26, THREAD_FPR26_LS64(\thread)
74 sdc1 $f28, THREAD_FPR28_LS64(\thread)
75 sdc1 $f30, THREAD_FPR30_LS64(\thread)
Paul Burton597ce172013-11-22 13:12:07 +000076 sw \tmp, THREAD_FCR31(\thread)
77 .endm
78
79 .macro fpu_save_16odd thread
80 .set push
81 .set mips64r2
Paul Burton02987632014-01-27 15:23:08 +000082 sdc1 $f1, THREAD_FPR1_LS64(\thread)
83 sdc1 $f3, THREAD_FPR3_LS64(\thread)
84 sdc1 $f5, THREAD_FPR5_LS64(\thread)
85 sdc1 $f7, THREAD_FPR7_LS64(\thread)
86 sdc1 $f9, THREAD_FPR9_LS64(\thread)
87 sdc1 $f11, THREAD_FPR11_LS64(\thread)
88 sdc1 $f13, THREAD_FPR13_LS64(\thread)
89 sdc1 $f15, THREAD_FPR15_LS64(\thread)
90 sdc1 $f17, THREAD_FPR17_LS64(\thread)
91 sdc1 $f19, THREAD_FPR19_LS64(\thread)
92 sdc1 $f21, THREAD_FPR21_LS64(\thread)
93 sdc1 $f23, THREAD_FPR23_LS64(\thread)
94 sdc1 $f25, THREAD_FPR25_LS64(\thread)
95 sdc1 $f27, THREAD_FPR27_LS64(\thread)
96 sdc1 $f29, THREAD_FPR29_LS64(\thread)
97 sdc1 $f31, THREAD_FPR31_LS64(\thread)
Paul Burton597ce172013-11-22 13:12:07 +000098 .set pop
99 .endm
100
101 .macro fpu_save_double thread status tmp
Paul Bollef5868f02014-02-09 14:32:25 +0100102#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
Paul Burton597ce172013-11-22 13:12:07 +0000103 sll \tmp, \status, 5
104 bgez \tmp, 10f
105 fpu_save_16odd \thread
10610:
107#endif
108 fpu_save_16even \thread \tmp
109 .endm
110
111 .macro fpu_restore_16even thread tmp=t0
112 lw \tmp, THREAD_FCR31(\thread)
Paul Burton02987632014-01-27 15:23:08 +0000113 ldc1 $f0, THREAD_FPR0_LS64(\thread)
114 ldc1 $f2, THREAD_FPR2_LS64(\thread)
115 ldc1 $f4, THREAD_FPR4_LS64(\thread)
116 ldc1 $f6, THREAD_FPR6_LS64(\thread)
117 ldc1 $f8, THREAD_FPR8_LS64(\thread)
118 ldc1 $f10, THREAD_FPR10_LS64(\thread)
119 ldc1 $f12, THREAD_FPR12_LS64(\thread)
120 ldc1 $f14, THREAD_FPR14_LS64(\thread)
121 ldc1 $f16, THREAD_FPR16_LS64(\thread)
122 ldc1 $f18, THREAD_FPR18_LS64(\thread)
123 ldc1 $f20, THREAD_FPR20_LS64(\thread)
124 ldc1 $f22, THREAD_FPR22_LS64(\thread)
125 ldc1 $f24, THREAD_FPR24_LS64(\thread)
126 ldc1 $f26, THREAD_FPR26_LS64(\thread)
127 ldc1 $f28, THREAD_FPR28_LS64(\thread)
128 ldc1 $f30, THREAD_FPR30_LS64(\thread)
Paul Burton597ce172013-11-22 13:12:07 +0000129 ctc1 \tmp, fcr31
130 .endm
131
132 .macro fpu_restore_16odd thread
133 .set push
134 .set mips64r2
Paul Burton02987632014-01-27 15:23:08 +0000135 ldc1 $f1, THREAD_FPR1_LS64(\thread)
136 ldc1 $f3, THREAD_FPR3_LS64(\thread)
137 ldc1 $f5, THREAD_FPR5_LS64(\thread)
138 ldc1 $f7, THREAD_FPR7_LS64(\thread)
139 ldc1 $f9, THREAD_FPR9_LS64(\thread)
140 ldc1 $f11, THREAD_FPR11_LS64(\thread)
141 ldc1 $f13, THREAD_FPR13_LS64(\thread)
142 ldc1 $f15, THREAD_FPR15_LS64(\thread)
143 ldc1 $f17, THREAD_FPR17_LS64(\thread)
144 ldc1 $f19, THREAD_FPR19_LS64(\thread)
145 ldc1 $f21, THREAD_FPR21_LS64(\thread)
146 ldc1 $f23, THREAD_FPR23_LS64(\thread)
147 ldc1 $f25, THREAD_FPR25_LS64(\thread)
148 ldc1 $f27, THREAD_FPR27_LS64(\thread)
149 ldc1 $f29, THREAD_FPR29_LS64(\thread)
150 ldc1 $f31, THREAD_FPR31_LS64(\thread)
Paul Burton597ce172013-11-22 13:12:07 +0000151 .set pop
152 .endm
153
154 .macro fpu_restore_double thread status tmp
Paul Bollef5868f02014-02-09 14:32:25 +0100155#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
Paul Burton597ce172013-11-22 13:12:07 +0000156 sll \tmp, \status, 5
157 bgez \tmp, 10f # 16 register mode?
158
159 fpu_restore_16odd \thread
16010:
161#endif
162 fpu_restore_16even \thread \tmp
163 .endm
164
Paul Burton1d688082014-01-15 10:31:49 +0000165#ifdef CONFIG_CPU_MIPSR2
166 .macro _EXT rd, rs, p, s
167 ext \rd, \rs, \p, \s
168 .endm
169#else /* !CONFIG_CPU_MIPSR2 */
170 .macro _EXT rd, rs, p, s
171 srl \rd, \rs, \p
172 andi \rd, \rd, (1 << \s) - 1
173 .endm
174#endif /* !CONFIG_CPU_MIPSR2 */
175
Ralf Baechle41c594a2006-04-05 09:45:45 +0100176/*
177 * Temporary until all gas have MT ASE support
178 */
179 .macro DMT reg=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100180 .word 0x41600bc1 | (\reg << 16)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100181 .endm
182
183 .macro EMT reg=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100184 .word 0x41600be1 | (\reg << 16)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100185 .endm
186
187 .macro DVPE reg=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100188 .word 0x41600001 | (\reg << 16)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100189 .endm
190
191 .macro EVPE reg=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100192 .word 0x41600021 | (\reg << 16)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100193 .endm
194
195 .macro MFTR rt=0, rd=0, u=0, sel=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100196 .word 0x41000000 | (\rt << 16) | (\rd << 11) | (\u << 5) | (\sel)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100197 .endm
198
199 .macro MTTR rt=0, rd=0, u=0, sel=0
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100200 .word 0x41800000 | (\rt << 16) | (\rd << 11) | (\u << 5) | (\sel)
Ralf Baechle41c594a2006-04-05 09:45:45 +0100201 .endm
202
Paul Burton7f65afb2014-01-27 15:23:09 +0000203#ifdef TOOLCHAIN_SUPPORTS_MSA
204 .macro ld_d wd, off, base
205 .set push
206 .set mips32r2
207 .set msa
208 ld.d $w\wd, \off(\base)
209 .set pop
210 .endm
211
212 .macro st_d wd, off, base
213 .set push
214 .set mips32r2
215 .set msa
216 st.d $w\wd, \off(\base)
217 .set pop
218 .endm
219
220 .macro copy_u_w rd, ws, n
221 .set push
222 .set mips32r2
223 .set msa
224 copy_u.w \rd, $w\ws[\n]
225 .set pop
226 .endm
227
228 .macro copy_u_d rd, ws, n
229 .set push
230 .set mips64r2
231 .set msa
232 copy_u.d \rd, $w\ws[\n]
233 .set pop
234 .endm
235
236 .macro insert_w wd, n, rs
237 .set push
238 .set mips32r2
239 .set msa
240 insert.w $w\wd[\n], \rs
241 .set pop
242 .endm
243
244 .macro insert_d wd, n, rs
245 .set push
246 .set mips64r2
247 .set msa
248 insert.d $w\wd[\n], \rs
249 .set pop
250 .endm
251#else
252 /*
253 * Temporary until all toolchains in use include MSA support.
254 */
255 .macro cfcmsa rd, cs
256 .set push
257 .set noat
258 .word 0x787e0059 | (\cs << 11)
259 move \rd, $1
260 .set pop
261 .endm
262
263 .macro ctcmsa cd, rs
264 .set push
265 .set noat
266 move $1, \rs
267 .word 0x783e0819 | (\cd << 6)
268 .set pop
269 .endm
270
271 .macro ld_d wd, off, base
272 .set push
273 .set noat
274 add $1, \base, \off
275 .word 0x78000823 | (\wd << 6)
276 .set pop
277 .endm
278
279 .macro st_d wd, off, base
280 .set push
281 .set noat
282 add $1, \base, \off
283 .word 0x78000827 | (\wd << 6)
284 .set pop
285 .endm
286
287 .macro copy_u_w rd, ws, n
288 .set push
289 .set noat
290 .word 0x78f00059 | (\n << 16) | (\ws << 11)
291 /* move triggers an assembler bug... */
292 or \rd, $1, zero
293 .set pop
294 .endm
295
296 .macro copy_u_d rd, ws, n
297 .set push
298 .set noat
299 .word 0x78f80059 | (\n << 16) | (\ws << 11)
300 /* move triggers an assembler bug... */
301 or \rd, $1, zero
302 .set pop
303 .endm
304
305 .macro insert_w wd, n, rs
306 .set push
307 .set noat
308 /* move triggers an assembler bug... */
309 or $1, \rs, zero
310 .word 0x79300819 | (\n << 16) | (\wd << 6)
311 .set pop
312 .endm
313
314 .macro insert_d wd, n, rs
315 .set push
316 .set noat
317 /* move triggers an assembler bug... */
318 or $1, \rs, zero
319 .word 0x79380819 | (\n << 16) | (\wd << 6)
320 .set pop
321 .endm
322#endif
323
Paul Burton1db1af82014-01-27 15:23:11 +0000324 .macro msa_save_all thread
325 st_d 0, THREAD_FPR0, \thread
326 st_d 1, THREAD_FPR1, \thread
327 st_d 2, THREAD_FPR2, \thread
328 st_d 3, THREAD_FPR3, \thread
329 st_d 4, THREAD_FPR4, \thread
330 st_d 5, THREAD_FPR5, \thread
331 st_d 6, THREAD_FPR6, \thread
332 st_d 7, THREAD_FPR7, \thread
333 st_d 8, THREAD_FPR8, \thread
334 st_d 9, THREAD_FPR9, \thread
335 st_d 10, THREAD_FPR10, \thread
336 st_d 11, THREAD_FPR11, \thread
337 st_d 12, THREAD_FPR12, \thread
338 st_d 13, THREAD_FPR13, \thread
339 st_d 14, THREAD_FPR14, \thread
340 st_d 15, THREAD_FPR15, \thread
341 st_d 16, THREAD_FPR16, \thread
342 st_d 17, THREAD_FPR17, \thread
343 st_d 18, THREAD_FPR18, \thread
344 st_d 19, THREAD_FPR19, \thread
345 st_d 20, THREAD_FPR20, \thread
346 st_d 21, THREAD_FPR21, \thread
347 st_d 22, THREAD_FPR22, \thread
348 st_d 23, THREAD_FPR23, \thread
349 st_d 24, THREAD_FPR24, \thread
350 st_d 25, THREAD_FPR25, \thread
351 st_d 26, THREAD_FPR26, \thread
352 st_d 27, THREAD_FPR27, \thread
353 st_d 28, THREAD_FPR28, \thread
354 st_d 29, THREAD_FPR29, \thread
355 st_d 30, THREAD_FPR30, \thread
356 st_d 31, THREAD_FPR31, \thread
357 .endm
358
359 .macro msa_restore_all thread
360 ld_d 0, THREAD_FPR0, \thread
361 ld_d 1, THREAD_FPR1, \thread
362 ld_d 2, THREAD_FPR2, \thread
363 ld_d 3, THREAD_FPR3, \thread
364 ld_d 4, THREAD_FPR4, \thread
365 ld_d 5, THREAD_FPR5, \thread
366 ld_d 6, THREAD_FPR6, \thread
367 ld_d 7, THREAD_FPR7, \thread
368 ld_d 8, THREAD_FPR8, \thread
369 ld_d 9, THREAD_FPR9, \thread
370 ld_d 10, THREAD_FPR10, \thread
371 ld_d 11, THREAD_FPR11, \thread
372 ld_d 12, THREAD_FPR12, \thread
373 ld_d 13, THREAD_FPR13, \thread
374 ld_d 14, THREAD_FPR14, \thread
375 ld_d 15, THREAD_FPR15, \thread
376 ld_d 16, THREAD_FPR16, \thread
377 ld_d 17, THREAD_FPR17, \thread
378 ld_d 18, THREAD_FPR18, \thread
379 ld_d 19, THREAD_FPR19, \thread
380 ld_d 20, THREAD_FPR20, \thread
381 ld_d 21, THREAD_FPR21, \thread
382 ld_d 22, THREAD_FPR22, \thread
383 ld_d 23, THREAD_FPR23, \thread
384 ld_d 24, THREAD_FPR24, \thread
385 ld_d 25, THREAD_FPR25, \thread
386 ld_d 26, THREAD_FPR26, \thread
387 ld_d 27, THREAD_FPR27, \thread
388 ld_d 28, THREAD_FPR28, \thread
389 ld_d 29, THREAD_FPR29, \thread
390 ld_d 30, THREAD_FPR30, \thread
391 ld_d 31, THREAD_FPR31, \thread
392 .endm
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#endif /* _ASM_ASMMACRO_H */