1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-11-10 22:59:13 +00:00

Fixed a crash with gcc-4.6.3 in 32-bit mode. The compiler aggressively optimizes exec_cpuid(), making the stack layout not exactly what the assembly expects. Rearranging instructions seems to fix things. The 64-bit changes aren't tested, though.

git-svn-id: https://svn.code.sf.net/p/libcpuid/code/HEAD/libcpuid@110 3b4be424-7ac5-41d7-8526-f4ddcb85d872
This commit is contained in:
Veselin Georgiev 2013-01-18 22:32:44 +00:00
parent b175d4d6df
commit 0f90f77910

View file

@ -85,12 +85,11 @@ void exec_cpuid(uint32_t *regs)
#ifdef COMPILER_GCC #ifdef COMPILER_GCC
# ifdef PLATFORM_X64 # ifdef PLATFORM_X64
__asm __volatile( __asm __volatile(
" mov %0, %%rdi\n"
" push %%rbx\n" " push %%rbx\n"
" push %%rcx\n" " push %%rcx\n"
" push %%rdx\n" " push %%rdx\n"
" push %%rdi\n"
" mov %0, %%rdi\n"
" mov (%%rdi), %%eax\n" " mov (%%rdi), %%eax\n"
" mov 4(%%rdi), %%ebx\n" " mov 4(%%rdi), %%ebx\n"
@ -103,21 +102,20 @@ void exec_cpuid(uint32_t *regs)
" movl %%ebx, 4(%%rdi)\n" " movl %%ebx, 4(%%rdi)\n"
" movl %%ecx, 8(%%rdi)\n" " movl %%ecx, 8(%%rdi)\n"
" movl %%edx, 12(%%rdi)\n" " movl %%edx, 12(%%rdi)\n"
" pop %%rdi\n"
" pop %%rdx\n" " pop %%rdx\n"
" pop %%rcx\n" " pop %%rcx\n"
" pop %%rbx\n" " pop %%rbx\n"
: :
:"rdi"(regs) :"m"(regs)
:"memory", "eax" :"memory", "eax", "rdi"
); );
# else # else
__asm __volatile( __asm __volatile(
" mov %0, %%edi\n"
" push %%ebx\n" " push %%ebx\n"
" push %%ecx\n" " push %%ecx\n"
" push %%edx\n" " push %%edx\n"
" push %%edi\n"
" mov %0, %%edi\n"
" mov (%%edi), %%eax\n" " mov (%%edi), %%eax\n"
" mov 4(%%edi), %%ebx\n" " mov 4(%%edi), %%ebx\n"
@ -130,13 +128,12 @@ void exec_cpuid(uint32_t *regs)
" mov %%ebx, 4(%%edi)\n" " mov %%ebx, 4(%%edi)\n"
" mov %%ecx, 8(%%edi)\n" " mov %%ecx, 8(%%edi)\n"
" mov %%edx, 12(%%edi)\n" " mov %%edx, 12(%%edi)\n"
" pop %%edi\n"
" pop %%edx\n" " pop %%edx\n"
" pop %%ecx\n" " pop %%ecx\n"
" pop %%ebx\n" " pop %%ebx\n"
: :
:"m"(regs) :"m"(regs)
:"memory", "eax" :"memory", "eax", "edi"
); );
# endif /* COMPILER_GCC */ # endif /* COMPILER_GCC */
#else #else