Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1994 Linus Torvalds |
| 3 | * |
| 4 | * Pentium III FXSR, SSE support |
| 5 | * General FPU state handling cleanups |
| 6 | * Gareth Hughes <gareth@valinux.com>, May 2000 |
| 7 | */ |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 8 | #include <linux/module.h> |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 9 | #include <linux/regset.h> |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 10 | #include <linux/sched.h> |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/sigcontext.h> |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 13 | #include <asm/processor.h> |
| 14 | #include <asm/math_emu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <asm/uaccess.h> |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 16 | #include <asm/ptrace.h> |
| 17 | #include <asm/i387.h> |
| 18 | #include <asm/user.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_X86_64 |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 21 | # include <asm/sigcontext32.h> |
| 22 | # include <asm/user32.h> |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 23 | #else |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 24 | # define save_i387_xstate_ia32 save_i387_xstate |
| 25 | # define restore_i387_xstate_ia32 restore_i387_xstate |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 26 | # define _fpstate_ia32 _fpstate |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 27 | # define _xstate_ia32 _xstate |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 28 | # define sig_xstate_ia32_size sig_xstate_size |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 29 | # define user_i387_ia32_struct user_i387_struct |
| 30 | # define user32_fxsr_struct user_fxsr_struct |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 31 | #endif |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_MATH_EMULATION |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 34 | # define HAVE_HWFP (boot_cpu_data.hard_math) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #else |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 36 | # define HAVE_HWFP 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #endif |
| 38 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 39 | static unsigned int mxcsr_feature_mask __read_mostly = 0xffffffffu; |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 40 | unsigned int xstate_size; |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 41 | unsigned int sig_xstate_ia32_size = sizeof(struct _fpstate_ia32); |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 42 | static struct i387_fxsave_struct fx_scratch __cpuinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 44 | void __cpuinit mxcsr_feature_mask_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | unsigned long mask = 0; |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | clts(); |
| 49 | if (cpu_has_fxsr) { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 50 | memset(&fx_scratch, 0, sizeof(struct i387_fxsave_struct)); |
| 51 | asm volatile("fxsave %0" : : "m" (fx_scratch)); |
| 52 | mask = fx_scratch.mxcsr_mask; |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 53 | if (mask == 0) |
| 54 | mask = 0x0000ffbf; |
| 55 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | mxcsr_feature_mask &= mask; |
| 57 | stts(); |
| 58 | } |
| 59 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 60 | void __init init_thread_xstate(void) |
| 61 | { |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 62 | if (!HAVE_HWFP) { |
| 63 | xstate_size = sizeof(struct i387_soft_struct); |
| 64 | return; |
| 65 | } |
| 66 | |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 67 | if (cpu_has_xsave) { |
| 68 | xsave_cntxt_init(); |
| 69 | return; |
| 70 | } |
| 71 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 72 | if (cpu_has_fxsr) |
| 73 | xstate_size = sizeof(struct i387_fxsave_struct); |
| 74 | #ifdef CONFIG_X86_32 |
| 75 | else |
| 76 | xstate_size = sizeof(struct i387_fsave_struct); |
| 77 | #endif |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_X86_64 |
| 81 | /* |
| 82 | * Called at bootup to set up the initial FPU state that is later cloned |
| 83 | * into all processes. |
| 84 | */ |
| 85 | void __cpuinit fpu_init(void) |
| 86 | { |
| 87 | unsigned long oldcr0 = read_cr0(); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 88 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 89 | set_in_cr4(X86_CR4_OSFXSR); |
| 90 | set_in_cr4(X86_CR4_OSXMMEXCPT); |
| 91 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 92 | write_cr0(oldcr0 & ~(X86_CR0_TS|X86_CR0_EM)); /* clear TS and EM */ |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 93 | |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Boot processor to setup the FP and extended state context info. |
| 96 | */ |
| 97 | if (!smp_processor_id()) |
| 98 | init_thread_xstate(); |
| 99 | xsave_init(); |
| 100 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 101 | mxcsr_feature_mask_init(); |
| 102 | /* clean state in init */ |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 103 | if (cpu_has_xsave) |
| 104 | current_thread_info()->status = TS_XSAVE; |
| 105 | else |
| 106 | current_thread_info()->status = 0; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 107 | clear_used_math(); |
| 108 | } |
| 109 | #endif /* CONFIG_X86_64 */ |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* |
| 112 | * The _current_ task is using the FPU for the first time |
| 113 | * so initialize it and set the mxcsr to its default |
| 114 | * value at reset if we support XMM instructions and then |
| 115 | * remeber the current task has used the FPU. |
| 116 | */ |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 117 | int init_fpu(struct task_struct *tsk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 119 | if (tsk_used_math(tsk)) { |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 120 | if (HAVE_HWFP && tsk == current) |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 121 | unlazy_fpu(tsk); |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * Memory allocation at the first usage of the FPU and other state. |
| 127 | */ |
| 128 | if (!tsk->thread.xstate) { |
| 129 | tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep, |
| 130 | GFP_KERNEL); |
| 131 | if (!tsk->thread.xstate) |
| 132 | return -ENOMEM; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 135 | #ifdef CONFIG_X86_32 |
| 136 | if (!HAVE_HWFP) { |
| 137 | memset(tsk->thread.xstate, 0, xstate_size); |
| 138 | finit(); |
| 139 | set_stopped_child_used_math(tsk); |
| 140 | return 0; |
| 141 | } |
| 142 | #endif |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (cpu_has_fxsr) { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 145 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; |
| 146 | |
| 147 | memset(fx, 0, xstate_size); |
| 148 | fx->cwd = 0x37f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | if (cpu_has_xmm) |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 150 | fx->mxcsr = MXCSR_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } else { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 152 | struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave; |
| 153 | memset(fp, 0, xstate_size); |
| 154 | fp->cwd = 0xffff037fu; |
| 155 | fp->swd = 0xffff0000u; |
| 156 | fp->twd = 0xffffffffu; |
| 157 | fp->fos = 0xffff0000u; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 159 | /* |
| 160 | * Only the device not available exception or ptrace can call init_fpu. |
| 161 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | set_stopped_child_used_math(tsk); |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 163 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 166 | int fpregs_active(struct task_struct *target, const struct user_regset *regset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 168 | return tsk_used_math(target) ? regset->n : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 170 | |
| 171 | int xfpregs_active(struct task_struct *target, const struct user_regset *regset) |
| 172 | { |
| 173 | return (cpu_has_fxsr && tsk_used_math(target)) ? regset->n : 0; |
| 174 | } |
| 175 | |
| 176 | int xfpregs_get(struct task_struct *target, const struct user_regset *regset, |
| 177 | unsigned int pos, unsigned int count, |
| 178 | void *kbuf, void __user *ubuf) |
| 179 | { |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 180 | int ret; |
| 181 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 182 | if (!cpu_has_fxsr) |
| 183 | return -ENODEV; |
| 184 | |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 185 | ret = init_fpu(target); |
| 186 | if (ret) |
| 187 | return ret; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 188 | |
| 189 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 190 | &target->thread.xstate->fxsave, 0, -1); |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | int xfpregs_set(struct task_struct *target, const struct user_regset *regset, |
| 194 | unsigned int pos, unsigned int count, |
| 195 | const void *kbuf, const void __user *ubuf) |
| 196 | { |
| 197 | int ret; |
| 198 | |
| 199 | if (!cpu_has_fxsr) |
| 200 | return -ENODEV; |
| 201 | |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 202 | ret = init_fpu(target); |
| 203 | if (ret) |
| 204 | return ret; |
| 205 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 206 | set_stopped_child_used_math(target); |
| 207 | |
| 208 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 209 | &target->thread.xstate->fxsave, 0, -1); |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * mxcsr reserved bits must be masked to zero for security reasons. |
| 213 | */ |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 214 | target->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 215 | |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* |
| 222 | * FPU tag word conversions. |
| 223 | */ |
| 224 | |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 225 | static inline unsigned short twd_i387_to_fxsr(unsigned short twd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | unsigned int tmp; /* to avoid 16 bit prefixes in the code */ |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* Transform each pair of bits into 01 (valid) or 00 (empty) */ |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 230 | tmp = ~twd; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 231 | tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 232 | /* and move the valid bits to the lower byte. */ |
| 233 | tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ |
| 234 | tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ |
| 235 | tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 236 | |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 237 | return tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 240 | #define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n) * 16); |
| 241 | #define FP_EXP_TAG_VALID 0 |
| 242 | #define FP_EXP_TAG_ZERO 1 |
| 243 | #define FP_EXP_TAG_SPECIAL 2 |
| 244 | #define FP_EXP_TAG_EMPTY 3 |
| 245 | |
| 246 | static inline u32 twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 248 | struct _fpxreg *st; |
| 249 | u32 tos = (fxsave->swd >> 11) & 7; |
| 250 | u32 twd = (unsigned long) fxsave->twd; |
| 251 | u32 tag; |
| 252 | u32 ret = 0xffff0000u; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | int i; |
| 254 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 255 | for (i = 0; i < 8; i++, twd >>= 1) { |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 256 | if (twd & 0x1) { |
| 257 | st = FPREG_ADDR(fxsave, (i - tos) & 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 259 | switch (st->exponent & 0x7fff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | case 0x7fff: |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 261 | tag = FP_EXP_TAG_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | break; |
| 263 | case 0x0000: |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 264 | if (!st->significand[0] && |
| 265 | !st->significand[1] && |
| 266 | !st->significand[2] && |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 267 | !st->significand[3]) |
| 268 | tag = FP_EXP_TAG_ZERO; |
| 269 | else |
| 270 | tag = FP_EXP_TAG_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | break; |
| 272 | default: |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 273 | if (st->significand[3] & 0x8000) |
| 274 | tag = FP_EXP_TAG_VALID; |
| 275 | else |
| 276 | tag = FP_EXP_TAG_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | } |
| 279 | } else { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 280 | tag = FP_EXP_TAG_EMPTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 282 | ret |= tag << (2 * i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | * FXSR floating point environment conversions. |
| 289 | */ |
| 290 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 291 | static void |
| 292 | convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 294 | struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 295 | struct _fpreg *to = (struct _fpreg *) &env->st_space[0]; |
| 296 | struct _fpxreg *from = (struct _fpxreg *) &fxsave->st_space[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | int i; |
| 298 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 299 | env->cwd = fxsave->cwd | 0xffff0000u; |
| 300 | env->swd = fxsave->swd | 0xffff0000u; |
| 301 | env->twd = twd_fxsr_to_i387(fxsave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 303 | #ifdef CONFIG_X86_64 |
| 304 | env->fip = fxsave->rip; |
| 305 | env->foo = fxsave->rdp; |
| 306 | if (tsk == current) { |
| 307 | /* |
| 308 | * should be actually ds/cs at fpu exception time, but |
| 309 | * that information is not available in 64bit mode. |
| 310 | */ |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 311 | asm("mov %%ds, %[fos]" : [fos] "=r" (env->fos)); |
| 312 | asm("mov %%cs, %[fcs]" : [fcs] "=r" (env->fcs)); |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 313 | } else { |
| 314 | struct pt_regs *regs = task_pt_regs(tsk); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 315 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 316 | env->fos = 0xffff0000 | tsk->thread.ds; |
| 317 | env->fcs = regs->cs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 319 | #else |
| 320 | env->fip = fxsave->fip; |
Jan Beulich | 609b529 | 2008-03-05 08:35:14 +0000 | [diff] [blame] | 321 | env->fcs = (u16) fxsave->fcs | ((u32) fxsave->fop << 16); |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 322 | env->foo = fxsave->foo; |
| 323 | env->fos = fxsave->fos; |
| 324 | #endif |
| 325 | |
| 326 | for (i = 0; i < 8; ++i) |
| 327 | memcpy(&to[i], &from[i], sizeof(to[0])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 330 | static void convert_to_fxsr(struct task_struct *tsk, |
| 331 | const struct user_i387_ia32_struct *env) |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 334 | struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 335 | struct _fpreg *from = (struct _fpreg *) &env->st_space[0]; |
| 336 | struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int i; |
| 338 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 339 | fxsave->cwd = env->cwd; |
| 340 | fxsave->swd = env->swd; |
| 341 | fxsave->twd = twd_i387_to_fxsr(env->twd); |
| 342 | fxsave->fop = (u16) ((u32) env->fcs >> 16); |
| 343 | #ifdef CONFIG_X86_64 |
| 344 | fxsave->rip = env->fip; |
| 345 | fxsave->rdp = env->foo; |
| 346 | /* cs and ds ignored */ |
| 347 | #else |
| 348 | fxsave->fip = env->fip; |
| 349 | fxsave->fcs = (env->fcs & 0xffff); |
| 350 | fxsave->foo = env->foo; |
| 351 | fxsave->fos = env->fos; |
| 352 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 354 | for (i = 0; i < 8; ++i) |
| 355 | memcpy(&to[i], &from[i], sizeof(from[0])); |
| 356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 358 | int fpregs_get(struct task_struct *target, const struct user_regset *regset, |
| 359 | unsigned int pos, unsigned int count, |
| 360 | void *kbuf, void __user *ubuf) |
| 361 | { |
| 362 | struct user_i387_ia32_struct env; |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 363 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 365 | ret = init_fpu(target); |
| 366 | if (ret) |
| 367 | return ret; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 368 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 369 | if (!HAVE_HWFP) |
| 370 | return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf); |
| 371 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 372 | if (!cpu_has_fxsr) { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 373 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 374 | &target->thread.xstate->fsave, 0, |
| 375 | -1); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 376 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 377 | |
| 378 | if (kbuf && pos == 0 && count == sizeof(env)) { |
| 379 | convert_from_fxsr(kbuf, target); |
| 380 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 382 | |
| 383 | convert_from_fxsr(&env, target); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 384 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 385 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &env, 0, -1); |
| 386 | } |
| 387 | |
| 388 | int fpregs_set(struct task_struct *target, const struct user_regset *regset, |
| 389 | unsigned int pos, unsigned int count, |
| 390 | const void *kbuf, const void __user *ubuf) |
| 391 | { |
| 392 | struct user_i387_ia32_struct env; |
| 393 | int ret; |
| 394 | |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 395 | ret = init_fpu(target); |
| 396 | if (ret) |
| 397 | return ret; |
| 398 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 399 | set_stopped_child_used_math(target); |
| 400 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 401 | if (!HAVE_HWFP) |
| 402 | return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf); |
| 403 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 404 | if (!cpu_has_fxsr) { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 405 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 406 | &target->thread.xstate->fsave, 0, -1); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 407 | } |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 408 | |
| 409 | if (pos > 0 || count < sizeof(env)) |
| 410 | convert_from_fxsr(&env, target); |
| 411 | |
| 412 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &env, 0, -1); |
| 413 | if (!ret) |
| 414 | convert_to_fxsr(target, &env); |
| 415 | |
| 416 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Signal frame handlers. |
| 421 | */ |
| 422 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 423 | static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | struct task_struct *tsk = current; |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 426 | struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 428 | fp->status = fp->swd; |
| 429 | if (__copy_to_user(buf, fp, sizeof(struct i387_fsave_struct))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | return -1; |
| 431 | return 1; |
| 432 | } |
| 433 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 434 | static int save_i387_fxsave(struct _fpstate_ia32 __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
| 436 | struct task_struct *tsk = current; |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 437 | struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 438 | struct user_i387_ia32_struct env; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | int err = 0; |
| 440 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 441 | convert_from_fxsr(&env, tsk); |
| 442 | if (__copy_to_user(buf, &env, sizeof(env))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | return -1; |
| 444 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 445 | err |= __put_user(fx->swd, &buf->status); |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 446 | err |= __put_user(X86_FXSR_MAGIC, &buf->magic); |
| 447 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | return -1; |
| 449 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 450 | if (__copy_to_user(&buf->_fxsr_env[0], fx, |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 451 | sizeof(struct i387_fxsave_struct))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return -1; |
| 453 | return 1; |
| 454 | } |
| 455 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 456 | int save_i387_xstate_ia32(void __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 458 | struct _fpstate_ia32 __user *fp = (struct _fpstate_ia32 __user *) buf; |
| 459 | struct task_struct *tsk = current; |
| 460 | |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 461 | if (!used_math()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 463 | |
| 464 | if (!access_ok(VERIFY_WRITE, buf, sig_xstate_ia32_size)) |
| 465 | return -EACCES; |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 466 | /* |
| 467 | * This will cause a "finit" to be triggered by the next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | * attempted FPU operation by the 'current' process. |
| 469 | */ |
| 470 | clear_used_math(); |
| 471 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 472 | if (!HAVE_HWFP) { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 473 | return fpregs_soft_get(current, NULL, |
| 474 | 0, sizeof(struct user_i387_ia32_struct), |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 475 | NULL, fp) ? -1 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 477 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 478 | unlazy_fpu(tsk); |
| 479 | |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 480 | if (cpu_has_fxsr) |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 481 | return save_i387_fxsave(fp); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 482 | else |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 483 | return save_i387_fsave(fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 486 | static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
| 488 | struct task_struct *tsk = current; |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 489 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 490 | return __copy_from_user(&tsk->thread.xstate->fsave, buf, |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 491 | sizeof(struct i387_fsave_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 494 | static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | struct task_struct *tsk = current; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 497 | struct user_i387_ia32_struct env; |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 498 | int err; |
| 499 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 500 | err = __copy_from_user(&tsk->thread.xstate->fxsave, &buf->_fxsr_env[0], |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 501 | sizeof(struct i387_fxsave_struct)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | /* mxcsr reserved bits must be masked to zero for security reasons */ |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 503 | tsk->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask; |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 504 | if (err || __copy_from_user(&env, buf, sizeof(env))) |
| 505 | return 1; |
| 506 | convert_to_fxsr(tsk, &env); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 507 | |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 508 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 511 | int restore_i387_xstate_ia32(void __user *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
| 513 | int err; |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 514 | struct task_struct *tsk = current; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 515 | struct _fpstate_ia32 __user *fp = (struct _fpstate_ia32 __user *) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 517 | if (HAVE_HWFP) |
Suresh Siddha | fd3c3ed | 2008-05-07 12:09:52 -0700 | [diff] [blame] | 518 | clear_fpu(tsk); |
| 519 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 520 | if (!buf) { |
| 521 | if (used_math()) { |
| 522 | clear_fpu(tsk); |
| 523 | clear_used_math(); |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } else |
| 528 | if (!access_ok(VERIFY_READ, buf, sig_xstate_ia32_size)) |
| 529 | return -EACCES; |
| 530 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 531 | if (!used_math()) { |
| 532 | err = init_fpu(tsk); |
| 533 | if (err) |
| 534 | return err; |
| 535 | } |
Suresh Siddha | fd3c3ed | 2008-05-07 12:09:52 -0700 | [diff] [blame] | 536 | |
Suresh Siddha | e8a496a | 2008-05-23 16:26:37 -0700 | [diff] [blame] | 537 | if (HAVE_HWFP) { |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 538 | if (cpu_has_fxsr) |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 539 | err = restore_i387_fxsave(fp); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 540 | else |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 541 | err = restore_i387_fsave(fp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } else { |
Roland McGrath | 4421011 | 2008-01-30 13:31:50 +0100 | [diff] [blame] | 543 | err = fpregs_soft_set(current, NULL, |
| 544 | 0, sizeof(struct user_i387_ia32_struct), |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame^] | 545 | NULL, fp) != 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | set_used_math(); |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | return err; |
| 550 | } |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* |
| 553 | * FPU state for core dumps. |
Roland McGrath | 60b3b9a | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 554 | * This is only used for a.out dumps now. |
| 555 | * It is declared generically using elf_fpregset_t (which is |
| 556 | * struct user_i387_struct) but is in fact only used for 32-bit |
| 557 | * dumps, so on 64-bit it is really struct user_i387_ia32_struct. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | */ |
Cyrill Gorcunov | 3b095a0 | 2008-01-30 13:31:26 +0100 | [diff] [blame] | 559 | int dump_fpu(struct pt_regs *regs, struct user_i387_struct *fpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | struct task_struct *tsk = current; |
Ingo Molnar | f668964 | 2008-03-05 15:37:32 +0100 | [diff] [blame] | 562 | int fpvalid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | fpvalid = !!used_math(); |
Roland McGrath | 60b3b9a | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 565 | if (fpvalid) |
| 566 | fpvalid = !fpregs_get(tsk, NULL, |
| 567 | 0, sizeof(struct user_i387_ia32_struct), |
| 568 | fpu, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | return fpvalid; |
| 571 | } |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 572 | EXPORT_SYMBOL(dump_fpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Roland McGrath | 60b3b9a | 2008-01-30 13:31:55 +0100 | [diff] [blame] | 574 | #endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */ |