VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/IEMAllThrdFuncs.cpp@ 103014

Last change on this file since 103014 was 102876, checked in by vboxsync, 11 months ago

VMM/IEM: Call different threaded functions for each branch in a conditional jump (jcc, loop, loopcc) so we can quit immediately when taking a different branch from what we did during compilation. bugref:10371

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.1 KB
Line 
1/* $Id: IEMAllThrdFuncs.cpp 102876 2024-01-15 14:26:27Z vboxsync $ */
2/** @file
3 * IEM - Instruction Decoding and Emulation, Threaded Functions.
4 */
5
6/*
7 * Copyright (C) 2011-2023 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
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#ifndef LOG_GROUP /* defined when included by tstIEMCheckMc.cpp */
33# define LOG_GROUP LOG_GROUP_IEM
34#endif
35#define VMCPU_INCL_CPUM_GST_CTX
36#define IEM_WITH_OPAQUE_DECODER_STATE
37#include <VBox/vmm/iem.h>
38#include <VBox/vmm/cpum.h>
39#include <VBox/vmm/apic.h>
40#include <VBox/vmm/pdm.h>
41#include <VBox/vmm/pgm.h>
42#include <VBox/vmm/iom.h>
43#include <VBox/vmm/em.h>
44#include <VBox/vmm/hm.h>
45#include <VBox/vmm/nem.h>
46#include <VBox/vmm/gim.h>
47#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
48# include <VBox/vmm/em.h>
49# include <VBox/vmm/hm_svm.h>
50#endif
51#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
52# include <VBox/vmm/hmvmxinline.h>
53#endif
54#include <VBox/vmm/tm.h>
55#include <VBox/vmm/dbgf.h>
56#include <VBox/vmm/dbgftrace.h>
57#include "IEMInternal.h"
58#include <VBox/vmm/vmcc.h>
59#include <VBox/log.h>
60#include <VBox/err.h>
61#include <VBox/param.h>
62#include <VBox/dis.h>
63#include <VBox/disopcode-x86-amd64.h>
64#include <iprt/asm-math.h>
65#include <iprt/assert.h>
66#include <iprt/string.h>
67#include <iprt/x86.h>
68
69#include "IEMInline.h"
70#include "IEMMc.h"
71
72#include "IEMThreadedFunctions.h"
73
74
75/*********************************************************************************************************************************
76* Defined Constants And Macros *
77*********************************************************************************************************************************/
78
79/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
80 * and only used when we're in 16-bit code on a pre-386 CPU. */
81#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC16(a_cbInstr, a_rcNormal) \
82 return iemRegAddToIp16AndFinishingNoFlags(pVCpu, a_cbInstr, a_rcNormal)
83
84/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
85 * and used for 16-bit and 32-bit code on 386 and later CPUs. */
86#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC32(a_cbInstr, a_rcNormal) \
87 return iemRegAddToEip32AndFinishingNoFlags(pVCpu, a_cbInstr, a_rcNormal)
88
89/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
90 * and only used when we're in 64-bit code. */
91#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC64(a_cbInstr, a_rcNormal) \
92 return iemRegAddToRip64AndFinishingNoFlags(pVCpu, a_cbInstr, a_rcNormal)
93
94
95/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
96 * and only used when we're in 16-bit code on a pre-386 CPU and we need to
97 * check and clear flags. */
98#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC16_WITH_FLAGS(a_cbInstr, a_rcNormal) \
99 return iemRegAddToIp16AndFinishingClearingRF(pVCpu, a_cbInstr, a_rcNormal)
100
101/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
102 * and used for 16-bit and 32-bit code on 386 and later CPUs and we need to
103 * check and clear flags. */
104#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_cbInstr, a_rcNormal) \
105 return iemRegAddToEip32AndFinishingClearingRF(pVCpu, a_cbInstr, a_rcNormal)
106
107/** Variant of IEM_MC_ADVANCE_RIP_AND_FINISH with instruction length as param
108 * and only used when we're in 64-bit code and we need to check and clear
109 * flags. */
110#define IEM_MC_ADVANCE_RIP_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_cbInstr, a_rcNormal) \
111 return iemRegAddToRip64AndFinishingClearingRF(pVCpu, a_cbInstr, a_rcNormal)
112
113#undef IEM_MC_ADVANCE_RIP_AND_FINISH
114
115
116/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length as extra
117 * parameter, for use in 16-bit code on a pre-386 CPU. */
118#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC16(a_i8, a_cbInstr, a_rcNormal) \
119 return iemRegIp16RelativeJumpS8AndFinishNoFlags(pVCpu, a_cbInstr, (a_i8), a_rcNormal)
120
121/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length and operand
122 * size as extra parameters, for use in 16-bit and 32-bit code on 386 and
123 * later CPUs. */
124#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC32(a_i8, a_cbInstr, a_enmEffOpSize, a_rcNormal) \
125 return iemRegEip32RelativeJumpS8AndFinishNoFlags(pVCpu, a_cbInstr, (a_i8), a_enmEffOpSize, a_rcNormal)
126
127/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length and operand
128 * size as extra parameters, for use in 64-bit code. */
129#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC64(a_i8, a_cbInstr, a_enmEffOpSize, a_rcNormal) \
130 return iemRegRip64RelativeJumpS8AndFinishNoFlags(pVCpu, a_cbInstr, (a_i8), a_enmEffOpSize, a_rcNormal)
131
132
133/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length as extra
134 * parameter, for use in 16-bit code on a pre-386 CPU and we need to check and
135 * clear flags. */
136#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC16_WITH_FLAGS(a_i8, a_cbInstr, a_rcNormal) \
137 return iemRegIp16RelativeJumpS8AndFinishClearingRF(pVCpu, a_cbInstr, (a_i8), a_rcNormal)
138
139/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length and operand
140 * size as extra parameters, for use in 16-bit and 32-bit code on 386 and
141 * later CPUs and we need to check and clear flags. */
142#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_i8, a_cbInstr, a_enmEffOpSize, a_rcNormal) \
143 return iemRegEip32RelativeJumpS8AndFinishClearingRF(pVCpu, a_cbInstr, (a_i8), a_enmEffOpSize, a_rcNormal)
144
145/** Variant of IEM_MC_REL_JMP_S8_AND_FINISH with instruction length and operand
146 * size as extra parameters, for use in 64-bit code and we need to check and
147 * clear flags. */
148#define IEM_MC_REL_JMP_S8_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_i8, a_cbInstr, a_enmEffOpSize, a_rcNormal) \
149 return iemRegRip64RelativeJumpS8AndFinishClearingRF(pVCpu, a_cbInstr, (a_i8), a_enmEffOpSize, a_rcNormal)
150
151#undef IEM_MC_REL_JMP_S8_AND_FINISH
152
153
154/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
155 * param, for use in 16-bit code on a pre-386 CPU. */
156#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC16(a_i16, a_cbInstr, a_rcNormal) \
157 return iemRegEip32RelativeJumpS16AndFinishNoFlags(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
158
159/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
160 * param, for use in 16-bit and 32-bit code on 386 and later CPUs. */
161#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC32(a_i16, a_cbInstr, a_rcNormal) \
162 return iemRegEip32RelativeJumpS16AndFinishNoFlags(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
163
164/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
165 * param, for use in 64-bit code. */
166#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC64(a_i16, a_cbInstr, a_rcNormal) \
167 return iemRegRip64RelativeJumpS16AndFinishNoFlags(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
168
169
170/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
171 * param, for use in 16-bit code on a pre-386 CPU and we need to check and
172 * clear flags. */
173#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC16_WITH_FLAGS(a_i16, a_cbInstr, a_rcNormal) \
174 return iemRegEip32RelativeJumpS16AndFinishClearingRF(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
175
176/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
177 * param, for use in 16-bit and 32-bit code on 386 and later CPUs and we need
178 * to check and clear flags. */
179#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_i16, a_cbInstr, a_rcNormal) \
180 return iemRegEip32RelativeJumpS16AndFinishClearingRF(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
181
182/** Variant of IEM_MC_REL_JMP_S16_AND_FINISH with instruction length as
183 * param, for use in 64-bit code and we need to check and clear flags. */
184#define IEM_MC_REL_JMP_S16_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_i16, a_cbInstr, a_rcNormal) \
185 return iemRegRip64RelativeJumpS16AndFinishClearingRF(pVCpu, a_cbInstr, (a_i16), a_rcNormal)
186
187#undef IEM_MC_REL_JMP_S16_AND_FINISH
188
189
190/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
191 * an extra parameter - dummy for pre-386 variations not eliminated by the
192 * python script. */
193#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC16(a_i32, a_cbInstr, a_rcNormal) \
194 do { RT_NOREF(pVCpu, a_i32, a_cbInstr, a_rcNormal); AssertFailedReturn(VERR_IEM_IPE_9); } while (0)
195
196/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
197 * an extra parameter, for use in 16-bit and 32-bit code on 386+. */
198#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC32(a_i32, a_cbInstr, a_rcNormal) \
199 return iemRegEip32RelativeJumpS32AndFinishNoFlags(pVCpu, a_cbInstr, (a_i32), a_rcNormal)
200
201/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
202 * an extra parameter, for use in 64-bit code. */
203#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC64(a_i32, a_cbInstr, a_rcNormal) \
204 return iemRegRip64RelativeJumpS32AndFinishNoFlags(pVCpu, a_cbInstr, (a_i32), a_rcNormal)
205
206
207/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
208 * an extra parameter - dummy for pre-386 variations not eliminated by the
209 * python script. */
210#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC16_WITH_FLAGS(a_i32, a_cbInstr, a_rcNormal) \
211 do { RT_NOREF(pVCpu, a_i32, a_cbInstr, a_rcNormal); AssertFailedReturn(VERR_IEM_IPE_9); } while (0)
212
213/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
214 * an extra parameter, for use in 16-bit and 32-bit code on 386+ and we need
215 * to check and clear flags. */
216#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_i32, a_cbInstr, a_rcNormal) \
217 return iemRegEip32RelativeJumpS32AndFinishClearingRF(pVCpu, a_cbInstr, (a_i32), a_rcNormal)
218
219/** Variant of IEM_MC_REL_JMP_S32_AND_FINISH with instruction length as
220 * an extra parameter, for use in 64-bit code and we need to check and clear
221 * flags. */
222#define IEM_MC_REL_JMP_S32_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_i32, a_cbInstr, a_rcNormal) \
223 return iemRegRip64RelativeJumpS32AndFinishClearingRF(pVCpu, a_cbInstr, (a_i32), a_rcNormal)
224
225#undef IEM_MC_REL_JMP_S32_AND_FINISH
226
227
228
229/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for pre-386 targets. */
230#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC16(a_u16NewIP) \
231 return iemRegRipJumpU16AndFinishNoFlags((pVCpu), (a_u16NewIP))
232
233/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for 386+ targets. */
234#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC32(a_u16NewIP) \
235 return iemRegRipJumpU16AndFinishNoFlags((pVCpu), (a_u16NewIP))
236
237/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for use in 64-bit code. */
238#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC64(a_u16NewIP) \
239 return iemRegRipJumpU16AndFinishNoFlags((pVCpu), (a_u16NewIP))
240
241/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for pre-386 targets that checks and
242 * clears flags. */
243#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC16_WITH_FLAGS(a_u16NewIP) \
244 return iemRegRipJumpU16AndFinishClearingRF((pVCpu), (a_u16NewIP), 0 /* cbInstr - not used */)
245
246/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for 386+ targets that checks and
247 * clears flags. */
248#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_u16NewIP) \
249 return iemRegRipJumpU16AndFinishClearingRF((pVCpu), (a_u16NewIP), 0 /* cbInstr - not used */)
250
251/** Variant of IEM_MC_SET_RIP_U16_AND_FINISH for use in 64-bit code that checks and
252 * clears flags. */
253#define IEM_MC_SET_RIP_U16_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_u16NewIP) \
254 return iemRegRipJumpU16AndFinishClearingRF((pVCpu), (a_u16NewIP), 0 /* cbInstr - not used */)
255
256#undef IEM_MC_SET_RIP_U16_AND_FINISH
257
258
259/** Variant of IEM_MC_SET_RIP_U32_AND_FINISH for 386+ targets. */
260#define IEM_MC_SET_RIP_U32_AND_FINISH_THREADED_PC32(a_u32NewEIP) \
261 return iemRegRipJumpU32AndFinishNoFlags((pVCpu), (a_u32NewEIP))
262
263/** Variant of IEM_MC_SET_RIP_U32_AND_FINISH for use in 64-bit code. */
264#define IEM_MC_SET_RIP_U32_AND_FINISH_THREADED_PC64(a_u32NewEIP) \
265 return iemRegRipJumpU32AndFinishNoFlags((pVCpu), (a_u32NewEIP))
266
267/** Variant of IEM_MC_SET_RIP_U32_AND_FINISH for 386+ targets that checks and
268 * clears flags. */
269#define IEM_MC_SET_RIP_U32_AND_FINISH_THREADED_PC32_WITH_FLAGS(a_u32NewEIP) \
270 return iemRegRipJumpU32AndFinishClearingRF((pVCpu), (a_u32NewEIP), 0 /* cbInstr - not used */)
271
272/** Variant of IEM_MC_SET_RIP_U32_AND_FINISH for use in 64-bit code that checks
273 * and clears flags. */
274#define IEM_MC_SET_RIP_U32_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_u32NewEIP) \
275 return iemRegRipJumpU32AndFinishClearingRF((pVCpu), (a_u32NewEIP), 0 /* cbInstr - not used */)
276
277#undef IEM_MC_SET_RIP_U32_AND_FINISH
278
279
280/** Variant of IEM_MC_SET_RIP_U64_AND_FINISH for use in 64-bit code. */
281#define IEM_MC_SET_RIP_U64_AND_FINISH_THREADED_PC64(a_u32NewEIP) \
282 return iemRegRipJumpU64AndFinishNoFlags((pVCpu), (a_u32NewEIP))
283
284/** Variant of IEM_MC_SET_RIP_U64_AND_FINISH for use in 64-bit code that checks
285 * and clears flags. */
286#define IEM_MC_SET_RIP_U64_AND_FINISH_THREADED_PC64_WITH_FLAGS(a_u32NewEIP) \
287 return iemRegRipJumpU64AndFinishClearingRF((pVCpu), (a_u32NewEIP), 0 /* cbInstr - not used */)
288
289#undef IEM_MC_SET_RIP_U64_AND_FINISH
290
291
292/** Variant of IEM_MC_CALC_RM_EFF_ADDR with additional parameters, 16-bit. */
293#define IEM_MC_CALC_RM_EFF_ADDR_THREADED_16(a_GCPtrEff, a_bRm, a_u16Disp) \
294 (a_GCPtrEff) = iemOpHlpCalcRmEffAddrThreadedAddr16(pVCpu, a_bRm, a_u16Disp)
295
296/** Variant of IEM_MC_CALC_RM_EFF_ADDR with additional parameters, 32-bit. */
297#define IEM_MC_CALC_RM_EFF_ADDR_THREADED_32(a_GCPtrEff, a_bRm, a_uSibAndRspOffset, a_u32Disp) \
298 (a_GCPtrEff) = iemOpHlpCalcRmEffAddrThreadedAddr32(pVCpu, a_bRm, a_uSibAndRspOffset, a_u32Disp)
299
300/** Variant of IEM_MC_CALC_RM_EFF_ADDR with additional parameters. */
301#define IEM_MC_CALC_RM_EFF_ADDR_THREADED_64(a_GCPtrEff, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm) \
302 (a_GCPtrEff) = iemOpHlpCalcRmEffAddrThreadedAddr64(pVCpu, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm)
303
304/** Variant of IEM_MC_CALC_RM_EFF_ADDR with additional parameters. */
305#define IEM_MC_CALC_RM_EFF_ADDR_THREADED_64_FSGS(a_GCPtrEff, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm) \
306 (a_GCPtrEff) = iemOpHlpCalcRmEffAddrThreadedAddr64(pVCpu, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm)
307
308/** Variant of IEM_MC_CALC_RM_EFF_ADDR with additional parameters.
309 * @todo How did that address prefix thing work for 64-bit code again? */
310#define IEM_MC_CALC_RM_EFF_ADDR_THREADED_64_ADDR32(a_GCPtrEff, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm) \
311 (a_GCPtrEff) = (uint32_t)iemOpHlpCalcRmEffAddrThreadedAddr64(pVCpu, a_bRmEx, a_uSibAndRspOffset, a_u32Disp, a_cbImm)
312
313#undef IEM_MC_CALC_RM_EFF_ADDR
314
315
316/** Variant of IEM_MC_CALL_CIMPL_1 with explicit instruction length parameter. */
317#define IEM_MC_CALL_CIMPL_1_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0) \
318 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0)
319#undef IEM_MC_CALL_CIMPL_1
320
321/** Variant of IEM_MC_CALL_CIMPL_2 with explicit instruction length parameter. */
322#define IEM_MC_CALL_CIMPL_2_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1) \
323 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1)
324#undef IEM_MC_CALL_CIMPL_2
325
326/** Variant of IEM_MC_CALL_CIMPL_3 with explicit instruction length parameter. */
327#define IEM_MC_CALL_CIMPL_3_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2) \
328 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2)
329#undef IEM_MC_CALL_CIMPL_3
330
331/** Variant of IEM_MC_CALL_CIMPL_4 with explicit instruction length parameter. */
332#define IEM_MC_CALL_CIMPL_4_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2, a3) \
333 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2, a3)
334#undef IEM_MC_CALL_CIMPL_4
335
336/** Variant of IEM_MC_CALL_CIMPL_5 with explicit instruction length parameter. */
337#define IEM_MC_CALL_CIMPL_5_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2, a3, a4) \
338 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2, a3, a4)
339#undef IEM_MC_CALL_CIMPL_5
340
341
342/** Variant of IEM_MC_DEFER_TO_CIMPL_0_RET with explicit instruction
343 * length parameter. */
344#define IEM_MC_DEFER_TO_CIMPL_0_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl) \
345 return (a_pfnCImpl)(pVCpu, (a_cbInstr))
346#undef IEM_MC_DEFER_TO_CIMPL_0_RET
347
348/** Variant of IEM_MC_DEFER_TO_CIMPL_1_RET with explicit instruction
349 * length parameter. */
350#define IEM_MC_DEFER_TO_CIMPL_1_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0) \
351 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0)
352#undef IEM_MC_DEFER_TO_CIMPL_1_RET
353
354/** Variant of IEM_MC_CALL_CIMPL_2 with explicit instruction length parameter. */
355#define IEM_MC_DEFER_TO_CIMPL_2_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1) \
356 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1)
357#undef IEM_MC_DEFER_TO_CIMPL_2_RET
358
359/** Variant of IEM_MC_DEFER_TO_CIMPL_3 with explicit instruction length
360 * parameter. */
361#define IEM_MC_DEFER_TO_CIMPL_3_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2) \
362 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2)
363#undef IEM_MC_DEFER_TO_CIMPL_3_RET
364
365/** Variant of IEM_MC_DEFER_TO_CIMPL_4 with explicit instruction length
366 * parameter. */
367#define IEM_MC_DEFER_TO_CIMPL_4_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2, a3) \
368 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2, a3)
369#undef IEM_MC_DEFER_TO_CIMPL_4_RET
370
371/** Variant of IEM_MC_DEFER_TO_CIMPL_5 with explicit instruction length
372 * parameter. */
373#define IEM_MC_DEFER_TO_CIMPL_5_RET_THREADED(a_cbInstr, a_fFlags, a_fGstShwFlush, a_pfnCImpl, a0, a1, a2, a3, a4) \
374 return (a_pfnCImpl)(pVCpu, (a_cbInstr), a0, a1, a2, a3, a4)
375#undef IEM_MC_DEFER_TO_CIMPL_5_RET
376
377
378/** Variant of IEM_MC_FETCH_GREG_U8 with extended (20) register index. */
379#define IEM_MC_FETCH_GREG_U8_THREADED(a_u8Dst, a_iGRegEx) \
380 (a_u8Dst) = iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
381
382/** Variant of IEM_MC_FETCH_GREG_U8_ZX_U16 with extended (20) register index. */
383#define IEM_MC_FETCH_GREG_U8_ZX_U16_THREADED(a_u16Dst, a_iGRegEx) \
384 (a_u16Dst) = iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
385
386/** Variant of IEM_MC_FETCH_GREG_U8_ZX_U32 with extended (20) register index. */
387#define IEM_MC_FETCH_GREG_U8_ZX_U32_THREADED(a_u32Dst, a_iGRegEx) \
388 (a_u32Dst) = iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
389
390/** Variant of IEM_MC_FETCH_GREG_U8_ZX_U64 with extended (20) register index. */
391#define IEM_MC_FETCH_GREG_U8_ZX_U64_THREADED(a_u64Dst, a_iGRegEx) \
392 (a_u64Dst) = iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
393
394/** Variant of IEM_MC_FETCH_GREG_U8_SX_U16 with extended (20) register index. */
395#define IEM_MC_FETCH_GREG_U8_SX_U16_THREADED(a_u16Dst, a_iGRegEx) \
396 (a_u16Dst) = (int8_t)iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
397
398/** Variant of IEM_MC_FETCH_GREG_U8_SX_U32 with extended (20) register index. */
399#define IEM_MC_FETCH_GREG_U8_SX_U32_THREADED(a_u32Dst, a_iGRegEx) \
400 (a_u32Dst) = (int8_t)iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
401#undef IEM_MC_FETCH_GREG_U8_SX_U32
402
403/** Variant of IEM_MC_FETCH_GREG_U8_SX_U64 with extended (20) register index. */
404#define IEM_MC_FETCH_GREG_U8_SX_U64_THREADED(a_u64Dst, a_iGRegEx) \
405 (a_u64Dst) = (int8_t)iemGRegFetchU8Ex(pVCpu, (a_iGRegEx))
406#undef IEM_MC_FETCH_GREG_U8_SX_U64
407
408/** Variant of IEM_MC_STORE_GREG_U8 with extended (20) register index. */
409#define IEM_MC_STORE_GREG_U8_THREADED(a_iGRegEx, a_u8Value) \
410 *iemGRegRefU8Ex(pVCpu, (a_iGRegEx)) = (a_u8Value)
411#undef IEM_MC_STORE_GREG_U8
412
413/** Variant of IEM_MC_STORE_GREG_U8_CONST with extended (20) register index. */
414#define IEM_MC_STORE_GREG_U8_CONST_THREADED(a_iGRegEx, a_u8Value) \
415 *iemGRegRefU8Ex(pVCpu, (a_iGRegEx)) = (a_u8Value)
416#undef IEM_MC_STORE_GREG_U8
417
418/** Variant of IEM_MC_REF_GREG_U8 with extended (20) register index. */
419#define IEM_MC_REF_GREG_U8_THREADED(a_pu8Dst, a_iGRegEx) \
420 (a_pu8Dst) = iemGRegRefU8Ex(pVCpu, (a_iGRegEx))
421#undef IEM_MC_REF_GREG_U8
422
423/** Variant of IEM_MC_ADD_GREG_U8_TO_LOCAL with extended (20) register index. */
424#define IEM_MC_ADD_GREG_U8_TO_LOCAL_THREADED(a_u8Value, a_iGRegEx) \
425 do { (a_u8Value) += iemGRegFetchU8Ex(pVCpu, (a_iGRegEx)); } while (0)
426#undef IEM_MC_ADD_GREG_U8_TO_LOCAL
427
428/** Variant of IEM_MC_AND_GREG_U8 with extended (20) register index. */
429#define IEM_MC_AND_GREG_U8_THREADED(a_iGRegEx, a_u8Value) \
430 *iemGRegRefU8Ex(pVCpu, (a_iGRegEx)) &= (a_u8Value)
431#undef IEM_MC_AND_GREG_U8
432
433/** Variant of IEM_MC_OR_GREG_U8 with extended (20) register index. */
434#define IEM_MC_OR_GREG_U8_THREADED(a_iGRegEx, a_u8Value) \
435 *iemGRegRefU8Ex(pVCpu, (a_iGRegEx)) |= (a_u8Value)
436#undef IEM_MC_OR_GREG_U8
437
438/**
439 * Calculates the effective address of a ModR/M memory operand, 16-bit
440 * addressing variant.
441 *
442 * Meant to be used via IEM_MC_CALC_RM_EFF_ADDR_THREADED_ADDR16.
443 *
444 * @returns The effective address.
445 * @param pVCpu The cross context virtual CPU structure of the calling thread.
446 * @param bRm The ModRM byte.
447 * @param u16Disp The displacement byte/word, if any.
448 * RIP relative addressing.
449 */
450static RTGCPTR iemOpHlpCalcRmEffAddrThreadedAddr16(PVMCPUCC pVCpu, uint8_t bRm, uint16_t u16Disp) RT_NOEXCEPT
451{
452 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr16: bRm=%#x u16Disp=%#x\n", bRm, u16Disp));
453 Assert(!IEM_IS_64BIT_CODE(pVCpu));
454
455 /* Handle the disp16 form with no registers first. */
456 if ((bRm & (X86_MODRM_MOD_MASK | X86_MODRM_RM_MASK)) == 6)
457 {
458 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr16: EffAddr=%#010RGv\n", (RTGCPTR)u16Disp));
459 return u16Disp;
460 }
461
462 /* Get the displacment. */
463 /** @todo we can eliminate this step by making u16Disp have this value
464 * already! */
465 uint16_t u16EffAddr;
466 switch ((bRm >> X86_MODRM_MOD_SHIFT) & X86_MODRM_MOD_SMASK)
467 {
468 case 0: u16EffAddr = 0; break;
469 case 1: u16EffAddr = (int16_t)(int8_t)u16Disp; break;
470 case 2: u16EffAddr = u16Disp; break;
471 default: AssertFailedStmt(u16EffAddr = 0);
472 }
473
474 /* Add the base and index registers to the disp. */
475 switch (bRm & X86_MODRM_RM_MASK)
476 {
477 case 0: u16EffAddr += pVCpu->cpum.GstCtx.bx + pVCpu->cpum.GstCtx.si; break;
478 case 1: u16EffAddr += pVCpu->cpum.GstCtx.bx + pVCpu->cpum.GstCtx.di; break;
479 case 2: u16EffAddr += pVCpu->cpum.GstCtx.bp + pVCpu->cpum.GstCtx.si; break;
480 case 3: u16EffAddr += pVCpu->cpum.GstCtx.bp + pVCpu->cpum.GstCtx.di; break;
481 case 4: u16EffAddr += pVCpu->cpum.GstCtx.si; break;
482 case 5: u16EffAddr += pVCpu->cpum.GstCtx.di; break;
483 case 6: u16EffAddr += pVCpu->cpum.GstCtx.bp; break;
484 case 7: u16EffAddr += pVCpu->cpum.GstCtx.bx; break;
485 }
486
487 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr16: EffAddr=%#010RGv\n", (RTGCPTR)u16EffAddr));
488 return u16EffAddr;
489}
490
491
492/**
493 * Calculates the effective address of a ModR/M memory operand, 32-bit
494 * addressing variant.
495 *
496 * Meant to be used via IEM_MC_CALC_RM_EFF_ADDR_THREADED_ADDR32 and
497 * IEM_MC_CALC_RM_EFF_ADDR_THREADED_ADDR32FLAT.
498 *
499 * @returns The effective address.
500 * @param pVCpu The cross context virtual CPU structure of the
501 * calling thread.
502 * @param bRm The ModRM byte.
503 * @param uSibAndRspOffset Two parts:
504 * - The first 8 bits make up the SIB byte.
505 * - The next 8 bits are the fixed RSP/ESP offse
506 * in case of a pop [xSP].
507 * @param u32Disp The displacement byte/dword, if any.
508 */
509static RTGCPTR iemOpHlpCalcRmEffAddrThreadedAddr32(PVMCPUCC pVCpu, uint8_t bRm, uint32_t uSibAndRspOffset,
510 uint32_t u32Disp) RT_NOEXCEPT
511{
512 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr32: bRm=%#x uSibAndRspOffset=%#x u32Disp=%#x\n", bRm, uSibAndRspOffset, u32Disp));
513
514 /* Handle the disp32 form with no registers first. */
515 if ((bRm & (X86_MODRM_MOD_MASK | X86_MODRM_RM_MASK)) == 5)
516 {
517 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr32: EffAddr=%#010RGv\n", (RTGCPTR)u32Disp));
518 return u32Disp;
519 }
520
521 /* Get the register (or SIB) value. */
522 uint32_t u32EffAddr;
523#ifdef _MSC_VER
524 u32EffAddr = 0;/* MSC uninitialized variable analysis is too simple, it seems. */
525#endif
526 switch (bRm & X86_MODRM_RM_MASK)
527 {
528 case 0: u32EffAddr = pVCpu->cpum.GstCtx.eax; break;
529 case 1: u32EffAddr = pVCpu->cpum.GstCtx.ecx; break;
530 case 2: u32EffAddr = pVCpu->cpum.GstCtx.edx; break;
531 case 3: u32EffAddr = pVCpu->cpum.GstCtx.ebx; break;
532 case 4: /* SIB */
533 {
534 /* Get the index and scale it. */
535 switch ((uSibAndRspOffset >> X86_SIB_INDEX_SHIFT) & X86_SIB_INDEX_SMASK)
536 {
537 case 0: u32EffAddr = pVCpu->cpum.GstCtx.eax; break;
538 case 1: u32EffAddr = pVCpu->cpum.GstCtx.ecx; break;
539 case 2: u32EffAddr = pVCpu->cpum.GstCtx.edx; break;
540 case 3: u32EffAddr = pVCpu->cpum.GstCtx.ebx; break;
541 case 4: u32EffAddr = 0; /*none */ break;
542 case 5: u32EffAddr = pVCpu->cpum.GstCtx.ebp; break;
543 case 6: u32EffAddr = pVCpu->cpum.GstCtx.esi; break;
544 case 7: u32EffAddr = pVCpu->cpum.GstCtx.edi; break;
545 }
546 u32EffAddr <<= (uSibAndRspOffset >> X86_SIB_SCALE_SHIFT) & X86_SIB_SCALE_SMASK;
547
548 /* add base */
549 switch (uSibAndRspOffset & X86_SIB_BASE_MASK)
550 {
551 case 0: u32EffAddr += pVCpu->cpum.GstCtx.eax; break;
552 case 1: u32EffAddr += pVCpu->cpum.GstCtx.ecx; break;
553 case 2: u32EffAddr += pVCpu->cpum.GstCtx.edx; break;
554 case 3: u32EffAddr += pVCpu->cpum.GstCtx.ebx; break;
555 case 4:
556 u32EffAddr += pVCpu->cpum.GstCtx.esp;
557 u32EffAddr += uSibAndRspOffset >> 8;
558 break;
559 case 5:
560 if ((bRm & X86_MODRM_MOD_MASK) != 0)
561 u32EffAddr += pVCpu->cpum.GstCtx.ebp;
562 else
563 u32EffAddr += u32Disp;
564 break;
565 case 6: u32EffAddr += pVCpu->cpum.GstCtx.esi; break;
566 case 7: u32EffAddr += pVCpu->cpum.GstCtx.edi; break;
567 }
568 break;
569 }
570 case 5: u32EffAddr = pVCpu->cpum.GstCtx.ebp; break;
571 case 6: u32EffAddr = pVCpu->cpum.GstCtx.esi; break;
572 case 7: u32EffAddr = pVCpu->cpum.GstCtx.edi; break;
573 }
574
575 /* Get and add the displacement. */
576 switch ((bRm >> X86_MODRM_MOD_SHIFT) & X86_MODRM_MOD_SMASK)
577 {
578 case 0: break;
579 case 1: u32EffAddr += (int8_t)u32Disp; break;
580 case 2: u32EffAddr += u32Disp; break;
581 default: AssertFailed();
582 }
583
584 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr32: EffAddr=%#010RGv\n", (RTGCPTR)u32EffAddr));
585 return u32EffAddr;
586}
587
588
589/**
590 * Calculates the effective address of a ModR/M memory operand.
591 *
592 * Meant to be used via IEM_MC_CALC_RM_EFF_ADDR_THREADED_ADDR64.
593 *
594 * @returns The effective address.
595 * @param pVCpu The cross context virtual CPU structure of the
596 * calling thread.
597 * @param bRmEx The ModRM byte but with bit 3 set to REX.B and
598 * bit 4 to REX.X. The two bits are part of the
599 * REG sub-field, which isn't needed in this
600 * function.
601 * @param uSibAndRspOffset Two parts:
602 * - The first 8 bits make up the SIB byte.
603 * - The next 8 bits are the fixed RSP/ESP offset
604 * in case of a pop [xSP].
605 * @param u32Disp The displacement byte/word/dword, if any.
606 * @param cbInstr The size of the fully decoded instruction. Used
607 * for RIP relative addressing.
608 * @todo combine cbInstr and cbImm!
609 */
610static RTGCPTR iemOpHlpCalcRmEffAddrThreadedAddr64(PVMCPUCC pVCpu, uint8_t bRmEx, uint32_t uSibAndRspOffset,
611 uint32_t u32Disp, uint8_t cbInstr) RT_NOEXCEPT
612{
613 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr64: bRmEx=%#x\n", bRmEx));
614 Assert(IEM_IS_64BIT_CODE(pVCpu));
615
616 uint64_t u64EffAddr;
617
618 /* Handle the rip+disp32 form with no registers first. */
619 if ((bRmEx & (X86_MODRM_MOD_MASK | X86_MODRM_RM_MASK)) == 5)
620 {
621 u64EffAddr = (int32_t)u32Disp;
622 u64EffAddr += pVCpu->cpum.GstCtx.rip + cbInstr;
623 }
624 else
625 {
626 /* Get the register (or SIB) value. */
627#ifdef _MSC_VER
628 u64EffAddr = 0; /* MSC uninitialized variable analysis is too simple, it seems. */
629#endif
630 switch (bRmEx & (X86_MODRM_RM_MASK | 0x8)) /* bRmEx[bit 3] = REX.B */
631 {
632 default:
633 case 0: u64EffAddr = pVCpu->cpum.GstCtx.rax; break;
634 case 1: u64EffAddr = pVCpu->cpum.GstCtx.rcx; break;
635 case 2: u64EffAddr = pVCpu->cpum.GstCtx.rdx; break;
636 case 3: u64EffAddr = pVCpu->cpum.GstCtx.rbx; break;
637 case 5: u64EffAddr = pVCpu->cpum.GstCtx.rbp; break;
638 case 6: u64EffAddr = pVCpu->cpum.GstCtx.rsi; break;
639 case 7: u64EffAddr = pVCpu->cpum.GstCtx.rdi; break;
640 case 8: u64EffAddr = pVCpu->cpum.GstCtx.r8; break;
641 case 9: u64EffAddr = pVCpu->cpum.GstCtx.r9; break;
642 case 10: u64EffAddr = pVCpu->cpum.GstCtx.r10; break;
643 case 11: u64EffAddr = pVCpu->cpum.GstCtx.r11; break;
644 case 13: u64EffAddr = pVCpu->cpum.GstCtx.r13; break;
645 case 14: u64EffAddr = pVCpu->cpum.GstCtx.r14; break;
646 case 15: u64EffAddr = pVCpu->cpum.GstCtx.r15; break;
647 /* SIB */
648 case 4:
649 case 12:
650 {
651 /* Get the index and scale it. */
652 switch ( ((uSibAndRspOffset >> X86_SIB_INDEX_SHIFT) & X86_SIB_INDEX_SMASK)
653 | ((bRmEx & 0x10) >> 1)) /* bRmEx[bit 4] = REX.X */
654 {
655 case 0: u64EffAddr = pVCpu->cpum.GstCtx.rax; break;
656 case 1: u64EffAddr = pVCpu->cpum.GstCtx.rcx; break;
657 case 2: u64EffAddr = pVCpu->cpum.GstCtx.rdx; break;
658 case 3: u64EffAddr = pVCpu->cpum.GstCtx.rbx; break;
659 case 4: u64EffAddr = 0; /*none */ break;
660 case 5: u64EffAddr = pVCpu->cpum.GstCtx.rbp; break;
661 case 6: u64EffAddr = pVCpu->cpum.GstCtx.rsi; break;
662 case 7: u64EffAddr = pVCpu->cpum.GstCtx.rdi; break;
663 case 8: u64EffAddr = pVCpu->cpum.GstCtx.r8; break;
664 case 9: u64EffAddr = pVCpu->cpum.GstCtx.r9; break;
665 case 10: u64EffAddr = pVCpu->cpum.GstCtx.r10; break;
666 case 11: u64EffAddr = pVCpu->cpum.GstCtx.r11; break;
667 case 12: u64EffAddr = pVCpu->cpum.GstCtx.r12; break;
668 case 13: u64EffAddr = pVCpu->cpum.GstCtx.r13; break;
669 case 14: u64EffAddr = pVCpu->cpum.GstCtx.r14; break;
670 case 15: u64EffAddr = pVCpu->cpum.GstCtx.r15; break;
671 }
672 u64EffAddr <<= (uSibAndRspOffset >> X86_SIB_SCALE_SHIFT) & X86_SIB_SCALE_SMASK;
673
674 /* add base */
675 switch ((uSibAndRspOffset & X86_SIB_BASE_MASK) | (bRmEx & 0x8)) /* bRmEx[bit 3] = REX.B */
676 {
677 case 0: u64EffAddr += pVCpu->cpum.GstCtx.rax; break;
678 case 1: u64EffAddr += pVCpu->cpum.GstCtx.rcx; break;
679 case 2: u64EffAddr += pVCpu->cpum.GstCtx.rdx; break;
680 case 3: u64EffAddr += pVCpu->cpum.GstCtx.rbx; break;
681 case 4:
682 u64EffAddr += pVCpu->cpum.GstCtx.rsp;
683 u64EffAddr += uSibAndRspOffset >> 8;
684 break;
685 case 6: u64EffAddr += pVCpu->cpum.GstCtx.rsi; break;
686 case 7: u64EffAddr += pVCpu->cpum.GstCtx.rdi; break;
687 case 8: u64EffAddr += pVCpu->cpum.GstCtx.r8; break;
688 case 9: u64EffAddr += pVCpu->cpum.GstCtx.r9; break;
689 case 10: u64EffAddr += pVCpu->cpum.GstCtx.r10; break;
690 case 11: u64EffAddr += pVCpu->cpum.GstCtx.r11; break;
691 case 12: u64EffAddr += pVCpu->cpum.GstCtx.r12; break;
692 case 14: u64EffAddr += pVCpu->cpum.GstCtx.r14; break;
693 case 15: u64EffAddr += pVCpu->cpum.GstCtx.r15; break;
694 /* complicated encodings */
695 case 5:
696 if ((bRmEx & X86_MODRM_MOD_MASK) != 0)
697 u64EffAddr += pVCpu->cpum.GstCtx.rbp;
698 else
699 u64EffAddr += (int32_t)u32Disp;
700 break;
701 case 13:
702 if ((bRmEx & X86_MODRM_MOD_MASK) != 0)
703 u64EffAddr += pVCpu->cpum.GstCtx.r13;
704 else
705 u64EffAddr += (int32_t)u32Disp;
706 break;
707 }
708 break;
709 }
710 }
711
712 /* Get and add the displacement. */
713 switch ((bRmEx >> X86_MODRM_MOD_SHIFT) & X86_MODRM_MOD_SMASK)
714 {
715 case 0: break;
716 case 1: u64EffAddr += (int8_t)u32Disp; break;
717 case 2: u64EffAddr += (int32_t)u32Disp; break;
718 default: AssertFailed();
719 }
720 }
721
722 Log5(("iemOpHlpCalcRmEffAddrThreadedAddr64: EffAddr=%#010RGv\n", u64EffAddr));
723 return u64EffAddr;
724}
725
726
727/*
728 * The threaded functions.
729 */
730#include "IEMThreadedFunctions.cpp.h"
731
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette