VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/IEMAllInstructionsThreadedRecompiler.cpp@ 99863

Last change on this file since 99863 was 99863, checked in by vboxsync, 19 months ago

scm fixes for src\platform\nix\VBoxUtils-nix.h Config.kmk VMM\VMMAll\IEMAllInstructionsThreadedRecompiler.cpp

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/* $Id: IEMAllInstructionsThreadedRecompiler.cpp 99863 2023-05-19 17:34:53Z vboxsync $ */
2/** @file
3 * IEM - Instruction Decoding and Emulation.
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#include <VBox/vmm/iem.h>
37#include <VBox/vmm/cpum.h>
38#include <VBox/vmm/apic.h>
39#include <VBox/vmm/pdm.h>
40#include <VBox/vmm/pgm.h>
41#include <VBox/vmm/iom.h>
42#include <VBox/vmm/em.h>
43#include <VBox/vmm/hm.h>
44#include <VBox/vmm/nem.h>
45#include <VBox/vmm/gim.h>
46#ifdef VBOX_WITH_NESTED_HWVIRT_SVM
47# include <VBox/vmm/em.h>
48# include <VBox/vmm/hm_svm.h>
49#endif
50#ifdef VBOX_WITH_NESTED_HWVIRT_VMX
51# include <VBox/vmm/hmvmxinline.h>
52#endif
53#include <VBox/vmm/tm.h>
54#include <VBox/vmm/dbgf.h>
55#include <VBox/vmm/dbgftrace.h>
56#ifndef TST_IEM_CHECK_MC
57# include "IEMInternal.h"
58#endif
59#include <VBox/vmm/vmcc.h>
60#include <VBox/log.h>
61#include <VBox/err.h>
62#include <VBox/param.h>
63#include <VBox/dis.h>
64#include <VBox/disopcode-x86-amd64.h>
65#include <iprt/asm-math.h>
66#include <iprt/assert.h>
67#include <iprt/string.h>
68#include <iprt/x86.h>
69
70#ifndef TST_IEM_CHECK_MC
71# include "IEMInline.h"
72# include "IEMOpHlp.h"
73# include "IEMMc.h"
74#endif
75
76#include "IEMThreadedFunctions.h"
77
78
79/*********************************************************************************************************************************
80* Structures and Typedefs *
81*********************************************************************************************************************************/
82/**
83 * A call for the threaded call table.
84 */
85typedef struct IEMTHRDEDCALLENTRY
86{
87 /** The function to call (IEMTHREADEDFUNCS). */
88 uint16_t enmFunction;
89 uint16_t uUnused0;
90
91 /** The opcode length. */
92 uint8_t cbOpcode;
93 /** The opcode chunk number.
94 * @note sketches for discontiguous opcode support */
95 uint8_t idxOpcodeChunk;
96 /** The offset into the opcode chunk of this function.
97 * @note sketches for discontiguous opcode support */
98 uint16_t offOpcodeChunk;
99
100 /** Generic parameters. */
101 uint64_t auParams[3];
102} IEMTHRDEDCALLENTRY;
103AssertCompileSize(IEMTHRDEDCALLENTRY, sizeof(uint64_t) * 4);
104/** Pointer to a threaded call entry. */
105typedef IEMTHRDEDCALLENTRY *PIEMTHRDEDCALLENTRY;
106/** Pointer to a const threaded call entry. */
107typedef IEMTHRDEDCALLENTRY const *PCIEMTHRDEDCALLENTRY;
108
109/** @name IEMTB_F_XXX - Translation block flags.
110 * @{ */
111#define IEMTB_F_MODE_MASK UINT32_C(0x00000007)
112#define IEMTB_F_MODE_X86_16BIT UINT32_C(0x00000001)
113#define IEMTB_F_MODE_X86_32BIT UINT32_C(0x00000002)
114#define IEMTB_F_MODE_X86_32BIT_FLAT UINT32_C(0x00000003)
115#define IEMTB_F_MODE_X86_64BIT UINT32_C(0x00000004)
116
117#define IEMTB_F_COMPILING RT_BIT_32(0)
118#define IEMTB_F_NATIVE RT_BIT_32(1)
119/** @} */
120
121/**
122 * Translation block.
123 */
124typedef struct IEMTB
125{
126 /** Next block with the same hash table entry. */
127 PIEMTB volatile pNext;
128 /** List on the local VCPU for blocks. */
129 RTLISTNODE LocalList;
130
131 /** @name What uniquely identifies the block.
132 * @{ */
133 RTGCPHYS GCPhysPc;
134 uint64_t uPc;
135 uint32_t fFlags;
136 union
137 {
138 struct
139 {
140 /** The CS base. */
141 uint32_t uCsBase;
142 /** The CS limit (UINT32_MAX for 64-bit code). */
143 uint32_t uCsLimit;
144 /** The CS selector value. */
145 uint16_t CS;
146 /**< Relevant X86DESCATTR_XXX bits. */
147 uint16_t fAttr;
148 } x86;
149 };
150 /** @} */
151
152 /** Number of bytes of opcodes covered by this block.
153 * @todo Support discontiguous chunks of opcodes in same block, though maybe
154 * restrict to the initial page or smth. */
155 uint32_t cbPC;
156
157 union
158 {
159 struct
160 {
161 /** Number of calls in paCalls. */
162 uint32_t cCalls;
163 /** Number of calls allocated. */
164 uint32_t cAllocated;
165 /** The call sequence table. */
166 PIEMTHRDEDCALLENTRY paCalls;
167 } Thrd;
168 };
169
170
171} IEMTB;
172
173
174/*********************************************************************************************************************************
175* Defined Constants And Macros *
176*********************************************************************************************************************************/
177#define g_apfnOneByteMap g_apfnIemThreadedRecompilerOneByteMap
178
179
180#undef IEM_MC_CALC_RM_EFF_ADDR
181#ifndef IEM_WITH_SETJMP
182# define IEM_MC_CALC_RM_EFF_ADDR(a_GCPtrEff, bRm, cbImm) \
183 uint64_t uEffAddrInfo; \
184 IEM_MC_RETURN_ON_FAILURE(iemOpHlpCalcRmEffAddrJmpEx(pVCpu, (bRm), (cbImm), &(a_GCPtrEff), &uEffAddrInfo))
185#else
186# define IEM_MC_CALC_RM_EFF_ADDR(a_GCPtrEff, bRm, cbImm) \
187 uint64_t uEffAddrInfo; \
188 ((a_GCPtrEff) = iemOpHlpCalcRmEffAddrJmpEx(pVCpu, (bRm), (cbImm), &uEffAddrInfo))
189#endif
190
191#define IEM_MC2_EMIT_CALL_1(a_enmFunction, a_uArg0) do { \
192 IEMTHREADEDFUNCS const enmFunctionCheck = a_enmFunction; RT_NOREF(enmFunctionCheck); \
193 uint64_t const uArg0Check = (a_uArg0); RT_NOREF(uArg0Check); \
194 \
195 PIEMTB const pTb = pVCpu->iem.s.pCurTbR3; \
196 PIEMTHRDEDCALLENTRY const pCall = &pTb->Thrd.paCalls[pTb->Thrd.cCalls++]; \
197 pCall->enmFunction = a_enmFunction; \
198 pCall->cbOpcode = IEM_GET_INSTR_LEN(pVCpu); \
199 pCall->auParams[0] = a_uArg0; \
200 pCall->auParams[1] = 0; \
201 pCall->auParams[2] = 0; \
202 } while (0)
203#define IEM_MC2_EMIT_CALL_2(a_enmFunction, a_uArg0, a_uArg1) do { \
204 IEMTHREADEDFUNCS const enmFunctionCheck = a_enmFunction; RT_NOREF(enmFunctionCheck); \
205 uint64_t const uArg0Check = (a_uArg0); RT_NOREF(uArg0Check); \
206 uint64_t const uArg1Check = (a_uArg1); RT_NOREF(uArg1Check); \
207 \
208 PIEMTB const pTb = pVCpu->iem.s.pCurTbR3; \
209 PIEMTHRDEDCALLENTRY const pCall = &pTb->Thrd.paCalls[pTb->Thrd.cCalls++]; \
210 pCall->enmFunction = a_enmFunction; \
211 pCall->cbOpcode = IEM_GET_INSTR_LEN(pVCpu); \
212 pCall->auParams[0] = a_uArg0; \
213 pCall->auParams[1] = a_uArg1; \
214 pCall->auParams[2] = 0; \
215 } while (0)
216#define IEM_MC2_EMIT_CALL_3(a_enmFunction, a_uArg0, a_uArg1, a_uArg2) do { \
217 IEMTHREADEDFUNCS const enmFunctionCheck = a_enmFunction; RT_NOREF(enmFunctionCheck); \
218 uint64_t const uArg0Check = (a_uArg0); RT_NOREF(uArg0Check); \
219 uint64_t const uArg1Check = (a_uArg1); RT_NOREF(uArg1Check); \
220 uint64_t const uArg2Check = (a_uArg2); RT_NOREF(uArg2Check); \
221 \
222 PIEMTB const pTb = pVCpu->iem.s.pCurTbR3; \
223 PIEMTHRDEDCALLENTRY const pCall = &pTb->Thrd.paCalls[pTb->Thrd.cCalls++]; \
224 pCall->enmFunction = a_enmFunction; \
225 pCall->cbOpcode = IEM_GET_INSTR_LEN(pVCpu); \
226 pCall->auParams[0] = a_uArg0; \
227 pCall->auParams[1] = a_uArg1; \
228 pCall->auParams[2] = a_uArg2; \
229 } while (0)
230
231
232/*
233 * IEM_MC_DEFER_TO_CIMPL_0 is easily wrapped up.
234 *
235 * Doing so will also take care of IEMOP_RAISE_DIVIDE_ERROR, IEMOP_RAISE_INVALID_LOCK_PREFIX,
236 * IEMOP_RAISE_INVALID_OPCODE and their users.
237 */
238#undef IEM_MC_DEFER_TO_CIMPL_0
239#define IEM_MC_DEFER_TO_CIMPL_0(a_pfnCImpl) iemThreadedRecompilerMcDeferToCImpl0(pVCpu, a_pfnCImpl)
240
241typedef IEM_CIMPL_DECL_TYPE_0(FNIEMCIMPL0);
242typedef FNIEMCIMPL0 *PFNIEMCIMPL0;
243
244DECLINLINE(VBOXSTRICTRC) iemThreadedRecompilerMcDeferToCImpl0(PVMCPUCC pVCpu, PFNIEMCIMPL0 pfnCImpl)
245{
246 return pfnCImpl(pVCpu, IEM_GET_INSTR_LEN(pVCpu));
247}
248
249/** @todo deal with IEM_MC_DEFER_TO_CIMPL_1, IEM_MC_DEFER_TO_CIMPL_2 and
250 * IEM_MC_DEFER_TO_CIMPL_3 as well. */
251
252/*
253 * Include the "annotated" IEMAllInstructions*.cpp.h files.
254 */
255#include "IEMThreadedInstructions.cpp.h"
256
257
258
259/*
260 * Real code.
261 */
262
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