Release 971101
[wine/multimedia.git] / misc / cpu.c
blob014c546cfa717586a95e7f53898b7dbc679fe7df
1 /*
2 * What processor?
4 * Copyright 1995 Morten Welinder
5 * Copyright 1997 Marcus Meissner
6 */
8 #include <stdio.h>
9 #include <ctype.h>
10 #include <string.h>
11 #include "windows.h"
13 VOID WINAPI GetSystemInfo(LPSYSTEM_INFO si)
15 static int cache = 0;
16 static SYSTEM_INFO cachedsi;
18 if (cache) {
19 memcpy(si,&cachedsi,sizeof(*si));
20 return;
23 /* choose sensible defaults ...
24 * FIXME: perhaps overrideable with precompiler flags?
26 cachedsi.u.x.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
27 cachedsi.dwPageSize = 4096;
29 /* FIXME: better values for the two entries below... */
30 cachedsi.lpMinimumApplicationAddress = (void *)0x40000000;
31 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
32 cachedsi.dwActiveProcessorMask = 1;
33 cachedsi.dwNumberOfProcessors = 1;
34 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
35 cachedsi.dwAllocationGranularity = 0x10000;
36 cachedsi.wProcessorLevel = 3; /* 386 */
37 cachedsi.wProcessorRevision = 0;
39 cache = 1; /* even if there is no more info, we now have a cacheentry */
40 memcpy(si,&cachedsi,sizeof(*si));
42 #ifdef linux
44 char line[200],info[200],value[200],junk[200];
45 FILE *f = fopen ("/proc/cpuinfo", "r");
47 if (!f)
48 return;
49 while (fgets(line,200,f)!=NULL) {
50 if (sscanf(line,"%s%[ \t:]%s",info,junk,value)!=3)
51 continue;
52 if (!lstrncmpi32A(line, "cpu",3)) {
53 if ( isdigit (value[0]) && value[1] == '8' &&
54 value[2] == '6' && value[3] == 0
55 ) {
56 switch (value[0] - '0') {
57 case 3:
58 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
59 cachedsi.wProcessorLevel= 3;
60 break;
61 case 4:
62 cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
63 cachedsi.wProcessorLevel= 4;
64 break;
65 case 5:
66 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
67 cachedsi.wProcessorLevel= 5;
68 break;
69 case 6: /* FIXME does the PPro have a special type? */
70 cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
71 cachedsi.wProcessorLevel= 5;
72 break;
73 default:
74 break;
78 if (!lstrncmpi32A(info,"processor",9)) {
79 /* processor number counts up...*/
80 int x;
82 if (sscanf(value,"%d",&x))
83 if (x+1>cachedsi.dwNumberOfProcessors)
84 cachedsi.dwNumberOfProcessors=x+1;
86 if (!lstrncmpi32A(info,"stepping",8)) {
87 int x;
89 if (sscanf(value,"%d",&x))
90 cachedsi.wProcessorRevision = x;
93 fclose (f);
95 memcpy(si,&cachedsi,sizeof(*si));
96 return;
97 #else /* linux */
98 /* FIXME: how do we do this on other systems? */
99 return;
100 #endif /* linux */