diff options
author | Roland McGrath <roland@redhat.com> | 2008-01-30 07:31:51 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:31:51 -0500 |
commit | 1eeaed7679eab3666d2d8c964d060c2169b3813b (patch) | |
tree | 2c2904e4ee8d75f30d00dd2367b12d37a5e3e55b /arch | |
parent | 4421011120b2304e5c248ae4165a2704588aedf1 (diff) |
x86: x86 i387 cleanup
This removes all the old code that is no longer used after
the i387 unification and cleanup. The i387_64.h is renamed
to i387.h with no changes, but since it replaces the nonempty
one-line stub i387.h it looks like a big diff and not a rename.
Signed-off-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/ia32/fpu32.c | 181 | ||||
-rw-r--r-- | arch/x86/kernel/i387_64.c | 119 |
2 files changed, 0 insertions, 300 deletions
diff --git a/arch/x86/ia32/fpu32.c b/arch/x86/ia32/fpu32.c deleted file mode 100644 index ae80745f668f..000000000000 --- a/arch/x86/ia32/fpu32.c +++ /dev/null | |||
@@ -1,181 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright 2002 Andi Kleen, SuSE Labs. | ||
3 | * FXSAVE<->i387 conversion support. Based on code by Gareth Hughes. | ||
4 | * This is used for ptrace, signals and coredumps in 32bit emulation. | ||
5 | */ | ||
6 | |||
7 | #include <linux/sched.h> | ||
8 | #include <asm/sigcontext32.h> | ||
9 | #include <asm/processor.h> | ||
10 | #include <asm/uaccess.h> | ||
11 | #include <asm/i387.h> | ||
12 | |||
13 | static inline unsigned short twd_i387_to_fxsr(unsigned short twd) | ||
14 | { | ||
15 | unsigned int tmp; /* to avoid 16 bit prefixes in the code */ | ||
16 | |||
17 | /* Transform each pair of bits into 01 (valid) or 00 (empty) */ | ||
18 | tmp = ~twd; | ||
19 | tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ | ||
20 | /* and move the valid bits to the lower byte. */ | ||
21 | tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ | ||
22 | tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ | ||
23 | tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ | ||
24 | return tmp; | ||
25 | } | ||
26 | |||
27 | #define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n) * 16); | ||
28 | #define FP_EXP_TAG_VALID 0 | ||
29 | #define FP_EXP_TAG_ZERO 1 | ||
30 | #define FP_EXP_TAG_SPECIAL 2 | ||
31 | #define FP_EXP_TAG_EMPTY 3 | ||
32 | |||
33 | static inline unsigned long twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) | ||
34 | { | ||
35 | struct _fpxreg *st; | ||
36 | unsigned long tos = (fxsave->swd >> 11) & 7; | ||
37 | unsigned long twd = (unsigned long) fxsave->twd; | ||
38 | unsigned long tag; | ||
39 | unsigned long ret = 0xffff0000; | ||
40 | int i; | ||
41 | |||
42 | for (i = 0; i < 8; i++, twd >>= 1) { | ||
43 | if (twd & 0x1) { | ||
44 | st = FPREG_ADDR(fxsave, (i - tos) & 7); | ||
45 | |||
46 | switch (st->exponent & 0x7fff) { | ||
47 | case 0x7fff: | ||
48 | tag = FP_EXP_TAG_SPECIAL; | ||
49 | break; | ||
50 | case 0x0000: | ||
51 | if (!st->significand[0] && | ||
52 | !st->significand[1] && | ||
53 | !st->significand[2] && | ||
54 | !st->significand[3]) | ||
55 | tag = FP_EXP_TAG_ZERO; | ||
56 | else | ||
57 | tag = FP_EXP_TAG_SPECIAL; | ||
58 | break; | ||
59 | default: | ||
60 | if (st->significand[3] & 0x8000) | ||
61 | tag = FP_EXP_TAG_VALID; | ||
62 | else | ||
63 | tag = FP_EXP_TAG_SPECIAL; | ||
64 | break; | ||
65 | } | ||
66 | } else { | ||
67 | tag = FP_EXP_TAG_EMPTY; | ||
68 | } | ||
69 | ret |= tag << (2 * i); | ||
70 | } | ||
71 | return ret; | ||
72 | } | ||
73 | |||
74 | #define G(num, val) err |= __get_user(val, num + (u32 __user *)buf) | ||
75 | |||
76 | static inline int convert_fxsr_from_user(struct i387_fxsave_struct *fxsave, | ||
77 | struct _fpstate_ia32 __user *buf) | ||
78 | { | ||
79 | struct _fpxreg *to; | ||
80 | struct _fpreg __user *from; | ||
81 | int i, err = 0; | ||
82 | u32 v; | ||
83 | |||
84 | G(0, fxsave->cwd); | ||
85 | G(1, fxsave->swd); | ||
86 | G(2, fxsave->twd); | ||
87 | fxsave->twd = twd_i387_to_fxsr(fxsave->twd); | ||
88 | G(3, fxsave->rip); | ||
89 | G(4, v); | ||
90 | /* cs ignored */ | ||
91 | fxsave->fop = v>>16; | ||
92 | G(5, fxsave->rdp); | ||
93 | /* 6: ds ignored */ | ||
94 | if (err) | ||
95 | return -1; | ||
96 | |||
97 | to = (struct _fpxreg *)&fxsave->st_space[0]; | ||
98 | from = &buf->_st[0]; | ||
99 | for (i = 0; i < 8; i++, to++, from++) { | ||
100 | if (__copy_from_user(to, from, sizeof(*from))) | ||
101 | return -1; | ||
102 | } | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | #define P(num, val) err |= __put_user(val, num + (u32 __user *)buf) | ||
107 | |||
108 | static inline int convert_fxsr_to_user(struct _fpstate_ia32 __user *buf, | ||
109 | struct i387_fxsave_struct *fxsave, | ||
110 | struct pt_regs *regs, | ||
111 | struct task_struct *tsk) | ||
112 | { | ||
113 | struct _fpreg __user *to; | ||
114 | struct _fpxreg *from; | ||
115 | int i, err = 0; | ||
116 | u16 cs, ds; | ||
117 | |||
118 | if (tsk == current) { | ||
119 | /* | ||
120 | * should be actually ds/cs at fpu exception time, but | ||
121 | * that information is not available in 64bit mode. | ||
122 | */ | ||
123 | asm("movw %%ds,%0 " : "=r" (ds)); | ||
124 | asm("movw %%cs,%0 " : "=r" (cs)); | ||
125 | } else { | ||
126 | /* ptrace. task has stopped. */ | ||
127 | ds = tsk->thread.ds; | ||
128 | cs = regs->cs; | ||
129 | } | ||
130 | |||
131 | P(0, (u32)fxsave->cwd | 0xffff0000); | ||
132 | P(1, (u32)fxsave->swd | 0xffff0000); | ||
133 | P(2, twd_fxsr_to_i387(fxsave)); | ||
134 | P(3, (u32)fxsave->rip); | ||
135 | P(4, cs | ((u32)fxsave->fop) << 16); | ||
136 | P(5, fxsave->rdp); | ||
137 | P(6, 0xffff0000 | ds); | ||
138 | |||
139 | if (err) | ||
140 | return -1; | ||
141 | |||
142 | to = &buf->_st[0]; | ||
143 | from = (struct _fpxreg *) &fxsave->st_space[0]; | ||
144 | for (i = 0; i < 8; i++, to++, from++) { | ||
145 | if (__copy_to_user(to, from, sizeof(*to))) | ||
146 | return -1; | ||
147 | } | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | int restore_i387_ia32(struct task_struct *tsk, | ||
152 | struct _fpstate_ia32 __user *buf, int fsave) | ||
153 | { | ||
154 | clear_fpu(tsk); | ||
155 | if (!fsave) { | ||
156 | if (__copy_from_user(&tsk->thread.i387.fxsave, | ||
157 | &buf->_fxsr_env[0], | ||
158 | sizeof(struct i387_fxsave_struct))) | ||
159 | return -1; | ||
160 | tsk->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask; | ||
161 | set_stopped_child_used_math(tsk); | ||
162 | } | ||
163 | return convert_fxsr_from_user(&tsk->thread.i387.fxsave, buf); | ||
164 | } | ||
165 | |||
166 | int save_i387_ia32(struct task_struct *tsk, struct _fpstate_ia32 __user *buf, | ||
167 | struct pt_regs *regs, int fsave) | ||
168 | { | ||
169 | int err = 0; | ||
170 | |||
171 | init_fpu(tsk); | ||
172 | if (convert_fxsr_to_user(buf, &tsk->thread.i387.fxsave, regs, tsk)) | ||
173 | return -1; | ||
174 | if (fsave) | ||
175 | return 0; | ||
176 | err |= __put_user(tsk->thread.i387.fxsave.swd, &buf->status); | ||
177 | err |= __put_user(X86_FXSR_MAGIC, &buf->magic); | ||
178 | err |= __copy_to_user(&buf->_fxsr_env[0], &tsk->thread.i387.fxsave, | ||
179 | sizeof(struct i387_fxsave_struct)); | ||
180 | return err ? -1 : 1; | ||
181 | } | ||
diff --git a/arch/x86/kernel/i387_64.c b/arch/x86/kernel/i387_64.c deleted file mode 100644 index f335a76d7ea7..000000000000 --- a/arch/x86/kernel/i387_64.c +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1994 Linus Torvalds | ||
3 | * Copyright (C) 2002 Andi Kleen, SuSE Labs | ||
4 | * | ||
5 | * Pentium III FXSR, SSE support | ||
6 | * General FPU state handling cleanups | ||
7 | * Gareth Hughes <gareth@valinux.com>, May 2000 | ||
8 | * | ||
9 | * x86-64 rework 2002 Andi Kleen. | ||
10 | * Does direct fxsave in and out of user space now for signal handlers. | ||
11 | * All the FSAVE<->FXSAVE conversion code has been moved to the 32bit emulation, | ||
12 | * the 64bit user space sees a FXSAVE frame directly. | ||
13 | */ | ||
14 | |||
15 | #include <linux/sched.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <asm/processor.h> | ||
18 | #include <asm/i387.h> | ||
19 | #include <asm/sigcontext.h> | ||
20 | #include <asm/user.h> | ||
21 | #include <asm/ptrace.h> | ||
22 | #include <asm/uaccess.h> | ||
23 | |||
24 | unsigned int mxcsr_feature_mask __read_mostly = 0xffffffff; | ||
25 | |||
26 | void mxcsr_feature_mask_init(void) | ||
27 | { | ||
28 | unsigned int mask; | ||
29 | clts(); | ||
30 | memset(¤t->thread.i387.fxsave, 0, sizeof(struct i387_fxsave_struct)); | ||
31 | asm volatile("fxsave %0" : : "m" (current->thread.i387.fxsave)); | ||
32 | mask = current->thread.i387.fxsave.mxcsr_mask; | ||
33 | if (mask == 0) mask = 0x0000ffbf; | ||
34 | mxcsr_feature_mask &= mask; | ||
35 | stts(); | ||
36 | } | ||
37 | |||
38 | /* | ||
39 | * Called at bootup to set up the initial FPU state that is later cloned | ||
40 | * into all processes. | ||
41 | */ | ||
42 | void __cpuinit fpu_init(void) | ||
43 | { | ||
44 | unsigned long oldcr0 = read_cr0(); | ||
45 | extern void __bad_fxsave_alignment(void); | ||
46 | |||
47 | if (offsetof(struct task_struct, thread.i387.fxsave) & 15) | ||
48 | __bad_fxsave_alignment(); | ||
49 | set_in_cr4(X86_CR4_OSFXSR); | ||
50 | set_in_cr4(X86_CR4_OSXMMEXCPT); | ||
51 | |||
52 | write_cr0(oldcr0 & ~((1UL<<3)|(1UL<<2))); /* clear TS and EM */ | ||
53 | |||
54 | mxcsr_feature_mask_init(); | ||
55 | /* clean state in init */ | ||
56 | current_thread_info()->status = 0; | ||
57 | clear_used_math(); | ||
58 | } | ||
59 | |||
60 | void init_fpu(struct task_struct *child) | ||
61 | { | ||
62 | if (tsk_used_math(child)) { | ||
63 | if (child == current) | ||
64 | unlazy_fpu(child); | ||
65 | return; | ||
66 | } | ||
67 | memset(&child->thread.i387.fxsave, 0, sizeof(struct i387_fxsave_struct)); | ||
68 | child->thread.i387.fxsave.cwd = 0x37f; | ||
69 | child->thread.i387.fxsave.mxcsr = 0x1f80; | ||
70 | /* only the device not available exception or ptrace can call init_fpu */ | ||
71 | set_stopped_child_used_math(child); | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * ptrace request handlers. | ||
76 | */ | ||
77 | |||
78 | int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *tsk) | ||
79 | { | ||
80 | init_fpu(tsk); | ||
81 | return __copy_to_user(buf, &tsk->thread.i387.fxsave, | ||
82 | sizeof(struct user_i387_struct)) ? -EFAULT : 0; | ||
83 | } | ||
84 | |||
85 | int set_fpregs(struct task_struct *tsk, struct user_i387_struct __user *buf) | ||
86 | { | ||
87 | if (__copy_from_user(&tsk->thread.i387.fxsave, buf, | ||
88 | sizeof(struct user_i387_struct))) | ||
89 | return -EFAULT; | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | /* | ||
94 | * FPU state for core dumps. | ||
95 | */ | ||
96 | |||
97 | int dump_fpu( struct pt_regs *regs, struct user_i387_struct *fpu ) | ||
98 | { | ||
99 | struct task_struct *tsk = current; | ||
100 | |||
101 | if (!used_math()) | ||
102 | return 0; | ||
103 | |||
104 | unlazy_fpu(tsk); | ||
105 | memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct)); | ||
106 | return 1; | ||
107 | } | ||
108 | |||
109 | int dump_task_fpu(struct task_struct *tsk, struct user_i387_struct *fpu) | ||
110 | { | ||
111 | int fpvalid = !!tsk_used_math(tsk); | ||
112 | |||
113 | if (fpvalid) { | ||
114 | if (tsk == current) | ||
115 | unlazy_fpu(tsk); | ||
116 | memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct)); | ||
117 | } | ||
118 | return fpvalid; | ||
119 | } | ||