shithub: dumb

Download patch

ref: 6cb73ee3430f7ba10376286a06f28eeb2ed598a2
parent: 651e5235b72883f8480bb8138fad01bb168c16f4
author: Chris Moeller <kode54@gmail.com>
date: Fri Apr 4 17:45:39 EDT 2014

Attempt to fix issue #5 with compiling cpuid inline assembly on any platform using PIC

--- a/dumb/src/helpers/resampler.c
+++ b/dumb/src/helpers/resampler.c
@@ -49,12 +49,28 @@
 static inline void
 __cpuid(int *data, int selector)
 {
+#if defined(__PIC__) && defined(__i386__)
+    asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
+        : "=a" (data[0]),
+        "=S" (data[1]),
+        "=c" (data[2]),
+        "=d" (data[3])
+        : "0" (selector));
+#elif defined(__PIC__) && defined(__amd64__)
+    asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
+        : "=a" (data[0]),
+        "=&r" (data[1]),
+        "=c" (data[2]),
+        "=d" (data[3])
+        : "0" (selector));
+#else
     asm("cpuid"
         : "=a" (data[0]),
         "=b" (data[1]),
         "=c" (data[2]),
         "=d" (data[3])
-        : "a"(selector));
+        : "0" (selector));
+#endif
 }
 #else
 #define __cpuid(a,b) memset((a), 0, sizeof(int) * 4)
--- a/dumb/src/it/itrender.c
+++ b/dumb/src/it/itrender.c
@@ -751,12 +751,28 @@
 static inline void
 __cpuid(int *data, int selector)
 {
+#if defined(__PIC__) && defined(__i386__)
+    asm("xchgl %%ebx, %%esi; cpuid; xchgl %%ebx, %%esi"
+        : "=a" (data[0]),
+        "=S" (data[1]),
+        "=c" (data[2]),
+        "=d" (data[3])
+        : "0" (selector));
+#elif defined(__PIC__) && defined(__amd64__)
+    asm("xchg{q} {%%}rbx, %q1; cpuid; xchg{q} {%%}rbx, %q1"
+        : "=a" (data[0]),
+        "=&r" (data[1]),
+        "=c" (data[2]),
+        "=d" (data[3])
+        : "0" (selector));
+#else
     asm("cpuid"
         : "=a" (data[0]),
         "=b" (data[1]),
         "=c" (data[2]),
         "=d" (data[3])
-        : "a"(selector));
+        : "0" (selector));
+#endif
 }
 #else
 #define __cpuid(a,b) memset((a), 0, sizeof(int) * 4)