crypt32: Add tests for encoding/decoding cert policy constraints.
[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     default: FIXME("Unknown processor architecture %x\n", sci.Architecture);
157     }
158     si->dwAllocationGranularity     = sbi.AllocationGranularity;
159     si->wProcessorLevel             = sci.Level;
160     si->wProcessorRevision          = sci.Revision;
161 }
162
163
164 /***********************************************************************
165  *                      GetNativeSystemInfo             [KERNEL32.@]
166  */
167 VOID WINAPI GetNativeSystemInfo(
168     LPSYSTEM_INFO si    /* [out] Destination for system information, may not be NULL */)
169 {
170     static BOOL reported = FALSE;
171     if (!reported) {
172         FIXME("(%p) using GetSystemInfo()\n", si);
173         reported = TRUE;
174     } else
175         TRACE("(%p) using GetSystemInfo()\n", si);
176     GetSystemInfo(si); 
177 }
178
179 /***********************************************************************
180  *                      IsProcessorFeaturePresent       [KERNEL32.@]
181  *
182  * Determine if the cpu supports a given feature.
183  * 
184  * RETURNS
185  *  TRUE, If the processor supports feature,
186  *  FALSE otherwise.
187  */
188 BOOL WINAPI IsProcessorFeaturePresent (
189         DWORD feature   /* [in] Feature number, (PF_ constants from "winnt.h") */) 
190 {
191   if (feature < 64)
192     return SHARED_DATA->ProcessorFeatures[feature];
193   else
194     return FALSE;
195 }