cpu.c 6.67 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 * What processor?
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
4
 * Copyright 1995,1997 Morten Welinder
Alexandre Julliard's avatar
Alexandre Julliard committed
5
 * Copyright 1997-1998 Marcus Meissner
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
20 21
 */

22
#include "config.h"
23 24
#include "wine/port.h"

25
#include <stdarg.h>
26
#include <stdio.h>
27
#include <stdlib.h>
28 29 30 31
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif

32

33 34
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
35 36
#include "ntstatus.h"
#define WIN32_NO_STATUS
37
#include "windef.h"
38
#include "winbase.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
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"
Alexandre Julliard's avatar
Alexandre Julliard committed
46

47
WINE_DEFAULT_DEBUG_CHANNEL(reg);
48

49 50
#define SHARED_DATA     ((KSHARED_USER_DATA*)0x7ffe0000)

51 52
/****************************************************************************
 *		QueryPerformanceCounter (KERNEL32.@)
Jon Griffiths's avatar
Jon Griffiths committed
53 54 55 56 57 58 59 60 61 62 63 64
 *
 * Get the current value of the performance counter.
 * 
 * PARAMS
 *  counter [O] Destination for the current counter reading
 *
 * RETURNS
 *  Success: TRUE. counter contains the current reading
 *  Failure: FALSE.
 *
 * SEE ALSO
 *  See QueryPerformanceFrequency.
65 66 67
 */
BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
{
68
    NtQueryPerformanceCounter( counter, NULL );
69 70 71 72 73 74
    return TRUE;
}


/****************************************************************************
 *		QueryPerformanceFrequency (KERNEL32.@)
Jon Griffiths's avatar
Jon Griffiths committed
75
 *
76
 * Get the resolution of the performance counter.
Jon Griffiths's avatar
Jon Griffiths committed
77 78 79 80 81 82 83 84 85 86
 *
 * PARAMS
 *  frequency [O] Destination for the counter resolution
 *
 * RETURNS
 *  Success. TRUE. Frequency contains the resolution of the counter.
 *  Failure: FALSE.
 *
 * SEE ALSO
 *  See QueryPerformanceCounter.
87 88 89
 */
BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
{
90 91
    LARGE_INTEGER counter;
    NtQueryPerformanceCounter( &counter, frequency );
92 93 94
    return TRUE;
}

95

