summaryrefslogtreecommitdiffstats
path: root/src/cpuid.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-03-16 16:27:55 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-03-16 16:28:23 +0100
commitbf811828eb0da362cbf3992a5228c5cafaf5ed8f (patch)
tree57581ca792d051922d331eaeb30030867bacc7fe /src/cpuid.h
parent82fe2bc0411386b5054269476b940e4f005a60c0 (diff)
downloadfastd-bf811828eb0da362cbf3992a5228c5cafaf5ed8f.tar
fastd-bf811828eb0da362cbf3992a5228c5cafaf5ed8f.zip
Make cpuid asm more robust
Diffstat (limited to 'src/cpuid.h')
-rw-r--r--src/cpuid.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cpuid.h b/src/cpuid.h
index 989f2ca..78f87e5 100644
--- a/src/cpuid.h
+++ b/src/cpuid.h
@@ -48,9 +48,20 @@
/** Returns the ECX and EDX return values of CPUID function 1 as a single uint64 */
static inline uint64_t fastd_cpuid(void) {
- unsigned eax, ebx, ecx, edx;
+ uint32_t ecx, edx;
- __asm__ __volatile__ ("mov %%ebx, %%edi;" "cpuid;" "xchgl %%ebx, %%edi;" : "=a" (eax), "=D" (ebx), "=c" (ecx), "=d" (edx) : "a" (1));
+#if defined (__i386__)
+#define REG_PFX "e"
+#elif defined (__amd64__)
+#define REG_PFX "r"
+#endif
+
+ __asm__ __volatile__ ("mov %%"REG_PFX"bx, %%"REG_PFX"di \n\t"
+ "cpuid \n\t"
+ "mov %%"REG_PFX"di, %%"REG_PFX"bx \n\t"
+ : "=c" (ecx), "=d" (edx) : "a" (1) : REG_PFX"ax", REG_PFX"di");
return ((uint64_t)ecx) << 32 | edx;
}
+
+#undef REG_PFX