comparison src/cpuinfo/SDL_cpuinfo.c @ 3420:935f36ec1844

Fixed bug #734 Save and restore the PIC register %ebx/%rbx using push/pop instead of %edi/%rdi
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Oct 2009 04:45:01 +0000
parents 714a352c8869
children 7bc83a9e09fd
comparison
equal deleted inserted replaced
3419:e00d6ecb5d4b 3420:935f36ec1844
151 { 151 {
152 int features = 0; 152 int features = 0;
153 /* *INDENT-OFF* */ 153 /* *INDENT-OFF* */
154 #if defined(__GNUC__) && defined(i386) 154 #if defined(__GNUC__) && defined(i386)
155 __asm__ ( 155 __asm__ (
156 " movl %%ebx,%%edi\n" 156 " pushl %%ebx\n"
157 " xorl %%eax,%%eax # Set up for CPUID instruction \n" 157 " xorl %%eax,%%eax # Set up for CPUID instruction \n"
158 " cpuid # Get and save vendor ID \n" 158 " cpuid # Get and save vendor ID \n"
159 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 159 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
160 " jl 1f # We dont have the CPUID instruction\n" 160 " jl 1f # We dont have the CPUID instruction\n"
161 " xorl %%eax,%%eax \n" 161 " xorl %%eax,%%eax \n"
162 " incl %%eax \n" 162 " incl %%eax \n"
163 " cpuid # Get family/model/stepping/features\n" 163 " cpuid # Get family/model/stepping/features\n"
164 " movl %%edx,%0 \n" 164 " movl %%edx,%0 \n"
165 "1: \n" 165 "1: \n"
166 " movl %%edi,%%ebx\n" 166 " popl %%ebx\n"
167 : "=m" (features) 167 : "=m" (features)
168 : 168 :
169 : "%eax", "%ecx", "%edx", "%edi" 169 : "%eax", "%ecx", "%edx", "cc"
170 ); 170 );
171 #elif defined(__GNUC__) && defined(__x86_64__) 171 #elif defined(__GNUC__) && defined(__x86_64__)
172 __asm__ ( 172 __asm__ (
173 " movq %%rbx,%%rdi\n" 173 " pushq %%rbx\n"
174 " xorl %%eax,%%eax # Set up for CPUID instruction \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 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n" 176 " cmpl $1,%%eax # Make sure 1 is valid input for CPUID\n"
177 " jl 1f # We dont have the CPUID instruction\n" 177 " jl 1f # We dont have the CPUID instruction\n"
178 " xorl %%eax,%%eax \n" 178 " xorl %%eax,%%eax \n"
179 " incl %%eax \n" 179 " incl %%eax \n"
180 " cpuid # Get family/model/stepping/features\n" 180 " cpuid # Get family/model/stepping/features\n"
181 " movl %%edx,%0 \n" 181 " movl %%edx,%0 \n"
182 "1: \n" 182 "1: \n"
183 " movq %%rdi,%%rbx\n" 183 " popq %%rbx\n"
184 : "=m" (features) 184 : "=m" (features)
185 : 185 :
186 : "%rax", "%rbx", "%rcx", "%rdx", "%rdi" 186 : "%rax", "%rcx", "%rdx", "cc"
187 ); 187 );
188 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 188 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
189 __asm { 189 __asm {
190 xor eax, eax ; Set up for CPUID instruction 190 xor eax, eax ; Set up for CPUID instruction
191 cpuid ; Get and save vendor ID 191 cpuid ; Get and save vendor ID
224 { 224 {
225 int features = 0; 225 int features = 0;
226 /* *INDENT-OFF* */ 226 /* *INDENT-OFF* */
227 #if defined(__GNUC__) && defined(i386) 227 #if defined(__GNUC__) && defined(i386)
228 __asm__ ( 228 __asm__ (
229 " movl %%ebx,%%edi\n" 229 " pushl %%ebx\n"
230 " movl $0x80000000,%%eax # Query for extended functions \n" 230 " movl $0x80000000,%%eax # Query for extended functions \n"
231 " cpuid # Get extended function limit \n" 231 " cpuid # Get extended function limit \n"
232 " cmpl $0x80000001,%%eax \n" 232 " cmpl $0x80000001,%%eax \n"
233 " jl 1f # Nope, we dont have function 800000001h\n" 233 " jl 1f # Nope, we dont have function 800000001h\n"
234 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" 234 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
235 " cpuid # and get the information \n" 235 " cpuid # and get the information \n"
236 " movl %%edx,%0 \n" 236 " movl %%edx,%0 \n"
237 "1: \n" 237 "1: \n"
238 " movl %%edi,%%ebx\n" 238 " popl %%ebx\n"
239 : "=m" (features) 239 : "=m" (features)
240 : 240 :
241 : "%eax", "%ecx", "%edx", "%edi" 241 : "%eax", "%ecx", "%edx", "cc"
242 ); 242 );
243 #elif defined(__GNUC__) && defined (__x86_64__) 243 #elif defined(__GNUC__) && defined (__x86_64__)
244 __asm__ ( 244 __asm__ (
245 " movq %%rbx,%%rdi\n" 245 " pushq %%rbx\n"
246 " movl $0x80000000,%%eax # Query for extended functions \n" 246 " movl $0x80000000,%%eax # Query for extended functions \n"
247 " cpuid # Get extended function limit \n" 247 " cpuid # Get extended function limit \n"
248 " cmpl $0x80000001,%%eax \n" 248 " cmpl $0x80000001,%%eax \n"
249 " jl 1f # Nope, we dont have function 800000001h\n" 249 " jl 1f # Nope, we dont have function 800000001h\n"
250 " movl $0x80000001,%%eax # Setup extended function 800000001h\n" 250 " movl $0x80000001,%%eax # Setup extended function 800000001h\n"
251 " cpuid # and get the information \n" 251 " cpuid # and get the information \n"
252 " movl %%edx,%0 \n" 252 " movl %%edx,%0 \n"
253 "1: \n" 253 "1: \n"
254 " movq %%rdi,%%rbx\n" 254 " popq %%rbx\n"
255 : "=m" (features) 255 : "=m" (features)
256 : 256 :
257 : "%rax", "%rbx", "%rcx", "%rdx", "%rdi" 257 : "%rax", "%rcx", "%rdx", "cc"
258 ); 258 );
259 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 259 #elif (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
260 __asm { 260 __asm {
261 mov eax,80000000h ; Query for extended functions 261 mov eax,80000000h ; Query for extended functions
262 cpuid ; Get extended function limit 262 cpuid ; Get extended function limit