4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(reg);
40 static BYTE PF[64] = {0,};
42 static void create_registry_keys( const SYSTEM_INFO *info )
44 static const WCHAR SystemW[] = {'M','a','c','h','i','n','e','\\',
45 'H','a','r','d','w','a','r','e','\\',
46 'D','e','s','c','r','i','p','t','i','o','n','\\',
47 'S','y','s','t','e','m',0};
48 static const WCHAR fpuW[] = {'F','l','o','a','t','i','n','g','P','o','i','n','t','P','r','o','c','e','s','s','o','r',0};
49 static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
50 static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
51 static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
54 HKEY hkey, system_key, cpu_key;
55 OBJECT_ATTRIBUTES attr;
56 UNICODE_STRING nameW, valueW;
58 attr.Length = sizeof(attr);
59 attr.RootDirectory = 0;
60 attr.ObjectName = &nameW;
62 attr.SecurityDescriptor = NULL;
63 attr.SecurityQualityOfService = NULL;
65 RtlInitUnicodeString( &nameW, SystemW );
66 if (NtCreateKey( &system_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
68 RtlInitUnicodeString( &valueW, IdentifierW );
69 NtSetValueKey( system_key, &valueW, 0, REG_SZ, SysidW, (strlenW(SysidW)+1) * sizeof(WCHAR) );
71 attr.RootDirectory = system_key;
72 RtlInitUnicodeString( &nameW, fpuW );
73 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) NtClose( hkey );
75 RtlInitUnicodeString( &nameW, cpuW );
76 if (!NtCreateKey( &cpu_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
78 for (i = 0; i < info->dwNumberOfProcessors; i++)
82 attr.RootDirectory = cpu_key;
83 sprintf( num, "%d", i );
84 RtlCreateUnicodeStringFromAsciiz( &nameW, num );
85 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
89 sprintf( id, "CPU %ld", info->dwProcessorType );
90 RtlMultiByteToUnicodeN( idW, sizeof(idW), NULL, id, strlen(id)+1 );
91 NtSetValueKey( hkey, &valueW, 0, REG_SZ, idW, (strlenW(idW)+1)*sizeof(WCHAR) );
94 RtlFreeUnicodeString( &nameW );
98 NtClose( system_key );
102 /***********************************************************************
103 * GetSystemInfo [KERNEL32.@]
105 * Gets the current system information.
107 * On the first call it creates cached values, so it doesn't have to determine
108 * them repeatedly. On Linux, the /proc/cpuinfo special file is used.
110 * It creates a registry subhierarchy, looking like:
111 * \HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\
112 * Identifier (CPU x86)
113 * Note that there is a hierarchy for every processor installed, so this
114 * supports multiprocessor systems. This is done like Win95 does it, I think.
116 * It also creates a cached flag array for IsProcessorFeaturePresent().
118 * No NULL ptr check for LPSYSTEM_INFO in Win9x.
123 VOID WINAPI GetSystemInfo(
124 LPSYSTEM_INFO si /* [out] system information */
126 static int cache = 0;
127 static SYSTEM_INFO cachedsi;
130 memcpy(si,&cachedsi,sizeof(*si));
133 memset(PF,0,sizeof(PF));
135 /* choose sensible defaults ...
136 * FIXME: perhaps overrideable with precompiler flags?
138 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
139 cachedsi.dwPageSize = getpagesize();
141 /* FIXME: the two entries below should be computed somehow... */
142 cachedsi.lpMinimumApplicationAddress = (void *)0x00010000;
143 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
144 cachedsi.dwActiveProcessorMask = 1;
145 cachedsi.dwNumberOfProcessors = 1;
146 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
147 cachedsi.dwAllocationGranularity = 0x10000;
148 cachedsi.wProcessorLevel = 5; /* 586 */
149 cachedsi.wProcessorRevision = 0;
151 cache = 1; /* even if there is no more info, we now have a cacheentry */
152 memcpy(si,&cachedsi,sizeof(*si));
154 /* Hmm, reasonable processor feature defaults? */
159 FILE *f = fopen ("/proc/cpuinfo", "r");
163 while (fgets(line,200,f)!=NULL) {
166 /* NOTE: the ':' is the only character we can rely on */
167 if (!(value = strchr(line,':')))
169 /* terminate the valuename */
171 /* skip any leading spaces */
172 while (*value==' ') value++;
173 if ((s=strchr(value,'\n')))
177 if (!strncasecmp(line, "cpu family",strlen("cpu family"))) {
178 if (isdigit (value[0])) {
179 switch (value[0] - '0') {
180 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
181 cachedsi.wProcessorLevel= 3;
183 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
184 cachedsi.wProcessorLevel= 4;
187 case 6: /* PPro/2/3 has same info as P1 */
188 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
189 cachedsi.wProcessorLevel= 5;
191 case 1: /* two-figure levels */
194 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
195 cachedsi.wProcessorLevel= 5;
200 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value);
207 if (!strncasecmp(line, "cpu",strlen("cpu"))) {
208 if ( isdigit (value[0]) && value[1] == '8' &&
209 value[2] == '6' && value[3] == 0
211 switch (value[0] - '0') {
212 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
213 cachedsi.wProcessorLevel= 3;
215 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
216 cachedsi.wProcessorLevel= 4;
219 case 6: /* PPro/2/3 has same info as P1 */
220 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
221 cachedsi.wProcessorLevel= 5;
224 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
230 if (!strncasecmp(line,"fdiv_bug",strlen("fdiv_bug"))) {
231 if (!strncasecmp(value,"yes",3))
232 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
236 if (!strncasecmp(line,"fpu",strlen("fpu"))) {
237 if (!strncasecmp(value,"no",2))
238 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
242 if (!strncasecmp(line,"processor",strlen("processor"))) {
243 /* processor number counts up... */
246 if (sscanf(value,"%d",&x))
247 if (x+1>cachedsi.dwNumberOfProcessors)
248 cachedsi.dwNumberOfProcessors=x+1;
250 if (!strncasecmp(line,"stepping",strlen("stepping"))) {
253 if (sscanf(value,"%d",&x))
254 cachedsi.wProcessorRevision = x;
256 if ( !strncasecmp(line,"flags",strlen("flags")) ||
257 !strncasecmp(line,"features",strlen("features"))
259 if (strstr(value,"cx8"))
260 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
261 if (strstr(value,"mmx"))
262 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
263 if (strstr(value,"tsc"))
264 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
270 memcpy(si,&cachedsi,sizeof(*si));
272 FIXME("not yet supported on this system\n");
274 TRACE("<- CPU arch %d, res'd %d, pagesize %ld, minappaddr %p, maxappaddr %p,"
275 " act.cpumask %08lx, numcpus %ld, CPU type %ld, allocgran. %ld, CPU level %d, CPU rev %d\n",
276 si->u.s.wProcessorArchitecture, si->u.s.wReserved, si->dwPageSize,
277 si->lpMinimumApplicationAddress, si->lpMaximumApplicationAddress,
278 si->dwActiveProcessorMask, si->dwNumberOfProcessors, si->dwProcessorType,
279 si->dwAllocationGranularity, si->wProcessorLevel, si->wProcessorRevision);
281 create_registry_keys( &cachedsi );
285 /***********************************************************************
286 * IsProcessorFeaturePresent [KERNEL32.@]
288 * TRUE if processor feature present
291 BOOL WINAPI IsProcessorFeaturePresent (
292 DWORD feature /* [in] feature number, see PF_ defines */
295 GetSystemInfo (&si); /* To ensure the information is loaded and cached */