]> git.wh0rd.org - ICEs.git/blobdiff - 388835/aesni-intel_glue.i.9
more
[ICEs.git] / 388835 / aesni-intel_glue.i.9
diff --git a/388835/aesni-intel_glue.i.9 b/388835/aesni-intel_glue.i.9
new file mode 100644 (file)
index 0000000..0f7f07c
--- /dev/null
@@ -0,0 +1,155 @@
+struct list_head {
+};
+int __static_cpu_has(unsigned short bit)
+{
+       asm goto ("1: jmp %l[t_no]\n" "2:\n" ".section .altinstructions,\"a\"\n"
+                 " " ".balign 4" " " "\n" " " ".long" " " "1b\n" " " ".long"
+                 " " "0\n" " .word %P0\n" " .byte 2b - 1b\n" " .byte 0\n"
+                 ".previous\n"::"i" (bit)::t_no);
+       return 1;
+      t_no:return 0;
+}
+
+struct cpuinfo_x86 {
+       unsigned int x86_capability[10];
+} __attribute__ ((__aligned__((1 << (6)))));
+extern struct cpuinfo_x86 boot_cpu_data;
+struct i387_fxsave_struct {
+       unsigned short swd;
+} __attribute__ ((aligned(16)));
+struct xsave_hdr_struct {
+       unsigned long long xstate_bv;
+} __attribute__ ((packed));
+struct xsave_struct {
+       struct xsave_hdr_struct xsave_hdr;
+} __attribute__ ((packed, aligned(64)));
+union thread_xstate {
+       struct i387_fxsave_struct fxsave;
+       struct xsave_struct xsave;
+};
+struct fpu {
+       union thread_xstate *state;
+};
+struct crypto_alg {
+       struct list_head cra_list;
+       void (*cia_decrypt) (void);
+};
+static __attribute__ ((always_inline)) __attribute__ ((pure))
+int use_xsave(void)
+{
+       return
+           __builtin_constant_p(constant_test_bit
+                                (boot_cpu_data.x86_capability)) ?
+           constant_test_bit(
+boot_cpu_data.x86_capability
+) :
+           __static_cpu_has(154);
+}
+
+static inline __attribute__ ((always_inline)) __attribute__ ((always_inline))
+    __attribute__ ((pure))
+int use_fxsr(void)
+{
+       return
+           __builtin_constant_p(variable_test_bit
+                                (24,
+                                 (unsigned long *)((&boot_cpu_data)->
+                                                   x86_capability))) ?
+           variable_test_bit(24,
+                             (unsigned long *)((&boot_cpu_data)->
+                                               x86_capability)) :
+           __static_cpu_has(24);
+}
+
+static inline __attribute__ ((always_inline))
+void fpu_save_init(struct fpu *fpu)
+{
+       if (__builtin_constant_p(use_xsave())? use_xsave() : use_xsave()) {
+               if (__builtin_constant_p
+                   (((!(fpu->state->xsave.xsave_hdr.
+                        xstate_bv & 0x1)))) ? ! !((!(fpu->state->xsave.
+                                                     xsave_hdr.
+                                                     xstate_bv & 0x1))) : ( {
+                                                                           ! !((!(fpu->state->xsave.xsave_hdr.xstate_bv & 0x1)));}
+                   ))
+                       return;
+       } else if (use_fxsr()) {
+       }
+       if (__builtin_constant_p
+           ((((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
+               ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
+                                                         __builtin_expect(! !
+                                                                          (fpu->
+                                                                           state->
+                                                                           fxsave.
+                                                                           swd
+                                                                           & (1
+                                                                              <<
+                                                                              7)),
+                                                                          1);}
+               )))))?
+           ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7)) ?
+                 ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
+                                                           __builtin_expect(! !
+                                                                            (fpu->
+                                                                             state->
+                                                                             fxsave.
+                                                                             swd
+                                                                             &
+                                                                             (1
+                                                                              <<
+                                                                              7)),
+                                                                            1);}
+      )))):      ( {
+                  int ______r;
+                  ______r =
+                  ! !(((__builtin_constant_p(fpu->state->fxsave.swd & (1 << 7))
+                        ? ! !(fpu->state->fxsave.swd & (1 << 7)) : ( {
+                                                                    ______r =
+                                                                    __builtin_expect
+                                                                    (! !
+                                                                     (fpu->
+                                                                      state->
+                                                                      fxsave.
+                                                                      swd & (1
+                                                                             <<
+                                                                             7)),
+                                                                     1);}
+                        ))));}
+           ))
+               asm volatile ("fnclex");
+}
+
+static __attribute__ ((always_inline))
+void __save_init_fpu(void)
+{
+       fpu_save_init(0);
+}
+
+static __attribute__ ((always_inline))
+void kernel_fpu_begin(void)
+{
+       __save_init_fpu();
+}
+
+static void aes_decrypt(void)
+{
+       if (!irq_fpu_usable())
+               crypto_aes_decrypt_x86(0);
+       else
+               kernel_fpu_begin();
+}
+
+static struct crypto_alg aesni_alg = {
+       .cra_list = { &aesni_alg.cra_list },
+       .cia_decrypt = aes_decrypt
+};
+
+static struct crypto_alg ablk_ecb_alg = {
+};
+
+int aesni_init(void)
+{
+       if (! !crypto_register_alg(&aesni_alg))
+               crypto_unregister_alg(&ablk_ecb_alg);
+}