From a234e505f9e4dc9b7aa3615b8fe0b1d1b3c268fd Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 7 May 2014 09:01:01 -0700 Subject: [PATCH] Saving %rbx may actually be required depending on the memory model. --- src/libsodium/sodium/runtime.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libsodium/sodium/runtime.c b/src/libsodium/sodium/runtime.c index d9baa541..a375c654 100644 --- a/src/libsodium/sodium/runtime.c +++ b/src/libsodium/sodium/runtime.c @@ -47,7 +47,7 @@ _cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type) __cpuidex((int *) cpu_info, cpu_info_type, 0); #elif defined(HAVE_CPUID) cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; -# if defined(__i386__) && !defined(__x86_64__) +# ifdef __i386__ __asm__ __volatile__ ("pushfl; pushfl; " "popl %0; " "movl %0, %1; xorl %2, %0; " @@ -59,10 +59,22 @@ _cpuid(unsigned int cpu_info[4U], const unsigned int cpu_info_type) return; } # endif +# ifdef __i386__ __asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" : "=a" (cpu_info[0]), "=&r" (cpu_info[1]), "=c" (cpu_info[2]), "=d" (cpu_info[3]) : "0" (cpu_info_type), "2" (0U)); +# elif defined(__x86_64__) + __asm__ __volatile__ ("xchgq %%rbx, %q1; cpuid; xchgq %%rbx, %q1" : + "=a" (cpu_info[0]), "=&r" (cpu_info[1]), + "=c" (cpu_info[2]), "=d" (cpu_info[3]) : + "0" (cpu_info_type), "2" (0U)); +# else + __asm__ __volatile__ ("cpuid" : + "=a" (cpu_info[0]), "=b" (cpu_info[1]), + "=c" (cpu_info[2]), "=d" (cpu_info[3]) : + "0" (cpu_info_type), "2" (0U)); +# endif #else cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; #endif