kernel32: Add condition variables prototypes and tests.
[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 "psapi.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
44 #include "ddk/wdm.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(reg);
47
48 #define SHARED_DATA     ((KSHARED_USER_DATA*)0x7ffe0000)
49
50 /****************************************************************************
51  *              QueryPerformanceCounter (KERNEL32.@)
52  *
53  * Get the current value of the performance counter.
54  * 
55  * PARAMS
56  *  counter [O] Destination for the current counter reading
57  *
58  * RETURNS
59  *  Success: TRUE. counter contains the current reading
60  *  Failure: FALSE.
61  *
62  * SEE ALSO
63  *  See QueryPerformanceFrequency.
64  */
65 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
66 {
67     NtQueryPerformanceCounter( counter, NULL );
68     return TRUE;
69 }
70
71
72 /****************************************************************************
73  *              QueryPerformanceFrequency (KERNEL32.@)
74  *
75  * Get the resolution of the performance counter.
76  *
77  * PARAMS
78  *  frequency [O] Destination for the counter resolution
79  *
80  * RETURNS
81  *  Success. TRUE. Frequency contains the resolution of the counter.
82  *  Failure: FALSE.
83  *
84  * SEE ALSO
85  *  See QueryPerformanceCounter.
86  */
87 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
88 {
89     LARGE_INTEGER counter;
90     NtQueryPerformanceCounter( &counter, frequency );
91     return TRUE;
92 }
93
94
95 /***********************************************************************
96  *                      GetSystemInfo                   [KERNEL32.@]
97  *
98  * Get information about the system.
99  *
100  * RETURNS
101  *  Nothing.
102  */
103 VOID WINAPI GetSystemInfo(
104         LPSYSTEM_INFO si        /* [out] Destination for system information, may not be NULL */)
105 {
106     NTSTATUS                 nts;
107     SYSTEM_BASIC_INFORMATION sbi;
108     SYSTEM_CPU_INFORMATION   sci;
109
110     TRACE("si=0x%p\n", si);
111
112     if ((nts = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL )) != STATUS_SUCCESS ||
113         (nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
114     {
115         SetLastError(RtlNtStatusToDosError(nts));
116         return;
117     }
118
119     si->u.s.wProcessorArchitecture  = sci.Architecture;
120     si->u.s.wReserved               = 0;
121     si->dwPageSize                  = sbi.PageSize;
122     si->lpMinimumApplicationAddress = sbi.LowestUserAddress;
123     si->lpMaximumApplicationAddress = sbi.HighestUserAddress;
124     si->dwActiveProcessorMask       = sbi.ActiveProcessorsAffinityMask;
125     si->dwNumberOfProcessors        = sbi.NumberOfProcessors;
126
127     switch (sci.Architecture)
128     {
129     case PROCESSOR_ARCHITECTURE_INTEL:
130         switch (sci.Level)
131         {
132         case 3:  si->dwProcessorType = PROCESSOR_INTEL_386;     break;
133         case 4:  si->dwProcessorType = PROCESSOR_INTEL_486;     break;
134         case 5:
135         case 6:  si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
136         default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
137         }
138         break;
139     case PROCESSOR_ARCHITECTURE_PPC:
140         switch (sci.Level)
141         {
142         case 1:  si->dwProcessorType = PROCESSOR_PPC_601;       break;
143         case 3:
144         case 6:  si->dwProcessorType = PROCESSOR_PPC_603;       break;
145         case 4:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
146         case 9:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
147         case 20: si->dwProcessorType = PROCESSOR_PPC_620;       break;
148         default: si->dwProcessorType = 0;
149         }
150         break;
151     case PROCESSOR_ARCHITECTURE_AMD64:
152         si->dwProcessorType = PROCESSOR_AMD_X8664;
153         break;
154     case PROCESSOR_ARCHITECTURE_ARM:
155         switch (sci.Level)
156         {
157         case 4:  si->dwProcessorType = PROCESSOR_ARM_7TDMI;     break;
158         default: si->dwProcessorType = PROCESSOR_ARM920;
159         }
160         break;
161     default:
162         FIXME("Unknown processor architecture %x\n", sci.Architecture);
163         si->dwProcessorType = 0;
164     }
165     si->dwAllocationGranularity     = sbi.AllocationGranularity;
166     si->wProcessorLevel             = sci.Level;
167     si->wProcessorRevision          = sci.Revision;
168 }
169
170
171 /***********************************************************************
172  *                      GetNativeSystemInfo             [KERNEL32.@]
173  */
174 VOID WINAPI GetNativeSystemInfo(
175     LPSYSTEM_INFO si    /* [out] Destination for system information, may not be NULL */)
176 {
177     BOOL is_wow64;
178
179     GetSystemInfo(si); 
180
181     IsWow64Process(GetCurrentProcess(), &is_wow64);
182     if (is_wow64)
183     {
184         if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
185         {
186             si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
187             si->dwProcessorType = PROCESSOR_AMD_X8664;
188         }
189         else
190         {
191             FIXME("Add the proper information for %d in wow64 mode\n",
192                   si->u.s.wProcessorArchitecture);
193         }
194     }
195 }
196
197 /***********************************************************************
198  *                      IsProcessorFeaturePresent       [KERNEL32.@]
199  *
200  * Determine if the cpu supports a given feature.
201  * 
202  * RETURNS
203  *  TRUE, If the processor supports feature,
204  *  FALSE otherwise.
205  */
206 BOOL WINAPI IsProcessorFeaturePresent (
207         DWORD feature   /* [in] Feature number, (PF_ constants from "winnt.h") */) 
208 {
209   if (feature < PROCESSOR_FEATURE_MAX)
210     return SHARED_DATA->ProcessorFeatures[feature];
211   else
212     return FALSE;
213 }
214
215 /***********************************************************************
216  *           K32GetPerformanceInfo (KERNEL32.@)
217  */
218 BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
219 {
220     NTSTATUS status;
221
222     TRACE( "(%p, %d)\n", info, size );
223
224     status = NtQuerySystemInformation( SystemPerformanceInformation, info, size, NULL );
225
226     if (status)
227     {
228         SetLastError( RtlNtStatusToDosError( status ) );
229         return FALSE;
230     }
231     return TRUE;
232 }