15598473aSDavid S. Miller #include <linux/kernel.h> 25598473aSDavid S. Miller #include <linux/types.h> 35598473aSDavid S. Miller #include <linux/thread_info.h> 45598473aSDavid S. Miller #include <linux/uaccess.h> 55598473aSDavid S. Miller #include <linux/sched.h> 65598473aSDavid S. Miller 75598473aSDavid S. Miller #include <asm/sigcontext.h> 85598473aSDavid S. Miller #include <asm/fpumacro.h> 95598473aSDavid S. Miller #include <asm/ptrace.h> 10d550bbd4SDavid Howells #include <asm/switch_to.h> 115598473aSDavid S. Miller 125598473aSDavid S. Miller #include "sigutil.h" 135598473aSDavid S. Miller 145598473aSDavid S. Miller int save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) 155598473aSDavid S. Miller { 165598473aSDavid S. Miller int err = 0; 175598473aSDavid S. Miller #ifdef CONFIG_SMP 185598473aSDavid S. Miller if (test_tsk_thread_flag(current, TIF_USEDFPU)) { 195598473aSDavid S. Miller put_psr(get_psr() | PSR_EF); 205598473aSDavid S. Miller fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr, 215598473aSDavid S. Miller ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth); 225598473aSDavid S. Miller regs->psr &= ~(PSR_EF); 235598473aSDavid S. Miller clear_tsk_thread_flag(current, TIF_USEDFPU); 245598473aSDavid S. Miller } 255598473aSDavid S. Miller #else 265598473aSDavid S. Miller if (current == last_task_used_math) { 275598473aSDavid S. Miller put_psr(get_psr() | PSR_EF); 285598473aSDavid S. Miller fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr, 295598473aSDavid S. Miller ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth); 305598473aSDavid S. Miller last_task_used_math = NULL; 315598473aSDavid S. Miller regs->psr &= ~(PSR_EF); 325598473aSDavid S. Miller } 335598473aSDavid S. Miller #endif 345598473aSDavid S. Miller err |= __copy_to_user(&fpu->si_float_regs[0], 355598473aSDavid S. Miller ¤t->thread.float_regs[0], 365598473aSDavid S. Miller (sizeof(unsigned long) * 32)); 375598473aSDavid S. Miller err |= __put_user(current->thread.fsr, &fpu->si_fsr); 385598473aSDavid S. Miller err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth); 395598473aSDavid S. Miller if (current->thread.fpqdepth != 0) 405598473aSDavid S. Miller err |= __copy_to_user(&fpu->si_fpqueue[0], 415598473aSDavid S. Miller ¤t->thread.fpqueue[0], 425598473aSDavid S. Miller ((sizeof(unsigned long) + 435598473aSDavid S. Miller (sizeof(unsigned long *)))*16)); 445598473aSDavid S. Miller clear_used_math(); 455598473aSDavid S. Miller return err; 465598473aSDavid S. Miller } 475598473aSDavid S. Miller 485598473aSDavid S. Miller int restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) 495598473aSDavid S. Miller { 505598473aSDavid S. Miller int err; 51*d11c2a0dSDavid S. Miller 52*d11c2a0dSDavid S. Miller if (((unsigned long) fpu) & 3) 53*d11c2a0dSDavid S. Miller return -EFAULT; 54*d11c2a0dSDavid S. Miller 555598473aSDavid S. Miller #ifdef CONFIG_SMP 565598473aSDavid S. Miller if (test_tsk_thread_flag(current, TIF_USEDFPU)) 575598473aSDavid S. Miller regs->psr &= ~PSR_EF; 585598473aSDavid S. Miller #else 595598473aSDavid S. Miller if (current == last_task_used_math) { 605598473aSDavid S. Miller last_task_used_math = NULL; 615598473aSDavid S. Miller regs->psr &= ~PSR_EF; 625598473aSDavid S. Miller } 635598473aSDavid S. Miller #endif 645598473aSDavid S. Miller set_used_math(); 655598473aSDavid S. Miller clear_tsk_thread_flag(current, TIF_USEDFPU); 665598473aSDavid S. Miller 675598473aSDavid S. Miller if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu))) 685598473aSDavid S. Miller return -EFAULT; 695598473aSDavid S. Miller 705598473aSDavid S. Miller err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0], 715598473aSDavid S. Miller (sizeof(unsigned long) * 32)); 725598473aSDavid S. Miller err |= __get_user(current->thread.fsr, &fpu->si_fsr); 735598473aSDavid S. Miller err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth); 745598473aSDavid S. Miller if (current->thread.fpqdepth != 0) 755598473aSDavid S. Miller err |= __copy_from_user(¤t->thread.fpqueue[0], 765598473aSDavid S. Miller &fpu->si_fpqueue[0], 775598473aSDavid S. Miller ((sizeof(unsigned long) + 785598473aSDavid S. Miller (sizeof(unsigned long *)))*16)); 795598473aSDavid S. Miller return err; 805598473aSDavid S. Miller } 815598473aSDavid S. Miller 825598473aSDavid S. Miller int save_rwin_state(int wsaved, __siginfo_rwin_t __user *rwin) 835598473aSDavid S. Miller { 845598473aSDavid S. Miller int i, err = __put_user(wsaved, &rwin->wsaved); 855598473aSDavid S. Miller 865598473aSDavid S. Miller for (i = 0; i < wsaved; i++) { 875598473aSDavid S. Miller struct reg_window32 *rp; 885598473aSDavid S. Miller unsigned long fp; 895598473aSDavid S. Miller 905598473aSDavid S. Miller rp = ¤t_thread_info()->reg_window[i]; 915598473aSDavid S. Miller fp = current_thread_info()->rwbuf_stkptrs[i]; 925598473aSDavid S. Miller err |= copy_to_user(&rwin->reg_window[i], rp, 935598473aSDavid S. Miller sizeof(struct reg_window32)); 945598473aSDavid S. Miller err |= __put_user(fp, &rwin->rwbuf_stkptrs[i]); 955598473aSDavid S. Miller } 965598473aSDavid S. Miller return err; 975598473aSDavid S. Miller } 985598473aSDavid S. Miller 995598473aSDavid S. Miller int restore_rwin_state(__siginfo_rwin_t __user *rp) 1005598473aSDavid S. Miller { 1015598473aSDavid S. Miller struct thread_info *t = current_thread_info(); 1025598473aSDavid S. Miller int i, wsaved, err; 1035598473aSDavid S. Miller 104*d11c2a0dSDavid S. Miller if (((unsigned long) rp) & 3) 105*d11c2a0dSDavid S. Miller return -EFAULT; 106*d11c2a0dSDavid S. Miller 107*d11c2a0dSDavid S. Miller get_user(wsaved, &rp->wsaved); 1085598473aSDavid S. Miller if (wsaved > NSWINS) 1095598473aSDavid S. Miller return -EFAULT; 1105598473aSDavid S. Miller 1115598473aSDavid S. Miller err = 0; 1125598473aSDavid S. Miller for (i = 0; i < wsaved; i++) { 1135598473aSDavid S. Miller err |= copy_from_user(&t->reg_window[i], 1145598473aSDavid S. Miller &rp->reg_window[i], 1155598473aSDavid S. Miller sizeof(struct reg_window32)); 1165598473aSDavid S. Miller err |= __get_user(t->rwbuf_stkptrs[i], 1175598473aSDavid S. Miller &rp->rwbuf_stkptrs[i]); 1185598473aSDavid S. Miller } 1195598473aSDavid S. Miller if (err) 1205598473aSDavid S. Miller return err; 1215598473aSDavid S. Miller 1225598473aSDavid S. Miller t->w_saved = wsaved; 1235598473aSDavid S. Miller synchronize_user_stack(); 1245598473aSDavid S. Miller if (t->w_saved) 1255598473aSDavid S. Miller return -EFAULT; 1265598473aSDavid S. Miller return 0; 1275598473aSDavid S. Miller 1285598473aSDavid S. Miller } 129