]>
Commit | Line | Data |
---|---|---|
bd3239d2 MF |
1 | int cpu_has(unsigned short bit) |
2 | { | |
3 | asm goto ("1: jmp %l[t_no]\n" "2:\n" ".section .altinstructions,\"a\"\n" | |
4 | ".balign 4\n" ".long 1b\n" ".long 0\n" ".word %P0\n" ".byte 2b - 1b\n" ".byte 0\n" | |
5 | ".previous\n"::"i" (bit)::t_no); | |
6 | return 1; | |
7 | t_no:return 0; | |
8 | } | |
9 | ||
10 | struct cpuinfo_x86 { | |
11 | unsigned int x86_capability[10]; | |
12 | }; | |
13 | extern struct cpuinfo_x86 boot_cpu_data; | |
14 | struct i387_fxsave_struct { | |
15 | unsigned short swd; | |
16 | }; | |
17 | struct xsave_struct { | |
18 | int xstate_bv; | |
19 | }; | |
20 | union thread_xstate { | |
21 | struct i387_fxsave_struct fxsave; | |
22 | struct xsave_struct xsave; | |
23 | int xstate_bv; | |
24 | }; | |
25 | struct fpu { | |
26 | union thread_xstate *state; | |
27 | }; | |
28 | __attribute__ ((always_inline)) __attribute__ ((pure)) | |
29 | int use_xsave(void) | |
30 | { | |
31 | return cpu_has(154); | |
32 | } | |
33 | ||
34 | __attribute__ ((always_inline)) __attribute__ ((pure)) | |
35 | int use_fxsr(void) | |
36 | { | |
37 | return cpu_has(24); | |
38 | } | |
39 | __attribute__ ((always_inline)) | |
40 | void fpu_save_init(struct fpu *fpu) | |
41 | { | |
42 | if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) { | |
43 | if (fpu->state-> | |
44 | xstate_bv) | |
45 | return; | |
46 | } else if (use_fxsr()) { | |
47 | } | |
48 | if (__builtin_constant_p | |
49 | ((((__builtin_constant_p(fpu->state->fxsave.swd & 1) ? | |
50 | ! !(fpu->state->fxsave.swd & 1) : ( { | |
51 | __builtin_expect(! ! | |
52 | (fpu-> | |
53 | state-> | |
54 | fxsave. | |
55 | swd | |
56 | & (1 | |
57 | << | |
58 | 7)), | |
59 | 1);} | |
60 | )))))? | |
61 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & 1) ? | |
62 | ! !(fpu->state->fxsave.swd & 1) : ( { | |
63 | __builtin_expect(! ! | |
64 | (fpu-> | |
65 | state-> | |
66 | fxsave. | |
67 | swd | |
68 | & | |
69 | (1 | |
70 | << | |
71 | 7)), | |
72 | 1);} | |
73 | )))): ( { | |
74 | int ______r; | |
75 | ______r = | |
76 | ! !(((__builtin_constant_p(fpu->state->fxsave.swd & 1) | |
77 | ? ! !(fpu->state->fxsave.swd & 1) : ( { | |
78 | ______r = | |
79 | __builtin_expect | |
80 | (! ! | |
81 | (fpu-> | |
82 | state-> | |
83 | fxsave. | |
84 | swd & (1 | |
85 | << | |
86 | 7)), | |
87 | 1);} | |
88 | ))));} | |
89 | )) | |
90 | asm volatile ("fnclex"); | |
91 | } | |
92 | ||
93 | void aes_decrypt(void) | |
94 | { | |
95 | if (irq_fpu_usable()) | |
96 | crypto_aes_decrypt_x86(); | |
97 | else | |
98 | fpu_save_init(0); | |
99 | } | |
100 | ||
101 | void (*funcptr)(void) = aes_decrypt; | |
102 | ||
103 | int aesni_init(void) | |
104 | { | |
105 | if (crypto_register_alg()) | |
106 | crypto_unregister_alg(0); | |
107 | } |