]> git.wh0rd.org - ICEs.git/blob - 388835/aesni-intel_glue.i.5
more
[ICEs.git] / 388835 / aesni-intel_glue.i.5
1 struct list_head {
2 };
3 int __static_cpu_has(unsigned short bit)
4 {
5 asm goto ("1: jmp %l[t_no]\n" "2:\n" ".section .altinstructions,\"a\"\n"
6 " " ".balign 4" " " "\n" " " ".long" " " "1b\n" " " ".long"
7 " " "0\n" " .word %P0\n" " .byte 2b - 1b\n" " .byte 0\n"
8 ".previous\n"::"i" (bit)::t_no);
9 return 1;
10 t_no:return 0;
11 }
12
13 struct cpuinfo_x86 {
14 unsigned int x86_capability[10];
15 } __attribute__ ((__aligned__((1 << (6)))));
16 extern struct cpuinfo_x86 boot_cpu_data;
17 struct i387_fxsave_struct {
18 unsigned short swd;
19 } __attribute__ ((aligned(16)));
20 struct xsave_hdr_struct {
21 unsigned long long xstate_bv;
22 } __attribute__ ((packed));
23 struct xsave_struct {
24 struct xsave_hdr_struct xsave_hdr;
25 } __attribute__ ((packed, aligned(64)));
26 union thread_xstate {
27 struct i387_fxsave_struct fxsave;
28 struct xsave_struct xsave;
29 };
30 struct fpu {
31 union thread_xstate *state;
32 };
33 struct cipher_alg {
34 void (*cia_decrypt) (struct crypto_tfm * tfm, unsigned char *dst,
35 const unsigned char *src);
36 };
37 struct crypto_alg {
38 struct list_head cra_list;
39 union {
40 struct cipher_alg cipher;
41 } cra_u;
42 };
43 static __attribute__ ((always_inline)) __attribute__ ((pure))
44 int use_xsave(void)
45 {
46 return (__builtin_constant_p
47 ((__builtin_constant_p(154)
48 &&
49 ((4 == 0
50 && (1UL << (26) &
51 ((1 << 0) | (1 << 6) |
52 (1 << 8) | (1 << 15))))
53 || ((4) == 1 && (1UL << (26) & 0)) || ((4) == 2
54 && (1UL <<
55 (26) & 0)) || ((4) == 3 && (1UL << (26) & 0)) || ((4) == 4 && (1UL << (26) & 0)) || ((4) == 5 && (1UL << (26) & 0)) || ((4) == 6 && (1UL << (26) & 0)) || ((4) == 7 && (1UL << (26) & 0)) || ((4) == 8 && (1UL << (26) & 0)) || ((4) == 9 && (1UL << (26) & 0))) ? 1 : (__builtin_constant_p(154) ? constant_test_bit(154, ((unsigned long *)((&boot_cpu_data)->x86_capability))) : variable_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability)))))) ? (__builtin_constant_p((154)) && (((4) == 0 && (1UL << (26) & ((1 << (0 & 31)) | (1 << ((6) & 31)) | (1 << ((0 * 32 + 8) & 31)) | (1 << ((15) & 31)) | 0))) || ((4) == 1 && (1UL << (26) & 0)) || ((4) == 2 && (1UL << (26) & 0)) || ((4) == 3 && (1UL << (26) & 0)) || ((4) == 4 && (1UL << (26) & 0)) || ((4) == 5 && (1UL << (26) & 0)) || ((4) == 6 && (1UL << (26) & 0)) || ((4) == 7 && (1UL << (26) & 0)) || ((4) == 8 && (1UL << (26) & 0)) || ((4) == 9 && (1UL << (26) & 0))) ? 1 : (__builtin_constant_p(((154))) ? constant_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))) : variable_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))))) : __builtin_constant_p((154)) ? __static_cpu_has((154)) : (__builtin_constant_p((154)) && (((4) == 0 && (1UL << (26) & ((1 << (0 & 31)) | (1 << ((6) & 31)) | (1 << ((8) & 31)) | (1 << ((15) & 31)) | 0))) || ((4) == 1 && (1UL << (26) & 0)) || ((4) == 2 && (1UL << (26) & 0)) || ((4) == 3 && (1UL << (26) & 0)) || ((4) == 4 && (1UL << (26) & 0)) || ((4) == 5 && (1UL << (26) & 0)) || ((4) == 6 && (1UL << (26) & 0)) || ((4) == 7 && (1UL << (26) & 0)) || ((4) == 8 && (1UL << (26) & 0)) || ((4) == 9 && (1UL << (26) & 0))) ? 1 : (__builtin_constant_p(((154))) ? constant_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))) : variable_test_bit(((154)), ((unsigned long *)((&boot_cpu_data)->x86_capability))))));
56 }
57
58 static inline __attribute__ ((always_inline)) __attribute__ ((always_inline))
59 __attribute__ ((pure))
60 int use_fxsr(void)
61 {
62 return (__builtin_constant_p
63 ((__builtin_constant_p((24))
64 &&
65 (((((24)) >> 5) == 0
66 && (1UL << (24) &
67 ((1 << 0) | (1 << 6) |
68 (1 << 8) | (1 << 15) )))
69 || ((((24)) >> 5) == 1 && (1UL << (24) & 0))
70 || ((((24)) >> 5) == 2 && (1UL << (24) & 0))
71 || ((((24)) >> 5) == 3 && (1UL << (24) & 0))
72 || ((((24)) >> 5) == 4 && (1UL << (24) & 0))
73 || ((((24)) >> 5) == 5 && (1UL << (24) & 0))
74 || ((((24)) >> 5) == 6 && (1UL << (24) & 0))
75 || ((((24)) >> 5) == 7 && (1UL << (24) & 0))
76 || ((((24)) >> 5) == 8 && (1UL << (24) & 0))
77 || ((((24)) >> 5) == 9
78 && (1UL << (24) & 0))) ? 1
79 : (__builtin_constant_p(((24))) ?
80 constant_test_bit(((24)),
81 ((unsigned long *)((&boot_cpu_data)->
82 x86_capability))) :
83 variable_test_bit(((24)),
84 ((unsigned long *)((&boot_cpu_data)->
85 x86_capability))))))
86 ? (__builtin_constant_p((24))
87 &&
88 (((((24)) >> 5) == 0
89 && (1UL << (24) &
90 ((1 << (0 & 31)) | (1 << ((6) & 31)) |
91 (1 << ((0 * 32 + 8) & 31)) | (1 << ((15) & 31)) |
92 0))) || ((((24)) >> 5) == 1 && (1UL << (24) & 0))
93 || ((((24)) >> 5) == 2 && (1UL << (24) & 0))
94 || ((((24)) >> 5) == 3 && (1UL << (24) & 0))
95 || ((((24)) >> 5) == 4 && (1UL << (24) & 0))
96 || ((((24)) >> 5) == 5 && (1UL << (24) & 0))
97 || ((((24)) >> 5) == 6 && (1UL << (24) & 0))
98 || ((((24)) >> 5) == 7 && (1UL << (24) & 0))
99 || ((((24)) >> 5) == 8 && (1UL << (24) & 0))
100 || ((((24)) >> 5) == 9
101 && (1UL << (24) & 0))) ? 1
102 : (__builtin_constant_p(((24))) ?
103 constant_test_bit(((24)),
104 ((unsigned long *)((&boot_cpu_data)->
105 x86_capability))) :
106 variable_test_bit(((24)),
107 ((unsigned long *)((&boot_cpu_data)->
108 x86_capability))))) :
109 __builtin_constant_p((24)) ? __static_cpu_has((24))
110 : (__builtin_constant_p((24))
111 &&
112 (((((24)) >> 5) == 0
113 && (1UL << (24) &
114 ((1 << (0 & 31)) | (1 << ((6) & 31)) |
115 (1 << ((8) & 31)) | (1 << ((15) & 31)) | 0)))
116 || ((((24)) >> 5) == 1 && (1UL << (24) & 0))
117 || ((((24)) >> 5) == 2 && (1UL << (24) & 0))
118 || ((((24)) >> 5) == 3 && (1UL << (24) & 0))
119 || ((((24)) >> 5) == 4 && (1UL << (24) & 0))
120 || ((((24)) >> 5) == 5 && (1UL << (24) & 0))
121 || ((((24)) >> 5) == 6 && (1UL << (24) & 0))
122 || ((((24)) >> 5) == 7 && (1UL << (24) & 0))
123 || ((((24)) >> 5) == 8 && (1UL << (24) & 0))
124 || ((((24)) >> 5) == 9
125 && (1UL << (24) & 0))) ? 1
126 : (__builtin_constant_p(((24))) ?
127 constant_test_bit(((24)),
128 ((unsigned long *)((&boot_cpu_data)->
129 x86_capability))) :
130 variable_test_bit(((24)),
131 ((unsigned long *)((&boot_cpu_data)->
132 x86_capability))))));
133 }
134
135 static inline __attribute__ ((always_inline))
136 void fpu_save_init(struct fpu *fpu)
137 {
138 if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) {
139 if (__builtin_constant_p
140 (((!(fpu->state->xsave.xsave_hdr.
141 xstate_bv & 0x1)))) ? ! !((!(fpu->state->xsave.
142 xsave_hdr.
143 xstate_bv & 0x1))) : ( {
144 ! !((!(fpu->state->xsave.xsave_hdr.xstate_bv & 0x1)));}
145 ))
146 return;
147 } else if (use_fxsr()) {
148 }
149 if (__builtin_constant_p
150 ((((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
151 ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
152 __builtin_expect(! !
153 (fpu->
154 state->
155 fxsave.
156 swd
157 & (1
158 <<
159 7)),
160 1);}
161 )))))?
162 ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
163 ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
164 __builtin_expect(! !
165 (fpu->
166 state->
167 fxsave.
168 swd
169 &
170 (1
171 <<
172 7)),
173 1);}
174 )))): ( {
175 int ______r;
176 ______r =
177 ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7))
178 ? ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
179 ______r =
180 __builtin_expect
181 (! !
182 (fpu->
183 state->
184 fxsave.
185 swd & (1
186 <<
187 7)),
188 1);}
189 ))));}
190 ))
191 asm volatile ("fnclex");
192 }
193
194 static __attribute__ ((always_inline))
195 void __save_init_fpu(void)
196 {
197 fpu_save_init(0);
198 }
199
200 static __attribute__ ((always_inline))
201 void kernel_fpu_begin(void)
202 {
203 __save_init_fpu();
204 }
205
206 static void aes_decrypt(void)
207 {
208 if (!irq_fpu_usable())
209 crypto_aes_decrypt_x86(0);
210 else
211 kernel_fpu_begin();
212 }
213
214 static struct crypto_alg aesni_alg = {
215 .cra_list = {
216 &aesni_alg.cra_list, &aesni_alg.cra_list}
217 ,.cra_u = {
218 .cipher = {
219 .cia_decrypt = aes_decrypt}
220 }
221 };
222
223 static struct crypto_alg ablk_ecb_alg = {
224 };
225
226 int aesni_init(void)
227 {
228 if (! !crypto_register_alg(&aesni_alg))
229 crypto_unregister_alg(&ablk_ecb_alg);
230 }