Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 1 | #ifndef __ASM_X86_XSAVE_H |
| 2 | #define __ASM_X86_XSAVE_H |
| 3 | |
| 4 | #include <asm/processor.h> |
| 5 | #include <asm/i387.h> |
| 6 | |
| 7 | #define XSTATE_FP 0x1 |
| 8 | #define XSTATE_SSE 0x2 |
| 9 | |
| 10 | #define XSTATE_FPSSE (XSTATE_FP | XSTATE_SSE) |
| 11 | |
| 12 | #define FXSAVE_SIZE 512 |
| 13 | |
| 14 | /* |
| 15 | * These are the features that the OS can handle currently. |
| 16 | */ |
| 17 | #define XCNTXT_LMASK (XSTATE_FP | XSTATE_SSE) |
| 18 | #define XCNTXT_HMASK 0x0 |
| 19 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 20 | #ifdef CONFIG_X86_64 |
| 21 | #define REX_PREFIX "0x48, " |
| 22 | #else |
| 23 | #define REX_PREFIX |
| 24 | #endif |
| 25 | |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 26 | extern unsigned int xstate_size, pcntxt_hmask, pcntxt_lmask; |
| 27 | extern struct xsave_struct *init_xstate_buf; |
| 28 | |
| 29 | extern void xsave_cntxt_init(void); |
| 30 | extern void xsave_init(void); |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 31 | extern int init_fpu(struct task_struct *child); |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame^] | 32 | extern int check_for_xstate(struct i387_fxsave_struct __user *buf, |
| 33 | void __user *fpstate, |
| 34 | struct _fpx_sw_bytes *sw); |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 35 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 36 | static inline int xrstor_checking(struct xsave_struct *fx) |
| 37 | { |
| 38 | int err; |
| 39 | |
| 40 | asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" |
| 41 | "2:\n" |
| 42 | ".section .fixup,\"ax\"\n" |
| 43 | "3: movl $-1,%[err]\n" |
| 44 | " jmp 2b\n" |
| 45 | ".previous\n" |
| 46 | _ASM_EXTABLE(1b, 3b) |
| 47 | : [err] "=r" (err) |
| 48 | : "D" (fx), "m" (*fx), "a" (-1), "d" (-1), "0" (0) |
| 49 | : "memory"); |
| 50 | |
| 51 | return err; |
| 52 | } |
| 53 | |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame^] | 54 | static inline int xsave_user(struct xsave_struct __user *buf) |
Suresh Siddha | 9dc89c0 | 2008-07-29 10:29:23 -0700 | [diff] [blame] | 55 | { |
| 56 | int err; |
| 57 | __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n" |
| 58 | "2:\n" |
| 59 | ".section .fixup,\"ax\"\n" |
| 60 | "3: movl $-1,%[err]\n" |
| 61 | " jmp 2b\n" |
| 62 | ".previous\n" |
| 63 | ".section __ex_table,\"a\"\n" |
| 64 | _ASM_ALIGN "\n" |
| 65 | _ASM_PTR "1b,3b\n" |
| 66 | ".previous" |
| 67 | : [err] "=r" (err) |
| 68 | : "D" (buf), "a" (-1), "d" (-1), "0" (0) |
| 69 | : "memory"); |
| 70 | if (unlikely(err) && __clear_user(buf, xstate_size)) |
| 71 | err = -EFAULT; |
| 72 | /* No need to clear here because the caller clears USED_MATH */ |
| 73 | return err; |
| 74 | } |
| 75 | |
| 76 | static inline int xrestore_user(struct xsave_struct __user *buf, |
| 77 | unsigned int lmask, |
| 78 | unsigned int hmask) |
| 79 | { |
| 80 | int err; |
| 81 | struct xsave_struct *xstate = ((__force struct xsave_struct *)buf); |
| 82 | |
| 83 | __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n" |
| 84 | "2:\n" |
| 85 | ".section .fixup,\"ax\"\n" |
| 86 | "3: movl $-1,%[err]\n" |
| 87 | " jmp 2b\n" |
| 88 | ".previous\n" |
| 89 | ".section __ex_table,\"a\"\n" |
| 90 | _ASM_ALIGN "\n" |
| 91 | _ASM_PTR "1b,3b\n" |
| 92 | ".previous" |
| 93 | : [err] "=r" (err) |
| 94 | : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0) |
| 95 | : "memory"); /* memory required? */ |
| 96 | return err; |
| 97 | } |
| 98 | |
| 99 | static inline void xrstor_state(struct xsave_struct *fx, int lmask, int hmask) |
| 100 | { |
| 101 | asm volatile(".byte " REX_PREFIX "0x0f,0xae,0x2f\n\t" |
| 102 | : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask) |
| 103 | : "memory"); |
| 104 | } |
| 105 | |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 106 | static inline void xsave(struct task_struct *tsk) |
| 107 | { |
| 108 | /* This, however, we can work around by forcing the compiler to select |
| 109 | an addressing mode that doesn't require extended registers. */ |
| 110 | __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27" |
| 111 | : : "D" (&(tsk->thread.xstate->xsave)), |
| 112 | "a" (-1), "d"(-1) : "memory"); |
| 113 | } |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 114 | #endif |