diff options
Diffstat (limited to 'arch/mips64/kernel/signal32.c')
-rw-r--r-- | arch/mips64/kernel/signal32.c | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/arch/mips64/kernel/signal32.c b/arch/mips64/kernel/signal32.c index 5a1ee45b0..4addc707c 100644 --- a/arch/mips64/kernel/signal32.c +++ b/arch/mips64/kernel/signal32.c @@ -64,6 +64,35 @@ typedef struct sigaltstack32 { } stack32_t; +static inline int store_fp_context(struct sigcontext *sc) +{ + unsigned int fcr0; + int err = 0; + + err |= __copy_to_user(&sc->sc_fpregs[0], + ¤t->thread.fpu.hard.fp_regs[0], NUM_FPU_REGS * + sizeof(unsigned long)); + err |= __copy_to_user(&sc->sc_fpc_csr, ¤t->thread.fpu.hard.control, + sizeof(unsigned int)); + __asm__ __volatile__("cfc1 %0, $0\n\t" : "=r" (fcr0)); + err |= __copy_to_user(&sc->sc_fpc_eir, &fcr0, sizeof(unsigned int)); + + return err; +} + +static inline int refill_fp_context(struct sigcontext *sc) +{ + int err = 0; + + if (verify_area(VERIFY_READ, sc, sizeof(*sc))) + return -EFAULT; + err |= __copy_from_user(¤t->thread.fpu.hard.fp_regs[0], + &sc->sc_fpregs[0], NUM_FPU_REGS * sizeof(unsigned long)); + err |= __copy_from_user(¤t->thread.fpu.hard.control, &sc->sc_fpc_csr, + sizeof(unsigned int)); + return err; +} + /* * Atomically swap in the new signal mask, and wait for a signal. */ @@ -210,8 +239,12 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc) err |= __get_user(owned_fp, &sc->sc_ownedfp); if (owned_fp) { - err |= restore_fp_context(sc); - last_task_used_math = current; + if (current == last_task_used_math) { + last_task_used_math = 0; + regs->cp0_status &= ~ST0_CU1; + } + current->used_math = 1; + err |= refill_fp_context(sc); } return err; @@ -316,11 +349,9 @@ badframe: static int inline setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc) { - int owned_fp; int err = 0; err |= __put_user(regs->cp0_epc, &sc->sc_pc); - err |= __put_user(regs->cp0_status, &sc->sc_status); #define save_gp_reg(i) { \ err |= __put_user(regs->regs[i], &sc->sc_regs[i]); \ @@ -341,16 +372,19 @@ setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc) err |= __put_user(regs->cp0_cause, &sc->sc_cause); err |= __put_user(regs->cp0_badvaddr, &sc->sc_badvaddr); - owned_fp = (current == last_task_used_math); - err |= __put_user(owned_fp, &sc->sc_ownedfp); - if (current->used_math) { /* fp is active. */ - set_cp0_status(ST0_CU1, ST0_CU1); - err |= save_fp_context(sc); - last_task_used_math = NULL; - regs->cp0_status &= ~ST0_CU1; + if (current == last_task_used_math) { + lazy_fpu_switch(current, 0); + last_task_used_math = NULL; + regs->cp0_status &= ~ST0_CU1; + } + err |= __put_user(1, &sc->sc_ownedfp); + err |= store_fp_context(sc); current->used_math = 0; + } else { + err |= __put_user(0, &sc->sc_ownedfp); } + err |= __put_user(regs->cp0_status, &sc->sc_status); return err; } |