4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(reg
);
22 static BYTE PF
[64] = {0,};
24 /***********************************************************************
25 * GetSystemInfo [KERNEL32.@]
27 * Gets the current system information.
29 * On the first call it creates cached values, so it doesn't have to determine
30 * them repeatedly. On Linux, the /proc/cpuinfo special file is used.
32 * It creates a registry subhierarchy, looking like:
33 * \HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\
34 * Identifier (CPU x86)
35 * Note that there is a hierarchy for every processor installed, so this
36 * supports multiprocessor systems. This is done like Win95 does it, I think.
38 * It also creates a cached flag array for IsProcessorFeaturePresent().
40 * No NULL ptr check for LPSYSTEM_INFO in Win9x.
45 VOID WINAPI
GetSystemInfo(
46 LPSYSTEM_INFO si
/* [out] system information */
49 static SYSTEM_INFO cachedsi
;
53 memcpy(si
,&cachedsi
,sizeof(*si
));
56 memset(PF
,0,sizeof(PF
));
58 /* choose sensible defaults ...
59 * FIXME: perhaps overrideable with precompiler flags?
61 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
62 cachedsi
.dwPageSize
= getpagesize();
64 /* FIXME: the two entries below should be computed somehow... */
65 cachedsi
.lpMinimumApplicationAddress
= (void *)0x00010000;
66 cachedsi
.lpMaximumApplicationAddress
= (void *)0x7FFFFFFF;
67 cachedsi
.dwActiveProcessorMask
= 1;
68 cachedsi
.dwNumberOfProcessors
= 1;
69 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
70 cachedsi
.dwAllocationGranularity
= 0x10000;
71 cachedsi
.wProcessorLevel
= 3; /* 386 */
72 cachedsi
.wProcessorRevision
= 0;
74 cache
= 1; /* even if there is no more info, we now have a cacheentry */
75 memcpy(si
,&cachedsi
,sizeof(*si
));
77 /* Hmm, reasonable processor feature defaults? */
79 /* Create these registry keys for all systems
80 * FPU entry is often empty on Windows, so we don't care either */
81 if ( (RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&hkey
)!=ERROR_SUCCESS
)
82 || (RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey
)!=ERROR_SUCCESS
) )
84 WARN("Unable to write FPU/CPU info to registry\n");
91 FILE *f
= fopen ("/proc/cpuinfo", "r");
96 while (fgets(line
,200,f
)!=NULL
) {
99 /* NOTE: the ':' is the only character we can rely on */
100 if (!(value
= strchr(line
,':')))
102 /* terminate the valuename */
104 /* skip any leading spaces */
105 while (*value
==' ') value
++;
106 if ((s
=strchr(value
,'\n')))
110 if (!strncasecmp(line
, "cpu family",strlen("cpu family"))) {
111 if (isdigit (value
[0])) {
112 switch (value
[0] - '0') {
113 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
114 cachedsi
.wProcessorLevel
= 3;
116 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
117 cachedsi
.wProcessorLevel
= 4;
120 case 6: /* PPro/2/3 has same info as P1 */
121 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
122 cachedsi
.wProcessorLevel
= 5;
124 case 1: /* two-figure levels */
127 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
128 cachedsi
.wProcessorLevel
= 5;
133 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value
);
137 /* set the CPU type of the current processor */
138 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
140 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
144 if (!strncasecmp(line
, "cpu",strlen("cpu"))) {
145 if ( isdigit (value
[0]) && value
[1] == '8' &&
146 value
[2] == '6' && value
[3] == 0
148 switch (value
[0] - '0') {
149 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
150 cachedsi
.wProcessorLevel
= 3;
152 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
153 cachedsi
.wProcessorLevel
= 4;
156 case 6: /* PPro/2/3 has same info as P1 */
157 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
158 cachedsi
.wProcessorLevel
= 5;
161 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value
);
165 /* set the CPU type of the current processor
166 * FIXME: someone reported P4 as being set to
167 * " Intel(R) Pentium(R) 4 CPU 1500MHz"
168 * Do we need to do the same ?
170 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
172 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
175 if (!strncasecmp(line
,"fdiv_bug",strlen("fdiv_bug"))) {
176 if (!strncasecmp(value
,"yes",3))
177 PF
[PF_FLOATING_POINT_PRECISION_ERRATA
] = TRUE
;
181 if (!strncasecmp(line
,"fpu",strlen("fpu"))) {
182 if (!strncasecmp(value
,"no",2))
183 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
187 if (!strncasecmp(line
,"processor",strlen("processor"))) {
188 /* processor number counts up... */
191 if (sscanf(value
,"%d",&x
))
192 if (x
+1>cachedsi
.dwNumberOfProcessors
)
193 cachedsi
.dwNumberOfProcessors
=x
+1;
195 /* Create a new processor subkey on a multiprocessor
201 RegCreateKeyA(hkey
,buf
,&xhkey
);
203 if (!strncasecmp(line
,"stepping",strlen("stepping"))) {
206 if (sscanf(value
,"%d",&x
))
207 cachedsi
.wProcessorRevision
= x
;
209 if ( !strncasecmp(line
,"flags",strlen("flags")) ||
210 !strncasecmp(line
,"features",strlen("features"))
212 if (strstr(value
,"cx8"))
213 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
214 if (strstr(value
,"mmx"))
215 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
216 if (strstr(value
,"tsc"))
217 PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
223 memcpy(si
,&cachedsi
,sizeof(*si
));
225 /* FIXME: how do we do this on other systems? */
227 RegCreateKeyA(hkey
,"0",&xhkey
);
228 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,"CPU 386",strlen("CPU 386"));
237 /***********************************************************************
238 * IsProcessorFeaturePresent [KERNEL32.@]
240 * TRUE if processor feature present
243 BOOL WINAPI
IsProcessorFeaturePresent (
244 DWORD feature
/* [in] feature number, see PF_ defines */
247 GetSystemInfo (&si
); /* To ensure the information is loaded and cached */