VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/GIMMinimal.cpp@ 57009

Last change on this file since 57009 was 54737, checked in by vboxsync, 10 years ago

VMM,REM: CPUID revamp - almost there now.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: GIMMinimal.cpp 54737 2015-03-12 21:02:21Z vboxsync $ */
2/** @file
3 * GIM - Guest Interface Manager, Minimal implementation.
4 */
5
6/*
7 * Copyright (C) 2014-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* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_GIM
22#include "GIMInternal.h"
23
24#include <iprt/assert.h>
25#include <iprt/err.h>
26#include <iprt/asm-amd64-x86.h>
27#include <iprt/string.h>
28
29#include <VBox/vmm/cpum.h>
30#include <VBox/vmm/vm.h>
31#include <VBox/vmm/tm.h>
32#include <VBox/vmm/pdmapi.h>
33
34/*******************************************************************************
35* Defined Constants And Macros *
36*******************************************************************************/
37
38/**
39 * Initializes the Minimal provider.
40 *
41 * @returns VBox status code.
42 * @param pVM Pointer to the VM.
43 */
44VMMR3_INT_DECL(int) gimR3MinimalInit(PVM pVM)
45{
46 AssertReturn(pVM, VERR_INVALID_PARAMETER);
47 AssertReturn(pVM->gim.s.enmProviderId == GIMPROVIDERID_MINIMAL, VERR_INTERNAL_ERROR_5);
48
49 /*
50 * Enable the Hypervisor Present.
51 */
52 CPUMSetGuestCpuIdFeature(pVM, CPUMCPUIDFEATURE_HVP);
53
54 return VINF_SUCCESS;
55}
56
57
58/**
59 * Initializes remaining bits of the Minimal provider.
60 * This is called after initializing HM and almost all other VMM components.
61 *
62 * @returns VBox status code.
63 * @param pVM Pointer to the VM.
64 */
65VMMR3_INT_DECL(int) gimR3MinimalInitCompleted(PVM pVM)
66{
67 /*
68 * Expose a generic hypervisor-agnostic leaf (originally defined VMware).
69 * The leaves range from 0x40000010 to 0x400000FF.
70 *
71 * This is done in the init. completed routine as we need PDM to be
72 * initialized (otherwise PDMApicGetTimerFreq() would fail).
73 */
74 CPUMCPUIDLEAF HyperLeaf;
75 int rc = CPUMR3CpuIdGetLeaf(pVM, &HyperLeaf, 0x40000000, 0 /* uSubLeaf */);
76 if (RT_SUCCESS(rc))
77 {
78 HyperLeaf.uEax = UINT32_C(0x40000010); /* Maximum leaf we implement. */
79 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
80 AssertLogRelRCReturn(rc, rc);
81
82 /*
83 * Insert missing zero leaves (you never know what missing leaves are
84 * going to return when read).
85 */
86 for (uint32_t uLeaf = UINT32_C(0x40000001); uLeaf < UINT32_C(0x40000010); uLeaf++)
87 {
88 rc = CPUMR3CpuIdGetLeaf(pVM, &HyperLeaf, uLeaf, 0 /* uSubLeaf */);
89 if (RT_FAILURE(rc))
90 {
91 RT_ZERO(HyperLeaf);
92 HyperLeaf.uLeaf = uLeaf;
93 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
94 AssertLogRelRCReturn(rc, rc);
95 }
96 }
97
98 /*
99 * Add the timing information hypervisor leaf.
100 * MacOS X uses this to determine the TSC, bus frequency. See @bugref{7270}.
101 *
102 * EAX - TSC frequency in KHz.
103 * EBX - APIC frequency in KHz.
104 * ECX, EDX - Reserved.
105 */
106 uint64_t uApicFreq;
107 rc = PDMApicGetTimerFreq(pVM, &uApicFreq);
108 AssertLogRelRCReturn(rc, rc);
109
110 RT_ZERO(HyperLeaf);
111 HyperLeaf.uLeaf = UINT32_C(0x40000010);
112 HyperLeaf.uEax = TMCpuTicksPerSecond(pVM) / UINT64_C(1000);
113 HyperLeaf.uEbx = (uApicFreq + 500) / UINT64_C(1000);
114 rc = CPUMR3CpuIdInsert(pVM, &HyperLeaf);
115 AssertLogRelRCReturn(rc, rc);
116 }
117 else
118 LogRel(("GIM: Minimal: failed to get hypervisor leaf 0x40000000.\n"));
119
120 return VINF_SUCCESS;
121}
122
123
124/**
125 * Applies relocations to data and code managed by this component.
126 *
127 * This function will be called at init and whenever the VMM need to relocate
128 * itself inside the GC.
129 *
130 * @param pVM Pointer to the VM.
131 * @param offDelta Relocation delta relative to old location.
132 */
133VMMR3_INT_DECL(void) gimR3MinimalRelocate(PVM pVM, RTGCINTPTR offDelta)
134{
135 NOREF(pVM); NOREF(offDelta);
136}
137
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