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. :)
1.1 --- a/src/cpuinfo/SDL_cpuinfo.c Tue Nov 17 05:14:23 2009 +0000
1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c Wed Dec 02 16:24:21 2009 +0000
1.3 @@ -26,7 +26,7 @@
1.4 #include "SDL.h"
1.5 #include "SDL_cpuinfo.h"
1.6
1.7 -#if defined(__MACOSX__) && defined(__ppc__)
1.8 +#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
1.9 #include <sys/sysctl.h> /* For AltiVec check */
1.10 #elif SDL_ALTIVEC_BLITTERS && HAVE_SETJMP
1.11 #include <signal.h>
1.12 @@ -148,34 +148,34 @@
1.13 int features = 0;
1.14 #if defined(__GNUC__) && defined(i386)
1.15 __asm__ (
1.16 -" pushl %%ebx\n"
1.17 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
1.18 +" pushl %%ebx \n"
1.19 " cpuid # Get and save vendor ID \n"
1.20 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
1.21 " jl 1f # We dont have the CPUID instruction\n"
1.22 " xorl %%eax,%%eax \n"
1.23 " incl %%eax \n"
1.24 " cpuid # Get family/model/stepping/features\n"
1.25 +" popl %%ebx \n"
1.26 " movl %%edx,%0 \n"
1.27 "1: \n"
1.28 -" popl %%ebx\n"
1.29 : "=m" (features)
1.30 :
1.31 : "%eax", "%ecx", "%edx"
1.32 );
1.33 #elif defined(__GNUC__) && defined(__x86_64__)
1.34 __asm__ (
1.35 +" xorl %%eax,%%eax # Set up for CPUID instruction \n"
1.36 " pushq %%rbx\n"
1.37 -" xorl %%eax,%%eax # Set up for CPUID instruction \n"
1.38 " cpuid # Get and save vendor ID \n"
1.39 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
1.40 " jl 1f # We dont have the CPUID instruction\n"
1.41 " xorl %%eax,%%eax \n"
1.42 " incl %%eax \n"
1.43 " cpuid # Get family/model/stepping/features\n"
1.44 +" popq %%rbx\n"
1.45 " movl %%edx,%0 \n"
1.46 "1: \n"
1.47 -" popq %%rbx\n"
1.48 : "=m" (features)
1.49 :
1.50 : "%rax", "%rcx", "%rdx"
1.51 @@ -183,32 +183,34 @@
1.52 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
1.53 __asm {
1.54 xor eax, eax ; Set up for CPUID instruction
1.55 + push ebx
1.56 cpuid ; Get and save vendor ID
1.57 cmp eax, 1 ; Make sure 1 is valid input for CPUID
1.58 jl done ; We dont have the CPUID instruction
1.59 xor eax, eax
1.60 inc eax
1.61 cpuid ; Get family/model/stepping/features
1.62 + pop ebx
1.63 mov features, edx
1.64 done:
1.65 }
1.66 #elif defined(__sun) && (defined(__i386) || defined(__amd64))
1.67 __asm(
1.68 -" pushl %ebx\n"
1.69 " xorl %eax,%eax \n"
1.70 +" pushl %ebx \n"
1.71 " cpuid \n"
1.72 " cmpl $1,%eax \n"
1.73 " jl 1f \n"
1.74 " xorl %eax,%eax \n"
1.75 " incl %eax \n"
1.76 " cpuid \n"
1.77 +" popl %ebx \n"
1.78 #ifdef __i386
1.79 " movl %edx,-8(%ebp) \n"
1.80 #else
1.81 " movl %edx,-8(%rbp) \n"
1.82 #endif
1.83 "1: \n"
1.84 -" popl %ebx\n" );
1.85 #endif
1.86 return features;
1.87 }
1.88 @@ -218,32 +220,32 @@
1.89 int features = 0;
1.90 #if defined(__GNUC__) && defined(i386)
1.91 __asm__ (
1.92 -" pushl %%ebx\n"
1.93 " movl $0x80000000,%%eax # Query for extended functions \n"
1.94 +" pushl %%ebx \n"
1.95 " cpuid # Get extended function limit \n"
1.96 " cmpl $0x80000001,%%eax \n"
1.97 " jl 1f # Nope, we dont have function 800000001h\n"
1.98 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
1.99 " cpuid # and get the information \n"
1.100 +" popl %%ebx \n"
1.101 " movl %%edx,%0 \n"
1.102 "1: \n"
1.103 -" popl %%ebx\n"
1.104 : "=m" (features)
1.105 :
1.106 : "%eax", "%ecx", "%edx"
1.107 );
1.108 #elif defined(__GNUC__) && defined (__x86_64__)
1.109 __asm__ (
1.110 -" pushq %%rbx\n"
1.111 " movl $0x80000000,%%eax # Query for extended functions \n"
1.112 +" pushq %%rbx \n"
1.113 " cpuid # Get extended function limit \n"
1.114 " cmpl $0x80000001,%%eax \n"
1.115 " jl 1f # Nope, we dont have function 800000001h\n"
1.116 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
1.117 " cpuid # and get the information \n"
1.118 +" popq %%rbx \n"
1.119 " movl %%edx,%0 \n"
1.120 "1: \n"
1.121 -" popq %%rbx\n"
1.122 : "=m" (features)
1.123 :
1.124 : "%rax", "%rcx", "%rdx"
1.125 @@ -251,30 +253,32 @@
1.126 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
1.127 __asm {
1.128 mov eax,80000000h ; Query for extended functions
1.129 + push ebx
1.130 cpuid ; Get extended function limit
1.131 cmp eax,80000001h
1.132 jl done ; Nope, we dont have function 800000001h
1.133 mov eax,80000001h ; Setup extended function 800000001h
1.134 cpuid ; and get the information
1.135 + pop ebx
1.136 mov features,edx
1.137 done:
1.138 }
1.139 #elif defined(__sun) && ( defined(__i386) || defined(__amd64) )
1.140 __asm (
1.141 -" pushl %ebx\n"
1.142 " movl $0x80000000,%eax \n"
1.143 +" pushl %ebx \n"
1.144 " cpuid \n"
1.145 " cmpl $0x80000001,%eax \n"
1.146 " jl 1f \n"
1.147 " movl $0x80000001,%eax \n"
1.148 " cpuid \n"
1.149 +" popl %ebx \n"
1.150 #ifdef __i386
1.151 " movl %edx,-8(%ebp) \n"
1.152 #else
1.153 " movl %edx,-8(%rbp) \n"
1.154 #endif
1.155 "1: \n"
1.156 -" popl %ebx\n"
1.157 );
1.158 #endif
1.159 return features;
1.160 @@ -339,7 +343,7 @@
1.161 static __inline__ int CPU_haveAltiVec(void)
1.162 {
1.163 volatile int altivec = 0;
1.164 -#if defined(__MACOSX__) && defined(__ppc__)
1.165 +#if defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))
1.166 int selectors[2] = { CTL_HW, HW_VECTORUNIT };
1.167 int hasVectorUnit = 0;
1.168 size_t length = sizeof(hasVectorUnit);