comparison src/cpuinfo/SDL_cpuinfo.c @ 3498:a4ce84c4f211

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. :)
author Sam Lantinga <slouken@libsdl.org>
date Mon, 30 Nov 2009 19:52:34 +0000
parents 7bc83a9e09fd
children 4cf8a1423d57
comparison
equal deleted inserted replaced
3497:74d2f44a85de 3498:a4ce84c4f211
168 : 168 :
169 : "%eax", "%ecx", "%edx" 169 : "%eax", "%ecx", "%edx"
170 ); 170 );
171 #elif defined(__GNUC__) && defined(__x86_64__) 171 #elif defined(__GNUC__) && defined(__x86_64__)
172 __asm__ ( 172 __asm__ (
173 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
173 " pushq %%rbx\n" 174 " pushq %%rbx\n"
174 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
175 " cpuid # Get and save vendor ID \n" 175 " cpuid # Get and save vendor ID \n"
176 " popq %%rbx\n"
176 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 177 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
177 " jl 1f # We dont have the CPUID instruction\n" 178 " jl 1f # We dont have the CPUID instruction\n"
178 " xorl %%eax,%%eax \n" 179 " xorl %%eax,%%eax \n"
179 " incl %%eax \n" 180 " incl %%eax \n"
181 " pushq %%rbx\n"
180 " cpuid # Get family/model/stepping/features\n" 182 " cpuid # Get family/model/stepping/features\n"
183 " popq %%rbx\n"
181 " movl %%edx,%0 \n" 184 " movl %%edx,%0 \n"
182 "1: \n" 185 "1: \n"
183 " popq %%rbx\n"
184 : "=m" (features) 186 : "=m" (features)
185 : 187 :
186 : "%rax", "%rcx", "%rdx" 188 : "%rax", "%rcx", "%rdx"
187 ); 189 );
188 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 190 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
240 : 242 :
241 : "%eax", "%ecx", "%edx" 243 : "%eax", "%ecx", "%edx"
242 ); 244 );
243 #elif defined(__GNUC__) && defined (__x86_64__) 245 #elif defined(__GNUC__) && defined (__x86_64__)
244 __asm__ ( 246 __asm__ (
247 " movl $0x80000000,%%eax # Query for extended functions \n"
245 " pushq %%rbx\n" 248 " pushq %%rbx\n"
246 " movl $0x80000000,%%eax # Query for extended functions \n"
247 " cpuid # Get extended function limit \n" 249 " cpuid # Get extended function limit \n"
250 " popq %%rbx\n"
248 " cmpl $0x80000001,%%eax \n" 251 " cmpl $0x80000001,%%eax \n"
249 " jl 1f # Nope, we dont have function 800000001h\n" 252 " jl 1f # Nope, we dont have function 800000001h\n"
250 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" 253 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
254 " pushq %%rbx\n"
251 " cpuid # and get the information \n" 255 " cpuid # and get the information \n"
256 " popq %%rbx\n"
252 " movl %%edx,%0 \n" 257 " movl %%edx,%0 \n"
253 "1: \n" 258 "1: \n"
254 " popq %%rbx\n"
255 : "=m" (features) 259 : "=m" (features)
256 : 260 :
257 : "%rax", "%rcx", "%rdx" 261 : "%rax", "%rcx", "%rdx"
258 ); 262 );
259 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 263 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)