1 | /** @file
|
---|
2 | * IEM - Interpreted Execution Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2024 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef VBOX_INCLUDED_vmm_iem_h
|
---|
37 | #define VBOX_INCLUDED_vmm_iem_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <VBox/types.h>
|
---|
43 | #include <VBox/vmm/trpm.h>
|
---|
44 | #include <iprt/assert.h>
|
---|
45 |
|
---|
46 | #ifdef VBOX_VMM_TARGET_ARMV8
|
---|
47 | # include <VBox/vmm/iem-armv8.h>
|
---|
48 | #else
|
---|
49 | # include <VBox/vmm/iem-x86-amd64.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 | RT_C_DECLS_BEGIN
|
---|
54 |
|
---|
55 | /** @defgroup grp_iem The Interpreted Execution Manager API.
|
---|
56 | * @ingroup grp_vmm
|
---|
57 | * @{
|
---|
58 | */
|
---|
59 |
|
---|
60 | /** @name IEMXCPTRAISEINFO_XXX - Extra info. on a recursive exception situation.
|
---|
61 | *
|
---|
62 | * This is primarily used by HM for working around a PGM limitation (see
|
---|
63 | * @bugref{6607}) and special NMI/IRET handling. In the future, this may be
|
---|
64 | * used for diagnostics.
|
---|
65 | *
|
---|
66 | * @{
|
---|
67 | */
|
---|
68 | typedef uint32_t IEMXCPTRAISEINFO;
|
---|
69 | /** Pointer to a IEMXCPTINFO type. */
|
---|
70 | typedef IEMXCPTRAISEINFO *PIEMXCPTRAISEINFO;
|
---|
71 | /** No addition info. available. */
|
---|
72 | #define IEMXCPTRAISEINFO_NONE RT_BIT_32(0)
|
---|
73 | /** Delivery of a \#AC caused another \#AC. */
|
---|
74 | #define IEMXCPTRAISEINFO_AC_AC RT_BIT_32(1)
|
---|
75 | /** Delivery of a \#PF caused another \#PF. */
|
---|
76 | #define IEMXCPTRAISEINFO_PF_PF RT_BIT_32(2)
|
---|
77 | /** Delivery of a \#PF caused some contributory exception. */
|
---|
78 | #define IEMXCPTRAISEINFO_PF_CONTRIBUTORY_XCPT RT_BIT_32(3)
|
---|
79 | /** Delivery of an external interrupt caused an exception. */
|
---|
80 | #define IEMXCPTRAISEINFO_EXT_INT_XCPT RT_BIT_32(4)
|
---|
81 | /** Delivery of an external interrupt caused an \#PF. */
|
---|
82 | #define IEMXCPTRAISEINFO_EXT_INT_PF RT_BIT_32(5)
|
---|
83 | /** Delivery of a software interrupt caused an exception. */
|
---|
84 | #define IEMXCPTRAISEINFO_SOFT_INT_XCPT RT_BIT_32(6)
|
---|
85 | /** Delivery of an NMI caused an exception. */
|
---|
86 | #define IEMXCPTRAISEINFO_NMI_XCPT RT_BIT_32(7)
|
---|
87 | /** Delivery of an NMI caused a \#PF. */
|
---|
88 | #define IEMXCPTRAISEINFO_NMI_PF RT_BIT_32(8)
|
---|
89 | /** Can re-execute the instruction at CS:RIP. */
|
---|
90 | #define IEMXCPTRAISEINFO_CAN_REEXEC_INSTR RT_BIT_32(9)
|
---|
91 | /** @} */
|
---|
92 |
|
---|
93 |
|
---|
94 | /** @name IEMXCPTRAISE_XXX - Ways to handle a recursive exception condition.
|
---|
95 | * @{ */
|
---|
96 | typedef enum IEMXCPTRAISE
|
---|
97 | {
|
---|
98 | /** Raise the current (second) exception. */
|
---|
99 | IEMXCPTRAISE_CURRENT_XCPT = 0,
|
---|
100 | /** Re-raise the previous (first) event (for HM, unused by IEM). */
|
---|
101 | IEMXCPTRAISE_PREV_EVENT,
|
---|
102 | /** Re-execute instruction at CS:RIP (for HM, unused by IEM). */
|
---|
103 | IEMXCPTRAISE_REEXEC_INSTR,
|
---|
104 | /** Raise a \#DF exception. */
|
---|
105 | IEMXCPTRAISE_DOUBLE_FAULT,
|
---|
106 | /** Raise a triple fault. */
|
---|
107 | IEMXCPTRAISE_TRIPLE_FAULT,
|
---|
108 | /** Cause a CPU hang. */
|
---|
109 | IEMXCPTRAISE_CPU_HANG,
|
---|
110 | /** Invalid sequence of events. */
|
---|
111 | IEMXCPTRAISE_INVALID = 0x7fffffff
|
---|
112 | } IEMXCPTRAISE;
|
---|
113 | /** Pointer to a IEMXCPTRAISE type. */
|
---|
114 | typedef IEMXCPTRAISE *PIEMXCPTRAISE;
|
---|
115 | /** @} */
|
---|
116 |
|
---|
117 |
|
---|
118 | /** @name IEM_XCPT_FLAGS_XXX - flags for iemRaiseXcptOrInt.
|
---|
119 | * @{ */
|
---|
120 | /** CPU exception. */
|
---|
121 | #define IEM_XCPT_FLAGS_T_CPU_XCPT RT_BIT_32(0)
|
---|
122 | /** External interrupt (from PIC, APIC, whatever). */
|
---|
123 | #define IEM_XCPT_FLAGS_T_EXT_INT RT_BIT_32(1)
|
---|
124 | /** Software interrupt (int or into, not bound).
|
---|
125 | * Returns to the following instruction */
|
---|
126 | #define IEM_XCPT_FLAGS_T_SOFT_INT RT_BIT_32(2)
|
---|
127 | /** Takes an error code. */
|
---|
128 | #define IEM_XCPT_FLAGS_ERR RT_BIT_32(3)
|
---|
129 | /** Takes a CR2. */
|
---|
130 | #define IEM_XCPT_FLAGS_CR2 RT_BIT_32(4)
|
---|
131 | /** Generated by the breakpoint instruction. */
|
---|
132 | #define IEM_XCPT_FLAGS_BP_INSTR RT_BIT_32(5)
|
---|
133 | /** Generated by a DRx instruction breakpoint and RF should be cleared. */
|
---|
134 | #define IEM_XCPT_FLAGS_DRx_INSTR_BP RT_BIT_32(6)
|
---|
135 | /** Generated by the icebp instruction. */
|
---|
136 | #define IEM_XCPT_FLAGS_ICEBP_INSTR RT_BIT_32(7)
|
---|
137 | /** Generated by the overflow instruction. */
|
---|
138 | #define IEM_XCPT_FLAGS_OF_INSTR RT_BIT_32(8)
|
---|
139 | /** @} */
|
---|
140 |
|
---|
141 |
|
---|
142 | /** @name IEM status codes.
|
---|
143 | *
|
---|
144 | * Not quite sure how this will play out in the end, just aliasing safe status
|
---|
145 | * codes for now.
|
---|
146 | *
|
---|
147 | * @{ */
|
---|
148 | #define VINF_IEM_RAISED_XCPT VINF_EM_RESCHEDULE
|
---|
149 | /** @} */
|
---|
150 |
|
---|
151 |
|
---|
152 | VMMDECL(VBOXSTRICTRC) IEMExecOne(PVMCPUCC pVCpu);
|
---|
153 | VMMDECL(VBOXSTRICTRC) IEMExecOneEx(PVMCPUCC pVCpu, uint32_t *pcbWritten);
|
---|
154 | VMMDECL(VBOXSTRICTRC) IEMExecOneWithPrefetchedByPC(PVMCPUCC pVCpu, uint64_t OpcodeBytesPC,
|
---|
155 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
156 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassEx(PVMCPUCC pVCpu, uint32_t *pcbWritten);
|
---|
157 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassWithPrefetchedByPC(PVMCPUCC pVCpu, uint64_t OpcodeBytesPC,
|
---|
158 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
159 | VMMDECL(VBOXSTRICTRC) IEMExecOneIgnoreLock(PVMCPUCC pVCpu);
|
---|
160 | VMMDECL(VBOXSTRICTRC) IEMExecLots(PVMCPUCC pVCpu, uint32_t cMaxInstructions, uint32_t cPollRate, uint32_t *pcInstructions);
|
---|
161 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecRecompiler(PVMCC pVM, PVMCPUCC pVCpu, bool fWasHalted);
|
---|
162 | /** Statistics returned by IEMExecForExits. */
|
---|
163 | typedef struct IEMEXECFOREXITSTATS
|
---|
164 | {
|
---|
165 | uint32_t cInstructions;
|
---|
166 | uint32_t cExits;
|
---|
167 | uint32_t cMaxExitDistance;
|
---|
168 | uint32_t cReserved;
|
---|
169 | } IEMEXECFOREXITSTATS;
|
---|
170 | /** Pointer to statistics returned by IEMExecForExits. */
|
---|
171 | typedef IEMEXECFOREXITSTATS *PIEMEXECFOREXITSTATS;
|
---|
172 | VMMDECL(VBOXSTRICTRC) IEMExecForExits(PVMCPUCC pVCpu, uint32_t fWillExit, uint32_t cMinInstructions, uint32_t cMaxInstructions,
|
---|
173 | uint32_t cMaxInstructionsWithoutExits, PIEMEXECFOREXITSTATS pStats);
|
---|
174 | VMMDECL(VBOXSTRICTRC) IEMInjectTrpmEvent(PVMCPUCC pVCpu);
|
---|
175 | VMM_INT_DECL(VBOXSTRICTRC) IEMInjectTrap(PVMCPUCC pVCpu, uint8_t u8TrapNo, TRPMEVENT enmType, uint16_t uErrCode, RTGCPTR uCr2,
|
---|
176 | uint8_t cbInstr);
|
---|
177 |
|
---|
178 | VMM_INT_DECL(int) IEMBreakpointSet(PVM pVM, RTGCPTR GCPtrBp);
|
---|
179 | VMM_INT_DECL(int) IEMBreakpointClear(PVM pVM, RTGCPTR GCPtrBp);
|
---|
180 |
|
---|
181 | /** Reasons why IEMTlbInvalidateAllPhysicalAllCpus is called. */
|
---|
182 | typedef enum IEMTLBPHYSFLUSHREASON
|
---|
183 | {
|
---|
184 | IEMTLBPHYSFLUSHREASON_INVALID = 0,
|
---|
185 | IEMTLBPHYSFLUSHREASON_ALLOCATED, /**< Allocated page, was zero page. */
|
---|
186 | IEMTLBPHYSFLUSHREASON_ALLOCATED_FROM_SHARED, /**< Allocated page, was shared page. */
|
---|
187 | IEMTLBPHYSFLUSHREASON_ALLOCATED_LARGE, /**< Allocated a large page (was zero). */
|
---|
188 | IEMTLBPHYSFLUSHREASON_FREED,
|
---|
189 | IEMTLBPHYSFLUSHREASON_MADE_WRITABLE,
|
---|
190 | IEMTLBPHYSFLUSHREASON_SHARED,
|
---|
191 | IEMTLBPHYSFLUSHREASON_ZERO_ALL,
|
---|
192 | IEMTLBPHYSFLUSHREASON_RESET_ALIAS,
|
---|
193 | IEMTLBPHYSFLUSHREASON_MMIO2_ALIAS,
|
---|
194 | IEMTLBPHYSFLUSHREASON_HANDLER_RESET,
|
---|
195 | IEMTLBPHYSFLUSHREASON_ROM_PROTECT,
|
---|
196 | IEMTLBPHYSFLUSHREASON_MISC,
|
---|
197 | IEMTLBPHYSFLUSHREASON_END
|
---|
198 | } IEMTLBPHYSFLUSHREASON;
|
---|
199 |
|
---|
200 | VMM_INT_DECL(void) IEMTlbInvalidateAll(PVMCPUCC pVCpu);
|
---|
201 | VMM_INT_DECL(void) IEMTlbInvalidateAllGlobal(PVMCPUCC pVCpu);
|
---|
202 | VMM_INT_DECL(void) IEMTlbInvalidatePage(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
203 | VMM_INT_DECL(void) IEMTlbInvalidateAllPhysical(PVMCPUCC pVCpu);
|
---|
204 | VMM_INT_DECL(void) IEMTlbInvalidateAllPhysicalAllCpus(PVMCC pVM, VMCPUID idCpuCaller, IEMTLBPHYSFLUSHREASON enmReason);
|
---|
205 |
|
---|
206 | VMM_INT_DECL(bool) IEMGetCurrentXcpt(PVMCPUCC pVCpu, uint8_t *puVector, uint32_t *pfFlags, uint32_t *puErr,
|
---|
207 | uint64_t *puCr2);
|
---|
208 | VMM_INT_DECL(IEMXCPTRAISE) IEMEvaluateRecursiveXcpt(PVMCPUCC pVCpu, uint32_t fPrevFlags, uint8_t uPrevVector, uint32_t fCurFlags,
|
---|
209 | uint8_t uCurVector, PIEMXCPTRAISEINFO pXcptRaiseInfo);
|
---|
210 |
|
---|
211 | /** @defgroup grp_iem_r3 The IEM Host Context Ring-3 API.
|
---|
212 | * @{
|
---|
213 | */
|
---|
214 | VMMR3DECL(int) IEMR3Init(PVM pVM);
|
---|
215 | VMMR3DECL(int) IEMR3Term(PVM pVM);
|
---|
216 | VMMR3DECL(void) IEMR3Relocate(PVM pVM);
|
---|
217 | VMMR3_INT_DECL(VBOXSTRICTRC) IEMR3ProcessForceFlag(PVM pVM, PVMCPUCC pVCpu, VBOXSTRICTRC rcStrict);
|
---|
218 | VMMR3DECL(const char *) IEMR3GetExitName(uint32_t uExit);
|
---|
219 | VMMR3DECL(int) IEMR3ThreadedProfileRecompilingSavedTbs(PVM pVM, const char *pszFilename, uint32_t cMinTbs);
|
---|
220 | /** @} */
|
---|
221 |
|
---|
222 | /** @} */
|
---|
223 |
|
---|
224 | RT_C_DECLS_END
|
---|
225 |
|
---|
226 | #endif /* !VBOX_INCLUDED_vmm_iem_h */
|
---|
227 |
|
---|