chiark / gitweb /
Fix handling of cpuid and PIC on i386 systems
[stressapptest] / src / worker.cc
index dcf4dcb6e6370ab18cfab6eafec1c21c64e41e9b..eddea6c12bb38a1ea6a3663eb803d047be94ef02 100644 (file)
@@ -82,7 +82,17 @@ namespace {
   inline int apicid(void) {
     int cpu;
 #if defined(STRESSAPPTEST_CPU_X86_64) || defined(STRESSAPPTEST_CPU_I686)
-    __asm __volatile("cpuid" : "=b" (cpu) : "a" (1) : "cx", "dx");
+    __asm__ __volatile__ (
+# if defined(STRESSAPPTEST_CPU_I686) && defined(__PIC__)
+        "xchg %%ebx, %%esi;"
+        "cpuid;"
+        "xchg %%esi, %%ebx;"
+        : "=S" (cpu)
+# else
+        "cpuid;"
+        : "=b" (cpu)
+# endif
+        : "a" (1) : "cx", "dx");
 #elif defined(STRESSAPPTEST_CPU_ARMV7A)
   #warning "Unsupported CPU type ARMV7A: unable to determine core ID."
     cpu = 0;