comparison cpudetect.c @ 3146:3164eaa93396

non x86 fix (otherwise we would need #ifdef ARCH_X86 around every if(gCpuCaps.has...))
author michael
date Mon, 26 Nov 2001 23:08:48 +0000
parents 6b4952e00ad0
children c4ca766a2d05
comparison
equal deleted inserted replaced
3145:78e11396f431 3146:3164eaa93396
1 #include "config.h" 1 #include "config.h"
2 #include "cpudetect.h" 2 #include "cpudetect.h"
3
4 CpuCaps gCpuCaps;
3 5
4 #ifdef ARCH_X86 6 #ifdef ARCH_X86
5 7
6 #include <stdio.h> 8 #include <stdio.h>
7 9
20 * team for SSE support detection and more cpu detect code. 22 * team for SSE support detection and more cpu detect code.
21 */ 23 */
22 24
23 /* I believe this code works. However, it has only been used on a PII and PIII */ 25 /* I believe this code works. However, it has only been used on a PII and PIII */
24 26
25 CpuCaps gCpuCaps;
26 static void check_os_katmai_support( void ); 27 static void check_os_katmai_support( void );
27 28
28 #if 1 29 #if 1
29 // return TRUE if cpuid supported 30 // return TRUE if cpuid supported
30 static int has_cpuid() 31 static int has_cpuid()
81 82
82 void GetCpuCaps( CpuCaps *caps) 83 void GetCpuCaps( CpuCaps *caps)
83 { 84 {
84 unsigned int regs[4]; 85 unsigned int regs[4];
85 unsigned int regs2[4]; 86 unsigned int regs2[4];
86 87
88 caps->isX86=1;
89
87 bzero(caps, sizeof(*caps)); 90 bzero(caps, sizeof(*caps));
88 if (!has_cpuid()) { 91 if (!has_cpuid()) {
89 printf("CPUID not supported!???\n"); 92 printf("CPUID not supported!???\n");
90 return; 93 return;
91 } 94 }
92 do_cpuid(0x00000000, regs); // get _max_ cpuid level and vendor name 95 do_cpuid(0x00000000, regs); // get _max_ cpuid level and vendor name
93 printf("CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n",&regs[1],&regs[3],&regs[2],regs[0]); 96 printf("CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n",&regs[1],&regs[3],&regs[2],regs[0]);
94 if (regs[0]>=0x00000001) 97 if (regs[0]>=0x00000001)
95 { 98 {
96 char *tmpstr; 99 char *tmpstr;
97 100
98 do_cpuid(0x00000001, regs2); 101 do_cpuid(0x00000001, regs2);
99 102
100 tmpstr=GetCpuFriendlyName(regs, regs2); 103 tmpstr=GetCpuFriendlyName(regs, regs2);
101 printf("CPU: %s\n",tmpstr); 104 printf("CPU: %s\n",tmpstr);
102 free(tmpstr); 105 free(tmpstr);
140 caps->hasSSE2 = 0; 143 caps->hasSSE2 = 0;
141 #else 144 #else
142 caps->hasSSE=0; 145 caps->hasSSE=0;
143 caps->hasSSE2 = 0; 146 caps->hasSSE2 = 0;
144 #endif 147 #endif
145 148 // caps->has3DNow=1;
149 // caps->hasMMX2 = 0;
150 // caps->hasMMX = 0;
146 151
147 } 152 }
148 153
149 154
150 #define CPUID_EXTFAMILY ((regs2[0] >> 20)&0xFF) /* 27..20 */ 155 #define CPUID_EXTFAMILY ((regs2[0] >> 20)&0xFF) /* 27..20 */
164 printf("Error: GetCpuFriendlyName() not enough memory\n"); 169 printf("Error: GetCpuFriendlyName() not enough memory\n");
165 exit(1); 170 exit(1);
166 } 171 }
167 172
168 sprintf(vendor,"%.4s%.4s%.4s",&regs[1],&regs[3],&regs[2]); 173 sprintf(vendor,"%.4s%.4s%.4s",&regs[1],&regs[3],&regs[2]);
169 174
170 for(i=0; i<MAX_VENDORS; i++){ 175 for(i=0; i<MAX_VENDORS; i++){
171 if(!strcmp(cpuvendors[i].string,vendor)){ 176 if(!strcmp(cpuvendors[i].string,vendor)){
172 if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){ 177 if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){
173 snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]); 178 snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
174 } else { 179 } else {
335 */ 340 */
336 message( "Not testing OS support for SSE, leaving disabled.\n" ); 341 message( "Not testing OS support for SSE, leaving disabled.\n" );
337 gCpuCaps.hasSSE=0; 342 gCpuCaps.hasSSE=0;
338 #endif /* __linux__ */ 343 #endif /* __linux__ */
339 } 344 }
340 #endif /* ARCH_X86 */ 345 #else /* ARCH_X86 */
346
347 void GetCpuCaps( CpuCaps *caps)
348 {
349 caps->cpuType=0;
350 caps->hasMMX=0;
351 caps->hasMMX2=0;
352 caps->has3DNow=0;
353 caps->has3DNowExt=0;
354 caps->hasSSE=0;
355 caps->hasSSE2=0;
356 caps->isX86=0;
357 }
358 #endif /* !ARCH_X86 */