kernel32: Moved K32EnumProcessModules to module.c.
[wine] / dlls / kernel32 / cpu.c
1 /*
2  * What processor?
3  *
4  * Copyright 1995,1997 Morten Welinder
5  * Copyright 1997-1998 Marcus Meissner
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
30 #endif
31
32
33 #define NONAMELESSUNION
34 #define NONAMELESSSTRUCT
35 #include "ntstatus.h"
36 #define WIN32_NO_STATUS
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winnt.h"
40 #include "winternl.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
43 #include "ddk/wdm.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(reg);
46
47 #define SHARED_DATA     ((KSHARED_USER_DATA*)0x7ffe0000)
48
49 /****************************************************************************
50  *              QueryPerformanceCounter (KERNEL32.@)
51  *
52  * Get the current value of the performance counter.
53  * 
54  * PARAMS
55  *  counter [O] Destination for the current counter reading
56  *
57  * RETURNS
58  *  Success: TRUE. counter contains the current reading
59  *  Failure: FALSE.
60  *
61  * SEE ALSO
62  *  See QueryPerformanceFrequency.
63  */
64 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
65 {
66     NtQueryPerformanceCounter( counter, NULL );
67     return TRUE;
68 }
69
70
71 /****************************************************************************
72  *              QueryPerformanceFrequency (KERNEL32.@)
73  *
74  * Get the resolution of the performance counter.
75  *
76  * PARAMS
77  *  frequency [O] Destination for the counter resolution
78  *
79  * RETURNS
80  *  Success. TRUE. Frequency contains the resolution of the counter.
81  *  Failure: FALSE.
82  *
83  * SEE ALSO
84  *  See QueryPerformanceCounter.
85  */
86 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
87 {
88     LARGE_INTEGER counter;
89     NtQueryPerformanceCounter( &counter, frequency );
90     return TRUE;
91 }
92
93
94 /***********************************************************************
95  *                      GetSystemInfo                   [KERNEL32.@]
96  *
97  * Get information about the system.
98  *
99  * RETURNS
100  *  Nothing.
101  *
102  * NOTES
103  * On the first call it creates cached values, so it doesn't have to determine
104  * them repeatedly. On Linux, the "/proc/cpuinfo" special file is used.
105  *
106  * It also creates a cached flag array for IsProcessorFeaturePresent().
107  */
108 VOID WINAPI GetSystemInfo(
109         LPSYSTEM_INFO si        /* [out] Destination for system information, may not be NULL */)
110 {
111     NTSTATUS                 nts;
112     SYSTEM_BASIC_INFORMATION sbi;
113     SYSTEM_CPU_INFORMATION   sci;
114
115     TRACE("si=0x%p\n", si);
116
117     if ((nts = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL )) != STATUS_SUCCESS ||
118         (nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
119     {
120         SetLastError(RtlNtStatusToDosError(nts));
121         return;
122     }
123
124     si->u.s.wProcessorArchitecture  = sci.Architecture;
125     si->u.s.wReserved               = 0;
126     si->dwPageSize                  = sbi.PageSize;
127     si->lpMinimumApplicationAddress = sbi.LowestUserAddress;
128     si->lpMaximumApplicationAddress = sbi.HighestUserAddress;
129     si->dwActiveProcessorMask       = sbi.ActiveProcessorsAffinityMask;
130     si->dwNumberOfProcessors        = sbi.NumberOfProcessors;
131
132     switch (sci.Architecture)
133     {
134     case PROCESSOR_ARCHITECTURE_INTEL:
135         switch (sci.Level)
136         {
137         case 3:  si->dwProcessorType = PROCESSOR_INTEL_386;     break;
138         case 4:  si->dwProcessorType = PROCESSOR_INTEL_486;     break;
139         case 5:
140         case 6:  si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
141         default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
142         }
143         break;
144     case PROCESSOR_ARCHITECTURE_PPC:
145         switch (sci.Level)
146         {
147         case 1:  si->dwProcessorType = PROCESSOR_PPC_601;       break;
148         case 3:
149         case 6:  si->dwProcessorType = PROCESSOR_PPC_603;       break;
150         case 4:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
151         case 9:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
152         case 20: si->dwProcessorType = PROCESSOR_PPC_620;       break;
153         default: si->dwProcessorType = 0;
154         }
155         break;
156     case PROCESSOR_ARCHITECTURE_AMD64:
157         si->dwProcessorType = PROCESSOR_AMD_X8664;
158         break;
159     default: FIXME("Unknown processor architecture %x\n", sci.Architecture);
160     }
161     si->dwAllocationGranularity     = sbi.AllocationGranularity;
162     si->wProcessorLevel             = sci.Level;
163     si->wProcessorRevision          = sci.Revision;
164 }
165
166
167 /***********************************************************************
168  *                      GetNativeSystemInfo             [KERNEL32.@]
169  */
170 VOID WINAPI GetNativeSystemInfo(
171     LPSYSTEM_INFO si    /* [out] Destination for system information, may not be NULL */)
172 {
173     BOOL is_wow64;
174
175     GetSystemInfo(si); 
176
177     IsWow64Process(GetCurrentProcess(), &is_wow64);
178     if (is_wow64)
179     {
180         if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
181         {
182             si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
183             si->dwProcessorType = PROCESSOR_AMD_X8664;
184         }
185         else
186         {
187             FIXME("Add the proper information for %d in wow64 mode\n",
188                   si->u.s.wProcessorArchitecture);
189         }
190     }
191 }
192
193 /***********************************************************************
194  *                      IsProcessorFeaturePresent       [KERNEL32.@]
195  *
196  * Determine if the cpu supports a given feature.
197  * 
198  * RETURNS
199  *  TRUE, If the processor supports feature,
200  *  FALSE otherwise.
201  */
202 BOOL WINAPI IsProcessorFeaturePresent (
203         DWORD feature   /* [in] Feature number, (PF_ constants from "winnt.h") */) 
204 {
205   if (feature < 64)
206     return SHARED_DATA->ProcessorFeatures[feature];
207   else
208     return FALSE;
209 }