xfreerdp: Fixed PIC base address corruption by inline assembly

EBX (or RBX on x86_64) is used for the PIC base address.
The current cpuid inline assembly only saved ebx which is fine
under i386 but only half of the fun on x86_64.
This commit is contained in:
Norbert Federa 2012-02-29 21:06:56 +01:00
parent 506cca7abb
commit f821425bf3
1 changed files with 16 additions and 8 deletions

View File

@ -598,14 +598,22 @@ void cpuid(unsigned info, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned
{ {
#ifdef __GNUC__ #ifdef __GNUC__
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
*eax = info;
__asm volatile __asm volatile
("mov %%ebx, %%edi;" /* 32bit PIC: don't clobber ebx */ (
"cpuid;" /* The EBX (or RBX register on x86_64) is used for the PIC base address
and must not be corrupted by our inline assembly. */
#if defined(__i386__)
"mov %%ebx, %%esi;" "mov %%ebx, %%esi;"
"mov %%edi, %%ebx;" "cpuid;"
:"+a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx) "xchg %%ebx, %%esi;"
: :"edi"); #else
"mov %%rbx, %%rsi;"
"cpuid;"
"xchg %%rbx, %%rsi;"
#endif
: "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
: "0" (info)
);
#endif #endif
#endif #endif
} }