1 #ifndef __ASM_X86_XSAVE_H
2 #define __ASM_X86_XSAVE_H
4 #include <linux/types.h>
5 #include <asm/processor.h>
10 #define XSTATE_YMM 0x4
12 #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE)
14 #define FXSAVE_SIZE 512
17 * These are the features that the OS can handle currently.
19 #define XCNTXT_MASK (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
22 #define REX_PREFIX "0x48, "
27 extern unsigned int xstate_size
;
28 extern u64 pcntxt_mask
;
29 extern struct xsave_struct
*init_xstate_buf
;
30 extern u64 xstate_fx_sw_bytes
[USER_XSTATE_FX_SW_WORDS
];
32 extern void xsave_cntxt_init(void);
33 extern void xsave_init(void);
34 extern void update_regset_xstate_info(unsigned int size
, u64 xstate_mask
);
35 extern int init_fpu(struct task_struct
*child
);
36 extern int check_for_xstate(struct i387_fxsave_struct __user
*buf
,
38 struct _fpx_sw_bytes
*sw
);
40 static inline int xrstor_checking(struct xsave_struct
*fx
)
44 asm volatile("1: .byte " REX_PREFIX
"0x0f,0xae,0x2f\n\t"
46 ".section .fixup,\"ax\"\n"
47 "3: movl $-1,%[err]\n"
52 : "D" (fx
), "m" (*fx
), "a" (-1), "d" (-1), "0" (0)
58 static inline int xsave_user(struct xsave_struct __user
*buf
)
61 __asm__
__volatile__("1: .byte " REX_PREFIX
"0x0f,0xae,0x27\n"
63 ".section .fixup,\"ax\"\n"
64 "3: movl $-1,%[err]\n"
67 ".section __ex_table,\"a\"\n"
72 : "D" (buf
), "a" (-1), "d" (-1), "0" (0)
74 if (unlikely(err
) && __clear_user(buf
, xstate_size
))
76 /* No need to clear here because the caller clears USED_MATH */
80 static inline int xrestore_user(struct xsave_struct __user
*buf
, u64 mask
)
83 struct xsave_struct
*xstate
= ((__force
struct xsave_struct
*)buf
);
85 u32 hmask
= mask
>> 32;
87 __asm__
__volatile__("1: .byte " REX_PREFIX
"0x0f,0xae,0x2f\n"
89 ".section .fixup,\"ax\"\n"
90 "3: movl $-1,%[err]\n"
93 ".section __ex_table,\"a\"\n"
98 : "D" (xstate
), "a" (lmask
), "d" (hmask
), "0" (0)
99 : "memory"); /* memory required? */
103 static inline void xrstor_state(struct xsave_struct
*fx
, u64 mask
)
106 u32 hmask
= mask
>> 32;
108 asm volatile(".byte " REX_PREFIX
"0x0f,0xae,0x2f\n\t"
109 : : "D" (fx
), "m" (*fx
), "a" (lmask
), "d" (hmask
)
113 static inline void xsave(struct task_struct
*tsk
)
115 /* This, however, we can work around by forcing the compiler to select
116 an addressing mode that doesn't require extended registers. */
117 __asm__
__volatile__(".byte " REX_PREFIX
"0x0f,0xae,0x27"
118 : : "D" (&(tsk
->thread
.xstate
->xsave
)),
119 "a" (-1), "d"(-1) : "memory");