From: Nikos Mavrogiannopoulos Date: Fri, 16 Sep 2011 20:46:13 +0000 (+0200) Subject: Added better detection of capabilities in 386. If cpuid doesn't exist don't try to... X-Git-Tag: gnutls_3_0_3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8c99c59b4a09f8ade727bfb3276807d72961108;p=thirdparty%2Fgnutls.git Added better detection of capabilities in 386. If cpuid doesn't exist don't try to execute it. --- diff --git a/configure.ac b/configure.ac index 85916ef627..a3ccb2cc91 100644 --- a/configure.ac +++ b/configure.ac @@ -94,8 +94,8 @@ esac fi -AM_CONDITIONAL(TRY_X86_OPTIMIZATIONS, test x"$hw_accel" = x"x86" || test x"$hw_accel" = x"x86-64") AM_CONDITIONAL(ASM_X86_64, test x"$hw_accel" = x"x86-64") +AM_CONDITIONAL(ASM_X86_32, test x"$hw_accel" = x"x86") AM_CONDITIONAL(HAVE_GCC_GNU89_INLINE_OPTION, test "$gnu89_inline" = "yes"]) AM_CONDITIONAL(HAVE_GCC, test "$GCC" = "yes") diff --git a/lib/accelerated/Makefile.am b/lib/accelerated/Makefile.am index 4a23dde76f..e9426d0be6 100644 --- a/lib/accelerated/Makefile.am +++ b/lib/accelerated/Makefile.am @@ -36,8 +36,14 @@ EXTRA_DIST = x86.h accelerated.h cryptodev.h libaccelerated_la_SOURCES = accelerated.c cryptodev.c libaccelerated_la_LIBADD = -if TRY_X86_OPTIMIZATIONS +if ASM_X86_64 SUBDIRS += intel -AM_CFLAGS += -DTRY_X86_OPTIMIZATIONS +AM_CFLAGS += -DASM_X86_64 +libaccelerated_la_LIBADD += intel/libintel.la +endif + +if ASM_X86_32 +SUBDIRS += intel +AM_CFLAGS += -DASM_X86_32 libaccelerated_la_LIBADD += intel/libintel.la endif diff --git a/lib/accelerated/accelerated.c b/lib/accelerated/accelerated.c index ddfdf0c54a..e2da12f6c3 100644 --- a/lib/accelerated/accelerated.c +++ b/lib/accelerated/accelerated.c @@ -21,16 +21,20 @@ */ #include -#ifdef TRY_X86_OPTIMIZATIONS +#if defined(ASM_X86_32) || defined(ASM_X86_64) # include +# include #endif void _gnutls_register_accel_crypto(void) { -#ifdef TRY_X86_OPTIMIZATIONS - register_x86_crypto (); - register_padlock_crypto (); +#if defined(ASM_X86_32) || defined(ASM_X86_64) + if (have_cpuid() != 0) + { + register_x86_crypto (); + register_padlock_crypto (); + } #endif return; diff --git a/lib/accelerated/x86.h b/lib/accelerated/x86.h index 2fdb9d6c79..0b61272cda 100644 --- a/lib/accelerated/x86.h +++ b/lib/accelerated/x86.h @@ -22,19 +22,25 @@ #include -#ifdef HAVE_CPUID_H -# include -# define cpuid __cpuid +#ifdef ASM_X86_64 -#else - -# ifdef ASM_X86_64 +# ifdef HAVE_CPUID_H +# include +# define cpuid __cpuid +# else -# define cpuid(func,ax,bx,cx,dx)\ +#define cpuid(func,ax,bx,cx,dx)\ __asm__ __volatile__ ("cpuid":\ "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func)); -# else +# endif + +# define have_cpuid() 1 + +#endif /* ASM_X86_64 */ + + +#ifdef ASM_X86_32 /* some GCC versions complain on the version above */ # define cpuid(func, a, b, c, d) g_cpuid(func, &a, &b, &c, &d) @@ -48,6 +54,23 @@ inline static void g_cpuid(uint32_t func, unsigned int *ax, unsigned int *bx, un :"a"(func) :"cc"); } -# endif -#endif +inline static unsigned int have_cpuid(void) +{ + unsigned int have_id; + asm volatile( + "pushfl\t\n" + "pop %0\t\n" + "orl $0x200000, %0\t\n" + "push %0\t\n" + "popfl\t\n" + "pushfl\t\n" + "pop %0\t\n" + "andl $0x200000, %0\t\n" + :"=r" (have_id) + :: + ); + + return have_id; +} +#endif /* ASM_X86_32 */