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
55 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
60 #define AUTH 0x68747541 /* "Auth" */
61 #define ENTI 0x69746e65 /* "enti" */
62 #define CAMD 0x444d4163 /* "cAMD" */
64 /* Calls cpuid with an eax of 'ax' and returns the 16 bytes in *p
65 * We are compiled with -fPIC, so we can't clobber ebx.
67 static inline void do_cpuid(unsigned int ax
, unsigned int *p
)
70 __asm__("pushl %%ebx\n\t"
72 "movl %%ebx, %%esi\n\t"
74 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
79 /* From xf86info havecpuid.c 1.11 */
80 static inline int have_cpuid(void)
94 : "=&r" (f1
), "=&r" (f2
)
96 return ((f1
^f2
) & 0x00200000) != 0;
102 static BYTE PF
[64] = {0,};
103 static ULONGLONG cpuHz
= 1000000000; /* default to a 1GHz */
105 static void create_system_registry_keys( const SYSTEM_INFO
*info
)
107 static const WCHAR SystemW
[] = {'M','a','c','h','i','n','e','\\',
108 'H','a','r','d','w','a','r','e','\\',
109 'D','e','s','c','r','i','p','t','i','o','n','\\',
110 'S','y','s','t','e','m',0};
111 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};
112 static const WCHAR cpuW
[] = {'C','e','n','t','r','a','l','P','r','o','c','e','s','s','o','r',0};
113 static const WCHAR IdentifierW
[] = {'I','d','e','n','t','i','f','i','e','r',0};
114 static const WCHAR SysidW
[] = {'A','T',' ','c','o','m','p','a','t','i','b','l','e',0};
115 static const WCHAR mhzKeyW
[] = {'~','M','H','z',0};
116 static const WCHAR VendorIdentifierW
[] = {'V','e','n','d','o','r','I','d','e','n','t','i','f','i','e','r',0};
117 static const WCHAR VenidIntelW
[] = {'G','e','n','u','i','n','e','I','n','t','e','l',0};
118 /* static const WCHAR VenidAMDW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0}; */
121 HANDLE hkey
, system_key
, cpu_key
;
122 OBJECT_ATTRIBUTES attr
;
123 UNICODE_STRING nameW
, valueW
;
125 attr
.Length
= sizeof(attr
);
126 attr
.RootDirectory
= 0;
127 attr
.ObjectName
= &nameW
;
129 attr
.SecurityDescriptor
= NULL
;
130 attr
.SecurityQualityOfService
= NULL
;
132 RtlInitUnicodeString( &nameW
, SystemW
);
133 if (NtCreateKey( &system_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
)) return;
135 RtlInitUnicodeString( &valueW
, IdentifierW
);
136 NtSetValueKey( system_key
, &valueW
, 0, REG_SZ
, SysidW
, (strlenW(SysidW
)+1) * sizeof(WCHAR
) );
138 attr
.RootDirectory
= system_key
;
139 RtlInitUnicodeString( &nameW
, fpuW
);
140 if (!NtCreateKey( &hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
)) NtClose( hkey
);
142 RtlInitUnicodeString( &nameW
, cpuW
);
143 if (!NtCreateKey( &cpu_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
))
145 for (i
= 0; i
< info
->dwNumberOfProcessors
; i
++)
147 char num
[10], id
[60];
149 attr
.RootDirectory
= cpu_key
;
150 sprintf( num
, "%d", i
);
151 RtlCreateUnicodeStringFromAsciiz( &nameW
, num
);
152 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
), NULL
, id
, strlen(id
)+1 );
163 NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, idW
, (strlenW(idW
)+1)*sizeof(WCHAR
) );
165 /*TODO; report amd's properly*/
166 RtlInitUnicodeString( &valueW
, VendorIdentifierW
);
167 NtSetValueKey( hkey
, &valueW
, 0, REG_SZ
, VenidIntelW
, (strlenW(VenidIntelW
)+1) * sizeof(WCHAR
) );
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
;
199 char nProc
[10],id
[60],procLevel
[10],rev
[10];
200 WCHAR nProcW
[10],idW
[60],procLevelW
[10],revW
[10];
202 /* Create some keys under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.
203 * All these environment variables are processor related and will be read during process initialization and hence
204 * show up in the environment of that process.
207 attr
.Length
= sizeof(attr
);
208 attr
.RootDirectory
= 0;
209 attr
.ObjectName
= &nameW
;
211 attr
.SecurityDescriptor
= NULL
;
212 attr
.SecurityQualityOfService
= NULL
;
214 RtlInitUnicodeString( &nameW
, EnvironW
);
215 if (NtCreateKey( &env_key
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
)) return;
217 sprintf( nProc
, "%d", info
->dwNumberOfProcessors
);
218 RtlMultiByteToUnicodeN( nProcW
, sizeof(nProcW
), NULL
, nProc
, strlen(nProc
)+1 );
219 RtlInitUnicodeString( &valueW
, NumProcW
);
220 NtSetValueKey( env_key
, &valueW
, 0, REG_SZ
, nProcW
, (strlenW(nProcW
)+1)*sizeof(WCHAR
) );
222 /* TODO: currently hardcoded x86, add different processors */
223 RtlInitUnicodeString( &valueW
, ProcArchW
);
224 NtSetValueKey( env_key
, &valueW
, 0, REG_SZ
, x86W
, (strlenW(x86W
)+1) * sizeof(WCHAR
) );
226 /* TODO: currently hardcoded Intel, add different processors */
227 sprintf( id
, "x86 Family %d Model %d Stepping %d, GenuineIntel",
228 info
->wProcessorLevel
, HIBYTE(info
->wProcessorRevision
), LOBYTE(info
->wProcessorRevision
) );
229 RtlMultiByteToUnicodeN( idW
, sizeof(idW
), NULL
, id
, strlen(id
)+1 );
230 RtlInitUnicodeString( &valueW
, ProcIdW
);
231 NtSetValueKey( env_key
, &valueW
, 0, REG_SZ
, idW
, (strlenW(idW
)+1)*sizeof(WCHAR
) );
233 sprintf( procLevel
, "%d", info
->wProcessorLevel
);
234 RtlMultiByteToUnicodeN( procLevelW
, sizeof(procLevelW
), NULL
, procLevel
, strlen(procLevel
)+1 );
235 RtlInitUnicodeString( &valueW
, ProcLvlW
);
236 NtSetValueKey( env_key
, &valueW
, 0, REG_SZ
, procLevelW
, (strlenW(procLevelW
)+1)*sizeof(WCHAR
) );
238 /* Properly report model/stepping */
239 sprintf( rev
, "%04x", info
->wProcessorRevision
);
240 RtlMultiByteToUnicodeN( revW
, sizeof(revW
), NULL
, rev
, strlen(rev
)+1 );
241 RtlInitUnicodeString( &valueW
, ProcRevW
);
242 NtSetValueKey( env_key
, &valueW
, 0, REG_SZ
, revW
, (strlenW(revW
)+1)*sizeof(WCHAR
) );
247 static inline void get_cpuinfo( SYSTEM_INFO
*info
)
249 unsigned int regs
[4], regs2
[4];
251 if (!have_cpuid()) return;
253 do_cpuid(0x00000000, regs
); /* get standard cpuid level and vendor name */
254 if (regs
[0]>=0x00000001) /* Check for supported cpuid version */
256 do_cpuid(0x00000001, regs2
); /* get cpu features */
257 switch ((regs2
[0] >> 8) & 0xf) /* cpu family */
260 info
->dwProcessorType
= PROCESSOR_INTEL_386
;
261 info
->wProcessorLevel
= 3;
264 info
->dwProcessorType
= PROCESSOR_INTEL_486
;
265 info
->wProcessorLevel
= 4;
268 info
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
269 info
->wProcessorLevel
= 5;
272 case 15: /* PPro/2/3/4 has same info as P1 */
273 info
->dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
274 info
->wProcessorLevel
= 6;
277 FIXME("unknown cpu family %d, please report! (-> setting to 386)\n",
278 (regs2
[0] >> 8)&0xf);
281 PF
[PF_FLOATING_POINT_EMULATED
] = !(regs2
[3] & 1);
282 PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = (regs2
[3] & (1 << 4 )) >> 4;
283 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = (regs2
[3] & (1 << 8 )) >> 8;
284 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 23)) >> 23;
286 if (regs
[1] == AUTH
&&
289 do_cpuid(0x80000000, regs
); /* get vendor cpuid level */
290 if (regs
[0]>=0x80000001) {
291 do_cpuid(0x80000001, regs2
); /* get vendor features */
292 PF
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = (regs2
[3] & (1 << 31 )) >> 31;
298 /****************************************************************************
299 * QueryPerformanceCounter (KERNEL32.@)
301 * Get the current value of the performance counter.
304 * counter [O] Destination for the current counter reading
307 * Success: TRUE. counter contains the current reading
311 * See QueryPerformanceFrequency.
313 BOOL WINAPI
QueryPerformanceCounter(PLARGE_INTEGER counter
)
315 NtQueryPerformanceCounter( counter
, NULL
);
320 /****************************************************************************
321 * QueryPerformanceFrequency (KERNEL32.@)
323 * Get the resolution of the performace counter.
326 * frequency [O] Destination for the counter resolution
329 * Success. TRUE. Frequency contains the resolution of the counter.
333 * See QueryPerformanceCounter.
335 BOOL WINAPI
QueryPerformanceFrequency(PLARGE_INTEGER frequency
)
337 LARGE_INTEGER counter
;
338 NtQueryPerformanceCounter( &counter
, frequency
);
343 /***********************************************************************
344 * GetSystemInfo [KERNEL32.@]
346 * Get information about the system.
352 * On the first call it creates cached values, so it doesn't have to determine
353 * them repeatedly. On Linux, the "/proc/cpuinfo" special file is used.
355 * It creates a registry subhierarchy, looking like:
356 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
357 * Note that there is a hierarchy for every processor installed, so this
358 * supports multiprocessor systems. This is done like Win95 does it, I think.
360 * It creates some registry entries in the environment part:
361 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
362 * always present. When deleted, Windows will add them again.
364 * It also creates a cached flag array for IsProcessorFeaturePresent().
366 VOID WINAPI
GetSystemInfo(
367 LPSYSTEM_INFO si
/* [out] Destination for system information, may not be NULL */)
369 static int cache
= 0;
370 static SYSTEM_INFO cachedsi
;
372 TRACE("si=0x%p\n", si
);
374 memcpy(si
,&cachedsi
,sizeof(*si
));
377 memset(PF
,0,sizeof(PF
));
379 /* choose sensible defaults ...
380 * FIXME: perhaps overridable with precompiler flags?
382 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
383 cachedsi
.dwPageSize
= getpagesize();
385 /* FIXME: the two entries below should be computed somehow... */
386 cachedsi
.lpMinimumApplicationAddress
= (void *)0x00010000;
387 cachedsi
.lpMaximumApplicationAddress
= (void *)0x7FFEFFFF;
388 cachedsi
.dwActiveProcessorMask
= 0;
389 cachedsi
.dwNumberOfProcessors
= 1;
390 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
391 cachedsi
.dwAllocationGranularity
= 0x10000;
392 cachedsi
.wProcessorLevel
= 5; /* 586 */
393 cachedsi
.wProcessorRevision
= 0;
395 cache
= 1; /* even if there is no more info, we now have a cache entry */
396 memcpy(si
,&cachedsi
,sizeof(*si
));
398 /* Hmm, reasonable processor feature defaults? */
403 FILE *f
= fopen ("/proc/cpuinfo", "r");
407 while (fgets(line
,200,f
)!=NULL
) {
410 /* NOTE: the ':' is the only character we can rely on */
411 if (!(value
= strchr(line
,':')))
414 /* terminate the valuename */
416 while ((s
>= line
) && ((*s
== ' ') || (*s
== '\t'))) s
--;
419 /* and strip leading spaces from value */
421 while (*value
==' ') value
++;
422 if ((s
=strchr(value
,'\n')))
425 if (!strcasecmp(line
,"processor")) {
426 /* processor number counts up... */
429 if (sscanf(value
,"%d",&x
))
430 if (x
+1>cachedsi
.dwNumberOfProcessors
)
431 cachedsi
.dwNumberOfProcessors
=x
+1;
435 if (!strcasecmp(line
,"model")) {
436 /* First part of wProcessorRevision */
439 if (sscanf(value
,"%d",&x
))
440 cachedsi
.wProcessorRevision
= cachedsi
.wProcessorRevision
| (x
<< 8);
446 if (!strcasecmp(line
, "cpu family")) {
447 if (isdigit (value
[0])) {
448 switch (value
[0] - '0') {
449 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
450 cachedsi
.wProcessorLevel
= 3;
452 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
453 cachedsi
.wProcessorLevel
= 4;
455 case 5: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
456 cachedsi
.wProcessorLevel
= 5;
458 case 6: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
459 cachedsi
.wProcessorLevel
= 6;
461 case 1: /* two-figure levels */
464 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
465 cachedsi
.wProcessorLevel
= 6;
470 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value
);
477 if (!strcasecmp(line
, "cpu")) {
478 if ( isdigit (value
[0]) && value
[1] == '8' &&
479 value
[2] == '6' && value
[3] == 0
481 switch (value
[0] - '0') {
482 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
483 cachedsi
.wProcessorLevel
= 3;
485 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
486 cachedsi
.wProcessorLevel
= 4;
488 case 5: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
489 cachedsi
.wProcessorLevel
= 5;
491 case 6: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
492 cachedsi
.wProcessorLevel
= 6;
495 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value
);
501 if (!strcasecmp(line
,"stepping")) {
502 /* Second part of wProcessorRevision */
505 if (sscanf(value
,"%d",&x
))
506 cachedsi
.wProcessorRevision
= cachedsi
.wProcessorRevision
| x
;
510 if (!strcasecmp(line
, "cpu MHz")) {
512 if (sscanf( value
, "%lf", &cmz
) == 1) {
513 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
514 cpuHz
= cmz
* 1000 * 1000;
518 if (!strcasecmp(line
,"fdiv_bug")) {
519 if (!strncasecmp(value
,"yes",3))
520 PF
[PF_FLOATING_POINT_PRECISION_ERRATA
] = TRUE
;
524 if (!strcasecmp(line
,"fpu")) {
525 if (!strncasecmp(value
,"no",2))
526 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
530 if ( !strcasecmp(line
,"flags") ||
531 !strcasecmp(line
,"features")) {
532 if (strstr(value
,"cx8"))
533 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
534 if (strstr(value
,"mmx"))
535 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
536 if (strstr(value
,"tsc"))
537 PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
538 if (strstr(value
,"3dnow"))
539 PF
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = TRUE
;
540 /* This will also catch sse2, but we have sse itself
541 * if we have sse2, so no problem */
542 if (strstr(value
,"sse"))
543 PF
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = TRUE
;
544 if (strstr(value
,"sse2"))
545 PF
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = TRUE
;
546 if (strstr(value
,"pae"))
547 PF
[PF_PAE_ENABLED
] = TRUE
;
554 #elif defined (__NetBSD__)
560 FILE *f
= fopen ("/var/run/dmesg.boot", "r");
562 /* first deduce as much as possible from the sysctls */
563 mib
[0] = CTL_MACHDEP
;
564 #ifdef CPU_FPU_PRESENT
565 mib
[1] = CPU_FPU_PRESENT
;
566 value
[1] = sizeof(int);
567 if (sysctl(mib
, 2, value
, value
+1, NULL
, 0) >= 0)
568 if (value
) PF
[PF_FLOATING_POINT_EMULATED
] = FALSE
;
569 else PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
572 mib
[1] = CPU_SSE
; /* this should imply MMX */
573 value
[1] = sizeof(int);
574 if (sysctl(mib
, 2, value
, value
+1, NULL
, 0) >= 0)
575 if (value
) PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
578 mib
[1] = CPU_SSE2
; /* this should imply MMX */
579 value
[1] = sizeof(int);
580 if (sysctl(mib
, 2, value
, value
+1, NULL
, 0) >= 0)
581 if (value
) PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
585 value
[1] = sizeof(int);
586 if (sysctl(mib
, 2, value
, value
+1, NULL
, 0) >= 0)
587 if (value
[0] > cachedsi
.dwNumberOfProcessors
)
588 cachedsi
.dwNumberOfProcessors
= value
[0];
591 if (sysctl(mib
, 2, model
, value
+1, NULL
, 0) >= 0) {
592 model
[value
[1]] = '\0'; /* just in case */
593 cpuclass
= strstr(model
, "-class");
594 if (cpuclass
!= NULL
) {
595 while(cpuclass
> model
&& cpuclass
[0] != '(') cpuclass
--;
596 if (!strncmp(cpuclass
+1, "386", 3)) {
597 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
;
598 cachedsi
.wProcessorLevel
= 3;
600 if (!strncmp(cpuclass
+1, "486", 3)) {
601 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
;
602 cachedsi
.wProcessorLevel
= 4;
604 if (!strncmp(cpuclass
+1, "586", 3)) {
605 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
606 cachedsi
.wProcessorLevel
= 5;
608 if (!strncmp(cpuclass
+1, "686", 3)) {
609 cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
;
610 cachedsi
.wProcessorLevel
= 6;
611 /* this should imply MMX */
612 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
617 /* it may be worth reading from /var/run/dmesg.boot for
618 additional information such as CX8, MMX and TSC
619 (however this information should be considered less
620 reliable than that from the sysctl calls) */
623 while (fgets(model
, 255, f
) != NULL
) {
624 if (sscanf(model
,"cpu%d: features %x<", value
, value
+1) == 2) {
625 /* we could scan the string but it is easier
626 to test the bits directly */
628 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
630 PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
631 if (value
[1] & 0x100)
632 PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
633 if (value
[1] & 0x800000)
634 PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
643 #elif defined(__FreeBSD__)
647 get_cpuinfo( &cachedsi
);
649 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
651 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
653 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
656 ret
= sysctlbyname("hw.ncpu", &num
, &len
, NULL
, 0);
658 cachedsi
.dwNumberOfProcessors
= num
;
662 int num
= sysconf( _SC_NPROCESSORS_ONLN
);
664 if (num
== -1) num
= 1;
665 get_cpuinfo( &cachedsi
);
666 cachedsi
.dwNumberOfProcessors
= num
;
668 #elif defined (__APPLE__)
671 unsigned long long longVal
;
676 valSize
= sizeof(int);
677 if (sysctlbyname ("hw.optional.floatingpoint", &value
, &valSize
, NULL
, 0) == 0)
680 PF
[PF_FLOATING_POINT_EMULATED
] = FALSE
;
682 PF
[PF_FLOATING_POINT_EMULATED
] = TRUE
;
684 valSize
= sizeof(int);
685 if (sysctlbyname ("hw.ncpu", &value
, &valSize
, NULL
, 0) == 0)
686 cachedsi
.dwNumberOfProcessors
= value
;
688 valSize
= sizeof(int);
689 if (sysctlbyname ("hw.activecpu", &value
, &valSize
, NULL
, 0) == 0)
690 cachedsi
.dwActiveProcessorMask
= value
;
692 valSize
= sizeof(int);
693 if (sysctlbyname ("hw.cputype", &cputype
, &valSize
, NULL
, 0) == 0)
697 case CPU_TYPE_POWERPC
:
698 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_PPC
;
699 valSize
= sizeof(int);
700 if (sysctlbyname ("hw.cpusubtype", &value
, &valSize
, NULL
, 0) == 0)
704 case CPU_SUBTYPE_POWERPC_601
:
705 case CPU_SUBTYPE_POWERPC_602
:
706 cachedsi
.dwProcessorType
= PROCESSOR_PPC_601
;
707 cachedsi
.wProcessorLevel
= 1;
709 case CPU_SUBTYPE_POWERPC_603
:
710 cachedsi
.dwProcessorType
= PROCESSOR_PPC_603
;
711 cachedsi
.wProcessorLevel
= 3;
713 case CPU_SUBTYPE_POWERPC_603e
:
714 case CPU_SUBTYPE_POWERPC_603ev
:
715 cachedsi
.dwProcessorType
= PROCESSOR_PPC_603
;
716 cachedsi
.wProcessorLevel
= 6;
718 case CPU_SUBTYPE_POWERPC_604
:
719 cachedsi
.dwProcessorType
= PROCESSOR_PPC_604
;
720 cachedsi
.wProcessorLevel
= 4;
722 case CPU_SUBTYPE_POWERPC_604e
:
723 cachedsi
.dwProcessorType
= PROCESSOR_PPC_604
;
724 cachedsi
.wProcessorLevel
= 9;
726 case CPU_SUBTYPE_POWERPC_620
:
727 cachedsi
.dwProcessorType
= PROCESSOR_PPC_620
;
728 cachedsi
.wProcessorLevel
= 20;
730 case CPU_SUBTYPE_POWERPC_750
:
731 case CPU_SUBTYPE_POWERPC_7400
:
732 case CPU_SUBTYPE_POWERPC_7450
:
733 /* G3/G4 derivate from 603 so ... */
734 cachedsi
.dwProcessorType
= PROCESSOR_PPC_603
;
735 cachedsi
.wProcessorLevel
= 6;
737 case CPU_SUBTYPE_POWERPC_970
:
738 cachedsi
.dwProcessorType
= PROCESSOR_PPC_604
;
739 cachedsi
.wProcessorLevel
= 9;
740 /* :o) PF[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
745 break; /* CPU_TYPE_POWERPC */
747 cachedsi
.u
.s
.wProcessorArchitecture
= PROCESSOR_ARCHITECTURE_INTEL
;
748 valSize
= sizeof(int);
749 if (sysctlbyname ("machdep.cpu.family", &value
, &valSize
, NULL
, 0) == 0)
751 cachedsi
.wProcessorLevel
= value
;
754 case 3: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_386
; break;
755 case 4: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_486
; break;
756 default: cachedsi
.dwProcessorType
= PROCESSOR_INTEL_PENTIUM
; break;
759 valSize
= sizeof(int);
760 if (sysctlbyname ("machdep.cpu.model", &value
, &valSize
, NULL
, 0) == 0)
761 cachedsi
.wProcessorRevision
= (value
<< 8);
762 valSize
= sizeof(int);
763 if (sysctlbyname ("machdep.cpu.stepping", &value
, &valSize
, NULL
, 0) == 0)
764 cachedsi
.wProcessorRevision
|= value
;
765 valSize
= sizeof(buffer
);
766 if (sysctlbyname ("machdep.cpu.features", buffer
, &valSize
, NULL
, 0) == 0)
768 cachedsi
.wProcessorRevision
|= value
;
769 if (strstr(buffer
,"CX8")) PF
[PF_COMPARE_EXCHANGE_DOUBLE
] = TRUE
;
770 if (strstr(buffer
,"MMX")) PF
[PF_MMX_INSTRUCTIONS_AVAILABLE
] = TRUE
;
771 if (strstr(buffer
,"TSC")) PF
[PF_RDTSC_INSTRUCTION_AVAILABLE
] = TRUE
;
772 if (strstr(buffer
,"3DNOW")) PF
[PF_3DNOW_INSTRUCTIONS_AVAILABLE
] = TRUE
;
773 if (strstr(buffer
,"SSE")) PF
[PF_XMMI_INSTRUCTIONS_AVAILABLE
] = TRUE
;
774 if (strstr(buffer
,"SSE2")) PF
[PF_XMMI64_INSTRUCTIONS_AVAILABLE
] = TRUE
;
775 if (strstr(buffer
,"PAE")) PF
[PF_PAE_ENABLED
] = TRUE
;
777 break; /* CPU_TYPE_I386 */
779 } /* switch (cputype) */
781 valSize
= sizeof(longVal
);
782 if (!sysctlbyname("hw.cpufrequency", &longVal
, &valSize
, NULL
, 0))
786 FIXME("not yet supported on this system\n");
788 if (!cachedsi
.dwActiveProcessorMask
)
789 cachedsi
.dwActiveProcessorMask
= (1 << cachedsi
.dwNumberOfProcessors
) - 1;
791 memcpy(si
,&cachedsi
,sizeof(*si
));
793 TRACE("<- CPU arch %d, res'd %d, pagesize %d, minappaddr %p, maxappaddr %p,"
794 " act.cpumask %08x, numcpus %d, CPU type %d, allocgran. %d, CPU level %d, CPU rev %d\n",
795 si
->u
.s
.wProcessorArchitecture
, si
->u
.s
.wReserved
, si
->dwPageSize
,
796 si
->lpMinimumApplicationAddress
, si
->lpMaximumApplicationAddress
,
797 si
->dwActiveProcessorMask
, si
->dwNumberOfProcessors
, si
->dwProcessorType
,
798 si
->dwAllocationGranularity
, si
->wProcessorLevel
, si
->wProcessorRevision
);
800 create_system_registry_keys( &cachedsi
);
801 create_env_registry_keys( &cachedsi
);
805 /***********************************************************************
806 * GetNativeSystemInfo [KERNEL32.@]
808 VOID WINAPI
GetNativeSystemInfo(
809 LPSYSTEM_INFO si
/* [out] Destination for system information, may not be NULL */)
811 FIXME("(%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 */