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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
25 #ifdef HAVE_SYS_PARAM_H
26 # include <sys/param.h>
28 #ifdef HAVE_SYS_SYSCTL_H
29 # include <sys/sysctl.h>
31 #ifdef HAVE_MACHINE_CPU_H
32 # include <machine/cpu.h>
34 #ifdef HAVE_MACH_MACHINE_H
35 # include <mach/machine.h>
43 #ifdef HAVE_SYS_TIME_H
44 # include <sys/time.h>
48 #define NONAMELESSUNION
49 #define NONAMELESSSTRUCT
54 #include "wine/unicode.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(reg);
59 #define AUTH 0x68747541 /* "Auth" */
60 #define ENTI 0x69746e65 /* "enti" */
61 #define CAMD 0x444d4163 /* "cAMD" */
63 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
64 * We are compiled with -fPIC, so we can't clobber ebx.
66 static inline void do_cpuid(unsigned int ax, unsigned int *p)
69 __asm__("pushl %%ebx\n\t"
71 "movl %%ebx, %%esi\n\t"
73 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
78 /* From xf86info havecpuid.c 1.11 */
79 static inline int have_cpuid(void)
93 : "=&r" (f1), "=&r" (f2)
95 return ((f1^f2) & 0x00200000) != 0;
101 static BYTE PF[64] = {0,};
102 static ULONGLONG cpuHz = 1000000000; /* default to a 1GHz */
104 static void create_system_registry_keys( const SYSTEM_INFO *info )
106 static const WCHAR SystemW[] = {'M','a','c','h','i','n','e','\\',
107 'H','a','r','d','w','a','r','e','\\',
108 'D','e','s','c','r','i','p','t','i','o','n','\\',
109 'S','y','s','t','e','m',0};
110 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};
111 static const WCHAR cpuW[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
112 static const WCHAR IdentifierW[] = {'I','d','e','n','t','i','f','i','e','r',0};
113 static const WCHAR SysidW[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
114 static const WCHAR mhzKeyW[] = {'~','M','H','z',0};
115 static const WCHAR VendorIdentifierW[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
116 static const WCHAR VenidIntelW[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
117 /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
120 HANDLE hkey, system_key, cpu_key;
121 OBJECT_ATTRIBUTES attr;
122 UNICODE_STRING nameW, valueW;
124 attr.Length = sizeof(attr);
125 attr.RootDirectory = 0;
126 attr.ObjectName = &nameW;
128 attr.SecurityDescriptor = NULL;
129 attr.SecurityQualityOfService = NULL;
131 RtlInitUnicodeString( &nameW, SystemW );
132 if (NtCreateKey( &system_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
134 RtlInitUnicodeString( &valueW, IdentifierW );
135 NtSetValueKey( system_key, &valueW, 0, REG_SZ, SysidW, sizeof(SysidW) );
137 attr.RootDirectory = system_key;
138 RtlInitUnicodeString( &nameW, fpuW );
139 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) NtClose( hkey );
141 RtlInitUnicodeString( &nameW, cpuW );
142 if (!NtCreateKey( &cpu_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
144 for (i = 0; i < info->dwNumberOfProcessors; i++)
146 char num[10], id[60];
148 attr.RootDirectory = cpu_key;
149 sprintf( num, "%d", i );
150 RtlCreateUnicodeStringFromAsciiz( &nameW, num );
151 if (!NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ))
155 DWORD cpuMHz = cpuHz / 1000000;
157 /*TODO: report 64bit processors properly*/
158 RtlInitUnicodeString( &valueW, IdentifierW );
159 sprintf( id, "x86 Family %d Model %d Stepping %d",
160 info->wProcessorLevel, HIBYTE(info->wProcessorRevision), LOBYTE(info->wProcessorRevision) );
162 RtlMultiByteToUnicodeN( idW, sizeof(idW), &sizeW, id, strlen(id)+1 );
163 NtSetValueKey( hkey, &valueW, 0, REG_SZ, idW, sizeW );
165 /*TODO; report amd's properly*/
166 RtlInitUnicodeString( &valueW, VendorIdentifierW );
167 NtSetValueKey( hkey, &valueW, 0, REG_SZ, VenidIntelW, sizeof(VenidIntelW) );
169 RtlInitUnicodeString( &valueW, mhzKeyW );
170 NtSetValueKey( hkey, &valueW, 0, REG_DWORD, &cpuMHz, sizeof(DWORD) );
173 RtlFreeUnicodeString( &nameW );
177 NtClose( system_key );
180 static void create_env_registry_keys( const SYSTEM_INFO *info )
182 static const WCHAR EnvironW[] = {'M','a','c','h','i','n','e','\\',
183 'S','y','s','t','e','m','\\',
184 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
185 'C','o','n','t','r','o','l','\\',
186 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
187 'E','n','v','i','r','o','n','m','e','n','t',0};
188 static const WCHAR NumProcW[] = {'N','U','M','B','E','R','_','O','F','_','P','R','O','C','E','S','S','O','R','S',0};
189 static const WCHAR ProcArchW[] = {'P','R','O','C','E','S','S','O','R','_','A','R','C','H','I','T','E','C','T','U','R','E',0};
190 static const WCHAR x86W[] = {'x','8','6',0};
191 static const WCHAR ProcIdW[] = {'P','R','O','C','E','S','S','O','R','_','I','D','E','N','T','I','F','I','E','R',0};
192 static const WCHAR ProcLvlW[] = {'P','R','O','C','E','S','S','O','R','_','L','E','V','E','L',0};
193 static const WCHAR ProcRevW[] = {'P','R','O','C','E','S','S','O','R','_','R','E','V','I','S','I','O','N',0};
196 OBJECT_ATTRIBUTES attr;
197 UNICODE_STRING nameW, valueW;
200 char nProc[10],id[60],procLevel[10],rev[10];
201 WCHAR nProcW[10],idW[60],procLevelW[10],revW[10];
203 /* Create some keys under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.
204 * All these environment variables are processor related and will be read during process initialization and hence
205 * show up in the environment of that process.
208 attr.Length = sizeof(attr);
209 attr.RootDirectory = 0;
210 attr.ObjectName = &nameW;
212 attr.SecurityDescriptor = NULL;
213 attr.SecurityQualityOfService = NULL;
215 RtlInitUnicodeString( &nameW, EnvironW );
216 if (NtCreateKey( &env_key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL )) return;
218 sprintf( nProc, "%d", info->dwNumberOfProcessors );
219 RtlMultiByteToUnicodeN( nProcW, sizeof(nProcW), &sizeW, nProc, strlen(nProc)+1 );
220 RtlInitUnicodeString( &valueW, NumProcW );
221 NtSetValueKey( env_key, &valueW, 0, REG_SZ, nProcW, sizeW );
223 /* TODO: currently hardcoded x86, add different processors */
224 RtlInitUnicodeString( &valueW, ProcArchW );
225 NtSetValueKey( env_key, &valueW, 0, REG_SZ, x86W, sizeof(x86W) );
227 /* TODO: currently hardcoded Intel, add different processors */
228 sprintf( id, "x86 Family %d Model %d Stepping %d, GenuineIntel",
229 info->wProcessorLevel, HIBYTE(info->wProcessorRevision), LOBYTE(info->wProcessorRevision) );
230 RtlMultiByteToUnicodeN( idW, sizeof(idW), &sizeW, id, strlen(id)+1 );
231 RtlInitUnicodeString( &valueW, ProcIdW );
232 NtSetValueKey( env_key, &valueW, 0, REG_SZ, idW, sizeW );
234 sprintf( procLevel, "%d", info->wProcessorLevel );
235 RtlMultiByteToUnicodeN( procLevelW, sizeof(procLevelW), &sizeW, procLevel, strlen(procLevel)+1 );
236 RtlInitUnicodeString( &valueW, ProcLvlW );
237 NtSetValueKey( env_key, &valueW, 0, REG_SZ, procLevelW, sizeW );
239 /* Properly report model/stepping */
240 sprintf( rev, "%04x", info->wProcessorRevision);
241 RtlMultiByteToUnicodeN( revW, sizeof(revW), &sizeW, rev, strlen(rev)+1 );
242 RtlInitUnicodeString( &valueW, ProcRevW );
243 NtSetValueKey( env_key, &valueW, 0, REG_SZ, revW, sizeW );
248 static inline void get_cpuinfo( SYSTEM_INFO *info )
250 unsigned int regs[4], regs2[4];
252 if (!have_cpuid()) return;
254 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
255 if (regs[0]>=0x00000001) /* Check for supported cpuid version */
257 do_cpuid(0x00000001, regs2); /* get cpu features */
258 switch ((regs2[0] >> 8) & 0xf) /* cpu family */
261 info->dwProcessorType = PROCESSOR_INTEL_386;
262 info->wProcessorLevel = 3;
265 info->dwProcessorType = PROCESSOR_INTEL_486;
266 info->wProcessorLevel = 4;
269 info->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
270 info->wProcessorLevel = 5;
273 case 15: /* PPro/2/3/4 has same info as P1 */
274 info->dwProcessorType = PROCESSOR_INTEL_PENTIUM;
275 info->wProcessorLevel = 6;
278 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
279 (regs2[0] >> 8)&0xf);
282 PF[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
283 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
284 PF[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
285 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
287 if (regs[1] == AUTH &&
290 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
291 if (regs[0]>=0x80000001) {
292 do_cpuid(0x80000001, regs2); /* get vendor features */
293 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 31 )) >> 31;
299 /****************************************************************************
300 * QueryPerformanceCounter (KERNEL32.@)
302 * Get the current value of the performance counter.
305 * counter [O] Destination for the current counter reading
308 * Success: TRUE. counter contains the current reading
312 * See QueryPerformanceFrequency.
314 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
316 NtQueryPerformanceCounter( counter, NULL );
321 /****************************************************************************
322 * QueryPerformanceFrequency (KERNEL32.@)
324 * Get the resolution of the performance counter.
327 * frequency [O] Destination for the counter resolution
330 * Success. TRUE. Frequency contains the resolution of the counter.
334 * See QueryPerformanceCounter.
336 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
338 LARGE_INTEGER counter;
339 NtQueryPerformanceCounter( &counter, frequency );
344 /***********************************************************************
345 * GetSystemInfo [KERNEL32.@]
347 * Get information about the system.
353 * On the first call it creates cached values, so it doesn't have to determine
354 * them repeatedly. On Linux, the "/proc/cpuinfo" special file is used.
356 * It creates a registry subhierarchy, looking like:
357 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
358 * Note that there is a hierarchy for every processor installed, so this
359 * supports multiprocessor systems. This is done like Win95 does it, I think.
361 * It creates some registry entries in the environment part:
362 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
363 * always present. When deleted, Windows will add them again.
365 * It also creates a cached flag array for IsProcessorFeaturePresent().
367 VOID WINAPI GetSystemInfo(
368 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
370 static int cache = 0;
371 static SYSTEM_INFO cachedsi;
372 SYSTEM_BASIC_INFORMATION sbi;
374 TRACE("si=0x%p\n", si);
379 memset(PF,0,sizeof(PF));
381 NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL );
382 cachedsi.dwPageSize = sbi.uPageSize;
383 cachedsi.lpMinimumApplicationAddress = sbi.pLowestUserAddress;
384 cachedsi.lpMaximumApplicationAddress = sbi.pMmHighestUserAddress;
385 cachedsi.dwNumberOfProcessors = sbi.uKeActiveProcessors;
386 cachedsi.dwAllocationGranularity = sbi.uAllocationGranularity;
388 /* choose sensible defaults ...
389 * FIXME: perhaps overridable with precompiler flags?
391 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
392 cachedsi.dwActiveProcessorMask = 0;
393 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
394 cachedsi.wProcessorLevel = 5; /* 586 */
395 cachedsi.wProcessorRevision = 0;
397 cache = 1; /* even if there is no more info, we now have a cache entry */
400 /* Hmm, reasonable processor feature defaults? */
405 FILE *f = fopen ("/proc/cpuinfo", "r");
409 while (fgets(line,200,f)!=NULL) {
412 /* NOTE: the ':' is the only character we can rely on */
413 if (!(value = strchr(line,':')))
416 /* terminate the valuename */
418 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
421 /* and strip leading spaces from value */
423 while (*value==' ') value++;
424 if ((s=strchr(value,'\n')))
427 if (!strcasecmp(line,"processor")) {
428 /* processor number counts up... */
431 if (sscanf(value,"%d",&x))
432 if (x+1>cachedsi.dwNumberOfProcessors)
433 cachedsi.dwNumberOfProcessors=x+1;
437 if (!strcasecmp(line,"model")) {
438 /* First part of wProcessorRevision */
441 if (sscanf(value,"%d",&x))
442 cachedsi.wProcessorRevision = cachedsi.wProcessorRevision | (x << 8);
448 if (!strcasecmp(line, "cpu family")) {
449 if (isdigit (value[0])) {
450 switch (value[0] - '0') {
451 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
452 cachedsi.wProcessorLevel= 3;
454 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
455 cachedsi.wProcessorLevel= 4;
457 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
458 cachedsi.wProcessorLevel= 5;
462 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
463 cachedsi.wProcessorLevel = atoi(value);
470 if (!strcasecmp(line, "cpu")) {
471 if ( isdigit (value[0]) && value[1] == '8' &&
472 value[2] == '6' && value[3] == 0
474 switch (value[0] - '0') {
475 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
476 cachedsi.wProcessorLevel= 3;
478 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
479 cachedsi.wProcessorLevel= 4;
481 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
482 cachedsi.wProcessorLevel= 5;
484 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
485 cachedsi.wProcessorLevel= 6;
488 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
494 if (!strcasecmp(line,"stepping")) {
495 /* Second part of wProcessorRevision */
498 if (sscanf(value,"%d",&x))
499 cachedsi.wProcessorRevision = cachedsi.wProcessorRevision | x;
503 if (!strcasecmp(line, "cpu MHz")) {
505 if (sscanf( value, "%lf", &cmz ) == 1) {
506 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
507 cpuHz = cmz * 1000 * 1000;
511 if (!strcasecmp(line,"fdiv_bug")) {
512 if (!strncasecmp(value,"yes",3))
513 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
517 if (!strcasecmp(line,"fpu")) {
518 if (!strncasecmp(value,"no",2))
519 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
523 if ( !strcasecmp(line,"flags") ||
524 !strcasecmp(line,"features")) {
525 if (strstr(value,"cx8"))
526 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
527 if (strstr(value,"mmx"))
528 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
529 if (strstr(value,"tsc"))
530 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
531 if (strstr(value,"3dnow"))
532 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
533 /* This will also catch sse2, but we have sse itself
534 * if we have sse2, so no problem */
535 if (strstr(value,"sse"))
536 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
537 if (strstr(value,"sse2"))
538 PF[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
539 if (strstr(value,"pae"))
540 PF[PF_PAE_ENABLED] = TRUE;
547 #elif defined (__NetBSD__)
554 FILE *f = fopen ("/var/run/dmesg.boot", "r");
556 /* first deduce as much as possible from the sysctls */
557 mib[0] = CTL_MACHDEP;
558 #ifdef CPU_FPU_PRESENT
559 mib[1] = CPU_FPU_PRESENT;
560 val_len = sizeof(value);
561 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
562 PF[PF_FLOATING_POINT_EMULATED] = !value;
565 mib[1] = CPU_SSE; /* this should imply MMX */
566 val_len = sizeof(value);
567 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
568 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
571 mib[1] = CPU_SSE2; /* this should imply MMX */
572 val_len = sizeof(value);
573 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
574 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
578 val_len = sizeof(value);
579 if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
580 if (value > cachedsi.dwNumberOfProcessors)
581 cachedsi.dwNumberOfProcessors = value;
583 val_len = sizeof(model)-1;
584 if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0) {
585 model[val_len] = '\0'; /* just in case */
586 cpuclass = strstr(model, "-class");
587 if (cpuclass != NULL) {
588 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
589 if (!strncmp(cpuclass+1, "386", 3)) {
590 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
591 cachedsi.wProcessorLevel= 3;
593 if (!strncmp(cpuclass+1, "486", 3)) {
594 cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
595 cachedsi.wProcessorLevel= 4;
597 if (!strncmp(cpuclass+1, "586", 3)) {
598 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
599 cachedsi.wProcessorLevel= 5;
601 if (!strncmp(cpuclass+1, "686", 3)) {
602 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
603 cachedsi.wProcessorLevel= 6;
604 /* this should imply MMX */
605 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
610 /* it may be worth reading from /var/run/dmesg.boot for
611 additional information such as CX8, MMX and TSC
612 (however this information should be considered less
613 reliable than that from the sysctl calls) */
616 while (fgets(model, 255, f) != NULL) {
618 if (sscanf(model,"cpu%d: features %x<", &cpu, &features) == 2) {
619 /* we could scan the string but it is easier
620 to test the bits directly */
622 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
624 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
625 if (features & 0x100)
626 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
627 if (features & 0x800000)
628 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
637 #elif defined(__FreeBSD__)
642 get_cpuinfo( &cachedsi );
644 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
646 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
648 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
651 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
653 cachedsi.dwNumberOfProcessors = num;
657 int num = sysconf( _SC_NPROCESSORS_ONLN );
659 if (num == -1) num = 1;
660 get_cpuinfo( &cachedsi );
661 cachedsi.dwNumberOfProcessors = num;
663 #elif defined (__APPLE__)
666 unsigned long long longVal;
671 valSize = sizeof(int);
672 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
675 PF[PF_FLOATING_POINT_EMULATED] = FALSE;
677 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
679 valSize = sizeof(int);
680 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
681 cachedsi.dwNumberOfProcessors = value;
683 valSize = sizeof(int);
684 if (sysctlbyname ("hw.activecpu", &value, &valSize, NULL, 0) == 0)
685 cachedsi.dwActiveProcessorMask = ((ULONG_PTR)1 << value) - 1;
687 valSize = sizeof(int);
688 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
692 case CPU_TYPE_POWERPC:
693 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_PPC;
694 valSize = sizeof(int);
695 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
699 case CPU_SUBTYPE_POWERPC_601:
700 case CPU_SUBTYPE_POWERPC_602:
701 cachedsi.dwProcessorType = PROCESSOR_PPC_601;
702 cachedsi.wProcessorLevel = 1;
704 case CPU_SUBTYPE_POWERPC_603:
705 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
706 cachedsi.wProcessorLevel = 3;
708 case CPU_SUBTYPE_POWERPC_603e:
709 case CPU_SUBTYPE_POWERPC_603ev:
710 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
711 cachedsi.wProcessorLevel = 6;
713 case CPU_SUBTYPE_POWERPC_604:
714 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
715 cachedsi.wProcessorLevel = 4;
717 case CPU_SUBTYPE_POWERPC_604e:
718 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
719 cachedsi.wProcessorLevel = 9;
721 case CPU_SUBTYPE_POWERPC_620:
722 cachedsi.dwProcessorType = PROCESSOR_PPC_620;
723 cachedsi.wProcessorLevel = 20;
725 case CPU_SUBTYPE_POWERPC_750:
726 case CPU_SUBTYPE_POWERPC_7400:
727 case CPU_SUBTYPE_POWERPC_7450:
728 /* G3/G4 derive from 603 so ... */
729 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
730 cachedsi.wProcessorLevel = 6;
732 case CPU_SUBTYPE_POWERPC_970:
733 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
734 cachedsi.wProcessorLevel = 9;
735 /* :o) PF[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
740 break; /* CPU_TYPE_POWERPC */
742 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
743 valSize = sizeof(int);
744 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
746 cachedsi.wProcessorLevel = value;
749 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; break;
750 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; break;
751 default: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
754 valSize = sizeof(int);
755 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
756 cachedsi.wProcessorRevision = (value << 8);
757 valSize = sizeof(int);
758 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
759 cachedsi.wProcessorRevision |= value;
760 valSize = sizeof(buffer);
761 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
763 cachedsi.wProcessorRevision |= value;
764 if (strstr(buffer,"CX8")) PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
765 if (strstr(buffer,"MMX")) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
766 if (strstr(buffer,"TSC")) PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
767 if (strstr(buffer,"3DNOW")) PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
768 if (strstr(buffer,"SSE")) PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
769 if (strstr(buffer,"SSE2")) PF[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
770 if (strstr(buffer,"PAE")) PF[PF_PAE_ENABLED] = TRUE;
772 break; /* CPU_TYPE_I386 */
774 } /* switch (cputype) */
776 valSize = sizeof(longVal);
777 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
781 FIXME("not yet supported on this system\n");
783 if (!cachedsi.dwActiveProcessorMask)
784 cachedsi.dwActiveProcessorMask = ((ULONG_PTR)1 << cachedsi.dwNumberOfProcessors) - 1;
788 TRACE("<- CPU arch %d, res'd %d, pagesize %d, minappaddr %p, maxappaddr %p,"
789 " act.cpumask %lx, numcpus %d, CPU type %d, allocgran. %d, CPU level %d, CPU rev %d\n",
790 si->u.s.wProcessorArchitecture, si->u.s.wReserved, si->dwPageSize,
791 si->lpMinimumApplicationAddress, si->lpMaximumApplicationAddress,
792 si->dwActiveProcessorMask, si->dwNumberOfProcessors, si->dwProcessorType,
793 si->dwAllocationGranularity, si->wProcessorLevel, si->wProcessorRevision);
795 create_system_registry_keys( &cachedsi );
796 create_env_registry_keys( &cachedsi );
800 /***********************************************************************
801 * GetNativeSystemInfo [KERNEL32.@]
803 VOID WINAPI GetNativeSystemInfo(
804 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
806 static BOOL reported = FALSE;
808 FIXME("(%p) using GetSystemInfo()\n", si);
811 TRACE("(%p) using GetSystemInfo()\n", si);
815 /***********************************************************************
816 * IsProcessorFeaturePresent [KERNEL32.@]
818 * Determine if the cpu supports a given feature.
821 * TRUE, If the processor supports feature,
824 BOOL WINAPI IsProcessorFeaturePresent (
825 DWORD feature /* [in] Feature number, (PF_ constants from "winnt.h") */)
828 GetSystemInfo (&si); /* To ensure the information is loaded and cached */