1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/config.h>
18#include <linux/sched.h>
19#include <asm/processor.h>
20#include <asm/i387.h>
21#include <asm/sigcontext.h>
22#include <asm/user.h>
23#include <asm/ptrace.h>
24#include <asm/uaccess.h>
25
26extern int exception_trace;
27
28void init_fpu(struct task_struct *child)
29{
30 if (child->used_math) {
31 unlazy_fpu(child);
32 return;
33 }
34 memset(&child->thread.i387.fxsave, 0, sizeof(struct i387_fxsave_struct));
35 child->thread.i387.fxsave.cwd = 0x37f;
36 child->thread.i387.fxsave.mxcsr = 0x1f80;
37 child->used_math = 1;
38}
39
40
41
42
43
44int save_i387(struct _fpstate *buf)
45{
46 struct task_struct *tsk = current;
47 int err = 0;
48
49 {
50 extern void bad_user_i387_struct(void);
51 if (sizeof(struct user_i387_struct) != sizeof(tsk->thread.i387.fxsave))
52 bad_user_i387_struct();
53 }
54
55 if (!tsk->used_math)
56 return 0;
57 tsk->used_math = 0;
58 if (tsk->flags & PF_USEDFPU) {
59 err = save_i387_checking((struct i387_fxsave_struct *)buf);
60 if (err) {
61 if (exception_trace)
62 printk("%s[%d] unaligned signal floating point context %p\n",
63 tsk->comm, tsk->pid, buf);
64 return err;
65 }
66 stts();
67 } else {
68 if (__copy_to_user(buf, &tsk->thread.i387.fxsave,
69 sizeof(struct i387_fxsave_struct)))
70 return -1;
71 }
72 return 1;
73}
74
75
76
77
78
79int get_fpregs(struct user_i387_struct *buf, struct task_struct *tsk)
80{
81 init_fpu(tsk);
82 return __copy_to_user((void *)buf, &tsk->thread.i387.fxsave,
83 sizeof(struct user_i387_struct)) ? -EFAULT : 0;
84}
85
86int set_fpregs(struct task_struct *tsk, struct user_i387_struct *buf)
87{
88 if (__copy_from_user(&tsk->thread.i387.fxsave, buf,
89 sizeof(struct user_i387_struct)))
90 return -EFAULT;
91
92 tsk->thread.i387.fxsave.mxcsr &= 0xffbf;
93 return 0;
94}
95
96
97
98
99
100int dump_fpu( struct pt_regs *regs, struct user_i387_struct *fpu )
101{
102 struct task_struct *tsk = current;
103
104 if (!tsk->used_math)
105 return 0;
106 unlazy_fpu(tsk);
107
108 memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct));
109 return 1;
110}
111