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> 10*d550bbd4SDavid 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; 515598473aSDavid S. Miller #ifdef CONFIG_SMP 525598473aSDavid S. Miller if (test_tsk_thread_flag(current, TIF_USEDFPU)) 535598473aSDavid S. Miller regs->psr &= ~PSR_EF; 545598473aSDavid S. Miller #else 555598473aSDavid S. Miller if (current == last_task_used_math) { 565598473aSDavid S. Miller last_task_used_math = NULL; 575598473aSDavid S. Miller regs->psr &= ~PSR_EF; 585598473aSDavid S. Miller } 595598473aSDavid S. Miller #endif 605598473aSDavid S. Miller set_used_math(); 615598473aSDavid S. Miller clear_tsk_thread_flag(current, TIF_USEDFPU); 625598473aSDavid S. Miller 635598473aSDavid S. Miller if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu))) 645598473aSDavid S. Miller return -EFAULT; 655598473aSDavid S. Miller 665598473aSDavid S. Miller err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0], 675598473aSDavid S. Miller (sizeof(unsigned long) * 32)); 685598473aSDavid S. Miller err |= __get_user(current->thread.fsr, &fpu->si_fsr); 695598473aSDavid S. Miller err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth); 705598473aSDavid S. Miller if (current->thread.fpqdepth != 0) 715598473aSDavid S. Miller err |= __copy_from_user(¤t->thread.fpqueue[0], 725598473aSDavid S. Miller &fpu->si_fpqueue[0], 735598473aSDavid S. Miller ((sizeof(unsigned long) + 745598473aSDavid S. Miller (sizeof(unsigned long *)))*16)); 755598473aSDavid S. Miller return err; 765598473aSDavid S. Miller } 775598473aSDavid S. Miller 785598473aSDavid S. Miller int save_rwin_state(int wsaved, __siginfo_rwin_t __user *rwin) 795598473aSDavid S. Miller { 805598473aSDavid S. Miller int i, err = __put_user(wsaved, &rwin->wsaved); 815598473aSDavid S. Miller 825598473aSDavid S. Miller for (i = 0; i < wsaved; i++) { 835598473aSDavid S. Miller struct reg_window32 *rp; 845598473aSDavid S. Miller unsigned long fp; 855598473aSDavid S. Miller 865598473aSDavid S. Miller rp = ¤t_thread_info()->reg_window[i]; 875598473aSDavid S. Miller fp = current_thread_info()->rwbuf_stkptrs[i]; 885598473aSDavid S. Miller err |= copy_to_user(&rwin->reg_window[i], rp, 895598473aSDavid S. Miller sizeof(struct reg_window32)); 905598473aSDavid S. Miller err |= __put_user(fp, &rwin->rwbuf_stkptrs[i]); 915598473aSDavid S. Miller } 925598473aSDavid S. Miller return err; 935598473aSDavid S. Miller } 945598473aSDavid S. Miller 955598473aSDavid S. Miller int restore_rwin_state(__siginfo_rwin_t __user *rp) 965598473aSDavid S. Miller { 975598473aSDavid S. Miller struct thread_info *t = current_thread_info(); 985598473aSDavid S. Miller int i, wsaved, err; 995598473aSDavid S. Miller 1005598473aSDavid S. Miller __get_user(wsaved, &rp->wsaved); 1015598473aSDavid S. Miller if (wsaved > NSWINS) 1025598473aSDavid S. Miller return -EFAULT; 1035598473aSDavid S. Miller 1045598473aSDavid S. Miller err = 0; 1055598473aSDavid S. Miller for (i = 0; i < wsaved; i++) { 1065598473aSDavid S. Miller err |= copy_from_user(&t->reg_window[i], 1075598473aSDavid S. Miller &rp->reg_window[i], 1085598473aSDavid S. Miller sizeof(struct reg_window32)); 1095598473aSDavid S. Miller err |= __get_user(t->rwbuf_stkptrs[i], 1105598473aSDavid S. Miller &rp->rwbuf_stkptrs[i]); 1115598473aSDavid S. Miller } 1125598473aSDavid S. Miller if (err) 1135598473aSDavid S. Miller return err; 1145598473aSDavid S. Miller 1155598473aSDavid S. Miller t->w_saved = wsaved; 1165598473aSDavid S. Miller synchronize_user_stack(); 1175598473aSDavid S. Miller if (t->w_saved) 1185598473aSDavid S. Miller return -EFAULT; 1195598473aSDavid S. Miller return 0; 1205598473aSDavid S. Miller 1215598473aSDavid S. Miller } 122