VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMRZ/CPUMRZ.cpp@ 101189

Last change on this file since 101189 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/* $Id: CPUMRZ.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * CPUM - Raw-mode and ring-0 context.
4 */
5
6/*
7 * Copyright (C) 2016-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_CPUM
33#include <VBox/vmm/cpum.h>
34#include "CPUMInternal.h"
35#include <VBox/vmm/vmcc.h>
36
37#include <VBox/err.h>
38#include <VBox/log.h>
39#include <VBox/vmm/hm.h>
40#include <iprt/assert.h>
41#include <iprt/x86.h>
42
43
44
45
46/**
47 * Prepares the host FPU/SSE/AVX stuff for IEM action.
48 *
49 * This will make sure the FPU/SSE/AVX guest state is _not_ loaded in the CPU.
50 * This will make sure the FPU/SSE/AVX host state is saved.
51 * Finally, it will make sure the FPU/SSE/AVX host features can be safely
52 * accessed.
53 *
54 * @param pVCpu The cross context virtual CPU structure.
55 */
56VMMRZ_INT_DECL(void) CPUMRZFpuStatePrepareHostCpuForUse(PVMCPUCC pVCpu)
57{
58 pVCpu->cpum.s.fChanged |= CPUM_CHANGED_FPU_REM;
59 switch (pVCpu->cpum.s.fUseFlags & (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST))
60 {
61 case 0:
62 if (cpumRZSaveHostFPUState(&pVCpu->cpum.s) == VINF_CPUM_HOST_CR0_MODIFIED)
63 HMR0NotifyCpumModifiedHostCr0(pVCpu);
64 Log6(("CPUMRZFpuStatePrepareHostCpuForUse: #0 - %#x\n", ASMGetCR0()));
65 break;
66
67 case CPUM_USED_FPU_HOST:
68 Log6(("CPUMRZFpuStatePrepareHostCpuForUse: #1 - %#x\n", ASMGetCR0()));
69 break;
70
71 case CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST:
72 cpumRZSaveGuestFpuState(&pVCpu->cpum.s, true /*fLeaveFpuAccessible*/);
73#ifdef IN_RING0
74 HMR0NotifyCpumUnloadedGuestFpuState(pVCpu);
75#endif
76 Log6(("CPUMRZFpuStatePrepareHostCpuForUse: #2 - %#x\n", ASMGetCR0()));
77 break;
78
79 default:
80 AssertFailed();
81 }
82
83}
84
85
86/**
87 * Makes sure the FPU/SSE/AVX guest state is saved in CPUMCPU::Guest and will be
88 * reloaded before direct use.
89 *
90 * No promisses about the FPU/SSE/AVX host features are made.
91 *
92 * @param pVCpu The cross context virtual CPU structure.
93 */
94VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForChange(PVMCPUCC pVCpu)
95{
96 CPUMRZFpuStatePrepareHostCpuForUse(pVCpu);
97}
98
99
100/**
101 * Makes sure the FPU/SSE/AVX state in CPUMCPU::Guest is up to date.
102 *
103 * This will not cause CPUM_USED_FPU_GUEST to change.
104 *
105 * @param pVCpu The cross context virtual CPU structure.
106 */
107VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForRead(PVMCPUCC pVCpu)
108{
109 if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
110 {
111 Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
112 cpumRZSaveGuestFpuState(&pVCpu->cpum.s, false /*fLeaveFpuAccessible*/);
113 pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
114 pVCpu->cpum.s.Guest.fUsedFpuGuest = true;
115 Log7(("CPUMRZFpuStateActualizeForRead\n"));
116 }
117}
118
119
120/**
121 * Makes sure the XMM0..XMM15 and MXCSR state in CPUMCPU::Guest is up to date.
122 *
123 * This will not cause CPUM_USED_FPU_GUEST to change.
124 *
125 * @param pVCpu The cross context virtual CPU structure.
126 */
127VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeSseForRead(PVMCPUCC pVCpu)
128{
129#if defined(VBOX_WITH_KERNEL_USING_XMM) && HC_ARCH_BITS == 64
130 NOREF(pVCpu);
131#else
132 if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
133 {
134 Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
135 cpumRZSaveGuestSseRegisters(&pVCpu->cpum.s);
136 Log7(("CPUMRZFpuStateActualizeSseForRead\n"));
137 }
138#endif
139}
140
141
142/**
143 * Makes sure the YMM0..YMM15 and MXCSR state in CPUMCPU::Guest is up to date.
144 *
145 * This will not cause CPUM_USED_FPU_GUEST to change.
146 *
147 * @param pVCpu The cross context virtual CPU structure.
148 */
149VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeAvxForRead(PVMCPUCC pVCpu)
150{
151 if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
152 {
153 Assert(pVCpu->cpum.s.Guest.fUsedFpuGuest);
154 cpumRZSaveGuestAvxRegisters(&pVCpu->cpum.s);
155 Log7(("CPUMRZFpuStateActualizeAvxForRead\n"));
156 }
157}
158
Note: See TracBrowser for help on using the repository browser.

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