4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
17 static BYTE PF[64] = {0,};
19 /***********************************************************************
20 * GetSystemInfo [KERNELL32.404]
22 * Gets the current system information.
24 * On the first call it reads cached values, so it doesn't have to determine
25 * them repeatedly. On Linux, the /proc/cpuinfo special file is used.
27 * It creates a registry subhierarchy, looking like:
28 * \HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\
29 * Identifier (CPU x86)
30 * Note that there is a hierarchy for every processor installed, so this
31 * supports multiprocessor systems. This is done like Win95 does it, I think.
33 * It also creates a cached flag array for IsProcessorFeaturePresent().
38 VOID WINAPI GetSystemInfo(
39 LPSYSTEM_INFO si /* [out] system information */
42 static SYSTEM_INFO cachedsi;
47 memcpy(si,&cachedsi,sizeof(*si));
50 memset(PF,0,sizeof(PF));
52 /* choose sensible defaults ...
53 * FIXME: perhaps overrideable with precompiler flags?
55 cachedsi.u.x.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
56 cachedsi.dwPageSize = VIRTUAL_GetPageSize();
58 /* FIXME: better values for the two entries below... */
59 cachedsi.lpMinimumApplicationAddress = (void *)0x40000000;
60 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
61 cachedsi.dwActiveProcessorMask = 1;
62 cachedsi.dwNumberOfProcessors = 1;
63 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
64 cachedsi.dwAllocationGranularity = 0x10000;
65 cachedsi.wProcessorLevel = 3; /* 386 */
66 cachedsi.wProcessorRevision = 0;
68 cache = 1; /* even if there is no more info, we now have a cacheentry */
69 memcpy(si,&cachedsi,sizeof(*si));
71 /* Hmm, reasonable processor feature defaults? */
73 /* Create this registry key for all systems */
74 if (RegCreateKey16(HKEY_LOCAL_MACHINE,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey)!=ERROR_SUCCESS) {
75 WARN(reg,"Unable to register CPU information\n");
81 FILE *f = fopen ("/proc/cpuinfo", "r");
86 while (fgets(line,200,f)!=NULL) {
89 /* NOTE: the ':' is the only character we can rely on */
90 if (!(value = strchr(line,':')))
92 /* terminate the valuename */
94 /* skip any leading spaces */
95 while (*value==' ') value++;
96 if ((s=strchr(value,'\n')))
100 if (!lstrncmpi32A(line, "cpu family",strlen("cpu family"))) {
101 if (isdigit (value[0])) {
102 switch (value[0] - '0') {
103 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
104 cachedsi.wProcessorLevel= 3;
106 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
107 cachedsi.wProcessorLevel= 4;
109 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
110 cachedsi.wProcessorLevel= 5;
112 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
113 cachedsi.wProcessorLevel= 5;
119 /* set the CPU type of the current processor */
120 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
122 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
126 if (!lstrncmpi32A(line, "cpu",strlen("cpu"))) {
127 if ( isdigit (value[0]) && value[1] == '8' &&
128 value[2] == '6' && value[3] == 0
130 switch (value[0] - '0') {
131 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
132 cachedsi.wProcessorLevel= 3;
134 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
135 cachedsi.wProcessorLevel= 4;
137 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
138 cachedsi.wProcessorLevel= 5;
140 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
141 cachedsi.wProcessorLevel= 5;
147 /* set the CPU type of the current processor */
148 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
150 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
153 if (!lstrncmpi32A(line,"fdiv_bug",strlen("fdiv_bug"))) {
154 if (!lstrncmpi32A(value,"yes",3))
155 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
159 if (!lstrncmpi32A(line,"fpu",strlen("fpu"))) {
160 if (!lstrncmpi32A(value,"no",2))
161 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
165 if (!lstrncmpi32A(line,"processor",strlen("processor"))) {
166 /* processor number counts up...*/
169 if (sscanf(value,"%d",&x))
170 if (x+1>cachedsi.dwNumberOfProcessors)
171 cachedsi.dwNumberOfProcessors=x+1;
173 /* Create a new processor subkey on a multiprocessor
179 RegCreateKey16(hkey,buf,&xhkey);
181 if (!lstrncmpi32A(line,"stepping",strlen("stepping"))) {
184 if (sscanf(value,"%d",&x))
185 cachedsi.wProcessorRevision = x;
187 if (!lstrncmpi32A(line,"flags",strlen("flags"))) {
188 if (strstr(value,"cx8"))
189 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
190 if (strstr(value,"mmx"))
191 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
197 memcpy(si,&cachedsi,sizeof(*si));
199 /* FIXME: how do we do this on other systems? */
201 RegCreateKey16(hkey,"0",&xhkey);
202 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,"CPU 386",strlen("CPU 386"));
211 /***********************************************************************
212 * IsProcessorFeaturePresent [KERNELL32.880]
214 * TRUE if processorfeature present
217 BOOL32 WINAPI IsProcessorFeaturePresent (
218 DWORD feature /* [in] feature number, see PF_ defines */
221 GetSystemInfo (&si); /* To ensure the information is loaded and cached */