blob: 92f3c6ed817fbd6d3ea2d110efb1c7d20e822213 [file] [log] [blame]
Linus Torvalds1361b832012-02-21 13:19:22 -08001/*
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 * x86-64 work by Andi Kleen 2002
8 */
9
10#ifndef _FPU_INTERNAL_H
11#define _FPU_INTERNAL_H
12
13#include <linux/kernel_stat.h>
14#include <linux/regset.h>
Suresh Siddha050902c2012-07-24 16:05:27 -070015#include <linux/compat.h>
Linus Torvalds1361b832012-02-21 13:19:22 -080016#include <linux/slab.h>
17#include <asm/asm.h>
18#include <asm/cpufeature.h>
19#include <asm/processor.h>
20#include <asm/sigcontext.h>
21#include <asm/user.h>
22#include <asm/uaccess.h>
23#include <asm/xsave.h>
24
Suresh Siddha72a671c2012-07-24 16:05:29 -070025#ifdef CONFIG_X86_64
26# include <asm/sigcontext32.h>
27# include <asm/user32.h>
28int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
29 compat_sigset_t *set, struct pt_regs *regs);
30int ia32_setup_frame(int sig, struct k_sigaction *ka,
31 compat_sigset_t *set, struct pt_regs *regs);
32#else
33# define user_i387_ia32_struct user_i387_struct
34# define user32_fxsr_struct user_fxsr_struct
35# define ia32_setup_frame __setup_frame
36# define ia32_setup_rt_frame __setup_rt_frame
37#endif
38
39extern unsigned int mxcsr_feature_mask;
Linus Torvalds1361b832012-02-21 13:19:22 -080040extern void fpu_init(void);
Suresh Siddha5d2bd702012-09-06 14:58:52 -070041extern void eager_fpu_init(void);
Linus Torvalds1361b832012-02-21 13:19:22 -080042
43DECLARE_PER_CPU(struct task_struct *, fpu_owner_task);
44
Suresh Siddha72a671c2012-07-24 16:05:29 -070045extern void convert_from_fxsr(struct user_i387_ia32_struct *env,
46 struct task_struct *tsk);
47extern void convert_to_fxsr(struct task_struct *tsk,
48 const struct user_i387_ia32_struct *env);
49
Linus Torvalds1361b832012-02-21 13:19:22 -080050extern user_regset_active_fn fpregs_active, xfpregs_active;
51extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get,
52 xstateregs_get;
53extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set,
54 xstateregs_set;
55
Linus Torvalds1361b832012-02-21 13:19:22 -080056/*
57 * xstateregs_active == fpregs_active. Please refer to the comment
58 * at the definition of fpregs_active.
59 */
60#define xstateregs_active fpregs_active
61
Linus Torvalds1361b832012-02-21 13:19:22 -080062#ifdef CONFIG_MATH_EMULATION
Suresh Siddha72a671c2012-07-24 16:05:29 -070063# define HAVE_HWFP (boot_cpu_data.hard_math)
Linus Torvalds1361b832012-02-21 13:19:22 -080064extern void finit_soft_fpu(struct i387_soft_struct *soft);
65#else
Suresh Siddha72a671c2012-07-24 16:05:29 -070066# define HAVE_HWFP 1
Linus Torvalds1361b832012-02-21 13:19:22 -080067static inline void finit_soft_fpu(struct i387_soft_struct *soft) {}
68#endif
69
Suresh Siddha050902c2012-07-24 16:05:27 -070070static inline int is_ia32_compat_frame(void)
71{
72 return config_enabled(CONFIG_IA32_EMULATION) &&
73 test_thread_flag(TIF_IA32);
74}
75
76static inline int is_ia32_frame(void)
77{
78 return config_enabled(CONFIG_X86_32) || is_ia32_compat_frame();
79}
80
81static inline int is_x32_frame(void)
82{
83 return config_enabled(CONFIG_X86_X32_ABI) && test_thread_flag(TIF_X32);
84}
85
Linus Torvalds1361b832012-02-21 13:19:22 -080086#define X87_FSW_ES (1 << 7) /* Exception Summary */
87
Suresh Siddha5d2bd702012-09-06 14:58:52 -070088static __always_inline __pure bool use_eager_fpu(void)
89{
90 return static_cpu_has(X86_FEATURE_EAGER_FPU);
91}
92
Linus Torvalds1361b832012-02-21 13:19:22 -080093static __always_inline __pure bool use_xsaveopt(void)
94{
95 return static_cpu_has(X86_FEATURE_XSAVEOPT);
96}
97
98static __always_inline __pure bool use_xsave(void)
99{
100 return static_cpu_has(X86_FEATURE_XSAVE);
101}
102
103static __always_inline __pure bool use_fxsr(void)
104{
105 return static_cpu_has(X86_FEATURE_FXSR);
106}
107
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700108static inline void fx_finit(struct i387_fxsave_struct *fx)
109{
110 memset(fx, 0, xstate_size);
111 fx->cwd = 0x37f;
Suresh Siddhaa8615af2012-09-10 10:40:08 -0700112 fx->mxcsr = MXCSR_DEFAULT;
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700113}
114
Linus Torvalds1361b832012-02-21 13:19:22 -0800115extern void __sanitize_i387_state(struct task_struct *);
116
117static inline void sanitize_i387_state(struct task_struct *tsk)
118{
119 if (!use_xsaveopt())
120 return;
121 __sanitize_i387_state(tsk);
122}
123
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700124#define check_insn(insn, output, input...) \
125({ \
126 int err; \
127 asm volatile("1:" #insn "\n\t" \
128 "2:\n" \
129 ".section .fixup,\"ax\"\n" \
130 "3: movl $-1,%[err]\n" \
131 " jmp 2b\n" \
132 ".previous\n" \
133 _ASM_EXTABLE(1b, 3b) \
134 : [err] "=r" (err), output \
135 : "0"(0), input); \
136 err; \
137})
Linus Torvalds1361b832012-02-21 13:19:22 -0800138
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700139static inline int fsave_user(struct i387_fsave_struct __user *fx)
140{
141 return check_insn(fnsave %[fx]; fwait, [fx] "=m" (*fx), "m" (*fx));
Linus Torvalds1361b832012-02-21 13:19:22 -0800142}
143
144static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
145{
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700146 if (config_enabled(CONFIG_X86_32))
147 return check_insn(fxsave %[fx], [fx] "=m" (*fx), "m" (*fx));
148 else if (config_enabled(CONFIG_AS_FXSAVEQ))
149 return check_insn(fxsaveq %[fx], [fx] "=m" (*fx), "m" (*fx));
150
151 /* See comment in fpu_fxsave() below. */
152 return check_insn(rex64/fxsave (%[fx]), "=m" (*fx), [fx] "R" (fx));
153}
154
155static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
156{
157 if (config_enabled(CONFIG_X86_32))
158 return check_insn(fxrstor %[fx], "=m" (*fx), [fx] "m" (*fx));
159 else if (config_enabled(CONFIG_AS_FXSAVEQ))
160 return check_insn(fxrstorq %[fx], "=m" (*fx), [fx] "m" (*fx));
161
162 /* See comment in fpu_fxsave() below. */
163 return check_insn(rex64/fxrstor (%[fx]), "=m" (*fx), [fx] "R" (fx),
164 "m" (*fx));
165}
166
167static inline int frstor_checking(struct i387_fsave_struct *fx)
168{
169 return check_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx));
Linus Torvalds1361b832012-02-21 13:19:22 -0800170}
171
172static inline void fpu_fxsave(struct fpu *fpu)
173{
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700174 if (config_enabled(CONFIG_X86_32))
175 asm volatile( "fxsave %[fx]" : [fx] "=m" (fpu->state->fxsave));
176 else if (config_enabled(CONFIG_AS_FXSAVEQ))
177 asm volatile("fxsaveq %0" : "=m" (fpu->state->fxsave));
178 else {
179 /* Using "rex64; fxsave %0" is broken because, if the memory
180 * operand uses any extended registers for addressing, a second
181 * REX prefix will be generated (to the assembler, rex64
182 * followed by semicolon is a separate instruction), and hence
183 * the 64-bitness is lost.
184 *
185 * Using "fxsaveq %0" would be the ideal choice, but is only
186 * supported starting with gas 2.16.
187 *
188 * Using, as a workaround, the properly prefixed form below
189 * isn't accepted by any binutils version so far released,
190 * complaining that the same type of prefix is used twice if
191 * an extended register is needed for addressing (fix submitted
192 * to mainline 2005-11-21).
193 *
194 * asm volatile("rex64/fxsave %0" : "=m" (fpu->state->fxsave));
195 *
196 * This, however, we can work around by forcing the compiler to
197 * select an addressing mode that doesn't require extended
198 * registers.
199 */
200 asm volatile( "rex64/fxsave (%[fx])"
201 : "=m" (fpu->state->fxsave)
202 : [fx] "R" (&fpu->state->fxsave));
203 }
Linus Torvalds1361b832012-02-21 13:19:22 -0800204}
Linus Torvalds1361b832012-02-21 13:19:22 -0800205
206/*
207 * These must be called with preempt disabled. Returns
208 * 'true' if the FPU state is still intact.
209 */
210static inline int fpu_save_init(struct fpu *fpu)
211{
212 if (use_xsave()) {
213 fpu_xsave(fpu);
214
215 /*
216 * xsave header may indicate the init state of the FP.
217 */
218 if (!(fpu->state->xsave.xsave_hdr.xstate_bv & XSTATE_FP))
219 return 1;
220 } else if (use_fxsr()) {
221 fpu_fxsave(fpu);
222 } else {
223 asm volatile("fnsave %[fx]; fwait"
224 : [fx] "=m" (fpu->state->fsave));
225 return 0;
226 }
227
228 /*
229 * If exceptions are pending, we need to clear them so
230 * that we don't randomly get exceptions later.
231 *
232 * FIXME! Is this perhaps only true for the old-style
233 * irq13 case? Maybe we could leave the x87 state
234 * intact otherwise?
235 */
236 if (unlikely(fpu->state->fxsave.swd & X87_FSW_ES)) {
237 asm volatile("fnclex");
238 return 0;
239 }
240 return 1;
241}
242
243static inline int __save_init_fpu(struct task_struct *tsk)
244{
245 return fpu_save_init(&tsk->thread.fpu);
246}
247
Linus Torvalds1361b832012-02-21 13:19:22 -0800248static inline int fpu_restore_checking(struct fpu *fpu)
249{
250 if (use_xsave())
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700251 return fpu_xrstor_checking(&fpu->state->xsave);
252 else if (use_fxsr())
253 return fxrstor_checking(&fpu->state->fxsave);
Linus Torvalds1361b832012-02-21 13:19:22 -0800254 else
Suresh Siddha0ca5bd02012-07-24 16:05:28 -0700255 return frstor_checking(&fpu->state->fsave);
Linus Torvalds1361b832012-02-21 13:19:22 -0800256}
257
258static inline int restore_fpu_checking(struct task_struct *tsk)
259{
260 /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
261 is pending. Clear the x87 state here by setting it to fixed
262 values. "m" is a random variable that should be in L1 */
263 alternative_input(
264 ASM_NOP8 ASM_NOP2,
265 "emms\n\t" /* clear stack tags */
266 "fildl %P[addr]", /* set F?P to defined value */
267 X86_FEATURE_FXSAVE_LEAK,
268 [addr] "m" (tsk->thread.fpu.has_fpu));
269
270 return fpu_restore_checking(&tsk->thread.fpu);
271}
272
273/*
274 * Software FPU state helpers. Careful: these need to
275 * be preemption protection *and* they need to be
276 * properly paired with the CR0.TS changes!
277 */
278static inline int __thread_has_fpu(struct task_struct *tsk)
279{
280 return tsk->thread.fpu.has_fpu;
281}
282
283/* Must be paired with an 'stts' after! */
284static inline void __thread_clear_has_fpu(struct task_struct *tsk)
285{
286 tsk->thread.fpu.has_fpu = 0;
Alex Shic6ae41e2012-05-11 15:35:27 +0800287 this_cpu_write(fpu_owner_task, NULL);
Linus Torvalds1361b832012-02-21 13:19:22 -0800288}
289
290/* Must be paired with a 'clts' before! */
291static inline void __thread_set_has_fpu(struct task_struct *tsk)
292{
293 tsk->thread.fpu.has_fpu = 1;
Alex Shic6ae41e2012-05-11 15:35:27 +0800294 this_cpu_write(fpu_owner_task, tsk);
Linus Torvalds1361b832012-02-21 13:19:22 -0800295}
296
297/*
298 * Encapsulate the CR0.TS handling together with the
299 * software flag.
300 *
301 * These generally need preemption protection to work,
302 * do try to avoid using these on their own.
303 */
304static inline void __thread_fpu_end(struct task_struct *tsk)
305{
306 __thread_clear_has_fpu(tsk);
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700307 if (!use_eager_fpu())
Suresh Siddha304bced2012-08-24 14:13:02 -0700308 stts();
Linus Torvalds1361b832012-02-21 13:19:22 -0800309}
310
311static inline void __thread_fpu_begin(struct task_struct *tsk)
312{
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700313 if (!use_eager_fpu())
Suresh Siddha304bced2012-08-24 14:13:02 -0700314 clts();
Linus Torvalds1361b832012-02-21 13:19:22 -0800315 __thread_set_has_fpu(tsk);
316}
317
Suresh Siddha304bced2012-08-24 14:13:02 -0700318static inline void __drop_fpu(struct task_struct *tsk)
319{
320 if (__thread_has_fpu(tsk)) {
321 /* Ignore delayed exceptions from user space */
322 asm volatile("1: fwait\n"
323 "2:\n"
324 _ASM_EXTABLE(1b, 2b));
325 __thread_fpu_end(tsk);
326 }
327}
328
329static inline void drop_fpu(struct task_struct *tsk)
330{
331 /*
332 * Forget coprocessor state..
333 */
334 preempt_disable();
335 tsk->fpu_counter = 0;
336 __drop_fpu(tsk);
337 clear_used_math();
338 preempt_enable();
339}
340
341static inline void drop_init_fpu(struct task_struct *tsk)
342{
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700343 if (!use_eager_fpu())
Suresh Siddha304bced2012-08-24 14:13:02 -0700344 drop_fpu(tsk);
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700345 else {
346 if (use_xsave())
347 xrstor_state(init_xstate_buf, -1);
348 else
349 fxrstor_checking(&init_xstate_buf->i387);
350 }
Suresh Siddha304bced2012-08-24 14:13:02 -0700351}
352
Linus Torvalds1361b832012-02-21 13:19:22 -0800353/*
354 * FPU state switching for scheduling.
355 *
356 * This is a two-stage process:
357 *
358 * - switch_fpu_prepare() saves the old state and
359 * sets the new state of the CR0.TS bit. This is
360 * done within the context of the old process.
361 *
362 * - switch_fpu_finish() restores the new state as
363 * necessary.
364 */
365typedef struct { int preload; } fpu_switch_t;
366
367/*
368 * FIXME! We could do a totally lazy restore, but we need to
369 * add a per-cpu "this was the task that last touched the FPU
370 * on this CPU" variable, and the task needs to have a "I last
371 * touched the FPU on this CPU" and check them.
372 *
373 * We don't do that yet, so "fpu_lazy_restore()" always returns
374 * false, but some day..
375 */
376static inline int fpu_lazy_restore(struct task_struct *new, unsigned int cpu)
377{
Alex Shic6ae41e2012-05-11 15:35:27 +0800378 return new == this_cpu_read_stable(fpu_owner_task) &&
Linus Torvalds1361b832012-02-21 13:19:22 -0800379 cpu == new->thread.fpu.last_cpu;
380}
381
382static inline fpu_switch_t switch_fpu_prepare(struct task_struct *old, struct task_struct *new, int cpu)
383{
384 fpu_switch_t fpu;
385
Suresh Siddha304bced2012-08-24 14:13:02 -0700386 /*
387 * If the task has used the math, pre-load the FPU on xsave processors
388 * or if the past 5 consecutive context-switches used math.
389 */
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700390 fpu.preload = tsk_used_math(new) && (use_eager_fpu() ||
Suresh Siddha304bced2012-08-24 14:13:02 -0700391 new->fpu_counter > 5);
Linus Torvalds1361b832012-02-21 13:19:22 -0800392 if (__thread_has_fpu(old)) {
393 if (!__save_init_fpu(old))
394 cpu = ~0;
395 old->thread.fpu.last_cpu = cpu;
396 old->thread.fpu.has_fpu = 0; /* But leave fpu_owner_task! */
397
398 /* Don't change CR0.TS if we just switch! */
399 if (fpu.preload) {
400 new->fpu_counter++;
401 __thread_set_has_fpu(new);
402 prefetch(new->thread.fpu.state);
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700403 } else if (!use_eager_fpu())
Linus Torvalds1361b832012-02-21 13:19:22 -0800404 stts();
405 } else {
406 old->fpu_counter = 0;
407 old->thread.fpu.last_cpu = ~0;
408 if (fpu.preload) {
409 new->fpu_counter++;
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700410 if (!use_eager_fpu() && fpu_lazy_restore(new, cpu))
Linus Torvalds1361b832012-02-21 13:19:22 -0800411 fpu.preload = 0;
412 else
413 prefetch(new->thread.fpu.state);
414 __thread_fpu_begin(new);
415 }
416 }
417 return fpu;
418}
419
420/*
421 * By the time this gets called, we've already cleared CR0.TS and
422 * given the process the FPU if we are going to preload the FPU
423 * state - all we need to do is to conditionally restore the register
424 * state itself.
425 */
426static inline void switch_fpu_finish(struct task_struct *new, fpu_switch_t fpu)
427{
428 if (fpu.preload) {
429 if (unlikely(restore_fpu_checking(new)))
Suresh Siddha304bced2012-08-24 14:13:02 -0700430 drop_init_fpu(new);
Linus Torvalds1361b832012-02-21 13:19:22 -0800431 }
432}
433
434/*
435 * Signal frame handlers...
436 */
Suresh Siddha72a671c2012-07-24 16:05:29 -0700437extern int save_xstate_sig(void __user *buf, void __user *fx, int size);
438extern int __restore_xstate_sig(void __user *buf, void __user *fx, int size);
Linus Torvalds1361b832012-02-21 13:19:22 -0800439
Suresh Siddha72a671c2012-07-24 16:05:29 -0700440static inline int xstate_sigframe_size(void)
441{
442 return use_xsave() ? xstate_size + FP_XSTATE_MAGIC2_SIZE : xstate_size;
443}
444
445static inline int restore_xstate_sig(void __user *buf, int ia32_frame)
446{
447 void __user *buf_fx = buf;
448 int size = xstate_sigframe_size();
449
450 if (ia32_frame && use_fxsr()) {
451 buf_fx = buf + sizeof(struct i387_fsave_struct);
452 size += sizeof(struct i387_fsave_struct);
453 }
454
455 return __restore_xstate_sig(buf, buf_fx, size);
456}
457
Linus Torvalds1361b832012-02-21 13:19:22 -0800458/*
Suresh Siddha377ffbc2012-08-24 14:12:58 -0700459 * Need to be preemption-safe.
Linus Torvalds1361b832012-02-21 13:19:22 -0800460 *
Suresh Siddha377ffbc2012-08-24 14:12:58 -0700461 * NOTE! user_fpu_begin() must be used only immediately before restoring
462 * it. This function does not do any save/restore on their own.
Linus Torvalds1361b832012-02-21 13:19:22 -0800463 */
Linus Torvalds1361b832012-02-21 13:19:22 -0800464static inline void user_fpu_begin(void)
465{
466 preempt_disable();
467 if (!user_has_fpu())
468 __thread_fpu_begin(current);
469 preempt_enable();
470}
471
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700472static inline void __save_fpu(struct task_struct *tsk)
473{
474 if (use_xsave())
475 xsave_state(&tsk->thread.fpu.state->xsave, -1);
476 else
477 fpu_fxsave(&tsk->thread.fpu);
478}
479
Linus Torvalds1361b832012-02-21 13:19:22 -0800480/*
481 * These disable preemption on their own and are safe
482 */
483static inline void save_init_fpu(struct task_struct *tsk)
484{
485 WARN_ON_ONCE(!__thread_has_fpu(tsk));
Suresh Siddha304bced2012-08-24 14:13:02 -0700486
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700487 if (use_eager_fpu()) {
488 __save_fpu(tsk);
Suresh Siddha304bced2012-08-24 14:13:02 -0700489 return;
490 }
491
Linus Torvalds1361b832012-02-21 13:19:22 -0800492 preempt_disable();
493 __save_init_fpu(tsk);
494 __thread_fpu_end(tsk);
495 preempt_enable();
496}
497
Linus Torvalds1361b832012-02-21 13:19:22 -0800498/*
499 * i387 state interaction
500 */
501static inline unsigned short get_fpu_cwd(struct task_struct *tsk)
502{
503 if (cpu_has_fxsr) {
504 return tsk->thread.fpu.state->fxsave.cwd;
505 } else {
506 return (unsigned short)tsk->thread.fpu.state->fsave.cwd;
507 }
508}
509
510static inline unsigned short get_fpu_swd(struct task_struct *tsk)
511{
512 if (cpu_has_fxsr) {
513 return tsk->thread.fpu.state->fxsave.swd;
514 } else {
515 return (unsigned short)tsk->thread.fpu.state->fsave.swd;
516 }
517}
518
519static inline unsigned short get_fpu_mxcsr(struct task_struct *tsk)
520{
521 if (cpu_has_xmm) {
522 return tsk->thread.fpu.state->fxsave.mxcsr;
523 } else {
524 return MXCSR_DEFAULT;
525 }
526}
527
528static bool fpu_allocated(struct fpu *fpu)
529{
530 return fpu->state != NULL;
531}
532
533static inline int fpu_alloc(struct fpu *fpu)
534{
535 if (fpu_allocated(fpu))
536 return 0;
537 fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_KERNEL);
538 if (!fpu->state)
539 return -ENOMEM;
540 WARN_ON((unsigned long)fpu->state & 15);
541 return 0;
542}
543
544static inline void fpu_free(struct fpu *fpu)
545{
546 if (fpu->state) {
547 kmem_cache_free(task_xstate_cachep, fpu->state);
548 fpu->state = NULL;
549 }
550}
551
Suresh Siddha304bced2012-08-24 14:13:02 -0700552static inline void fpu_copy(struct task_struct *dst, struct task_struct *src)
Linus Torvalds1361b832012-02-21 13:19:22 -0800553{
Suresh Siddha5d2bd702012-09-06 14:58:52 -0700554 if (use_eager_fpu()) {
555 memset(&dst->thread.fpu.state->xsave, 0, xstate_size);
556 __save_fpu(dst);
Suresh Siddha304bced2012-08-24 14:13:02 -0700557 } else {
558 struct fpu *dfpu = &dst->thread.fpu;
559 struct fpu *sfpu = &src->thread.fpu;
560
561 unlazy_fpu(src);
562 memcpy(dfpu->state, sfpu->state, xstate_size);
563 }
564}
Linus Torvalds1361b832012-02-21 13:19:22 -0800565
Suresh Siddha72a671c2012-07-24 16:05:29 -0700566static inline unsigned long
567alloc_mathframe(unsigned long sp, int ia32_frame, unsigned long *buf_fx,
568 unsigned long *size)
569{
570 unsigned long frame_size = xstate_sigframe_size();
571
572 *buf_fx = sp = round_down(sp - frame_size, 64);
573 if (ia32_frame && use_fxsr()) {
574 frame_size += sizeof(struct i387_fsave_struct);
575 sp -= sizeof(struct i387_fsave_struct);
576 }
577
578 *size = frame_size;
579 return sp;
580}
581
Linus Torvalds1361b832012-02-21 13:19:22 -0800582#endif