1 #ifndef __ASM_X86_XSAVE_H
2 #define __ASM_X86_XSAVE_H
4 #include <linux/types.h>
5 #include <asm/processor.h>
11 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE)
13 #define FXSAVE_SIZE 512
16 * These are the features that the OS can handle currently.
18 #define XCNTXT_MASK (XSTATE_FP | XSTATE_SSE)
21 #define REX_PREFIX "0x48, "
26 extern unsigned int xstate_size;
27 extern u64 pcntxt_mask;
28 extern struct xsave_struct *init_xstate_buf;
30 extern void xsave_cntxt_init(void);
31 extern void xsave_init(void);
32 extern int init_fpu(struct task_struct *child);
33 extern int check_for_xstate(struct i387_fxsave_struct __user *buf,
35 struct _fpx_sw_bytes *sw);
37 static inline int xrstor_checking(struct xsave_struct *fx)
41 asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
43 ".section .fixup,\"ax\"\n"
44 "3: movl $-1,%[err]\n"
49 : "D" (fx), "m" (*fx), "a" (-1), "d" (-1), "0" (0)
55 static inline int xsave_user(struct xsave_struct __user *buf)
58 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
60 ".section .fixup,\"ax\"\n"
61 "3: movl $-1,%[err]\n"
64 ".section __ex_table,\"a\"\n"
69 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
71 if (unlikely(err) && __clear_user(buf, xstate_size))
73 /* No need to clear here because the caller clears USED_MATH */
77 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
80 struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
82 u32 hmask = mask >> 32;
84 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
86 ".section .fixup,\"ax\"\n"
87 "3: movl $-1,%[err]\n"
90 ".section __ex_table,\"a\"\n"
95 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
96 : "memory"); /* memory required? */
100 static inline void xrstor_state(struct xsave_struct *fx, u64 mask)
103 u32 hmask = mask >> 32;
105 asm volatile(".byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
106 : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
110 static inline void xsave(struct task_struct *tsk)
112 /* This, however, we can work around by forcing the compiler to select
113 an addressing mode that doesn't require extended registers. */
114 __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
115 : : "D" (&(tsk->thread.xstate->xsave)),
116 "a" (-1), "d"(-1) : "memory");