msi: Make sure to ignore UI level flags in dialog and files as well.
[wine/hacks.git] / dlls / kernel32 / cpu.c
blob9f2113258a4ad5b12c93e58e1b6b08fba09054c6
1 /*
2 * What processor?
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
22 #include "config.h"
23 #include "wine/port.h"
25 #ifdef HAVE_SYS_PARAM_H
26 # include <sys/param.h>
27 #endif
28 #ifdef HAVE_SYS_SYSCTL_H
29 # include <sys/sysctl.h>
30 #endif
31 #ifdef HAVE_MACHINE_CPU_H
32 # include <machine/cpu.h>
33 #endif
34 #ifdef HAVE_MACH_MACHINE_H
35 # include <mach/machine.h>
36 #endif
38 #include <ctype.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #ifdef HAVE_SYS_TIME_H
44 # include <sys/time.h>
45 #endif
48 #define NONAMELESSUNION
49 #define NONAMELESSSTRUCT
50 #include "windef.h"
51 #include "winbase.h"
52 #include "winnt.h"
53 #include "winternl.h"
54 #include "winerror.h"
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(int ax, int *p)
69 #ifdef __i386__
70 __asm__("pushl %%ebx\n\t"
71 "cpuid\n\t"
72 "movl %%ebx, %%esi\n\t"
73 "popl %%ebx"
74 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
75 : "0" (ax));
76 #endif
79 /* From xf86info havecpuid.c 1.11 */
80 static inline int have_cpuid(void)
82 #ifdef __i386__
83 unsigned int f1, f2;
84 __asm__("pushfl\n\t"
85 "pushfl\n\t"
86 "popl %0\n\t"
87 "movl %0,%1\n\t"
88 "xorl %2,%0\n\t"
89 "pushl %0\n\t"
90 "popfl\n\t"
91 "pushfl\n\t"
92 "popl %0\n\t"
93 "popfl"
94 : "=&r" (f1), "=&r" (f2)
95 : "ir" (0x00200000));
96 return ((f1^f2) & 0x00200000) != 0;
97 #else
98 return 0;
99 #endif
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}; */
120 unsigned int i;
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;
128 attr.Attributes = 0;
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 ))
154 WCHAR idW[60];
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) );
171 NtClose( hkey );
173 RtlFreeUnicodeString( &nameW );
175 NtClose( cpu_key );
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};
195 HANDLE env_key;
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;
210 attr.Attributes = 0;
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) );
244 NtClose( env_key );
247 /****************************************************************************
248 * QueryPerformanceCounter (KERNEL32.@)
250 * Get the current value of the performance counter.
252 * PARAMS
253 * counter [O] Destination for the current counter reading
255 * RETURNS
256 * Success: TRUE. counter contains the current reading
257 * Failure: FALSE.
259 * SEE ALSO
260 * See QueryPerformanceFrequency.
262 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
264 NtQueryPerformanceCounter( counter, NULL );
265 return TRUE;
269 /****************************************************************************
270 * QueryPerformanceFrequency (KERNEL32.@)
272 * Get the resolution of the performace counter.
274 * PARAMS
275 * frequency [O] Destination for the counter resolution
277 * RETURNS
278 * Success. TRUE. Frequency contains the resolution of the counter.
279 * Failure: FALSE.
281 * SEE ALSO
282 * See QueryPerformanceCounter.
284 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
286 LARGE_INTEGER counter;
287 NtQueryPerformanceCounter( &counter, frequency );
288 return TRUE;
292 /***********************************************************************
293 * GetSystemInfo [KERNEL32.@]
295 * Get information about the system.
297 * RETURNS
298 * Nothing.
300 * NOTES
301 * On the first call it creates cached values, so it doesn't have to determine
302 * them repeatedly. On Linux, the "/proc/cpuinfo" special file is used.
304 * It creates a registry subhierarchy, looking like:
305 * "\HARDWARE\DESCRIPTION\System\CentralProcessor\<processornumber>\Identifier (CPU x86)".
306 * Note that there is a hierarchy for every processor installed, so this
307 * supports multiprocessor systems. This is done like Win95 does it, I think.
309 * It creates some registry entries in the environment part:
310 * "\HKLM\System\CurrentControlSet\Control\Session Manager\Environment". These are
311 * always present. When deleted, Windows will add them again.
313 * It also creates a cached flag array for IsProcessorFeaturePresent().
315 VOID WINAPI GetSystemInfo(
316 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
318 static int cache = 0;
319 static SYSTEM_INFO cachedsi;
321 TRACE("si=0x%p\n", si);
322 if (cache) {
323 memcpy(si,&cachedsi,sizeof(*si));
324 return;
326 memset(PF,0,sizeof(PF));
328 /* choose sensible defaults ...
329 * FIXME: perhaps overridable with precompiler flags?
331 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
332 cachedsi.dwPageSize = getpagesize();
334 /* FIXME: the two entries below should be computed somehow... */
335 cachedsi.lpMinimumApplicationAddress = (void *)0x00010000;
336 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFEFFFF;
337 cachedsi.dwActiveProcessorMask = 1;
338 cachedsi.dwNumberOfProcessors = 1;
339 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
340 cachedsi.dwAllocationGranularity = 0x10000;
341 cachedsi.wProcessorLevel = 5; /* 586 */
342 cachedsi.wProcessorRevision = 0;
344 cache = 1; /* even if there is no more info, we now have a cache entry */
345 memcpy(si,&cachedsi,sizeof(*si));
347 /* Hmm, reasonable processor feature defaults? */
349 #ifdef linux
351 char line[200];
352 FILE *f = fopen ("/proc/cpuinfo", "r");
354 if (!f)
355 return;
356 while (fgets(line,200,f)!=NULL) {
357 char *s,*value;
359 /* NOTE: the ':' is the only character we can rely on */
360 if (!(value = strchr(line,':')))
361 continue;
363 /* terminate the valuename */
364 s = value - 1;
365 while ((s >= line) && ((*s == ' ') || (*s == '\t'))) s--;
366 *(s + 1) = '\0';
368 /* and strip leading spaces from value */
369 value += 1;
370 while (*value==' ') value++;
371 if ((s=strchr(value,'\n')))
372 *s='\0';
374 if (!strcasecmp(line,"processor")) {
375 /* processor number counts up... */
376 unsigned int x;
378 if (sscanf(value,"%d",&x))
379 if (x+1>cachedsi.dwNumberOfProcessors)
380 cachedsi.dwNumberOfProcessors=x+1;
382 continue;
384 if (!strcasecmp(line,"model")) {
385 /* First part of wProcessorRevision */
386 int x;
388 if (sscanf(value,"%d",&x))
389 cachedsi.wProcessorRevision = cachedsi.wProcessorRevision | (x << 8);
391 continue;
394 /* 2.1 method */
395 if (!strcasecmp(line, "cpu family")) {
396 if (isdigit (value[0])) {
397 switch (value[0] - '0') {
398 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
399 cachedsi.wProcessorLevel= 3;
400 break;
401 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
402 cachedsi.wProcessorLevel= 4;
403 break;
404 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
405 cachedsi.wProcessorLevel= 5;
406 break;
407 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
408 cachedsi.wProcessorLevel= 6;
409 break;
410 case 1: /* two-figure levels */
411 if (value[1] == '5')
413 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
414 cachedsi.wProcessorLevel= 6;
415 break;
417 /* fall through */
418 default:
419 FIXME("unknown cpu family '%s', please report ! (-> setting to 386)\n", value);
420 break;
423 continue;
425 /* old 2.0 method */
426 if (!strcasecmp(line, "cpu")) {
427 if ( isdigit (value[0]) && value[1] == '8' &&
428 value[2] == '6' && value[3] == 0
430 switch (value[0] - '0') {
431 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
432 cachedsi.wProcessorLevel= 3;
433 break;
434 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
435 cachedsi.wProcessorLevel= 4;
436 break;
437 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
438 cachedsi.wProcessorLevel= 5;
439 break;
440 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
441 cachedsi.wProcessorLevel= 6;
442 break;
443 default:
444 FIXME("unknown Linux 2.0 cpu family '%s', please report ! (-> setting to 386)\n", value);
445 break;
448 continue;
450 if (!strcasecmp(line,"stepping")) {
451 /* Second part of wProcessorRevision */
452 int x;
454 if (sscanf(value,"%d",&x))
455 cachedsi.wProcessorRevision = cachedsi.wProcessorRevision | x;
457 continue;
459 if (!strcasecmp(line, "cpu MHz")) {
460 double cmz;
461 if (sscanf( value, "%lf", &cmz ) == 1) {
462 /* SYSTEMINFO doesn't have a slot for cpu speed, so store in a global */
463 cpuHz = cmz * 1000 * 1000;
465 continue;
467 if (!strcasecmp(line,"fdiv_bug")) {
468 if (!strncasecmp(value,"yes",3))
469 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
471 continue;
473 if (!strcasecmp(line,"fpu")) {
474 if (!strncasecmp(value,"no",2))
475 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
477 continue;
479 if ( !strcasecmp(line,"flags") ||
480 !strcasecmp(line,"features")) {
481 if (strstr(value,"cx8"))
482 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
483 if (strstr(value,"mmx"))
484 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
485 if (strstr(value,"tsc"))
486 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
487 if (strstr(value,"3dnow"))
488 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
489 /* This will also catch sse2, but we have sse itself
490 * if we have sse2, so no problem */
491 if (strstr(value,"sse"))
492 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
493 if (strstr(value,"sse2"))
494 PF[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
495 if (strstr(value,"pae"))
496 PF[PF_PAE_ENABLED] = TRUE;
498 continue;
501 fclose (f);
503 memcpy(si,&cachedsi,sizeof(*si));
504 #elif defined (__NetBSD__)
506 int mib[2];
507 int value[2];
508 char model[256];
509 char *cpuclass;
510 FILE *f = fopen ("/var/run/dmesg.boot", "r");
512 /* first deduce as much as possible from the sysctls */
513 mib[0] = CTL_MACHDEP;
514 #ifdef CPU_FPU_PRESENT
515 mib[1] = CPU_FPU_PRESENT;
516 value[1] = sizeof(int);
517 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
518 if (value) PF[PF_FLOATING_POINT_EMULATED] = FALSE;
519 else PF[PF_FLOATING_POINT_EMULATED] = TRUE;
520 #endif
521 #ifdef CPU_SSE
522 mib[1] = CPU_SSE; /* this should imply MMX */
523 value[1] = sizeof(int);
524 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
525 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
526 #endif
527 #ifdef CPU_SSE2
528 mib[1] = CPU_SSE2; /* this should imply MMX */
529 value[1] = sizeof(int);
530 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
531 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
532 #endif
533 mib[0] = CTL_HW;
534 mib[1] = HW_NCPU;
535 value[1] = sizeof(int);
536 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
537 if (value[0] > cachedsi.dwNumberOfProcessors)
538 cachedsi.dwNumberOfProcessors = value[0];
539 mib[1] = HW_MODEL;
540 value[1] = 255;
541 if (sysctl(mib, 2, model, value+1, NULL, 0) >= 0) {
542 model[value[1]] = '\0'; /* just in case */
543 cpuclass = strstr(model, "-class");
544 if (cpuclass != NULL) {
545 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
546 if (!strncmp(cpuclass+1, "386", 3)) {
547 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
548 cachedsi.wProcessorLevel= 3;
550 if (!strncmp(cpuclass+1, "486", 3)) {
551 cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
552 cachedsi.wProcessorLevel= 4;
554 if (!strncmp(cpuclass+1, "586", 3)) {
555 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
556 cachedsi.wProcessorLevel= 5;
558 if (!strncmp(cpuclass+1, "686", 3)) {
559 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
560 cachedsi.wProcessorLevel= 6;
561 /* this should imply MMX */
562 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
567 /* it may be worth reading from /var/run/dmesg.boot for
568 additional information such as CX8, MMX and TSC
569 (however this information should be considered less
570 reliable than that from the sysctl calls) */
571 if (f != NULL)
573 while (fgets(model, 255, f) != NULL) {
574 if (sscanf(model,"cpu%d: features %x<", value, value+1) == 2) {
575 /* we could scan the string but it is easier
576 to test the bits directly */
577 if (value[1] & 0x1)
578 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
579 if (value[1] & 0x10)
580 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
581 if (value[1] & 0x100)
582 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
583 if (value[1] & 0x800000)
584 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
586 break;
589 fclose(f);
593 memcpy(si,&cachedsi,sizeof(*si));
594 #elif defined(__FreeBSD__)
596 unsigned int regs[4], regs2[4];
597 int ret, len, num;
598 if (!have_cpuid())
599 regs[0] = 0; /* No cpuid support -- skip the rest */
600 else
601 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
602 if (regs[0]>=0x00000001) { /* Check for supported cpuid version */
603 do_cpuid(0x00000001, regs2); /* get cpu features */
604 switch ((regs2[0] >> 8)&0xf) { /* cpu family */
605 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
606 cachedsi.wProcessorLevel = 3;
607 break;
608 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
609 cachedsi.wProcessorLevel = 4;
610 break;
611 case 5:
612 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
613 cachedsi.wProcessorLevel = 5;
614 break;
615 case 6:
616 case 15: /* PPro/2/3/4 has same info as P1 */
617 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
618 cachedsi.wProcessorLevel = 6;
619 break;
620 default:
621 FIXME("unknown FreeBSD cpu family %d, please report! (-> setting to 386)\n",
622 (regs2[0] >> 8)&0xf);
623 break;
625 PF[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
626 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
627 PF[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
628 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
629 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
630 /*len = sizeof(num);
631 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
632 if (!ret)
633 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
635 if (regs[1] == AUTH &&
636 regs[3] == ENTI &&
637 regs[2] == CAMD) {
638 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
639 if (regs[0]>=0x80000001) {
640 do_cpuid(0x80000001, regs2); /* get vendor features */
641 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] =
642 (regs2[3] & (1 << 31 )) >> 31;
646 len = sizeof(num);
647 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
648 if (!ret)
649 cachedsi.dwNumberOfProcessors = num;
651 memcpy(si,&cachedsi,sizeof(*si));
652 #elif defined (__APPLE__)
654 size_t valSize;
655 unsigned long long longVal;
656 int value;
657 int cputype;
658 char buffer[256];
660 valSize = sizeof(int);
661 if (sysctlbyname ("hw.optional.floatingpoint", &value, &valSize, NULL, 0) == 0)
663 if (value)
664 PF[PF_FLOATING_POINT_EMULATED] = FALSE;
665 else
666 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
668 valSize = sizeof(int);
669 if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
670 cachedsi.dwNumberOfProcessors = value;
672 valSize = sizeof(int);
673 if (sysctlbyname ("hw.activecpu", &value, &valSize, NULL, 0) == 0)
674 cachedsi.dwActiveProcessorMask = value;
676 valSize = sizeof(int);
677 if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
679 switch (cputype)
681 case CPU_TYPE_POWERPC:
682 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_PPC;
683 valSize = sizeof(int);
684 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
686 switch (value)
688 case CPU_SUBTYPE_POWERPC_601:
689 case CPU_SUBTYPE_POWERPC_602:
690 cachedsi.dwProcessorType = PROCESSOR_PPC_601;
691 cachedsi.wProcessorLevel = 1;
692 break;
693 case CPU_SUBTYPE_POWERPC_603:
694 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
695 cachedsi.wProcessorLevel = 3;
696 break;
697 case CPU_SUBTYPE_POWERPC_603e:
698 case CPU_SUBTYPE_POWERPC_603ev:
699 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
700 cachedsi.wProcessorLevel = 6;
701 break;
702 case CPU_SUBTYPE_POWERPC_604:
703 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
704 cachedsi.wProcessorLevel = 4;
705 break;
706 case CPU_SUBTYPE_POWERPC_604e:
707 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
708 cachedsi.wProcessorLevel = 9;
709 break;
710 case CPU_SUBTYPE_POWERPC_620:
711 cachedsi.dwProcessorType = PROCESSOR_PPC_620;
712 cachedsi.wProcessorLevel = 20;
713 break;
714 case CPU_SUBTYPE_POWERPC_750:
715 case CPU_SUBTYPE_POWERPC_7400:
716 case CPU_SUBTYPE_POWERPC_7450:
717 /* G3/G4 derivate from 603 so ... */
718 cachedsi.dwProcessorType = PROCESSOR_PPC_603;
719 cachedsi.wProcessorLevel = 6;
720 break;
721 case CPU_SUBTYPE_POWERPC_970:
722 cachedsi.dwProcessorType = PROCESSOR_PPC_604;
723 cachedsi.wProcessorLevel = 9;
724 /* :o) PF[PF_ALTIVEC_INSTRUCTIONS_AVAILABLE] ;-) */
725 break;
726 default: break;
729 break; /* CPU_TYPE_POWERPC */
730 case CPU_TYPE_I386:
731 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
732 valSize = sizeof(int);
733 if (sysctlbyname ("machdep.cpu.family", &value, &valSize, NULL, 0) == 0)
735 cachedsi.wProcessorLevel = value;
736 switch (value)
738 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386; break;
739 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486; break;
740 default: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
743 valSize = sizeof(int);
744 if (sysctlbyname ("machdep.cpu.model", &value, &valSize, NULL, 0) == 0)
745 cachedsi.wProcessorRevision = (value << 8);
746 valSize = sizeof(int);
747 if (sysctlbyname ("machdep.cpu.stepping", &value, &valSize, NULL, 0) == 0)
748 cachedsi.wProcessorRevision |= value;
749 valSize = sizeof(buffer);
750 if (sysctlbyname ("machdep.cpu.features", buffer, &valSize, NULL, 0) == 0)
752 cachedsi.wProcessorRevision |= value;
753 if (strstr(buffer,"CX8")) PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
754 if (strstr(buffer,"MMX")) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
755 if (strstr(buffer,"TSC")) PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
756 if (strstr(buffer,"3DNOW")) PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
757 if (strstr(buffer,"SSE")) PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
758 if (strstr(buffer,"SSE2")) PF[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
759 if (strstr(buffer,"PAE")) PF[PF_PAE_ENABLED] = TRUE;
761 break; /* CPU_TYPE_I386 */
762 default: break;
763 } /* switch (cputype) */
765 valSize = sizeof(longVal);
766 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
767 cpuHz = longVal;
769 memcpy(si,&cachedsi,sizeof(*si));
770 #else
771 FIXME("not yet supported on this system\n");
772 #endif
773 TRACE("<- CPU arch %d, res'd %d, pagesize %d, minappaddr %p, maxappaddr %p,"
774 " act.cpumask %08x, numcpus %d, CPU type %d, allocgran. %d, CPU level %d, CPU rev %d\n",
775 si->u.s.wProcessorArchitecture, si->u.s.wReserved, si->dwPageSize,
776 si->lpMinimumApplicationAddress, si->lpMaximumApplicationAddress,
777 si->dwActiveProcessorMask, si->dwNumberOfProcessors, si->dwProcessorType,
778 si->dwAllocationGranularity, si->wProcessorLevel, si->wProcessorRevision);
780 create_system_registry_keys( &cachedsi );
781 create_env_registry_keys( &cachedsi );
785 /***********************************************************************
786 * GetNativeSystemInfo [KERNEL32.@]
788 VOID WINAPI GetNativeSystemInfo(
789 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
791 FIXME("(%p) using GetSystemInfo()\n", si);
792 GetSystemInfo(si);
795 /***********************************************************************
796 * IsProcessorFeaturePresent [KERNEL32.@]
798 * Determine if the cpu supports a given feature.
800 * RETURNS
801 * TRUE, If the processor supports feature,
802 * FALSE otherwise.
804 BOOL WINAPI IsProcessorFeaturePresent (
805 DWORD feature /* [in] Feature number, (PF_ constants from "winnt.h") */)
807 SYSTEM_INFO si;
808 GetSystemInfo (&si); /* To ensure the information is loaded and cached */
810 if (feature < 64)
811 return PF[feature];
812 else
813 return FALSE;