shlwapi: Add tests for PathCombineA.
[wine/dcerpc.git] / dlls / kernel / cpu.c
blobb077ad6c306673cf8c525f5a36ebdf9727896c17
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, "%ld", 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 overrideable 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 cacheentry */
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;
464 TRACE("CPU speed read as %lld\n", cpuHz);
466 continue;
468 if (!strcasecmp(line,"fdiv_bug")) {
469 if (!strncasecmp(value,"yes",3))
470 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
472 continue;
474 if (!strcasecmp(line,"fpu")) {
475 if (!strncasecmp(value,"no",2))
476 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
478 continue;
480 if ( !strcasecmp(line,"flags") ||
481 !strcasecmp(line,"features")) {
482 if (strstr(value,"cx8"))
483 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
484 if (strstr(value,"mmx"))
485 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
486 if (strstr(value,"tsc"))
487 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
488 if (strstr(value,"3dnow"))
489 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = TRUE;
490 /* This will also catch sse2, but we have sse itself
491 * if we have sse2, so no problem */
492 if (strstr(value,"sse"))
493 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = TRUE;
494 if (strstr(value,"sse2"))
495 PF[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = TRUE;
496 if (strstr(value,"pae"))
497 PF[PF_PAE_ENABLED] = TRUE;
499 continue;
502 fclose (f);
504 memcpy(si,&cachedsi,sizeof(*si));
505 #elif defined (__NetBSD__)
507 int mib[2];
508 int value[2];
509 char model[256];
510 char *cpuclass;
511 FILE *f = fopen ("/var/run/dmesg.boot", "r");
513 /* first deduce as much as possible from the sysctls */
514 mib[0] = CTL_MACHDEP;
515 #ifdef CPU_FPU_PRESENT
516 mib[1] = CPU_FPU_PRESENT;
517 value[1] = sizeof(int);
518 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
519 if (value) PF[PF_FLOATING_POINT_EMULATED] = FALSE;
520 else PF[PF_FLOATING_POINT_EMULATED] = TRUE;
521 #endif
522 #ifdef CPU_SSE
523 mib[1] = CPU_SSE; /* this should imply MMX */
524 value[1] = sizeof(int);
525 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
526 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
527 #endif
528 #ifdef CPU_SSE2
529 mib[1] = CPU_SSE2; /* this should imply MMX */
530 value[1] = sizeof(int);
531 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
532 if (value) PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
533 #endif
534 mib[0] = CTL_HW;
535 mib[1] = HW_NCPU;
536 value[1] = sizeof(int);
537 if (sysctl(mib, 2, value, value+1, NULL, 0) >= 0)
538 if (value[0] > cachedsi.dwNumberOfProcessors)
539 cachedsi.dwNumberOfProcessors = value[0];
540 mib[1] = HW_MODEL;
541 value[1] = 255;
542 if (sysctl(mib, 2, model, value+1, NULL, 0) >= 0) {
543 model[value[1]] = '\0'; /* just in case */
544 cpuclass = strstr(model, "-class");
545 if (cpuclass != NULL) {
546 while(cpuclass > model && cpuclass[0] != '(') cpuclass--;
547 if (!strncmp(cpuclass+1, "386", 3)) {
548 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
549 cachedsi.wProcessorLevel= 3;
551 if (!strncmp(cpuclass+1, "486", 3)) {
552 cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
553 cachedsi.wProcessorLevel= 4;
555 if (!strncmp(cpuclass+1, "586", 3)) {
556 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
557 cachedsi.wProcessorLevel= 5;
559 if (!strncmp(cpuclass+1, "686", 3)) {
560 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
561 cachedsi.wProcessorLevel= 6;
562 /* this should imply MMX */
563 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
568 /* it may be worth reading from /var/run/dmesg.boot for
569 additional information such as CX8, MMX and TSC
570 (however this information should be considered less
571 reliable than that from the sysctl calls) */
572 if (f != NULL)
574 while (fgets(model, 255, f) != NULL) {
575 if (sscanf(model,"cpu%d: features %x<", value, value+1) == 2) {
576 /* we could scan the string but it is easier
577 to test the bits directly */
578 if (value[1] & 0x1)
579 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
580 if (value[1] & 0x10)
581 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = TRUE;
582 if (value[1] & 0x100)
583 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
584 if (value[1] & 0x800000)
585 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
587 break;
590 fclose(f);
594 memcpy(si,&cachedsi,sizeof(*si));
595 #elif defined(__FreeBSD__)
597 unsigned int regs[4], regs2[4];
598 int ret, len, num;
599 if (!have_cpuid())
600 regs[0] = 0; /* No cpuid support -- skip the rest */
601 else
602 do_cpuid(0x00000000, regs); /* get standard cpuid level and vendor name */
603 if (regs[0]>=0x00000001) { /* Check for supported cpuid version */
604 do_cpuid(0x00000001, regs2); /* get cpu features */
605 switch ((regs2[0] >> 8)&0xf) { /* cpu family */
606 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
607 cachedsi.wProcessorLevel = 3;
608 break;
609 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
610 cachedsi.wProcessorLevel = 4;
611 break;
612 case 5:
613 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
614 cachedsi.wProcessorLevel = 5;
615 break;
616 case 6:
617 case 15: /* PPro/2/3/4 has same info as P1 */
618 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
619 cachedsi.wProcessorLevel = 6;
620 break;
621 default:
622 FIXME("unknown FreeBSD cpu family %d, please report! (-> setting to 386)\n", \
623 (regs2[0] >> 8)&0xf);
624 break;
626 PF[PF_FLOATING_POINT_EMULATED] = !(regs2[3] & 1);
627 PF[PF_RDTSC_INSTRUCTION_AVAILABLE] = (regs2[3] & (1 << 4 )) >> 4;
628 PF[PF_COMPARE_EXCHANGE_DOUBLE] = (regs2[3] & (1 << 8 )) >> 8;
629 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = (regs2[3] & (1 << 23)) >> 23;
630 /* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
631 /*len = sizeof(num);
632 ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
633 if (!ret)
634 PF[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
636 if (regs[1] == AUTH &&
637 regs[3] == ENTI &&
638 regs[2] == CAMD) {
639 do_cpuid(0x80000000, regs); /* get vendor cpuid level */
640 if (regs[0]>=0x80000001) {
641 do_cpuid(0x80000001, regs2); /* get vendor features */
642 PF[PF_3DNOW_INSTRUCTIONS_AVAILABLE] =
643 (regs2[3] & (1 << 31 )) >> 31;
647 len = sizeof(num);
648 ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
649 if (!ret)
650 cachedsi.dwNumberOfProcessors = num;
652 memcpy(si,&cachedsi,sizeof(*si));
653 #elif defined (__APPLE__)
655 size_t valSize;
656 unsigned long long longVal;
657 int value;
658 int cputype;
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 valSize = sizeof(int);
680 if (sysctlbyname ("hw.cpusubtype", &value, &valSize, NULL, 0) == 0)
682 switch (cputype)
684 case CPU_TYPE_POWERPC:
685 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_PPC;
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;
728 break; /* CPU_TYPE_POWERPC */
729 case CPU_TYPE_I386:
730 cachedsi.u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
731 switch (value)
733 case CPU_SUBTYPE_386:
734 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
735 cachedsi.wProcessorLevel = 3;
736 break;
737 case CPU_SUBTYPE_486:
738 case CPU_SUBTYPE_486SX:
739 cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
740 cachedsi.wProcessorLevel = 4;
741 break;
742 case CPU_SUBTYPE_586:
743 case CPU_SUBTYPE_PENTPRO:
744 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
745 cachedsi.wProcessorLevel = 5;
746 break;
747 case CPU_SUBTYPE_PENTII_M3:
748 case CPU_SUBTYPE_PENTII_M5:
749 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
750 cachedsi.wProcessorLevel = 5;
751 /* this should imply MMX */
752 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
753 break;
754 default: break;
756 break; /* CPU_TYPE_I386 */
757 default: break;
758 } /* switch (cputype) */
761 valSize = sizeof(longVal);
762 if (!sysctlbyname("hw.cpufrequency", &longVal, &valSize, NULL, 0))
763 cpuHz = longVal;
765 memcpy(si,&cachedsi,sizeof(*si));
766 #else
767 FIXME("not yet supported on this system\n");
768 #endif
769 TRACE("<- CPU arch %d, res'd %d, pagesize %ld, minappaddr %p, maxappaddr %p,"
770 " act.cpumask %08lx, numcpus %ld, CPU type %ld, allocgran. %ld, CPU level %d, CPU rev %d\n",
771 si->u.s.wProcessorArchitecture, si->u.s.wReserved, si->dwPageSize,
772 si->lpMinimumApplicationAddress, si->lpMaximumApplicationAddress,
773 si->dwActiveProcessorMask, si->dwNumberOfProcessors, si->dwProcessorType,
774 si->dwAllocationGranularity, si->wProcessorLevel, si->wProcessorRevision);
776 create_system_registry_keys( &cachedsi );
777 create_env_registry_keys( &cachedsi );
781 /***********************************************************************
782 * IsProcessorFeaturePresent [KERNEL32.@]
784 * Determine if the cpu supports a given feature.
786 * RETURNS
787 * TRUE, If the processor supports feature,
788 * FALSE otherwise.
790 BOOL WINAPI IsProcessorFeaturePresent (
791 DWORD feature /* [in] Feature number, (PF_ constants from "winnt.h") */)
793 SYSTEM_INFO si;
794 GetSystemInfo (&si); /* To ensure the information is loaded and cached */
796 if (feature < 64)
797 return PF[feature];
798 else
799 return FALSE;