1 | /** @file
|
---|
2 | * IEM - Interpreted Execution Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___VBox_vmm_iem_h
|
---|
27 | #define ___VBox_vmm_iem_h
|
---|
28 |
|
---|
29 | #include <VBox/types.h>
|
---|
30 | #include <VBox/vmm/trpm.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 |
|
---|
34 | RT_C_DECLS_BEGIN
|
---|
35 |
|
---|
36 | /** @defgroup grp_iem The Interpreted Execution Manager API.
|
---|
37 | * @ingroup grp_vmm
|
---|
38 | * @{
|
---|
39 | */
|
---|
40 |
|
---|
41 | /** @name IEMXCPTRAISEINFO_XXX - Extra info. on a recursive exception situation.
|
---|
42 | *
|
---|
43 | * This is primarily used by HM for working around a PGM limitation (see
|
---|
44 | * @bugref{6607}) and special NMI/IRET handling. In the future, this may be
|
---|
45 | * used for diagnostics.
|
---|
46 | *
|
---|
47 | * @{
|
---|
48 | */
|
---|
49 | typedef uint32_t IEMXCPTRAISEINFO;
|
---|
50 | /** Pointer to a IEMXCPTINFO type. */
|
---|
51 | typedef IEMXCPTRAISEINFO *PIEMXCPTRAISEINFO;
|
---|
52 | /** No addition info. available. */
|
---|
53 | #define IEMXCPTRAISEINFO_NONE RT_BIT_32(0)
|
---|
54 | /** Delivery of a \#AC caused another \#AC. */
|
---|
55 | #define IEMXCPTRAISEINFO_AC_AC RT_BIT_32(1)
|
---|
56 | /** Delivery of a \#PF caused another \#PF. */
|
---|
57 | #define IEMXCPTRAISEINFO_PF_PF RT_BIT_32(2)
|
---|
58 | /** Delivery of a \#PF caused some contributory exception. */
|
---|
59 | #define IEMXCPTRAISEINFO_PF_CONTRIBUTORY_XCPT RT_BIT_32(3)
|
---|
60 | /** Delivery of an external interrupt caused an exception. */
|
---|
61 | #define IEMXCPTRAISEINFO_EXT_INT_XCPT RT_BIT_32(4)
|
---|
62 | /** Delivery of an external interrupt caused an \#PF. */
|
---|
63 | #define IEMXCPTRAISEINFO_EXT_INT_PF RT_BIT_32(5)
|
---|
64 | /** Delivery of a software interrupt caused an exception. */
|
---|
65 | #define IEMXCPTRAISEINFO_SOFT_INT_XCPT RT_BIT_32(6)
|
---|
66 | /** Delivery of an NMI caused an exception. */
|
---|
67 | #define IEMXCPTRAISEINFO_NMI_XCPT RT_BIT_32(7)
|
---|
68 | /** Delivery of an NMI caused a \#PF. */
|
---|
69 | #define IEMXCPTRAISEINFO_NMI_PF RT_BIT_32(8)
|
---|
70 | /** Can re-execute the instruction at CS:RIP. */
|
---|
71 | #define IEMXCPTRAISEINFO_CAN_REEXEC_INSTR RT_BIT_32(9)
|
---|
72 | /** @} */
|
---|
73 |
|
---|
74 |
|
---|
75 | /** @name IEMXCPTRAISE_XXX - Ways to handle a recursive exception condition.
|
---|
76 | * @{ */
|
---|
77 | typedef enum IEMXCPTRAISE
|
---|
78 | {
|
---|
79 | /** Raise the current (second) exception. */
|
---|
80 | IEMXCPTRAISE_CURRENT_XCPT = 0,
|
---|
81 | /** Re-raise the previous (first) event (for HM, unused by IEM). */
|
---|
82 | IEMXCPTRAISE_PREV_EVENT,
|
---|
83 | /** Re-execute instruction at CS:RIP (for HM, unused by IEM). */
|
---|
84 | IEMXCPTRAISE_REEXEC_INSTR,
|
---|
85 | /** Raise a \#DF exception. */
|
---|
86 | IEMXCPTRAISE_DOUBLE_FAULT,
|
---|
87 | /** Raise a triple fault. */
|
---|
88 | IEMXCPTRAISE_TRIPLE_FAULT,
|
---|
89 | /** Cause a CPU hang. */
|
---|
90 | IEMXCPTRAISE_CPU_HANG,
|
---|
91 | /** Invalid sequence of events. */
|
---|
92 | IEMXCPTRAISE_INVALID = 0x7fffffff
|
---|
93 | } IEMXCPTRAISE;
|
---|
94 | /** Pointer to a IEMXCPTRAISE type. */
|
---|
95 | typedef IEMXCPTRAISE *PIEMXCPTRAISE;
|
---|
96 | /** @} */
|
---|
97 |
|
---|
98 |
|
---|
99 | /** @name Operand or addressing mode.
|
---|
100 | * @{ */
|
---|
101 | typedef uint8_t IEMMODE;
|
---|
102 | #define IEMMODE_16BIT 0
|
---|
103 | #define IEMMODE_32BIT 1
|
---|
104 | #define IEMMODE_64BIT 2
|
---|
105 | /** @} */
|
---|
106 |
|
---|
107 |
|
---|
108 | /** @name IEM_XCPT_FLAGS_XXX - flags for iemRaiseXcptOrInt.
|
---|
109 | * @{ */
|
---|
110 | /** CPU exception. */
|
---|
111 | #define IEM_XCPT_FLAGS_T_CPU_XCPT RT_BIT_32(0)
|
---|
112 | /** External interrupt (from PIC, APIC, whatever). */
|
---|
113 | #define IEM_XCPT_FLAGS_T_EXT_INT RT_BIT_32(1)
|
---|
114 | /** Software interrupt (int or into, not bound).
|
---|
115 | * Returns to the following instruction */
|
---|
116 | #define IEM_XCPT_FLAGS_T_SOFT_INT RT_BIT_32(2)
|
---|
117 | /** Takes an error code. */
|
---|
118 | #define IEM_XCPT_FLAGS_ERR RT_BIT_32(3)
|
---|
119 | /** Takes a CR2. */
|
---|
120 | #define IEM_XCPT_FLAGS_CR2 RT_BIT_32(4)
|
---|
121 | /** Generated by the breakpoint instruction. */
|
---|
122 | #define IEM_XCPT_FLAGS_BP_INSTR RT_BIT_32(5)
|
---|
123 | /** Generated by a DRx instruction breakpoint and RF should be cleared. */
|
---|
124 | #define IEM_XCPT_FLAGS_DRx_INSTR_BP RT_BIT_32(6)
|
---|
125 | /** Generated by the icebp instruction. */
|
---|
126 | #define IEM_XCPT_FLAGS_ICEBP_INSTR RT_BIT_32(7)
|
---|
127 | /** Generated by the overflow instruction. */
|
---|
128 | #define IEM_XCPT_FLAGS_OF_INSTR RT_BIT_32(8)
|
---|
129 | /** @} */
|
---|
130 |
|
---|
131 |
|
---|
132 | /** @name IEMTARGETCPU_XXX - IEM target CPU specification.
|
---|
133 | *
|
---|
134 | * This is a gross simpliciation of CPUMMICROARCH for dealing with really old
|
---|
135 | * CPUs which didn't have much in the way of hinting at supported instructions
|
---|
136 | * and features. This slowly changes with the introduction of CPUID with the
|
---|
137 | * Intel Pentium.
|
---|
138 | *
|
---|
139 | * @{
|
---|
140 | */
|
---|
141 | /** The dynamic target CPU mode is for getting thru the BIOS and then use
|
---|
142 | * the debugger or modifying instruction behaviour (e.g. HLT) to switch to a
|
---|
143 | * different target CPU. */
|
---|
144 | #define IEMTARGETCPU_DYNAMIC UINT32_C(0)
|
---|
145 | /** Intel 8086/8088. */
|
---|
146 | #define IEMTARGETCPU_8086 UINT32_C(1)
|
---|
147 | /** NEC V20/V30.
|
---|
148 | * @remarks must be between 8086 and 80186. */
|
---|
149 | #define IEMTARGETCPU_V20 UINT32_C(2)
|
---|
150 | /** Intel 80186/80188. */
|
---|
151 | #define IEMTARGETCPU_186 UINT32_C(3)
|
---|
152 | /** Intel 80286. */
|
---|
153 | #define IEMTARGETCPU_286 UINT32_C(4)
|
---|
154 | /** Intel 80386. */
|
---|
155 | #define IEMTARGETCPU_386 UINT32_C(5)
|
---|
156 | /** Intel 80486. */
|
---|
157 | #define IEMTARGETCPU_486 UINT32_C(6)
|
---|
158 | /** Intel Pentium . */
|
---|
159 | #define IEMTARGETCPU_PENTIUM UINT32_C(7)
|
---|
160 | /** Intel PentiumPro. */
|
---|
161 | #define IEMTARGETCPU_PPRO UINT32_C(8)
|
---|
162 | /** A reasonably current CPU, probably newer than the pentium pro when it comes
|
---|
163 | * to the feature set and behaviour. Generally the CPUID info and CPU vendor
|
---|
164 | * dicates the behaviour here. */
|
---|
165 | #define IEMTARGETCPU_CURRENT UINT32_C(9)
|
---|
166 | /** @} */
|
---|
167 |
|
---|
168 |
|
---|
169 | /** @name IEM status codes.
|
---|
170 | *
|
---|
171 | * Not quite sure how this will play out in the end, just aliasing safe status
|
---|
172 | * codes for now.
|
---|
173 | *
|
---|
174 | * @{ */
|
---|
175 | #define VINF_IEM_RAISED_XCPT VINF_EM_RESCHEDULE
|
---|
176 | /** @} */
|
---|
177 |
|
---|
178 |
|
---|
179 | VMMDECL(VBOXSTRICTRC) IEMExecOne(PVMCPU pVCpu);
|
---|
180 | VMMDECL(VBOXSTRICTRC) IEMExecOneEx(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, uint32_t *pcbWritten);
|
---|
181 | VMMDECL(VBOXSTRICTRC) IEMExecOneWithPrefetchedByPC(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, uint64_t OpcodeBytesPC,
|
---|
182 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
183 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassEx(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, uint32_t *pcbWritten);
|
---|
184 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassWithPrefetchedByPC(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, uint64_t OpcodeBytesPC,
|
---|
185 | const void *pvOpcodeBytes, size_t cbOpcodeBytes);
|
---|
186 | VMMDECL(VBOXSTRICTRC) IEMExecOneBypassWithPrefetchedByPCWritten(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, uint64_t OpcodeBytesPC,
|
---|
187 | const void *pvOpcodeBytes, size_t cbOpcodeBytes,
|
---|
188 | uint32_t *pcbWritten);
|
---|
189 | VMMDECL(VBOXSTRICTRC) IEMExecLots(PVMCPU pVCpu, uint32_t *pcInstructions);
|
---|
190 | VMMDECL(VBOXSTRICTRC) IEMInjectTrpmEvent(PVMCPU pVCpu);
|
---|
191 | VMM_INT_DECL(VBOXSTRICTRC) IEMInjectTrap(PVMCPU pVCpu, uint8_t u8TrapNo, TRPMEVENT enmType, uint16_t uErrCode, RTGCPTR uCr2,
|
---|
192 | uint8_t cbInstr);
|
---|
193 |
|
---|
194 | VMM_INT_DECL(int) IEMBreakpointSet(PVM pVM, RTGCPTR GCPtrBp);
|
---|
195 | VMM_INT_DECL(int) IEMBreakpointClear(PVM pVM, RTGCPTR GCPtrBp);
|
---|
196 |
|
---|
197 | VMM_INT_DECL(void) IEMTlbInvalidateAll(PVMCPU pVCpu, bool fVmm);
|
---|
198 | VMM_INT_DECL(void) IEMTlbInvalidatePage(PVMCPU pVCpu, RTGCPTR GCPtr);
|
---|
199 | VMM_INT_DECL(void) IEMTlbInvalidateAllPhysical(PVMCPU pVCpu);
|
---|
200 | VMM_INT_DECL(bool) IEMGetCurrentXcpt(PVMCPU pVCpu, uint8_t *puVector, uint32_t *pfFlags, uint32_t *puErr,
|
---|
201 | uint64_t *puCr2);
|
---|
202 | VMM_INT_DECL(IEMXCPTRAISE) IEMEvaluateRecursiveXcpt(PVMCPU pVCpu, uint32_t fPrevFlags, uint8_t uPrevVector, uint32_t fCurFlags,
|
---|
203 | uint8_t uCurVector, PIEMXCPTRAISEINFO pXcptRaiseInfo);
|
---|
204 |
|
---|
205 | /** @name Given Instruction Interpreters
|
---|
206 | * @{ */
|
---|
207 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecStringIoWrite(PVMCPU pVCpu, uint8_t cbValue, IEMMODE enmAddrMode,
|
---|
208 | bool fRepPrefix, uint8_t cbInstr, uint8_t iEffSeg, bool fIoChecked);
|
---|
209 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecStringIoRead(PVMCPU pVCpu, uint8_t cbValue, IEMMODE enmAddrMode,
|
---|
210 | bool fRepPrefix, uint8_t cbInstr, bool fIoChecked);
|
---|
211 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedOut(PVMCPU pVCpu, uint8_t cbInstr, uint16_t u16Port, uint8_t cbReg);
|
---|
212 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedIn(PVMCPU pVCpu, uint8_t cbInstr, uint16_t u16Port, uint8_t cbReg);
|
---|
213 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedMovCRxWrite(PVMCPU pVCpu, uint8_t cbInstr, uint8_t iCrReg, uint8_t iGReg);
|
---|
214 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedMovCRxRead(PVMCPU pVCpu, uint8_t cbInstr, uint8_t iGReg, uint8_t iCrReg);
|
---|
215 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedClts(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
216 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedLmsw(PVMCPU pVCpu, uint8_t cbInstr, uint16_t uValue);
|
---|
217 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedXsetbv(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
218 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedInvlpg(PVMCPU pVCpu, uint8_t cbInstr, RTGCPTR GCPtrPage);
|
---|
219 | #ifdef VBOX_WITH_NESTED_HWVIRT
|
---|
220 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedClgi(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
221 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedStgi(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
222 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedVmload(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
223 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedVmsave(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
224 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedInvlpga(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
225 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecDecodedVmrun(PVMCPU pVCpu, uint8_t cbInstr);
|
---|
226 | VMM_INT_DECL(VBOXSTRICTRC) IEMExecSvmVmexit(PVMCPU pVCpu, uint64_t uExitCode, uint64_t uExitInfo1, uint64_t uExitInfo2);
|
---|
227 | #endif
|
---|
228 | /** @} */
|
---|
229 |
|
---|
230 | #if defined(IEM_VERIFICATION_MODE) && defined(IN_RING3)
|
---|
231 | VMM_INT_DECL(void) IEMNotifyMMIORead(PVM pVM, RTGCPHYS GCPhys, size_t cbValue);
|
---|
232 | VMM_INT_DECL(void) IEMNotifyMMIOWrite(PVM pVM, RTGCPHYS GCPhys, uint32_t u32Value, size_t cbValue);
|
---|
233 | VMM_INT_DECL(void) IEMNotifyIOPortRead(PVM pVM, RTIOPORT Port, size_t cbValue);
|
---|
234 | VMM_INT_DECL(void) IEMNotifyIOPortWrite(PVM pVM, RTIOPORT Port, uint32_t u32Value, size_t cbValue);
|
---|
235 | VMM_INT_DECL(void) IEMNotifyIOPortReadString(PVM pVM, RTIOPORT Port, void *pvDst, RTGCUINTREG cTransfers, size_t cbValue);
|
---|
236 | VMM_INT_DECL(void) IEMNotifyIOPortWriteString(PVM pVM, RTIOPORT Port, void const *pvSrc, RTGCUINTREG cTransfers, size_t cbValue);
|
---|
237 | #endif
|
---|
238 |
|
---|
239 |
|
---|
240 | /** @defgroup grp_iem_r3 The IEM Host Context Ring-3 API.
|
---|
241 | * @{
|
---|
242 | */
|
---|
243 | VMMR3DECL(int) IEMR3Init(PVM pVM);
|
---|
244 | VMMR3DECL(int) IEMR3Term(PVM pVM);
|
---|
245 | VMMR3DECL(void) IEMR3Relocate(PVM pVM);
|
---|
246 | VMMR3_INT_DECL(VBOXSTRICTRC) IEMR3ProcessForceFlag(PVM pVM, PVMCPU pVCpu, VBOXSTRICTRC rcStrict);
|
---|
247 | /** @} */
|
---|
248 |
|
---|
249 | /** @} */
|
---|
250 |
|
---|
251 | RT_C_DECLS_END
|
---|
252 |
|
---|
253 | #endif
|
---|
254 |
|
---|