4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
12 #include "wine/port.h"
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(reg);
21 static BYTE PF[64] = {0,};
23 /***********************************************************************
24 * GetSystemInfo [KERNEL32.@]
26 * Gets the current system information.
28 * On the first call it creates cached values, so it doesn't have to determine
29 * them repeatedly. On Linux, the /proc/cpuinfo special file is used.
31 * It creates a registry subhierarchy, looking like:
32 * \HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\
33 * Identifier (CPU x86)
34 * Note that there is a hierarchy for every processor installed, so this
35 * supports multiprocessor systems. This is done like Win95 does it, I think.
37 * It also creates a cached flag array for IsProcessorFeaturePresent().
39 * No NULL ptr check for LPSYSTEM_INFO in Win9x.
44 VOID WINAPI GetSystemInfo(
45 LPSYSTEM_INFO si /* [out] system information */
48 static SYSTEM_INFO cachedsi;
52 memcpy(si,&cachedsi,sizeof(*si));
55 memset(PF,0,sizeof(PF));
57 /* choose sensible defaults ...
58 * FIXME: perhaps overrideable with precompiler flags?
60 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
61 cachedsi.dwPageSize = getpagesize();
63 /* FIXME: the two entries below should be computed somehow... */
64 cachedsi.lpMinimumApplicationAddress = (void *)0x00010000;
65 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
66 cachedsi.dwActiveProcessorMask = 1;
67 cachedsi.dwNumberOfProcessors = 1;
68 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
69 cachedsi.dwAllocationGranularity = 0x10000;
70 cachedsi.wProcessorLevel = 3; /* 386 */
71 cachedsi.wProcessorRevision = 0;
73 cache = 1; /* even if there is no more info, we now have a cacheentry */
74 memcpy(si,&cachedsi,sizeof(*si));
76 /* Hmm, reasonable processor feature defaults? */
78 /* Create these registry keys for all systems
79 * FPU entry is often empty on Windows, so we don't care either */
80 if ( (RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\FloatingPointProcessor",&hkey)!=ERROR_SUCCESS)
81 || (RegCreateKeyA(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) )
83 WARN("Unable to write FPU/CPU info to registry\n");
90 FILE *f = fopen ("/proc/cpuinfo", "r");
95 while (fgets(line,200,f)!=NULL) {
98 /* NOTE: the ':' is the only character we can rely on */
99 if (!(value = strchr(line,':')))
101 /* terminate the valuename */
103 /* skip any leading spaces */
104 while (*value==' ') value++;
105 if ((s=strchr(value,'\n')))
109 if (!strncasecmp(line, "cpu family",strlen("cpu family"))) {
110 if (isdigit (value[0])) {
111 switch (value[0] - '0') {
112 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
113 cachedsi.wProcessorLevel= 3;
115 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
116 cachedsi.wProcessorLevel= 4;
119 case 6: /* PPro/2/3 has same info as P1 */
120 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
121 cachedsi.wProcessorLevel= 5;
123 case 1: /* two-figure levels */
126 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
127 cachedsi.wProcessorLevel= 5;
132 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value);
136 /* set the CPU type of the current processor */
137 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
139 RegSetValueExA(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
143 if (!strncasecmp(line, "cpu",strlen("cpu"))) {
144 if ( isdigit (value[0]) && value[1] == '8' &&
145 value[2] == '6' && value[3] == 0
147 switch (value[0] - '0') {
148 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
149 cachedsi.wProcessorLevel= 3;
151 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
152 cachedsi.wProcessorLevel= 4;
155 case 6: /* PPro/2/3 has same info as P1 */
156 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
157 cachedsi.wProcessorLevel= 5;
160 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
164 /* set the CPU type of the current processor
165 * FIXME: someone reported P4 as being set to
166 * " Intel(R) Pentium(R) 4 CPU 1500MHz"
167 * Do we need to do the same ?
169 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
171 RegSetValueExA(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
174 if (!strncasecmp(line,"fdiv_bug",strlen("fdiv_bug"))) {
175 if (!strncasecmp(value,"yes",3))
176 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
180 if (!strncasecmp(line,"fpu",strlen("fpu"))) {
181 if (!strncasecmp(value,"no",2))
182 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
186 if (!strncasecmp(line,"processor",strlen("processor"))) {
187 /* processor number counts up... */
190 if (sscanf(value,"%d",&x))
191 if (x+1>cachedsi.dwNumberOfProcessors)
192 cachedsi.dwNumberOfProcessors=x+1;
194 /* Create a new processor subkey on a multiprocessor
200 RegCreateKeyA(hkey,buf,&xhkey);
202 if (!strncasecmp(line,"stepping",strlen("stepping"))) {
205 if (sscanf(value,"%d",&x))
206 cachedsi.wProcessorRevision = x;
208 if ( !strncasecmp(line,"flags",strlen("flags")) ||
209 !strncasecmp(line,"features",strlen("features"))
211 if (strstr(value,"cx8"))
212 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
213 if (strstr(value,"mmx"))
214 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
215 if (strstr(value,"tsc"))
216 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
222 memcpy(si,&cachedsi,sizeof(*si));
224 /* FIXME: how do we do this on other systems? */
226 RegCreateKeyA(hkey,"0",&xhkey);
227 RegSetValueExA(xhkey,"Identifier",0,REG_SZ,"CPU 386",strlen("CPU 386"));
236 /***********************************************************************
237 * IsProcessorFeaturePresent [KERNEL32.@]
239 * TRUE if processor feature present
242 BOOL WINAPI IsProcessorFeaturePresent (
243 DWORD feature /* [in] feature number, see PF_ defines */
246 GetSystemInfo (&si); /* To ensure the information is loaded and cached */