4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997 Marcus Meissner
15 static BYTE PF[64] = {0,};
17 /***********************************************************************
18 * GetSystemInfo [KERNELL32.404]
20 VOID WINAPI GetSystemInfo(LPSYSTEM_INFO si)
23 static SYSTEM_INFO cachedsi;
28 memcpy(si,&cachedsi,sizeof(*si));
31 memset(PF,0,sizeof(PF));
33 /* choose sensible defaults ...
34 * FIXME: perhaps overrideable with precompiler flags?
36 cachedsi.u.x.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
37 cachedsi.dwPageSize = 4096;
39 /* FIXME: better values for the two entries below... */
40 cachedsi.lpMinimumApplicationAddress = (void *)0x40000000;
41 cachedsi.lpMaximumApplicationAddress = (void *)0x7FFFFFFF;
42 cachedsi.dwActiveProcessorMask = 1;
43 cachedsi.dwNumberOfProcessors = 1;
44 cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
45 cachedsi.dwAllocationGranularity = 0x10000;
46 cachedsi.wProcessorLevel = 3; /* 386 */
47 cachedsi.wProcessorRevision = 0;
49 cache = 1; /* even if there is no more info, we now have a cacheentry */
50 memcpy(si,&cachedsi,sizeof(*si));
52 /* hmm, reasonable processor feature defaults? */
57 FILE *f = fopen ("/proc/cpuinfo", "r");
62 RegCreateKey16(HKEY_LOCAL_MACHINE,"\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor",&hkey);
63 while (fgets(line,200,f)!=NULL) {
66 /* NOTE: the ':' is the only character we can rely on */
67 if (!(value = strchr(line,':')))
69 /* terminate the valuename */
71 /* skip any leading spaces */
72 while (*value==' ') value++;
73 if ((s=strchr(value,'\n')))
77 if (!lstrncmpi32A(line, "cpu family",strlen("cpu family"))) {
78 if (isdigit (value[0])) {
79 switch (value[0] - '0') {
80 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
81 cachedsi.wProcessorLevel= 3;
83 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
84 cachedsi.wProcessorLevel= 4;
86 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
87 cachedsi.wProcessorLevel= 5;
89 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
90 cachedsi.wProcessorLevel= 5;
96 /* set the CPU type of the current processor */
97 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
99 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
103 if (!lstrncmpi32A(line, "cpu",strlen("cpu"))) {
104 if ( isdigit (value[0]) && value[1] == '8' &&
105 value[2] == '6' && value[3] == 0
107 switch (value[0] - '0') {
108 case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
109 cachedsi.wProcessorLevel= 3;
111 case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
112 cachedsi.wProcessorLevel= 4;
114 case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
115 cachedsi.wProcessorLevel= 5;
117 case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
118 cachedsi.wProcessorLevel= 5;
124 /* set the CPU type of the current processor */
125 sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
127 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,buf,strlen(buf));
130 if (!lstrncmpi32A(line,"fdiv_bug",strlen("fdiv_bug"))) {
131 if (!lstrncmpi32A(value,"yes",3))
132 PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
136 if (!lstrncmpi32A(line,"fpu",strlen("fpu"))) {
137 if (!lstrncmpi32A(value,"no",2))
138 PF[PF_FLOATING_POINT_EMULATED] = TRUE;
142 if (!lstrncmpi32A(line,"processor",strlen("processor"))) {
143 /* processor number counts up...*/
146 if (sscanf(value,"%d",&x))
147 if (x+1>cachedsi.dwNumberOfProcessors)
148 cachedsi.dwNumberOfProcessors=x+1;
150 /* create a new processor subkey */
154 RegCreateKey16(hkey,buf,&xhkey);
156 if (!lstrncmpi32A(line,"stepping",strlen("stepping"))) {
159 if (sscanf(value,"%d",&x))
160 cachedsi.wProcessorRevision = x;
162 if (!lstrncmpi32A(line,"flags",strlen("flags"))) {
163 if (strstr(value,"cx8"))
164 PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
165 if (strstr(value,"mmx"))
166 PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
172 memcpy(si,&cachedsi,sizeof(*si));
174 /* FIXME: how do we do this on other systems? */
176 RegCreateKey16(hkey,"0",&xhkey);
177 RegSetValueEx32A(xhkey,"Identifier",0,REG_SZ,"CPU 386",strlen("CPU 386"));
184 /***********************************************************************
185 * IsProcessorFeaturePresent [KERNELL32.880]
187 BOOL32 WINAPI IsProcessorFeaturePresent (DWORD feature)
190 GetSystemInfo (&si); /* to ensure the information is loaded and cached */