# HG changeset patch # User Sam Lantinga # Date 1259771061 0 # Node ID dcb26ac38e6bb206589d711916ab02701223c651 # Parent a2bb1445744689e6c0ac4786d7c2e330eb119565 Fixed crash - need to save and restore rbx around cpuid, since the compiler may be assuming the stack pointer isn't being modified when filling in %0. I did it around each call to cpuid which isn't strictly necessary, but is definitely future proof. :) diff -r a2bb14457446 -r dcb26ac38e6b src/cpuinfo/SDL_cpuinfo.c --- a/src/cpuinfo/SDL_cpuinfo.c Tue Nov 17 05:14:23 2009 +0000 +++ b/src/cpuinfo/SDL_cpuinfo.c Wed Dec 02 16:24:21 2009 +0000 @@ -26,7 +26,7 @@ #include "SDL.h" #include "SDL_cpuinfo.h" -#if defined(__MACOSX__) && defined(__ppc__) +#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__)) #include /* For AltiVec check */ #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP #include @@ -148,34 +148,34 @@ int features = 0; #if defined(__GNUC__) && defined(i386) __asm__ ( -" pushl %%ebx\n" " xorl %%eax,%%eax # Set up for CPUID instruction \n" +" pushl %%ebx \n" " cpuid # Get and save vendor ID \n" " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" " jl 1f # We dont have the CPUID instruction\n" " xorl %%eax,%%eax \n" " incl %%eax \n" " cpuid # Get family/model/stepping/features\n" +" popl %%ebx \n" " movl %%edx,%0 \n" "1: \n" -" popl %%ebx\n" : "=m" (features) : : "%eax", "%ecx", "%edx" ); #elif defined(__GNUC__) && defined(__x86_64__) __asm__ ( +" xorl %%eax,%%eax # Set up for CPUID instruction \n" " pushq %%rbx\n" -" xorl %%eax,%%eax # Set up for CPUID instruction \n" " cpuid # Get and save vendor ID \n" " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" " jl 1f # We dont have the CPUID instruction\n" " xorl %%eax,%%eax \n" " incl %%eax \n" " cpuid # Get family/model/stepping/features\n" +" popq %%rbx\n" " movl %%edx,%0 \n" "1: \n" -" popq %%rbx\n" : "=m" (features) : : "%rax", "%rcx", "%rdx" @@ -183,32 +183,34 @@ #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) __asm { xor eax, eax ; Set up for CPUID instruction + push ebx cpuid ; Get and save vendor ID cmp eax, 1 ; Make sure 1 is valid input for CPUID jl done ; We dont have the CPUID instruction xor eax, eax inc eax cpuid ; Get family/model/stepping/features + pop ebx mov features, edx done: } #elif defined(__sun) && (defined(__i386) || defined(__amd64)) __asm( -" pushl %ebx\n" " xorl %eax,%eax \n" +" pushl %ebx \n" " cpuid \n" " cmpl $1,%eax \n" " jl 1f \n" " xorl %eax,%eax \n" " incl %eax \n" " cpuid \n" +" popl %ebx \n" #ifdef __i386 " movl %edx,-8(%ebp) \n" #else " movl %edx,-8(%rbp) \n" #endif "1: \n" -" popl %ebx\n" ); #endif return features; } @@ -218,32 +220,32 @@ int features = 0; #if defined(__GNUC__) && defined(i386) __asm__ ( -" pushl %%ebx\n" " movl $0x80000000,%%eax # Query for extended functions \n" +" pushl %%ebx \n" " cpuid # Get extended function limit \n" " cmpl $0x80000001,%%eax \n" " jl 1f # Nope, we dont have function 800000001h\n" " movl $0x80000001,%%eax # Setup extended function 800000001h\n" " cpuid # and get the information \n" +" popl %%ebx \n" " movl %%edx,%0 \n" "1: \n" -" popl %%ebx\n" : "=m" (features) : : "%eax", "%ecx", "%edx" ); #elif defined(__GNUC__) && defined (__x86_64__) __asm__ ( -" pushq %%rbx\n" " movl $0x80000000,%%eax # Query for extended functions \n" +" pushq %%rbx \n" " cpuid # Get extended function limit \n" " cmpl $0x80000001,%%eax \n" " jl 1f # Nope, we dont have function 800000001h\n" " movl $0x80000001,%%eax # Setup extended function 800000001h\n" " cpuid # and get the information \n" +" popq %%rbx \n" " movl %%edx,%0 \n" "1: \n" -" popq %%rbx\n" : "=m" (features) : : "%rax", "%rcx", "%rdx" @@ -251,30 +253,32 @@ #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) __asm { mov eax,80000000h ; Query for extended functions + push ebx cpuid ; Get extended function limit cmp eax,80000001h jl done ; Nope, we dont have function 800000001h mov eax,80000001h ; Setup extended function 800000001h cpuid ; and get the information + pop ebx mov features,edx done: } #elif defined(__sun) && ( defined(__i386) || defined(__amd64) ) __asm ( -" pushl %ebx\n" " movl $0x80000000,%eax \n" +" pushl %ebx \n" " cpuid \n" " cmpl $0x80000001,%eax \n" " jl 1f \n" " movl $0x80000001,%eax \n" " cpuid \n" +" popl %ebx \n" #ifdef __i386 " movl %edx,-8(%ebp) \n" #else " movl %edx,-8(%rbp) \n" #endif "1: \n" -" popl %ebx\n" ); #endif return features; @@ -339,7 +343,7 @@ static __inline__ int CPU_haveAltiVec(void) { volatile int altivec = 0; -#if defined(__MACOSX__) && defined(__ppc__) +#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__)) int selectors[2] = { CTL_HW, HW_VECTORUNIT }; int hasVectorUnit = 0; size_t length = sizeof(hasVectorUnit);