From c146f067937fbd285ec378b1e7e0583f60a74bae Mon Sep 17 00:00:00 2001 From: pcpa Date: Sun, 23 Feb 2014 17:31:12 -0300 Subject: [PATCH] x86_64: Change x86_64 to also save/restore %rbx in inline asm. * lib/jit_x86.c: Rewrite previous patch to inline save/restore because clobbering %ebx in x86 is treated as an error (jit_x86.c:239:5: error: PIC register clobbered by 'ebx' in 'asm'). --- ChangeLog | 6 ++++++ lib/jit_x86.c | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index f3ab5a042..d5a24a98e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-23-02 Paulo Andrade + + * lib/jit_x86.c: Rewrite previous patch to inline save/restore + because clobbering %ebx in x86 is treated as an error + (jit_x86.c:239:5: error: PIC register clobbered by 'ebx' in 'asm'). + 2014-19-02 Paulo Andrade * lib/jit_x86.c: Rewrite incorrect inline assembly that could diff --git a/lib/jit_x86.c b/lib/jit_x86.c index 027e6db4c..5eaad68e9 100644 --- a/lib/jit_x86.c +++ b/lib/jit_x86.c @@ -170,7 +170,7 @@ jit_get_cpu(void) jit_uint32_t __reserved3 : 1; jit_uint32_t __alwayszero : 1; /* amd RAZ */ } bits; - jit_uint32_t cpuid; + jit_uword_t cpuid; } ecx; union { struct { @@ -207,12 +207,12 @@ jit_get_cpu(void) jit_uint32_t __reserved2 : 1; jit_uint32_t pbe : 1; /* amd reserved */ } bits; - jit_uint32_t cpuid; + jit_uword_t cpuid; } edx; #if __WORDSIZE == 32 int ac, flags; #endif - jit_uint32_t eax, ebx; + jit_uword_t eax, ebx; #if __WORDSIZE == 32 /* adapted from glibc __sysconf */ @@ -236,11 +236,14 @@ jit_get_cpu(void) #endif /* query %eax = 1 function */ - __asm__ volatile ("cpuid; movl %%ebx, %1" +#if __WORDSIZE == 32 + __asm__ volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" +#else + __asm__ volatile ("xchgq %%rbx, %1; cpuid; xchgq %%rbx, %1" +#endif : "=a" (eax), "=r" (ebx), "=c" (ecx.cpuid), "=d" (edx.cpuid) - : "0" (1) - : "ebx"); + : "0" (1)); jit_cpu.fpu = edx.bits.fpu; jit_cpu.cmpxchg8b = edx.bits.cmpxchg8b; @@ -262,11 +265,10 @@ jit_get_cpu(void) #if __WORDSIZE == 64 /* query %eax = 0x80000001 function */ - __asm__ volatile ("cpuid; movl %%ebx, %1" + __asm__ volatile ("xchgq %%rbx, %1; cpuid; xchgq %%rbx, %1" : "=a" (eax), "=r" (ebx), "=c" (ecx.cpuid), "=d" (edx.cpuid) - : "0" (0x80000001) - : "ebx"); + : "0" (0x80000001)); jit_cpu.lahf = ecx.cpuid & 1; #endif }