VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/CPUMR3Db.cpp@ 59083

Last change on this file since 59083 was 58653, checked in by vboxsync, 9 years ago

Forgot to add Intel_Core_i7_6700K.h before comitting it. duh.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.0 KB
Line 
1/* $Id: CPUMR3Db.cpp 58653 2015-11-10 22:53:17Z vboxsync $ */
2/** @file
3 * CPUM - CPU database part.
4 */
5
6/*
7 * Copyright (C) 2013-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_CPUM
23#include <VBox/vmm/cpum.h>
24#include "CPUMInternal.h"
25#include <VBox/vmm/vm.h>
26#include <VBox/vmm/mm.h>
27
28#include <VBox/err.h>
29#include <iprt/asm-amd64-x86.h>
30#include <iprt/mem.h>
31#include <iprt/string.h>
32
33
34/*********************************************************************************************************************************
35* Structures and Typedefs *
36*********************************************************************************************************************************/
37typedef struct CPUMDBENTRY
38{
39 /** The CPU name. */
40 const char *pszName;
41 /** The full CPU name. */
42 const char *pszFullName;
43 /** The CPU vendor (CPUMCPUVENDOR). */
44 uint8_t enmVendor;
45 /** The CPU family. */
46 uint8_t uFamily;
47 /** The CPU model. */
48 uint8_t uModel;
49 /** The CPU stepping. */
50 uint8_t uStepping;
51 /** The microarchitecture. */
52 CPUMMICROARCH enmMicroarch;
53 /** Scalable bus frequency used for reporting other frequencies. */
54 uint64_t uScalableBusFreq;
55 /** Flags (TBD). */
56 uint32_t fFlags;
57 /** The maximum physical address with of the CPU. This should correspond to
58 * the value in CPUID leaf 0x80000008 when present. */
59 uint8_t cMaxPhysAddrWidth;
60 /** Pointer to an array of CPUID leaves. */
61 PCCPUMCPUIDLEAF paCpuIdLeaves;
62 /** The number of CPUID leaves in the array paCpuIdLeaves points to. */
63 uint32_t cCpuIdLeaves;
64 /** The method used to deal with unknown CPUID leaves. */
65 CPUMUNKNOWNCPUID enmUnknownCpuId;
66 /** The default unknown CPUID value. */
67 CPUMCPUID DefUnknownCpuId;
68
69 /** MSR mask. Several microarchitectures ignore higher bits of the */
70 uint32_t fMsrMask;
71
72 /** The number of ranges in the table pointed to b paMsrRanges. */
73 uint32_t cMsrRanges;
74 /** MSR ranges for this CPU. */
75 PCCPUMMSRRANGE paMsrRanges;
76} CPUMDBENTRY;
77
78
79/*********************************************************************************************************************************
80* Defined Constants And Macros *
81*********************************************************************************************************************************/
82
83/** @def NULL_ALONE
84 * For eliminating an unnecessary data dependency in standalone builds (for
85 * VBoxSVC). */
86/** @def ZERO_ALONE
87 * For eliminating an unnecessary data size dependency in standalone builds (for
88 * VBoxSVC). */
89#ifndef CPUM_DB_STANDALONE
90# define NULL_ALONE(a_aTable) a_aTable
91# define ZERO_ALONE(a_cTable) a_cTable
92#else
93# define NULL_ALONE(a_aTable) NULL
94# define ZERO_ALONE(a_cTable) 0
95#endif
96
97
98/** @name Short macros for the MSR range entries.
99 *
100 * These are rather cryptic, but this is to reduce the attack on the right
101 * margin.
102 *
103 * @{ */
104/** Alias one MSR onto another (a_uTarget). */
105#define MAL(a_uMsr, a_szName, a_uTarget) \
106 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_MsrAlias, kCpumMsrWrFn_MsrAlias, 0, a_uTarget, 0, 0, a_szName)
107/** Functions handles everything. */
108#define MFN(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff) \
109 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, 0, 0, 0, a_szName)
110/** Functions handles everything, with GP mask. */
111#define MFG(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_fWrGpMask) \
112 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, 0, 0, a_fWrGpMask, a_szName)
113/** Function handlers, read-only. */
114#define MFO(a_uMsr, a_szName, a_enmRdFnSuff) \
115 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_ReadOnly, 0, 0, 0, UINT64_MAX, a_szName)
116/** Function handlers, ignore all writes. */
117#define MFI(a_uMsr, a_szName, a_enmRdFnSuff) \
118 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_IgnoreWrite, 0, 0, UINT64_MAX, 0, a_szName)
119/** Function handlers, with value. */
120#define MFV(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_uValue) \
121 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, a_uValue, 0, 0, a_szName)
122/** Function handlers, with write ignore mask. */
123#define MFW(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_fWrIgnMask) \
124 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, 0, a_fWrIgnMask, 0, a_szName)
125/** Function handlers, extended version. */
126#define MFX(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_uValue, a_fWrIgnMask, a_fWrGpMask) \
127 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, a_uValue, a_fWrIgnMask, a_fWrGpMask, a_szName)
128/** Function handlers, with CPUMCPU storage variable. */
129#define MFS(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_CpumCpuMember) \
130 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, \
131 RT_OFFSETOF(CPUMCPU, a_CpumCpuMember), 0, 0, 0, a_szName)
132/** Function handlers, with CPUMCPU storage variable, ignore mask and GP mask. */
133#define MFZ(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_CpumCpuMember, a_fWrIgnMask, a_fWrGpMask) \
134 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, \
135 RT_OFFSETOF(CPUMCPU, a_CpumCpuMember), 0, a_fWrIgnMask, a_fWrGpMask, a_szName)
136/** Read-only fixed value. */
137#define MVO(a_uMsr, a_szName, a_uValue) \
138 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_ReadOnly, 0, a_uValue, 0, UINT64_MAX, a_szName)
139/** Read-only fixed value, ignores all writes. */
140#define MVI(a_uMsr, a_szName, a_uValue) \
141 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_IgnoreWrite, 0, a_uValue, UINT64_MAX, 0, a_szName)
142/** Read fixed value, ignore writes outside GP mask. */
143#define MVG(a_uMsr, a_szName, a_uValue, a_fWrGpMask) \
144 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_IgnoreWrite, 0, a_uValue, 0, a_fWrGpMask, a_szName)
145/** Read fixed value, extended version with both GP and ignore masks. */
146#define MVX(a_uMsr, a_szName, a_uValue, a_fWrIgnMask, a_fWrGpMask) \
147 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_IgnoreWrite, 0, a_uValue, a_fWrIgnMask, a_fWrGpMask, a_szName)
148/** The short form, no CPUM backing. */
149#define MSN(a_uMsr, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask) \
150 RINT(a_uMsr, a_uMsr, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, \
151 a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName)
152
153/** Range: Functions handles everything. */
154#define RFN(a_uFirst, a_uLast, a_szName, a_enmRdFnSuff, a_enmWrFnSuff) \
155 RINT(a_uFirst, a_uLast, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, 0, 0, 0, a_szName)
156/** Range: Read fixed value, read-only. */
157#define RVO(a_uFirst, a_uLast, a_szName, a_uValue) \
158 RINT(a_uFirst, a_uLast, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_ReadOnly, 0, a_uValue, 0, UINT64_MAX, a_szName)
159/** Range: Read fixed value, ignore writes. */
160#define RVI(a_uFirst, a_uLast, a_szName, a_uValue) \
161 RINT(a_uFirst, a_uLast, kCpumMsrRdFn_FixedValue, kCpumMsrWrFn_IgnoreWrite, 0, a_uValue, UINT64_MAX, 0, a_szName)
162/** Range: The short form, no CPUM backing. */
163#define RSN(a_uFirst, a_uLast, a_szName, a_enmRdFnSuff, a_enmWrFnSuff, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask) \
164 RINT(a_uFirst, a_uLast, kCpumMsrRdFn_##a_enmRdFnSuff, kCpumMsrWrFn_##a_enmWrFnSuff, 0, \
165 a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName)
166
167/** Internal form used by the macros. */
168#ifdef VBOX_WITH_STATISTICS
169# define RINT(a_uFirst, a_uLast, a_enmRdFn, a_enmWrFn, a_offCpumCpu, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName) \
170 { a_uFirst, a_uLast, a_enmRdFn, a_enmWrFn, a_offCpumCpu, 0, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName, \
171 { 0 }, { 0 }, { 0 }, { 0 } }
172#else
173# define RINT(a_uFirst, a_uLast, a_enmRdFn, a_enmWrFn, a_offCpumCpu, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName) \
174 { a_uFirst, a_uLast, a_enmRdFn, a_enmWrFn, a_offCpumCpu, 0, a_uInitOrReadValue, a_fWrIgnMask, a_fWrGpMask, a_szName }
175#endif
176/** @} */
177
178
179#include "cpus/Intel_Core_i7_6700K.h"
180#include "cpus/Intel_Core_i7_5600U.h"
181#include "cpus/Intel_Core_i7_3960X.h"
182#include "cpus/Intel_Core_i5_3570.h"
183#include "cpus/Intel_Core_i7_2635QM.h"
184#include "cpus/Intel_Xeon_X5482_3_20GHz.h"
185#include "cpus/Intel_Pentium_M_processor_2_00GHz.h"
186#include "cpus/Intel_Pentium_4_3_00GHz.h"
187#include "cpus/Intel_Atom_330_1_60GHz.h"
188
189#include "cpus/AMD_FX_8150_Eight_Core.h"
190#include "cpus/AMD_Phenom_II_X6_1100T.h"
191#include "cpus/Quad_Core_AMD_Opteron_2384.h"
192#include "cpus/AMD_Athlon_64_X2_Dual_Core_4200.h"
193#include "cpus/AMD_Athlon_64_3200.h"
194
195#include "cpus/VIA_QuadCore_L4700_1_2_GHz.h"
196
197
198
199/**
200 * The database entries.
201 *
202 * 1. The first entry is special. It is the fallback for unknown
203 * processors. Thus, it better be pretty representative.
204 *
205 * 2. The first entry for a CPU vendor is likewise important as it is
206 * the default entry for that vendor.
207 *
208 * Generally we put the most recent CPUs first, since these tend to have the
209 * most complicated and backwards compatible list of MSRs.
210 */
211static CPUMDBENTRY const * const g_apCpumDbEntries[] =
212{
213#ifdef VBOX_CPUDB_Intel_Core_i7_6700K
214 &g_Entry_Intel_Core_i7_6700K,
215#endif
216#ifdef VBOX_CPUDB_Intel_Core_i7_5600U
217 &g_Entry_Intel_Core_i7_5600U,
218#endif
219#ifdef VBOX_CPUDB_Intel_Core_i5_3570
220 &g_Entry_Intel_Core_i5_3570,
221#endif
222#ifdef VBOX_CPUDB_Intel_Core_i7_3960X
223 &g_Entry_Intel_Core_i7_3960X,
224#endif
225#ifdef VBOX_CPUDB_Intel_Core_i7_2635QM
226 &g_Entry_Intel_Core_i7_2635QM,
227#endif
228#ifdef VBOX_CPUDB_Intel_Atom_330_1_60GHz
229 &g_Entry_Intel_Atom_330_1_60GHz,
230#endif
231#ifdef Intel_Pentium_M_processor_2_00GHz
232 &g_Entry_Intel_Pentium_M_processor_2_00GHz,
233#endif
234#ifdef VBOX_CPUDB_Intel_Xeon_X5482_3_20GHz
235 &g_Entry_Intel_Xeon_X5482_3_20GHz,
236#endif
237#ifdef VBOX_CPUDB_Intel_Pentium_4_3_00GHz
238 &g_Entry_Intel_Pentium_4_3_00GHz,
239#endif
240
241#ifdef VBOX_CPUDB_AMD_FX_8150_Eight_Core
242 &g_Entry_AMD_FX_8150_Eight_Core,
243#endif
244#ifdef VBOX_CPUDB_AMD_Phenom_II_X6_1100T
245 &g_Entry_AMD_Phenom_II_X6_1100T,
246#endif
247#ifdef VBOX_CPUDB_Quad_Core_AMD_Opteron_2384
248 &g_Entry_Quad_Core_AMD_Opteron_2384,
249#endif
250#ifdef VBOX_CPUDB_AMD_Athlon_64_X2_Dual_Core_4200
251 &g_Entry_AMD_Athlon_64_X2_Dual_Core_4200,
252#endif
253#ifdef VBOX_CPUDB_AMD_Athlon_64_3200
254 &g_Entry_AMD_Athlon_64_3200,
255#endif
256
257#ifdef VBOX_CPUDB_VIA_QuadCore_L4700_1_2_GHz
258 &g_Entry_VIA_QuadCore_L4700_1_2_GHz,
259#endif
260};
261
262
263#ifndef CPUM_DB_STANDALONE
264
265/**
266 * Binary search used by cpumR3MsrRangesInsert and has some special properties
267 * wrt to mismatches.
268 *
269 * @returns Insert location.
270 * @param paMsrRanges The MSR ranges to search.
271 * @param cMsrRanges The number of MSR ranges.
272 * @param uMsr What to search for.
273 */
274static uint32_t cpumR3MsrRangesBinSearch(PCCPUMMSRRANGE paMsrRanges, uint32_t cMsrRanges, uint32_t uMsr)
275{
276 if (!cMsrRanges)
277 return 0;
278
279 uint32_t iStart = 0;
280 uint32_t iLast = cMsrRanges - 1;
281 for (;;)
282 {
283 uint32_t i = iStart + (iLast - iStart + 1) / 2;
284 if ( uMsr >= paMsrRanges[i].uFirst
285 && uMsr <= paMsrRanges[i].uLast)
286 return i;
287 if (uMsr < paMsrRanges[i].uFirst)
288 {
289 if (i <= iStart)
290 return i;
291 iLast = i - 1;
292 }
293 else
294 {
295 if (i >= iLast)
296 {
297 if (i < cMsrRanges)
298 i++;
299 return i;
300 }
301 iStart = i + 1;
302 }
303 }
304}
305
306
307/**
308 * Ensures that there is space for at least @a cNewRanges in the table,
309 * reallocating the table if necessary.
310 *
311 * @returns Pointer to the MSR ranges on success, NULL on failure. On failure
312 * @a *ppaMsrRanges is freed and set to NULL.
313 * @param pVM The cross context VM structure. If NULL,
314 * use the process heap, otherwise the VM's hyper heap.
315 * @param ppaMsrRanges The variable pointing to the ranges (input/output).
316 * @param cMsrRanges The current number of ranges.
317 * @param cNewRanges The number of ranges to be added.
318 */
319static PCPUMMSRRANGE cpumR3MsrRangesEnsureSpace(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t cMsrRanges, uint32_t cNewRanges)
320{
321 uint32_t cMsrRangesAllocated;
322 if (!pVM)
323 cMsrRangesAllocated = RT_ALIGN_32(cMsrRanges, 16);
324 else
325 {
326 /*
327 * We're using the hyper heap now, but when the range array was copied over to it from
328 * the host-context heap, we only copy the exact size and not the ensured size.
329 * See @bugref{7270}.
330 */
331 cMsrRangesAllocated = cMsrRanges;
332 }
333 if (cMsrRangesAllocated < cMsrRanges + cNewRanges)
334 {
335 void *pvNew;
336 uint32_t cNew = RT_ALIGN_32(cMsrRanges + cNewRanges, 16);
337 if (pVM)
338 {
339 Assert(ppaMsrRanges == &pVM->cpum.s.GuestInfo.paMsrRangesR3);
340 Assert(cMsrRanges == pVM->cpum.s.GuestInfo.cMsrRanges);
341
342 size_t cb = cMsrRangesAllocated * sizeof(**ppaMsrRanges);
343 size_t cbNew = cNew * sizeof(**ppaMsrRanges);
344 int rc = MMR3HyperRealloc(pVM, *ppaMsrRanges, cb, 32, MM_TAG_CPUM_MSRS, cbNew, &pvNew);
345 if (RT_FAILURE(rc))
346 {
347 *ppaMsrRanges = NULL;
348 pVM->cpum.s.GuestInfo.paMsrRangesR0 = NIL_RTR0PTR;
349 pVM->cpum.s.GuestInfo.paMsrRangesRC = NIL_RTRCPTR;
350 LogRel(("CPUM: cpumR3MsrRangesEnsureSpace: MMR3HyperRealloc failed. rc=%Rrc\n", rc));
351 return NULL;
352 }
353 *ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
354 }
355 else
356 {
357 pvNew = RTMemRealloc(*ppaMsrRanges, cNew * sizeof(**ppaMsrRanges));
358 if (!pvNew)
359 {
360 RTMemFree(*ppaMsrRanges);
361 *ppaMsrRanges = NULL;
362 return NULL;
363 }
364 }
365 *ppaMsrRanges = (PCPUMMSRRANGE)pvNew;
366 }
367
368 if (pVM)
369 {
370 /* Update R0 and RC pointers. */
371 Assert(ppaMsrRanges == &pVM->cpum.s.GuestInfo.paMsrRangesR3);
372 pVM->cpum.s.GuestInfo.paMsrRangesR0 = MMHyperR3ToR0(pVM, *ppaMsrRanges);
373 pVM->cpum.s.GuestInfo.paMsrRangesRC = MMHyperR3ToRC(pVM, *ppaMsrRanges);
374 }
375
376 return *ppaMsrRanges;
377}
378
379
380/**
381 * Inserts a new MSR range in into an sorted MSR range array.
382 *
383 * If the new MSR range overlaps existing ranges, the existing ones will be
384 * adjusted/removed to fit in the new one.
385 *
386 * @returns VBox status code.
387 * @retval VINF_SUCCESS
388 * @retval VERR_NO_MEMORY
389 *
390 * @param pVM The cross context VM structure. If NULL,
391 * use the process heap, otherwise the VM's hyper heap.
392 * @param ppaMsrRanges The variable pointing to the ranges (input/output).
393 * Must be NULL if using the hyper heap.
394 * @param pcMsrRanges The variable holding number of ranges. Must be NULL
395 * if using the hyper heap.
396 * @param pNewRange The new range.
397 */
398int cpumR3MsrRangesInsert(PVM pVM, PCPUMMSRRANGE *ppaMsrRanges, uint32_t *pcMsrRanges, PCCPUMMSRRANGE pNewRange)
399{
400 Assert(pNewRange->uLast >= pNewRange->uFirst);
401 Assert(pNewRange->enmRdFn > kCpumMsrRdFn_Invalid && pNewRange->enmRdFn < kCpumMsrRdFn_End);
402 Assert(pNewRange->enmWrFn > kCpumMsrWrFn_Invalid && pNewRange->enmWrFn < kCpumMsrWrFn_End);
403
404 /*
405 * Validate and use the VM's MSR ranges array if we are using the hyper heap.
406 */
407 if (pVM)
408 {
409 AssertReturn(!ppaMsrRanges, VERR_INVALID_PARAMETER);
410 AssertReturn(!pcMsrRanges, VERR_INVALID_PARAMETER);
411
412 ppaMsrRanges = &pVM->cpum.s.GuestInfo.paMsrRangesR3;
413 pcMsrRanges = &pVM->cpum.s.GuestInfo.cMsrRanges;
414 }
415
416 uint32_t cMsrRanges = *pcMsrRanges;
417 PCPUMMSRRANGE paMsrRanges = *ppaMsrRanges;
418
419 /*
420 * Optimize the linear insertion case where we add new entries at the end.
421 */
422 if ( cMsrRanges > 0
423 && paMsrRanges[cMsrRanges - 1].uLast < pNewRange->uFirst)
424 {
425 paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
426 if (!paMsrRanges)
427 return VERR_NO_MEMORY;
428 paMsrRanges[cMsrRanges] = *pNewRange;
429 *pcMsrRanges += 1;
430 }
431 else
432 {
433 uint32_t i = cpumR3MsrRangesBinSearch(paMsrRanges, cMsrRanges, pNewRange->uFirst);
434 Assert(i == cMsrRanges || pNewRange->uFirst <= paMsrRanges[i].uLast);
435 Assert(i == 0 || pNewRange->uFirst > paMsrRanges[i - 1].uLast);
436
437 /*
438 * Adding an entirely new entry?
439 */
440 if ( i >= cMsrRanges
441 || pNewRange->uLast < paMsrRanges[i].uFirst)
442 {
443 paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
444 if (!paMsrRanges)
445 return VERR_NO_MEMORY;
446 if (i < cMsrRanges)
447 memmove(&paMsrRanges[i + 1], &paMsrRanges[i], (cMsrRanges - i) * sizeof(paMsrRanges[0]));
448 paMsrRanges[i] = *pNewRange;
449 *pcMsrRanges += 1;
450 }
451 /*
452 * Replace existing entry?
453 */
454 else if ( pNewRange->uFirst == paMsrRanges[i].uFirst
455 && pNewRange->uLast == paMsrRanges[i].uLast)
456 paMsrRanges[i] = *pNewRange;
457 /*
458 * Splitting an existing entry?
459 */
460 else if ( pNewRange->uFirst > paMsrRanges[i].uFirst
461 && pNewRange->uLast < paMsrRanges[i].uLast)
462 {
463 paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 2);
464 if (!paMsrRanges)
465 return VERR_NO_MEMORY;
466 if (i < cMsrRanges)
467 memmove(&paMsrRanges[i + 2], &paMsrRanges[i], (cMsrRanges - i) * sizeof(paMsrRanges[0]));
468 paMsrRanges[i + 1] = *pNewRange;
469 paMsrRanges[i + 2] = paMsrRanges[i];
470 paMsrRanges[i ].uLast = pNewRange->uFirst - 1;
471 paMsrRanges[i + 2].uFirst = pNewRange->uLast + 1;
472 *pcMsrRanges += 2;
473 }
474 /*
475 * Complicated scenarios that can affect more than one range.
476 *
477 * The current code does not optimize memmove calls when replacing
478 * one or more existing ranges, because it's tedious to deal with and
479 * not expected to be a frequent usage scenario.
480 */
481 else
482 {
483 /* Adjust start of first match? */
484 if ( pNewRange->uFirst <= paMsrRanges[i].uFirst
485 && pNewRange->uLast < paMsrRanges[i].uLast)
486 paMsrRanges[i].uFirst = pNewRange->uLast + 1;
487 else
488 {
489 /* Adjust end of first match? */
490 if (pNewRange->uFirst > paMsrRanges[i].uFirst)
491 {
492 Assert(paMsrRanges[i].uLast >= pNewRange->uFirst);
493 paMsrRanges[i].uLast = pNewRange->uFirst - 1;
494 i++;
495 }
496 /* Replace the whole first match (lazy bird). */
497 else
498 {
499 if (i + 1 < cMsrRanges)
500 memmove(&paMsrRanges[i], &paMsrRanges[i + 1], (cMsrRanges - i - 1) * sizeof(paMsrRanges[0]));
501 cMsrRanges = *pcMsrRanges -= 1;
502 }
503
504 /* Do the new range affect more ranges? */
505 while ( i < cMsrRanges
506 && pNewRange->uLast >= paMsrRanges[i].uFirst)
507 {
508 if (pNewRange->uLast < paMsrRanges[i].uLast)
509 {
510 /* Adjust the start of it, then we're done. */
511 paMsrRanges[i].uFirst = pNewRange->uLast + 1;
512 break;
513 }
514
515 /* Remove it entirely. */
516 if (i + 1 < cMsrRanges)
517 memmove(&paMsrRanges[i], &paMsrRanges[i + 1], (cMsrRanges - i - 1) * sizeof(paMsrRanges[0]));
518 cMsrRanges = *pcMsrRanges -= 1;
519 }
520 }
521
522 /* Now, perform a normal insertion. */
523 paMsrRanges = cpumR3MsrRangesEnsureSpace(pVM, ppaMsrRanges, cMsrRanges, 1);
524 if (!paMsrRanges)
525 return VERR_NO_MEMORY;
526 if (i < cMsrRanges)
527 memmove(&paMsrRanges[i + 1], &paMsrRanges[i], (cMsrRanges - i) * sizeof(paMsrRanges[0]));
528 paMsrRanges[i] = *pNewRange;
529 *pcMsrRanges += 1;
530 }
531 }
532
533 return VINF_SUCCESS;
534}
535
536
537/**
538 * Worker for cpumR3MsrApplyFudge that applies one table.
539 *
540 * @returns VBox status code.
541 * @param pVM The cross context VM structure.
542 * @param paRanges Array of MSRs to fudge.
543 * @param cRanges Number of MSRs in the array.
544 */
545static int cpumR3MsrApplyFudgeTable(PVM pVM, PCCPUMMSRRANGE paRanges, size_t cRanges)
546{
547 for (uint32_t i = 0; i < cRanges; i++)
548 if (!cpumLookupMsrRange(pVM, paRanges[i].uFirst))
549 {
550 LogRel(("CPUM: MSR fudge: %#010x %s\n", paRanges[i].uFirst, paRanges[i].szName));
551 int rc = cpumR3MsrRangesInsert(NULL /* pVM */, &pVM->cpum.s.GuestInfo.paMsrRangesR3, &pVM->cpum.s.GuestInfo.cMsrRanges,
552 &paRanges[i]);
553 if (RT_FAILURE(rc))
554 return rc;
555 }
556 return VINF_SUCCESS;
557}
558
559
560/**
561 * Fudges the MSRs that guest are known to access in some odd cases.
562 *
563 * A typical example is a VM that has been moved between different hosts where
564 * for instance the cpu vendor differs.
565 *
566 * @returns VBox status code.
567 * @param pVM The cross context VM structure.
568 */
569int cpumR3MsrApplyFudge(PVM pVM)
570{
571 /*
572 * Basic.
573 */
574 static CPUMMSRRANGE const s_aFudgeMsrs[] =
575 {
576 MFO(0x00000000, "IA32_P5_MC_ADDR", Ia32P5McAddr),
577 MFX(0x00000001, "IA32_P5_MC_TYPE", Ia32P5McType, Ia32P5McType, 0, 0, UINT64_MAX),
578 MVO(0x00000017, "IA32_PLATFORM_ID", 0),
579 MFN(0x0000001b, "IA32_APIC_BASE", Ia32ApicBase, Ia32ApicBase),
580 MVI(0x0000008b, "BIOS_SIGN", 0),
581 MFX(0x000000fe, "IA32_MTRRCAP", Ia32MtrrCap, ReadOnly, 0x508, 0, 0),
582 MFX(0x00000179, "IA32_MCG_CAP", Ia32McgCap, ReadOnly, 0x005, 0, 0),
583 MFX(0x0000017a, "IA32_MCG_STATUS", Ia32McgStatus, Ia32McgStatus, 0, ~(uint64_t)UINT32_MAX, 0),
584 MFN(0x000001a0, "IA32_MISC_ENABLE", Ia32MiscEnable, Ia32MiscEnable),
585 MFN(0x000001d9, "IA32_DEBUGCTL", Ia32DebugCtl, Ia32DebugCtl),
586 MFO(0x000001db, "P6_LAST_BRANCH_FROM_IP", P6LastBranchFromIp),
587 MFO(0x000001dc, "P6_LAST_BRANCH_TO_IP", P6LastBranchToIp),
588 MFO(0x000001dd, "P6_LAST_INT_FROM_IP", P6LastIntFromIp),
589 MFO(0x000001de, "P6_LAST_INT_TO_IP", P6LastIntToIp),
590 MFS(0x00000277, "IA32_PAT", Ia32Pat, Ia32Pat, Guest.msrPAT),
591 MFZ(0x000002ff, "IA32_MTRR_DEF_TYPE", Ia32MtrrDefType, Ia32MtrrDefType, GuestMsrs.msr.MtrrDefType, 0, ~(uint64_t)0xc07),
592 MFN(0x00000400, "IA32_MCi_CTL_STATUS_ADDR_MISC", Ia32McCtlStatusAddrMiscN, Ia32McCtlStatusAddrMiscN),
593 };
594 int rc = cpumR3MsrApplyFudgeTable(pVM, &s_aFudgeMsrs[0], RT_ELEMENTS(s_aFudgeMsrs));
595 AssertLogRelRCReturn(rc, rc);
596
597 /*
598 * XP might mistake opterons and other newer CPUs for P4s.
599 */
600 if (pVM->cpum.s.GuestFeatures.uFamily >= 0xf)
601 {
602 static CPUMMSRRANGE const s_aP4FudgeMsrs[] =
603 {
604 MFX(0x0000002c, "P4_EBC_FREQUENCY_ID", IntelP4EbcFrequencyId, IntelP4EbcFrequencyId, 0xf12010f, UINT64_MAX, 0),
605 };
606 rc = cpumR3MsrApplyFudgeTable(pVM, &s_aP4FudgeMsrs[0], RT_ELEMENTS(s_aP4FudgeMsrs));
607 AssertLogRelRCReturn(rc, rc);
608 }
609
610 return rc;
611}
612
613
614/**
615 * Do we consider @a enmConsider a better match for @a enmTarget than
616 * @a enmFound?
617 *
618 * Only called when @a enmConsider isn't exactly what we're looking for.
619 *
620 * @returns true/false.
621 * @param enmConsider The new microarch to consider.
622 * @param enmTarget The target microarch.
623 * @param enmFound The best microarch match we've found thus far.
624 */
625DECLINLINE(bool) cpumR3DbIsBetterMarchMatch(CPUMMICROARCH enmConsider, CPUMMICROARCH enmTarget, CPUMMICROARCH enmFound)
626{
627 Assert(enmConsider != enmTarget);
628
629 /*
630 * If we've got an march match, don't bother with enmConsider.
631 */
632 if (enmFound == enmTarget)
633 return false;
634
635 /*
636 * Found is below: Pick 'consider' if it's closer to the target or above it.
637 */
638 if (enmFound < enmTarget)
639 return enmConsider > enmFound;
640
641 /*
642 * Found is above: Pick 'consider' if it's also above (paranoia: or equal)
643 * and but closer to the target.
644 */
645 return enmConsider >= enmTarget && enmConsider < enmFound;
646}
647
648
649/**
650 * Do we consider @a enmConsider a better match for @a enmTarget than
651 * @a enmFound?
652 *
653 * Only called for intel family 06h CPUs.
654 *
655 * @returns true/false.
656 * @param enmConsider The new microarch to consider.
657 * @param enmTarget The target microarch.
658 * @param enmFound The best microarch match we've found thus far.
659 */
660static bool cpumR3DbIsBetterIntelFam06Match(CPUMMICROARCH enmConsider, CPUMMICROARCH enmTarget, CPUMMICROARCH enmFound)
661{
662 /* Check intel family 06h claims. */
663 AssertReturn(enmConsider >= kCpumMicroarch_Intel_P6_Core_Atom_First && enmConsider <= kCpumMicroarch_Intel_P6_Core_Atom_End,
664 false);
665 AssertReturn(enmTarget >= kCpumMicroarch_Intel_P6_Core_Atom_First && enmTarget <= kCpumMicroarch_Intel_P6_Core_Atom_End,
666 false);
667
668 /* Put matches out of the way. */
669 if (enmConsider == enmTarget)
670 return true;
671 if (enmFound == enmTarget)
672 return false;
673
674 /* If found isn't a family 06h march, whatever we're considering must be a better choice. */
675 if ( enmFound < kCpumMicroarch_Intel_P6_Core_Atom_First
676 || enmFound > kCpumMicroarch_Intel_P6_Core_Atom_End)
677 return true;
678
679 /*
680 * The family 06h stuff is split into three categories:
681 * - Common P6 heritage
682 * - Core
683 * - Atom
684 *
685 * Determin which of the three arguments are Atom marchs, because that's
686 * all we need to make the right choice.
687 */
688 bool const fConsiderAtom = enmConsider >= kCpumMicroarch_Intel_Atom_First;
689 bool const fTargetAtom = enmTarget >= kCpumMicroarch_Intel_Atom_First;
690 bool const fFoundAtom = enmFound >= kCpumMicroarch_Intel_Atom_First;
691
692 /*
693 * Want atom:
694 */
695 if (fTargetAtom)
696 {
697 /* Pick the atom if we've got one of each.*/
698 if (fConsiderAtom != fFoundAtom)
699 return fConsiderAtom;
700 /* If we haven't got any atoms under consideration, pick a P6 or the earlier core.
701 Note! Not entirely sure Dothan is the best choice, but it'll do for now. */
702 if (!fConsiderAtom)
703 {
704 if (enmConsider > enmFound)
705 return enmConsider <= kCpumMicroarch_Intel_P6_M_Dothan;
706 return enmFound > kCpumMicroarch_Intel_P6_M_Dothan;
707 }
708 /* else: same category, default comparison rules. */
709 Assert(fConsiderAtom && fFoundAtom);
710 }
711 /*
712 * Want non-atom:
713 */
714 /* Pick the non-atom if we've got one of each. */
715 else if (fConsiderAtom != fFoundAtom)
716 return fFoundAtom;
717 /* If we've only got atoms under consideration, pick the older one just to pick something. */
718 else if (fConsiderAtom)
719 return enmConsider < enmFound;
720 else
721 Assert(!fConsiderAtom && !fFoundAtom);
722
723 /*
724 * Same basic category. Do same compare as caller.
725 */
726 return cpumR3DbIsBetterMarchMatch(enmConsider, enmTarget, enmFound);
727}
728
729
730int cpumR3DbGetCpuInfo(const char *pszName, PCPUMINFO pInfo)
731{
732 CPUMDBENTRY const *pEntry = NULL;
733 int rc;
734
735 if (!strcmp(pszName, "host"))
736 {
737 /*
738 * Create a CPU database entry for the host CPU. This means getting
739 * the CPUID bits from the real CPU and grabbing the closest matching
740 * database entry for MSRs.
741 */
742 rc = CPUMR3CpuIdDetectUnknownLeafMethod(&pInfo->enmUnknownCpuIdMethod, &pInfo->DefCpuId);
743 if (RT_FAILURE(rc))
744 return rc;
745 rc = CPUMR3CpuIdCollectLeaves(&pInfo->paCpuIdLeavesR3, &pInfo->cCpuIdLeaves);
746 if (RT_FAILURE(rc))
747 return rc;
748
749 /* Lookup database entry for MSRs. */
750 CPUMCPUVENDOR const enmVendor = CPUMR3CpuIdDetectVendorEx(pInfo->paCpuIdLeavesR3[0].uEax,
751 pInfo->paCpuIdLeavesR3[0].uEbx,
752 pInfo->paCpuIdLeavesR3[0].uEcx,
753 pInfo->paCpuIdLeavesR3[0].uEdx);
754 uint32_t const uStd1Eax = pInfo->paCpuIdLeavesR3[1].uEax;
755 uint8_t const uFamily = ASMGetCpuFamily(uStd1Eax);
756 uint8_t const uModel = ASMGetCpuModel(uStd1Eax, enmVendor == CPUMCPUVENDOR_INTEL);
757 uint8_t const uStepping = ASMGetCpuStepping(uStd1Eax);
758 CPUMMICROARCH const enmMicroarch = CPUMR3CpuIdDetermineMicroarchEx(enmVendor, uFamily, uModel, uStepping);
759
760 for (unsigned i = 0; i < RT_ELEMENTS(g_apCpumDbEntries); i++)
761 {
762 CPUMDBENTRY const *pCur = g_apCpumDbEntries[i];
763 if ((CPUMCPUVENDOR)pCur->enmVendor == enmVendor)
764 {
765 /* Match against Family, Microarch, model and stepping. Except
766 for family, always match the closer with preference given to
767 the later/older ones. */
768 if (pCur->uFamily == uFamily)
769 {
770 if (pCur->enmMicroarch == enmMicroarch)
771 {
772 if (pCur->uModel == uModel)
773 {
774 if (pCur->uStepping == uStepping)
775 {
776 /* Perfect match. */
777 pEntry = pCur;
778 break;
779 }
780
781 if ( !pEntry
782 || pEntry->uModel != uModel
783 || pEntry->enmMicroarch != enmMicroarch
784 || pEntry->uFamily != uFamily)
785 pEntry = pCur;
786 else if ( pCur->uStepping >= uStepping
787 ? pCur->uStepping < pEntry->uStepping || pEntry->uStepping < uStepping
788 : pCur->uStepping > pEntry->uStepping)
789 pEntry = pCur;
790 }
791 else if ( !pEntry
792 || pEntry->enmMicroarch != enmMicroarch
793 || pEntry->uFamily != uFamily)
794 pEntry = pCur;
795 else if ( pCur->uModel >= uModel
796 ? pCur->uModel < pEntry->uModel || pEntry->uModel < uModel
797 : pCur->uModel > pEntry->uModel)
798 pEntry = pCur;
799 }
800 else if ( !pEntry
801 || pEntry->uFamily != uFamily)
802 pEntry = pCur;
803 /* Special march matching rules applies to intel family 06h. */
804 else if ( enmVendor == CPUMCPUVENDOR_INTEL
805 && uFamily == 6
806 ? cpumR3DbIsBetterIntelFam06Match(pCur->enmMicroarch, enmMicroarch, pEntry->enmMicroarch)
807 : cpumR3DbIsBetterMarchMatch(pCur->enmMicroarch, enmMicroarch, pEntry->enmMicroarch))
808 pEntry = pCur;
809 }
810 /* We don't do closeness matching on family, we use the first
811 entry for the CPU vendor instead. (P4 workaround.) */
812 else if (!pEntry)
813 pEntry = pCur;
814 }
815 }
816
817 if (pEntry)
818 LogRel(("CPUM: Matched host CPU %s %#x/%#x/%#x %s with CPU DB entry '%s' (%s %#x/%#x/%#x %s)\n",
819 CPUMR3CpuVendorName(enmVendor), uFamily, uModel, uStepping, CPUMR3MicroarchName(enmMicroarch),
820 pEntry->pszName, CPUMR3CpuVendorName((CPUMCPUVENDOR)pEntry->enmVendor), pEntry->uFamily, pEntry->uModel,
821 pEntry->uStepping, CPUMR3MicroarchName(pEntry->enmMicroarch) ));
822 else
823 {
824 pEntry = g_apCpumDbEntries[0];
825 LogRel(("CPUM: No matching processor database entry %s %#x/%#x/%#x %s, falling back on '%s'\n",
826 CPUMR3CpuVendorName(enmVendor), uFamily, uModel, uStepping, CPUMR3MicroarchName(enmMicroarch),
827 pEntry->pszName));
828 }
829 }
830 else
831 {
832 /*
833 * We're supposed to be emulating a specific CPU that is included in
834 * our CPU database. The CPUID tables needs to be copied onto the
835 * heap so the caller can modify them and so they can be freed like
836 * in the host case above.
837 */
838 for (unsigned i = 0; i < RT_ELEMENTS(g_apCpumDbEntries); i++)
839 if (!strcmp(pszName, g_apCpumDbEntries[i]->pszName))
840 {
841 pEntry = g_apCpumDbEntries[i];
842 break;
843 }
844 if (!pEntry)
845 {
846 LogRel(("CPUM: Cannot locate any CPU by the name '%s'\n", pszName));
847 return VERR_CPUM_DB_CPU_NOT_FOUND;
848 }
849
850 pInfo->cCpuIdLeaves = pEntry->cCpuIdLeaves;
851 if (pEntry->cCpuIdLeaves)
852 {
853 pInfo->paCpuIdLeavesR3 = (PCPUMCPUIDLEAF)RTMemDup(pEntry->paCpuIdLeaves,
854 sizeof(pEntry->paCpuIdLeaves[0]) * pEntry->cCpuIdLeaves);
855 if (!pInfo->paCpuIdLeavesR3)
856 return VERR_NO_MEMORY;
857 }
858 else
859 pInfo->paCpuIdLeavesR3 = NULL;
860
861 pInfo->enmUnknownCpuIdMethod = pEntry->enmUnknownCpuId;
862 pInfo->DefCpuId = pEntry->DefUnknownCpuId;
863
864 LogRel(("CPUM: Using CPU DB entry '%s' (%s %#x/%#x/%#x %s)\n",
865 pEntry->pszName, CPUMR3CpuVendorName((CPUMCPUVENDOR)pEntry->enmVendor),
866 pEntry->uFamily, pEntry->uModel, pEntry->uStepping, CPUMR3MicroarchName(pEntry->enmMicroarch) ));
867 }
868
869 pInfo->fMsrMask = pEntry->fMsrMask;
870 pInfo->iFirstExtCpuIdLeaf = 0; /* Set by caller. */
871 pInfo->uPadding = 0;
872 pInfo->uScalableBusFreq = pEntry->uScalableBusFreq;
873 pInfo->paCpuIdLeavesR0 = NIL_RTR0PTR;
874 pInfo->paMsrRangesR0 = NIL_RTR0PTR;
875 pInfo->paCpuIdLeavesRC = NIL_RTRCPTR;
876 pInfo->paMsrRangesRC = NIL_RTRCPTR;
877
878 /*
879 * Copy the MSR range.
880 */
881 uint32_t cMsrs = 0;
882 PCPUMMSRRANGE paMsrs = NULL;
883
884 PCCPUMMSRRANGE pCurMsr = pEntry->paMsrRanges;
885 uint32_t cLeft = pEntry->cMsrRanges;
886 while (cLeft-- > 0)
887 {
888 rc = cpumR3MsrRangesInsert(NULL /* pVM */, &paMsrs, &cMsrs, pCurMsr);
889 if (RT_FAILURE(rc))
890 {
891 Assert(!paMsrs); /* The above function frees this. */
892 RTMemFree(pInfo->paCpuIdLeavesR3);
893 pInfo->paCpuIdLeavesR3 = NULL;
894 return rc;
895 }
896 pCurMsr++;
897 }
898
899 pInfo->paMsrRangesR3 = paMsrs;
900 pInfo->cMsrRanges = cMsrs;
901 return VINF_SUCCESS;
902}
903
904
905/**
906 * Insert an MSR range into the VM.
907 *
908 * If the new MSR range overlaps existing ranges, the existing ones will be
909 * adjusted/removed to fit in the new one.
910 *
911 * @returns VBox status code.
912 * @param pVM The cross context VM structure.
913 * @param pNewRange Pointer to the MSR range being inserted.
914 */
915VMMR3DECL(int) CPUMR3MsrRangesInsert(PVM pVM, PCCPUMMSRRANGE pNewRange)
916{
917 AssertReturn(pVM, VERR_INVALID_PARAMETER);
918 AssertReturn(pNewRange, VERR_INVALID_PARAMETER);
919
920 return cpumR3MsrRangesInsert(pVM, NULL /* ppaMsrRanges */, NULL /* pcMsrRanges */, pNewRange);
921}
922
923
924/**
925 * Register statistics for the MSRs.
926 *
927 * This must not be called before the MSRs have been finalized and moved to the
928 * hyper heap.
929 *
930 * @returns VBox status code.
931 * @param pVM The cross context VM structure.
932 */
933int cpumR3MsrRegStats(PVM pVM)
934{
935 /*
936 * Global statistics.
937 */
938 PCPUM pCpum = &pVM->cpum.s;
939 STAM_REL_REG(pVM, &pCpum->cMsrReads, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/Reads",
940 STAMUNIT_OCCURENCES, "All RDMSRs making it to CPUM.");
941 STAM_REL_REG(pVM, &pCpum->cMsrReadsRaiseGp, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/ReadsRaisingGP",
942 STAMUNIT_OCCURENCES, "RDMSR raising #GPs, except unknown MSRs.");
943 STAM_REL_REG(pVM, &pCpum->cMsrReadsUnknown, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/ReadsUnknown",
944 STAMUNIT_OCCURENCES, "RDMSR on unknown MSRs (raises #GP).");
945 STAM_REL_REG(pVM, &pCpum->cMsrWrites, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/Writes",
946 STAMUNIT_OCCURENCES, "All RDMSRs making it to CPUM.");
947 STAM_REL_REG(pVM, &pCpum->cMsrWritesRaiseGp, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesRaisingGP",
948 STAMUNIT_OCCURENCES, "WRMSR raising #GPs, except unknown MSRs.");
949 STAM_REL_REG(pVM, &pCpum->cMsrWritesToIgnoredBits, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesToIgnoredBits",
950 STAMUNIT_OCCURENCES, "Writing of ignored bits.");
951 STAM_REL_REG(pVM, &pCpum->cMsrWritesUnknown, STAMTYPE_COUNTER, "/CPUM/MSR-Totals/WritesUnknown",
952 STAMUNIT_OCCURENCES, "WRMSR on unknown MSRs (raises #GP).");
953
954
955# ifdef VBOX_WITH_STATISTICS
956 /*
957 * Per range.
958 */
959 PCPUMMSRRANGE paRanges = pVM->cpum.s.GuestInfo.paMsrRangesR3;
960 uint32_t cRanges = pVM->cpum.s.GuestInfo.cMsrRanges;
961 for (uint32_t i = 0; i < cRanges; i++)
962 {
963 char szName[160];
964 ssize_t cchName;
965
966 if (paRanges[i].uFirst == paRanges[i].uLast)
967 cchName = RTStrPrintf(szName, sizeof(szName), "/CPUM/MSRs/%#010x-%s",
968 paRanges[i].uFirst, paRanges[i].szName);
969 else
970 cchName = RTStrPrintf(szName, sizeof(szName), "/CPUM/MSRs/%#010x-%#010x-%s",
971 paRanges[i].uFirst, paRanges[i].uLast, paRanges[i].szName);
972
973 RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-reads");
974 STAMR3Register(pVM, &paRanges[i].cReads, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, szName, STAMUNIT_OCCURENCES, "RDMSR");
975
976 RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-writes");
977 STAMR3Register(pVM, &paRanges[i].cWrites, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "WRMSR");
978
979 RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-GPs");
980 STAMR3Register(pVM, &paRanges[i].cGps, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "#GPs");
981
982 RTStrCopy(&szName[cchName], sizeof(szName) - cchName, "-ign-bits-writes");
983 STAMR3Register(pVM, &paRanges[i].cIgnoredBits, STAMTYPE_COUNTER, STAMVISIBILITY_USED, szName, STAMUNIT_OCCURENCES, "WRMSR w/ ignored bits");
984 }
985# endif /* VBOX_WITH_STATISTICS */
986
987 return VINF_SUCCESS;
988}
989
990#endif /* !CPUM_DB_STANDALONE */
991
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette