4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
12 #include "wine/winbase16.h"
13 #include "wine/winestring.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(reg
);
22 static BYTE PF
[64] = {0,};
24 /***********************************************************************
25 * GetSystemInfo [KERNELL32.404]
27 * Gets the current system information.
29 * On the first call it reads 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().
43 VOID WINAPI
GetSystemInfo(
44 LPSYSTEM_INFO si
/* [out] system information */
47 static SYSTEM_INFO cachedsi
;
51 memcpy(si
,&cachedsi
,sizeof(*si
));
54 memset(PF
,0,sizeof(PF
));
56 /* choose sensible defaults ...
57 * FIXME: perhaps overrideable with precompiler flags?
59 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
60 cachedsi
.dwPageSize
= VIRTUAL_GetPageSize();
62 /* FIXME: better values for the two entries below... */
63 cachedsi
.lpMinimumApplicationAddress
= (void *)0x40000000;
64 cachedsi
.lpMaximumApplicationAddress
= (void *)0x7FFFFFFF;
65 cachedsi
.dwActiveProcessorMask
= 1;
66 cachedsi
.dwNumberOfProcessors
= 1;
67 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
68 cachedsi
.dwAllocationGranularity
= 0x10000;
69 cachedsi
.wProcessorLevel
= 3; /* 386 */
70 cachedsi
.wProcessorRevision
= 0;
72 cache
= 1; /* even if there is no more info, we now have a cacheentry */
73 memcpy(si
,&cachedsi
,sizeof(*si
));
75 /* Hmm, reasonable processor feature defaults? */
77 /* Create this registry key for all systems */
78 if (RegCreateKey16(HKEY_LOCAL_MACHINE
,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey
)!=ERROR_SUCCESS
) {
79 WARN("Unable to register CPU information\n");
86 FILE *f
= fopen ("/proc/cpuinfo", "r");
91 while (fgets(line
,200,f
)!=NULL
) {
94 /* NOTE: the ':' is the only character we can rely on */
95 if (!(value
= strchr(line
,':')))
97 /* terminate the valuename */
99 /* skip any leading spaces */
100 while (*value
==' ') value
++;
101 if ((s
=strchr(value
,'\n')))
105 if (!lstrncmpiA(line
, "cpu family",strlen("cpu family"))) {
106 if (isdigit (value
[0])) {
107 switch (value
[0] - '0') {
108 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
109 cachedsi
.wProcessorLevel
= 3;
111 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
112 cachedsi
.wProcessorLevel
= 4;
114 case 5: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
115 cachedsi
.wProcessorLevel
= 5;
117 case 6: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
118 cachedsi
.wProcessorLevel
= 5;
124 /* set the CPU type of the current processor */
125 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
127 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
131 if (!lstrncmpiA(line
, "cpu",strlen("cpu"))) {
132 if ( isdigit (value
[0]) && value
[1] == '8' &&
133 value
[2] == '6' && value
[3] == 0
135 switch (value
[0] - '0') {
136 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
137 cachedsi
.wProcessorLevel
= 3;
139 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
140 cachedsi
.wProcessorLevel
= 4;
142 case 5: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
143 cachedsi
.wProcessorLevel
= 5;
145 case 6: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
146 cachedsi
.wProcessorLevel
= 5;
152 /* set the CPU type of the current processor */
153 sprintf(buf
,"CPU %ld",cachedsi
.dwProcessorType
);
155 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,buf
,strlen(buf
));
158 if (!lstrncmpiA(line
,"fdiv_bug",strlen("fdiv_bug"))) {
159 if (!lstrncmpiA(value
,"yes",3))
160 PF
[PF_FLOATING_POINT_PRECISION_ERRATA
] = TRUE
;
164 if (!lstrncmpiA(line
,"fpu",strlen("fpu"))) {
165 if (!lstrncmpiA(value
,"no",2))
166 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
170 if (!lstrncmpiA(line
,"processor",strlen("processor"))) {
171 /* processor number counts up...*/
174 if (sscanf(value
,"%d",&x
))
175 if (x
+1>cachedsi
.dwNumberOfProcessors
)
176 cachedsi
.dwNumberOfProcessors
=x
+1;
178 /* Create a new processor subkey on a multiprocessor
184 RegCreateKey16(hkey
,buf
,&xhkey
);
186 if (!lstrncmpiA(line
,"stepping",strlen("stepping"))) {
189 if (sscanf(value
,"%d",&x
))
190 cachedsi
.wProcessorRevision
= x
;
192 if (!lstrncmpiA(line
,"flags",strlen("flags"))) {
193 if (strstr(value
,"cx8"))
194 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
195 if (strstr(value
,"mmx"))
196 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
202 memcpy(si
,&cachedsi
,sizeof(*si
));
204 /* FIXME: how do we do this on other systems? */
206 RegCreateKey16(hkey
,"0",&xhkey
);
207 RegSetValueExA(xhkey
,"Identifier",0,REG_SZ
,"CPU 386",strlen("CPU 386"));
216 /***********************************************************************
217 * IsProcessorFeaturePresent [KERNELL32.880]
219 * TRUE if processorfeature present
222 BOOL WINAPI
IsProcessorFeaturePresent (
223 DWORD feature
/* [in] feature number, see PF_ defines */
226 GetSystemInfo (&si
); /* To ensure the information is loaded and cached */