]> git.wh0rd.org - ICEs.git/blame - 388835/aesni-intel_glue.i.8
more
[ICEs.git] / 388835 / aesni-intel_glue.i.8
CommitLineData
bd3239d2
MF
1struct list_head {
2};
3int __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
13struct cpuinfo_x86 {
14 unsigned int x86_capability[10];
15} __attribute__ ((__aligned__((1 << (6)))));
16extern struct cpuinfo_x86 boot_cpu_data;
17struct i387_fxsave_struct {
18 unsigned short swd;
19} __attribute__ ((aligned(16)));
20struct xsave_hdr_struct {
21 unsigned long long xstate_bv;
22} __attribute__ ((packed));
23struct xsave_struct {
24 struct xsave_hdr_struct xsave_hdr;
25} __attribute__ ((packed, aligned(64)));
26union thread_xstate {
27 struct i387_fxsave_struct fxsave;
28 struct xsave_struct xsave;
29};
30struct fpu {
31 union thread_xstate *state;
32};
33struct cipher_alg {
34 void (*cia_decrypt) (struct crypto_tfm * tfm, unsigned char *dst,
35 const unsigned char *src);
36};
37struct crypto_alg {
38 struct list_head cra_list;
39 union {
40 struct cipher_alg cipher;
41 } cra_u;
42};
43static __attribute__ ((always_inline)) __attribute__ ((pure))
44int use_xsave(void)
45{
46 return __builtin_constant_p(constant_test_bit(154, (unsigned long *)((&boot_cpu_data)->x86_capability)))
47?
48 constant_test_bit(154, (unsigned long *)((&boot_cpu_data)->x86_capability)) :
49 __static_cpu_has(154)
50
51;
52}
53
54static inline __attribute__ ((always_inline)) __attribute__ ((always_inline))
55 __attribute__ ((pure))
56int use_fxsr(void)
57{
58 return __builtin_constant_p
59 (variable_test_bit(24, (unsigned long *)((&boot_cpu_data)->x86_capability)))
60 ?
61variable_test_bit(24, (unsigned long *)((&boot_cpu_data)->x86_capability)) :
62 __static_cpu_has(24)
63;
64}
65
66static inline __attribute__ ((always_inline))
67void fpu_save_init(struct fpu *fpu)
68{
69 if (
70__builtin_constant_p(use_xsave())? use_xsave() :
71use_xsave()
72) {
73 if (__builtin_constant_p
74 (((!(fpu->state->xsave.xsave_hdr.
75 xstate_bv & 0x1)))) ? ! !((!(fpu->state->xsave.
76 xsave_hdr.
77 xstate_bv & 0x1))) : ( {
78 ! !((!(fpu->state->xsave.xsave_hdr.xstate_bv & 0x1)));}
79 ))
80 return;
81 } else if (use_fxsr()) {
82 }
83 if (__builtin_constant_p
84 ((((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
85 ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
86 __builtin_expect(! !
87 (fpu->
88 state->
89 fxsave.
90 swd
91 & (1
92 <<
93 7)),
94 1);}
95 )))))?
96 ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
97 ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
98 __builtin_expect(! !
99 (fpu->
100 state->
101 fxsave.
102 swd
103 &
104 (1
105 <<
106 7)),
107 1);}
108 )))): ( {
109 int ______r;
110 ______r =
111 ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7))
112 ? ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
113 ______r =
114 __builtin_expect
115 (! !
116 (fpu->
117 state->
118 fxsave.
119 swd & (1
120 <<
121 7)),
122 1);}
123 ))));}
124 ))
125 asm volatile ("fnclex");
126}
127
128static __attribute__ ((always_inline))
129void __save_init_fpu(void)
130{
131 fpu_save_init(0);
132}
133
134static __attribute__ ((always_inline))
135void kernel_fpu_begin(void)
136{
137 __save_init_fpu();
138}
139
140static void aes_decrypt(void)
141{
142 if (!irq_fpu_usable())
143 crypto_aes_decrypt_x86(0);
144 else
145 kernel_fpu_begin();
146}
147
148static struct crypto_alg aesni_alg = {
149 .cra_list = {
150 &aesni_alg.cra_list, &aesni_alg.cra_list}
151 ,.cra_u = {
152 .cipher = {
153 .cia_decrypt = aes_decrypt}
154 }
155};
156
157static struct crypto_alg ablk_ecb_alg = {
158};
159
160int aesni_init(void)
161{
162 if (! !crypto_register_alg(&aesni_alg))
163 crypto_unregister_alg(&ablk_ecb_alg);
164}