4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(reg
);
23 static BYTE PF
[64] = {0,};
25 /***********************************************************************
26 * GetSystemInfo [KERNEL32.@]
28 * Gets the current system information.
30 * On the first call it creates cached values, so it doesn't have to determine
31 * them repeatedly. On Linux, the /proc/cpuinfo special file is used.
33 * It creates a registry subhierarchy, looking like:
34 * \HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\
35 * Identifier (CPU x86)
36 * Note that there is a hierarchy for every processor installed, so this
37 * supports multiprocessor systems. This is done like Win95 does it, I think.
39 * It also creates a cached flag array for IsProcessorFeaturePresent().
41 * No NULL ptr check for LPSYSTEM_INFO in Win9x.
46 VOID WINAPI
GetSystemInfo(
47 LPSYSTEM_INFO si
/* [out] system information */
50 static SYSTEM_INFO cachedsi
;
54 memcpy(si
,&cachedsi
,sizeof(*si
));
57 memset(PF
,0,sizeof(PF
));
59 /* choose sensible defaults ...
60 * FIXME: perhaps overrideable with precompiler flags?
62 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
63 cachedsi
.dwPageSize
= getpagesize();
65 /* FIXME: the two entries below should be computed somehow... */
66 cachedsi
.lpMinimumApplicationAddress
= (void *)0x00010000;
67 cachedsi
.lpMaximumApplicationAddress
= (void *)0x7FFFFFFF;
68 cachedsi
.dwActiveProcessorMask
= 1;
69 cachedsi
.dwNumberOfProcessors
= 1;
70 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
71 cachedsi
.dwAllocationGranularity
= 0x10000;
72 cachedsi
.wProcessorLevel
= 3; /* 386 */
73 cachedsi
.wProcessorRevision
= 0;
75 cache
= 1; /* even if there is no more info, we now have a cacheentry */
76 memcpy(si
,&cachedsi
,sizeof(*si
));
78 /* Hmm, reasonable processor feature defaults? */
80 /* Create these registry keys for all systems
81 * FPU entry is often empty on Windows, so we don't care either */
82 if ( (RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&hkey
)!=ERROR_SUCCESS
)
83 || (RegCreateKeyA(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey
)!=ERROR_SUCCESS
) )
85 WARN("Unable to write FPU/CPU info to registry\n");
92 FILE *f
= fopen ("/proc/cpuinfo", "r");
97 while (fgets(line
,200,f
)!=NULL
) {
100 /* NOTE: the ':' is the only character we can rely on */
101 if (!(value
= strchr(line
,':')))
103 /* terminate the valuename */
105 /* skip any leading spaces */
106 while (*value
==' ') value
++;
107 if ((s
=strchr(value
,'\n')))
111 if (!strncasecmp(line
, "cpu family",strlen("cpu family"))) {
112 if (isdigit (value
[0])) {
113 switch (value
[0] - '0') {
114 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
115 cachedsi
.wProcessorLevel
= 3;
117 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
118 cachedsi
.wProcessorLevel
= 4;
121 case 6: /* PPro/2/3 has same info as P1 */
122 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
123 cachedsi
.wProcessorLevel
= 5;
125 case 1: /* two-figure levels */
128 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
129 cachedsi
.wProcessorLevel
= 5;
134 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value
);
138 /* set the CPU type of the current processor */
139 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
141 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
145 if (!strncasecmp(line
, "cpu",strlen("cpu"))) {
146 if ( isdigit (value
[0]) && value
[1] == '8' &&
147 value
[2] == '6' && value
[3] == 0
149 switch (value
[0] - '0') {
150 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
151 cachedsi
.wProcessorLevel
= 3;
153 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
154 cachedsi
.wProcessorLevel
= 4;
157 case 6: /* PPro/2/3 has same info as P1 */
158 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
159 cachedsi
.wProcessorLevel
= 5;
162 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value
);
166 /* set the CPU type of the current processor
167 * FIXME: someone reported P4 as being set to
168 * " Intel(R) Pentium(R) 4 CPU 1500MHz"
169 * Do we need to do the same ?
171 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
173 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
176 if (!strncasecmp(line
,"fdiv_bug",strlen("fdiv_bug"))) {
177 if (!strncasecmp(value
,"yes",3))
178 PF
[PF_FLOATING_POINT_PRECISION_ERRATA
] = TRUE
;
182 if (!strncasecmp(line
,"fpu",strlen("fpu"))) {
183 if (!strncasecmp(value
,"no",2))
184 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
188 if (!strncasecmp(line
,"processor",strlen("processor"))) {
189 /* processor number counts up... */
192 if (sscanf(value
,"%d",&x
))
193 if (x
+1>cachedsi
.dwNumberOfProcessors
)
194 cachedsi
.dwNumberOfProcessors
=x
+1;
196 /* Create a new processor subkey on a multiprocessor
202 RegCreateKeyA(hkey
,buf
,&xhkey
);
204 if (!strncasecmp(line
,"stepping",strlen("stepping"))) {
207 if (sscanf(value
,"%d",&x
))
208 cachedsi
.wProcessorRevision
= x
;
210 if ( !strncasecmp(line
,"flags",strlen("flags")) ||
211 !strncasecmp(line
,"features",strlen("features"))
213 if (strstr(value
,"cx8"))
214 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
215 if (strstr(value
,"mmx"))
216 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
217 if (strstr(value
,"tsc"))
218 PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
224 memcpy(si
,&cachedsi
,sizeof(*si
));
226 /* FIXME: how do we do this on other systems? */
228 RegCreateKeyA(hkey
,"0",&xhkey
);
229 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,"CPU 386",strlen("CPU 386"));
238 /***********************************************************************
239 * IsProcessorFeaturePresent [KERNEL32.@]
241 * TRUE if processor feature present
244 BOOL WINAPI
IsProcessorFeaturePresent (
245 DWORD feature
/* [in] feature number, see PF_ defines */
248 GetSystemInfo (&si
); /* To ensure the information is loaded and cached */