1 | /* $Id: CPUMRZ.cpp 61068 2016-05-20 01:24:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * CPUM - Raw-mode and ring-0 context.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016 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/vm.h>
|
---|
26 | #include <VBox/err.h>
|
---|
27 | #include <VBox/log.h>
|
---|
28 | #include <VBox/vmm/hm.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/x86.h>
|
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Prepares the host FPU/SSE/AVX stuff for IEM action.
|
---|
37 | *
|
---|
38 | * This will make sure the FPU/SSE/AVX guest state is _not_ loaded in the CPU.
|
---|
39 | * This will make sure the FPU/SSE/AVX host state is saved.
|
---|
40 | * Finally, it will make sure the FPU/SSE/AVX host features can be safely
|
---|
41 | * accessed.
|
---|
42 | *
|
---|
43 | * @param pVCpu The cross context virtual CPU structure.
|
---|
44 | */
|
---|
45 | VMMRZ_INT_DECL(void) CPUMRZFpuStatePrepareHostCpuForUse(PVMCPU pVCpu)
|
---|
46 | {
|
---|
47 | pVCpu->cpum.s.fChanged |= CPUM_CHANGED_FPU_REM;
|
---|
48 | switch (pVCpu->cpum.s.fUseFlags & (CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST))
|
---|
49 | {
|
---|
50 | case 0:
|
---|
51 | cpumRZSaveHostFPUState(&pVCpu->cpum.s);
|
---|
52 | break;
|
---|
53 |
|
---|
54 | case CPUM_USED_FPU_HOST:
|
---|
55 | #if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
|
---|
56 | if (pVCpu->cpum.s.fUseFlags | CPUM_SYNC_FPU_STATE)
|
---|
57 | {
|
---|
58 | pVCpu->cpum.s.fUseFlags &= ~CPUM_SYNC_FPU_STATE;
|
---|
59 | /** @todo tell HM! */
|
---|
60 | }
|
---|
61 | #endif
|
---|
62 | break;
|
---|
63 |
|
---|
64 | case CPUM_USED_FPU_GUEST | CPUM_USED_FPU_HOST:
|
---|
65 | /** @todo tell HM! */
|
---|
66 | #if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
|
---|
67 | Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE));
|
---|
68 | if (CPUMIsGuestInLongModeEx(&pVCpu->cpum.s.Guest))
|
---|
69 | HMR0SaveFPUState(pVCpu->CTX_SUFF(pVM), pVCpu, &pVCpu->cpum.s.Guest);
|
---|
70 | else
|
---|
71 | #endif
|
---|
72 | cpumRZSaveGuestFpuState(&pVCpu->cpum.s);
|
---|
73 |
|
---|
74 | break;
|
---|
75 |
|
---|
76 | default:
|
---|
77 | AssertFailed();
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Makes sure the FPU/SSE/AVX guest state is saved in CPUMCPU::Guest and will be
|
---|
85 | * reloaded before direct use.
|
---|
86 | *
|
---|
87 | * No promisses about the FPU/SSE/AVX host features are made.
|
---|
88 | *
|
---|
89 | * @param pVCpu The cross context virtual CPU structure.
|
---|
90 | */
|
---|
91 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForChange(PVMCPU pVCpu)
|
---|
92 | {
|
---|
93 | CPUMRZFpuStatePrepareHostCpuForUse(pVCpu);
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Makes sure the FPU/SSE/AVX state in CPUMCPU::Guest is up to date.
|
---|
99 | *
|
---|
100 | * This will not cause CPUM_USED_FPU_GUEST to change.
|
---|
101 | *
|
---|
102 | * @param pVCpu The cross context virtual CPU structure.
|
---|
103 | */
|
---|
104 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeForRead(PVMCPU pVCpu)
|
---|
105 | {
|
---|
106 | if (pVCpu->cpum.s.fUseFlags & CPUM_USED_FPU_GUEST)
|
---|
107 | {
|
---|
108 | #if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
|
---|
109 | Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE));
|
---|
110 | if (CPUMIsGuestInLongModeEx(&pVCpu->cpum.s.Guest))
|
---|
111 | HMR0SaveFPUState(pVCpu->CTX_SUFF(pVM), pVCpu, &pVCpu->cpum.s.Guest);
|
---|
112 | else
|
---|
113 | #endif
|
---|
114 | cpumRZSaveGuestFpuState(&pVCpu->cpum.s);
|
---|
115 | pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Makes sure the XMM0..XMM15 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 | */
|
---|
127 | VMMRZ_INT_DECL(void) CPUMRZFpuStateActualizeSseForRead(PVMCPU 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 | # if defined(IN_RING0) && ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
|
---|
135 | if (CPUMIsGuestInLongModeEx(&pVCpu->cpum.s.Guest))
|
---|
136 | {
|
---|
137 | Assert(!(pVCpu->cpum.s.fUseFlags & CPUM_SYNC_FPU_STATE));
|
---|
138 | HMR0SaveFPUState(pVCpu->CTX_SUFF(pVM), pVCpu, &pVCpu->cpum.s.Guest);
|
---|
139 | pVCpu->cpum.s.fUseFlags |= CPUM_USED_FPU_GUEST;
|
---|
140 | }
|
---|
141 | else
|
---|
142 | # endif
|
---|
143 | cpumRZSaveGuestSseRegisters(&pVCpu->cpum.s);
|
---|
144 | }
|
---|
145 | #endif
|
---|
146 | }
|
---|
147 |
|
---|