cpu.c 6.21 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 41
#include "winternl.h"
#include "wine/unicode.h"
42
#include "wine/debug.h"
43
#include "ddk/wdm.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
44

45
WINE_DEFAULT_DEBUG_CHANNEL(reg);
46

47 48
#define SHARED_DATA     ((KSHARED_USER_DATA*)0x7ffe0000)

49 50
/****************************************************************************
 *		QueryPerformanceCounter (KERNEL32.@)
Jon Griffiths's avatar
Jon Griffiths committed
51 52 53 54 55 56 57 58 59 60 61 62
 *
 * 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.
63 64 65
 */
BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
{
66
    NtQueryPerformanceCounter( counter, NULL );
67 68 69 70 71 72
    return TRUE;
}


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

93

Alexandre Julliard's avatar
Alexandre Julliard committed
94
/***********************************************************************
95
 * 			GetSystemInfo            	[KERNEL32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
96
 *
Jon Griffiths's avatar
Jon Griffiths committed
97
 * Get information about the system.
Alexandre Julliard's avatar
Alexandre Julliard committed
98
 *
Jon Griffiths's avatar
Jon Griffiths committed
99 100 101 102
 * RETURNS
 *  Nothing.
 *
 * NOTES
103
 * On the first call it creates cached values, so it doesn't have to determine
Jon Griffiths's avatar
Jon Griffiths committed
104
 * them repeatedly. On Linux, the "/proc/cpuinfo" special file is used.
Alexandre Julliard's avatar
Alexandre Julliard committed
105 106
 *
 * It also creates a cached flag array for IsProcessorFeaturePresent().
Alexandre Julliard's avatar
Alexandre Julliard committed
107
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
108
VOID WINAPI GetSystemInfo(
Jon Griffiths's avatar
Jon Griffiths committed
109 110
	LPSYSTEM_INFO si	/* [out] Destination for system information, may not be NULL */)
{
111 112 113
    NTSTATUS                 nts;
    SYSTEM_BASIC_INFORMATION sbi;
    SYSTEM_CPU_INFORMATION   sci;
Alexandre Julliard's avatar
Alexandre Julliard committed
114

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

117 118 119 120 121 122
    if ((nts = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL )) != STATUS_SUCCESS ||
        (nts = NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL )) != STATUS_SUCCESS)
    {
        SetLastError(RtlNtStatusToDosError(nts));
        return;
    }
123

124 125 126 127 128 129 130
    si->u.s.wProcessorArchitecture  = sci.Architecture;
    si->u.s.wReserved               = 0;
    si->dwPageSize                  = sbi.PageSize;
    si->lpMinimumApplicationAddress = sbi.LowestUserAddress;
    si->lpMaximumApplicationAddress = sbi.HighestUserAddress;
    si->dwActiveProcessorMask       = sbi.ActiveProcessorsAffinityMask;
    si->dwNumberOfProcessors        = sbi.NumberOfProcessors;
131

132 133 134 135
    switch (sci.Architecture)
    {
    case PROCESSOR_ARCHITECTURE_INTEL:
        switch (sci.Level)
136
        {
137 138 139 140 141
        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;
142
        }
143 144 145 146 147 148 149 150 151 152 153 154 155
        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;
156 157 158
    case PROCESSOR_ARCHITECTURE_AMD64:
        si->dwProcessorType = PROCESSOR_AMD_X8664;
        break;
159 160 161 162 163
    default: FIXME("Unknown processor architecture %x\n", sci.Architecture);
    }
    si->dwAllocationGranularity     = sbi.AllocationGranularity;
    si->wProcessorLevel             = sci.Level;
    si->wProcessorRevision          = sci.Revision;
Alexandre Julliard's avatar
Alexandre Julliard committed
164
}
Alexandre Julliard's avatar
Alexandre Julliard committed
165

Alexandre Julliard's avatar
Alexandre Julliard committed
166

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

175
    GetSystemInfo(si); 
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

    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);
        }
    }
191 192
}

Alexandre Julliard's avatar
Alexandre Julliard committed
193
/***********************************************************************
194
 * 			IsProcessorFeaturePresent	[KERNEL32.@]
Jon Griffiths's avatar
Jon Griffiths committed
195 196 197 198 199 200
 *
 * Determine if the cpu supports a given feature.
 * 
 * RETURNS
 *  TRUE, If the processor supports feature,
 *  FALSE otherwise.
Alexandre Julliard's avatar
Alexandre Julliard committed
201
 */
202
BOOL WINAPI IsProcessorFeaturePresent (
Jon Griffiths's avatar
Jon Griffiths committed
203 204
	DWORD feature	/* [in] Feature number, (PF_ constants from "winnt.h") */) 
{
Alexandre Julliard's avatar
Alexandre Julliard committed
205
  if (feature < 64)
206
    return SHARED_DATA->ProcessorFeatures[feature];
Alexandre Julliard's avatar
Alexandre Julliard committed
207 208
  else
    return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
209
}