Skip to content

Commit eec43a2

Browse files
paulburtonralfbaechle
authored andcommitted
MIPS: Save/restore MSA context around signals
This patch extends sigcontext in order to hold the most significant 64 bits of each vector register in addition to the MSA control & status register. The least significant 64 bits are already saved as the scalar FP context. This makes things a little awkward since the least & most significant 64 bits of each vector register are not contiguous in memory. Thus the copy_u & insert instructions are used to transfer the values of the most significant 64 bits via GP registers. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/6533/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent a8ad136 commit eec43a2

6 files changed

Lines changed: 357 additions & 16 deletions

File tree

‎arch/mips/include/asm/sigcontext.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct sigcontext32 {
3232
__u32 sc_lo2;
3333
__u32 sc_hi3;
3434
__u32 sc_lo3;
35+
__u64 sc_msaregs[32]; /* Most significant 64 bits */
36+
__u32 sc_msa_csr;
3537
};
3638
#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 || _MIPS_SIM == _MIPS_SIM_NABI32 */
3739
#endif /* _ASM_SIGCONTEXT_H */

‎arch/mips/include/uapi/asm/sigcontext.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <linux/types.h>
1313
#include <asm/sgidefs.h>
1414

15+
/* Bits which may be set in sc_used_math */
16+
#define USEDMATH_FP (1 << 0)
17+
#define USEDMATH_MSA (1 << 1)
18+
1519
#if _MIPS_SIM == _MIPS_SIM_ABI32
1620

1721
/*
@@ -37,6 +41,8 @@ struct sigcontext {
3741
unsigned long sc_lo2;
3842
unsigned long sc_hi3;
3943
unsigned long sc_lo3;
44+
unsigned long long sc_msaregs[32]; /* Most significant 64 bits */
45+
unsigned long sc_msa_csr;
4046
};
4147

4248
#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
@@ -70,6 +76,8 @@ struct sigcontext {
7076
__u32 sc_used_math;
7177
__u32 sc_dsp;
7278
__u32 sc_reserved;
79+
__u64 sc_msaregs[32];
80+
__u32 sc_msa_csr;
7381
};
7482

7583

‎arch/mips/kernel/asm-offsets.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void output_sc_defines(void)
295295
OFFSET(SC_LO2, sigcontext, sc_lo2);
296296
OFFSET(SC_HI3, sigcontext, sc_hi3);
297297
OFFSET(SC_LO3, sigcontext, sc_lo3);
298+
OFFSET(SC_MSAREGS, sigcontext, sc_msaregs);
298299
BLANK();
299300
}
300301
#endif
@@ -309,6 +310,7 @@ void output_sc_defines(void)
309310
OFFSET(SC_MDLO, sigcontext, sc_mdlo);
310311
OFFSET(SC_PC, sigcontext, sc_pc);
311312
OFFSET(SC_FPC_CSR, sigcontext, sc_fpc_csr);
313+
OFFSET(SC_MSAREGS, sigcontext, sc_msaregs);
312314
BLANK();
313315
}
314316
#endif
@@ -320,6 +322,7 @@ void output_sc32_defines(void)
320322
OFFSET(SC32_FPREGS, sigcontext32, sc_fpregs);
321323
OFFSET(SC32_FPC_CSR, sigcontext32, sc_fpc_csr);
322324
OFFSET(SC32_FPC_EIR, sigcontext32, sc_fpc_eir);
325+
OFFSET(SC32_MSAREGS, sigcontext32, sc_msaregs);
323326
BLANK();
324327
}
325328
#endif

‎arch/mips/kernel/r4k_fpu.S‎

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (C) 1999, 2001 Silicon Graphics, Inc.
1414
*/
1515
#include <asm/asm.h>
16+
#include <asm/asmmacro.h>
1617
#include <asm/errno.h>
1718
#include <asm/fpregdef.h>
1819
#include <asm/mipsregs.h>
@@ -245,6 +246,218 @@ LEAF(_restore_fp_context32)
245246
END(_restore_fp_context32)
246247
#endif
247248

