1 | /* $Id: CPUMRZ.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * CPUM - Raw-mode and ring-0 context.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2020 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 | */
|
---|
46 | VMMRZ_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 | */
|
---|
84 | VMMRZ_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 | */
|
---|
97 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForRead(PVMCPUCC pVCpu)
|
---|
98 | {
|
---|
99 | if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
|
---|
100 | {
|
---|
101 | cpumRZSaveGuestFpuState(&pVCpu->cpum.s, false /*fLeaveFpuAccessible*/);
|
---|
102 | pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
|
---|
103 | Log7(("CPUMRZFpuStateActualizeForRead\n"));
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Makes sure the XMM0..XMM15 and MXCSR state in CPUMCPU::Guest is up to date.
|
---|
110 | *
|
---|
111 | * This will not cause CPUM_USED_FPU_GUEST to change.
|
---|
112 | *
|
---|
113 | * @param pVCpu The cross context virtual CPU structure.
|
---|
114 | */
|
---|
115 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeSseForRead(PVMCPUCC pVCpu)
|
---|
116 | {
|
---|
117 | #if defined(VBOX_WITH_KERNEL_USING_XMM) && HC_ARCH_BITS == 64
|
---|
118 | NOREF(pVCpu);
|
---|
119 | #else
|
---|
120 | if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
|
---|
121 | {
|
---|
122 | cpumRZSaveGuestSseRegisters(&pVCpu->cpum.s);
|
---|
123 | Log7(("CPUMRZFpuStateActualizeSseForRead\n"));
|
---|
124 | }
|
---|
125 | #endif
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Makes sure the YMM0..YMM15 and MXCSR state in CPUMCPU::Guest is up to date.
|
---|
131 | *
|
---|
132 | * This will not cause CPUM_USED_FPU_GUEST to change.
|
---|
133 | *
|
---|
134 | * @param pVCpu The cross context virtual CPU structure.
|
---|
135 | */
|
---|
136 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeAvxForRead(PVMCPUCC pVCpu)
|
---|
137 | {
|
---|
138 | if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
|
---|
139 | {
|
---|
140 | cpumRZSaveGuestAvxRegisters(&pVCpu->cpum.s);
|
---|
141 | Log7(("CPUMRZFpuStateActualizeAvxForRead\n"));
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|