Alexandre Julliard's avatar
Alexandre Julliard committed
96
/***********************************************************************
97
 * 			GetSystemInfo            	[KERNEL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
98
 *
Jon Griffiths's avatar
Jon Griffiths committed
99
 * Get information about the system.
Alexandre Julliard's avatar
Alexandre Julliard committed
100
 *
Jon Griffiths's avatar
Jon Griffiths committed
101 102
 * RETURNS
 *  Nothing.
Alexandre Julliard's avatar
Alexandre Julliard committed
103
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
104
VOID WINAPI GetSystemInfo(
Jon Griffiths's avatar
Jon Griffiths committed
105 106
	LPSYSTEM_INFO si	/* [out] Destination for system information, may not be NULL */)
{
107 108
    NTSTATUS                 nts;
    SYSTEM_CPU_INFORMATION   sci;
Alexandre Julliard's avatar
Alexandre Julliard committed
109

110
    TRACE("si=0x%p\n", si);
Alexandre Julliard's avatar
Alexandre Julliard committed
111

112
    if ((nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
113 114 115 116
    {
        SetLastError(RtlNtStatusToDosError(nts));
        return;
    }
117

118 119
    si->u.s.wProcessorArchitecture  = sci.Architecture;
    si->u.s.wReserved               = 0;
120 121 122 123 124
    si->dwPageSize                  = system_info.PageSize;
    si->lpMinimumApplicationAddress = system_info.LowestUserAddress;
    si->lpMaximumApplicationAddress = system_info.HighestUserAddress;
    si->dwActiveProcessorMask       = system_info.ActiveProcessorsAffinityMask;
    si->dwNumberOfProcessors        = system_info.NumberOfProcessors;
125

126 127 128 129
    switch (sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_INTEL:
        switch (sci.Level)
130
        {
131 132 133 134 135
        case 3:  si->dwProcessorType = PROCESSOR_INTEL_386;     break;
        case 4:  si->dwProcessorType = PROCESSOR_INTEL_486;     break;
        case 5:
        case 6:  si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
        default: si->dwProcessorType = PROCESSOR_INTEL_PENTIUM; break;
136
        }
137 138 139 140 141 142 143 144 145 146 147 148 149
        break;
    case PROCESSOR_ARCHITECTURE_PPC:
        switch (sci.Level)
        {
        case 1:  si->dwProcessorType = PROCESSOR_PPC_601;       break;
        case 3:
        case 6:  si->dwProcessorType = PROCESSOR_PPC_603;       break;
        case 4:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
        case 9:  si->dwProcessorType = PROCESSOR_PPC_604;       break;
        case 20: si->dwProcessorType = PROCESSOR_PPC_620;       break;
        default: si->dwProcessorType = 0;
        }
        break;
150 151 152
    case PROCESSOR_ARCHITECTURE_AMD64:
        si->dwProcessorType = PROCESSOR_AMD_X8664;
        break;
153 154 155 156 157 158 159
    case PROCESSOR_ARCHITECTURE_ARM:
        switch (sci.Level)
        {
        case 4:  si->dwProcessorType = PROCESSOR_ARM_7TDMI;     break;
        default: si->dwProcessorType = PROCESSOR_ARM920;
        }
        break;
160 161 162
    default:
        FIXME("Unknown processor architecture %x\n", sci.Architecture);
        si->dwProcessorType = 0;
163
    }
164
    si->dwAllocationGranularity     = system_info.AllocationGranularity;
165 166
    si->wProcessorLevel             = sci.Level;
    si->wProcessorRevision          = sci.Revision;
Alexandre Julliard's avatar
Alexandre Julliard committed
167
}
Alexandre Julliard's avatar
Alexandre Julliard committed
168

Alexandre Julliard's avatar
Alexandre Julliard committed
169

170 171 172 173 174 175
/***********************************************************************
 * 			GetNativeSystemInfo            	[KERNEL32.@]
 */
VOID WINAPI GetNativeSystemInfo(
    LPSYSTEM_INFO si	/* [out] Destination for system information, may not be NULL */)
{
176 177
    BOOL is_wow64;

178
    GetSystemInfo(si); 
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

    IsWow64Process(GetCurrentProcess(), &is_wow64);
    if (is_wow64)
    {
        if (si->u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
        {
            si->u.s.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64;
            si->dwProcessorType = PROCESSOR_AMD_X8664;
        }
        else
        {
            FIXME("Add the proper information for %d in wow64 mode\n",
                  si->u.s.wProcessorArchitecture);
        }
    }
194 195
}

Alexandre Julliard's avatar
Alexandre Julliard committed
196
/***********************************************************************
197
 * 			IsProcessorFeaturePresent	[KERNEL32.@]
Jon Griffiths's avatar
Jon Griffiths committed
198 199 200 201 202 203
 *
 * Determine if the cpu supports a given feature.
 * 
 * RETURNS
 *  TRUE, If the processor supports feature,
 *  FALSE otherwise.
Alexandre Julliard's avatar
Alexandre Julliard committed
204
 */
205
BOOL WINAPI IsProcessorFeaturePresent (
Jon Griffiths's avatar
Jon Griffiths committed
206 207
	DWORD feature	/* [in] Feature number, (PF_ constants from "winnt.h") */) 
{
208
  if (feature < PROCESSOR_FEATURE_MAX)
209
    return SHARED_DATA->ProcessorFeatures[feature];
Alexandre Julliard's avatar
Alexandre Julliard committed
210 211
  else
    return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
212
}
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231

/***********************************************************************
 *           K32GetPerformanceInfo (KERNEL32.@)
 */
BOOL WINAPI K32GetPerformanceInfo(PPERFORMANCE_INFORMATION info, DWORD size)
{
    NTSTATUS status;

    TRACE( "(%p, %d)\n", info, size );

    status = NtQuerySystemInformation( SystemPerformanceInformation, info, size, NULL );

    if (status)
    {
        SetLastError( RtlNtStatusToDosError( status ) );
        return FALSE;
    }
    return TRUE;
}