ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / kernel32 / cpu.c
blob9445d0bc056239d8275cc7275dac66e23a0e96f8
1 /*
2 * What processor?
4 * Copyright 1995,1997 Morten Welinder
5 * Copyright 1997-1998 Marcus Meissner
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.
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.
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
22 #include "config.h"
23 #include "wine/port.h"
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
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 "ddk/wdm.h"
43 #include "wine/unicode.h"
44 #include "kernel_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(reg);
49 /****************************************************************************
50 * QueryPerformanceCounter (KERNEL32.@)
52 * Get the current value of the performance counter.
54 * PARAMS
55 * counter [O] Destination for the current counter reading
57 * RETURNS
58 * Success: TRUE. counter contains the current reading
59 * Failure: FALSE.
61 * SEE ALSO
62 * See QueryPerformanceFrequency.
64 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
66 NtQueryPerformanceCounter( counter, NULL );
67 return TRUE;
71 /****************************************************************************
72 * QueryPerformanceFrequency (KERNEL32.@)
74 * Get the resolution of the performance counter.
76 * PARAMS
77 * frequency [O] Destination for the counter resolution
79 * RETURNS
80 * Success. TRUE. Frequency contains the resolution of the counter.
81 * Failure: FALSE.
83 * SEE ALSO
84 * See QueryPerformanceCounter.
86 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
88 LARGE_INTEGER counter;
89 NtQueryPerformanceCounter( &counter, frequency );
90 return TRUE;
94 /***********************************************************************
95 * GetSystemInfo [KERNEL32.@]
97 * Get information about the system.
99 * RETURNS
100 * Nothing.
102 VOID WINAPI GetSystemInfo(
103 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
105 NTSTATUS nts;
106 SYSTEM_CPU_INFORMATION sci;
108 TRACE("si=0x%p\n", si);
110 if ((nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
112 SetLastError(RtlNtStatusToDosError(nts));
113 return;
116 si->u.s.wProcessorArchitecture = sci.Architecture;
117 si->u.s.wReserved = 0;
118 si->dwPageSize = system_info.PageSize;
119 si->lpMinimumApplicationAddress = system_info.LowestUserAddress;
120 si->lpMaximumApplicationAddress = system_info.HighestUserAddress;
121 si->dwActiveProcessorMask = system_info.ActiveProcessorsAffinityMask;
122 si->dwNumberOfProcessors = system_info.NumberOfProcessors;
124 switch (sci.Architecture)
126 case PROCESSOR_ARCHITECTURE_INTEL:
127 switch (sci.Level)
129 case 3: si->dwProcessorType = PROCESSOR_INTEL_386; break;
130 case 4: si->dwProcessorType = PROCESSOR_INTEL_486; break;
131 case 5:
132 case 6: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
133 default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
135 break;
136 case PROCESSOR_ARCHITECTURE_PPC:
137 switch (sci.Level)
139 case 1: si->dwProcessorType = PROCESSOR_PPC_601; break;
140 case 3:
141 case 6: si->dwProcessorType = PROCESSOR_PPC_603; break;
142 case 4: si->dwProcessorType = PROCESSOR_PPC_604; break;
143 case 9: si->dwProcessorType = PROCESSOR_PPC_604; break;
144 case 20: si->dwProcessorType = PROCESSOR_PPC_620; break;
145 default: si->dwProcessorType = 0;
147 break;
148 case PROCESSOR_ARCHITECTURE_AMD64:
149 si->dwProcessorType = PROCESSOR_AMD_X8664;
150 break;
151 case PROCESSOR_ARCHITECTURE_ARM:
152 switch (sci.Level)
154 case 4: si->dwProcessorType = PROCESSOR_ARM_7TDMI; break;
155 default: si->dwProcessorType = PROCESSOR_ARM920;
157 break;
158 case PROCESSOR_ARCHITECTURE_ARM64:
159 si->dwProcessorType = 0;
160 break;
161 default:
162 FIXME("Unknown processor architecture %x\n", sci.Architecture);
163 si->dwProcessorType = 0;
165 si->dwAllocationGranularity = system_info.AllocationGranularity;
166 si->wProcessorLevel = sci.Level;
167 si->wProcessorRevision = sci.Revision;
171 /***********************************************************************
172 * GetNativeSystemInfo [KERNEL32.@]
174 VOID WINAPI GetNativeSystemInfo(
175 LPSYSTEM_INFO si /* [out] Destination for system information, may not be NULL */)
177 BOOL is_wow64;
179 GetSystemInfo(si);
181 IsWow64Process(GetCurrentProcess(), &is_wow64);
182 if (is_wow64)
184 if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
186 si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
187 si->dwProcessorType = PROCESSOR_AMD_X8664;
189 else
191 FIXME("Add the proper information for %d in wow64 mode\n",
192 si->u.s.wProcessorArchitecture);
197 /***********************************************************************
198 * IsProcessorFeaturePresent [KERNEL32.@]
200 * Determine if the cpu supports a given feature.
202 BOOL WINAPI IsProcessorFeaturePresent ( DWORD feature )
204 return RtlIsProcessorFeaturePresent( feature );
207 /***********************************************************************
208 * K32GetPerformanceInfo (KERNEL32.@)
210 BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
212 union
214 SYSTEM_PERFORMANCE_INFORMATION performance;
215 SYSTEM_PROCESS_INFORMATION process;
216 SYSTEM_BASIC_INFORMATION basic;
217 } *sysinfo;
218 SYSTEM_PROCESS_INFORMATION *spi;
219 DWORD process_info_size;
220 NTSTATUS status;
222 TRACE( "(%p, %d)\n", info, size );
224 if (size < sizeof(*info))
226 SetLastError( ERROR_BAD_LENGTH );
227 return FALSE;
230 memset( info, 0, sizeof(*info) );
231 info->cb = sizeof(*info);
233 /* fields from SYSTEM_PROCESS_INFORMATION */
234 NtQuerySystemInformation( SystemProcessInformation, NULL, 0, &process_info_size );
235 for (;;)
237 sysinfo = HeapAlloc( GetProcessHeap(), 0, max(process_info_size, sizeof(*sysinfo)) );
238 if (!sysinfo)
240 SetLastError( ERROR_OUTOFMEMORY );
241 return FALSE;
243 status = NtQuerySystemInformation( SystemProcessInformation, &sysinfo->process,
244 process_info_size, &process_info_size );
245 if (!status) break;
246 if (status != STATUS_INFO_LENGTH_MISMATCH)
247 goto err;
248 HeapFree( GetProcessHeap(), 0, sysinfo );
250 for (spi = &sysinfo->process;; spi = (SYSTEM_PROCESS_INFORMATION *)(((PCHAR)spi) + spi->NextEntryOffset))
252 info->ProcessCount++;
253 info->HandleCount += spi->HandleCount;
254 info->ThreadCount += spi->dwThreadCount;
255 if (spi->NextEntryOffset == 0) break;
258 /* fields from SYSTEM_PERFORMANCE_INFORMATION */
259 status = NtQuerySystemInformation( SystemPerformanceInformation, &sysinfo->performance,
260 sizeof(sysinfo->performance), NULL );
261 if (status) goto err;
262 info->CommitTotal = sysinfo->performance.TotalCommittedPages;
263 info->CommitLimit = sysinfo->performance.TotalCommitLimit;
264 info->CommitPeak = sysinfo->performance.PeakCommitment;
265 info->PhysicalAvailable = sysinfo->performance.AvailablePages;
266 info->KernelTotal = sysinfo->performance.PagedPoolUsage +
267 sysinfo->performance.NonPagedPoolUsage;
268 info->KernelPaged = sysinfo->performance.PagedPoolUsage;
269 info->KernelNonpaged = sysinfo->performance.NonPagedPoolUsage;
271 /* fields from SYSTEM_BASIC_INFORMATION */
272 status = NtQuerySystemInformation( SystemBasicInformation, &sysinfo->basic,
273 sizeof(sysinfo->basic), NULL );
274 if (status) goto err;
275 info->PhysicalTotal = sysinfo->basic.MmNumberOfPhysicalPages;
276 info->PageSize = sysinfo->basic.PageSize;
278 err:
279 HeapFree( GetProcessHeap(), 0, sysinfo );
280 if (status)
282 SetLastError( RtlNtStatusToDosError( status ) );
283 return FALSE;
285 return TRUE;
288 /***********************************************************************
289 * GetLargePageMinimum (KERNEL32.@)
291 SIZE_T WINAPI GetLargePageMinimum(void)
293 #if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
294 return 2 * 1024 * 1024;
295 #endif
296 FIXME("Not implemented on your platform/architecture.\n");
297 return 0;
300 /***********************************************************************
301 * GetActiveProcessorGroupCount (KERNEL32.@)
303 WORD WINAPI GetActiveProcessorGroupCount(void)
305 FIXME("semi-stub, always returning 1\n");
306 return 1;
309 /***********************************************************************
310 * GetActiveProcessorCount (KERNEL32.@)
312 DWORD WINAPI GetActiveProcessorCount(WORD group)
314 SYSTEM_INFO si;
315 DWORD cpus;
317 GetSystemInfo( &si );
318 cpus = si.dwNumberOfProcessors;
320 FIXME("semi-stub, returning %u\n", cpus);
321 return cpus;
324 /***********************************************************************
325 * GetMaximumProcessorCount (KERNEL32.@)
327 DWORD WINAPI GetMaximumProcessorCount(WORD group)
329 SYSTEM_INFO si;
330 DWORD cpus;
332 GetSystemInfo( &si );
333 cpus = si.dwNumberOfProcessors;
335 FIXME("semi-stub, returning %u\n", cpus);
336 return cpus;
339 /***********************************************************************
340 * GetEnabledXStateFeatures (KERNEL32.@)
342 DWORD64 WINAPI GetEnabledXStateFeatures(void)
344 FIXME("\n");
345 return 0;
348 /***********************************************************************
349 * GetSystemFirmwareTable (KERNEL32.@)
351 UINT WINAPI GetSystemFirmwareTable(DWORD provider, DWORD id, void *buffer, DWORD size)
353 ULONG buffer_size = FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer) + size;
354 SYSTEM_FIRMWARE_TABLE_INFORMATION *sfti = HeapAlloc(GetProcessHeap(), 0, buffer_size);
355 NTSTATUS status;
357 TRACE("(0x%08x, 0x%08x, %p, %d)\n", provider, id, buffer, size);
359 if (!sfti)
361 SetLastError(ERROR_OUTOFMEMORY);
362 return 0;
365 sfti->ProviderSignature = provider;
366 sfti->Action = SystemFirmwareTable_Get;
367 sfti->TableID = id;
369 status = NtQuerySystemInformation(SystemFirmwareTableInformation, sfti, buffer_size, &buffer_size);
370 buffer_size -= FIELD_OFFSET(SYSTEM_FIRMWARE_TABLE_INFORMATION, TableBuffer);
371 if (buffer_size <= size)
372 memcpy(buffer, sfti->TableBuffer, buffer_size);
374 if (status) SetLastError(RtlNtStatusToDosError(status));
375 HeapFree(GetProcessHeap(), 0, sfti);
376 return buffer_size;