Commit 2db9ca0a authored by Paul Burton's avatar Paul Burton Committed by Ralf Baechle

MIPS: Use struct mips_abi offsets to save FP context

When saving FP state to struct sigcontext, make use of the offsets
provided by struct mips_abi to obtain appropriate addresses for the
sc_fpregs & sc_fpc_csr fields of the sigcontext. This is done only for
the native struct sigcontext in this patch (ie. for O32 in CONFIG_32BIT
kernels or for N64 in CONFIG_64BIT kernels) but is done in preparation
for sharing this code with compat ABIs in further patches.
Signed-off-by: default avatarPaul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Matthew Fortune <matthew.fortune@imgtec.com>
Cc: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
Cc: linux-kernel@vger.kernel.org
Cc: Richard Weinberger <richard@nod.at>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Markos Chandras <markos.chandras@imgtec.com>
Cc: Manuel Lauss <manuel.lauss@gmail.com>
Cc: Maciej W. Rozycki <macro@codesourcery.com>
Patchwork: https://patchwork.linux-mips.org/patch/10789/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 77856100
...@@ -36,6 +36,14 @@ ...@@ -36,6 +36,14 @@
.set noreorder .set noreorder
/**
* _save_fp_context() - save FP context from the FPU
* @a0 - pointer to fpregs field of sigcontext
* @a1 - pointer to fpc_csr field of sigcontext
*
* Save FP context, including the 32 FP data registers and the FP
* control & status register, from the FPU to signal context.
*/
LEAF(_save_fp_context) LEAF(_save_fp_context)
.set push .set push
SET_HARDFLOAT SET_HARDFLOAT
...@@ -55,45 +63,45 @@ LEAF(_save_fp_context) ...@@ -55,45 +63,45 @@ LEAF(_save_fp_context)
nop nop
#endif #endif
/* Store the 16 odd double precision registers */ /* Store the 16 odd double precision registers */
EX sdc1 $f1, SC_FPREGS+8(a0) EX sdc1 $f1, 8(a0)
EX sdc1 $f3, SC_FPREGS+24(a0) EX sdc1 $f3, 24(a0)
EX sdc1 $f5, SC_FPREGS+40(a0) EX sdc1 $f5, 40(a0)
EX sdc1 $f7, SC_FPREGS+56(a0) EX sdc1 $f7, 56(a0)
EX sdc1 $f9, SC_FPREGS+72(a0) EX sdc1 $f9, 72(a0)
EX sdc1 $f11, SC_FPREGS+88(a0) EX sdc1 $f11, 88(a0)
EX sdc1 $f13, SC_FPREGS+104(a0) EX sdc1 $f13, 104(a0)
EX sdc1 $f15, SC_FPREGS+120(a0) EX sdc1 $f15, 120(a0)
EX sdc1 $f17, SC_FPREGS+136(a0) EX sdc1 $f17, 136(a0)
EX sdc1 $f19, SC_FPREGS+152(a0) EX sdc1 $f19, 152(a0)
EX sdc1 $f21, SC_FPREGS+168(a0) EX sdc1 $f21, 168(a0)
EX sdc1 $f23, SC_FPREGS+184(a0) EX sdc1 $f23, 184(a0)
EX sdc1 $f25, SC_FPREGS+200(a0) EX sdc1 $f25, 200(a0)
EX sdc1 $f27, SC_FPREGS+216(a0) EX sdc1 $f27, 216(a0)
EX sdc1 $f29, SC_FPREGS+232(a0) EX sdc1 $f29, 232(a0)
EX sdc1 $f31, SC_FPREGS+248(a0) EX sdc1 $f31, 248(a0)
1: .set pop 1: .set pop
#endif #endif
.set push .set push
SET_HARDFLOAT SET_HARDFLOAT
/* Store the 16 even double precision registers */ /* Store the 16 even double precision registers */
EX sdc1 $f0, SC_FPREGS+0(a0) EX sdc1 $f0, 0(a0)
EX sdc1 $f2, SC_FPREGS+16(a0) EX sdc1 $f2, 16(a0)
EX sdc1 $f4, SC_FPREGS+32(a0) EX sdc1 $f4, 32(a0)
EX sdc1 $f6, SC_FPREGS+48(a0) EX sdc1 $f6, 48(a0)
EX sdc1 $f8, SC_FPREGS+64(a0) EX sdc1 $f8, 64(a0)
EX sdc1 $f10, SC_FPREGS+80(a0) EX sdc1 $f10, 80(a0)
EX sdc1 $f12, SC_FPREGS+96(a0) EX sdc1 $f12, 96(a0)
EX sdc1 $f14, SC_FPREGS+112(a0) EX sdc1 $f14, 112(a0)
EX sdc1 $f16, SC_FPREGS+128(a0) EX sdc1 $f16, 128(a0)
EX sdc1 $f18, SC_FPREGS+144(a0) EX sdc1 $f18, 144(a0)
EX sdc1 $f20, SC_FPREGS+160(a0) EX sdc1 $f20, 160(a0)
EX sdc1 $f22, SC_FPREGS+176(a0) EX sdc1 $f22, 176(a0)
EX sdc1 $f24, SC_FPREGS+192(a0) EX sdc1 $f24, 192(a0)
EX sdc1 $f26, SC_FPREGS+208(a0) EX sdc1 $f26, 208(a0)
EX sdc1 $f28, SC_FPREGS+224(a0) EX sdc1 $f28, 224(a0)
EX sdc1 $f30, SC_FPREGS+240(a0) EX sdc1 $f30, 240(a0)
EX sw t1, SC_FPC_CSR(a0) EX sw t1, 0(a1)
jr ra jr ra
li v0, 0 # success li v0, 0 # success
.set pop .set pop
...@@ -159,13 +167,16 @@ LEAF(_save_fp_context32) ...@@ -159,13 +167,16 @@ LEAF(_save_fp_context32)
END(_save_fp_context32) END(_save_fp_context32)
#endif #endif
/* /**
* Restore FPU state: * _restore_fp_context() - restore FP context to the FPU
* - fp gp registers * @a0 - pointer to fpregs field of sigcontext
* - cp1 status/control register * @a1 - pointer to fpc_csr field of sigcontext
*
* Restore FP context, including the 32 FP data registers and the FP
* control & status register, from signal context to the FPU.
*/ */
LEAF(_restore_fp_context) LEAF(_restore_fp_context)
EX lw t1, SC_FPC_CSR(a0) EX lw t1, 0(a1)
#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) || \ #if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) || \
defined(CONFIG_CPU_MIPS32_R6) defined(CONFIG_CPU_MIPS32_R6)
...@@ -179,42 +190,42 @@ LEAF(_restore_fp_context) ...@@ -179,42 +190,42 @@ LEAF(_restore_fp_context)
bgez t0, 1f # skip loading odd if FR=0 bgez t0, 1f # skip loading odd if FR=0
nop nop
#endif #endif
EX ldc1 $f1, SC_FPREGS+8(a0) EX ldc1 $f1, 8(a0)
EX ldc1 $f3, SC_FPREGS+24(a0) EX ldc1 $f3, 24(a0)
EX ldc1 $f5, SC_FPREGS+40(a0) EX ldc1 $f5, 40(a0)
EX ldc1 $f7, SC_FPREGS+56(a0) EX ldc1 $f7, 56(a0)
EX ldc1 $f9, SC_FPREGS+72(a0) EX ldc1 $f9, 72(a0)
EX ldc1 $f11, SC_FPREGS+88(a0) EX ldc1 $f11, 88(a0)
EX ldc1 $f13, SC_FPREGS+104(a0) EX ldc1 $f13, 104(a0)
EX ldc1 $f15, SC_FPREGS+120(a0) EX ldc1 $f15, 120(a0)
EX ldc1 $f17, SC_FPREGS+136(a0) EX ldc1 $f17, 136(a0)
EX ldc1 $f19, SC_FPREGS+152(a0) EX ldc1 $f19, 152(a0)
EX ldc1 $f21, SC_FPREGS+168(a0) EX ldc1 $f21, 168(a0)
EX ldc1 $f23, SC_FPREGS+184(a0) EX ldc1 $f23, 184(a0)
EX ldc1 $f25, SC_FPREGS+200(a0) EX ldc1 $f25, 200(a0)
EX ldc1 $f27, SC_FPREGS+216(a0) EX ldc1 $f27, 216(a0)
EX ldc1 $f29, SC_FPREGS+232(a0) EX ldc1 $f29, 232(a0)
EX ldc1 $f31, SC_FPREGS+248(a0) EX ldc1 $f31, 248(a0)
1: .set pop 1: .set pop
#endif #endif
.set push .set push
SET_HARDFLOAT SET_HARDFLOAT
EX ldc1 $f0, SC_FPREGS+0(a0) EX ldc1 $f0, 0(a0)
EX ldc1 $f2, SC_FPREGS+16(a0) EX ldc1 $f2, 16(a0)
EX ldc1 $f4, SC_FPREGS+32(a0) EX ldc1 $f4, 32(a0)
EX ldc1 $f6, SC_FPREGS+48(a0) EX ldc1 $f6, 48(a0)
EX ldc1 $f8, SC_FPREGS+64(a0) EX ldc1 $f8, 64(a0)
EX ldc1 $f10, SC_FPREGS+80(a0) EX ldc1 $f10, 80(a0)
EX ldc1 $f12, SC_FPREGS+96(a0) EX ldc1 $f12, 96(a0)
EX ldc1 $f14, SC_FPREGS+112(a0) EX ldc1 $f14, 112(a0)
EX ldc1 $f16, SC_FPREGS+128(a0) EX ldc1 $f16, 128(a0)
EX ldc1 $f18, SC_FPREGS+144(a0) EX ldc1 $f18, 144(a0)
EX ldc1 $f20, SC_FPREGS+160(a0) EX ldc1 $f20, 160(a0)
EX ldc1 $f22, SC_FPREGS+176(a0) EX ldc1 $f22, 176(a0)
EX ldc1 $f24, SC_FPREGS+192(a0) EX ldc1 $f24, 192(a0)
EX ldc1 $f26, SC_FPREGS+208(a0) EX ldc1 $f26, 208(a0)
EX ldc1 $f28, SC_FPREGS+224(a0) EX ldc1 $f28, 224(a0)
EX ldc1 $f30, SC_FPREGS+240(a0) EX ldc1 $f30, 240(a0)
ctc1 t1, fcr31 ctc1 t1, fcr31
.set pop .set pop
jr ra jr ra
......
...@@ -31,4 +31,10 @@ extern int fpcsr_pending(unsigned int __user *fpcsr); ...@@ -31,4 +31,10 @@ extern int fpcsr_pending(unsigned int __user *fpcsr);
#define lock_fpu_owner() ({ preempt_disable(); pagefault_disable(); }) #define lock_fpu_owner() ({ preempt_disable(); pagefault_disable(); })
#define unlock_fpu_owner() ({ pagefault_enable(); preempt_enable(); }) #define unlock_fpu_owner() ({ pagefault_enable(); preempt_enable(); })
/* Assembly functions to move context to/from the FPU */
extern asmlinkage int
_save_fp_context(void __user *fpregs, void __user *csr);
extern asmlinkage int
_restore_fp_context(void __user *fpregs, void __user *csr);
#endif /* __SIGNAL_COMMON_H */ #endif /* __SIGNAL_COMMON_H */
...@@ -41,11 +41,8 @@ ...@@ -41,11 +41,8 @@
#include "signal-common.h" #include "signal-common.h"
static int (*save_fp_context)(struct sigcontext __user *sc); static int (*save_fp_context)(void __user *sc);
static int (*restore_fp_context)(struct sigcontext __user *sc); static int (*restore_fp_context)(void __user *sc);
extern asmlinkage int _save_fp_context(struct sigcontext __user *sc);
extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc);
struct sigframe { struct sigframe {
u32 sf_ass[4]; /* argument save space for o32 */ u32 sf_ass[4]; /* argument save space for o32 */
...@@ -65,41 +62,71 @@ struct rt_sigframe { ...@@ -65,41 +62,71 @@ struct rt_sigframe {
* Thread saved context copy to/from a signal context presumed to be on the * Thread saved context copy to/from a signal context presumed to be on the
* user stack, and therefore accessed with appropriate macros from uaccess.h. * user stack, and therefore accessed with appropriate macros from uaccess.h.
*/ */
static int copy_fp_to_sigcontext(struct sigcontext __user *sc) static int copy_fp_to_sigcontext(void __user *sc)
{ {
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
int i; int i;
int err = 0; int err = 0;
for (i = 0; i < NUM_FPU_REGS; i++) { for (i = 0; i < NUM_FPU_REGS; i++) {
err |= err |=
__put_user(get_fpr64(&current->thread.fpu.fpr[i], 0), __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
&sc->sc_fpregs[i]); &fpregs[i]);
} }
err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); err |= __put_user(current->thread.fpu.fcr31, csr);
return err; return err;
} }
static int copy_fp_from_sigcontext(struct sigcontext __user *sc) static int copy_fp_from_sigcontext(void __user *sc)
{ {
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
int i; int i;
int err = 0; int err = 0;
u64 fpr_val; u64 fpr_val;
for (i = 0; i < NUM_FPU_REGS; i++) { for (i = 0; i < NUM_FPU_REGS; i++) {
err |= __get_user(fpr_val, &sc->sc_fpregs[i]); err |= __get_user(fpr_val, &fpregs[i]);
set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val); set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
} }
err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); err |= __get_user(current->thread.fpu.fcr31, csr);
return err; return err;
} }
/*
* Wrappers for the assembly _{save,restore}_fp_context functions.
*/
static int save_hw_fp_context(void __user *sc)
{
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
return _save_fp_context(fpregs, csr);
}
static int restore_hw_fp_context(void __user *sc)
{
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
return _restore_fp_context(fpregs, csr);
}
/* /*
* Helper routines * Helper routines
*/ */
static int protected_save_fp_context(struct sigcontext __user *sc) static int protected_save_fp_context(void __user *sc)
{ {
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
int err; int err;
/* /*
...@@ -121,9 +148,9 @@ static int protected_save_fp_context(struct sigcontext __user *sc) ...@@ -121,9 +148,9 @@ static int protected_save_fp_context(struct sigcontext __user *sc)
if (likely(!err)) if (likely(!err))
break; break;
/* touch the sigcontext and try again */ /* touch the sigcontext and try again */
err = __put_user(0, &sc->sc_fpregs[0]) | err = __put_user(0, &fpregs[0]) |
__put_user(0, &sc->sc_fpregs[31]) | __put_user(0, &fpregs[31]) |
__put_user(0, &sc->sc_fpc_csr); __put_user(0, csr);
if (err) if (err)
break; /* really bad sigcontext */ break; /* really bad sigcontext */
} }
...@@ -131,8 +158,11 @@ static int protected_save_fp_context(struct sigcontext __user *sc) ...@@ -131,8 +158,11 @@ static int protected_save_fp_context(struct sigcontext __user *sc)
return err; return err;
} }
static int protected_restore_fp_context(struct sigcontext __user *sc) static int protected_restore_fp_context(void __user *sc)
{ {
struct mips_abi *abi = current->thread.abi;
uint64_t __user *fpregs = sc + abi->off_sc_fpregs;
uint32_t __user *csr = sc + abi->off_sc_fpc_csr;
int err, tmp __maybe_unused; int err, tmp __maybe_unused;
/* /*
...@@ -155,9 +185,9 @@ static int protected_restore_fp_context(struct sigcontext __user *sc) ...@@ -155,9 +185,9 @@ static int protected_restore_fp_context(struct sigcontext __user *sc)
if (likely(!err)) if (likely(!err))
break; break;
/* touch the sigcontext and try again */ /* touch the sigcontext and try again */
err = __get_user(tmp, &sc->sc_fpregs[0]) | err = __get_user(tmp, &fpregs[0]) |
__get_user(tmp, &sc->sc_fpregs[31]) | __get_user(tmp, &fpregs[31]) |
__get_user(tmp, &sc->sc_fpc_csr); __get_user(tmp, csr);
if (err) if (err)
break; /* really bad sigcontext */ break; /* really bad sigcontext */
} }
...@@ -225,11 +255,12 @@ int fpcsr_pending(unsigned int __user *fpcsr) ...@@ -225,11 +255,12 @@ int fpcsr_pending(unsigned int __user *fpcsr)
} }
static int static int
check_and_restore_fp_context(struct sigcontext __user *sc) check_and_restore_fp_context(void __user *sc)
{ {
struct mips_abi *abi = current->thread.abi;
int err, sig; int err, sig;
err = sig = fpcsr_pending(&sc->sc_fpc_csr); err = sig = fpcsr_pending(sc + abi->off_sc_fpc_csr);
if (err > 0) if (err > 0)
err = 0; err = 0;
err |= protected_restore_fp_context(sc); err |= protected_restore_fp_context(sc);
...@@ -634,17 +665,17 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused, ...@@ -634,17 +665,17 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
} }
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
static int smp_save_fp_context(struct sigcontext __user *sc) static int smp_save_fp_context(void __user *sc)
{ {
return raw_cpu_has_fpu return raw_cpu_has_fpu
? _save_fp_context(sc) ? save_hw_fp_context(sc)
: copy_fp_to_sigcontext(sc); : copy_fp_to_sigcontext(sc);
} }
static int smp_restore_fp_context(struct sigcontext __user *sc) static int smp_restore_fp_context(void __user *sc)
{ {
return raw_cpu_has_fpu return raw_cpu_has_fpu
? _restore_fp_context(sc) ? restore_hw_fp_context(sc)
: copy_fp_from_sigcontext(sc); : copy_fp_from_sigcontext(sc);
} }
#endif #endif
...@@ -657,8 +688,8 @@ static int signal_setup(void) ...@@ -657,8 +688,8 @@ static int signal_setup(void)
restore_fp_context = smp_restore_fp_context; restore_fp_context = smp_restore_fp_context;
#else #else
if (cpu_has_fpu) { if (cpu_has_fpu) {
save_fp_context = _save_fp_context; save_fp_context = save_hw_fp_context;
restore_fp_context = _restore_fp_context; restore_fp_context = restore_hw_fp_context;
} else { } else {
save_fp_context = copy_fp_to_sigcontext; save_fp_context = copy_fp_to_sigcontext;
restore_fp_context = copy_fp_from_sigcontext; restore_fp_context = copy_fp_from_sigcontext;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment