comparison cpudetect.c @ 5937:4b18bf35f153

printf to mp_msg
author albeu
date Thu, 02 May 2002 11:00:16 +0000
parents 35ed5387b804
children 2f59920361ff
comparison
equal deleted inserted replaced
5936:d0f040d8f53c 5937:4b18bf35f153
1 #include "config.h" 1 #include "config.h"
2 #include "cpudetect.h" 2 #include "cpudetect.h"
3 #include "mp_msg.h"
3 4
4 CpuCaps gCpuCaps; 5 CpuCaps gCpuCaps;
5 6
6 #ifdef HAVE_MALLOC_H 7 #ifdef HAVE_MALLOC_H
7 #include <malloc.h> 8 #include <malloc.h>
92 93
93 caps->isX86=1; 94 caps->isX86=1;
94 95
95 memset(caps, 0, sizeof(*caps)); 96 memset(caps, 0, sizeof(*caps));
96 if (!has_cpuid()) { 97 if (!has_cpuid()) {
97 printf("CPUID not supported!???\n"); 98 mp_msg(MSGT_CPUDETECT,MSGL_ERR,"CPUID not supported!???\n");
98 return; 99 return;
99 } 100 }
100 do_cpuid(0x00000000, regs); // get _max_ cpuid level and vendor name 101 do_cpuid(0x00000000, regs); // get _max_ cpuid level and vendor name
101 printf("CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n", 102 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n",
102 (char*) (regs+1),(char*) (regs+3),(char*) (regs+2), regs[0]); 103 (char*) (regs+1),(char*) (regs+3),(char*) (regs+2), regs[0]);
103 if (regs[0]>=0x00000001) 104 if (regs[0]>=0x00000001)
104 { 105 {
105 char *tmpstr; 106 char *tmpstr;
106 107
107 do_cpuid(0x00000001, regs2); 108 do_cpuid(0x00000001, regs2);
108 109
109 tmpstr=GetCpuFriendlyName(regs, regs2); 110 tmpstr=GetCpuFriendlyName(regs, regs2);
110 printf("CPU: %s ",tmpstr); 111 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: %s ",tmpstr);
111 free(tmpstr); 112 free(tmpstr);
112 113
113 caps->cpuType=(regs2[0] >> 8)&0xf; 114 caps->cpuType=(regs2[0] >> 8)&0xf;
114 if(caps->cpuType==0xf){ 115 if(caps->cpuType==0xf){
115 // use extended family (P4, IA64) 116 // use extended family (P4, IA64)
116 caps->cpuType=8+((regs2[0]>>20)&255); 117 caps->cpuType=8+((regs2[0]>>20)&255);
117 } 118 }
118 caps->cpuStepping=regs2[0] & 0xf; 119 caps->cpuStepping=regs2[0] & 0xf;
119 printf("(Type: %d, Stepping: %d)\n", 120 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"(Type: %d, Stepping: %d)\n",
120 caps->cpuType, caps->cpuStepping); 121 caps->cpuType, caps->cpuStepping);
121 122
122 // general feature flags: 123 // general feature flags:
123 caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; // 0x0800000 124 caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
124 caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25; // 0x2000000 125 caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25; // 0x2000000
125 caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // 0x4000000 126 caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // 0x4000000
126 caps->hasMMX2 = caps->hasSSE; // SSE cpus supports mmxext too 127 caps->hasMMX2 = caps->hasSSE; // SSE cpus supports mmxext too
127 } 128 }
128 do_cpuid(0x80000000, regs); 129 do_cpuid(0x80000000, regs);
129 if (regs[0]>=0x80000001) { 130 if (regs[0]>=0x80000001) {
130 printf("extended cpuid-level: %d\n",regs[0]&0x7FFFFFFF); 131 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"extended cpuid-level: %d\n",regs[0]&0x7FFFFFFF);
131 do_cpuid(0x80000001, regs2); 132 do_cpuid(0x80000001, regs2);
132 caps->hasMMX |= (regs2[3] & (1 << 23 )) >> 23; // 0x0800000 133 caps->hasMMX |= (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
133 caps->hasMMX2 |= (regs2[3] & (1 << 22 )) >> 22; // 0x400000 134 caps->hasMMX2 |= (regs2[3] & (1 << 22 )) >> 22; // 0x400000
134 caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; //0x80000000 135 caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; //0x80000000
135 caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30; 136 caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30;
136 } 137 }
137 #if 0 138 #if 0
138 printf("cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n", 139 mp_msg(MSGT_CPUDETECT,MSGL_INFO,"cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n",
139 gCpuCaps.hasMMX, 140 gCpuCaps.hasMMX,
140 gCpuCaps.hasMMX2, 141 gCpuCaps.hasMMX2,
141 gCpuCaps.hasSSE, 142 gCpuCaps.hasSSE,
142 gCpuCaps.hasSSE2, 143 gCpuCaps.hasSSE2,
143 gCpuCaps.has3DNow, 144 gCpuCaps.has3DNow,
157 // caps->has3DNow=1; 158 // caps->has3DNow=1;
158 // caps->hasMMX2 = 0; 159 // caps->hasMMX2 = 0;
159 // caps->hasMMX = 0; 160 // caps->hasMMX = 0;
160 161
161 #ifndef HAVE_MMX 162 #ifndef HAVE_MMX
162 if(caps->hasMMX) printf("MMX supported but disabled\n"); 163 if(caps->hasMMX) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"MMX supported but disabled\n");
163 caps->hasMMX=0; 164 caps->hasMMX=0;
164 #endif 165 #endif
165 #ifndef HAVE_MMX2 166 #ifndef HAVE_MMX2
166 if(caps->hasMMX2) printf("MMX2 supported but disabled\n"); 167 if(caps->hasMMX2) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"MMX2 supported but disabled\n");
167 caps->hasMMX2=0; 168 caps->hasMMX2=0;
168 #endif 169 #endif
169 #ifndef HAVE_SSE 170 #ifndef HAVE_SSE
170 if(caps->hasSSE) printf("SSE supported but disabled\n"); 171 if(caps->hasSSE) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"SSE supported but disabled\n");
171 caps->hasSSE=0; 172 caps->hasSSE=0;
172 #endif 173 #endif
173 #ifndef HAVE_SSE2 174 #ifndef HAVE_SSE2
174 if(caps->hasSSE2) printf("SSE2 supported but disabled\n"); 175 if(caps->hasSSE2) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"SSE2 supported but disabled\n");
175 caps->hasSSE2=0; 176 caps->hasSSE2=0;
176 #endif 177 #endif
177 #ifndef HAVE_3DNOW 178 #ifndef HAVE_3DNOW
178 if(caps->has3DNow) printf("3DNow supported but disabled\n"); 179 if(caps->has3DNow) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"3DNow supported but disabled\n");
179 caps->has3DNow=0; 180 caps->has3DNow=0;
180 #endif 181 #endif
181 #ifndef HAVE_3DNOWEX 182 #ifndef HAVE_3DNOWEX
182 if(caps->has3DNowExt) printf("3DNowExt supported but disabled\n"); 183 if(caps->has3DNowExt) mp_msg(MSGT_CPUDETECT,MSGL_INFO,"3DNowExt supported but disabled\n");
183 caps->has3DNowExt=0; 184 caps->has3DNowExt=0;
184 #endif 185 #endif
185 } 186 }
186 187
187 188
197 char vendor[17]; 198 char vendor[17];
198 char *retname; 199 char *retname;
199 int i; 200 int i;
200 201
201 if (NULL==(retname=(char*)malloc(256))) { 202 if (NULL==(retname=(char*)malloc(256))) {
202 printf("Error: GetCpuFriendlyName() not enough memory\n"); 203 mp_msg(MSGT_CPUDETECT,MSGL_FATAL,"Error: GetCpuFriendlyName() not enough memory\n");
203 exit(1); 204 exit(1);
204 } 205 }
205 206
206 sprintf(vendor,"%.4s%.4s%.4s",(char*)(regs+1),(char*)(regs+3),(char*)(regs+2)); 207 sprintf(vendor,"%.4s%.4s%.4s",(char*)(regs+1),(char*)(regs+3),(char*)(regs+2));
207 208
209 if(!strcmp(cpuvendors[i].string,vendor)){ 210 if(!strcmp(cpuvendors[i].string,vendor)){
210 if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){ 211 if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){
211 snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]); 212 snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
212 } else { 213 } else {
213 snprintf(retname,255,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY); 214 snprintf(retname,255,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY);
214 printf("unknown %s CPU:\n",cpuvendors[i].name); 215 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"unknown %s CPU:\n",cpuvendors[i].name);
215 printf("Vendor: %s\n",cpuvendors[i].string); 216 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Vendor: %s\n",cpuvendors[i].string);
216 printf("Type: %d\n",CPUID_TYPE); 217 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Type: %d\n",CPUID_TYPE);
217 printf("Family: %d (ext: %d)\n",CPUID_FAMILY,CPUID_EXTFAMILY); 218 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Family: %d (ext: %d)\n",CPUID_FAMILY,CPUID_EXTFAMILY);
218 printf("Model: %d (ext: %d)\n",CPUID_MODEL,CPUID_EXTMODEL); 219 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Model: %d (ext: %d)\n",CPUID_MODEL,CPUID_EXTMODEL);
219 printf("Stepping: %d\n",CPUID_STEPPING); 220 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Stepping: %d\n",CPUID_STEPPING);
220 printf("Please send the above info along with the exact CPU name" 221 mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Please send the above info along with the exact CPU name"
221 "to the MPlayer-Developers, so we can add it to the list!\n"); 222 "to the MPlayer-Developers, so we can add it to the list!\n");
222 } 223 }
223 } 224 }
224 } 225 }
225 226
236 237
237 238
238 #if defined(__linux__) && defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC) 239 #if defined(__linux__) && defined(_POSIX_SOURCE) && defined(X86_FXSR_MAGIC)
239 static void sigill_handler_sse( int signal, struct sigcontext sc ) 240 static void sigill_handler_sse( int signal, struct sigcontext sc )
240 { 241 {
241 printf( "SIGILL, " ); 242 mp_msg(MSGT_CPUDETECT,MSGL_FATAL, "SIGILL, " );
242 243
243 /* Both the "xorps %%xmm0,%%xmm0" and "divps %xmm0,%%xmm1" 244 /* Both the "xorps %%xmm0,%%xmm0" and "divps %xmm0,%%xmm1"
244 * instructions are 3 bytes long. We must increment the instruction 245 * instructions are 3 bytes long. We must increment the instruction
245 * pointer manually to avoid repeated execution of the offending 246 * pointer manually to avoid repeated execution of the offending
246 * instruction. 247 * instruction.
255 gCpuCaps.hasSSE=0; 256 gCpuCaps.hasSSE=0;
256 } 257 }
257 258
258 static void sigfpe_handler_sse( int signal, struct sigcontext sc ) 259 static void sigfpe_handler_sse( int signal, struct sigcontext sc )
259 { 260 {
260 printf( "SIGFPE, " ); 261 mp_msg(MSGT_CPUDETECT,MSGL_FATAL, "SIGFPE, " );
261 262
262 if ( sc.fpstate->magic != 0xffff ) { 263 if ( sc.fpstate->magic != 0xffff ) {
263 /* Our signal context has the extended FPU state, so reset the 264 /* Our signal context has the extended FPU state, so reset the
264 * divide-by-zero exception mask and clear the divide-by-zero 265 * divide-by-zero exception mask and clear the divide-by-zero
265 * exception bit. 266 * exception bit.
267 sc.fpstate->mxcsr |= 0x00000200; 268 sc.fpstate->mxcsr |= 0x00000200;
268 sc.fpstate->mxcsr &= 0xfffffffb; 269 sc.fpstate->mxcsr &= 0xfffffffb;
269 } else { 270 } else {
270 /* If we ever get here, we're completely hosed. 271 /* If we ever get here, we're completely hosed.
271 */ 272 */
272 printf( "\n\n" ); 273 mp_msg(MSGT_CPUDETECT,MSGL_FATAL, "\n\n" );
273 printf( "SSE enabling test failed badly!" ); 274 mp_msg(MSGT_CPUDETECT,MSGL_FATAL, "SSE enabling test failed badly!" );
274 } 275 }
275 } 276 }
276 #endif /* __linux__ && _POSIX_SOURCE && X86_FXSR_MAGIC */ 277 #endif /* __linux__ && _POSIX_SOURCE && X86_FXSR_MAGIC */
277 278
278 /* If we're running on a processor that can do SSE, let's see if we 279 /* If we're running on a processor that can do SSE, let's see if we
309 * we execute an SSE instruction on a PIII and get a SIGILL, the OS 310 * we execute an SSE instruction on a PIII and get a SIGILL, the OS
310 * doesn't support Streaming SIMD Exceptions, even if the processor 311 * doesn't support Streaming SIMD Exceptions, even if the processor
311 * does. 312 * does.
312 */ 313 */
313 if ( gCpuCaps.hasSSE ) { 314 if ( gCpuCaps.hasSSE ) {
314 printf( "Testing OS support for SSE... " ); 315 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "Testing OS support for SSE... " );
315 316
316 // __asm __volatile ("xorps %%xmm0, %%xmm0"); 317 // __asm __volatile ("xorps %%xmm0, %%xmm0");
317 __asm __volatile ("xorps %xmm0, %xmm0"); 318 __asm __volatile ("xorps %xmm0, %xmm0");
318 319
319 if ( gCpuCaps.hasSSE ) { 320 if ( gCpuCaps.hasSSE ) {
320 printf( "yes.\n" ); 321 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "yes.\n" );
321 } else { 322 } else {
322 printf( "no!\n" ); 323 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "no!\n" );
323 } 324 }
324 } 325 }
325 326
326 /* Emulate test for OSXMMEXCPT in CR4. The OS will set this bit if 327 /* Emulate test for OSXMMEXCPT in CR4. The OS will set this bit if
327 * it supports unmasked SIMD FPU exceptions. If we unmask the 328 * it supports unmasked SIMD FPU exceptions. If we unmask the
335 * doesn't even support them. We at least know the user-space SSE 336 * doesn't even support them. We at least know the user-space SSE
336 * support is good in kernels that do support unmasked exceptions, 337 * support is good in kernels that do support unmasked exceptions,
337 * and therefore to be safe I'm going to leave this test in here. 338 * and therefore to be safe I'm going to leave this test in here.
338 */ 339 */
339 if ( gCpuCaps.hasSSE ) { 340 if ( gCpuCaps.hasSSE ) {
340 printf( "Testing OS support for SSE unmasked exceptions... " ); 341 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "Testing OS support for SSE unmasked exceptions... " );
341 342
342 // test_os_katmai_exception_support(); 343 // test_os_katmai_exception_support();
343 344
344 if ( gCpuCaps.hasSSE ) { 345 if ( gCpuCaps.hasSSE ) {
345 printf( "yes.\n" ); 346 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "yes.\n" );
346 } else { 347 } else {
347 printf( "no!\n" ); 348 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "no!\n" );
348 } 349 }
349 } 350 }
350 351
351 /* Restore the original signal handlers. 352 /* Restore the original signal handlers.
352 */ 353 */
355 356
356 /* If we've gotten to here and the XMM CPUID bit is still set, we're 357 /* If we've gotten to here and the XMM CPUID bit is still set, we're
357 * safe to go ahead and hook out the SSE code throughout Mesa. 358 * safe to go ahead and hook out the SSE code throughout Mesa.
358 */ 359 */
359 if ( gCpuCaps.hasSSE ) { 360 if ( gCpuCaps.hasSSE ) {
360 printf( "Tests of OS support for SSE passed.\n" ); 361 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "Tests of OS support for SSE passed.\n" );
361 } else { 362 } else {
362 printf( "Tests of OS support for SSE failed!\n" ); 363 mp_msg(MSGT_CPUDETECT,MSGL_INFO, "Tests of OS support for SSE failed!\n" );
363 } 364 }
364 #else 365 #else
365 /* We can't use POSIX signal handling to test the availability of 366 /* We can't use POSIX signal handling to test the availability of
366 * SSE, so we disable it by default. 367 * SSE, so we disable it by default.
367 */ 368 */
368 printf( "Cannot test OS support for SSE, disabling to be safe.\n" ); 369 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Cannot test OS support for SSE, disabling to be safe.\n" );
369 gCpuCaps.hasSSE=0; 370 gCpuCaps.hasSSE=0;
370 #endif /* _POSIX_SOURCE && X86_FXSR_MAGIC */ 371 #endif /* _POSIX_SOURCE && X86_FXSR_MAGIC */
371 #else 372 #else
372 /* Do nothing on other platforms for now. 373 /* Do nothing on other platforms for now.
373 */ 374 */
374 printf( "Not testing OS support for SSE, leaving disabled.\n" ); 375 mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Not testing OS support for SSE, leaving disabled.\n" );
375 gCpuCaps.hasSSE=0; 376 gCpuCaps.hasSSE=0;
376 #endif /* __linux__ */ 377 #endif /* __linux__ */
377 } 378 }
378 #else /* ARCH_X86 */ 379 #else /* ARCH_X86 */
379 380