summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-01-02 21:28:40 +0000
committerrubidium <rubidium@openttd.org>2014-01-02 21:28:40 +0000
commit456dba4889108027f8af9c94514978d06012b6e7 (patch)
tree1bd0d3dae6bb510e8cf350ececf6a6315737c111 /src
parentb1001258668ee3fd2cdb579ddbc9aa3bd5ac0c2c (diff)
downloadopenttd-456dba4889108027f8af9c94514978d06012b6e7.tar.xz
(svn r26208) -Fix (r26197): the cpuid assembly didn't work when PIC was enabled
Diffstat (limited to 'src')
-rw-r--r--src/cpu.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cpu.cpp b/src/cpu.cpp
index 45b7faab4..b1d1c328f 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -96,9 +96,21 @@ void ottd_cpuid(int info[4], int type)
#elif defined(__x86_64__) || defined(__i386)
void ottd_cpuid(int info[4], int type)
{
+ /* The easy variant would be just cpuid, however... ebx gets clobbered by PIC. */
__asm__ __volatile__ (
- "cpuid"
- : "=a" (info[0]), "=b" (info[1]), "=c" (info[2]), "=d" (info[3])
+#if defined(__x86_64__)
+ "pushq %%rbx \n\t" // save %rbx
+#else
+ "pushl %%ebx \n\t" // save %ebx
+#endif
+ "cpuid \n\t"
+ "movl %%ebx, %1 \n\t" // write the result into output var
+#if defined(__x86_64__)
+ "popq %%rbx \n\t" // restore %rbx
+#else
+ "popl %%ebx \n\t" // restore %ebc
+#endif
+ : "=a" (info[0]), "=r" (info[1]), "=c" (info[2]), "=d" (info[3])
: "a" (type)
);
}