1 | /** @file
|
---|
2 | * IEM - Interpreted Execution Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2023 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 Operand or addressing mode.
|
---|
119 | * @{ */
|
---|
120 | typedef uint8_t IEMMODE;
|
---|
121 | #define IEMMODE_16BIT 0
|
---|
122 | #define IEMMODE_32BIT 1
|
---|
123 | #define IEMMODE_64BIT 2
|
---|
124 | /** @} */
|
---|
125 |
|
---|
126 |
|
---|
127 | /** @name IEM_XCPT_FLAGS_XXX - flags for iemRaiseXcptOrInt.
|
---|
128 | * @{ */
|
---|
129 | /** CPU exception. */
|
---|
130 | #define IEM_XCPT_FLAGS_T_CPU_XCPT RT_BIT_32(0)
|
---|
131 | /** External interrupt (from PIC, APIC, whatever). */
|
---|
132 | #define IEM_XCPT_FLAGS_T_EXT_INT RT_BIT_32(1)
|
---|
133 | /** Software interrupt (int or into, not bound).
|
---|
134 | * Returns to the following instruction */
|
---|
135 | #define IEM_XCPT_FLAGS_T_SOFT_INT RT_BIT_32(2)
|
---|
136 | /** Takes an error code. */
|
---|
137 | #define IEM_XCPT_FLAGS_ERR RT_BIT_32(3)
|
---|
138 | /** Takes a CR2. */
|
---|
139 | #define IEM_XCPT_FLAGS_CR2 RT_BIT_32(4)
|
---|
140 | /** Generated by the breakpoint instruction. */
|
---|
141 | #define IEM_XCPT_FLAGS_BP_INSTR RT_BIT_32(5)
|
---|
142 | /** Generated by a DRx instruction breakpoint and RF should be cleared. */
|
---|
143 | #define IEM_XCPT_FLAGS_DRx_INSTR_BP RT_BIT_32(6)
|
---|
144 | /** Generated by the icebp instruction. */
|
---|
145 | #define IEM_XCPT_FLAGS_ICEBP_INSTR RT_BIT_32(7)
|
---|
146 | /** Generated by the overflow instruction. */
|
---|
147 | #define IEM_XCPT_FLAGS_OF_INSTR RT_BIT_32(8)
|
---|
148 | /** @} */
|
---|
149 |
|
---|
150 |
|
---|
151 | /** @name IEM status codes.
|
---|
152 | *
|
---|
153 | * Not quite sure how this will play out in the end, just aliasing safe status
|
---|
154 | * codes for now.
|
---|
155 | *
|
---|
156 | * @{ */
|
---|
157 | #define VINF_IEM_RAISED_XCPT VINF_EM_RESCHEDULE
|
---|
158 | /** @} */
|
---|
159 |
|
---|
160 |
|
---|
161 | VMMDECL(VBOXSTRICTRC) IEMExecOne(PVMCPUCC pVCpu);
|
---|
162 | VMMDECL(VBOXSTRICTRC) IEMExecOneEx(PVMCPUCC pVCpu, uint32_t *pcbWritten);
|
---|
163 | VMMDECL(VBOXSTRICTRC) IEMExecOneWithPrefetchedByPC(PVMCPUCC pVCpu, uint64_t OpcodeBytesPC,
|
---|
164 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
165 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassEx(PVMCPUCC pVCpu, uint32_t *pcbWritten);
|
---|
166 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassWithPrefetchedByPC(PVMCPUCC pVCpu, uint64_t OpcodeBytesPC,
|
---|
167 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
168 | VMMDECL(VBOXSTRICTRC) IEMExecOneIgnoreLock(PVMCPUCC pVCpu);
|
---|
169 | VMMDECL(VBOXSTRICTRC) IEMExecLots(PVMCPUCC pVCpu, uint32_t cMaxInstructions, uint32_t cPollRate, uint32_t *pcInstructions);
|
---|
170 | /** Statistics returned by IEMExecForExits. */
|
---|
171 | typedef struct IEMEXECFOREXITSTATS
|
---|
172 | {
|
---|
173 | uint32_t cInstructions;
|
---|
174 | uint32_t cExits;
|
---|
175 | uint32_t cMaxExitDistance;
|
---|
176 | uint32_t cReserved;
|
---|
177 | } IEMEXECFOREXITSTATS;
|
---|
178 | /** Pointer to statistics returned by IEMExecForExits. */
|
---|
179 | typedef IEMEXECFOREXITSTATS *PIEMEXECFOREXITSTATS;
|
---|
180 | VMMDECL(VBOXSTRICTRC) IEMExecForExits(PVMCPUCC pVCpu, uint32_t fWillExit, uint32_t cMinInstructions, uint32_t cMaxInstructions,
|
---|
181 | uint32_t cMaxInstructionsWithoutExits, PIEMEXECFOREXITSTATS pStats);
|
---|
182 | VMMDECL(VBOXSTRICTRC) IEMInjectTrpmEvent(PVMCPUCC pVCpu);
|
---|
183 | VMM_INT_DECL(VBOXSTRICTRC) IEMInjectTrap(PVMCPUCC pVCpu, uint8_t u8TrapNo, TRPMEVENT enmType, uint16_t uErrCode, RTGCPTR uCr2,
|
---|
184 | uint8_t cbInstr);
|
---|
185 |
|
---|
186 | VMM_INT_DECL(int) IEMBreakpointSet(PVM pVM, RTGCPTR GCPtrBp);
|
---|
187 | VMM_INT_DECL(int) IEMBreakpointClear(PVM pVM, RTGCPTR GCPtrBp);
|
---|
188 |
|
---|
189 | VMM_INT_DECL(void) IEMTlbInvalidateAll(PVMCPUCC pVCpu);
|
---|
190 | VMM_INT_DECL(void) IEMTlbInvalidatePage(PVMCPUCC pVCpu, RTGCPTR GCPtr);
|
---|
191 | VMM_INT_DECL(void) IEMTlbInvalidateAllPhysical(PVMCPUCC pVCpu);
|
---|
192 | VMM_INT_DECL(void) IEMTlbInvalidateAllPhysicalAllCpus(PVMCC pVM, VMCPUID idCpuCaller);
|
---|
193 | VMM_INT_DECL(bool) IEMGetCurrentXcpt(PVMCPUCC pVCpu, uint8_t *puVector, uint32_t *pfFlags, uint32_t *puErr,
|
---|
194 | uint64_t *puCr2);
|
---|
195 | VMM_INT_DECL(IEMXCPTRAISE) IEMEvaluateRecursiveXcpt(PVMCPUCC pVCpu, uint32_t fPrevFlags, uint8_t uPrevVector, uint32_t fCurFlags,
|
---|
196 | uint8_t uCurVector, PIEMXCPTRAISEINFO pXcptRaiseInfo);
|
---|
197 |
|
---|
198 | /** @defgroup grp_iem_r3 The IEM Host Context Ring-3 API.
|
---|
199 | * @{
|
---|
200 | */
|
---|
201 | VMMR3DECL(int) IEMR3Init(PVM pVM);
|
---|
202 | VMMR3DECL(int) IEMR3Term(PVM pVM);
|
---|
203 | VMMR3DECL(void) IEMR3Relocate(PVM pVM);
|
---|
204 | VMMR3_INT_DECL(VBOXSTRICTRC) IEMR3ProcessForceFlag(PVM pVM, PVMCPUCC pVCpu, VBOXSTRICTRC rcStrict);
|
---|
205 | /** @} */
|
---|
206 |
|
---|
207 | /** @} */
|
---|
208 |
|
---|
209 | RT_C_DECLS_END
|
---|
210 |
|
---|
211 | #endif /* !VBOX_INCLUDED_vmm_iem_h */
|
---|
212 |
|
---|