VirtualBox

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

Last change on this file since 94167 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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