]> git.wh0rd.org - ICEs.git/blobdiff - 388835/aesni-intel_glue.i
more
[ICEs.git] / 388835 / aesni-intel_glue.i
diff --git a/388835/aesni-intel_glue.i b/388835/aesni-intel_glue.i
new file mode 100644 (file)
index 0000000..e5099bd
--- /dev/null
@@ -0,0 +1,32 @@
+__attribute__ ((always_inline)) __attribute__ ((pure))
+int 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;
+}
+
+union thread_xstate {
+       int swd;
+       int xstate_bv;
+};
+
+void aes_decrypt(union thread_xstate *state)
+{
+       if (fpu_usable()) {
+               decrypt();
+               return;
+       }
+
+       if (__builtin_constant_p(cpu_has(154)) ? cpu_has(154) : cpu_has(154)) {
+               if (state->xstate_bv)
+                       return;
+       } else if (cpu_has(24)) {}
+
+       if (state->swd)
+               asm volatile ("fnclex");
+}
+
+void (*funcptr)(void) = aes_decrypt;