summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-09-17 11:44:08 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-09-17 11:44:58 +0200
commit327aacdf029c56bc5e488367c63fe5903dc7e0c6 (patch)
tree27eead86dc74552081371b3053dc9b14d59dd6b2
parentd620e7020092ba1be4e2f170a7f84cc25cd0d2a1 (diff)
downloadgnutls-327aacdf029c56bc5e488367c63fe5903dc7e0c6.tar.gz
eliminated inline assembly.
-rw-r--r--lib/accelerated/accelerated.c2
-rw-r--r--lib/accelerated/intel/Makefile.am4
-rw-r--r--lib/accelerated/intel/aes-padlock.c2
-rw-r--r--lib/accelerated/intel/aes-x86.c6
-rw-r--r--lib/accelerated/intel/asm/cpuid-x86-64.s39
-rw-r--r--lib/accelerated/intel/asm/cpuid-x86.s54
-rw-r--r--lib/accelerated/x86.h56
7 files changed, 108 insertions, 55 deletions
diff --git a/lib/accelerated/accelerated.c b/lib/accelerated/accelerated.c
index e2da12f6c3..8a89e3dc96 100644
--- a/lib/accelerated/accelerated.c
+++ b/lib/accelerated/accelerated.c
@@ -30,7 +30,7 @@ void _gnutls_register_accel_crypto(void)
{
#if defined(ASM_X86_32) || defined(ASM_X86_64)
- if (have_cpuid() != 0)
+ if (_gnutls_have_cpuid() != 0)
{
register_x86_crypto ();
register_padlock_crypto ();
diff --git a/lib/accelerated/intel/Makefile.am b/lib/accelerated/intel/Makefile.am
index a0ea3338d3..996c0d5862 100644
--- a/lib/accelerated/intel/Makefile.am
+++ b/lib/accelerated/intel/Makefile.am
@@ -38,8 +38,8 @@ libintel_la_SOURCES = aes-x86.c aes-padlock.c aes-gcm-padlock.c
if ASM_X86_64
AM_CPPFLAGS += -DASM_X86_64
-libintel_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s aes-gcm-x86.c asm/padlock-x86-64.s
+libintel_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s aes-gcm-x86.c asm/padlock-x86-64.s asm/cpuid-x86-64.s
else
-libintel_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s
+libintel_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s asm/cpuid-x86.s
endif
diff --git a/lib/accelerated/intel/aes-padlock.c b/lib/accelerated/intel/aes-padlock.c
index e0e79c1656..59f33bc55e 100644
--- a/lib/accelerated/intel/aes-padlock.c
+++ b/lib/accelerated/intel/aes-padlock.c
@@ -170,7 +170,7 @@ static int check_padlock(void)
static unsigned check_via(void)
{
unsigned int a, b, c, d;
- cpuid(0, a, b, c, d);
+ _gnutls_cpuid(0, &a, &b, &c, &d);
if ((memcmp(&b, "VIA ", 4) == 0 &&
memcmp(&d, "VIA ", 4) == 0 && memcmp(&c, "VIA ", 4) == 0)) {
diff --git a/lib/accelerated/intel/aes-x86.c b/lib/accelerated/intel/aes-x86.c
index 9f4c4cbed7..5f465a5290 100644
--- a/lib/accelerated/intel/aes-x86.c
+++ b/lib/accelerated/intel/aes-x86.c
@@ -126,7 +126,7 @@ static unsigned
check_optimized_aes (void)
{
unsigned int a, b, c, d;
- cpuid (1, a, b, c, d);
+ _gnutls_cpuid (1, &a, &b, &c, &d);
return (c & 0x2000000);
}
@@ -136,7 +136,7 @@ static unsigned
check_pclmul (void)
{
unsigned int a, b, c, d;
- cpuid (1, a, b, c, d);
+ _gnutls_cpuid (1, &a, &b, &c, &d);
return (c & 0x2);
}
@@ -146,7 +146,7 @@ static unsigned
check_intel_or_amd (void)
{
unsigned int a, b, c, d;
- cpuid (0, a, b, c, d);
+ _gnutls_cpuid (0, &a, &b, &c, &d);
if ((memcmp (&b, "Genu", 4) == 0 &&
memcmp (&d, "ineI", 4) == 0 &&
diff --git a/lib/accelerated/intel/asm/cpuid-x86-64.s b/lib/accelerated/intel/asm/cpuid-x86-64.s
new file mode 100644
index 0000000000..48b2cc4b66
--- /dev/null
+++ b/lib/accelerated/intel/asm/cpuid-x86-64.s
@@ -0,0 +1,39 @@
+ .file "cpuid.asm"
+
+ .text
+ .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+ pushq %rbp
+ movq %rsp, %rbp
+ pushq %rbx
+ movl %edi, -12(%rbp)
+ movq %rsi, -24(%rbp)
+ movq %rdx, -32(%rbp)
+ movq %rcx, -40(%rbp)
+ movq %r8, -48(%rbp)
+ movl -12(%rbp), %eax
+ movl %eax, -60(%rbp)
+ movl -60(%rbp), %eax
+ cpuid
+ movl %edx, -56(%rbp)
+ movl %ecx, %esi
+ movl %eax, -52(%rbp)
+ movq -24(%rbp), %rax
+ movl -52(%rbp), %edx
+ movl %edx, (%rax)
+ movq -32(%rbp), %rax
+ movl %ebx, (%rax)
+ movq -40(%rbp), %rax
+ movl %esi, (%rax)
+ movq -48(%rbp), %rax
+ movl -56(%rbp), %ecx
+ movl %ecx, (%rax)
+ popq %rbx
+ leave
+ ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+
+.section .note.GNU-stack,"",@progbits
diff --git a/lib/accelerated/intel/asm/cpuid-x86.s b/lib/accelerated/intel/asm/cpuid-x86.s
new file mode 100644
index 0000000000..b286225048
--- /dev/null
+++ b/lib/accelerated/intel/asm/cpuid-x86.s
@@ -0,0 +1,54 @@
+ .file "cpuid.asm"
+
+ .text
+ .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+ pushl %ebp
+ movl %esp, %ebp
+ subl $12, %esp
+ movl %ebx, (%esp)
+ movl 8(%ebp), %eax
+ movl %esi, 4(%esp)
+ movl %edi, 8(%esp)
+ pushl %ebx
+ cpuid
+ movl %ebx, %edi
+ popl %ebx
+ movl %edx, %esi
+ movl 12(%ebp), %edx
+ movl %eax, (%edx)
+ movl 16(%ebp), %eax
+ movl %edi, (%eax)
+ movl 20(%ebp), %eax
+ movl %ecx, (%eax)
+ movl 24(%ebp), %eax
+ movl %esi, (%eax)
+ movl (%esp), %ebx
+ movl 4(%esp), %esi
+ movl 8(%esp), %edi
+ movl %ebp, %esp
+ popl %ebp
+ ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+ .globl _gnutls_have_cpuid
+ .type _gnutls_have_cpuid, @function
+_gnutls_have_cpuid:
+.LFB0:
+ .cfi_startproc
+ pushfl
+ pop %eax
+ orl $0x200000, %eax
+ push %eax
+ popfl
+ pushfl
+ pop %eax
+ andl $0x200000, %eax
+ ret
+ .cfi_endproc
+.LFE0:
+ .size _gnutls_have_cpuid, .-_gnutls_have_cpuid
+
+.section .note.GNU-stack,"",@progbits
diff --git a/lib/accelerated/x86.h b/lib/accelerated/x86.h
index 0b61272cda..4a5d5c7701 100644
--- a/lib/accelerated/x86.h
+++ b/lib/accelerated/x86.h
@@ -22,55 +22,15 @@
#include <config.h>
-#ifdef ASM_X86_64
+#if defined(ASM_X86_32) || defined(ASM_X86_64)
-# ifdef HAVE_CPUID_H
-# include <cpuid.h>
-# define cpuid __cpuid
-# else
-
-#define cpuid(func,ax,bx,cx,dx)\
- __asm__ __volatile__ ("cpuid":\
- "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
-
-# endif
-
-# define have_cpuid() 1
+void _gnutls_cpuid(unsigned int func, unsigned int *ax, unsigned int *bx, unsigned int *cx, unsigned int* dx);
-#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)
+# ifdef ASM_X86_32
+unsigned int _gnutls_have_cpuid(void);
+# else
+# define _gnutls_have_cpuid() 1
+# endif /* ASM_X86_32 */
-inline static void g_cpuid(uint32_t func, unsigned int *ax, unsigned int *bx, unsigned int *cx, unsigned int* dx)
-{
- asm volatile ("pushl %%ebx\n"
- "cpuid\n"
- "movl %%ebx, %1\n"
- "popl %%ebx\n"
- :"=a" (*ax), "=r"(*bx), "=c"(*cx), "=d"(*dx)
- :"a"(func)
- :"cc");
-}
+#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 */