[23] | 1 | /* $Id: CPUMAllRegs.cpp 43657 2012-10-16 15:34:05Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[12657] | 3 | * CPUM - CPU Monitor(/Manager) - Getters and Setters.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[41728] | 7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | /*******************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *******************************************************************************/
|
---|
| 22 | #define LOG_GROUP LOG_GROUP_CPUM
|
---|
[35346] | 23 | #include <VBox/vmm/cpum.h>
|
---|
| 24 | #include <VBox/vmm/patm.h>
|
---|
| 25 | #include <VBox/vmm/dbgf.h>
|
---|
| 26 | #include <VBox/vmm/pdm.h>
|
---|
| 27 | #include <VBox/vmm/pgm.h>
|
---|
| 28 | #include <VBox/vmm/mm.h>
|
---|
[42165] | 29 | #if defined(VBOX_WITH_RAW_MODE) && !defined(IN_RING0)
|
---|
| 30 | # include <VBox/vmm/selm.h>
|
---|
| 31 | #endif
|
---|
[1] | 32 | #include "CPUMInternal.h"
|
---|
[35346] | 33 | #include <VBox/vmm/vm.h>
|
---|
[1] | 34 | #include <VBox/err.h>
|
---|
| 35 | #include <VBox/dis.h>
|
---|
| 36 | #include <VBox/log.h>
|
---|
[43387] | 37 | #include <VBox/vmm/hm.h>
|
---|
[35346] | 38 | #include <VBox/vmm/tm.h>
|
---|
[1] | 39 | #include <iprt/assert.h>
|
---|
[772] | 40 | #include <iprt/asm.h>
|
---|
[29250] | 41 | #include <iprt/asm-amd64-x86.h>
|
---|
[13960] | 42 | #ifdef IN_RING3
|
---|
| 43 | #include <iprt/thread.h>
|
---|
| 44 | #endif
|
---|
[1] | 45 |
|
---|
| 46 | /** Disable stack frame pointer generation here. */
|
---|
| 47 | #if defined(_MSC_VER) && !defined(DEBUG)
|
---|
| 48 | # pragma optimize("y", off)
|
---|
| 49 | #endif
|
---|
| 50 |
|
---|
| 51 |
|
---|
[42165] | 52 | /*******************************************************************************
|
---|
| 53 | * Defined Constants And Macros *
|
---|
| 54 | *******************************************************************************/
|
---|
[1] | 55 | /**
|
---|
[42165] | 56 | * Converts a CPUMCPU::Guest pointer into a VMCPU pointer.
|
---|
| 57 | *
|
---|
| 58 | * @returns Pointer to the Virtual CPU.
|
---|
| 59 | * @param a_pGuestCtx Pointer to the guest context.
|
---|
| 60 | */
|
---|
| 61 | #define CPUM_GUEST_CTX_TO_VMCPU(a_pGuestCtx) RT_FROM_MEMBER(a_pGuestCtx, VMCPU, cpum.s.Guest)
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * Lazily loads the hidden parts of a selector register when using raw-mode.
|
---|
| 65 | */
|
---|
| 66 | #if defined(VBOX_WITH_RAW_MODE) && !defined(IN_RING0)
|
---|
[42407] | 67 | # define CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(a_pVCpu, a_pSReg) \
|
---|
[42165] | 68 | do \
|
---|
| 69 | { \
|
---|
[42407] | 70 | if (!CPUMSELREG_ARE_HIDDEN_PARTS_VALID(a_pVCpu, a_pSReg)) \
|
---|
| 71 | cpumGuestLazyLoadHiddenSelectorReg(a_pVCpu, a_pSReg); \
|
---|
[42165] | 72 | } while (0)
|
---|
| 73 | #else
|
---|
[42407] | 74 | # define CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(a_pVCpu, a_pSReg) \
|
---|
| 75 | Assert(CPUMSELREG_ARE_HIDDEN_PARTS_VALID(a_pVCpu, a_pSReg));
|
---|
[42165] | 76 | #endif
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 |
|
---|
[42193] | 80 | #ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
[42165] | 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Does the lazy hidden selector register loading.
|
---|
| 84 | *
|
---|
| 85 | * @param pVCpu The current Virtual CPU.
|
---|
| 86 | * @param pSReg The selector register to lazily load hidden parts of.
|
---|
| 87 | */
|
---|
[42407] | 88 | static void cpumGuestLazyLoadHiddenSelectorReg(PVMCPU pVCpu, PCPUMSELREG pSReg)
|
---|
[42165] | 89 | {
|
---|
[42407] | 90 | Assert(!CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, pSReg));
|
---|
[43387] | 91 | Assert(!HMIsEnabled(pVCpu->CTX_SUFF(pVM)));
|
---|
[42407] | 92 | Assert((uintptr_t)(pSReg - &pVCpu->cpum.s.Guest.es) < X86_SREG_COUNT);
|
---|
[42165] | 93 |
|
---|
| 94 | if (pVCpu->cpum.s.Guest.eflags.Bits.u1VM)
|
---|
| 95 | {
|
---|
| 96 | /* V8086 mode - Tightly controlled environment, no question about the limit or flags. */
|
---|
| 97 | pSReg->Attr.u = 0;
|
---|
[42407] | 98 | pSReg->Attr.n.u4Type = pSReg == &pVCpu->cpum.s.Guest.cs ? X86_SEL_TYPE_ER_ACC : X86_SEL_TYPE_RW_ACC;
|
---|
[42165] | 99 | pSReg->Attr.n.u1DescType = 1; /* code/data segment */
|
---|
[42407] | 100 | pSReg->Attr.n.u2Dpl = 3;
|
---|
[42165] | 101 | pSReg->Attr.n.u1Present = 1;
|
---|
| 102 | pSReg->u32Limit = 0x0000ffff;
|
---|
| 103 | pSReg->u64Base = (uint32_t)pSReg->Sel << 4;
|
---|
| 104 | pSReg->ValidSel = pSReg->Sel;
|
---|
| 105 | pSReg->fFlags = CPUMSELREG_FLAGS_VALID;
|
---|
| 106 | /** @todo Check what the accessed bit should be (VT-x and AMD-V). */
|
---|
| 107 | }
|
---|
| 108 | else if (!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE))
|
---|
| 109 | {
|
---|
| 110 | /* Real mode - leave the limit and flags alone here, at least for now. */
|
---|
| 111 | pSReg->u64Base = (uint32_t)pSReg->Sel << 4;
|
---|
| 112 | pSReg->ValidSel = pSReg->Sel;
|
---|
| 113 | pSReg->fFlags = CPUMSELREG_FLAGS_VALID;
|
---|
| 114 | }
|
---|
| 115 | else
|
---|
| 116 | {
|
---|
| 117 | /* Protected mode - get it from the selector descriptor tables. */
|
---|
[42427] | 118 | if (!(pSReg->Sel & X86_SEL_MASK_OFF_RPL))
|
---|
[42165] | 119 | {
|
---|
| 120 | Assert(!CPUMIsGuestInLongMode(pVCpu));
|
---|
| 121 | pSReg->Sel = 0;
|
---|
| 122 | pSReg->u64Base = 0;
|
---|
| 123 | pSReg->u32Limit = 0;
|
---|
| 124 | pSReg->Attr.u = 0;
|
---|
| 125 | pSReg->ValidSel = 0;
|
---|
| 126 | pSReg->fFlags = CPUMSELREG_FLAGS_VALID;
|
---|
| 127 | /** @todo see todo in iemHlpLoadNullDataSelectorProt. */
|
---|
| 128 | }
|
---|
| 129 | else
|
---|
| 130 | SELMLoadHiddenSelectorReg(pVCpu, &pVCpu->cpum.s.Guest, pSReg);
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | /**
|
---|
| 136 | * Makes sure the hidden CS and SS selector registers are valid, loading them if
|
---|
| 137 | * necessary.
|
---|
| 138 | *
|
---|
| 139 | * @param pVCpu The current virtual CPU.
|
---|
| 140 | */
|
---|
| 141 | VMM_INT_DECL(void) CPUMGuestLazyLoadHiddenCsAndSs(PVMCPU pVCpu)
|
---|
| 142 | {
|
---|
[42407] | 143 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, &pVCpu->cpum.s.Guest.cs);
|
---|
| 144 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, &pVCpu->cpum.s.Guest.ss);
|
---|
[42165] | 145 | }
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | /**
|
---|
| 149 | * Loads a the hidden parts of a selector register.
|
---|
| 150 | *
|
---|
| 151 | * @param pVCpu The current virtual CPU.
|
---|
| 152 | */
|
---|
| 153 | VMM_INT_DECL(void) CPUMGuestLazyLoadHiddenSelectorReg(PVMCPU pVCpu, PCPUMSELREG pSReg)
|
---|
| 154 | {
|
---|
[42407] | 155 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, pSReg);
|
---|
[42165] | 156 | }
|
---|
| 157 |
|
---|
[42193] | 158 | #endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
|
---|
[42165] | 159 |
|
---|
| 160 |
|
---|
| 161 | /**
|
---|
[41931] | 162 | * Obsolete.
|
---|
[1] | 163 | *
|
---|
[41931] | 164 | * We don't support nested hypervisor context interrupts or traps. Life is much
|
---|
| 165 | * simpler when we don't. It's also slightly faster at times.
|
---|
[1] | 166 | *
|
---|
| 167 | * @param pVM Handle to the virtual machine.
|
---|
| 168 | */
|
---|
[18927] | 169 | VMMDECL(PCCPUMCTXCORE) CPUMGetHyperCtxCore(PVMCPU pVCpu)
|
---|
[1] | 170 | {
|
---|
[41931] | 171 | return CPUMCTX2CORE(&pVCpu->cpum.s.Hyper);
|
---|
[1] | 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | /**
|
---|
[41931] | 176 | * Gets the pointer to the hypervisor CPU context structure of a virtual CPU.
|
---|
[1] | 177 | *
|
---|
[42034] | 178 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 179 | */
|
---|
[41931] | 180 | VMMDECL(PCPUMCTX) CPUMGetHyperCtxPtr(PVMCPU pVCpu)
|
---|
[1] | 181 | {
|
---|
[41931] | 182 | return &pVCpu->cpum.s.Hyper;
|
---|
[1] | 183 | }
|
---|
| 184 |
|
---|
[12657] | 185 |
|
---|
[18927] | 186 | VMMDECL(void) CPUMSetHyperGDTR(PVMCPU pVCpu, uint32_t addr, uint16_t limit)
|
---|
[1] | 187 | {
|
---|
[18927] | 188 | pVCpu->cpum.s.Hyper.gdtr.cbGdt = limit;
|
---|
| 189 | pVCpu->cpum.s.Hyper.gdtr.pGdt = addr;
|
---|
[1] | 190 | }
|
---|
| 191 |
|
---|
[12657] | 192 |
|
---|
[18927] | 193 | VMMDECL(void) CPUMSetHyperIDTR(PVMCPU pVCpu, uint32_t addr, uint16_t limit)
|
---|
[1] | 194 | {
|
---|
[18927] | 195 | pVCpu->cpum.s.Hyper.idtr.cbIdt = limit;
|
---|
[41931] | 196 | pVCpu->cpum.s.Hyper.idtr.pIdt = addr;
|
---|
[1] | 197 | }
|
---|
| 198 |
|
---|
[12657] | 199 |
|
---|
[18927] | 200 | VMMDECL(void) CPUMSetHyperCR3(PVMCPU pVCpu, uint32_t cr3)
|
---|
[1] | 201 | {
|
---|
[18927] | 202 | pVCpu->cpum.s.Hyper.cr3 = cr3;
|
---|
[16859] | 203 |
|
---|
| 204 | #ifdef IN_RC
|
---|
| 205 | /* Update the current CR3. */
|
---|
| 206 | ASMSetCR3(cr3);
|
---|
| 207 | #endif
|
---|
[1] | 208 | }
|
---|
| 209 |
|
---|
[18927] | 210 | VMMDECL(uint32_t) CPUMGetHyperCR3(PVMCPU pVCpu)
|
---|
[16859] | 211 | {
|
---|
[18927] | 212 | return pVCpu->cpum.s.Hyper.cr3;
|
---|
[16859] | 213 | }
|
---|
[12657] | 214 |
|
---|
[16859] | 215 |
|
---|
[18927] | 216 | VMMDECL(void) CPUMSetHyperCS(PVMCPU pVCpu, RTSEL SelCS)
|
---|
[1] | 217 | {
|
---|
[41931] | 218 | pVCpu->cpum.s.Hyper.cs.Sel = SelCS;
|
---|
[1] | 219 | }
|
---|
| 220 |
|
---|
[12657] | 221 |
|
---|
[18927] | 222 | VMMDECL(void) CPUMSetHyperDS(PVMCPU pVCpu, RTSEL SelDS)
|
---|
[1] | 223 | {
|
---|
[41931] | 224 | pVCpu->cpum.s.Hyper.ds.Sel = SelDS;
|
---|
[1] | 225 | }
|
---|
| 226 |
|
---|
[12657] | 227 |
|
---|
[18927] | 228 | VMMDECL(void) CPUMSetHyperES(PVMCPU pVCpu, RTSEL SelES)
|
---|
[1] | 229 | {
|
---|
[41931] | 230 | pVCpu->cpum.s.Hyper.es.Sel = SelES;
|
---|
[1] | 231 | }
|
---|
| 232 |
|
---|
[12657] | 233 |
|
---|
[18927] | 234 | VMMDECL(void) CPUMSetHyperFS(PVMCPU pVCpu, RTSEL SelFS)
|
---|
[1] | 235 | {
|
---|
[41931] | 236 | pVCpu->cpum.s.Hyper.fs.Sel = SelFS;
|
---|
[1] | 237 | }
|
---|
| 238 |
|
---|
[12657] | 239 |
|
---|
[18927] | 240 | VMMDECL(void) CPUMSetHyperGS(PVMCPU pVCpu, RTSEL SelGS)
|
---|
[1] | 241 | {
|
---|
[41931] | 242 | pVCpu->cpum.s.Hyper.gs.Sel = SelGS;
|
---|
[1] | 243 | }
|
---|
| 244 |
|
---|
[12657] | 245 |
|
---|
[18927] | 246 | VMMDECL(void) CPUMSetHyperSS(PVMCPU pVCpu, RTSEL SelSS)
|
---|
[1] | 247 | {
|
---|
[41931] | 248 | pVCpu->cpum.s.Hyper.ss.Sel = SelSS;
|
---|
[1] | 249 | }
|
---|
| 250 |
|
---|
[12657] | 251 |
|
---|
[18927] | 252 | VMMDECL(void) CPUMSetHyperESP(PVMCPU pVCpu, uint32_t u32ESP)
|
---|
[1] | 253 | {
|
---|
[41931] | 254 | pVCpu->cpum.s.Hyper.esp = u32ESP;
|
---|
[1] | 255 | }
|
---|
| 256 |
|
---|
[12657] | 257 |
|
---|
[41976] | 258 | VMMDECL(void) CPUMSetHyperEDX(PVMCPU pVCpu, uint32_t u32ESP)
|
---|
| 259 | {
|
---|
| 260 | pVCpu->cpum.s.Hyper.esp = u32ESP;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 |
|
---|
[18927] | 264 | VMMDECL(int) CPUMSetHyperEFlags(PVMCPU pVCpu, uint32_t Efl)
|
---|
[1] | 265 | {
|
---|
[41931] | 266 | pVCpu->cpum.s.Hyper.eflags.u32 = Efl;
|
---|
[1] | 267 | return VINF_SUCCESS;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
[12657] | 270 |
|
---|
[18927] | 271 | VMMDECL(void) CPUMSetHyperEIP(PVMCPU pVCpu, uint32_t u32EIP)
|
---|
[1] | 272 | {
|
---|
[41931] | 273 | pVCpu->cpum.s.Hyper.eip = u32EIP;
|
---|
[1] | 274 | }
|
---|
| 275 |
|
---|
[12657] | 276 |
|
---|
[41976] | 277 | /**
|
---|
| 278 | * Used by VMMR3RawRunGC to reinitialize the general raw-mode context registers,
|
---|
| 279 | * EFLAGS and EIP prior to resuming guest execution.
|
---|
| 280 | *
|
---|
| 281 | * All general register not given as a parameter will be set to 0. The EFLAGS
|
---|
| 282 | * register will be set to sane values for C/C++ code execution with interrupts
|
---|
| 283 | * disabled and IOPL 0.
|
---|
| 284 | *
|
---|
| 285 | * @param pVCpu The current virtual CPU.
|
---|
| 286 | * @param u32EIP The EIP value.
|
---|
| 287 | * @param u32ESP The ESP value.
|
---|
| 288 | * @param u32EAX The EAX value.
|
---|
| 289 | * @param u32EDX The EDX value.
|
---|
| 290 | */
|
---|
| 291 | VMM_INT_DECL(void) CPUMSetHyperState(PVMCPU pVCpu, uint32_t u32EIP, uint32_t u32ESP, uint32_t u32EAX, uint32_t u32EDX)
|
---|
| 292 | {
|
---|
| 293 | pVCpu->cpum.s.Hyper.eip = u32EIP;
|
---|
| 294 | pVCpu->cpum.s.Hyper.esp = u32ESP;
|
---|
| 295 | pVCpu->cpum.s.Hyper.eax = u32EAX;
|
---|
| 296 | pVCpu->cpum.s.Hyper.edx = u32EDX;
|
---|
| 297 | pVCpu->cpum.s.Hyper.ecx = 0;
|
---|
| 298 | pVCpu->cpum.s.Hyper.ebx = 0;
|
---|
| 299 | pVCpu->cpum.s.Hyper.ebp = 0;
|
---|
| 300 | pVCpu->cpum.s.Hyper.esi = 0;
|
---|
| 301 | pVCpu->cpum.s.Hyper.edi = 0;
|
---|
| 302 | pVCpu->cpum.s.Hyper.eflags.u = X86_EFL_1;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 |
|
---|
[18927] | 306 | VMMDECL(void) CPUMSetHyperTR(PVMCPU pVCpu, RTSEL SelTR)
|
---|
[1] | 307 | {
|
---|
[41906] | 308 | pVCpu->cpum.s.Hyper.tr.Sel = SelTR;
|
---|
[1] | 309 | }
|
---|
| 310 |
|
---|
[12657] | 311 |
|
---|
[18927] | 312 | VMMDECL(void) CPUMSetHyperLDTR(PVMCPU pVCpu, RTSEL SelLDTR)
|
---|
[1] | 313 | {
|
---|
[41906] | 314 | pVCpu->cpum.s.Hyper.ldtr.Sel = SelLDTR;
|
---|
[1] | 315 | }
|
---|
| 316 |
|
---|
[12657] | 317 |
|
---|
[18927] | 318 | VMMDECL(void) CPUMSetHyperDR0(PVMCPU pVCpu, RTGCUINTREG uDr0)
|
---|
[1] | 319 | {
|
---|
[18927] | 320 | pVCpu->cpum.s.Hyper.dr[0] = uDr0;
|
---|
[1] | 321 | /** @todo in GC we must load it! */
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[12657] | 324 |
|
---|
[18927] | 325 | VMMDECL(void) CPUMSetHyperDR1(PVMCPU pVCpu, RTGCUINTREG uDr1)
|
---|
[1] | 326 | {
|
---|
[18927] | 327 | pVCpu->cpum.s.Hyper.dr[1] = uDr1;
|
---|
[1] | 328 | /** @todo in GC we must load it! */
|
---|
| 329 | }
|
---|
| 330 |
|
---|
[12657] | 331 |
|
---|
[18927] | 332 | VMMDECL(void) CPUMSetHyperDR2(PVMCPU pVCpu, RTGCUINTREG uDr2)
|
---|
[1] | 333 | {
|
---|
[18927] | 334 | pVCpu->cpum.s.Hyper.dr[2] = uDr2;
|
---|
[1] | 335 | /** @todo in GC we must load it! */
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[12657] | 338 |
|
---|
[18927] | 339 | VMMDECL(void) CPUMSetHyperDR3(PVMCPU pVCpu, RTGCUINTREG uDr3)
|
---|
[1] | 340 | {
|
---|
[18927] | 341 | pVCpu->cpum.s.Hyper.dr[3] = uDr3;
|
---|
[1] | 342 | /** @todo in GC we must load it! */
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[12657] | 345 |
|
---|
[18927] | 346 | VMMDECL(void) CPUMSetHyperDR6(PVMCPU pVCpu, RTGCUINTREG uDr6)
|
---|
[1] | 347 | {
|
---|
[18927] | 348 | pVCpu->cpum.s.Hyper.dr[6] = uDr6;
|
---|
[1] | 349 | /** @todo in GC we must load it! */
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[12657] | 352 |
|
---|
[18927] | 353 | VMMDECL(void) CPUMSetHyperDR7(PVMCPU pVCpu, RTGCUINTREG uDr7)
|
---|
[1] | 354 | {
|
---|
[18927] | 355 | pVCpu->cpum.s.Hyper.dr[7] = uDr7;
|
---|
[1] | 356 | /** @todo in GC we must load it! */
|
---|
| 357 | }
|
---|
| 358 |
|
---|
| 359 |
|
---|
[18927] | 360 | VMMDECL(RTSEL) CPUMGetHyperCS(PVMCPU pVCpu)
|
---|
[1] | 361 | {
|
---|
[41931] | 362 | return pVCpu->cpum.s.Hyper.cs.Sel;
|
---|
[1] | 363 | }
|
---|
| 364 |
|
---|
[12657] | 365 |
|
---|
[18927] | 366 | VMMDECL(RTSEL) CPUMGetHyperDS(PVMCPU pVCpu)
|
---|
[1] | 367 | {
|
---|
[41931] | 368 | return pVCpu->cpum.s.Hyper.ds.Sel;
|
---|
[1] | 369 | }
|
---|
| 370 |
|
---|
[12657] | 371 |
|
---|
[18927] | 372 | VMMDECL(RTSEL) CPUMGetHyperES(PVMCPU pVCpu)
|
---|
[1] | 373 | {
|
---|
[41931] | 374 | return pVCpu->cpum.s.Hyper.es.Sel;
|
---|
[1] | 375 | }
|
---|
| 376 |
|
---|
[12657] | 377 |
|
---|
[18927] | 378 | VMMDECL(RTSEL) CPUMGetHyperFS(PVMCPU pVCpu)
|
---|
[1] | 379 | {
|
---|
[41931] | 380 | return pVCpu->cpum.s.Hyper.fs.Sel;
|
---|
[1] | 381 | }
|
---|
| 382 |
|
---|
[12657] | 383 |
|
---|
[18927] | 384 | VMMDECL(RTSEL) CPUMGetHyperGS(PVMCPU pVCpu)
|
---|
[1] | 385 | {
|
---|
[41931] | 386 | return pVCpu->cpum.s.Hyper.gs.Sel;
|
---|
[1] | 387 | }
|
---|
| 388 |
|
---|
[12657] | 389 |
|
---|
[18927] | 390 | VMMDECL(RTSEL) CPUMGetHyperSS(PVMCPU pVCpu)
|
---|
[1] | 391 | {
|
---|
[41931] | 392 | return pVCpu->cpum.s.Hyper.ss.Sel;
|
---|
[1] | 393 | }
|
---|
| 394 |
|
---|
| 395 |
|
---|
[18927] | 396 | VMMDECL(uint32_t) CPUMGetHyperEAX(PVMCPU pVCpu)
|
---|
[1] | 397 | {
|
---|
[41931] | 398 | return pVCpu->cpum.s.Hyper.eax;
|
---|
[1] | 399 | }
|
---|
| 400 |
|
---|
| 401 |
|
---|
[18927] | 402 | VMMDECL(uint32_t) CPUMGetHyperEBX(PVMCPU pVCpu)
|
---|
[1] | 403 | {
|
---|
[41931] | 404 | return pVCpu->cpum.s.Hyper.ebx;
|
---|
[1] | 405 | }
|
---|
| 406 |
|
---|
| 407 |
|
---|
[18927] | 408 | VMMDECL(uint32_t) CPUMGetHyperECX(PVMCPU pVCpu)
|
---|
[1] | 409 | {
|
---|
[41931] | 410 | return pVCpu->cpum.s.Hyper.ecx;
|
---|
[1] | 411 | }
|
---|
| 412 |
|
---|
| 413 |
|
---|
[18927] | 414 | VMMDECL(uint32_t) CPUMGetHyperEDX(PVMCPU pVCpu)
|
---|
[1] | 415 | {
|
---|
[41931] | 416 | return pVCpu->cpum.s.Hyper.edx;
|
---|
[1] | 417 | }
|
---|
| 418 |
|
---|
[12657] | 419 |
|
---|
[18927] | 420 | VMMDECL(uint32_t) CPUMGetHyperESI(PVMCPU pVCpu)
|
---|
[1] | 421 | {
|
---|
[41931] | 422 | return pVCpu->cpum.s.Hyper.esi;
|
---|
[1] | 423 | }
|
---|
| 424 |
|
---|
[12657] | 425 |
|
---|
[18927] | 426 | VMMDECL(uint32_t) CPUMGetHyperEDI(PVMCPU pVCpu)
|
---|
[1] | 427 | {
|
---|
[41931] | 428 | return pVCpu->cpum.s.Hyper.edi;
|
---|
[1] | 429 | }
|
---|
| 430 |
|
---|
[12657] | 431 |
|
---|
[18927] | 432 | VMMDECL(uint32_t) CPUMGetHyperEBP(PVMCPU pVCpu)
|
---|
[1] | 433 | {
|
---|
[41931] | 434 | return pVCpu->cpum.s.Hyper.ebp;
|
---|
[1] | 435 | }
|
---|
| 436 |
|
---|
[12657] | 437 |
|
---|
[18927] | 438 | VMMDECL(uint32_t) CPUMGetHyperESP(PVMCPU pVCpu)
|
---|
[1] | 439 | {
|
---|
[41931] | 440 | return pVCpu->cpum.s.Hyper.esp;
|
---|
[1] | 441 | }
|
---|
| 442 |
|
---|
[12657] | 443 |
|
---|
[18927] | 444 | VMMDECL(uint32_t) CPUMGetHyperEFlags(PVMCPU pVCpu)
|
---|
[1] | 445 | {
|
---|
[41931] | 446 | return pVCpu->cpum.s.Hyper.eflags.u32;
|
---|
[1] | 447 | }
|
---|
| 448 |
|
---|
[12657] | 449 |
|
---|
[18927] | 450 | VMMDECL(uint32_t) CPUMGetHyperEIP(PVMCPU pVCpu)
|
---|
[1] | 451 | {
|
---|
[41931] | 452 | return pVCpu->cpum.s.Hyper.eip;
|
---|
[1] | 453 | }
|
---|
| 454 |
|
---|
[12657] | 455 |
|
---|
[18927] | 456 | VMMDECL(uint64_t) CPUMGetHyperRIP(PVMCPU pVCpu)
|
---|
[9841] | 457 | {
|
---|
[41931] | 458 | return pVCpu->cpum.s.Hyper.rip;
|
---|
[9841] | 459 | }
|
---|
| 460 |
|
---|
[12657] | 461 |
|
---|
[18927] | 462 | VMMDECL(uint32_t) CPUMGetHyperIDTR(PVMCPU pVCpu, uint16_t *pcbLimit)
|
---|
[1] | 463 | {
|
---|
| 464 | if (pcbLimit)
|
---|
[18927] | 465 | *pcbLimit = pVCpu->cpum.s.Hyper.idtr.cbIdt;
|
---|
| 466 | return pVCpu->cpum.s.Hyper.idtr.pIdt;
|
---|
[1] | 467 | }
|
---|
| 468 |
|
---|
[12657] | 469 |
|
---|
[18927] | 470 | VMMDECL(uint32_t) CPUMGetHyperGDTR(PVMCPU pVCpu, uint16_t *pcbLimit)
|
---|
[1] | 471 | {
|
---|
| 472 | if (pcbLimit)
|
---|
[18927] | 473 | *pcbLimit = pVCpu->cpum.s.Hyper.gdtr.cbGdt;
|
---|
| 474 | return pVCpu->cpum.s.Hyper.gdtr.pGdt;
|
---|
[1] | 475 | }
|
---|
| 476 |
|
---|
[12657] | 477 |
|
---|
[18927] | 478 | VMMDECL(RTSEL) CPUMGetHyperLDTR(PVMCPU pVCpu)
|
---|
[1] | 479 | {
|
---|
[41906] | 480 | return pVCpu->cpum.s.Hyper.ldtr.Sel;
|
---|
[1] | 481 | }
|
---|
| 482 |
|
---|
[12657] | 483 |
|
---|
[18927] | 484 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR0(PVMCPU pVCpu)
|
---|
[1] | 485 | {
|
---|
[18927] | 486 | return pVCpu->cpum.s.Hyper.dr[0];
|
---|
[1] | 487 | }
|
---|
| 488 |
|
---|
[12657] | 489 |
|
---|
[18927] | 490 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR1(PVMCPU pVCpu)
|
---|
[1] | 491 | {
|
---|
[18927] | 492 | return pVCpu->cpum.s.Hyper.dr[1];
|
---|
[1] | 493 | }
|
---|
| 494 |
|
---|
[12657] | 495 |
|
---|
[18927] | 496 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR2(PVMCPU pVCpu)
|
---|
[1] | 497 | {
|
---|
[18927] | 498 | return pVCpu->cpum.s.Hyper.dr[2];
|
---|
[1] | 499 | }
|
---|
| 500 |
|
---|
[12657] | 501 |
|
---|
[18927] | 502 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR3(PVMCPU pVCpu)
|
---|
[1] | 503 | {
|
---|
[18927] | 504 | return pVCpu->cpum.s.Hyper.dr[3];
|
---|
[1] | 505 | }
|
---|
| 506 |
|
---|
[12657] | 507 |
|
---|
[18927] | 508 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR6(PVMCPU pVCpu)
|
---|
[1] | 509 | {
|
---|
[18927] | 510 | return pVCpu->cpum.s.Hyper.dr[6];
|
---|
[1] | 511 | }
|
---|
| 512 |
|
---|
[12657] | 513 |
|
---|
[18927] | 514 | VMMDECL(RTGCUINTREG) CPUMGetHyperDR7(PVMCPU pVCpu)
|
---|
[1] | 515 | {
|
---|
[18927] | 516 | return pVCpu->cpum.s.Hyper.dr[7];
|
---|
[1] | 517 | }
|
---|
| 518 |
|
---|
| 519 |
|
---|
| 520 | /**
|
---|
| 521 | * Gets the pointer to the internal CPUMCTXCORE structure.
|
---|
| 522 | * This is only for reading in order to save a few calls.
|
---|
| 523 | *
|
---|
[18927] | 524 | * @param pVCpu Handle to the virtual cpu.
|
---|
[1] | 525 | */
|
---|
[18927] | 526 | VMMDECL(PCCPUMCTXCORE) CPUMGetGuestCtxCore(PVMCPU pVCpu)
|
---|
[1] | 527 | {
|
---|
[13975] | 528 | return CPUMCTX2CORE(&pVCpu->cpum.s.Guest);
|
---|
| 529 | }
|
---|
[1] | 530 |
|
---|
[13975] | 531 |
|
---|
[1] | 532 | /**
|
---|
[42034] | 533 | * Queries the pointer to the internal CPUMCTX structure.
|
---|
[1] | 534 | *
|
---|
[13532] | 535 | * @returns The CPUMCTX pointer.
|
---|
[18927] | 536 | * @param pVCpu Handle to the virtual cpu.
|
---|
[1] | 537 | */
|
---|
[18927] | 538 | VMMDECL(PCPUMCTX) CPUMQueryGuestCtxPtr(PVMCPU pVCpu)
|
---|
[1] | 539 | {
|
---|
[13960] | 540 | return &pVCpu->cpum.s.Guest;
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[36762] | 543 | VMMDECL(int) CPUMSetGuestGDTR(PVMCPU pVCpu, uint64_t GCPtrBase, uint16_t cbLimit)
|
---|
[1] | 544 | {
|
---|
[42705] | 545 | #ifdef VBOX_WITH_IEM
|
---|
| 546 | # ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
[43387] | 547 | if (!HMIsEnabled(pVCpu->CTX_SUFF(pVM)))
|
---|
[42705] | 548 | VMCPU_FF_SET(pVCpu, VMCPU_FF_SELM_SYNC_GDT);
|
---|
| 549 | # endif
|
---|
| 550 | #endif
|
---|
[36762] | 551 | pVCpu->cpum.s.Guest.gdtr.cbGdt = cbLimit;
|
---|
| 552 | pVCpu->cpum.s.Guest.gdtr.pGdt = GCPtrBase;
|
---|
[18927] | 553 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_GDTR;
|
---|
[42452] | 554 | return VINF_SUCCESS; /* formality, consider it void. */
|
---|
[1] | 555 | }
|
---|
| 556 |
|
---|
[36762] | 557 | VMMDECL(int) CPUMSetGuestIDTR(PVMCPU pVCpu, uint64_t GCPtrBase, uint16_t cbLimit)
|
---|
[1] | 558 | {
|
---|
[42705] | 559 | #ifdef VBOX_WITH_IEM
|
---|
| 560 | # ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
[43387] | 561 | if (!HMIsEnabled(pVCpu->CTX_SUFF(pVM)))
|
---|
[42705] | 562 | VMCPU_FF_SET(pVCpu, VMCPU_FF_TRPM_SYNC_IDT);
|
---|
| 563 | # endif
|
---|
| 564 | #endif
|
---|
[36762] | 565 | pVCpu->cpum.s.Guest.idtr.cbIdt = cbLimit;
|
---|
| 566 | pVCpu->cpum.s.Guest.idtr.pIdt = GCPtrBase;
|
---|
[18927] | 567 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_IDTR;
|
---|
[42452] | 568 | return VINF_SUCCESS; /* formality, consider it void. */
|
---|
[1] | 569 | }
|
---|
| 570 |
|
---|
[18927] | 571 | VMMDECL(int) CPUMSetGuestTR(PVMCPU pVCpu, uint16_t tr)
|
---|
[1] | 572 | {
|
---|
[42705] | 573 | #ifdef VBOX_WITH_IEM
|
---|
| 574 | # ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
[43387] | 575 | if (!HMIsEnabled(pVCpu->CTX_SUFF(pVM)))
|
---|
[42705] | 576 | VMCPU_FF_SET(pVCpu, VMCPU_FF_SELM_SYNC_TSS);
|
---|
| 577 | # endif
|
---|
| 578 | #endif
|
---|
[41906] | 579 | pVCpu->cpum.s.Guest.tr.Sel = tr;
|
---|
[18927] | 580 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_TR;
|
---|
[42452] | 581 | return VINF_SUCCESS; /* formality, consider it void. */
|
---|
[1] | 582 | }
|
---|
| 583 |
|
---|
[18927] | 584 | VMMDECL(int) CPUMSetGuestLDTR(PVMCPU pVCpu, uint16_t ldtr)
|
---|
[1] | 585 | {
|
---|
[42705] | 586 | #ifdef VBOX_WITH_IEM
|
---|
| 587 | # ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
| 588 | if ( ( ldtr != 0
|
---|
| 589 | || pVCpu->cpum.s.Guest.ldtr.Sel != 0)
|
---|
[43387] | 590 | && !HMIsEnabled(pVCpu->CTX_SUFF(pVM)))
|
---|
[42705] | 591 | VMCPU_FF_SET(pVCpu, VMCPU_FF_SELM_SYNC_LDT);
|
---|
| 592 | # endif
|
---|
| 593 | #endif
|
---|
[42407] | 594 | pVCpu->cpum.s.Guest.ldtr.Sel = ldtr;
|
---|
| 595 | /* The caller will set more hidden bits if it has them. */
|
---|
| 596 | pVCpu->cpum.s.Guest.ldtr.ValidSel = 0;
|
---|
| 597 | pVCpu->cpum.s.Guest.ldtr.fFlags = 0;
|
---|
[18927] | 598 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_LDTR;
|
---|
[42452] | 599 | return VINF_SUCCESS; /* formality, consider it void. */
|
---|
[1] | 600 | }
|
---|
| 601 |
|
---|
| 602 |
|
---|
[5389] | 603 | /**
|
---|
[5695] | 604 | * Set the guest CR0.
|
---|
| 605 | *
|
---|
| 606 | * When called in GC, the hyper CR0 may be updated if that is
|
---|
| 607 | * required. The caller only has to take special action if AM,
|
---|
| 608 | * WP, PG or PE changes.
|
---|
| 609 | *
|
---|
[5389] | 610 | * @returns VINF_SUCCESS (consider it void).
|
---|
[18927] | 611 | * @param pVCpu Handle to the virtual cpu.
|
---|
[5389] | 612 | * @param cr0 The new CR0 value.
|
---|
| 613 | */
|
---|
[18927] | 614 | VMMDECL(int) CPUMSetGuestCR0(PVMCPU pVCpu, uint64_t cr0)
|
---|
[1] | 615 | {
|
---|
[13832] | 616 | #ifdef IN_RC
|
---|
[5389] | 617 | /*
|
---|
[5695] | 618 | * Check if we need to change hypervisor CR0 because
|
---|
[5389] | 619 | * of math stuff.
|
---|
| 620 | */
|
---|
[31079] | 621 | if ( (cr0 & (X86_CR0_TS | X86_CR0_EM | X86_CR0_MP))
|
---|
[18927] | 622 | != (pVCpu->cpum.s.Guest.cr0 & (X86_CR0_TS | X86_CR0_EM | X86_CR0_MP)))
|
---|
[5389] | 623 | {
|
---|
[18927] | 624 | if (!(pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU))
|
---|
[5389] | 625 | {
|
---|
[5695] | 626 | /*
|
---|
| 627 | * We haven't saved the host FPU state yet, so TS and MT are both set
|
---|
[5389] | 628 | * and EM should be reflecting the guest EM (it always does this).
|
---|
| 629 | */
|
---|
[18927] | 630 | if ((cr0 & X86_CR0_EM) != (pVCpu->cpum.s.Guest.cr0 & X86_CR0_EM))
|
---|
[5389] | 631 | {
|
---|
| 632 | uint32_t HyperCR0 = ASMGetCR0();
|
---|
| 633 | AssertMsg((HyperCR0 & (X86_CR0_TS | X86_CR0_MP)) == (X86_CR0_TS | X86_CR0_MP), ("%#x\n", HyperCR0));
|
---|
[18927] | 634 | AssertMsg((HyperCR0 & X86_CR0_EM) == (pVCpu->cpum.s.Guest.cr0 & X86_CR0_EM), ("%#x\n", HyperCR0));
|
---|
[5389] | 635 | HyperCR0 &= ~X86_CR0_EM;
|
---|
| 636 | HyperCR0 |= cr0 & X86_CR0_EM;
|
---|
| 637 | Log(("CPUM New HyperCR0=%#x\n", HyperCR0));
|
---|
| 638 | ASMSetCR0(HyperCR0);
|
---|
| 639 | }
|
---|
[12657] | 640 | # ifdef VBOX_STRICT
|
---|
[5389] | 641 | else
|
---|
| 642 | {
|
---|
| 643 | uint32_t HyperCR0 = ASMGetCR0();
|
---|
| 644 | AssertMsg((HyperCR0 & (X86_CR0_TS | X86_CR0_MP)) == (X86_CR0_TS | X86_CR0_MP), ("%#x\n", HyperCR0));
|
---|
[18927] | 645 | AssertMsg((HyperCR0 & X86_CR0_EM) == (pVCpu->cpum.s.Guest.cr0 & X86_CR0_EM), ("%#x\n", HyperCR0));
|
---|
[5389] | 646 | }
|
---|
[12657] | 647 | # endif
|
---|
[5389] | 648 | }
|
---|
| 649 | else
|
---|
| 650 | {
|
---|
| 651 | /*
|
---|
[5695] | 652 | * Already saved the state, so we're just mirroring
|
---|
[5389] | 653 | * the guest flags.
|
---|
| 654 | */
|
---|
| 655 | uint32_t HyperCR0 = ASMGetCR0();
|
---|
[31079] | 656 | AssertMsg( (HyperCR0 & (X86_CR0_TS | X86_CR0_EM | X86_CR0_MP))
|
---|
[18927] | 657 | == (pVCpu->cpum.s.Guest.cr0 & (X86_CR0_TS | X86_CR0_EM | X86_CR0_MP)),
|
---|
| 658 | ("%#x %#x\n", HyperCR0, pVCpu->cpum.s.Guest.cr0));
|
---|
[5389] | 659 | HyperCR0 &= ~(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP);
|
---|
| 660 | HyperCR0 |= cr0 & (X86_CR0_TS | X86_CR0_EM | X86_CR0_MP);
|
---|
| 661 | Log(("CPUM New HyperCR0=%#x\n", HyperCR0));
|
---|
| 662 | ASMSetCR0(HyperCR0);
|
---|
| 663 | }
|
---|
| 664 | }
|
---|
[13832] | 665 | #endif /* IN_RC */
|
---|
[5389] | 666 |
|
---|
[5695] | 667 | /*
|
---|
| 668 | * Check for changes causing TLB flushes (for REM).
|
---|
| 669 | * The caller is responsible for calling PGM when appropriate.
|
---|
[5389] | 670 | */
|
---|
[31079] | 671 | if ( (cr0 & (X86_CR0_PG | X86_CR0_WP | X86_CR0_PE))
|
---|
[18927] | 672 | != (pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PG | X86_CR0_WP | X86_CR0_PE)))
|
---|
| 673 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_GLOBAL_TLB_FLUSH;
|
---|
| 674 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CR0;
|
---|
[5389] | 675 |
|
---|
[18927] | 676 | pVCpu->cpum.s.Guest.cr0 = cr0 | X86_CR0_ET;
|
---|
[1] | 677 | return VINF_SUCCESS;
|
---|
| 678 | }
|
---|
| 679 |
|
---|
[12657] | 680 |
|
---|
[18927] | 681 | VMMDECL(int) CPUMSetGuestCR2(PVMCPU pVCpu, uint64_t cr2)
|
---|
[1] | 682 | {
|
---|
[18927] | 683 | pVCpu->cpum.s.Guest.cr2 = cr2;
|
---|
[1] | 684 | return VINF_SUCCESS;
|
---|
| 685 | }
|
---|
| 686 |
|
---|
[12657] | 687 |
|
---|
[18927] | 688 | VMMDECL(int) CPUMSetGuestCR3(PVMCPU pVCpu, uint64_t cr3)
|
---|
[1] | 689 | {
|
---|
[18927] | 690 | pVCpu->cpum.s.Guest.cr3 = cr3;
|
---|
| 691 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CR3;
|
---|
[1] | 692 | return VINF_SUCCESS;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[12657] | 695 |
|
---|
[18927] | 696 | VMMDECL(int) CPUMSetGuestCR4(PVMCPU pVCpu, uint64_t cr4)
|
---|
[1] | 697 | {
|
---|
[31060] | 698 | if ( (cr4 & (X86_CR4_PGE | X86_CR4_PAE | X86_CR4_PSE))
|
---|
[18927] | 699 | != (pVCpu->cpum.s.Guest.cr4 & (X86_CR4_PGE | X86_CR4_PAE | X86_CR4_PSE)))
|
---|
| 700 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_GLOBAL_TLB_FLUSH;
|
---|
| 701 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CR4;
|
---|
| 702 | if (!CPUMSupportsFXSR(pVCpu->CTX_SUFF(pVM)))
|
---|
[1] | 703 | cr4 &= ~X86_CR4_OSFSXR;
|
---|
[18927] | 704 | pVCpu->cpum.s.Guest.cr4 = cr4;
|
---|
[1] | 705 | return VINF_SUCCESS;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
[12657] | 708 |
|
---|
[18927] | 709 | VMMDECL(int) CPUMSetGuestEFlags(PVMCPU pVCpu, uint32_t eflags)
|
---|
[1] | 710 | {
|
---|
[18927] | 711 | pVCpu->cpum.s.Guest.eflags.u32 = eflags;
|
---|
[1] | 712 | return VINF_SUCCESS;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[12657] | 715 |
|
---|
[18927] | 716 | VMMDECL(int) CPUMSetGuestEIP(PVMCPU pVCpu, uint32_t eip)
|
---|
[1] | 717 | {
|
---|
[18927] | 718 | pVCpu->cpum.s.Guest.eip = eip;
|
---|
[1] | 719 | return VINF_SUCCESS;
|
---|
| 720 | }
|
---|
| 721 |
|
---|
[12657] | 722 |
|
---|
[18927] | 723 | VMMDECL(int) CPUMSetGuestEAX(PVMCPU pVCpu, uint32_t eax)
|
---|
[1] | 724 | {
|
---|
[18927] | 725 | pVCpu->cpum.s.Guest.eax = eax;
|
---|
[1] | 726 | return VINF_SUCCESS;
|
---|
| 727 | }
|
---|
| 728 |
|
---|
[12657] | 729 |
|
---|
[18927] | 730 | VMMDECL(int) CPUMSetGuestEBX(PVMCPU pVCpu, uint32_t ebx)
|
---|
[1] | 731 | {
|
---|
[18927] | 732 | pVCpu->cpum.s.Guest.ebx = ebx;
|
---|
[1] | 733 | return VINF_SUCCESS;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[12657] | 736 |
|
---|
[18927] | 737 | VMMDECL(int) CPUMSetGuestECX(PVMCPU pVCpu, uint32_t ecx)
|
---|
[1] | 738 | {
|
---|
[18927] | 739 | pVCpu->cpum.s.Guest.ecx = ecx;
|
---|
[1] | 740 | return VINF_SUCCESS;
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[12657] | 743 |
|
---|
[18927] | 744 | VMMDECL(int) CPUMSetGuestEDX(PVMCPU pVCpu, uint32_t edx)
|
---|
[1] | 745 | {
|
---|
[18927] | 746 | pVCpu->cpum.s.Guest.edx = edx;
|
---|
[1] | 747 | return VINF_SUCCESS;
|
---|
| 748 | }
|
---|
| 749 |
|
---|
[12657] | 750 |
|
---|
[18927] | 751 | VMMDECL(int) CPUMSetGuestESP(PVMCPU pVCpu, uint32_t esp)
|
---|
[1] | 752 | {
|
---|
[18927] | 753 | pVCpu->cpum.s.Guest.esp = esp;
|
---|
[1] | 754 | return VINF_SUCCESS;
|
---|
| 755 | }
|
---|
| 756 |
|
---|
[12657] | 757 |
|
---|
[18927] | 758 | VMMDECL(int) CPUMSetGuestEBP(PVMCPU pVCpu, uint32_t ebp)
|
---|
[1] | 759 | {
|
---|
[18927] | 760 | pVCpu->cpum.s.Guest.ebp = ebp;
|
---|
[1] | 761 | return VINF_SUCCESS;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
[12657] | 764 |
|
---|
[18927] | 765 | VMMDECL(int) CPUMSetGuestESI(PVMCPU pVCpu, uint32_t esi)
|
---|
[1] | 766 | {
|
---|
[18927] | 767 | pVCpu->cpum.s.Guest.esi = esi;
|
---|
[1] | 768 | return VINF_SUCCESS;
|
---|
| 769 | }
|
---|
| 770 |
|
---|
[12657] | 771 |
|
---|
[18927] | 772 | VMMDECL(int) CPUMSetGuestEDI(PVMCPU pVCpu, uint32_t edi)
|
---|
[1] | 773 | {
|
---|
[18927] | 774 | pVCpu->cpum.s.Guest.edi = edi;
|
---|
[1] | 775 | return VINF_SUCCESS;
|
---|
| 776 | }
|
---|
| 777 |
|
---|
[12657] | 778 |
|
---|
[18927] | 779 | VMMDECL(int) CPUMSetGuestSS(PVMCPU pVCpu, uint16_t ss)
|
---|
[1] | 780 | {
|
---|
[41906] | 781 | pVCpu->cpum.s.Guest.ss.Sel = ss;
|
---|
[1] | 782 | return VINF_SUCCESS;
|
---|
| 783 | }
|
---|
| 784 |
|
---|
[12657] | 785 |
|
---|
[18927] | 786 | VMMDECL(int) CPUMSetGuestCS(PVMCPU pVCpu, uint16_t cs)
|
---|
[1] | 787 | {
|
---|
[41906] | 788 | pVCpu->cpum.s.Guest.cs.Sel = cs;
|
---|
[1] | 789 | return VINF_SUCCESS;
|
---|
| 790 | }
|
---|
| 791 |
|
---|
[12657] | 792 |
|
---|
[18927] | 793 | VMMDECL(int) CPUMSetGuestDS(PVMCPU pVCpu, uint16_t ds)
|
---|
[1] | 794 | {
|
---|
[41906] | 795 | pVCpu->cpum.s.Guest.ds.Sel = ds;
|
---|
[1] | 796 | return VINF_SUCCESS;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
[12657] | 799 |
|
---|
[18927] | 800 | VMMDECL(int) CPUMSetGuestES(PVMCPU pVCpu, uint16_t es)
|
---|
[1] | 801 | {
|
---|
[41906] | 802 | pVCpu->cpum.s.Guest.es.Sel = es;
|
---|
[1] | 803 | return VINF_SUCCESS;
|
---|
| 804 | }
|
---|
| 805 |
|
---|
[12657] | 806 |
|
---|
[18927] | 807 | VMMDECL(int) CPUMSetGuestFS(PVMCPU pVCpu, uint16_t fs)
|
---|
[1] | 808 | {
|
---|
[41906] | 809 | pVCpu->cpum.s.Guest.fs.Sel = fs;
|
---|
[1] | 810 | return VINF_SUCCESS;
|
---|
| 811 | }
|
---|
| 812 |
|
---|
[12657] | 813 |
|
---|
[18927] | 814 | VMMDECL(int) CPUMSetGuestGS(PVMCPU pVCpu, uint16_t gs)
|
---|
[1] | 815 | {
|
---|
[41906] | 816 | pVCpu->cpum.s.Guest.gs.Sel = gs;
|
---|
[1] | 817 | return VINF_SUCCESS;
|
---|
| 818 | }
|
---|
| 819 |
|
---|
[12657] | 820 |
|
---|
[18927] | 821 | VMMDECL(void) CPUMSetGuestEFER(PVMCPU pVCpu, uint64_t val)
|
---|
[7730] | 822 | {
|
---|
[18927] | 823 | pVCpu->cpum.s.Guest.msrEFER = val;
|
---|
[7730] | 824 | }
|
---|
[1] | 825 |
|
---|
[12657] | 826 |
|
---|
[30861] | 827 | /**
|
---|
| 828 | * Query an MSR.
|
---|
| 829 | *
|
---|
| 830 | * The caller is responsible for checking privilege if the call is the result
|
---|
[41836] | 831 | * of a RDMSR instruction. We'll do the rest.
|
---|
[30861] | 832 | *
|
---|
| 833 | * @retval VINF_SUCCESS on success.
|
---|
| 834 | * @retval VERR_CPUM_RAISE_GP_0 on failure (invalid MSR), the caller is
|
---|
| 835 | * expected to take the appropriate actions. @a *puValue is set to 0.
|
---|
[41836] | 836 | * @param pVCpu Pointer to the VMCPU.
|
---|
[30861] | 837 | * @param idMsr The MSR.
|
---|
[41836] | 838 | * @param puValue Where to return the value.
|
---|
[30861] | 839 | *
|
---|
| 840 | * @remarks This will always return the right values, even when we're in the
|
---|
| 841 | * recompiler.
|
---|
| 842 | */
|
---|
| 843 | VMMDECL(int) CPUMQueryGuestMsr(PVMCPU pVCpu, uint32_t idMsr, uint64_t *puValue)
|
---|
[9852] | 844 | {
|
---|
[30861] | 845 | /*
|
---|
| 846 | * If we don't indicate MSR support in the CPUID feature bits, indicate
|
---|
| 847 | * that a #GP(0) should be raised.
|
---|
| 848 | */
|
---|
| 849 | if (!(pVCpu->CTX_SUFF(pVM)->cpum.s.aGuestCpuIdStd[1].edx & X86_CPUID_FEATURE_EDX_MSR))
|
---|
| 850 | {
|
---|
| 851 | *puValue = 0;
|
---|
[40170] | 852 | return VERR_CPUM_RAISE_GP_0; /** @todo isn't \#UD more correct if not supported? */
|
---|
[30861] | 853 | }
|
---|
[9852] | 854 |
|
---|
[30861] | 855 | int rc = VINF_SUCCESS;
|
---|
| 856 | uint8_t const u8Multiplier = 4;
|
---|
[9852] | 857 | switch (idMsr)
|
---|
| 858 | {
|
---|
[18082] | 859 | case MSR_IA32_TSC:
|
---|
[30861] | 860 | *puValue = TMCpuTickGet(pVCpu);
|
---|
[18082] | 861 | break;
|
---|
| 862 |
|
---|
[30861] | 863 | case MSR_IA32_APICBASE:
|
---|
[43657] | 864 | {
|
---|
| 865 | PVM pVM = pVCpu->CTX_SUFF(pVM);
|
---|
| 866 | if ( ( pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1
|
---|
| 867 | && (pVM->cpum.s.aGuestCpuIdStd[1].edx & X86_CPUID_FEATURE_EDX_APIC))
|
---|
| 868 | || ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
| 869 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD
|
---|
| 870 | && (pVM->cpum.s.aGuestCpuIdExt[1].edx & X86_CPUID_AMD_FEATURE_EDX_APIC)))
|
---|
| 871 | {
|
---|
| 872 | *puValue = pVCpu->cpum.s.Guest.msrApicBase;
|
---|
| 873 | }
|
---|
[30861] | 874 | else
|
---|
| 875 | {
|
---|
| 876 | *puValue = 0;
|
---|
| 877 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 878 | }
|
---|
| 879 | break;
|
---|
[43657] | 880 | }
|
---|
[30861] | 881 |
|
---|
[12657] | 882 | case MSR_IA32_CR_PAT:
|
---|
[30861] | 883 | *puValue = pVCpu->cpum.s.Guest.msrPAT;
|
---|
[12657] | 884 | break;
|
---|
[9852] | 885 |
|
---|
[12657] | 886 | case MSR_IA32_SYSENTER_CS:
|
---|
[30861] | 887 | *puValue = pVCpu->cpum.s.Guest.SysEnter.cs;
|
---|
[12657] | 888 | break;
|
---|
[9852] | 889 |
|
---|
[12657] | 890 | case MSR_IA32_SYSENTER_EIP:
|
---|
[30861] | 891 | *puValue = pVCpu->cpum.s.Guest.SysEnter.eip;
|
---|
[12657] | 892 | break;
|
---|
[9852] | 893 |
|
---|
[12657] | 894 | case MSR_IA32_SYSENTER_ESP:
|
---|
[30861] | 895 | *puValue = pVCpu->cpum.s.Guest.SysEnter.esp;
|
---|
[12657] | 896 | break;
|
---|
[9852] | 897 |
|
---|
[40170] | 898 | case MSR_IA32_MTRR_CAP:
|
---|
| 899 | {
|
---|
| 900 | /* This is currently a bit weird. :-) */
|
---|
| 901 | uint8_t const cVariableRangeRegs = 0;
|
---|
| 902 | bool const fSystemManagementRangeRegisters = false;
|
---|
| 903 | bool const fFixedRangeRegisters = false;
|
---|
| 904 | bool const fWriteCombiningType = false;
|
---|
| 905 | *puValue = cVariableRangeRegs
|
---|
| 906 | | (fFixedRangeRegisters ? RT_BIT_64(8) : 0)
|
---|
| 907 | | (fWriteCombiningType ? RT_BIT_64(10) : 0)
|
---|
| 908 | | (fSystemManagementRangeRegisters ? RT_BIT_64(11) : 0);
|
---|
| 909 | break;
|
---|
| 910 | }
|
---|
| 911 |
|
---|
| 912 | case MSR_IA32_MTRR_DEF_TYPE:
|
---|
| 913 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrDefType;
|
---|
| 914 | break;
|
---|
| 915 |
|
---|
| 916 | case IA32_MTRR_FIX64K_00000:
|
---|
| 917 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix64K_00000;
|
---|
| 918 | break;
|
---|
| 919 | case IA32_MTRR_FIX16K_80000:
|
---|
| 920 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix16K_80000;
|
---|
| 921 | break;
|
---|
| 922 | case IA32_MTRR_FIX16K_A0000:
|
---|
| 923 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix16K_A0000;
|
---|
| 924 | break;
|
---|
| 925 | case IA32_MTRR_FIX4K_C0000:
|
---|
| 926 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_C0000;
|
---|
| 927 | break;
|
---|
| 928 | case IA32_MTRR_FIX4K_C8000:
|
---|
| 929 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_C8000;
|
---|
| 930 | break;
|
---|
| 931 | case IA32_MTRR_FIX4K_D0000:
|
---|
| 932 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_D0000;
|
---|
| 933 | break;
|
---|
| 934 | case IA32_MTRR_FIX4K_D8000:
|
---|
| 935 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_D8000;
|
---|
| 936 | break;
|
---|
| 937 | case IA32_MTRR_FIX4K_E0000:
|
---|
| 938 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_E0000;
|
---|
| 939 | break;
|
---|
| 940 | case IA32_MTRR_FIX4K_E8000:
|
---|
| 941 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_E8000;
|
---|
| 942 | break;
|
---|
| 943 | case IA32_MTRR_FIX4K_F0000:
|
---|
| 944 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_F0000;
|
---|
| 945 | break;
|
---|
| 946 | case IA32_MTRR_FIX4K_F8000:
|
---|
| 947 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_F8000;
|
---|
| 948 | break;
|
---|
| 949 |
|
---|
[12657] | 950 | case MSR_K6_EFER:
|
---|
[30861] | 951 | *puValue = pVCpu->cpum.s.Guest.msrEFER;
|
---|
[12657] | 952 | break;
|
---|
[9852] | 953 |
|
---|
[12657] | 954 | case MSR_K8_SF_MASK:
|
---|
[30861] | 955 | *puValue = pVCpu->cpum.s.Guest.msrSFMASK;
|
---|
[12657] | 956 | break;
|
---|
[9852] | 957 |
|
---|
[12657] | 958 | case MSR_K6_STAR:
|
---|
[30861] | 959 | *puValue = pVCpu->cpum.s.Guest.msrSTAR;
|
---|
[12657] | 960 | break;
|
---|
[9852] | 961 |
|
---|
[12657] | 962 | case MSR_K8_LSTAR:
|
---|
[30861] | 963 | *puValue = pVCpu->cpum.s.Guest.msrLSTAR;
|
---|
[12657] | 964 | break;
|
---|
[9852] | 965 |
|
---|
[12657] | 966 | case MSR_K8_CSTAR:
|
---|
[30861] | 967 | *puValue = pVCpu->cpum.s.Guest.msrCSTAR;
|
---|
[12657] | 968 | break;
|
---|
[9852] | 969 |
|
---|
[30861] | 970 | case MSR_K8_FS_BASE:
|
---|
[41906] | 971 | *puValue = pVCpu->cpum.s.Guest.fs.u64Base;
|
---|
[30861] | 972 | break;
|
---|
| 973 |
|
---|
| 974 | case MSR_K8_GS_BASE:
|
---|
[41906] | 975 | *puValue = pVCpu->cpum.s.Guest.gs.u64Base;
|
---|
[30861] | 976 | break;
|
---|
| 977 |
|
---|
[12657] | 978 | case MSR_K8_KERNEL_GS_BASE:
|
---|
[30861] | 979 | *puValue = pVCpu->cpum.s.Guest.msrKERNELGSBASE;
|
---|
[12657] | 980 | break;
|
---|
[9852] | 981 |
|
---|
[14411] | 982 | case MSR_K8_TSC_AUX:
|
---|
[40170] | 983 | *puValue = pVCpu->cpum.s.GuestMsrs.msr.TscAux;
|
---|
[14411] | 984 | break;
|
---|
| 985 |
|
---|
[24753] | 986 | case MSR_IA32_PERF_STATUS:
|
---|
[30861] | 987 | /** @todo could really be not exactly correct, maybe use host's values */
|
---|
| 988 | *puValue = UINT64_C(1000) /* TSC increment by tick */
|
---|
| 989 | | ((uint64_t)u8Multiplier << 24) /* CPU multiplier (aka bus ratio) min */
|
---|
| 990 | | ((uint64_t)u8Multiplier << 40) /* CPU multiplier (aka bus ratio) max */;
|
---|
[24753] | 991 | break;
|
---|
| 992 |
|
---|
[30861] | 993 | case MSR_IA32_FSB_CLOCK_STS:
|
---|
| 994 | /*
|
---|
[28030] | 995 | * Encoded as:
|
---|
| 996 | * 0 - 266
|
---|
| 997 | * 1 - 133
|
---|
| 998 | * 2 - 200
|
---|
| 999 | * 3 - return 166
|
---|
| 1000 | * 5 - return 100
|
---|
| 1001 | */
|
---|
[30861] | 1002 | *puValue = (2 << 4);
|
---|
[28030] | 1003 | break;
|
---|
| 1004 |
|
---|
[26993] | 1005 | case MSR_IA32_PLATFORM_INFO:
|
---|
[30861] | 1006 | *puValue = (u8Multiplier << 8) /* Flex ratio max */
|
---|
| 1007 | | ((uint64_t)u8Multiplier << 40) /* Flex ratio min */;
|
---|
[26993] | 1008 | break;
|
---|
| 1009 |
|
---|
[28030] | 1010 | case MSR_IA32_THERM_STATUS:
|
---|
[33540] | 1011 | /* CPU temperature relative to TCC, to actually activate, CPUID leaf 6 EAX[0] must be set */
|
---|
[39038] | 1012 | *puValue = RT_BIT(31) /* validity bit */
|
---|
| 1013 | | (UINT64_C(20) << 16) /* degrees till TCC */;
|
---|
[28030] | 1014 | break;
|
---|
| 1015 |
|
---|
[27331] | 1016 | case MSR_IA32_MISC_ENABLE:
|
---|
| 1017 | #if 0
|
---|
| 1018 | /* Needs to be tested more before enabling. */
|
---|
[30861] | 1019 | *puValue = pVCpu->cpum.s.GuestMsr.msr.miscEnable;
|
---|
[27331] | 1020 | #else
|
---|
[36315] | 1021 | /* Currenty we don't allow guests to modify enable MSRs. */
|
---|
| 1022 | *puValue = MSR_IA32_MISC_ENABLE_FAST_STRINGS /* by default */;
|
---|
| 1023 |
|
---|
| 1024 | if ((pVCpu->CTX_SUFF(pVM)->cpum.s.aGuestCpuIdStd[1].ecx & X86_CPUID_FEATURE_ECX_MONITOR) != 0)
|
---|
[36639] | 1025 |
|
---|
[36315] | 1026 | *puValue |= MSR_IA32_MISC_ENABLE_MONITOR /* if mwait/monitor available */;
|
---|
| 1027 | /** @todo: add more cpuid-controlled features this way. */
|
---|
[27331] | 1028 | #endif
|
---|
| 1029 | break;
|
---|
| 1030 |
|
---|
[30861] | 1031 | #if 0 /*def IN_RING0 */
|
---|
| 1032 | case MSR_IA32_PLATFORM_ID:
|
---|
| 1033 | case MSR_IA32_BIOS_SIGN_ID:
|
---|
| 1034 | if (CPUMGetCPUVendor(pVM) == CPUMCPUVENDOR_INTEL)
|
---|
| 1035 | {
|
---|
| 1036 | /* Available since the P6 family. VT-x implies that this feature is present. */
|
---|
| 1037 | if (idMsr == MSR_IA32_PLATFORM_ID)
|
---|
| 1038 | *puValue = ASMRdMsr(MSR_IA32_PLATFORM_ID);
|
---|
| 1039 | else if (idMsr == MSR_IA32_BIOS_SIGN_ID)
|
---|
| 1040 | *puValue = ASMRdMsr(MSR_IA32_BIOS_SIGN_ID);
|
---|
| 1041 | break;
|
---|
| 1042 | }
|
---|
| 1043 | /* no break */
|
---|
| 1044 | #endif
|
---|
| 1045 |
|
---|
[42640] | 1046 | /*
|
---|
| 1047 | * Intel specifics MSRs:
|
---|
| 1048 | */
|
---|
[42647] | 1049 | case MSR_IA32_PLATFORM_ID: /* fam/mod >= 6_01 */
|
---|
[42640] | 1050 | case MSR_IA32_BIOS_SIGN_ID: /* fam/mod >= 6_01 */
|
---|
[42647] | 1051 | /*case MSR_IA32_BIOS_UPDT_TRIG: - write-only? */
|
---|
| 1052 | case MSR_IA32_MCP_CAP: /* fam/mod >= 6_01 */
|
---|
| 1053 | /*case MSR_IA32_MCP_STATUS: - indicated as not present in CAP */
|
---|
| 1054 | /*case MSR_IA32_MCP_CTRL: - indicated as not present in CAP */
|
---|
| 1055 | case MSR_IA32_MC0_CTL:
|
---|
| 1056 | case MSR_IA32_MC0_STATUS:
|
---|
[42640] | 1057 | *puValue = 0;
|
---|
| 1058 | if (CPUMGetGuestCpuVendor(pVCpu->CTX_SUFF(pVM)) != CPUMCPUVENDOR_INTEL)
|
---|
| 1059 | {
|
---|
| 1060 | Log(("MSR %#x is Intel, the virtual CPU isn't an Intel one -> #GP\n", idMsr));
|
---|
| 1061 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 1062 | }
|
---|
| 1063 | break;
|
---|
| 1064 |
|
---|
[12657] | 1065 | default:
|
---|
[42640] | 1066 | /*
|
---|
| 1067 | * Hand the X2APIC range to PDM and the APIC.
|
---|
| 1068 | */
|
---|
[30861] | 1069 | if ( idMsr >= MSR_IA32_APIC_START
|
---|
| 1070 | && idMsr < MSR_IA32_APIC_END)
|
---|
| 1071 | {
|
---|
| 1072 | rc = PDMApicReadMSR(pVCpu->CTX_SUFF(pVM), pVCpu->idCpu, idMsr, puValue);
|
---|
| 1073 | if (RT_SUCCESS(rc))
|
---|
| 1074 | rc = VINF_SUCCESS;
|
---|
| 1075 | else
|
---|
| 1076 | {
|
---|
| 1077 | *puValue = 0;
|
---|
| 1078 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 1079 | }
|
---|
| 1080 | }
|
---|
| 1081 | else
|
---|
| 1082 | {
|
---|
| 1083 | *puValue = 0;
|
---|
| 1084 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 1085 | }
|
---|
[12657] | 1086 | break;
|
---|
[9852] | 1087 | }
|
---|
[30861] | 1088 |
|
---|
| 1089 | return rc;
|
---|
[9852] | 1090 | }
|
---|
| 1091 |
|
---|
[30861] | 1092 |
|
---|
| 1093 | /**
|
---|
| 1094 | * Sets the MSR.
|
---|
| 1095 | *
|
---|
| 1096 | * The caller is responsible for checking privilege if the call is the result
|
---|
[41836] | 1097 | * of a WRMSR instruction. We'll do the rest.
|
---|
[30861] | 1098 | *
|
---|
| 1099 | * @retval VINF_SUCCESS on success.
|
---|
| 1100 | * @retval VERR_CPUM_RAISE_GP_0 on failure, the caller is expected to take the
|
---|
| 1101 | * appropriate actions.
|
---|
| 1102 | *
|
---|
[41836] | 1103 | * @param pVCpu Pointer to the VMCPU.
|
---|
[30861] | 1104 | * @param idMsr The MSR id.
|
---|
| 1105 | * @param uValue The value to set.
|
---|
| 1106 | *
|
---|
| 1107 | * @remarks Everyone changing MSR values, including the recompiler, shall do it
|
---|
[41836] | 1108 | * by calling this method. This makes sure we have current values and
|
---|
[30861] | 1109 | * that we trigger all the right actions when something changes.
|
---|
| 1110 | */
|
---|
| 1111 | VMMDECL(int) CPUMSetGuestMsr(PVMCPU pVCpu, uint32_t idMsr, uint64_t uValue)
|
---|
[14411] | 1112 | {
|
---|
[30861] | 1113 | /*
|
---|
| 1114 | * If we don't indicate MSR support in the CPUID feature bits, indicate
|
---|
| 1115 | * that a #GP(0) should be raised.
|
---|
| 1116 | */
|
---|
| 1117 | if (!(pVCpu->CTX_SUFF(pVM)->cpum.s.aGuestCpuIdStd[1].edx & X86_CPUID_FEATURE_EDX_MSR))
|
---|
[40170] | 1118 | return VERR_CPUM_RAISE_GP_0; /** @todo isn't \#UD more correct if not supported? */
|
---|
[30861] | 1119 |
|
---|
| 1120 | int rc = VINF_SUCCESS;
|
---|
[14411] | 1121 | switch (idMsr)
|
---|
| 1122 | {
|
---|
[30861] | 1123 | case MSR_IA32_MISC_ENABLE:
|
---|
[40170] | 1124 | pVCpu->cpum.s.GuestMsrs.msr.MiscEnable = uValue;
|
---|
[14411] | 1125 | break;
|
---|
| 1126 |
|
---|
[30861] | 1127 | case MSR_IA32_TSC:
|
---|
| 1128 | TMCpuTickSet(pVCpu->CTX_SUFF(pVM), pVCpu, uValue);
|
---|
[27331] | 1129 | break;
|
---|
| 1130 |
|
---|
[30861] | 1131 | case MSR_IA32_APICBASE:
|
---|
[43657] | 1132 | rc = PDMApicSetBase(pVCpu, uValue);
|
---|
[30861] | 1133 | if (rc != VINF_SUCCESS)
|
---|
| 1134 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 1135 | break;
|
---|
| 1136 |
|
---|
| 1137 | case MSR_IA32_CR_PAT:
|
---|
| 1138 | pVCpu->cpum.s.Guest.msrPAT = uValue;
|
---|
| 1139 | break;
|
---|
| 1140 |
|
---|
| 1141 | case MSR_IA32_SYSENTER_CS:
|
---|
| 1142 | pVCpu->cpum.s.Guest.SysEnter.cs = uValue & 0xffff; /* 16 bits selector */
|
---|
| 1143 | break;
|
---|
| 1144 |
|
---|
| 1145 | case MSR_IA32_SYSENTER_EIP:
|
---|
| 1146 | pVCpu->cpum.s.Guest.SysEnter.eip = uValue;
|
---|
| 1147 | break;
|
---|
| 1148 |
|
---|
| 1149 | case MSR_IA32_SYSENTER_ESP:
|
---|
| 1150 | pVCpu->cpum.s.Guest.SysEnter.esp = uValue;
|
---|
| 1151 | break;
|
---|
| 1152 |
|
---|
[40170] | 1153 | case MSR_IA32_MTRR_CAP:
|
---|
| 1154 | return VERR_CPUM_RAISE_GP_0;
|
---|
| 1155 |
|
---|
| 1156 | case MSR_IA32_MTRR_DEF_TYPE:
|
---|
| 1157 | if ( (uValue & UINT64_C(0xfffffffffffff300))
|
---|
| 1158 | || ( (uValue & 0xff) != 0
|
---|
| 1159 | && (uValue & 0xff) != 1
|
---|
| 1160 | && (uValue & 0xff) != 4
|
---|
| 1161 | && (uValue & 0xff) != 5
|
---|
| 1162 | && (uValue & 0xff) != 6) )
|
---|
| 1163 | {
|
---|
| 1164 | Log(("MSR_IA32_MTRR_DEF_TYPE: #GP(0) - writing reserved value (%#llx)\n", uValue));
|
---|
| 1165 | return VERR_CPUM_RAISE_GP_0;
|
---|
| 1166 | }
|
---|
| 1167 | pVCpu->cpum.s.GuestMsrs.msr.MtrrDefType = uValue;
|
---|
| 1168 | break;
|
---|
| 1169 |
|
---|
| 1170 | case IA32_MTRR_FIX64K_00000:
|
---|
| 1171 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix64K_00000 = uValue;
|
---|
| 1172 | break;
|
---|
| 1173 | case IA32_MTRR_FIX16K_80000:
|
---|
| 1174 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix16K_80000 = uValue;
|
---|
| 1175 | break;
|
---|
| 1176 | case IA32_MTRR_FIX16K_A0000:
|
---|
| 1177 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix16K_A0000 = uValue;
|
---|
| 1178 | break;
|
---|
| 1179 | case IA32_MTRR_FIX4K_C0000:
|
---|
| 1180 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_C0000 = uValue;
|
---|
| 1181 | break;
|
---|
| 1182 | case IA32_MTRR_FIX4K_C8000:
|
---|
| 1183 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_C8000 = uValue;
|
---|
| 1184 | break;
|
---|
| 1185 | case IA32_MTRR_FIX4K_D0000:
|
---|
| 1186 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_D0000 = uValue;
|
---|
| 1187 | break;
|
---|
| 1188 | case IA32_MTRR_FIX4K_D8000:
|
---|
| 1189 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_D8000 = uValue;
|
---|
| 1190 | break;
|
---|
| 1191 | case IA32_MTRR_FIX4K_E0000:
|
---|
| 1192 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_E0000 = uValue;
|
---|
| 1193 | break;
|
---|
| 1194 | case IA32_MTRR_FIX4K_E8000:
|
---|
| 1195 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_E8000 = uValue;
|
---|
| 1196 | break;
|
---|
| 1197 | case IA32_MTRR_FIX4K_F0000:
|
---|
| 1198 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_F0000 = uValue;
|
---|
| 1199 | break;
|
---|
| 1200 | case IA32_MTRR_FIX4K_F8000:
|
---|
| 1201 | pVCpu->cpum.s.GuestMsrs.msr.MtrrFix4K_F8000 = uValue;
|
---|
| 1202 | break;
|
---|
| 1203 |
|
---|
[42640] | 1204 | /*
|
---|
| 1205 | * AMD64 MSRs.
|
---|
| 1206 | */
|
---|
[30861] | 1207 | case MSR_K6_EFER:
|
---|
| 1208 | {
|
---|
| 1209 | PVM pVM = pVCpu->CTX_SUFF(pVM);
|
---|
| 1210 | uint64_t const uOldEFER = pVCpu->cpum.s.Guest.msrEFER;
|
---|
| 1211 | uint32_t const fExtFeatures = pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
| 1212 | ? pVM->cpum.s.aGuestCpuIdExt[1].edx
|
---|
| 1213 | : 0;
|
---|
| 1214 | uint64_t fMask = 0;
|
---|
| 1215 |
|
---|
| 1216 | /* Filter out those bits the guest is allowed to change. (e.g. LMA is read-only) */
|
---|
[42024] | 1217 | if (fExtFeatures & X86_CPUID_EXT_FEATURE_EDX_NX)
|
---|
[30861] | 1218 | fMask |= MSR_K6_EFER_NXE;
|
---|
[42024] | 1219 | if (fExtFeatures & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE)
|
---|
[30861] | 1220 | fMask |= MSR_K6_EFER_LME;
|
---|
[42024] | 1221 | if (fExtFeatures & X86_CPUID_EXT_FEATURE_EDX_SYSCALL)
|
---|
[30861] | 1222 | fMask |= MSR_K6_EFER_SCE;
|
---|
| 1223 | if (fExtFeatures & X86_CPUID_AMD_FEATURE_EDX_FFXSR)
|
---|
| 1224 | fMask |= MSR_K6_EFER_FFXSR;
|
---|
| 1225 |
|
---|
| 1226 | /* Check for illegal MSR_K6_EFER_LME transitions: not allowed to change LME if
|
---|
| 1227 | paging is enabled. (AMD Arch. Programmer's Manual Volume 2: Table 14-5) */
|
---|
| 1228 | if ( (uOldEFER & MSR_K6_EFER_LME) != (uValue & fMask & MSR_K6_EFER_LME)
|
---|
| 1229 | && (pVCpu->cpum.s.Guest.cr0 & X86_CR0_PG))
|
---|
| 1230 | {
|
---|
| 1231 | Log(("Illegal MSR_K6_EFER_LME change: paging is enabled!!\n"));
|
---|
| 1232 | return VERR_CPUM_RAISE_GP_0;
|
---|
| 1233 | }
|
---|
| 1234 |
|
---|
| 1235 | /* There are a few more: e.g. MSR_K6_EFER_LMSLE */
|
---|
| 1236 | AssertMsg(!(uValue & ~(MSR_K6_EFER_NXE | MSR_K6_EFER_LME | MSR_K6_EFER_LMA /* ignored anyway */ | MSR_K6_EFER_SCE | MSR_K6_EFER_FFXSR)),
|
---|
| 1237 | ("Unexpected value %RX64\n", uValue));
|
---|
| 1238 | pVCpu->cpum.s.Guest.msrEFER = (uOldEFER & ~fMask) | (uValue & fMask);
|
---|
| 1239 |
|
---|
| 1240 | /* AMD64 Architecture Programmer's Manual: 15.15 TLB Control; flush the TLB
|
---|
| 1241 | if MSR_K6_EFER_NXE, MSR_K6_EFER_LME or MSR_K6_EFER_LMA are changed. */
|
---|
[30889] | 1242 | if ( (uOldEFER & (MSR_K6_EFER_NXE | MSR_K6_EFER_LME | MSR_K6_EFER_LMA))
|
---|
[30861] | 1243 | != (pVCpu->cpum.s.Guest.msrEFER & (MSR_K6_EFER_NXE | MSR_K6_EFER_LME | MSR_K6_EFER_LMA)))
|
---|
| 1244 | {
|
---|
| 1245 | /// @todo PGMFlushTLB(pVCpu, cr3, true /*fGlobal*/);
|
---|
[43387] | 1246 | HMFlushTLB(pVCpu);
|
---|
[30861] | 1247 |
|
---|
| 1248 | /* Notify PGM about NXE changes. */
|
---|
[30889] | 1249 | if ( (uOldEFER & MSR_K6_EFER_NXE)
|
---|
[30861] | 1250 | != (pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_NXE))
|
---|
[30889] | 1251 | PGMNotifyNxeChanged(pVCpu, !(uOldEFER & MSR_K6_EFER_NXE));
|
---|
[30861] | 1252 | }
|
---|
| 1253 | break;
|
---|
| 1254 | }
|
---|
| 1255 |
|
---|
| 1256 | case MSR_K8_SF_MASK:
|
---|
| 1257 | pVCpu->cpum.s.Guest.msrSFMASK = uValue;
|
---|
| 1258 | break;
|
---|
| 1259 |
|
---|
| 1260 | case MSR_K6_STAR:
|
---|
| 1261 | pVCpu->cpum.s.Guest.msrSTAR = uValue;
|
---|
| 1262 | break;
|
---|
| 1263 |
|
---|
| 1264 | case MSR_K8_LSTAR:
|
---|
| 1265 | pVCpu->cpum.s.Guest.msrLSTAR = uValue;
|
---|
| 1266 | break;
|
---|
| 1267 |
|
---|
| 1268 | case MSR_K8_CSTAR:
|
---|
| 1269 | pVCpu->cpum.s.Guest.msrCSTAR = uValue;
|
---|
| 1270 | break;
|
---|
| 1271 |
|
---|
| 1272 | case MSR_K8_FS_BASE:
|
---|
[41906] | 1273 | pVCpu->cpum.s.Guest.fs.u64Base = uValue;
|
---|
[30861] | 1274 | break;
|
---|
| 1275 |
|
---|
| 1276 | case MSR_K8_GS_BASE:
|
---|
[41906] | 1277 | pVCpu->cpum.s.Guest.gs.u64Base = uValue;
|
---|
[30861] | 1278 | break;
|
---|
| 1279 |
|
---|
| 1280 | case MSR_K8_KERNEL_GS_BASE:
|
---|
| 1281 | pVCpu->cpum.s.Guest.msrKERNELGSBASE = uValue;
|
---|
| 1282 | break;
|
---|
| 1283 |
|
---|
| 1284 | case MSR_K8_TSC_AUX:
|
---|
[40170] | 1285 | pVCpu->cpum.s.GuestMsrs.msr.TscAux = uValue;
|
---|
[30861] | 1286 | break;
|
---|
| 1287 |
|
---|
[42640] | 1288 | /*
|
---|
| 1289 | * Intel specifics MSRs:
|
---|
| 1290 | */
|
---|
[42647] | 1291 | /*case MSR_IA32_PLATFORM_ID: - read-only */
|
---|
[42640] | 1292 | case MSR_IA32_BIOS_SIGN_ID: /* fam/mod >= 6_01 */
|
---|
| 1293 | case MSR_IA32_BIOS_UPDT_TRIG: /* fam/mod >= 6_01 */
|
---|
[42647] | 1294 | /*case MSR_IA32_MCP_CAP: - read-only */
|
---|
| 1295 | /*case MSR_IA32_MCP_STATUS: - read-only */
|
---|
| 1296 | /*case MSR_IA32_MCP_CTRL: - indicated as not present in CAP */
|
---|
| 1297 | /*case MSR_IA32_MC0_CTL: - read-only? */
|
---|
| 1298 | /*case MSR_IA32_MC0_STATUS: - read-only? */
|
---|
[42640] | 1299 | if (CPUMGetGuestCpuVendor(pVCpu->CTX_SUFF(pVM)) != CPUMCPUVENDOR_INTEL)
|
---|
| 1300 | {
|
---|
| 1301 | Log(("MSR %#x is Intel, the virtual CPU isn't an Intel one -> #GP\n", idMsr));
|
---|
| 1302 | return VERR_CPUM_RAISE_GP_0;
|
---|
| 1303 | }
|
---|
| 1304 | /* ignored */
|
---|
| 1305 | break;
|
---|
| 1306 |
|
---|
[14411] | 1307 | default:
|
---|
[42640] | 1308 | /*
|
---|
| 1309 | * Hand the X2APIC range to PDM and the APIC.
|
---|
| 1310 | */
|
---|
[30861] | 1311 | if ( idMsr >= MSR_IA32_APIC_START
|
---|
| 1312 | && idMsr < MSR_IA32_APIC_END)
|
---|
| 1313 | {
|
---|
| 1314 | rc = PDMApicWriteMSR(pVCpu->CTX_SUFF(pVM), pVCpu->idCpu, idMsr, uValue);
|
---|
| 1315 | if (rc != VINF_SUCCESS)
|
---|
| 1316 | rc = VERR_CPUM_RAISE_GP_0;
|
---|
| 1317 | }
|
---|
| 1318 | else
|
---|
| 1319 | {
|
---|
| 1320 | /* We should actually trigger a #GP here, but don't as that might cause more trouble. */
|
---|
| 1321 | /** @todo rc = VERR_CPUM_RAISE_GP_0 */
|
---|
| 1322 | Log(("CPUMSetGuestMsr: Unknown MSR %#x attempted set to %#llx\n", idMsr, uValue));
|
---|
| 1323 | }
|
---|
[14411] | 1324 | break;
|
---|
| 1325 | }
|
---|
[30861] | 1326 | return rc;
|
---|
[14411] | 1327 | }
|
---|
| 1328 |
|
---|
[30861] | 1329 |
|
---|
[18927] | 1330 | VMMDECL(RTGCPTR) CPUMGetGuestIDTR(PVMCPU pVCpu, uint16_t *pcbLimit)
|
---|
[1] | 1331 | {
|
---|
| 1332 | if (pcbLimit)
|
---|
[18927] | 1333 | *pcbLimit = pVCpu->cpum.s.Guest.idtr.cbIdt;
|
---|
| 1334 | return pVCpu->cpum.s.Guest.idtr.pIdt;
|
---|
[1] | 1335 | }
|
---|
| 1336 |
|
---|
[12657] | 1337 |
|
---|
[18927] | 1338 | VMMDECL(RTSEL) CPUMGetGuestTR(PVMCPU pVCpu, PCPUMSELREGHID pHidden)
|
---|
[1] | 1339 | {
|
---|
[17035] | 1340 | if (pHidden)
|
---|
[41906] | 1341 | *pHidden = pVCpu->cpum.s.Guest.tr;
|
---|
| 1342 | return pVCpu->cpum.s.Guest.tr.Sel;
|
---|
[1] | 1343 | }
|
---|
| 1344 |
|
---|
[12657] | 1345 |
|
---|
[18927] | 1346 | VMMDECL(RTSEL) CPUMGetGuestCS(PVMCPU pVCpu)
|
---|
[1] | 1347 | {
|
---|
[41906] | 1348 | return pVCpu->cpum.s.Guest.cs.Sel;
|
---|
[1] | 1349 | }
|
---|
| 1350 |
|
---|
[12657] | 1351 |
|
---|
[18927] | 1352 | VMMDECL(RTSEL) CPUMGetGuestDS(PVMCPU pVCpu)
|
---|
[1] | 1353 | {
|
---|
[41906] | 1354 | return pVCpu->cpum.s.Guest.ds.Sel;
|
---|
[1] | 1355 | }
|
---|
| 1356 |
|
---|
[12657] | 1357 |
|
---|
[18927] | 1358 | VMMDECL(RTSEL) CPUMGetGuestES(PVMCPU pVCpu)
|
---|
[1] | 1359 | {
|
---|
[41906] | 1360 | return pVCpu->cpum.s.Guest.es.Sel;
|
---|
[1] | 1361 | }
|
---|
| 1362 |
|
---|
[12657] | 1363 |
|
---|
[18927] | 1364 | VMMDECL(RTSEL) CPUMGetGuestFS(PVMCPU pVCpu)
|
---|
[1] | 1365 | {
|
---|
[41906] | 1366 | return pVCpu->cpum.s.Guest.fs.Sel;
|
---|
[1] | 1367 | }
|
---|
| 1368 |
|
---|
[12657] | 1369 |
|
---|
[18927] | 1370 | VMMDECL(RTSEL) CPUMGetGuestGS(PVMCPU pVCpu)
|
---|
[1] | 1371 | {
|
---|
[41906] | 1372 | return pVCpu->cpum.s.Guest.gs.Sel;
|
---|
[1] | 1373 | }
|
---|
| 1374 |
|
---|
[12657] | 1375 |
|
---|
[18927] | 1376 | VMMDECL(RTSEL) CPUMGetGuestSS(PVMCPU pVCpu)
|
---|
[1] | 1377 | {
|
---|
[41906] | 1378 | return pVCpu->cpum.s.Guest.ss.Sel;
|
---|
[1] | 1379 | }
|
---|
| 1380 |
|
---|
[12657] | 1381 |
|
---|
[18927] | 1382 | VMMDECL(RTSEL) CPUMGetGuestLDTR(PVMCPU pVCpu)
|
---|
[1] | 1383 | {
|
---|
[41906] | 1384 | return pVCpu->cpum.s.Guest.ldtr.Sel;
|
---|
[1] | 1385 | }
|
---|
| 1386 |
|
---|
[12657] | 1387 |
|
---|
[42427] | 1388 | VMMDECL(RTSEL) CPUMGetGuestLdtrEx(PVMCPU pVCpu, uint64_t *pGCPtrBase, uint32_t *pcbLimit)
|
---|
| 1389 | {
|
---|
| 1390 | *pGCPtrBase = pVCpu->cpum.s.Guest.ldtr.u64Base;
|
---|
| 1391 | *pcbLimit = pVCpu->cpum.s.Guest.ldtr.u32Limit;
|
---|
| 1392 | return pVCpu->cpum.s.Guest.ldtr.Sel;
|
---|
| 1393 | }
|
---|
| 1394 |
|
---|
| 1395 |
|
---|
[18927] | 1396 | VMMDECL(uint64_t) CPUMGetGuestCR0(PVMCPU pVCpu)
|
---|
[1] | 1397 | {
|
---|
[18927] | 1398 | return pVCpu->cpum.s.Guest.cr0;
|
---|
[1] | 1399 | }
|
---|
| 1400 |
|
---|
[12657] | 1401 |
|
---|
[18927] | 1402 | VMMDECL(uint64_t) CPUMGetGuestCR2(PVMCPU pVCpu)
|
---|
[1] | 1403 | {
|
---|
[18927] | 1404 | return pVCpu->cpum.s.Guest.cr2;
|
---|
[1] | 1405 | }
|
---|
| 1406 |
|
---|
[12657] | 1407 |
|
---|
[18927] | 1408 | VMMDECL(uint64_t) CPUMGetGuestCR3(PVMCPU pVCpu)
|
---|
[1] | 1409 | {
|
---|
[18927] | 1410 | return pVCpu->cpum.s.Guest.cr3;
|
---|
[1] | 1411 | }
|
---|
| 1412 |
|
---|
[12657] | 1413 |
|
---|
[18927] | 1414 | VMMDECL(uint64_t) CPUMGetGuestCR4(PVMCPU pVCpu)
|
---|
[1] | 1415 | {
|
---|
[18927] | 1416 | return pVCpu->cpum.s.Guest.cr4;
|
---|
[1] | 1417 | }
|
---|
| 1418 |
|
---|
[12657] | 1419 |
|
---|
[31489] | 1420 | VMMDECL(uint64_t) CPUMGetGuestCR8(PVMCPU pVCpu)
|
---|
| 1421 | {
|
---|
| 1422 | uint64_t u64;
|
---|
[41728] | 1423 | int rc = CPUMGetGuestCRx(pVCpu, DISCREG_CR8, &u64);
|
---|
[31489] | 1424 | if (RT_FAILURE(rc))
|
---|
| 1425 | u64 = 0;
|
---|
| 1426 | return u64;
|
---|
| 1427 | }
|
---|
| 1428 |
|
---|
| 1429 |
|
---|
[18927] | 1430 | VMMDECL(void) CPUMGetGuestGDTR(PVMCPU pVCpu, PVBOXGDTR pGDTR)
|
---|
[1] | 1431 | {
|
---|
[18927] | 1432 | *pGDTR = pVCpu->cpum.s.Guest.gdtr;
|
---|
[1] | 1433 | }
|
---|
| 1434 |
|
---|
[12657] | 1435 |
|
---|
[18927] | 1436 | VMMDECL(uint32_t) CPUMGetGuestEIP(PVMCPU pVCpu)
|
---|
[1] | 1437 | {
|
---|
[18927] | 1438 | return pVCpu->cpum.s.Guest.eip;
|
---|
[1] | 1439 | }
|
---|
| 1440 |
|
---|
[12657] | 1441 |
|
---|
[18927] | 1442 | VMMDECL(uint64_t) CPUMGetGuestRIP(PVMCPU pVCpu)
|
---|
[9841] | 1443 | {
|
---|
[18927] | 1444 | return pVCpu->cpum.s.Guest.rip;
|
---|
[9841] | 1445 | }
|
---|
| 1446 |
|
---|
[12657] | 1447 |
|
---|
[18927] | 1448 | VMMDECL(uint32_t) CPUMGetGuestEAX(PVMCPU pVCpu)
|
---|
[1] | 1449 | {
|
---|
[18927] | 1450 | return pVCpu->cpum.s.Guest.eax;
|
---|
[1] | 1451 | }
|
---|
| 1452 |
|
---|
[12657] | 1453 |
|
---|
[18927] | 1454 | VMMDECL(uint32_t) CPUMGetGuestEBX(PVMCPU pVCpu)
|
---|
[1] | 1455 | {
|
---|
[18927] | 1456 | return pVCpu->cpum.s.Guest.ebx;
|
---|
[1] | 1457 | }
|
---|
| 1458 |
|
---|
[12657] | 1459 |
|
---|
[18927] | 1460 | VMMDECL(uint32_t) CPUMGetGuestECX(PVMCPU pVCpu)
|
---|
[1] | 1461 | {
|
---|
[18927] | 1462 | return pVCpu->cpum.s.Guest.ecx;
|
---|
[1] | 1463 | }
|
---|
| 1464 |
|
---|
[12657] | 1465 |
|
---|
[18927] | 1466 | VMMDECL(uint32_t) CPUMGetGuestEDX(PVMCPU pVCpu)
|
---|
[1] | 1467 | {
|
---|
[18927] | 1468 | return pVCpu->cpum.s.Guest.edx;
|
---|
[1] | 1469 | }
|
---|
| 1470 |
|
---|
[12657] | 1471 |
|
---|
[18927] | 1472 | VMMDECL(uint32_t) CPUMGetGuestESI(PVMCPU pVCpu)
|
---|
[1] | 1473 | {
|
---|
[18927] | 1474 | return pVCpu->cpum.s.Guest.esi;
|
---|
[1] | 1475 | }
|
---|
| 1476 |
|
---|
[12657] | 1477 |
|
---|
[18927] | 1478 | VMMDECL(uint32_t) CPUMGetGuestEDI(PVMCPU pVCpu)
|
---|
[1] | 1479 | {
|
---|
[18927] | 1480 | return pVCpu->cpum.s.Guest.edi;
|
---|
[1] | 1481 | }
|
---|
| 1482 |
|
---|
[12657] | 1483 |
|
---|
[18927] | 1484 | VMMDECL(uint32_t) CPUMGetGuestESP(PVMCPU pVCpu)
|
---|
[1] | 1485 | {
|
---|
[18927] | 1486 | return pVCpu->cpum.s.Guest.esp;
|
---|
[1] | 1487 | }
|
---|
| 1488 |
|
---|
[12657] | 1489 |
|
---|
[18927] | 1490 | VMMDECL(uint32_t) CPUMGetGuestEBP(PVMCPU pVCpu)
|
---|
[1] | 1491 | {
|
---|
[18927] | 1492 | return pVCpu->cpum.s.Guest.ebp;
|
---|
[1] | 1493 | }
|
---|
| 1494 |
|
---|
[12657] | 1495 |
|
---|
[18927] | 1496 | VMMDECL(uint32_t) CPUMGetGuestEFlags(PVMCPU pVCpu)
|
---|
[1] | 1497 | {
|
---|
[18927] | 1498 | return pVCpu->cpum.s.Guest.eflags.u32;
|
---|
[1] | 1499 | }
|
---|
| 1500 |
|
---|
[12657] | 1501 |
|
---|
[18927] | 1502 | VMMDECL(int) CPUMGetGuestCRx(PVMCPU pVCpu, unsigned iReg, uint64_t *pValue)
|
---|
[1] | 1503 | {
|
---|
| 1504 | switch (iReg)
|
---|
| 1505 | {
|
---|
[41728] | 1506 | case DISCREG_CR0:
|
---|
[18927] | 1507 | *pValue = pVCpu->cpum.s.Guest.cr0;
|
---|
[1] | 1508 | break;
|
---|
[31489] | 1509 |
|
---|
[41728] | 1510 | case DISCREG_CR2:
|
---|
[18927] | 1511 | *pValue = pVCpu->cpum.s.Guest.cr2;
|
---|
[1] | 1512 | break;
|
---|
[31489] | 1513 |
|
---|
[41728] | 1514 | case DISCREG_CR3:
|
---|
[18927] | 1515 | *pValue = pVCpu->cpum.s.Guest.cr3;
|
---|
[1] | 1516 | break;
|
---|
[31489] | 1517 |
|
---|
[41728] | 1518 | case DISCREG_CR4:
|
---|
[18927] | 1519 | *pValue = pVCpu->cpum.s.Guest.cr4;
|
---|
[1] | 1520 | break;
|
---|
[31489] | 1521 |
|
---|
[41728] | 1522 | case DISCREG_CR8:
|
---|
[31489] | 1523 | {
|
---|
| 1524 | uint8_t u8Tpr;
|
---|
| 1525 | int rc = PDMApicGetTPR(pVCpu, &u8Tpr, NULL /*pfPending*/);
|
---|
| 1526 | if (RT_FAILURE(rc))
|
---|
| 1527 | {
|
---|
| 1528 | AssertMsg(rc == VERR_PDM_NO_APIC_INSTANCE, ("%Rrc\n", rc));
|
---|
| 1529 | *pValue = 0;
|
---|
| 1530 | return rc;
|
---|
| 1531 | }
|
---|
| 1532 | *pValue = u8Tpr >> 4; /* bits 7-4 contain the task priority that go in cr8, bits 3-0*/
|
---|
| 1533 | break;
|
---|
| 1534 | }
|
---|
| 1535 |
|
---|
[1] | 1536 | default:
|
---|
| 1537 | return VERR_INVALID_PARAMETER;
|
---|
| 1538 | }
|
---|
| 1539 | return VINF_SUCCESS;
|
---|
| 1540 | }
|
---|
| 1541 |
|
---|
[12657] | 1542 |
|
---|
[18927] | 1543 | VMMDECL(uint64_t) CPUMGetGuestDR0(PVMCPU pVCpu)
|
---|
[1] | 1544 | {
|
---|
[18927] | 1545 | return pVCpu->cpum.s.Guest.dr[0];
|
---|
[1] | 1546 | }
|
---|
| 1547 |
|
---|
[12657] | 1548 |
|
---|
[18927] | 1549 | VMMDECL(uint64_t) CPUMGetGuestDR1(PVMCPU pVCpu)
|
---|
[1] | 1550 | {
|
---|
[18927] | 1551 | return pVCpu->cpum.s.Guest.dr[1];
|
---|
[1] | 1552 | }
|
---|
| 1553 |
|
---|
[12657] | 1554 |
|
---|
[18927] | 1555 | VMMDECL(uint64_t) CPUMGetGuestDR2(PVMCPU pVCpu)
|
---|
[1] | 1556 | {
|
---|
[18927] | 1557 | return pVCpu->cpum.s.Guest.dr[2];
|
---|
[1] | 1558 | }
|
---|
| 1559 |
|
---|
[12657] | 1560 |
|
---|
[18927] | 1561 | VMMDECL(uint64_t) CPUMGetGuestDR3(PVMCPU pVCpu)
|
---|
[1] | 1562 | {
|
---|
[18927] | 1563 | return pVCpu->cpum.s.Guest.dr[3];
|
---|
[1] | 1564 | }
|
---|
| 1565 |
|
---|
[12657] | 1566 |
|
---|
[18927] | 1567 | VMMDECL(uint64_t) CPUMGetGuestDR6(PVMCPU pVCpu)
|
---|
[1] | 1568 | {
|
---|
[18927] | 1569 | return pVCpu->cpum.s.Guest.dr[6];
|
---|
[1] | 1570 | }
|
---|
| 1571 |
|
---|
[12657] | 1572 |
|
---|
[18927] | 1573 | VMMDECL(uint64_t) CPUMGetGuestDR7(PVMCPU pVCpu)
|
---|
[1] | 1574 | {
|
---|
[18927] | 1575 | return pVCpu->cpum.s.Guest.dr[7];
|
---|
[1] | 1576 | }
|
---|
| 1577 |
|
---|
[12657] | 1578 |
|
---|
[18927] | 1579 | VMMDECL(int) CPUMGetGuestDRx(PVMCPU pVCpu, uint32_t iReg, uint64_t *pValue)
|
---|
[1] | 1580 | {
|
---|
[41728] | 1581 | AssertReturn(iReg <= DISDREG_DR7, VERR_INVALID_PARAMETER);
|
---|
[12657] | 1582 | /* DR4 is an alias for DR6, and DR5 is an alias for DR7. */
|
---|
| 1583 | if (iReg == 4 || iReg == 5)
|
---|
| 1584 | iReg += 2;
|
---|
[18927] | 1585 | *pValue = pVCpu->cpum.s.Guest.dr[iReg];
|
---|
[1] | 1586 | return VINF_SUCCESS;
|
---|
| 1587 | }
|
---|
| 1588 |
|
---|
[12657] | 1589 |
|
---|
[18927] | 1590 | VMMDECL(uint64_t) CPUMGetGuestEFER(PVMCPU pVCpu)
|
---|
[7730] | 1591 | {
|
---|
[18927] | 1592 | return pVCpu->cpum.s.Guest.msrEFER;
|
---|
[7730] | 1593 | }
|
---|
| 1594 |
|
---|
[12657] | 1595 |
|
---|
[1] | 1596 | /**
|
---|
[42034] | 1597 | * Gets a CPUID leaf.
|
---|
[1] | 1598 | *
|
---|
[41802] | 1599 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 1600 | * @param iLeaf The CPUID leaf to get.
|
---|
| 1601 | * @param pEax Where to store the EAX value.
|
---|
| 1602 | * @param pEbx Where to store the EBX value.
|
---|
| 1603 | * @param pEcx Where to store the ECX value.
|
---|
| 1604 | * @param pEdx Where to store the EDX value.
|
---|
| 1605 | */
|
---|
[19076] | 1606 | VMMDECL(void) CPUMGetGuestCpuId(PVMCPU pVCpu, uint32_t iLeaf, uint32_t *pEax, uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx)
|
---|
[1] | 1607 | {
|
---|
[19076] | 1608 | PVM pVM = pVCpu->CTX_SUFF(pVM);
|
---|
| 1609 |
|
---|
[1] | 1610 | PCCPUMCPUID pCpuId;
|
---|
[11311] | 1611 | if (iLeaf < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd))
|
---|
[1] | 1612 | pCpuId = &pVM->cpum.s.aGuestCpuIdStd[iLeaf];
|
---|
[5285] | 1613 | else if (iLeaf - UINT32_C(0x80000000) < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt))
|
---|
[1] | 1614 | pCpuId = &pVM->cpum.s.aGuestCpuIdExt[iLeaf - UINT32_C(0x80000000)];
|
---|
[40235] | 1615 | else if ( iLeaf - UINT32_C(0x40000000) < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdHyper)
|
---|
| 1616 | && (pVCpu->CTX_SUFF(pVM)->cpum.s.aGuestCpuIdStd[1].ecx & X86_CPUID_FEATURE_ECX_HVP))
|
---|
| 1617 | pCpuId = &pVM->cpum.s.aGuestCpuIdHyper[iLeaf - UINT32_C(0x40000000)]; /* Only report if HVP bit set. */
|
---|
[5285] | 1618 | else if (iLeaf - UINT32_C(0xc0000000) < RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur))
|
---|
| 1619 | pCpuId = &pVM->cpum.s.aGuestCpuIdCentaur[iLeaf - UINT32_C(0xc0000000)];
|
---|
[1] | 1620 | else
|
---|
| 1621 | pCpuId = &pVM->cpum.s.GuestCpuIdDef;
|
---|
| 1622 |
|
---|
[25803] | 1623 | uint32_t cCurrentCacheIndex = *pEcx;
|
---|
[22037] | 1624 |
|
---|
[1] | 1625 | *pEax = pCpuId->eax;
|
---|
| 1626 | *pEbx = pCpuId->ebx;
|
---|
| 1627 | *pEcx = pCpuId->ecx;
|
---|
| 1628 | *pEdx = pCpuId->edx;
|
---|
[19076] | 1629 |
|
---|
[26648] | 1630 | if ( iLeaf == 1)
|
---|
[19076] | 1631 | {
|
---|
| 1632 | /* Bits 31-24: Initial APIC ID */
|
---|
| 1633 | Assert(pVCpu->idCpu <= 255);
|
---|
| 1634 | *pEbx |= (pVCpu->idCpu << 24);
|
---|
[22037] | 1635 | }
|
---|
| 1636 |
|
---|
[22070] | 1637 | if ( iLeaf == 4
|
---|
[25803] | 1638 | && cCurrentCacheIndex < 3
|
---|
[23794] | 1639 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_INTEL)
|
---|
[22037] | 1640 | {
|
---|
[25803] | 1641 | uint32_t type, level, sharing, linesize,
|
---|
| 1642 | partitions, associativity, sets, cores;
|
---|
| 1643 |
|
---|
| 1644 | /* For type: 1 - data cache, 2 - i-cache, 3 - unified */
|
---|
| 1645 | partitions = 1;
|
---|
[25815] | 1646 | /* Those are only to shut up compiler, as they will always
|
---|
[25803] | 1647 | get overwritten, and compiler should be able to figure that out */
|
---|
| 1648 | sets = associativity = sharing = level = 1;
|
---|
| 1649 | cores = pVM->cCpus > 32 ? 32 : pVM->cCpus;
|
---|
| 1650 | switch (cCurrentCacheIndex)
|
---|
| 1651 | {
|
---|
| 1652 | case 0:
|
---|
| 1653 | type = 1;
|
---|
| 1654 | level = 1;
|
---|
| 1655 | sharing = 1;
|
---|
| 1656 | linesize = 64;
|
---|
| 1657 | associativity = 8;
|
---|
| 1658 | sets = 64;
|
---|
| 1659 | break;
|
---|
| 1660 | case 1:
|
---|
| 1661 | level = 1;
|
---|
| 1662 | type = 2;
|
---|
| 1663 | sharing = 1;
|
---|
| 1664 | linesize = 64;
|
---|
| 1665 | associativity = 8;
|
---|
| 1666 | sets = 64;
|
---|
| 1667 | break;
|
---|
[26026] | 1668 | default: /* shut up gcc.*/
|
---|
| 1669 | AssertFailed();
|
---|
[25803] | 1670 | case 2:
|
---|
| 1671 | level = 2;
|
---|
| 1672 | type = 3;
|
---|
[26673] | 1673 | sharing = cores; /* our L2 cache is modelled as shared between all cores */
|
---|
[25803] | 1674 | linesize = 64;
|
---|
| 1675 | associativity = 24;
|
---|
| 1676 | sets = 4096;
|
---|
| 1677 | break;
|
---|
| 1678 | }
|
---|
| 1679 |
|
---|
| 1680 | *pEax |= ((cores - 1) << 26) |
|
---|
| 1681 | ((sharing - 1) << 14) |
|
---|
| 1682 | (level << 5) |
|
---|
| 1683 | 1;
|
---|
| 1684 | *pEbx = (linesize - 1) |
|
---|
| 1685 | ((partitions - 1) << 12) |
|
---|
| 1686 | ((associativity - 1) << 22); /* -1 encoding */
|
---|
| 1687 | *pEcx = sets - 1;
|
---|
[19076] | 1688 | }
|
---|
| 1689 |
|
---|
[1] | 1690 | Log2(("CPUMGetGuestCpuId: iLeaf=%#010x %RX32 %RX32 %RX32 %RX32\n", iLeaf, *pEax, *pEbx, *pEcx, *pEdx));
|
---|
| 1691 | }
|
---|
| 1692 |
|
---|
| 1693 | /**
|
---|
| 1694 | * Gets a number of standard CPUID leafs.
|
---|
| 1695 | *
|
---|
| 1696 | * @returns Number of leafs.
|
---|
[41783] | 1697 | * @param pVM Pointer to the VM.
|
---|
[1] | 1698 | * @remark Intended for PATM.
|
---|
| 1699 | */
|
---|
[12989] | 1700 | VMMDECL(uint32_t) CPUMGetGuestCpuIdStdMax(PVM pVM)
|
---|
[1] | 1701 | {
|
---|
[5285] | 1702 | return RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdStd);
|
---|
[1] | 1703 | }
|
---|
| 1704 |
|
---|
[12657] | 1705 |
|
---|
[1] | 1706 | /**
|
---|
| 1707 | * Gets a number of extended CPUID leafs.
|
---|
| 1708 | *
|
---|
| 1709 | * @returns Number of leafs.
|
---|
[41783] | 1710 | * @param pVM Pointer to the VM.
|
---|
[1] | 1711 | * @remark Intended for PATM.
|
---|
| 1712 | */
|
---|
[12989] | 1713 | VMMDECL(uint32_t) CPUMGetGuestCpuIdExtMax(PVM pVM)
|
---|
[1] | 1714 | {
|
---|
[5285] | 1715 | return RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdExt);
|
---|
[1] | 1716 | }
|
---|
| 1717 |
|
---|
[12657] | 1718 |
|
---|
[1] | 1719 | /**
|
---|
[5285] | 1720 | * Gets a number of centaur CPUID leafs.
|
---|
| 1721 | *
|
---|
| 1722 | * @returns Number of leafs.
|
---|
[41783] | 1723 | * @param pVM Pointer to the VM.
|
---|
[5285] | 1724 | * @remark Intended for PATM.
|
---|
| 1725 | */
|
---|
[12989] | 1726 | VMMDECL(uint32_t) CPUMGetGuestCpuIdCentaurMax(PVM pVM)
|
---|
[5285] | 1727 | {
|
---|
| 1728 | return RT_ELEMENTS(pVM->cpum.s.aGuestCpuIdCentaur);
|
---|
| 1729 | }
|
---|
| 1730 |
|
---|
[12657] | 1731 |
|
---|
[5285] | 1732 | /**
|
---|
[1] | 1733 | * Sets a CPUID feature bit.
|
---|
| 1734 | *
|
---|
[41783] | 1735 | * @param pVM Pointer to the VM.
|
---|
[1] | 1736 | * @param enmFeature The feature to set.
|
---|
| 1737 | */
|
---|
[12989] | 1738 | VMMDECL(void) CPUMSetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
|
---|
[1] | 1739 | {
|
---|
| 1740 | switch (enmFeature)
|
---|
| 1741 | {
|
---|
| 1742 | /*
|
---|
| 1743 | * Set the APIC bit in both feature masks.
|
---|
| 1744 | */
|
---|
| 1745 | case CPUMCPUIDFEATURE_APIC:
|
---|
[2633] | 1746 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
[1] | 1747 | pVM->cpum.s.aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_APIC;
|
---|
| 1748 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 1749 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[1] | 1750 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_AMD_FEATURE_EDX_APIC;
|
---|
[9354] | 1751 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled APIC\n"));
|
---|
[1] | 1752 | break;
|
---|
| 1753 |
|
---|
[12971] | 1754 | /*
|
---|
| 1755 | * Set the x2APIC bit in the standard feature mask.
|
---|
[12972] | 1756 | */
|
---|
[12971] | 1757 | case CPUMCPUIDFEATURE_X2APIC:
|
---|
| 1758 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1759 | pVM->cpum.s.aGuestCpuIdStd[1].ecx |= X86_CPUID_FEATURE_ECX_X2APIC;
|
---|
| 1760 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled x2APIC\n"));
|
---|
| 1761 | break;
|
---|
| 1762 |
|
---|
[771] | 1763 | /*
|
---|
[9354] | 1764 | * Set the sysenter/sysexit bit in the standard feature mask.
|
---|
[771] | 1765 | * Assumes the caller knows what it's doing! (host must support these)
|
---|
| 1766 | */
|
---|
| 1767 | case CPUMCPUIDFEATURE_SEP:
|
---|
| 1768 | {
|
---|
[7650] | 1769 | if (!(ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_SEP))
|
---|
[771] | 1770 | {
|
---|
| 1771 | AssertMsgFailed(("ERROR: Can't turn on SEP when the host doesn't support it!!\n"));
|
---|
| 1772 | return;
|
---|
| 1773 | }
|
---|
| 1774 |
|
---|
| 1775 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1776 | pVM->cpum.s.aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_SEP;
|
---|
[9354] | 1777 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled sysenter/exit\n"));
|
---|
[771] | 1778 | break;
|
---|
| 1779 | }
|
---|
| 1780 |
|
---|
[7644] | 1781 | /*
|
---|
[9354] | 1782 | * Set the syscall/sysret bit in the extended feature mask.
|
---|
| 1783 | * Assumes the caller knows what it's doing! (host must support these)
|
---|
| 1784 | */
|
---|
| 1785 | case CPUMCPUIDFEATURE_SYSCALL:
|
---|
| 1786 | {
|
---|
| 1787 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1788 | || !(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_SYSCALL))
|
---|
[9354] | 1789 | {
|
---|
[15390] | 1790 | #if HC_ARCH_BITS == 32
|
---|
[42024] | 1791 | /* X86_CPUID_EXT_FEATURE_EDX_SYSCALL not set it seems in 32 bits mode.
|
---|
[15390] | 1792 | * Even when the cpu is capable of doing so in 64 bits mode.
|
---|
| 1793 | */
|
---|
| 1794 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1795 | || !(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE)
|
---|
| 1796 | || !(ASMCpuId_EDX(1) & X86_CPUID_EXT_FEATURE_EDX_SYSCALL))
|
---|
[15390] | 1797 | #endif
|
---|
| 1798 | {
|
---|
| 1799 | LogRel(("WARNING: Can't turn on SYSCALL/SYSRET when the host doesn't support it!!\n"));
|
---|
| 1800 | return;
|
---|
| 1801 | }
|
---|
[9354] | 1802 | }
|
---|
| 1803 | /* Valid for both Intel and AMD CPUs, although only in 64 bits mode for Intel. */
|
---|
[42024] | 1804 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_EXT_FEATURE_EDX_SYSCALL;
|
---|
[9825] | 1805 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled syscall/ret\n"));
|
---|
[9354] | 1806 | break;
|
---|
| 1807 | }
|
---|
| 1808 |
|
---|
| 1809 | /*
|
---|
[7644] | 1810 | * Set the PAE bit in both feature masks.
|
---|
| 1811 | * Assumes the caller knows what it's doing! (host must support these)
|
---|
| 1812 | */
|
---|
| 1813 | case CPUMCPUIDFEATURE_PAE:
|
---|
| 1814 | {
|
---|
[7647] | 1815 | if (!(ASMCpuId_EDX(1) & X86_CPUID_FEATURE_EDX_PAE))
|
---|
[7644] | 1816 | {
|
---|
[8106] | 1817 | LogRel(("WARNING: Can't turn on PAE when the host doesn't support it!!\n"));
|
---|
[7644] | 1818 | return;
|
---|
| 1819 | }
|
---|
| 1820 |
|
---|
| 1821 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1822 | pVM->cpum.s.aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_PAE;
|
---|
| 1823 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 1824 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[7644] | 1825 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_AMD_FEATURE_EDX_PAE;
|
---|
[9354] | 1826 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled PAE\n"));
|
---|
[7644] | 1827 | break;
|
---|
| 1828 | }
|
---|
| 1829 |
|
---|
[7645] | 1830 | /*
|
---|
| 1831 | * Set the LONG MODE bit in the extended feature mask.
|
---|
| 1832 | * Assumes the caller knows what it's doing! (host must support these)
|
---|
| 1833 | */
|
---|
| 1834 | case CPUMCPUIDFEATURE_LONG_MODE:
|
---|
| 1835 | {
|
---|
[7646] | 1836 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1837 | || !(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE))
|
---|
[7645] | 1838 | {
|
---|
[9354] | 1839 | LogRel(("WARNING: Can't turn on LONG MODE when the host doesn't support it!!\n"));
|
---|
[7645] | 1840 | return;
|
---|
| 1841 | }
|
---|
| 1842 |
|
---|
[9354] | 1843 | /* Valid for both Intel and AMD. */
|
---|
[42024] | 1844 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_EXT_FEATURE_EDX_LONG_MODE;
|
---|
[9354] | 1845 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled LONG MODE\n"));
|
---|
[7645] | 1846 | break;
|
---|
| 1847 | }
|
---|
| 1848 |
|
---|
[9354] | 1849 | /*
|
---|
[42024] | 1850 | * Set the NX/XD bit in the extended feature mask.
|
---|
[9354] | 1851 | * Assumes the caller knows what it's doing! (host must support these)
|
---|
| 1852 | */
|
---|
[42024] | 1853 | case CPUMCPUIDFEATURE_NX:
|
---|
[9354] | 1854 | {
|
---|
| 1855 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1856 | || !(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_NX))
|
---|
[9354] | 1857 | {
|
---|
[42024] | 1858 | LogRel(("WARNING: Can't turn on NX/XD when the host doesn't support it!!\n"));
|
---|
[9354] | 1859 | return;
|
---|
| 1860 | }
|
---|
| 1861 |
|
---|
| 1862 | /* Valid for both Intel and AMD. */
|
---|
[42024] | 1863 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_EXT_FEATURE_EDX_NX;
|
---|
| 1864 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled NX\n"));
|
---|
[9354] | 1865 | break;
|
---|
| 1866 | }
|
---|
| 1867 |
|
---|
[42024] | 1868 | /*
|
---|
| 1869 | * Set the LAHF/SAHF support in 64-bit mode.
|
---|
| 1870 | * Assumes the caller knows what it's doing! (host must support this)
|
---|
| 1871 | */
|
---|
[9354] | 1872 | case CPUMCPUIDFEATURE_LAHF:
|
---|
| 1873 | {
|
---|
| 1874 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1875 | || !(ASMCpuId_ECX(0x80000001) & X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF))
|
---|
[9354] | 1876 | {
|
---|
| 1877 | LogRel(("WARNING: Can't turn on LAHF/SAHF when the host doesn't support it!!\n"));
|
---|
| 1878 | return;
|
---|
| 1879 | }
|
---|
| 1880 |
|
---|
[42024] | 1881 | /* Valid for both Intel and AMD. */
|
---|
| 1882 | pVM->cpum.s.aGuestCpuIdExt[1].ecx |= X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF;
|
---|
[9354] | 1883 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled LAHF/SAHF\n"));
|
---|
| 1884 | break;
|
---|
| 1885 | }
|
---|
| 1886 |
|
---|
[11704] | 1887 | case CPUMCPUIDFEATURE_PAT:
|
---|
| 1888 | {
|
---|
| 1889 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1890 | pVM->cpum.s.aGuestCpuIdStd[1].edx |= X86_CPUID_FEATURE_EDX_PAT;
|
---|
| 1891 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 1892 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[11704] | 1893 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_AMD_FEATURE_EDX_PAT;
|
---|
[43151] | 1894 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled PAT\n"));
|
---|
[11704] | 1895 | break;
|
---|
| 1896 | }
|
---|
| 1897 |
|
---|
[42024] | 1898 | /*
|
---|
| 1899 | * Set the RDTSCP support bit.
|
---|
| 1900 | * Assumes the caller knows what it's doing! (host must support this)
|
---|
| 1901 | */
|
---|
[14411] | 1902 | case CPUMCPUIDFEATURE_RDTSCP:
|
---|
| 1903 | {
|
---|
| 1904 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax < 0x80000001
|
---|
[42024] | 1905 | || !(ASMCpuId_EDX(0x80000001) & X86_CPUID_EXT_FEATURE_EDX_RDTSCP)
|
---|
[30164] | 1906 | || pVM->cpum.s.u8PortableCpuIdLevel > 0)
|
---|
[14411] | 1907 | {
|
---|
[30164] | 1908 | if (!pVM->cpum.s.u8PortableCpuIdLevel)
|
---|
| 1909 | LogRel(("WARNING: Can't turn on RDTSCP when the host doesn't support it!!\n"));
|
---|
[14411] | 1910 | return;
|
---|
| 1911 | }
|
---|
| 1912 |
|
---|
[42024] | 1913 | /* Valid for both Intel and AMD. */
|
---|
| 1914 | pVM->cpum.s.aGuestCpuIdExt[1].edx |= X86_CPUID_EXT_FEATURE_EDX_RDTSCP;
|
---|
[14411] | 1915 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled RDTSCP.\n"));
|
---|
| 1916 | break;
|
---|
| 1917 | }
|
---|
| 1918 |
|
---|
[37136] | 1919 | /*
|
---|
| 1920 | * Set the Hypervisor Present bit in the standard feature mask.
|
---|
| 1921 | */
|
---|
| 1922 | case CPUMCPUIDFEATURE_HVP:
|
---|
| 1923 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1924 | pVM->cpum.s.aGuestCpuIdStd[1].ecx |= X86_CPUID_FEATURE_ECX_HVP;
|
---|
| 1925 | LogRel(("CPUMSetGuestCpuIdFeature: Enabled Hypervisor Present bit\n"));
|
---|
| 1926 | break;
|
---|
| 1927 |
|
---|
[1] | 1928 | default:
|
---|
| 1929 | AssertMsgFailed(("enmFeature=%d\n", enmFeature));
|
---|
| 1930 | break;
|
---|
| 1931 | }
|
---|
[22890] | 1932 | for (VMCPUID i = 0; i < pVM->cCpus; i++)
|
---|
[18927] | 1933 | {
|
---|
| 1934 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
| 1935 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CPUID;
|
---|
| 1936 | }
|
---|
[1] | 1937 | }
|
---|
| 1938 |
|
---|
[12657] | 1939 |
|
---|
[1] | 1940 | /**
|
---|
[8111] | 1941 | * Queries a CPUID feature bit.
|
---|
| 1942 | *
|
---|
| 1943 | * @returns boolean for feature presence
|
---|
[41783] | 1944 | * @param pVM Pointer to the VM.
|
---|
[8111] | 1945 | * @param enmFeature The feature to query.
|
---|
| 1946 | */
|
---|
[12989] | 1947 | VMMDECL(bool) CPUMGetGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
|
---|
[8111] | 1948 | {
|
---|
| 1949 | switch (enmFeature)
|
---|
| 1950 | {
|
---|
| 1951 | case CPUMCPUIDFEATURE_PAE:
|
---|
| 1952 | {
|
---|
| 1953 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 1954 | return !!(pVM->cpum.s.aGuestCpuIdStd[1].edx & X86_CPUID_FEATURE_EDX_PAE);
|
---|
| 1955 | break;
|
---|
| 1956 | }
|
---|
| 1957 |
|
---|
[42024] | 1958 | case CPUMCPUIDFEATURE_NX:
|
---|
[30145] | 1959 | {
|
---|
| 1960 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
[42024] | 1961 | return !!(pVM->cpum.s.aGuestCpuIdExt[1].edx & X86_CPUID_EXT_FEATURE_EDX_NX);
|
---|
[30145] | 1962 | }
|
---|
| 1963 |
|
---|
[14411] | 1964 | case CPUMCPUIDFEATURE_RDTSCP:
|
---|
| 1965 | {
|
---|
| 1966 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
[42024] | 1967 | return !!(pVM->cpum.s.aGuestCpuIdExt[1].edx & X86_CPUID_EXT_FEATURE_EDX_RDTSCP);
|
---|
[14411] | 1968 | break;
|
---|
| 1969 | }
|
---|
| 1970 |
|
---|
[14704] | 1971 | case CPUMCPUIDFEATURE_LONG_MODE:
|
---|
| 1972 | {
|
---|
| 1973 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
[42024] | 1974 | return !!(pVM->cpum.s.aGuestCpuIdExt[1].edx & X86_CPUID_EXT_FEATURE_EDX_LONG_MODE);
|
---|
[14704] | 1975 | break;
|
---|
| 1976 | }
|
---|
[15416] | 1977 |
|
---|
[8111] | 1978 | default:
|
---|
| 1979 | AssertMsgFailed(("enmFeature=%d\n", enmFeature));
|
---|
| 1980 | break;
|
---|
| 1981 | }
|
---|
| 1982 | return false;
|
---|
| 1983 | }
|
---|
| 1984 |
|
---|
[12657] | 1985 |
|
---|
[8111] | 1986 | /**
|
---|
[1] | 1987 | * Clears a CPUID feature bit.
|
---|
| 1988 | *
|
---|
[41783] | 1989 | * @param pVM Pointer to the VM.
|
---|
[1] | 1990 | * @param enmFeature The feature to clear.
|
---|
| 1991 | */
|
---|
[12989] | 1992 | VMMDECL(void) CPUMClearGuestCpuIdFeature(PVM pVM, CPUMCPUIDFEATURE enmFeature)
|
---|
[1] | 1993 | {
|
---|
| 1994 | switch (enmFeature)
|
---|
| 1995 | {
|
---|
| 1996 | /*
|
---|
| 1997 | * Set the APIC bit in both feature masks.
|
---|
| 1998 | */
|
---|
| 1999 | case CPUMCPUIDFEATURE_APIC:
|
---|
| 2000 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 2001 | pVM->cpum.s.aGuestCpuIdStd[1].edx &= ~X86_CPUID_FEATURE_EDX_APIC;
|
---|
[9354] | 2002 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 2003 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[1] | 2004 | pVM->cpum.s.aGuestCpuIdExt[1].edx &= ~X86_CPUID_AMD_FEATURE_EDX_APIC;
|
---|
[43151] | 2005 | Log(("CPUMClearGuestCpuIdFeature: Disabled APIC\n"));
|
---|
[1] | 2006 | break;
|
---|
| 2007 |
|
---|
[12972] | 2008 | /*
|
---|
| 2009 | * Clear the x2APIC bit in the standard feature mask.
|
---|
| 2010 | */
|
---|
| 2011 | case CPUMCPUIDFEATURE_X2APIC:
|
---|
| 2012 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 2013 | pVM->cpum.s.aGuestCpuIdStd[1].ecx &= ~X86_CPUID_FEATURE_ECX_X2APIC;
|
---|
[43151] | 2014 | LogRel(("CPUMClearGuestCpuIdFeature: Disabled x2APIC\n"));
|
---|
[12972] | 2015 | break;
|
---|
| 2016 |
|
---|
[8110] | 2017 | case CPUMCPUIDFEATURE_PAE:
|
---|
| 2018 | {
|
---|
| 2019 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 2020 | pVM->cpum.s.aGuestCpuIdStd[1].edx &= ~X86_CPUID_FEATURE_EDX_PAE;
|
---|
| 2021 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 2022 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[8110] | 2023 | pVM->cpum.s.aGuestCpuIdExt[1].edx &= ~X86_CPUID_AMD_FEATURE_EDX_PAE;
|
---|
| 2024 | LogRel(("CPUMClearGuestCpuIdFeature: Disabled PAE!\n"));
|
---|
| 2025 | break;
|
---|
| 2026 | }
|
---|
| 2027 |
|
---|
[11704] | 2028 | case CPUMCPUIDFEATURE_PAT:
|
---|
| 2029 | {
|
---|
| 2030 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 2031 | pVM->cpum.s.aGuestCpuIdStd[1].edx &= ~X86_CPUID_FEATURE_EDX_PAT;
|
---|
| 2032 | if ( pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001
|
---|
[23794] | 2033 | && pVM->cpum.s.enmGuestCpuVendor == CPUMCPUVENDOR_AMD)
|
---|
[11704] | 2034 | pVM->cpum.s.aGuestCpuIdExt[1].edx &= ~X86_CPUID_AMD_FEATURE_EDX_PAT;
|
---|
| 2035 | LogRel(("CPUMClearGuestCpuIdFeature: Disabled PAT!\n"));
|
---|
| 2036 | break;
|
---|
| 2037 | }
|
---|
| 2038 |
|
---|
[14704] | 2039 | case CPUMCPUIDFEATURE_LONG_MODE:
|
---|
| 2040 | {
|
---|
| 2041 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
[42024] | 2042 | pVM->cpum.s.aGuestCpuIdExt[1].edx &= ~X86_CPUID_EXT_FEATURE_EDX_LONG_MODE;
|
---|
[14704] | 2043 | break;
|
---|
| 2044 | }
|
---|
| 2045 |
|
---|
| 2046 | case CPUMCPUIDFEATURE_LAHF:
|
---|
| 2047 | {
|
---|
| 2048 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
[42024] | 2049 | pVM->cpum.s.aGuestCpuIdExt[1].ecx &= ~X86_CPUID_EXT_FEATURE_ECX_LAHF_SAHF;
|
---|
[14704] | 2050 | break;
|
---|
| 2051 | }
|
---|
| 2052 |
|
---|
[42033] | 2053 | case CPUMCPUIDFEATURE_RDTSCP:
|
---|
| 2054 | {
|
---|
| 2055 | if (pVM->cpum.s.aGuestCpuIdExt[0].eax >= 0x80000001)
|
---|
| 2056 | pVM->cpum.s.aGuestCpuIdExt[1].edx &= ~X86_CPUID_EXT_FEATURE_EDX_RDTSCP;
|
---|
| 2057 | LogRel(("CPUMClearGuestCpuIdFeature: Disabled RDTSCP!\n"));
|
---|
| 2058 | break;
|
---|
| 2059 | }
|
---|
| 2060 |
|
---|
[37136] | 2061 | case CPUMCPUIDFEATURE_HVP:
|
---|
[40234] | 2062 | if (pVM->cpum.s.aGuestCpuIdStd[0].eax >= 1)
|
---|
| 2063 | pVM->cpum.s.aGuestCpuIdStd[1].ecx &= ~X86_CPUID_FEATURE_ECX_HVP;
|
---|
[37136] | 2064 | break;
|
---|
| 2065 |
|
---|
[1] | 2066 | default:
|
---|
| 2067 | AssertMsgFailed(("enmFeature=%d\n", enmFeature));
|
---|
| 2068 | break;
|
---|
| 2069 | }
|
---|
[22890] | 2070 | for (VMCPUID i = 0; i < pVM->cCpus; i++)
|
---|
[18927] | 2071 | {
|
---|
| 2072 | PVMCPU pVCpu = &pVM->aCpus[i];
|
---|
| 2073 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_CPUID;
|
---|
| 2074 | }
|
---|
[1] | 2075 | }
|
---|
| 2076 |
|
---|
[12657] | 2077 |
|
---|
[9354] | 2078 | /**
|
---|
[42034] | 2079 | * Gets the host CPU vendor.
|
---|
[23794] | 2080 | *
|
---|
[42034] | 2081 | * @returns CPU vendor.
|
---|
[41783] | 2082 | * @param pVM Pointer to the VM.
|
---|
[23794] | 2083 | */
|
---|
| 2084 | VMMDECL(CPUMCPUVENDOR) CPUMGetHostCpuVendor(PVM pVM)
|
---|
| 2085 | {
|
---|
| 2086 | return pVM->cpum.s.enmHostCpuVendor;
|
---|
| 2087 | }
|
---|
| 2088 |
|
---|
[42034] | 2089 |
|
---|
[23794] | 2090 | /**
|
---|
[42034] | 2091 | * Gets the CPU vendor.
|
---|
[9354] | 2092 | *
|
---|
[42034] | 2093 | * @returns CPU vendor.
|
---|
[41783] | 2094 | * @param pVM Pointer to the VM.
|
---|
[9354] | 2095 | */
|
---|
[23794] | 2096 | VMMDECL(CPUMCPUVENDOR) CPUMGetGuestCpuVendor(PVM pVM)
|
---|
[9354] | 2097 | {
|
---|
[23794] | 2098 | return pVM->cpum.s.enmGuestCpuVendor;
|
---|
[9354] | 2099 | }
|
---|
[1] | 2100 |
|
---|
| 2101 |
|
---|
[18927] | 2102 | VMMDECL(int) CPUMSetGuestDR0(PVMCPU pVCpu, uint64_t uDr0)
|
---|
[1] | 2103 | {
|
---|
[18927] | 2104 | pVCpu->cpum.s.Guest.dr[0] = uDr0;
|
---|
| 2105 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2106 | }
|
---|
| 2107 |
|
---|
[12657] | 2108 |
|
---|
[18927] | 2109 | VMMDECL(int) CPUMSetGuestDR1(PVMCPU pVCpu, uint64_t uDr1)
|
---|
[1] | 2110 | {
|
---|
[18927] | 2111 | pVCpu->cpum.s.Guest.dr[1] = uDr1;
|
---|
| 2112 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2113 | }
|
---|
| 2114 |
|
---|
[12657] | 2115 |
|
---|
[18927] | 2116 | VMMDECL(int) CPUMSetGuestDR2(PVMCPU pVCpu, uint64_t uDr2)
|
---|
[1] | 2117 | {
|
---|
[18927] | 2118 | pVCpu->cpum.s.Guest.dr[2] = uDr2;
|
---|
| 2119 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2120 | }
|
---|
| 2121 |
|
---|
[12657] | 2122 |
|
---|
[18927] | 2123 | VMMDECL(int) CPUMSetGuestDR3(PVMCPU pVCpu, uint64_t uDr3)
|
---|
[1] | 2124 | {
|
---|
[18927] | 2125 | pVCpu->cpum.s.Guest.dr[3] = uDr3;
|
---|
| 2126 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2127 | }
|
---|
| 2128 |
|
---|
[12657] | 2129 |
|
---|
[18927] | 2130 | VMMDECL(int) CPUMSetGuestDR6(PVMCPU pVCpu, uint64_t uDr6)
|
---|
[1] | 2131 | {
|
---|
[18927] | 2132 | pVCpu->cpum.s.Guest.dr[6] = uDr6;
|
---|
| 2133 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2134 | }
|
---|
| 2135 |
|
---|
[12657] | 2136 |
|
---|
[18927] | 2137 | VMMDECL(int) CPUMSetGuestDR7(PVMCPU pVCpu, uint64_t uDr7)
|
---|
[1] | 2138 | {
|
---|
[18927] | 2139 | pVCpu->cpum.s.Guest.dr[7] = uDr7;
|
---|
| 2140 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2141 | }
|
---|
| 2142 |
|
---|
[12657] | 2143 |
|
---|
[18927] | 2144 | VMMDECL(int) CPUMSetGuestDRx(PVMCPU pVCpu, uint32_t iReg, uint64_t Value)
|
---|
[1] | 2145 | {
|
---|
[41728] | 2146 | AssertReturn(iReg <= DISDREG_DR7, VERR_INVALID_PARAMETER);
|
---|
[12657] | 2147 | /* DR4 is an alias for DR6, and DR5 is an alias for DR7. */
|
---|
| 2148 | if (iReg == 4 || iReg == 5)
|
---|
| 2149 | iReg += 2;
|
---|
[18927] | 2150 | pVCpu->cpum.s.Guest.dr[iReg] = Value;
|
---|
| 2151 | return CPUMRecalcHyperDRx(pVCpu);
|
---|
[1] | 2152 | }
|
---|
| 2153 |
|
---|
| 2154 |
|
---|
| 2155 | /**
|
---|
[33540] | 2156 | * Recalculates the hypervisor DRx register values based on
|
---|
[1] | 2157 | * current guest registers and DBGF breakpoints.
|
---|
| 2158 | *
|
---|
| 2159 | * This is called whenever a guest DRx register is modified and when DBGF
|
---|
| 2160 | * sets a hardware breakpoint. In guest context this function will reload
|
---|
| 2161 | * any (hyper) DRx registers which comes out with a different value.
|
---|
| 2162 | *
|
---|
| 2163 | * @returns VINF_SUCCESS.
|
---|
[41802] | 2164 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 2165 | */
|
---|
[18927] | 2166 | VMMDECL(int) CPUMRecalcHyperDRx(PVMCPU pVCpu)
|
---|
[1] | 2167 | {
|
---|
[18927] | 2168 | PVM pVM = pVCpu->CTX_SUFF(pVM);
|
---|
| 2169 |
|
---|
[1] | 2170 | /*
|
---|
| 2171 | * Compare the DR7s first.
|
---|
| 2172 | *
|
---|
| 2173 | * We only care about the enabled flags. The GE and LE flags are always
|
---|
| 2174 | * set and we don't care if the guest doesn't set them. GD is virtualized
|
---|
| 2175 | * when we dispatch #DB, we never enable it.
|
---|
| 2176 | */
|
---|
| 2177 | const RTGCUINTREG uDbgfDr7 = DBGFBpGetDR7(pVM);
|
---|
| 2178 | #ifdef CPUM_VIRTUALIZE_DRX
|
---|
[18927] | 2179 | const RTGCUINTREG uGstDr7 = CPUMGetGuestDR7(pVCpu);
|
---|
[1] | 2180 | #else
|
---|
| 2181 | const RTGCUINTREG uGstDr7 = 0;
|
---|
| 2182 | #endif
|
---|
| 2183 | if ((uGstDr7 | uDbgfDr7) & X86_DR7_ENABLED_MASK)
|
---|
| 2184 | {
|
---|
| 2185 | /*
|
---|
| 2186 | * Ok, something is enabled. Recalc each of the breakpoints.
|
---|
| 2187 | * Straight forward code, not optimized/minimized in any way.
|
---|
| 2188 | */
|
---|
| 2189 | RTGCUINTREG uNewDr7 = X86_DR7_GE | X86_DR7_LE | X86_DR7_MB1_MASK;
|
---|
| 2190 |
|
---|
| 2191 | /* bp 0 */
|
---|
| 2192 | RTGCUINTREG uNewDr0;
|
---|
| 2193 | if (uDbgfDr7 & (X86_DR7_L0 | X86_DR7_G0))
|
---|
| 2194 | {
|
---|
| 2195 | uNewDr7 |= uDbgfDr7 & (X86_DR7_L0 | X86_DR7_G0 | X86_DR7_RW0_MASK | X86_DR7_LEN0_MASK);
|
---|
| 2196 | uNewDr0 = DBGFBpGetDR0(pVM);
|
---|
| 2197 | }
|
---|
| 2198 | else if (uGstDr7 & (X86_DR7_L0 | X86_DR7_G0))
|
---|
| 2199 | {
|
---|
| 2200 | uNewDr7 |= uGstDr7 & (X86_DR7_L0 | X86_DR7_G0 | X86_DR7_RW0_MASK | X86_DR7_LEN0_MASK);
|
---|
[18927] | 2201 | uNewDr0 = CPUMGetGuestDR0(pVCpu);
|
---|
[1] | 2202 | }
|
---|
| 2203 | else
|
---|
[18927] | 2204 | uNewDr0 = pVCpu->cpum.s.Hyper.dr[0];
|
---|
[1] | 2205 |
|
---|
| 2206 | /* bp 1 */
|
---|
| 2207 | RTGCUINTREG uNewDr1;
|
---|
| 2208 | if (uDbgfDr7 & (X86_DR7_L1 | X86_DR7_G1))
|
---|
| 2209 | {
|
---|
| 2210 | uNewDr7 |= uDbgfDr7 & (X86_DR7_L1 | X86_DR7_G1 | X86_DR7_RW1_MASK | X86_DR7_LEN1_MASK);
|
---|
| 2211 | uNewDr1 = DBGFBpGetDR1(pVM);
|
---|
| 2212 | }
|
---|
| 2213 | else if (uGstDr7 & (X86_DR7_L1 | X86_DR7_G1))
|
---|
| 2214 | {
|
---|
| 2215 | uNewDr7 |= uGstDr7 & (X86_DR7_L1 | X86_DR7_G1 | X86_DR7_RW1_MASK | X86_DR7_LEN1_MASK);
|
---|
[18927] | 2216 | uNewDr1 = CPUMGetGuestDR1(pVCpu);
|
---|
[1] | 2217 | }
|
---|
| 2218 | else
|
---|
[18927] | 2219 | uNewDr1 = pVCpu->cpum.s.Hyper.dr[1];
|
---|
[1] | 2220 |
|
---|
| 2221 | /* bp 2 */
|
---|
| 2222 | RTGCUINTREG uNewDr2;
|
---|
| 2223 | if (uDbgfDr7 & (X86_DR7_L2 | X86_DR7_G2))
|
---|
| 2224 | {
|
---|
| 2225 | uNewDr7 |= uDbgfDr7 & (X86_DR7_L2 | X86_DR7_G2 | X86_DR7_RW2_MASK | X86_DR7_LEN2_MASK);
|
---|
| 2226 | uNewDr2 = DBGFBpGetDR2(pVM);
|
---|
| 2227 | }
|
---|
| 2228 | else if (uGstDr7 & (X86_DR7_L2 | X86_DR7_G2))
|
---|
| 2229 | {
|
---|
| 2230 | uNewDr7 |= uGstDr7 & (X86_DR7_L2 | X86_DR7_G2 | X86_DR7_RW2_MASK | X86_DR7_LEN2_MASK);
|
---|
[18927] | 2231 | uNewDr2 = CPUMGetGuestDR2(pVCpu);
|
---|
[1] | 2232 | }
|
---|
| 2233 | else
|
---|
[18927] | 2234 | uNewDr2 = pVCpu->cpum.s.Hyper.dr[2];
|
---|
[1] | 2235 |
|
---|
| 2236 | /* bp 3 */
|
---|
| 2237 | RTGCUINTREG uNewDr3;
|
---|
| 2238 | if (uDbgfDr7 & (X86_DR7_L3 | X86_DR7_G3))
|
---|
| 2239 | {
|
---|
| 2240 | uNewDr7 |= uDbgfDr7 & (X86_DR7_L3 | X86_DR7_G3 | X86_DR7_RW3_MASK | X86_DR7_LEN3_MASK);
|
---|
| 2241 | uNewDr3 = DBGFBpGetDR3(pVM);
|
---|
| 2242 | }
|
---|
| 2243 | else if (uGstDr7 & (X86_DR7_L3 | X86_DR7_G3))
|
---|
| 2244 | {
|
---|
| 2245 | uNewDr7 |= uGstDr7 & (X86_DR7_L3 | X86_DR7_G3 | X86_DR7_RW3_MASK | X86_DR7_LEN3_MASK);
|
---|
[18927] | 2246 | uNewDr3 = CPUMGetGuestDR3(pVCpu);
|
---|
[1] | 2247 | }
|
---|
| 2248 | else
|
---|
[18927] | 2249 | uNewDr3 = pVCpu->cpum.s.Hyper.dr[3];
|
---|
[1] | 2250 |
|
---|
| 2251 | /*
|
---|
| 2252 | * Apply the updates.
|
---|
| 2253 | */
|
---|
[13832] | 2254 | #ifdef IN_RC
|
---|
[18927] | 2255 | if (!(pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS))
|
---|
[1] | 2256 | {
|
---|
| 2257 | /** @todo save host DBx registers. */
|
---|
| 2258 | }
|
---|
| 2259 | #endif
|
---|
[18927] | 2260 | pVCpu->cpum.s.fUseFlags |= CPUM_USE_DEBUG_REGS;
|
---|
| 2261 | if (uNewDr3 != pVCpu->cpum.s.Hyper.dr[3])
|
---|
| 2262 | CPUMSetHyperDR3(pVCpu, uNewDr3);
|
---|
| 2263 | if (uNewDr2 != pVCpu->cpum.s.Hyper.dr[2])
|
---|
| 2264 | CPUMSetHyperDR2(pVCpu, uNewDr2);
|
---|
| 2265 | if (uNewDr1 != pVCpu->cpum.s.Hyper.dr[1])
|
---|
| 2266 | CPUMSetHyperDR1(pVCpu, uNewDr1);
|
---|
| 2267 | if (uNewDr0 != pVCpu->cpum.s.Hyper.dr[0])
|
---|
| 2268 | CPUMSetHyperDR0(pVCpu, uNewDr0);
|
---|
| 2269 | if (uNewDr7 != pVCpu->cpum.s.Hyper.dr[7])
|
---|
| 2270 | CPUMSetHyperDR7(pVCpu, uNewDr7);
|
---|
[1] | 2271 | }
|
---|
| 2272 | else
|
---|
| 2273 | {
|
---|
[13832] | 2274 | #ifdef IN_RC
|
---|
[18927] | 2275 | if (pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS)
|
---|
[1] | 2276 | {
|
---|
| 2277 | /** @todo restore host DBx registers. */
|
---|
| 2278 | }
|
---|
| 2279 | #endif
|
---|
[18927] | 2280 | pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS;
|
---|
[1] | 2281 | }
|
---|
| 2282 | Log2(("CPUMRecalcHyperDRx: fUseFlags=%#x %RGr %RGr %RGr %RGr %RGr %RGr\n",
|
---|
[18927] | 2283 | pVCpu->cpum.s.fUseFlags, pVCpu->cpum.s.Hyper.dr[0], pVCpu->cpum.s.Hyper.dr[1],
|
---|
| 2284 | pVCpu->cpum.s.Hyper.dr[2], pVCpu->cpum.s.Hyper.dr[3], pVCpu->cpum.s.Hyper.dr[6],
|
---|
| 2285 | pVCpu->cpum.s.Hyper.dr[7]));
|
---|
[1] | 2286 |
|
---|
| 2287 | return VINF_SUCCESS;
|
---|
| 2288 | }
|
---|
| 2289 |
|
---|
[25835] | 2290 |
|
---|
| 2291 | /**
|
---|
| 2292 | * Tests if the guest has No-Execute Page Protection Enabled (NXE).
|
---|
| 2293 | *
|
---|
| 2294 | * @returns true if in real mode, otherwise false.
|
---|
[41803] | 2295 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2296 | */
|
---|
| 2297 | VMMDECL(bool) CPUMIsGuestNXEnabled(PVMCPU pVCpu)
|
---|
| 2298 | {
|
---|
| 2299 | return !!(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_NXE);
|
---|
| 2300 | }
|
---|
| 2301 |
|
---|
| 2302 |
|
---|
| 2303 | /**
|
---|
[25866] | 2304 | * Tests if the guest has the Page Size Extension enabled (PSE).
|
---|
| 2305 | *
|
---|
| 2306 | * @returns true if in real mode, otherwise false.
|
---|
[41803] | 2307 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25866] | 2308 | */
|
---|
| 2309 | VMMDECL(bool) CPUMIsGuestPageSizeExtEnabled(PVMCPU pVCpu)
|
---|
| 2310 | {
|
---|
[26635] | 2311 | /* PAE or AMD64 implies support for big pages regardless of CR4.PSE */
|
---|
[26673] | 2312 | return !!(pVCpu->cpum.s.Guest.cr4 & (X86_CR4_PSE | X86_CR4_PAE));
|
---|
[25866] | 2313 | }
|
---|
| 2314 |
|
---|
| 2315 |
|
---|
| 2316 | /**
|
---|
| 2317 | * Tests if the guest has the paging enabled (PG).
|
---|
| 2318 | *
|
---|
| 2319 | * @returns true if in real mode, otherwise false.
|
---|
[41803] | 2320 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25866] | 2321 | */
|
---|
| 2322 | VMMDECL(bool) CPUMIsGuestPagingEnabled(PVMCPU pVCpu)
|
---|
| 2323 | {
|
---|
| 2324 | return !!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PG);
|
---|
| 2325 | }
|
---|
| 2326 |
|
---|
| 2327 |
|
---|
| 2328 | /**
|
---|
| 2329 | * Tests if the guest has the paging enabled (PG).
|
---|
| 2330 | *
|
---|
| 2331 | * @returns true if in real mode, otherwise false.
|
---|
[41803] | 2332 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25866] | 2333 | */
|
---|
| 2334 | VMMDECL(bool) CPUMIsGuestR0WriteProtEnabled(PVMCPU pVCpu)
|
---|
| 2335 | {
|
---|
| 2336 | return !!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_WP);
|
---|
| 2337 | }
|
---|
| 2338 |
|
---|
| 2339 |
|
---|
| 2340 | /**
|
---|
[25835] | 2341 | * Tests if the guest is running in real mode or not.
|
---|
| 2342 | *
|
---|
| 2343 | * @returns true if in real mode, otherwise false.
|
---|
[41803] | 2344 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2345 | */
|
---|
| 2346 | VMMDECL(bool) CPUMIsGuestInRealMode(PVMCPU pVCpu)
|
---|
| 2347 | {
|
---|
| 2348 | return !(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE);
|
---|
| 2349 | }
|
---|
| 2350 |
|
---|
| 2351 |
|
---|
| 2352 | /**
|
---|
[36639] | 2353 | * Tests if the guest is running in real or virtual 8086 mode.
|
---|
| 2354 | *
|
---|
| 2355 | * @returns @c true if it is, @c false if not.
|
---|
[41803] | 2356 | * @param pVCpu Pointer to the VMCPU.
|
---|
[36639] | 2357 | */
|
---|
| 2358 | VMMDECL(bool) CPUMIsGuestInRealOrV86Mode(PVMCPU pVCpu)
|
---|
| 2359 | {
|
---|
| 2360 | return !(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE)
|
---|
| 2361 | || pVCpu->cpum.s.Guest.eflags.Bits.u1VM; /** @todo verify that this cannot be set in long mode. */
|
---|
| 2362 | }
|
---|
| 2363 |
|
---|
| 2364 |
|
---|
| 2365 | /**
|
---|
[25835] | 2366 | * Tests if the guest is running in protected or not.
|
---|
| 2367 | *
|
---|
| 2368 | * @returns true if in protected mode, otherwise false.
|
---|
[41803] | 2369 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2370 | */
|
---|
| 2371 | VMMDECL(bool) CPUMIsGuestInProtectedMode(PVMCPU pVCpu)
|
---|
| 2372 | {
|
---|
| 2373 | return !!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE);
|
---|
| 2374 | }
|
---|
| 2375 |
|
---|
| 2376 |
|
---|
| 2377 | /**
|
---|
| 2378 | * Tests if the guest is running in paged protected or not.
|
---|
| 2379 | *
|
---|
| 2380 | * @returns true if in paged protected mode, otherwise false.
|
---|
[41803] | 2381 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2382 | */
|
---|
| 2383 | VMMDECL(bool) CPUMIsGuestInPagedProtectedMode(PVMCPU pVCpu)
|
---|
| 2384 | {
|
---|
| 2385 | return (pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PE | X86_CR0_PG)) == (X86_CR0_PE | X86_CR0_PG);
|
---|
| 2386 | }
|
---|
| 2387 |
|
---|
| 2388 |
|
---|
| 2389 | /**
|
---|
| 2390 | * Tests if the guest is running in long mode or not.
|
---|
| 2391 | *
|
---|
| 2392 | * @returns true if in long mode, otherwise false.
|
---|
[41803] | 2393 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2394 | */
|
---|
| 2395 | VMMDECL(bool) CPUMIsGuestInLongMode(PVMCPU pVCpu)
|
---|
| 2396 | {
|
---|
| 2397 | return (pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA) == MSR_K6_EFER_LMA;
|
---|
| 2398 | }
|
---|
| 2399 |
|
---|
| 2400 |
|
---|
| 2401 | /**
|
---|
| 2402 | * Tests if the guest is running in PAE mode or not.
|
---|
| 2403 | *
|
---|
| 2404 | * @returns true if in PAE mode, otherwise false.
|
---|
[41803] | 2405 | * @param pVCpu Pointer to the VMCPU.
|
---|
[25835] | 2406 | */
|
---|
| 2407 | VMMDECL(bool) CPUMIsGuestInPAEMode(PVMCPU pVCpu)
|
---|
| 2408 | {
|
---|
| 2409 | return (pVCpu->cpum.s.Guest.cr4 & X86_CR4_PAE)
|
---|
| 2410 | && (pVCpu->cpum.s.Guest.cr0 & (X86_CR0_PE | X86_CR0_PG)) == (X86_CR0_PE | X86_CR0_PG)
|
---|
| 2411 | && !(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA);
|
---|
| 2412 | }
|
---|
| 2413 |
|
---|
| 2414 |
|
---|
[42165] | 2415 | /**
|
---|
| 2416 | * Tests if the guest is running in 64 bits mode or not.
|
---|
| 2417 | *
|
---|
| 2418 | * @returns true if in 64 bits protected mode, otherwise false.
|
---|
| 2419 | * @param pVCpu The current virtual CPU.
|
---|
| 2420 | */
|
---|
| 2421 | VMMDECL(bool) CPUMIsGuestIn64BitCode(PVMCPU pVCpu)
|
---|
| 2422 | {
|
---|
| 2423 | if (!CPUMIsGuestInLongMode(pVCpu))
|
---|
| 2424 | return false;
|
---|
[42407] | 2425 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, &pVCpu->cpum.s.Guest.cs);
|
---|
[42165] | 2426 | return pVCpu->cpum.s.Guest.cs.Attr.n.u1Long;
|
---|
| 2427 | }
|
---|
| 2428 |
|
---|
| 2429 |
|
---|
| 2430 | /**
|
---|
| 2431 | * Helper for CPUMIsGuestIn64BitCodeEx that handles lazy resolving of hidden CS
|
---|
| 2432 | * registers.
|
---|
| 2433 | *
|
---|
| 2434 | * @returns true if in 64 bits protected mode, otherwise false.
|
---|
| 2435 | * @param pCtx Pointer to the current guest CPU context.
|
---|
| 2436 | */
|
---|
| 2437 | VMM_INT_DECL(bool) CPUMIsGuestIn64BitCodeSlow(PCPUMCTX pCtx)
|
---|
| 2438 | {
|
---|
| 2439 | return CPUMIsGuestIn64BitCode(CPUM_GUEST_CTX_TO_VMCPU(pCtx));
|
---|
| 2440 | }
|
---|
| 2441 |
|
---|
[42407] | 2442 | #ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
| 2443 | /**
|
---|
| 2444 | *
|
---|
| 2445 | * @returns @c true if we've entered raw-mode and selectors with RPL=1 are
|
---|
| 2446 | * really RPL=0, @c false if we've not (RPL=1 really is RPL=1).
|
---|
| 2447 | * @param pVCpu The current virtual CPU.
|
---|
| 2448 | */
|
---|
| 2449 | VMM_INT_DECL(bool) CPUMIsGuestInRawMode(PVMCPU pVCpu)
|
---|
| 2450 | {
|
---|
| 2451 | return pVCpu->cpum.s.fRawEntered;
|
---|
| 2452 | }
|
---|
| 2453 | #endif
|
---|
[42165] | 2454 |
|
---|
[42705] | 2455 |
|
---|
[1] | 2456 | /**
|
---|
| 2457 | * Updates the EFLAGS while we're in raw-mode.
|
---|
| 2458 | *
|
---|
[41802] | 2459 | * @param pVCpu Pointer to the VMCPU.
|
---|
[41940] | 2460 | * @param fEfl The new EFLAGS value.
|
---|
[1] | 2461 | */
|
---|
[41940] | 2462 | VMMDECL(void) CPUMRawSetEFlags(PVMCPU pVCpu, uint32_t fEfl)
|
---|
[1] | 2463 | {
|
---|
[42705] | 2464 | #ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
| 2465 | if (pVCpu->cpum.s.fRawEntered)
|
---|
| 2466 | PATMRawSetEFlags(pVCpu->CTX_SUFF(pVM), CPUMCTX2CORE(&pVCpu->cpum.s.Guest), fEfl);
|
---|
| 2467 | else
|
---|
| 2468 | #endif
|
---|
[41940] | 2469 | pVCpu->cpum.s.Guest.eflags.u32 = fEfl;
|
---|
[1] | 2470 | }
|
---|
| 2471 |
|
---|
[30263] | 2472 |
|
---|
[1] | 2473 | /**
|
---|
| 2474 | * Gets the EFLAGS while we're in raw-mode.
|
---|
| 2475 | *
|
---|
| 2476 | * @returns The eflags.
|
---|
[41940] | 2477 | * @param pVCpu Pointer to the current virtual CPU.
|
---|
[1] | 2478 | */
|
---|
[41940] | 2479 | VMMDECL(uint32_t) CPUMRawGetEFlags(PVMCPU pVCpu)
|
---|
[1] | 2480 | {
|
---|
[42705] | 2481 | #ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
| 2482 | if (pVCpu->cpum.s.fRawEntered)
|
---|
| 2483 | return PATMRawGetEFlags(pVCpu->CTX_SUFF(pVM), CPUMCTX2CORE(&pVCpu->cpum.s.Guest));
|
---|
| 2484 | #endif
|
---|
[41940] | 2485 | return pVCpu->cpum.s.Guest.eflags.u32;
|
---|
[1] | 2486 | }
|
---|
| 2487 |
|
---|
| 2488 |
|
---|
| 2489 | /**
|
---|
| 2490 | * Sets the specified changed flags (CPUM_CHANGED_*).
|
---|
| 2491 | *
|
---|
[41940] | 2492 | * @param pVCpu Pointer to the current virtual CPU.
|
---|
[1] | 2493 | */
|
---|
[18927] | 2494 | VMMDECL(void) CPUMSetChangedFlags(PVMCPU pVCpu, uint32_t fChangedFlags)
|
---|
[1] | 2495 | {
|
---|
[18927] | 2496 | pVCpu->cpum.s.fChanged |= fChangedFlags;
|
---|
[1] | 2497 | }
|
---|
| 2498 |
|
---|
[12657] | 2499 |
|
---|
[1] | 2500 | /**
|
---|
| 2501 | * Checks if the CPU supports the FXSAVE and FXRSTOR instruction.
|
---|
| 2502 | * @returns true if supported.
|
---|
| 2503 | * @returns false if not supported.
|
---|
[41783] | 2504 | * @param pVM Pointer to the VM.
|
---|
[1] | 2505 | */
|
---|
[12989] | 2506 | VMMDECL(bool) CPUMSupportsFXSR(PVM pVM)
|
---|
[1] | 2507 | {
|
---|
| 2508 | return pVM->cpum.s.CPUFeatures.edx.u1FXSR != 0;
|
---|
| 2509 | }
|
---|
| 2510 |
|
---|
| 2511 |
|
---|
| 2512 | /**
|
---|
| 2513 | * Checks if the host OS uses the SYSENTER / SYSEXIT instructions.
|
---|
| 2514 | * @returns true if used.
|
---|
| 2515 | * @returns false if not used.
|
---|
[41783] | 2516 | * @param pVM Pointer to the VM.
|
---|
[1] | 2517 | */
|
---|
[12989] | 2518 | VMMDECL(bool) CPUMIsHostUsingSysEnter(PVM pVM)
|
---|
[1] | 2519 | {
|
---|
[18927] | 2520 | return (pVM->cpum.s.fHostUseFlags & CPUM_USE_SYSENTER) != 0;
|
---|
[1] | 2521 | }
|
---|
| 2522 |
|
---|
| 2523 |
|
---|
| 2524 | /**
|
---|
| 2525 | * Checks if the host OS uses the SYSCALL / SYSRET instructions.
|
---|
| 2526 | * @returns true if used.
|
---|
| 2527 | * @returns false if not used.
|
---|
[41783] | 2528 | * @param pVM Pointer to the VM.
|
---|
[1] | 2529 | */
|
---|
[12989] | 2530 | VMMDECL(bool) CPUMIsHostUsingSysCall(PVM pVM)
|
---|
[1] | 2531 | {
|
---|
[18927] | 2532 | return (pVM->cpum.s.fHostUseFlags & CPUM_USE_SYSCALL) != 0;
|
---|
[1] | 2533 | }
|
---|
| 2534 |
|
---|
[12657] | 2535 | #ifndef IN_RING3
|
---|
[5695] | 2536 |
|
---|
[1] | 2537 | /**
|
---|
[42034] | 2538 | * Lazily sync in the FPU/XMM state.
|
---|
[1] | 2539 | *
|
---|
| 2540 | * @returns VBox status code.
|
---|
[41803] | 2541 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 2542 | */
|
---|
[18927] | 2543 | VMMDECL(int) CPUMHandleLazyFPU(PVMCPU pVCpu)
|
---|
[1] | 2544 | {
|
---|
[15416] | 2545 | return cpumHandleLazyFPUAsm(&pVCpu->cpum.s);
|
---|
[1] | 2546 | }
|
---|
| 2547 |
|
---|
[5695] | 2548 | #endif /* !IN_RING3 */
|
---|
[1] | 2549 |
|
---|
| 2550 | /**
|
---|
[42034] | 2551 | * Checks if we activated the FPU/XMM state of the guest OS.
|
---|
[1] | 2552 | * @returns true if we did.
|
---|
| 2553 | * @returns false if not.
|
---|
[41802] | 2554 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 2555 | */
|
---|
[13960] | 2556 | VMMDECL(bool) CPUMIsGuestFPUStateActive(PVMCPU pVCpu)
|
---|
[1] | 2557 | {
|
---|
[13960] | 2558 | return (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU) != 0;
|
---|
[1] | 2559 | }
|
---|
| 2560 |
|
---|
[5695] | 2561 |
|
---|
[1] | 2562 | /**
|
---|
[42034] | 2563 | * Deactivate the FPU/XMM state of the guest OS.
|
---|
[41802] | 2564 | * @param pVCpu Pointer to the VMCPU.
|
---|
[1] | 2565 | */
|
---|
[18927] | 2566 | VMMDECL(void) CPUMDeactivateGuestFPUState(PVMCPU pVCpu)
|
---|
[1] | 2567 | {
|
---|
[18927] | 2568 | pVCpu->cpum.s.fUseFlags &= ~CPUM_USED_FPU;
|
---|
[1] | 2569 | }
|
---|
| 2570 |
|
---|
[5695] | 2571 |
|
---|
[1] | 2572 | /**
|
---|
[42034] | 2573 | * Checks if the guest debug state is active.
|
---|
[12578] | 2574 | *
|
---|
| 2575 | * @returns boolean
|
---|
[41800] | 2576 | * @param pVM Pointer to the VM.
|
---|
[12578] | 2577 | */
|
---|
[18927] | 2578 | VMMDECL(bool) CPUMIsGuestDebugStateActive(PVMCPU pVCpu)
|
---|
[12578] | 2579 | {
|
---|
[18927] | 2580 | return (pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS) != 0;
|
---|
[12578] | 2581 | }
|
---|
| 2582 |
|
---|
[21252] | 2583 | /**
|
---|
[42034] | 2584 | * Checks if the hyper debug state is active.
|
---|
[21252] | 2585 | *
|
---|
| 2586 | * @returns boolean
|
---|
[41800] | 2587 | * @param pVM Pointer to the VM.
|
---|
[21252] | 2588 | */
|
---|
| 2589 | VMMDECL(bool) CPUMIsHyperDebugStateActive(PVMCPU pVCpu)
|
---|
| 2590 | {
|
---|
| 2591 | return (pVCpu->cpum.s.fUseFlags & CPUM_USE_DEBUG_REGS_HYPER) != 0;
|
---|
| 2592 | }
|
---|
[12657] | 2593 |
|
---|
[21252] | 2594 |
|
---|
[12578] | 2595 | /**
|
---|
[30263] | 2596 | * Mark the guest's debug state as inactive.
|
---|
[12578] | 2597 | *
|
---|
| 2598 | * @returns boolean
|
---|
[41800] | 2599 | * @param pVM Pointer to the VM.
|
---|
[12578] | 2600 | */
|
---|
[18927] | 2601 | VMMDECL(void) CPUMDeactivateGuestDebugState(PVMCPU pVCpu)
|
---|
[12578] | 2602 | {
|
---|
[18927] | 2603 | pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS;
|
---|
[12578] | 2604 | }
|
---|
| 2605 |
|
---|
| 2606 |
|
---|
| 2607 | /**
|
---|
[30263] | 2608 | * Mark the hypervisor's debug state as inactive.
|
---|
[21252] | 2609 | *
|
---|
| 2610 | * @returns boolean
|
---|
[41800] | 2611 | * @param pVM Pointer to the VM.
|
---|
[21252] | 2612 | */
|
---|
| 2613 | VMMDECL(void) CPUMDeactivateHyperDebugState(PVMCPU pVCpu)
|
---|
| 2614 | {
|
---|
| 2615 | pVCpu->cpum.s.fUseFlags &= ~CPUM_USE_DEBUG_REGS_HYPER;
|
---|
| 2616 | }
|
---|
| 2617 |
|
---|
[1] | 2618 |
|
---|
[1828] | 2619 | /**
|
---|
| 2620 | * Get the current privilege level of the guest.
|
---|
| 2621 | *
|
---|
[41939] | 2622 | * @returns CPL
|
---|
| 2623 | * @param pVCpu Pointer to the current virtual CPU.
|
---|
[1828] | 2624 | */
|
---|
[41939] | 2625 | VMMDECL(uint32_t) CPUMGetGuestCPL(PVMCPU pVCpu)
|
---|
[1828] | 2626 | {
|
---|
[42166] | 2627 | /*
|
---|
| 2628 | * CPL can reliably be found in SS.DPL (hidden regs valid) or SS if not.
|
---|
| 2629 | *
|
---|
| 2630 | * Note! We used to check CS.DPL here, assuming it was always equal to
|
---|
| 2631 | * CPL even if a conforming segment was loaded. But this truned out to
|
---|
| 2632 | * only apply to older AMD-V. With VT-x we had an ACP2 regression
|
---|
| 2633 | * during install after a far call to ring 2 with VT-x. Then on newer
|
---|
| 2634 | * AMD-V CPUs we have to move the VMCB.guest.u8CPL into cs.Attr.n.u2Dpl
|
---|
| 2635 | * as well as ss.Attr.n.u2Dpl to make this (and other) code work right.
|
---|
| 2636 | *
|
---|
| 2637 | * So, forget CS.DPL, always use SS.DPL.
|
---|
| 2638 | *
|
---|
| 2639 | * Note! The SS RPL is always equal to the CPL, while the CS RPL
|
---|
| 2640 | * isn't necessarily equal if the segment is conforming.
|
---|
| 2641 | * See section 4.11.1 in the AMD manual.
|
---|
| 2642 | */
|
---|
[41939] | 2643 | uint32_t uCpl;
|
---|
[42166] | 2644 | if (pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE)
|
---|
[10523] | 2645 | {
|
---|
[42166] | 2646 | if (!pVCpu->cpum.s.Guest.eflags.Bits.u1VM)
|
---|
[31512] | 2647 | {
|
---|
[42407] | 2648 | if (CPUMSELREG_ARE_HIDDEN_PARTS_VALID(pVCpu, &pVCpu->cpum.s.Guest.ss))
|
---|
[41939] | 2649 | uCpl = pVCpu->cpum.s.Guest.ss.Attr.n.u2Dpl;
|
---|
[31512] | 2650 | else
|
---|
[42166] | 2651 | {
|
---|
| 2652 | uCpl = (pVCpu->cpum.s.Guest.ss.Sel & X86_SEL_RPL);
|
---|
[42188] | 2653 | #ifdef VBOX_WITH_RAW_MODE_NOT_R0
|
---|
[42166] | 2654 | if (uCpl == 1)
|
---|
| 2655 | uCpl = 0;
|
---|
[1828] | 2656 | #endif
|
---|
[42166] | 2657 | }
|
---|
[1969] | 2658 | }
|
---|
| 2659 | else
|
---|
[42166] | 2660 | uCpl = 3; /* V86 has CPL=3; REM doesn't set DPL=3 in V8086 mode. See @bugref{5130}. */
|
---|
[1828] | 2661 | }
|
---|
| 2662 | else
|
---|
[42166] | 2663 | uCpl = 0; /* Real mode is zero; CPL set to 3 for VT-x real-mode emulation. */
|
---|
[41939] | 2664 | return uCpl;
|
---|
[1828] | 2665 | }
|
---|
[4207] | 2666 |
|
---|
| 2667 |
|
---|
| 2668 | /**
|
---|
| 2669 | * Gets the current guest CPU mode.
|
---|
| 2670 | *
|
---|
| 2671 | * If paging mode is what you need, check out PGMGetGuestMode().
|
---|
| 2672 | *
|
---|
| 2673 | * @returns The CPU mode.
|
---|
[41802] | 2674 | * @param pVCpu Pointer to the VMCPU.
|
---|
[4207] | 2675 | */
|
---|
[18927] | 2676 | VMMDECL(CPUMMODE) CPUMGetGuestMode(PVMCPU pVCpu)
|
---|
[4207] | 2677 | {
|
---|
| 2678 | CPUMMODE enmMode;
|
---|
[18927] | 2679 | if (!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE))
|
---|
[4207] | 2680 | enmMode = CPUMMODE_REAL;
|
---|
[18927] | 2681 | else if (!(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA))
|
---|
[4207] | 2682 | enmMode = CPUMMODE_PROTECTED;
|
---|
[9543] | 2683 | else
|
---|
| 2684 | enmMode = CPUMMODE_LONG;
|
---|
[4207] | 2685 |
|
---|
| 2686 | return enmMode;
|
---|
| 2687 | }
|
---|
[42186] | 2688 |
|
---|
| 2689 |
|
---|
| 2690 | /**
|
---|
| 2691 | * Figure whether the CPU is currently executing 16, 32 or 64 bit code.
|
---|
| 2692 | *
|
---|
| 2693 | * @returns 16, 32 or 64.
|
---|
| 2694 | * @param pVCpu The current virtual CPU.
|
---|
| 2695 | */
|
---|
| 2696 | VMMDECL(uint32_t) CPUMGetGuestCodeBits(PVMCPU pVCpu)
|
---|
| 2697 | {
|
---|
| 2698 | if (!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE))
|
---|
| 2699 | return 16;
|
---|
| 2700 |
|
---|
| 2701 | if (pVCpu->cpum.s.Guest.eflags.Bits.u1VM)
|
---|
| 2702 | {
|
---|
| 2703 | Assert(!(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA));
|
---|
| 2704 | return 16;
|
---|
| 2705 | }
|
---|
| 2706 |
|
---|
[42407] | 2707 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, &pVCpu->cpum.s.Guest.cs);
|
---|
[42186] | 2708 | if ( pVCpu->cpum.s.Guest.cs.Attr.n.u1Long
|
---|
| 2709 | && (pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA))
|
---|
| 2710 | return 64;
|
---|
| 2711 |
|
---|
| 2712 | if (pVCpu->cpum.s.Guest.cs.Attr.n.u1DefBig)
|
---|
| 2713 | return 32;
|
---|
| 2714 |
|
---|
| 2715 | return 16;
|
---|
| 2716 | }
|
---|
| 2717 |
|
---|
| 2718 |
|
---|
| 2719 | VMMDECL(DISCPUMODE) CPUMGetGuestDisMode(PVMCPU pVCpu)
|
---|
| 2720 | {
|
---|
| 2721 | if (!(pVCpu->cpum.s.Guest.cr0 & X86_CR0_PE))
|
---|
| 2722 | return DISCPUMODE_16BIT;
|
---|
| 2723 |
|
---|
| 2724 | if (pVCpu->cpum.s.Guest.eflags.Bits.u1VM)
|
---|
| 2725 | {
|
---|
| 2726 | Assert(!(pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA));
|
---|
| 2727 | return DISCPUMODE_16BIT;
|
---|
| 2728 | }
|
---|
| 2729 |
|
---|
[42407] | 2730 | CPUMSELREG_LAZY_LOAD_HIDDEN_PARTS(pVCpu, &pVCpu->cpum.s.Guest.cs);
|
---|
[42186] | 2731 | if ( pVCpu->cpum.s.Guest.cs.Attr.n.u1Long
|
---|
| 2732 | && (pVCpu->cpum.s.Guest.msrEFER & MSR_K6_EFER_LMA))
|
---|
| 2733 | return DISCPUMODE_64BIT;
|
---|
| 2734 |
|
---|
| 2735 | if (pVCpu->cpum.s.Guest.cs.Attr.n.u1DefBig)
|
---|
| 2736 | return DISCPUMODE_32BIT;
|
---|
| 2737 |
|
---|
| 2738 | return DISCPUMODE_16BIT;
|
---|
| 2739 | }
|
---|
| 2740 |
|
---|