From a029c75470284d76badcea91aee3d87f22042304 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 3 May 2011 19:02:52 +0200 Subject: [PATCH] Does not clobber ebx to allow compilation in PIC mode. --- cpu.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cpu.h b/cpu.h index d4426948..0609418a 100644 --- a/cpu.h +++ b/cpu.h @@ -31,9 +31,19 @@ static inline int cpu_has(uint32_t flag) uint32_t eax = (flag >> 5) ? 0x80000001 : 1; uint32_t edx; - asm volatile("cpuid" + asm volatile( +#if defined(__i386__) + /* allow compilation in PIC mode saving ebx */ + "push %%ebx\n" + "cpuid\n" + "pop %%ebx\n" + : "+a" (eax), "=d" (edx) + : : "ecx"); +#else + "cpuid\n" : "+a" (eax), "=d" (edx) : : "ecx", "ebx"); +#endif return (edx >> (flag & 31)) & 1; }