249+
#ifdef CONFIG_CPU_HAS_MSA
250+
251+
.macro save_sc_msareg wr, off, sc, tmp
252+
#ifdef CONFIG_64BIT
253+
copy_u_d \tmp, \wr, 1
254+
EX sd \tmp, (\off+(\wr*8))(\sc)
255+
#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
256+
copy_u_w \tmp, \wr, 2
257+
EX sw \tmp, (\off+(\wr*8)+0)(\sc)
258+
copy_u_w \tmp, \wr, 3
259+
EX sw \tmp, (\off+(\wr*8)+4)(\sc)
260+
#else /* CONFIG_CPU_BIG_ENDIAN */
261+
copy_u_w \tmp, \wr, 2
262+
EX sw \tmp, (\off+(\wr*8)+4)(\sc)
263+
copy_u_w \tmp, \wr, 3
264+
EX sw \tmp, (\off+(\wr*8)+0)(\sc)
265+
#endif
266+
.endm
267+
268+
/*
269+
* int _save_msa_context(struct sigcontext *sc)
270+
*
271+
* Save the upper 64 bits of each vector register along with the MSA_CSR
272+
* register into sc. Returns zero on success, else non-zero.
273+
*/
274+
LEAF(_save_msa_context)
275+
save_sc_msareg 0, SC_MSAREGS, a0, t0
276+
save_sc_msareg 1, SC_MSAREGS, a0, t0
277+
save_sc_msareg 2, SC_MSAREGS, a0, t0
278+
save_sc_msareg 3, SC_MSAREGS, a0, t0
279+
save_sc_msareg 4, SC_MSAREGS, a0, t0
280+
save_sc_msareg 5, SC_MSAREGS, a0, t0
281+
save_sc_msareg 6, SC_MSAREGS, a0, t0
282+
save_sc_msareg 7, SC_MSAREGS, a0, t0
283+
save_sc_msareg 8, SC_MSAREGS, a0, t0
284+
save_sc_msareg 9, SC_MSAREGS, a0, t0
285+
save_sc_msareg 10, SC_MSAREGS, a0, t0
286+
save_sc_msareg 11, SC_MSAREGS, a0, t0
287+
save_sc_msareg 12, SC_MSAREGS, a0, t0
288+
save_sc_msareg 13, SC_MSAREGS, a0, t0
289+
save_sc_msareg 14, SC_MSAREGS, a0, t0
290+
save_sc_msareg 15, SC_MSAREGS, a0, t0
291+
save_sc_msareg 16, SC_MSAREGS, a0, t0
292+
save_sc_msareg 17, SC_MSAREGS, a0, t0
293+
save_sc_msareg 18, SC_MSAREGS, a0, t0
294+
save_sc_msareg 19, SC_MSAREGS, a0, t0
295+
save_sc_msareg 20, SC_MSAREGS, a0, t0
296+
save_sc_msareg 21, SC_MSAREGS, a0, t0
297+
save_sc_msareg 22, SC_MSAREGS, a0, t0
298+
save_sc_msareg 23, SC_MSAREGS, a0, t0
299+
save_sc_msareg 24, SC_MSAREGS, a0, t0
300+
save_sc_msareg 25, SC_MSAREGS, a0, t0
301+
save_sc_msareg 26, SC_MSAREGS, a0, t0
302+
save_sc_msareg 27, SC_MSAREGS, a0, t0
303+
save_sc_msareg 28, SC_MSAREGS, a0, t0
304+
save_sc_msareg 29, SC_MSAREGS, a0, t0
305+
save_sc_msareg 30, SC_MSAREGS, a0, t0
306+
save_sc_msareg 31, SC_MSAREGS, a0, t0
307+
jr ra
308+
li v0, 0
309+
END(_save_msa_context)
310+
311+
#ifdef CONFIG_MIPS32_COMPAT
312+
313+
/*
314+
* int _save_msa_context32(struct sigcontext32 *sc)
315+
*
316+
* Save the upper 64 bits of each vector register along with the MSA_CSR
317+
* register into sc. Returns zero on success, else non-zero.
318+
*/
319+
LEAF(_save_msa_context32)
320+
save_sc_msareg 0, SC32_MSAREGS, a0, t0
321+
save_sc_msareg 1, SC32_MSAREGS, a0, t0
322+
save_sc_msareg 2, SC32_MSAREGS, a0, t0
323+
save_sc_msareg 3, SC32_MSAREGS, a0, t0
324+
save_sc_msareg 4, SC32_MSAREGS, a0, t0
325+
save_sc_msareg 5, SC32_MSAREGS, a0, t0
326+
save_sc_msareg 6, SC32_MSAREGS, a0, t0
327+
save_sc_msareg 7, SC32_MSAREGS, a0, t0
328+
save_sc_msareg 8, SC32_MSAREGS, a0, t0
329+
save_sc_msareg 9, SC32_MSAREGS, a0, t0
330+
save_sc_msareg 10, SC32_MSAREGS, a0, t0
331+
save_sc_msareg 11, SC32_MSAREGS, a0, t0
332+
save_sc_msareg 12, SC32_MSAREGS, a0, t0
333+
save_sc_msareg 13, SC32_MSAREGS, a0, t0
334+
save_sc_msareg 14, SC32_MSAREGS, a0, t0
335+
save_sc_msareg 15, SC32_MSAREGS, a0, t0
336+
save_sc_msareg 16, SC32_MSAREGS, a0, t0
337+
save_sc_msareg 17, SC32_MSAREGS, a0, t0
338+
save_sc_msareg 18, SC32_MSAREGS, a0, t0
339+
save_sc_msareg 19, SC32_MSAREGS, a0, t0
340+
save_sc_msareg 20, SC32_MSAREGS, a0, t0
341+
save_sc_msareg 21, SC32_MSAREGS, a0, t0
342+
save_sc_msareg 22, SC32_MSAREGS, a0, t0
343+
save_sc_msareg 23, SC32_MSAREGS, a0, t0
344+
save_sc_msareg 24, SC32_MSAREGS, a0, t0
345+
save_sc_msareg 25, SC32_MSAREGS, a0, t0
346+
save_sc_msareg 26, SC32_MSAREGS, a0, t0
347+
save_sc_msareg 27, SC32_MSAREGS, a0, t0
348+
save_sc_msareg 28, SC32_MSAREGS, a0, t0
349+
save_sc_msareg 29, SC32_MSAREGS, a0, t0
350+
save_sc_msareg 30, SC32_MSAREGS, a0, t0
351+
save_sc_msareg 31, SC32_MSAREGS, a0, t0
352+
jr ra
353+
li v0, 0
354+
END(_save_msa_context32)
355+
356+
#endif /* CONFIG_MIPS32_COMPAT */
357+
358+
.macro restore_sc_msareg wr, off, sc, tmp
359+
#ifdef CONFIG_64BIT
360+
EX ld \tmp, (\off+(\wr*8))(\sc)
361+
insert_d \wr, 1, \tmp
362+
#elif defined(CONFIG_CPU_LITTLE_ENDIAN)
363+
EX lw \tmp, (\off+(\wr*8)+0)(\sc)
364+
insert_w \wr, 2, \tmp
365+
EX lw \tmp, (\off+(\wr*8)+4)(\sc)
366+
insert_w \wr, 3, \tmp
367+
#else /* CONFIG_CPU_BIG_ENDIAN */
368+
EX lw \tmp, (\off+(\wr*8)+4)(\sc)
369+
insert_w \wr, 2, \tmp
370+
EX lw \tmp, (\off+(\wr*8)+0)(\sc)
371+
insert_w \wr, 3, \tmp
372+
#endif
373+
.endm
374+
375+
/*
376+
* int _restore_msa_context(struct sigcontext *sc)
377+
*/
378+
LEAF(_restore_msa_context)
379+
restore_sc_msareg 0, SC_MSAREGS, a0, t0
380+
restore_sc_msareg 1, SC_MSAREGS, a0, t0
381+
restore_sc_msareg 2, SC_MSAREGS, a0, t0
382+
restore_sc_msareg 3, SC_MSAREGS, a0, t0
383+
restore_sc_msareg 4, SC_MSAREGS, a0, t0
384+
restore_sc_msareg 5, SC_MSAREGS, a0, t0
385+
restore_sc_msareg 6, SC_MSAREGS, a0, t0
386+
restore_sc_msareg 7, SC_MSAREGS, a0, t0
387+
restore_sc_msareg 8, SC_MSAREGS, a0, t0
388+
restore_sc_msareg 9, SC_MSAREGS, a0, t0
389+
restore_sc_msareg 10, SC_MSAREGS, a0, t0
390+
restore_sc_msareg 11, SC_MSAREGS, a0, t0
391+
restore_sc_msareg 12, SC_MSAREGS, a0, t0
392+
restore_sc_msareg 13, SC_MSAREGS, a0, t0
393+
restore_sc_msareg 14, SC_MSAREGS, a0, t0
394+
restore_sc_msareg 15, SC_MSAREGS, a0, t0
395+
restore_sc_msareg 16, SC_MSAREGS, a0, t0
396+
restore_sc_msareg 17, SC_MSAREGS, a0, t0
397+
restore_sc_msareg 18, SC_MSAREGS, a0, t0
398+
restore_sc_msareg 19, SC_MSAREGS, a0, t0
399+
restore_sc_msareg 20, SC_MSAREGS, a0, t0
400+
restore_sc_msareg 21, SC_MSAREGS, a0, t0
401+
restore_sc_msareg 22, SC_MSAREGS, a0, t0
402+
restore_sc_msareg 23, SC_MSAREGS, a0, t0
403+
restore_sc_msareg 24, SC_MSAREGS, a0, t0
404+
restore_sc_msareg 25, SC_MSAREGS, a0, t0
405+
restore_sc_msareg 26, SC_MSAREGS, a0, t0
406+
restore_sc_msareg 27, SC_MSAREGS, a0, t0
407+
restore_sc_msareg 28, SC_MSAREGS, a0, t0
408+
restore_sc_msareg 29, SC_MSAREGS, a0, t0
409+
restore_sc_msareg 30, SC_MSAREGS, a0, t0
410+
restore_sc_msareg 31, SC_MSAREGS, a0, t0
411+
jr ra
412+
li v0, 0
413+
END(_restore_msa_context)
414+
415+
#ifdef CONFIG_MIPS32_COMPAT
416+
417+
/*
418+
* int _restore_msa_context32(struct sigcontext32 *sc)
419+
*/
420+
LEAF(_restore_msa_context32)
421+
restore_sc_msareg 0, SC32_MSAREGS, a0, t0
422+
restore_sc_msareg 1, SC32_MSAREGS, a0, t0
423+
restore_sc_msareg 2, SC32_MSAREGS, a0, t0
424+
restore_sc_msareg 3, SC32_MSAREGS, a0, t0
425+
restore_sc_msareg 4, SC32_MSAREGS, a0, t0
426+
restore_sc_msareg 5, SC32_MSAREGS, a0, t0
427+
restore_sc_msareg 6, SC32_MSAREGS, a0, t0
428+
restore_sc_msareg 7, SC32_MSAREGS, a0, t0
429+
restore_sc_msareg 8, SC32_MSAREGS, a0, t0
430+
restore_sc_msareg 9, SC32_MSAREGS, a0, t0
431+
restore_sc_msareg 10, SC32_MSAREGS, a0, t0
432+
restore_sc_msareg 11, SC32_MSAREGS, a0, t0
433+
restore_sc_msareg 12, SC32_MSAREGS, a0, t0
434+
restore_sc_msareg 13, SC32_MSAREGS, a0, t0
435+
restore_sc_msareg 14, SC32_MSAREGS, a0, t0
436+
restore_sc_msareg 15, SC32_MSAREGS, a0, t0
437+
restore_sc_msareg 16, SC32_MSAREGS, a0, t0
438+
restore_sc_msareg 17, SC32_MSAREGS, a0, t0
439+
restore_sc_msareg 18, SC32_MSAREGS, a0, t0
440+
restore_sc_msareg 19, SC32_MSAREGS, a0, t0
441+
restore_sc_msareg 20, SC32_MSAREGS, a0, t0
442+
restore_sc_msareg 21, SC32_MSAREGS, a0, t0
443+
restore_sc_msareg 22, SC32_MSAREGS, a0, t0
444+
restore_sc_msareg 23, SC32_MSAREGS, a0, t0
445+
restore_sc_msareg 24, SC32_MSAREGS, a0, t0
446+
restore_sc_msareg 25, SC32_MSAREGS, a0, t0
447+
restore_sc_msareg 26, SC32_MSAREGS, a0, t0
448+
restore_sc_msareg 27, SC32_MSAREGS, a0, t0
449+
restore_sc_msareg 28, SC32_MSAREGS, a0, t0
450+
restore_sc_msareg 29, SC32_MSAREGS, a0, t0
451+
restore_sc_msareg 30, SC32_MSAREGS, a0, t0
452+
restore_sc_msareg 31, SC32_MSAREGS, a0, t0
453+
jr ra
454+
li v0, 0
455+
END(_restore_msa_context32)
456+
457+
#endif /* CONFIG_MIPS32_COMPAT */
458+
459+
#endif /* CONFIG_CPU_HAS_MSA */
460+
248461
.set reorder
249462

250463
.type fault@function

0 commit comments

Comments
 (0)