1 | /* $Id: IEMInlineExec.h 108409 2025-02-27 10:35:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IEM - Interpreted Execution Manager - Inline Exec/Decoder routines.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 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 | #ifndef VMM_INCLUDED_SRC_include_IEMInlineExec_h
|
---|
29 | #define VMM_INCLUDED_SRC_include_IEMInlineExec_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/err.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | /* Documentation and forward declarations for inline functions required for every target: */
|
---|
38 |
|
---|
39 | RT_NO_WARN_UNUSED_INLINE_PROTOTYPE_BEGIN
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Calculates the the IEM_F_XXX flags.
|
---|
43 | *
|
---|
44 | * @returns IEM_F_XXX combination match the current CPU state.
|
---|
45 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
46 | * calling thread.
|
---|
47 | */
|
---|
48 | DECL_FORCE_INLINE(uint32_t) iemCalcExecFlags(PVMCPUCC pVCpu) RT_NOEXCEPT;
|
---|
49 |
|
---|
50 | #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
|
---|
51 | /**
|
---|
52 | * Invalidates the decoder state and asserts various stuff - strict builds only.
|
---|
53 | *
|
---|
54 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
55 | * calling thread.
|
---|
56 | */
|
---|
57 | DECLINLINE(void) iemInitExecTargetStrict(PVMCPUCC pVCpu) RT_NOEXCEPT;
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | RT_NO_WARN_UNUSED_INLINE_PROTOTYPE_END
|
---|
61 |
|
---|
62 |
|
---|
63 | //#ifdef VBOX_VMM_TARGET_X86
|
---|
64 | //# include "VMMAll/target-x86/IEMInlineExec-x86.h"
|
---|
65 | //#elif defined(VBOX_VMM_TARGET_ARMV8)
|
---|
66 | //# include "VMMAll/target-armv8/IEMInlineExec-armv8.h"
|
---|
67 | //#endif
|
---|
68 |
|
---|
69 |
|
---|
70 | # if defined(VBOX_INCLUDED_vmm_dbgf_h) || defined(DOXYGEN_RUNNING) /* dbgf.ro.cEnabledHwBreakpoints */
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Initializes the execution state.
|
---|
74 | *
|
---|
75 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
76 | * calling thread.
|
---|
77 | * @param fExecOpts Optional execution flags:
|
---|
78 | * - IEM_F_BYPASS_HANDLERS
|
---|
79 | * - IEM_F_X86_DISREGARD_LOCK
|
---|
80 | *
|
---|
81 | * @remarks Callers of this must call iemUninitExec() to undo potentially fatal
|
---|
82 | * side-effects in strict builds.
|
---|
83 | */
|
---|
84 | DECLINLINE(void) iemInitExec(PVMCPUCC pVCpu, uint32_t fExecOpts) RT_NOEXCEPT
|
---|
85 | {
|
---|
86 | IEM_CTX_ASSERT(pVCpu, IEM_CPUMCTX_EXTRN_EXEC_DECODED_NO_MEM_MASK);
|
---|
87 | Assert(!VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_IEM));
|
---|
88 |
|
---|
89 | pVCpu->iem.s.rcPassUp = VINF_SUCCESS;
|
---|
90 | pVCpu->iem.s.fExec = iemCalcExecFlags(pVCpu) | fExecOpts;
|
---|
91 | pVCpu->iem.s.cActiveMappings = 0;
|
---|
92 | pVCpu->iem.s.iNextMapping = 0;
|
---|
93 |
|
---|
94 | # ifdef VBOX_STRICT
|
---|
95 | iemInitExecTargetStrict(pVCpu);
|
---|
96 | # endif
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | # if defined(VBOX_WITH_NESTED_HWVIRT_SVM) || defined(VBOX_WITH_NESTED_HWVIRT_VMX)
|
---|
101 | /**
|
---|
102 | * Performs a minimal reinitialization of the execution state.
|
---|
103 | *
|
---|
104 | * This is intended to be used by VM-exits, SMM, LOADALL and other similar
|
---|
105 | * 'world-switch' types operations on the CPU. Currently only nested
|
---|
106 | * hardware-virtualization uses it.
|
---|
107 | *
|
---|
108 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
109 | * @param cbInstr The instruction length (for flushing).
|
---|
110 | */
|
---|
111 | DECLINLINE(void) iemReInitExec(PVMCPUCC pVCpu, uint8_t cbInstr) RT_NOEXCEPT
|
---|
112 | {
|
---|
113 | pVCpu->iem.s.fExec = iemCalcExecFlags(pVCpu) | (pVCpu->iem.s.fExec & IEM_F_USER_OPTS);
|
---|
114 | # ifdef VBOX_VMM_TARGET_X86
|
---|
115 | iemOpcodeFlushHeavy(pVCpu, cbInstr);
|
---|
116 | # elif !defined(IEM_WITH_CODE_TLB)
|
---|
117 | pVCpu->iem.s.cbOpcode = cbInstr;
|
---|
118 | # else
|
---|
119 | pVCpu->iem.s.cbInstrBufTotal = 0;
|
---|
120 | RT_NOREF(cbInstr);
|
---|
121 | # endif
|
---|
122 | }
|
---|
123 | # endif
|
---|
124 |
|
---|
125 | # endif /* VBOX_INCLUDED_vmm_dbgf_h || DOXYGEN_RUNNING */
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Counterpart to #iemInitExec that undoes evil strict-build stuff.
|
---|
129 | *
|
---|
130 | * @param pVCpu The cross context virtual CPU structure of the
|
---|
131 | * calling thread.
|
---|
132 | */
|
---|
133 | DECLINLINE(void) iemUninitExec(PVMCPUCC pVCpu) RT_NOEXCEPT
|
---|
134 | {
|
---|
135 | /* Note! do not touch fInPatchCode here! (see iemUninitExecAndFiddleStatusAndMaybeReenter) */
|
---|
136 | # ifdef VBOX_STRICT
|
---|
137 | # ifdef IEM_WITH_CODE_TLB
|
---|
138 | NOREF(pVCpu);
|
---|
139 | # else
|
---|
140 | pVCpu->iem.s.cbOpcode = 0;
|
---|
141 | # endif
|
---|
142 | # else
|
---|
143 | NOREF(pVCpu);
|
---|
144 | # endif
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Calls iemUninitExec, iemExecStatusCodeFiddling and iemRCRawMaybeReenter.
|
---|
150 | *
|
---|
151 | * Only calling iemRCRawMaybeReenter in raw-mode, obviously.
|
---|
152 | *
|
---|
153 | * @returns Fiddled strict vbox status code, ready to return to non-IEM caller.
|
---|
154 | * @param pVCpu The cross context virtual CPU structure of the calling thread.
|
---|
155 | * @param rcStrict The status code to fiddle.
|
---|
156 | */
|
---|
157 | DECLINLINE(VBOXSTRICTRC) iemUninitExecAndFiddleStatusAndMaybeReenter(PVMCPUCC pVCpu, VBOXSTRICTRC rcStrict) RT_NOEXCEPT
|
---|
158 | {
|
---|
159 | iemUninitExec(pVCpu);
|
---|
160 | return iemExecStatusCodeFiddling(pVCpu, rcStrict);
|
---|
161 | }
|
---|
162 |
|
---|
163 | #endif /* !VMM_INCLUDED_SRC_include_IEMInlineExec_h */
|
---|