e_padlock.c: make it compile on MacOS X.
[openssl.git] / engines / e_padlock.c
index b89113e3bd1e50d8bdc64b69ecd4f5595f49b250..7c64cf38c53c7d056a1d1f0a0702fac6d89c0344 100644 (file)
      ) || \
      (defined(_MSC_VER) && defined(_M_IX86))
 #  define COMPILE_HW_PADLOCK
+#  ifdef OPENSSL_NO_DYNAMIC_ENGINE
 static ENGINE *ENGINE_padlock (void);
+#  endif
 # endif
 #endif
 
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
+
 void ENGINE_load_padlock (void)
 {
 /* On non-x86 CPUs it just returns. */
@@ -123,19 +127,21 @@ void ENGINE_load_padlock (void)
 #endif
 }
 
+#endif
+
 #ifdef COMPILE_HW_PADLOCK
 /* We do these includes here to avoid header problems on platforms that
    do not have the VIA padlock anyway... */
+#include <stdlib.h>
 #ifdef _WIN32
 # include <malloc.h>
 # ifndef alloca
 #  define alloca _alloca
 # endif
-#elif defined(NETWARE_CLIB) && defined(__GNUC__)
-  void *alloca(size_t);
-# define alloca(s) __builtin_alloca(s)
-#else
-# include <stdlib.h>
+#elif defined(__GNUC__)
+# ifndef alloca
+#  define alloca(s) __builtin_alloca((s))
+# endif
 #endif
 
 /* Function for ENGINE detection and control */
@@ -196,6 +202,7 @@ padlock_bind_helper(ENGINE *e)
        return 1;
 }
 
+#ifdef OPENSSL_NO_DYNAMIC_ENGINE
 /* Constructor */
 static ENGINE *
 ENGINE_padlock(void)
@@ -213,6 +220,7 @@ ENGINE_padlock(void)
 
        return eng;
 }
+#endif
 
 /* Check availability of the engine */
 static int
@@ -450,25 +458,27 @@ padlock_available(void)
        eax = 0x00000000;
        vendor_string[12] = 0;
        asm volatile (
+               "pushq  %%rbx\n"
                "cpuid\n"
                "movl   %%ebx,(%1)\n"
                "movl   %%edx,4(%1)\n"
                "movl   %%ecx,8(%1)\n"
-               : "+a"(eax) : "r"(vendor_string) : "rbx", "rcx", "rdx");
+               "popq   %%rbx"
+               : "+a"(eax) : "r"(vendor_string) : "rcx", "rdx");
        if (strcmp(vendor_string, "CentaurHauls") != 0)
                return 0;
 
        /* Check for Centaur Extended Feature Flags presence */
        eax = 0xC0000000;
-       asm volatile ("cpuid"
-               : "+a"(eax) : : "rbx", "rcx", "rdx");
+       asm volatile ("pushq %%rbx; cpuid; popq %%rbx"
+               : "+a"(eax) : : "rcx", "rdx");
        if (eax < 0xC0000001)
                return 0;
 
        /* Read the Centaur Extended Feature Flags */
        eax = 0xC0000001;
-       asm volatile ("cpuid"
-               : "+a"(eax), "=d"(edx) : : "rbx", "rcx");
+       asm volatile ("pushq %%rbx; cpuid; popq %%rbx"
+               : "+a"(eax), "=d"(edx) : : "rcx");
 
        /* Fill up some flags */
        padlock_use_ace = ((edx & (0x3<<6)) == (0x3<<6));
@@ -524,12 +534,14 @@ static inline void *name(size_t cnt,              \
        struct padlock_cipher_data *cdata,      \
        void *out, const void *inp)             \
 {      void *iv;                               \
-       asm volatile ( "leaq    16(%0),%%rdx\n" \
+       asm volatile ( "pushq   %%rbx\n"        \
+               "       leaq    16(%0),%%rdx\n" \
                "       leaq    32(%0),%%rbx\n" \
                        rep_xcrypt "\n"         \
+               "       popq    %%rbx"          \
                : "=a"(iv), "=c"(cnt), "=D"(out), "=S"(inp) \
                : "0"(cdata), "1"(cnt), "2"(out), "3"(inp)  \
-               : "rbx", "rdx", "cc", "memory");        \
+               : "rdx", "cc", "memory");       \
        return iv;                              \
 }
 #endif
@@ -1322,9 +1334,12 @@ static RAND_METHOD padlock_rand = {
 #else  /* !COMPILE_HW_PADLOCK */
 #ifndef OPENSSL_NO_DYNAMIC_ENGINE
 OPENSSL_EXPORT
+int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns);
+OPENSSL_EXPORT
 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; }
 IMPLEMENT_DYNAMIC_CHECK_FN()
 #endif
+#endif /* COMPILE_HW_PADLOCK */
 
 #endif /* !OPENSSL_NO_HW_PADLOCK */
 #endif /* !OPENSSL_NO_HW */