1 | /* $Id: IEMN8veRecompiler.h 106622 2024-10-23 13:33:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IEM - Interpreted Execution Manager - Native Recompiler Internals.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 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 | #ifndef VMM_INCLUDED_SRC_include_IEMN8veRecompiler_h
|
---|
29 | #define VMM_INCLUDED_SRC_include_IEMN8veRecompiler_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 |
|
---|
35 | /** @defgroup grp_iem_n8ve_re Native Recompiler Internals.
|
---|
36 | * @ingroup grp_iem_int
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | #include <iprt/assertcompile.h> /* for RT_IN_ASSEMBLER mode */
|
---|
41 |
|
---|
42 | /** @def IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
43 | * Enables generating internal debug info for better TB disassembly dumping. */
|
---|
44 | #if defined(DEBUG) || defined(DOXYGEN_RUNNING) || 0
|
---|
45 | # define IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | /** @def IEMNATIVE_WITH_LIVENESS_ANALYSIS
|
---|
49 | * Enables liveness analysis. */
|
---|
50 | #if 1 || defined(DOXYGEN_RUNNING)
|
---|
51 | # define IEMNATIVE_WITH_LIVENESS_ANALYSIS
|
---|
52 | #endif
|
---|
53 |
|
---|
54 | /** @def IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
55 | * Enables skipping EFLAGS calculations/updating based on liveness info. */
|
---|
56 | #if defined(IEMNATIVE_WITH_LIVENESS_ANALYSIS) || defined(DOXYGEN_RUNNING)
|
---|
57 | # define IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | /** @def IEMNATIVE_STRICT_EFLAGS_SKIPPING
|
---|
61 | * Enables strict consistency checks around EFLAGS skipping.
|
---|
62 | * @note Only defined when IEMNATIVE_WITH_EFLAGS_SKIPPING is also defined. */
|
---|
63 | #ifdef IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
64 | # ifdef VBOX_STRICT
|
---|
65 | # define IEMNATIVE_STRICT_EFLAGS_SKIPPING
|
---|
66 | # endif
|
---|
67 | #elif defined(DOXYGEN_RUNNING)
|
---|
68 | # define IEMNATIVE_STRICT_EFLAGS_SKIPPING
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | /** @def IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
72 | * Enables delaying EFLAGS calculations/updating to conditional code paths
|
---|
73 | * that are (hopefully) not taken so frequently.
|
---|
74 | *
|
---|
75 | * This can only help with case where there is an conditional
|
---|
76 | * call/exception/tbexit that needs the flag, but in the default code stream the
|
---|
77 | * flag will be clobbered. Useful for TlbMiss scenarios and sequences of memory
|
---|
78 | * based instructions clobbering status flags. */
|
---|
79 | #if defined(IEMNATIVE_WITH_LIVENESS_ANALYSIS) || defined(DOXYGEN_RUNNING)
|
---|
80 | # if 1 || defined(DOXYGEN_RUNNING)
|
---|
81 | # define IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
82 | # endif
|
---|
83 | #endif
|
---|
84 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
85 | # ifndef IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
86 | # error "IEMNATIVE_WITH_EFLAGS_POSTPONING requires IEMNATIVE_WITH_EFLAGS_SKIPPING at present"
|
---|
87 | # endif
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | /** @def IEMLIVENESS_EXTENDED_LAYOUT
|
---|
91 | * Enables the extended liveness data layout. */
|
---|
92 | #if defined(IEMNATIVE_WITH_EFLAGS_POSTPONING) || defined(DOXYGEN_RUNNING) || 0
|
---|
93 | # define IEMLIVENESS_EXTENDED_LAYOUT
|
---|
94 | #endif
|
---|
95 |
|
---|
96 |
|
---|
97 | #ifdef VBOX_WITH_STATISTICS
|
---|
98 | /** Always count instructions for now. */
|
---|
99 | # define IEMNATIVE_WITH_INSTRUCTION_COUNTING
|
---|
100 | #endif
|
---|
101 |
|
---|
102 |
|
---|
103 | /** @name Stack Frame Layout
|
---|
104 | *
|
---|
105 | * @{ */
|
---|
106 | /** The size of the area for stack variables and spills and stuff.
|
---|
107 | * @note This limit is duplicated in the python script(s). We add 0x40 for
|
---|
108 | * alignment padding. */
|
---|
109 | #define IEMNATIVE_FRAME_VAR_SIZE (0xc0 + 0x40)
|
---|
110 | /** Number of 64-bit variable slots (0x100 / 8 = 32. */
|
---|
111 | #define IEMNATIVE_FRAME_VAR_SLOTS (IEMNATIVE_FRAME_VAR_SIZE / 8)
|
---|
112 | AssertCompile(IEMNATIVE_FRAME_VAR_SLOTS == 32);
|
---|
113 |
|
---|
114 | #ifdef RT_ARCH_AMD64
|
---|
115 | /** An stack alignment adjustment (between non-volatile register pushes and
|
---|
116 | * the stack variable area, so the latter better aligned). */
|
---|
117 | # define IEMNATIVE_FRAME_ALIGN_SIZE 8
|
---|
118 |
|
---|
119 | /** Number of stack arguments slots for calls made from the frame. */
|
---|
120 | # ifdef RT_OS_WINDOWS
|
---|
121 | # define IEMNATIVE_FRAME_STACK_ARG_COUNT 4
|
---|
122 | # else
|
---|
123 | # define IEMNATIVE_FRAME_STACK_ARG_COUNT 2
|
---|
124 | # endif
|
---|
125 | /** Number of any shadow arguments (spill area) for calls we make. */
|
---|
126 | # ifdef RT_OS_WINDOWS
|
---|
127 | # define IEMNATIVE_FRAME_SHADOW_ARG_COUNT 4
|
---|
128 | # else
|
---|
129 | # define IEMNATIVE_FRAME_SHADOW_ARG_COUNT 0
|
---|
130 | # endif
|
---|
131 |
|
---|
132 | /** Frame pointer (RBP) relative offset of the last push. */
|
---|
133 | # ifdef RT_OS_WINDOWS
|
---|
134 | # define IEMNATIVE_FP_OFF_LAST_PUSH (7 * -8)
|
---|
135 | # else
|
---|
136 | # define IEMNATIVE_FP_OFF_LAST_PUSH (5 * -8)
|
---|
137 | # endif
|
---|
138 | /** Frame pointer (RBP) relative offset of the stack variable area (the lowest
|
---|
139 | * address for it). */
|
---|
140 | # define IEMNATIVE_FP_OFF_STACK_VARS (IEMNATIVE_FP_OFF_LAST_PUSH - IEMNATIVE_FRAME_ALIGN_SIZE - IEMNATIVE_FRAME_VAR_SIZE)
|
---|
141 | /** Frame pointer (RBP) relative offset of the first stack argument for calls. */
|
---|
142 | # define IEMNATIVE_FP_OFF_STACK_ARG0 (IEMNATIVE_FP_OFF_STACK_VARS - IEMNATIVE_FRAME_STACK_ARG_COUNT * 8)
|
---|
143 | /** Frame pointer (RBP) relative offset of the second stack argument for calls. */
|
---|
144 | # define IEMNATIVE_FP_OFF_STACK_ARG1 (IEMNATIVE_FP_OFF_STACK_ARG0 + 8)
|
---|
145 | # ifdef RT_OS_WINDOWS
|
---|
146 | /** Frame pointer (RBP) relative offset of the third stack argument for calls. */
|
---|
147 | # define IEMNATIVE_FP_OFF_STACK_ARG2 (IEMNATIVE_FP_OFF_STACK_ARG0 + 16)
|
---|
148 | /** Frame pointer (RBP) relative offset of the fourth stack argument for calls. */
|
---|
149 | # define IEMNATIVE_FP_OFF_STACK_ARG3 (IEMNATIVE_FP_OFF_STACK_ARG0 + 24)
|
---|
150 | # endif
|
---|
151 |
|
---|
152 | # ifdef RT_OS_WINDOWS
|
---|
153 | /** Frame pointer (RBP) relative offset of the first incoming shadow argument. */
|
---|
154 | # define IEMNATIVE_FP_OFF_IN_SHADOW_ARG0 (16)
|
---|
155 | /** Frame pointer (RBP) relative offset of the second incoming shadow argument. */
|
---|
156 | # define IEMNATIVE_FP_OFF_IN_SHADOW_ARG1 (24)
|
---|
157 | /** Frame pointer (RBP) relative offset of the third incoming shadow argument. */
|
---|
158 | # define IEMNATIVE_FP_OFF_IN_SHADOW_ARG2 (32)
|
---|
159 | /** Frame pointer (RBP) relative offset of the fourth incoming shadow argument. */
|
---|
160 | # define IEMNATIVE_FP_OFF_IN_SHADOW_ARG3 (40)
|
---|
161 | # endif
|
---|
162 |
|
---|
163 | #elif RT_ARCH_ARM64
|
---|
164 | /** No alignment padding needed for arm64. */
|
---|
165 | # define IEMNATIVE_FRAME_ALIGN_SIZE 0
|
---|
166 | /** No stack argument slots, got 8 registers for arguments will suffice. */
|
---|
167 | # define IEMNATIVE_FRAME_STACK_ARG_COUNT 0
|
---|
168 | /** There are no argument spill area. */
|
---|
169 | # define IEMNATIVE_FRAME_SHADOW_ARG_COUNT 0
|
---|
170 |
|
---|
171 | /** Number of saved registers at the top of our stack frame.
|
---|
172 | * This includes the return address and old frame pointer, so x19 thru x30. */
|
---|
173 | # define IEMNATIVE_FRAME_SAVE_REG_COUNT (12)
|
---|
174 | /** The size of the save registered (IEMNATIVE_FRAME_SAVE_REG_COUNT). */
|
---|
175 | # define IEMNATIVE_FRAME_SAVE_REG_SIZE (IEMNATIVE_FRAME_SAVE_REG_COUNT * 8)
|
---|
176 |
|
---|
177 | /** Frame pointer (BP) relative offset of the last push. */
|
---|
178 | # define IEMNATIVE_FP_OFF_LAST_PUSH (10 * -8)
|
---|
179 |
|
---|
180 | /** Frame pointer (BP) relative offset of the stack variable area (the lowest
|
---|
181 | * address for it). */
|
---|
182 | # define IEMNATIVE_FP_OFF_STACK_VARS (IEMNATIVE_FP_OFF_LAST_PUSH - IEMNATIVE_FRAME_ALIGN_SIZE - IEMNATIVE_FRAME_VAR_SIZE)
|
---|
183 |
|
---|
184 | #else
|
---|
185 | # error "port me"
|
---|
186 | #endif
|
---|
187 | /** @} */
|
---|
188 |
|
---|
189 |
|
---|
190 | /** @name Fixed Register Allocation(s)
|
---|
191 | * @{ */
|
---|
192 | /** @def IEMNATIVE_REG_FIXED_PVMCPU
|
---|
193 | * The number of the register holding the pVCpu pointer. */
|
---|
194 | /** @def IEMNATIVE_REG_FIXED_PCPUMCTX
|
---|
195 | * The number of the register holding the &pVCpu->cpum.GstCtx pointer.
|
---|
196 | * @note This not available on AMD64, only ARM64. */
|
---|
197 | /** @def IEMNATIVE_REG_FIXED_TMP0
|
---|
198 | * Dedicated temporary register.
|
---|
199 | * @note This has extremely short lifetime, must be used with great care to make
|
---|
200 | * sure any calling code or code being called is making use of it.
|
---|
201 | * It will definitely not survive a call or anything of that nature.
|
---|
202 | * @todo replace this by a register allocator and content tracker. */
|
---|
203 | /** @def IEMNATIVE_REG_FIXED_MASK
|
---|
204 | * Mask GPRs with fixes assignments, either by us or dictated by the CPU/OS
|
---|
205 | * architecture. */
|
---|
206 | /** @def IEMNATIVE_SIMD_REG_FIXED_TMP0
|
---|
207 | * Mask SIMD registers with fixes assignments, either by us or dictated by the CPU/OS
|
---|
208 | * architecture. */
|
---|
209 | /** @def IEMNATIVE_SIMD_REG_FIXED_TMP0
|
---|
210 | * Dedicated temporary SIMD register. */
|
---|
211 | #if defined(RT_ARCH_ARM64) || defined(DOXYGEN_RUNNING) /* arm64 goes first because of doxygen */
|
---|
212 | # define IEMNATIVE_REG_FIXED_PVMCPU ARMV8_A64_REG_X28
|
---|
213 | # define IEMNATIVE_REG_FIXED_PVMCPU_ASM RT_CONCAT(x,IEMNATIVE_REG_FIXED_PVMCPU)
|
---|
214 | # define IEMNATIVE_REG_FIXED_PCPUMCTX ARMV8_A64_REG_X27
|
---|
215 | # define IEMNATIVE_REG_FIXED_PCPUMCTX_ASM RT_CONCAT(x,IEMNATIVE_REG_FIXED_PCPUMCTX)
|
---|
216 | # define IEMNATIVE_REG_FIXED_TMP0 ARMV8_A64_REG_X15
|
---|
217 | # if defined(IEMNATIVE_WITH_DELAYED_PC_UPDATING) && 0 /* debug the updating with a shadow RIP. */
|
---|
218 | # define IEMNATIVE_REG_FIXED_TMP1 ARMV8_A64_REG_X16
|
---|
219 | # define IEMNATIVE_REG_FIXED_PC_DBG ARMV8_A64_REG_X26
|
---|
220 | # define IEMNATIVE_REG_FIXED_MASK_ADD ( RT_BIT_32(IEMNATIVE_REG_FIXED_TMP1) \
|
---|
221 | | RT_BIT_32(IEMNATIVE_REG_FIXED_PC_DBG))
|
---|
222 | # else
|
---|
223 | # define IEMNATIVE_REG_FIXED_MASK_ADD 0
|
---|
224 | # endif
|
---|
225 | # define IEMNATIVE_REG_FIXED_MASK ( RT_BIT_32(ARMV8_A64_REG_SP) \
|
---|
226 | | RT_BIT_32(ARMV8_A64_REG_LR) \
|
---|
227 | | RT_BIT_32(ARMV8_A64_REG_BP) \
|
---|
228 | | RT_BIT_32(IEMNATIVE_REG_FIXED_PVMCPU) \
|
---|
229 | | RT_BIT_32(IEMNATIVE_REG_FIXED_PCPUMCTX) \
|
---|
230 | | RT_BIT_32(ARMV8_A64_REG_X18) \
|
---|
231 | | RT_BIT_32(IEMNATIVE_REG_FIXED_TMP0) \
|
---|
232 | | IEMNATIVE_REG_FIXED_MASK_ADD)
|
---|
233 |
|
---|
234 | # define IEMNATIVE_SIMD_REG_FIXED_TMP0 ARMV8_A64_REG_Q30
|
---|
235 | # if defined(IEMNATIVE_WITH_SIMD_REG_ACCESS_ALL_REGISTERS)
|
---|
236 | # define IEMNATIVE_SIMD_REG_FIXED_MASK RT_BIT_32(ARMV8_A64_REG_Q30)
|
---|
237 | # else
|
---|
238 | /** @note
|
---|
239 | * ARM64 has 32 registers, but they are only 128-bit wide. So, in order to
|
---|
240 | * support emulating 256-bit registers we pair two real registers statically to
|
---|
241 | * one virtual for now, leaving us with only 16 256-bit registers. We always
|
---|
242 | * pair v0 with v1, v2 with v3, etc. so we mark the higher register as fixed and
|
---|
243 | * the register allocator assumes that it will be always free when the lower is
|
---|
244 | * picked.
|
---|
245 | *
|
---|
246 | * Also ARM64 declares the low 64-bit of v8-v15 as callee saved, so we don't
|
---|
247 | * touch them in order to avoid having to save and restore them in the
|
---|
248 | * prologue/epilogue.
|
---|
249 | */
|
---|
250 | # define IEMNATIVE_SIMD_REG_FIXED_MASK ( UINT32_C(0xff00) \
|
---|
251 | | RT_BIT_32(ARMV8_A64_REG_Q31) \
|
---|
252 | | RT_BIT_32(ARMV8_A64_REG_Q30) \
|
---|
253 | | RT_BIT_32(ARMV8_A64_REG_Q29) \
|
---|
254 | | RT_BIT_32(ARMV8_A64_REG_Q27) \
|
---|
255 | | RT_BIT_32(ARMV8_A64_REG_Q25) \
|
---|
256 | | RT_BIT_32(ARMV8_A64_REG_Q23) \
|
---|
257 | | RT_BIT_32(ARMV8_A64_REG_Q21) \
|
---|
258 | | RT_BIT_32(ARMV8_A64_REG_Q19) \
|
---|
259 | | RT_BIT_32(ARMV8_A64_REG_Q17) \
|
---|
260 | | RT_BIT_32(ARMV8_A64_REG_Q15) \
|
---|
261 | | RT_BIT_32(ARMV8_A64_REG_Q13) \
|
---|
262 | | RT_BIT_32(ARMV8_A64_REG_Q11) \
|
---|
263 | | RT_BIT_32(ARMV8_A64_REG_Q9) \
|
---|
264 | | RT_BIT_32(ARMV8_A64_REG_Q7) \
|
---|
265 | | RT_BIT_32(ARMV8_A64_REG_Q5) \
|
---|
266 | | RT_BIT_32(ARMV8_A64_REG_Q3) \
|
---|
267 | | RT_BIT_32(ARMV8_A64_REG_Q1))
|
---|
268 | # endif
|
---|
269 |
|
---|
270 | #elif defined(RT_ARCH_AMD64)
|
---|
271 | # define IEMNATIVE_REG_FIXED_PVMCPU X86_GREG_xBX
|
---|
272 | # define IEMNATIVE_REG_FIXED_PVMCPU_ASM xBX
|
---|
273 | # define IEMNATIVE_REG_FIXED_TMP0 X86_GREG_x11
|
---|
274 | # define IEMNATIVE_REG_FIXED_MASK ( RT_BIT_32(IEMNATIVE_REG_FIXED_PVMCPU) \
|
---|
275 | | RT_BIT_32(IEMNATIVE_REG_FIXED_TMP0) \
|
---|
276 | | RT_BIT_32(X86_GREG_xSP) \
|
---|
277 | | RT_BIT_32(X86_GREG_xBP) )
|
---|
278 |
|
---|
279 | # define IEMNATIVE_SIMD_REG_FIXED_TMP0 5 /* xmm5/ymm5 */
|
---|
280 | # ifndef IEMNATIVE_WITH_SIMD_REG_ACCESS_ALL_REGISTERS
|
---|
281 | # ifndef _MSC_VER
|
---|
282 | # define IEMNATIVE_WITH_SIMD_REG_ACCESS_ALL_REGISTERS
|
---|
283 | # endif
|
---|
284 | # endif
|
---|
285 | # ifdef IEMNATIVE_WITH_SIMD_REG_ACCESS_ALL_REGISTERS
|
---|
286 | # define IEMNATIVE_SIMD_REG_FIXED_MASK (RT_BIT_32(IEMNATIVE_SIMD_REG_FIXED_TMP0))
|
---|
287 | # else
|
---|
288 | /** @note On Windows/AMD64 xmm6 through xmm15 are marked as callee saved. */
|
---|
289 | # define IEMNATIVE_SIMD_REG_FIXED_MASK ( UINT32_C(0xffc0) \
|
---|
290 | | RT_BIT_32(IEMNATIVE_SIMD_REG_FIXED_TMP0))
|
---|
291 | # endif
|
---|
292 |
|
---|
293 | #else
|
---|
294 | # error "port me"
|
---|
295 | #endif
|
---|
296 | /** @} */
|
---|
297 |
|
---|
298 | /** @name Call related registers.
|
---|
299 | * @{ */
|
---|
300 | /** @def IEMNATIVE_CALL_RET_GREG
|
---|
301 | * The return value register. */
|
---|
302 | /** @def IEMNATIVE_CALL_ARG_GREG_COUNT
|
---|
303 | * Number of arguments in registers. */
|
---|
304 | /** @def IEMNATIVE_CALL_ARG0_GREG
|
---|
305 | * The general purpose register carrying argument \#0. */
|
---|
306 | /** @def IEMNATIVE_CALL_ARG1_GREG
|
---|
307 | * The general purpose register carrying argument \#1. */
|
---|
308 | /** @def IEMNATIVE_CALL_ARG2_GREG
|
---|
309 | * The general purpose register carrying argument \#2. */
|
---|
310 | /** @def IEMNATIVE_CALL_ARG3_GREG
|
---|
311 | * The general purpose register carrying argument \#3. */
|
---|
312 | /** @def IEMNATIVE_CALL_VOLATILE_GREG_MASK
|
---|
313 | * Mask of registers the callee will not save and may trash. */
|
---|
314 | #ifdef RT_ARCH_AMD64
|
---|
315 | # define IEMNATIVE_CALL_RET_GREG X86_GREG_xAX
|
---|
316 |
|
---|
317 | # ifdef RT_OS_WINDOWS
|
---|
318 | # define IEMNATIVE_CALL_ARG_GREG_COUNT 4
|
---|
319 | # define IEMNATIVE_CALL_ARG0_GREG X86_GREG_xCX
|
---|
320 | # define IEMNATIVE_CALL_ARG1_GREG X86_GREG_xDX
|
---|
321 | # define IEMNATIVE_CALL_ARG2_GREG X86_GREG_x8
|
---|
322 | # define IEMNATIVE_CALL_ARG3_GREG X86_GREG_x9
|
---|
323 | # define IEMNATIVE_CALL_ARGS_GREG_MASK ( RT_BIT_32(IEMNATIVE_CALL_ARG0_GREG) \
|
---|
324 | | RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) \
|
---|
325 | | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) \
|
---|
326 | | RT_BIT_32(IEMNATIVE_CALL_ARG3_GREG) )
|
---|
327 | # define IEMNATIVE_CALL_VOLATILE_GREG_MASK ( RT_BIT_32(X86_GREG_xAX) \
|
---|
328 | | RT_BIT_32(X86_GREG_xCX) \
|
---|
329 | | RT_BIT_32(X86_GREG_xDX) \
|
---|
330 | | RT_BIT_32(X86_GREG_x8) \
|
---|
331 | | RT_BIT_32(X86_GREG_x9) \
|
---|
332 | | RT_BIT_32(X86_GREG_x10) \
|
---|
333 | | RT_BIT_32(X86_GREG_x11) )
|
---|
334 | /* xmm0 - xmm5 are marked as volatile. */
|
---|
335 | # define IEMNATIVE_CALL_VOLATILE_SIMD_REG_MASK (UINT32_C(0x3f))
|
---|
336 |
|
---|
337 | # else /* !RT_OS_WINDOWS */
|
---|
338 | # define IEMNATIVE_CALL_ARG_GREG_COUNT 6
|
---|
339 | # define IEMNATIVE_CALL_ARG0_GREG X86_GREG_xDI
|
---|
340 | # define IEMNATIVE_CALL_ARG1_GREG X86_GREG_xSI
|
---|
341 | # define IEMNATIVE_CALL_ARG2_GREG X86_GREG_xDX
|
---|
342 | # define IEMNATIVE_CALL_ARG3_GREG X86_GREG_xCX
|
---|
343 | # define IEMNATIVE_CALL_ARG4_GREG X86_GREG_x8
|
---|
344 | # define IEMNATIVE_CALL_ARG5_GREG X86_GREG_x9
|
---|
345 | # define IEMNATIVE_CALL_ARGS_GREG_MASK ( RT_BIT_32(IEMNATIVE_CALL_ARG0_GREG) \
|
---|
346 | | RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) \
|
---|
347 | | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) \
|
---|
348 | | RT_BIT_32(IEMNATIVE_CALL_ARG3_GREG) \
|
---|
349 | | RT_BIT_32(IEMNATIVE_CALL_ARG4_GREG) \
|
---|
350 | | RT_BIT_32(IEMNATIVE_CALL_ARG5_GREG) )
|
---|
351 | # define IEMNATIVE_CALL_VOLATILE_GREG_MASK ( RT_BIT_32(X86_GREG_xAX) \
|
---|
352 | | RT_BIT_32(X86_GREG_xCX) \
|
---|
353 | | RT_BIT_32(X86_GREG_xDX) \
|
---|
354 | | RT_BIT_32(X86_GREG_xDI) \
|
---|
355 | | RT_BIT_32(X86_GREG_xSI) \
|
---|
356 | | RT_BIT_32(X86_GREG_x8) \
|
---|
357 | | RT_BIT_32(X86_GREG_x9) \
|
---|
358 | | RT_BIT_32(X86_GREG_x10) \
|
---|
359 | | RT_BIT_32(X86_GREG_x11) )
|
---|
360 | /* xmm0 - xmm15 are marked as volatile. */
|
---|
361 | # define IEMNATIVE_CALL_VOLATILE_SIMD_REG_MASK (UINT32_C(0xffff))
|
---|
362 | # endif /* !RT_OS_WINDOWS */
|
---|
363 |
|
---|
364 | #elif defined(RT_ARCH_ARM64)
|
---|
365 | # define IEMNATIVE_CALL_RET_GREG ARMV8_A64_REG_X0
|
---|
366 | # define IEMNATIVE_CALL_ARG_GREG_COUNT 8
|
---|
367 | # define IEMNATIVE_CALL_ARG0_GREG ARMV8_A64_REG_X0
|
---|
368 | # define IEMNATIVE_CALL_ARG1_GREG ARMV8_A64_REG_X1
|
---|
369 | # define IEMNATIVE_CALL_ARG2_GREG ARMV8_A64_REG_X2
|
---|
370 | # define IEMNATIVE_CALL_ARG3_GREG ARMV8_A64_REG_X3
|
---|
371 | # define IEMNATIVE_CALL_ARG4_GREG ARMV8_A64_REG_X4
|
---|
372 | # define IEMNATIVE_CALL_ARG5_GREG ARMV8_A64_REG_X5
|
---|
373 | # define IEMNATIVE_CALL_ARG6_GREG ARMV8_A64_REG_X6
|
---|
374 | # define IEMNATIVE_CALL_ARG7_GREG ARMV8_A64_REG_X7
|
---|
375 | # define IEMNATIVE_CALL_ARGS_GREG_MASK ( RT_BIT_32(ARMV8_A64_REG_X0) \
|
---|
376 | | RT_BIT_32(ARMV8_A64_REG_X1) \
|
---|
377 | | RT_BIT_32(ARMV8_A64_REG_X2) \
|
---|
378 | | RT_BIT_32(ARMV8_A64_REG_X3) \
|
---|
379 | | RT_BIT_32(ARMV8_A64_REG_X4) \
|
---|
380 | | RT_BIT_32(ARMV8_A64_REG_X5) \
|
---|
381 | | RT_BIT_32(ARMV8_A64_REG_X6) \
|
---|
382 | | RT_BIT_32(ARMV8_A64_REG_X7) )
|
---|
383 | # define IEMNATIVE_CALL_VOLATILE_GREG_MASK ( RT_BIT_32(ARMV8_A64_REG_X0) \
|
---|
384 | | RT_BIT_32(ARMV8_A64_REG_X1) \
|
---|
385 | | RT_BIT_32(ARMV8_A64_REG_X2) \
|
---|
386 | | RT_BIT_32(ARMV8_A64_REG_X3) \
|
---|
387 | | RT_BIT_32(ARMV8_A64_REG_X4) \
|
---|
388 | | RT_BIT_32(ARMV8_A64_REG_X5) \
|
---|
389 | | RT_BIT_32(ARMV8_A64_REG_X6) \
|
---|
390 | | RT_BIT_32(ARMV8_A64_REG_X7) \
|
---|
391 | | RT_BIT_32(ARMV8_A64_REG_X8) \
|
---|
392 | | RT_BIT_32(ARMV8_A64_REG_X9) \
|
---|
393 | | RT_BIT_32(ARMV8_A64_REG_X10) \
|
---|
394 | | RT_BIT_32(ARMV8_A64_REG_X11) \
|
---|
395 | | RT_BIT_32(ARMV8_A64_REG_X12) \
|
---|
396 | | RT_BIT_32(ARMV8_A64_REG_X13) \
|
---|
397 | | RT_BIT_32(ARMV8_A64_REG_X14) \
|
---|
398 | | RT_BIT_32(ARMV8_A64_REG_X15) \
|
---|
399 | | RT_BIT_32(ARMV8_A64_REG_X16) \
|
---|
400 | | RT_BIT_32(ARMV8_A64_REG_X17) )
|
---|
401 | /* The low 64 bits of v8 - v15 marked as callee saved but the rest is volatile,
|
---|
402 | * so to simplify our life a bit we just mark everything as volatile. */
|
---|
403 | # define IEMNATIVE_CALL_VOLATILE_SIMD_REG_MASK UINT32_C(0xffffffff)
|
---|
404 |
|
---|
405 | #endif
|
---|
406 |
|
---|
407 | /** This is the maximum argument count we'll ever be needing. */
|
---|
408 | #define IEMNATIVE_CALL_MAX_ARG_COUNT 7
|
---|
409 | #ifdef RT_OS_WINDOWS
|
---|
410 | # ifdef VBOXSTRICTRC_STRICT_ENABLED
|
---|
411 | # undef IEMNATIVE_CALL_MAX_ARG_COUNT
|
---|
412 | # define IEMNATIVE_CALL_MAX_ARG_COUNT 8
|
---|
413 | # endif
|
---|
414 | #endif
|
---|
415 |
|
---|
416 | /** @def IEMNATIVE_CALL_VOLATILE_NOTMP_GREG_MASK
|
---|
417 | * Variant of IEMNATIVE_CALL_VOLATILE_GREG_MASK that excludes
|
---|
418 | * IEMNATIVE_REG_FIXED_TMP0 on hosts that uses it. */
|
---|
419 | #ifdef IEMNATIVE_REG_FIXED_TMP0
|
---|
420 | # ifdef IEMNATIVE_REG_FIXED_TMP1
|
---|
421 | # define IEMNATIVE_CALL_VOLATILE_NOTMP_GREG_MASK ( IEMNATIVE_CALL_VOLATILE_GREG_MASK \
|
---|
422 | & ~( RT_BIT_32(IEMNATIVE_REG_FIXED_TMP0) \
|
---|
423 | | RT_BIT_32(IEMNATIVE_REG_FIXED_TMP1)))
|
---|
424 | # else
|
---|
425 | # define IEMNATIVE_CALL_VOLATILE_NOTMP_GREG_MASK (IEMNATIVE_CALL_VOLATILE_GREG_MASK & ~RT_BIT_32(IEMNATIVE_REG_FIXED_TMP0))
|
---|
426 | # endif
|
---|
427 | #else
|
---|
428 | # define IEMNATIVE_CALL_VOLATILE_NOTMP_GREG_MASK IEMNATIVE_CALL_VOLATILE_GREG_MASK
|
---|
429 | #endif
|
---|
430 |
|
---|
431 | /** @def IEMNATIVE_CALL_NONVOLATILE_GREG_MASK
|
---|
432 | * The allocatable non-volatile general purpose register set. */
|
---|
433 | #define IEMNATIVE_CALL_NONVOLATILE_GREG_MASK \
|
---|
434 | (~IEMNATIVE_CALL_VOLATILE_GREG_MASK & ~IEMNATIVE_REG_FIXED_MASK & IEMNATIVE_HST_GREG_MASK)
|
---|
435 | /** @} */
|
---|
436 |
|
---|
437 |
|
---|
438 | /** @def IEMNATIVE_HST_GREG_COUNT
|
---|
439 | * Number of host general purpose registers we tracker. */
|
---|
440 | /** @def IEMNATIVE_HST_GREG_MASK
|
---|
441 | * Mask corresponding to IEMNATIVE_HST_GREG_COUNT that can be applied to
|
---|
442 | * inverted register masks and such to get down to a correct set of regs. */
|
---|
443 | /** @def IEMNATIVE_HST_SIMD_REG_COUNT
|
---|
444 | * Number of host SIMD registers we track. */
|
---|
445 | /** @def IEMNATIVE_HST_SIMD_REG_MASK
|
---|
446 | * Mask corresponding to IEMNATIVE_HST_SIMD_REG_COUNT that can be applied to
|
---|
447 | * inverted register masks and such to get down to a correct set of regs. */
|
---|
448 | #ifdef RT_ARCH_AMD64
|
---|
449 | # define IEMNATIVE_HST_GREG_COUNT 16
|
---|
450 | # define IEMNATIVE_HST_GREG_MASK UINT32_C(0xffff)
|
---|
451 |
|
---|
452 | # define IEMNATIVE_HST_SIMD_REG_COUNT 16
|
---|
453 | # define IEMNATIVE_HST_SIMD_REG_MASK UINT32_C(0xffff)
|
---|
454 |
|
---|
455 | #elif defined(RT_ARCH_ARM64)
|
---|
456 | # define IEMNATIVE_HST_GREG_COUNT 32
|
---|
457 | # define IEMNATIVE_HST_GREG_MASK UINT32_MAX
|
---|
458 |
|
---|
459 | # define IEMNATIVE_HST_SIMD_REG_COUNT 32
|
---|
460 | # define IEMNATIVE_HST_SIMD_REG_MASK UINT32_MAX
|
---|
461 |
|
---|
462 | #else
|
---|
463 | # error "Port me!"
|
---|
464 | #endif
|
---|
465 |
|
---|
466 |
|
---|
467 | #ifndef RT_IN_ASSEMBLER /* ASM-NOINC-START - the rest of the file */
|
---|
468 |
|
---|
469 |
|
---|
470 | /** Native code generator label types. */
|
---|
471 | typedef enum
|
---|
472 | {
|
---|
473 | kIemNativeLabelType_Invalid = 0,
|
---|
474 | /** @name Exit reasons - Labels w/o data, only once instance per TB.
|
---|
475 | *
|
---|
476 | * The labels requiring register inputs are documented.
|
---|
477 | *
|
---|
478 | * @note Jumps to these requires instructions that are capable of spanning the
|
---|
479 | * max TB length.
|
---|
480 | * @{
|
---|
481 | */
|
---|
482 | /* Simple labels comes first for indexing reasons. RaiseXx is order by the exception's numerical value(s). */
|
---|
483 | kIemNativeLabelType_RaiseDe, /**< Raise (throw) X86_XCPT_DE (00h). */
|
---|
484 | kIemNativeLabelType_RaiseUd, /**< Raise (throw) X86_XCPT_UD (06h). */
|
---|
485 | kIemNativeLabelType_RaiseSseRelated, /**< Raise (throw) X86_XCPT_UD or X86_XCPT_NM according to cr0 & cr4. */
|
---|
486 | kIemNativeLabelType_RaiseAvxRelated, /**< Raise (throw) X86_XCPT_UD or X86_XCPT_NM according to xcr0, cr0 & cr4. */
|
---|
487 | kIemNativeLabelType_RaiseSseAvxFpRelated, /**< Raise (throw) X86_XCPT_UD or X86_XCPT_XF according to c4. */
|
---|
488 | kIemNativeLabelType_RaiseNm, /**< Raise (throw) X86_XCPT_NM (07h). */
|
---|
489 | kIemNativeLabelType_RaiseGp0, /**< Raise (throw) X86_XCPT_GP (0dh) w/ errcd=0. */
|
---|
490 | kIemNativeLabelType_RaiseMf, /**< Raise (throw) X86_XCPT_MF (10h). */
|
---|
491 | kIemNativeLabelType_RaiseXf, /**< Raise (throw) X86_XCPT_XF (13h). */
|
---|
492 | kIemNativeLabelType_ObsoleteTb, /**< Calls iemNativeHlpObsoleteTb (no inputs). */
|
---|
493 | kIemNativeLabelType_NeedCsLimChecking, /**< Calls iemNativeHlpNeedCsLimChecking (no inputs). */
|
---|
494 | kIemNativeLabelType_CheckBranchMiss, /**< Calls iemNativeHlpCheckBranchMiss (no inputs). */
|
---|
495 | kIemNativeLabelType_LastSimple = kIemNativeLabelType_CheckBranchMiss,
|
---|
496 |
|
---|
497 | /* Manually defined labels: */
|
---|
498 | /**< Returns with VINF_SUCCESS, no inputs. */
|
---|
499 | kIemNativeLabelType_ReturnSuccess,
|
---|
500 | /** Returns with VINF_IEM_REEXEC_FINISH_WITH_FLAGS, no inputs. */
|
---|
501 | kIemNativeLabelType_ReturnWithFlags,
|
---|
502 | /** Returns with VINF_IEM_REEXEC_BREAK, no inputs. */
|
---|
503 | kIemNativeLabelType_ReturnBreak,
|
---|
504 | /** Returns with VINF_IEM_REEXEC_BREAK_FF, no inputs. */
|
---|
505 | kIemNativeLabelType_ReturnBreakFF,
|
---|
506 | /** The last TB exit label that doesn't have any input registers. */
|
---|
507 | kIemNativeLabelType_LastTbExitWithoutInputs = kIemNativeLabelType_ReturnBreakFF,
|
---|
508 |
|
---|
509 | /** Argument registers 1, 2 & 3 are set up. */
|
---|
510 | kIemNativeLabelType_ReturnBreakViaLookup,
|
---|
511 | /** Argument registers 1, 2 & 3 are set up. */
|
---|
512 | kIemNativeLabelType_ReturnBreakViaLookupWithIrq,
|
---|
513 | /** Argument registers 1 & 2 are set up. */
|
---|
514 | kIemNativeLabelType_ReturnBreakViaLookupWithTlb,
|
---|
515 | /** Argument registers 1 & 2 are set up. */
|
---|
516 | kIemNativeLabelType_ReturnBreakViaLookupWithTlbAndIrq,
|
---|
517 | /** Return register holds the RC and the instruction number is in CL/RCX
|
---|
518 | * on amd64 and the 2rd argument register elsewhere. */
|
---|
519 | kIemNativeLabelType_NonZeroRetOrPassUp,
|
---|
520 |
|
---|
521 | /** The last fixup for branches that can span almost the whole TB length.
|
---|
522 | * @note Whether kIemNativeLabelType_Return needs to be one of these is
|
---|
523 | * a bit questionable, since nobody jumps to it except other tail code. */
|
---|
524 | kIemNativeLabelType_LastWholeTbBranch = kIemNativeLabelType_NonZeroRetOrPassUp,
|
---|
525 | /** The last fixup for branches that exits the TB. */
|
---|
526 | kIemNativeLabelType_LastTbExit = kIemNativeLabelType_NonZeroRetOrPassUp,
|
---|
527 | /** @} */
|
---|
528 |
|
---|
529 | /** Loop-jump target. */
|
---|
530 | kIemNativeLabelType_LoopJumpTarget,
|
---|
531 |
|
---|
532 | /*
|
---|
533 | * Labels with data, potentially multiple instances per TB:
|
---|
534 | *
|
---|
535 | * These are localized labels, so no fixed jump type restrictions here.
|
---|
536 | */
|
---|
537 | kIemNativeLabelType_FirstWithMultipleInstances,
|
---|
538 | kIemNativeLabelType_If = kIemNativeLabelType_FirstWithMultipleInstances,
|
---|
539 | kIemNativeLabelType_Else,
|
---|
540 | kIemNativeLabelType_Endif,
|
---|
541 | kIemNativeLabelType_CheckIrq,
|
---|
542 | kIemNativeLabelType_TlbLookup,
|
---|
543 | kIemNativeLabelType_TlbMiss,
|
---|
544 | kIemNativeLabelType_TlbDone,
|
---|
545 | kIemNativeLabelType_End
|
---|
546 | } IEMNATIVELABELTYPE;
|
---|
547 |
|
---|
548 | #define IEMNATIVELABELTYPE_IS_EXIT_REASON(a_enmLabel) \
|
---|
549 | ((a_enmLabel) <= kIemNativeLabelType_LastTbExit && (a_enmLabel) > kIemNativeLabelType_Invalid)
|
---|
550 |
|
---|
551 | #define IEMNATIVELABELTYPE_IS_EXIT_WITHOUT_INPUTS(a_enmLabel) \
|
---|
552 | ((a_enmLabel) <= kIemNativeLabelType_LastTbExitWithoutInputs && (a_enmLabel) > kIemNativeLabelType_Invalid)
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * Get the mask of input registers for an TB exit label.
|
---|
556 | * This will return zero for any non-exit lable.
|
---|
557 | */
|
---|
558 | #ifdef RT_ARCH_AMD64
|
---|
559 | # define IEMNATIVELABELTYPE_GET_INPUT_REG_MASK(a_enmLabel) \
|
---|
560 | ( (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookup \
|
---|
561 | || (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithIrq \
|
---|
562 | ? RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG3_GREG) \
|
---|
563 | : (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithTlb \
|
---|
564 | || (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithTlbAndIrq \
|
---|
565 | ? RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) \
|
---|
566 | : (a_enmLabel) == kIemNativeLabelType_NonZeroRetOrPassUp \
|
---|
567 | ? RT_BIT_32(IEMNATIVE_CALL_RET_GREG) | RT_BIT_32(X86_GREG_xCX) /* <-- the difference */ \
|
---|
568 | : 0)
|
---|
569 | # else
|
---|
570 | # define IEMNATIVELABELTYPE_GET_INPUT_REG_MASK(a_enmLabel) \
|
---|
571 | ( (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookup \
|
---|
572 | || (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithIrq \
|
---|
573 | ? RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG3_GREG) \
|
---|
574 | : (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithTlb \
|
---|
575 | || (a_enmLabel) == kIemNativeLabelType_ReturnBreakViaLookupWithTlbAndIrq \
|
---|
576 | ? RT_BIT_32(IEMNATIVE_CALL_ARG1_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) \
|
---|
577 | : (a_enmLabel) == kIemNativeLabelType_NonZeroRetOrPassUp \
|
---|
578 | ? RT_BIT_32(IEMNATIVE_CALL_RET_GREG) | RT_BIT_32(IEMNATIVE_CALL_ARG2_GREG) \
|
---|
579 | : 0)
|
---|
580 | #endif
|
---|
581 |
|
---|
582 |
|
---|
583 | /** Native code generator label definition. */
|
---|
584 | typedef struct IEMNATIVELABEL
|
---|
585 | {
|
---|
586 | /** Code offset if defined, UINT32_MAX if it needs to be generated after/in
|
---|
587 | * the epilog. */
|
---|
588 | uint32_t off;
|
---|
589 | /** The type of label (IEMNATIVELABELTYPE). */
|
---|
590 | uint16_t enmType;
|
---|
591 | /** Additional label data, type specific. */
|
---|
592 | uint16_t uData;
|
---|
593 | } IEMNATIVELABEL;
|
---|
594 | /** Pointer to a label. */
|
---|
595 | typedef IEMNATIVELABEL *PIEMNATIVELABEL;
|
---|
596 |
|
---|
597 |
|
---|
598 |
|
---|
599 | /** Native code generator fixup types. */
|
---|
600 | typedef enum
|
---|
601 | {
|
---|
602 | kIemNativeFixupType_Invalid = 0,
|
---|
603 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
604 | /** AMD64 fixup: PC relative 32-bit with addend in bData. */
|
---|
605 | kIemNativeFixupType_Rel32,
|
---|
606 | #elif defined(RT_ARCH_ARM64)
|
---|
607 | /** ARM64 fixup: PC relative offset at bits 25:0 (B, BL). */
|
---|
608 | kIemNativeFixupType_RelImm26At0,
|
---|
609 | /** ARM64 fixup: PC relative offset at bits 23:5 (CBZ, CBNZ, B.CC). */
|
---|
610 | kIemNativeFixupType_RelImm19At5,
|
---|
611 | /** ARM64 fixup: PC relative offset at bits 18:5 (TBZ, TBNZ). */
|
---|
612 | kIemNativeFixupType_RelImm14At5,
|
---|
613 | #endif
|
---|
614 | kIemNativeFixupType_End
|
---|
615 | } IEMNATIVEFIXUPTYPE;
|
---|
616 |
|
---|
617 | /** Native code generator fixup. */
|
---|
618 | typedef struct IEMNATIVEFIXUP
|
---|
619 | {
|
---|
620 | /** Code offset of the fixup location. */
|
---|
621 | uint32_t off;
|
---|
622 | /** The IEMNATIVELABEL this is a fixup for. */
|
---|
623 | uint16_t idxLabel;
|
---|
624 | /** The fixup type (IEMNATIVEFIXUPTYPE). */
|
---|
625 | uint8_t enmType;
|
---|
626 | /** Addend or other data. */
|
---|
627 | int8_t offAddend;
|
---|
628 | } IEMNATIVEFIXUP;
|
---|
629 | /** Pointer to a native code generator fixup. */
|
---|
630 | typedef IEMNATIVEFIXUP *PIEMNATIVEFIXUP;
|
---|
631 |
|
---|
632 |
|
---|
633 |
|
---|
634 | /** Native code generator fixup to per chunk TB tail code. */
|
---|
635 | typedef struct IEMNATIVEEXITFIXUP
|
---|
636 | {
|
---|
637 | /** Code offset of the fixup location. */
|
---|
638 | uint32_t off;
|
---|
639 | /** The exit reason. */
|
---|
640 | IEMNATIVELABELTYPE enmExitReason;
|
---|
641 | } IEMNATIVEEXITFIXUP;
|
---|
642 | /** Pointer to a native code generator TB exit fixup. */
|
---|
643 | typedef IEMNATIVEEXITFIXUP *PIEMNATIVEEXITFIXUP;
|
---|
644 |
|
---|
645 | /**
|
---|
646 | * Per executable memory chunk context with addresses for common code.
|
---|
647 | */
|
---|
648 | typedef struct IEMNATIVEPERCHUNKCTX
|
---|
649 | {
|
---|
650 | /** Pointers to the exit labels */
|
---|
651 | PIEMNATIVEINSTR apExitLabels[kIemNativeLabelType_LastTbExit + 1];
|
---|
652 | } IEMNATIVEPERCHUNKCTX;
|
---|
653 | /** Pointer to per-chunk recompiler context. */
|
---|
654 | typedef IEMNATIVEPERCHUNKCTX *PIEMNATIVEPERCHUNKCTX;
|
---|
655 | /** Pointer to const per-chunk recompiler context. */
|
---|
656 | typedef const IEMNATIVEPERCHUNKCTX *PCIEMNATIVEPERCHUNKCTX;
|
---|
657 |
|
---|
658 |
|
---|
659 |
|
---|
660 | /**
|
---|
661 | * One bit of the state.
|
---|
662 | *
|
---|
663 | * Each register state takes up two bits. We keep the two bits in two separate
|
---|
664 | * 64-bit words to simplify applying them to the guest shadow register mask in
|
---|
665 | * the register allocator.
|
---|
666 | */
|
---|
667 | typedef union IEMLIVENESSBIT
|
---|
668 | {
|
---|
669 | uint64_t bm64;
|
---|
670 | RT_GCC_EXTENSION struct
|
---|
671 | { /* bit no */
|
---|
672 | uint64_t bmGprs : 16; /**< 0x00 / 0: The 16 general purpose registers. */
|
---|
673 | uint64_t fCr0 : 1; /**< 0x10 / 16: */
|
---|
674 | uint64_t fCr4 : 1; /**< 0x11 / 17: */
|
---|
675 | uint64_t fFcw : 1; /**< 0x12 / 18: */
|
---|
676 | uint64_t fFsw : 1; /**< 0x13 / 19: */
|
---|
677 | uint64_t bmSegBase : 6; /**< 0x14 / 20: */
|
---|
678 | uint64_t bmSegAttrib : 6; /**< 0x1a / 26: */
|
---|
679 | uint64_t bmSegLimit : 6; /**< 0x20 / 32: */
|
---|
680 | uint64_t bmSegSel : 6; /**< 0x26 / 38: */
|
---|
681 | uint64_t fXcr0 : 1; /**< 0x2c / 44: */
|
---|
682 | uint64_t fMxCsr : 1; /**< 0x2d / 45: */
|
---|
683 | uint64_t fEflOther : 1; /**< 0x2e / 46: Other EFLAGS bits (~X86_EFL_STATUS_BITS & X86_EFL_LIVE_MASK). First! */
|
---|
684 | uint64_t fEflCf : 1; /**< 0x2f / 47: Carry flag (X86_EFL_CF / 0). */
|
---|
685 | uint64_t fEflPf : 1; /**< 0x30 / 48: Parity flag (X86_EFL_PF / 2). */
|
---|
686 | uint64_t fEflAf : 1; /**< 0x31 / 59: Auxilary carry flag (X86_EFL_AF / 4). */
|
---|
687 | uint64_t fEflZf : 1; /**< 0x32 / 50: Zero flag (X86_EFL_ZF / 6). */
|
---|
688 | uint64_t fEflSf : 1; /**< 0x33 / 51: Signed flag (X86_EFL_SF / 7). */
|
---|
689 | uint64_t fEflOf : 1; /**< 0x34 / 52: Overflow flag (X86_EFL_OF / 12). */
|
---|
690 | uint64_t fUnusedPc : 1; /**< 0x35 / 53: (PC in ) */
|
---|
691 | uint64_t uUnused : 10; /* 0x36 / 54 -> 0x40/64 */
|
---|
692 | };
|
---|
693 | } IEMLIVENESSBIT;
|
---|
694 | AssertCompileSize(IEMLIVENESSBIT, 8);
|
---|
695 |
|
---|
696 | #define IEMLIVENESSBIT_IDX_EFL_OTHER ((unsigned)kIemNativeGstReg_EFlags + 0)
|
---|
697 | #define IEMLIVENESSBIT_IDX_EFL_CF ((unsigned)kIemNativeGstReg_EFlags + 1)
|
---|
698 | #define IEMLIVENESSBIT_IDX_EFL_PF ((unsigned)kIemNativeGstReg_EFlags + 2)
|
---|
699 | #define IEMLIVENESSBIT_IDX_EFL_AF ((unsigned)kIemNativeGstReg_EFlags + 3)
|
---|
700 | #define IEMLIVENESSBIT_IDX_EFL_ZF ((unsigned)kIemNativeGstReg_EFlags + 4)
|
---|
701 | #define IEMLIVENESSBIT_IDX_EFL_SF ((unsigned)kIemNativeGstReg_EFlags + 5)
|
---|
702 | #define IEMLIVENESSBIT_IDX_EFL_OF ((unsigned)kIemNativeGstReg_EFlags + 6)
|
---|
703 | #define IEMLIVENESSBIT_IDX_EFL_COUNT 7
|
---|
704 |
|
---|
705 |
|
---|
706 | /**
|
---|
707 | * A liveness state entry.
|
---|
708 | *
|
---|
709 | * The first 128 bits runs parallel to kIemNativeGstReg_xxx for the most part.
|
---|
710 | * Once we add a SSE register shadowing, we'll add another 64-bit element for
|
---|
711 | * that.
|
---|
712 | */
|
---|
713 | typedef union IEMLIVENESSENTRY
|
---|
714 | {
|
---|
715 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
716 | uint64_t bm64[16 / 8];
|
---|
717 | uint16_t bm32[16 / 4];
|
---|
718 | uint16_t bm16[16 / 2];
|
---|
719 | uint8_t bm8[ 16 / 1];
|
---|
720 | IEMLIVENESSBIT aBits[2];
|
---|
721 | #else
|
---|
722 | uint64_t bm64[32 / 8];
|
---|
723 | uint16_t bm32[32 / 4];
|
---|
724 | uint16_t bm16[32 / 2];
|
---|
725 | uint8_t bm8[ 32 / 1];
|
---|
726 | IEMLIVENESSBIT aBits[4];
|
---|
727 | #endif
|
---|
728 | RT_GCC_EXTENSION struct
|
---|
729 | {
|
---|
730 | /** Bit \#0 of the register states. */
|
---|
731 | IEMLIVENESSBIT Bit0;
|
---|
732 | /** Bit \#1 of the register states. */
|
---|
733 | IEMLIVENESSBIT Bit1;
|
---|
734 | #ifdef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
735 | /** Bit \#2 of the register states. */
|
---|
736 | IEMLIVENESSBIT Bit2;
|
---|
737 | /** Bit \#3 of the register states. */
|
---|
738 | IEMLIVENESSBIT Bit3;
|
---|
739 | #endif
|
---|
740 | };
|
---|
741 | } IEMLIVENESSENTRY;
|
---|
742 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
743 | AssertCompileSize(IEMLIVENESSENTRY, 16);
|
---|
744 | #else
|
---|
745 | AssertCompileSize(IEMLIVENESSENTRY, 32);
|
---|
746 | #endif
|
---|
747 | /** Pointer to a liveness state entry. */
|
---|
748 | typedef IEMLIVENESSENTRY *PIEMLIVENESSENTRY;
|
---|
749 | /** Pointer to a const liveness state entry. */
|
---|
750 | typedef IEMLIVENESSENTRY const *PCIEMLIVENESSENTRY;
|
---|
751 |
|
---|
752 | /** @name 64-bit value masks for IEMLIVENESSENTRY.
|
---|
753 | * @{ */ /* 0xzzzzyyyyxxxxwwww */
|
---|
754 | #define IEMLIVENESSBIT_MASK UINT64_C(0x001fffffffffffff)
|
---|
755 |
|
---|
756 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
757 | # define IEMLIVENESSBIT0_XCPT_OR_CALL UINT64_C(0x0000000000000000)
|
---|
758 | # define IEMLIVENESSBIT1_XCPT_OR_CALL IEMLIVENESSBIT_MASK
|
---|
759 |
|
---|
760 | # define IEMLIVENESSBIT0_ALL_UNUSED IEMLIVENESSBIT_MASK
|
---|
761 | # define IEMLIVENESSBIT1_ALL_UNUSED UINT64_C(0x0000000000000000)
|
---|
762 | #endif
|
---|
763 |
|
---|
764 | #define IEMLIVENESSBIT_ALL_EFL_MASK UINT64_C(0x001fc00000000000)
|
---|
765 | #define IEMLIVENESSBIT_STATUS_EFL_MASK UINT64_C(0x001f800000000000)
|
---|
766 |
|
---|
767 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
768 | # define IEMLIVENESSBIT0_ALL_EFL_INPUT IEMLIVENESSBIT_ALL_EFL_MASK
|
---|
769 | # define IEMLIVENESSBIT1_ALL_EFL_INPUT IEMLIVENESSBIT_ALL_EFL_MASK
|
---|
770 | #endif
|
---|
771 | /** @} */
|
---|
772 |
|
---|
773 |
|
---|
774 | /** @name The liveness state for a register.
|
---|
775 | *
|
---|
776 | * The state values have been picked to with state accumulation in mind (what
|
---|
777 | * the iemNativeLivenessFunc_xxxx functions does), as that is the most
|
---|
778 | * performance critical work done with the values.
|
---|
779 | *
|
---|
780 | * This is a compressed state that only requires 2 bits per register.
|
---|
781 | * When accumulating state, we'll be using three IEMLIVENESSENTRY copies:
|
---|
782 | * 1. the incoming state from the following call,
|
---|
783 | * 2. the outgoing state for this call,
|
---|
784 | * 3. mask of the entries set in the 2nd.
|
---|
785 | *
|
---|
786 | * The mask entry (3rd one above) will be used both when updating the outgoing
|
---|
787 | * state and when merging in incoming state for registers not touched by the
|
---|
788 | * current call.
|
---|
789 | *
|
---|
790 | *
|
---|
791 | * Extended Layout:
|
---|
792 | *
|
---|
793 | * The extended layout variation differs from the above as it records the
|
---|
794 | * different register accesses as individual bits, and it is currently used for
|
---|
795 | * the delayed EFLAGS calculation experiments. The latter means that
|
---|
796 | * calls/tb-exits and potential calls/exceptions/tb-exits are recorded
|
---|
797 | * separately so the latter can be checked for in combination with clobbering.
|
---|
798 | *
|
---|
799 | * @{ */
|
---|
800 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
801 | /** The register will be clobbered and the current value thrown away.
|
---|
802 | *
|
---|
803 | * When this is applied to the state (2) we'll simply be AND'ing it with the
|
---|
804 | * (old) mask (3) and adding the register to the mask. This way we'll
|
---|
805 | * preserve the high priority IEMLIVENESS_STATE_XCPT_OR_CALL and
|
---|
806 | * IEMLIVENESS_STATE_INPUT states. */
|
---|
807 | # define IEMLIVENESS_STATE_CLOBBERED 0
|
---|
808 | /** The register is unused in the remainder of the TB.
|
---|
809 | *
|
---|
810 | * This is an initial state and can not be set by any of the
|
---|
811 | * iemNativeLivenessFunc_xxxx callbacks. */
|
---|
812 | # define IEMLIVENESS_STATE_UNUSED 1
|
---|
813 | /** The register value is required in a potential call or exception.
|
---|
814 | *
|
---|
815 | * This means that the register value must be calculated and is best written to
|
---|
816 | * the state, but that any shadowing registers can be flushed thereafter as it's
|
---|
817 | * not used again. This state has lower priority than IEMLIVENESS_STATE_INPUT.
|
---|
818 | *
|
---|
819 | * It is typically applied across the board, but we preserve incoming
|
---|
820 | * IEMLIVENESS_STATE_INPUT values. This latter means we have to do some extra
|
---|
821 | * trickery to filter out IEMLIVENESS_STATE_UNUSED:
|
---|
822 | * 1. r0 = old & ~mask;
|
---|
823 | * 2. r0 = t1 & (t1 >> 1);
|
---|
824 | * 3. state |= r0 | 0b10;
|
---|
825 | * 4. mask = ~0;
|
---|
826 | */
|
---|
827 | # define IEMLIVENESS_STATE_XCPT_OR_CALL 2
|
---|
828 | /** The register value is used as input.
|
---|
829 | *
|
---|
830 | * This means that the register value must be calculated and it is best to keep
|
---|
831 | * it in a register. It does not need to be writtent out as such. This is the
|
---|
832 | * highest priority state.
|
---|
833 | *
|
---|
834 | * Whether the call modifies the register or not isn't relevant to earlier
|
---|
835 | * calls, so that's not recorded.
|
---|
836 | *
|
---|
837 | * When applying this state we just or in the value in the outgoing state and
|
---|
838 | * mask. */
|
---|
839 | # define IEMLIVENESS_STATE_INPUT 3
|
---|
840 | /** Mask of the state bits. */
|
---|
841 | # define IEMLIVENESS_STATE_MASK 3
|
---|
842 | /** The number of bits per state. */
|
---|
843 | # define IEMLIVENESS_STATE_BIT_COUNT 2
|
---|
844 |
|
---|
845 | /** Check if we're expecting read & write accesses to a register with the given (previous) liveness state.
|
---|
846 | * @note only used in assertions. */
|
---|
847 | # define IEMLIVENESS_STATE_IS_MODIFY_EXPECTED(a_uState) ((uint32_t)((a_uState) - 1U) >= (uint32_t)(IEMLIVENESS_STATE_INPUT - 1U))
|
---|
848 | /** Check if we're expecting read accesses to a register with the given (previous) liveness state.
|
---|
849 | * @note only used in assertions. */
|
---|
850 | # define IEMLIVENESS_STATE_IS_INPUT_EXPECTED(a_uState) IEMLIVENESS_STATE_IS_MODIFY_EXPECTED(a_uState)
|
---|
851 | /** Check if a register clobbering is expected given the (previous) liveness state.
|
---|
852 | * The state must be either CLOBBERED or XCPT_OR_CALL, but it may also
|
---|
853 | * include INPUT if the register is used in more than one place.
|
---|
854 | * @note only used in assertions. */
|
---|
855 | # define IEMLIVENESS_STATE_IS_CLOBBER_EXPECTED(a_uState) ((uint32_t)(a_uState) != IEMLIVENESS_STATE_UNUSED)
|
---|
856 |
|
---|
857 | /** Check if all status flags are going to be clobbered and doesn't need
|
---|
858 | * calculating in the current step.
|
---|
859 | * @param a_pCurEntry The current liveness entry.
|
---|
860 | * @note Used by actual code. */
|
---|
861 | # define IEMLIVENESS_STATE_ARE_STATUS_EFL_TO_BE_CLOBBERED(a_pCurEntry) \
|
---|
862 | ( (((a_pCurEntry)->Bit0.bm64 | (a_pCurEntry)->Bit1.bm64) & IEMLIVENESSBIT_STATUS_EFL_MASK) == 0 )
|
---|
863 |
|
---|
864 | /***
|
---|
865 | * Construct a mask of what will be clobbered and never used.
|
---|
866 | *
|
---|
867 | * This is mainly used with IEMLIVENESSBIT_STATUS_EFL_MASK to avoid
|
---|
868 | * unnecessary EFLAGS calculations.
|
---|
869 | *
|
---|
870 | * @param a_pCurEntry The current liveness entry.
|
---|
871 | * @note Used by actual code.
|
---|
872 | */
|
---|
873 | # define IEMLIVENESS_STATE_GET_WILL_BE_CLOBBERED_SET(a_pCurEntry) \
|
---|
874 | ( ~((a_pCurEntry)->Bit0.bm64 | (a_pCurEntry)->Bit1.bm64) & IEMLIVENESSBIT_MASK )
|
---|
875 |
|
---|
876 | /** Construct a mask of the guest registers in the UNUSED and XCPT_OR_CALL
|
---|
877 | * states, as these are no longer needed.
|
---|
878 | * @param a_pCurEntry The current liveness entry.
|
---|
879 | * @note Used by actual code. */
|
---|
880 | AssertCompile(IEMLIVENESS_STATE_UNUSED == 1 && IEMLIVENESS_STATE_XCPT_OR_CALL == 2);
|
---|
881 | # define IEMLIVENESS_STATE_GET_CAN_BE_FREED_SET(a_pCurEntry) \
|
---|
882 | ( (a_pCurEntry)->Bit0.bm64 ^ (a_pCurEntry)->Bit1.bm64 )
|
---|
883 |
|
---|
884 |
|
---|
885 | #else /* IEMLIVENESS_EXTENDED_LAYOUT */
|
---|
886 | /** The register is not used any more. */
|
---|
887 | # define IEMLIVENESS_STATE_UNUSED 0
|
---|
888 | /** Flag: The register is required in a potential call or/and exception. */
|
---|
889 | # define IEMLIVENESS_STATE_POTENTIAL_CALL 1
|
---|
890 | # define IEMLIVENESS_BIT_POTENTIAL_CALL 0
|
---|
891 | /** Flag: The register is read. */
|
---|
892 | # define IEMLIVENESS_STATE_READ 2
|
---|
893 | # define IEMLIVENESS_BIT_READ 1
|
---|
894 | /** Flag: The register is written. */
|
---|
895 | # define IEMLIVENESS_STATE_WRITE 4
|
---|
896 | # define IEMLIVENESS_BIT_WRITE 2
|
---|
897 | /** Flag: Unconditional call. */
|
---|
898 | # define IEMLIVENESS_STATE_CALL 8
|
---|
899 | # define IEMLIVENESS_BIT_CALL 3
|
---|
900 |
|
---|
901 | # define IEMLIVENESS_STATE_IS_MODIFY_EXPECTED(a_uState) \
|
---|
902 | ( ((a_uState) & (IEMLIVENESS_STATE_WRITE | IEMLIVENESS_STATE_READ)) == (IEMLIVENESS_STATE_WRITE | IEMLIVENESS_STATE_READ) )
|
---|
903 | # define IEMLIVENESS_STATE_IS_INPUT_EXPECTED(a_uState) RT_BOOL((a_uState) & IEMLIVENESS_STATE_READ)
|
---|
904 | # define IEMLIVENESS_STATE_IS_CLOBBER_EXPECTED(a_uState) RT_BOOL((a_uState) & IEMLIVENESS_STATE_WRITE)
|
---|
905 |
|
---|
906 | # define IEMLIVENESS_STATE_ARE_STATUS_EFL_TO_BE_CLOBBERED(a_pCurEntry) \
|
---|
907 | ( ((a_pCurEntry)->aBits[IEMLIVENESS_BIT_WRITE].bm64 & IEMLIVENESSBIT_STATUS_EFL_MASK) == IEMLIVENESSBIT_STATUS_EFL_MASK \
|
---|
908 | && !( ( (a_pCurEntry)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 \
|
---|
909 | | (a_pCurEntry)->aBits[IEMLIVENESS_BIT_READ].bm64 \
|
---|
910 | | (a_pCurEntry)->aBits[IEMLIVENESS_BIT_CALL].bm64) \
|
---|
911 | & IEMLIVENESSBIT_STATUS_EFL_MASK) )
|
---|
912 |
|
---|
913 | /** Construct a mask of the registers not in the read or write state.
|
---|
914 | * @note We could skips writes, if they aren't from us, as this is just a hack
|
---|
915 | * to prevent trashing registers that have just been written or will be
|
---|
916 | * written when we retire the current instruction.
|
---|
917 | * @param a_pCurEntry The current liveness entry.
|
---|
918 | * @note Used by actual code. */
|
---|
919 | # define IEMLIVENESS_STATE_GET_CAN_BE_FREED_SET(a_pCurEntry) \
|
---|
920 | ( ~(a_pCurEntry)->aBits[IEMLIVENESS_BIT_READ].bm64 \
|
---|
921 | & ~(a_pCurEntry)->aBits[IEMLIVENESS_BIT_WRITE].bm64 \
|
---|
922 | & IEMLIVENESSBIT_MASK )
|
---|
923 |
|
---|
924 | /***
|
---|
925 | * Construct a mask of what will be clobbered and never used.
|
---|
926 | *
|
---|
927 | * This is mainly used with IEMLIVENESSBIT_STATUS_EFL_MASK to avoid
|
---|
928 | * unnecessary EFLAGS calculations.
|
---|
929 | *
|
---|
930 | * @param a_pCurEntry The current liveness entry.
|
---|
931 | * @note Used by actual code.
|
---|
932 | */
|
---|
933 | # define IEMLIVENESS_STATE_GET_WILL_BE_CLOBBERED_SET(a_pCurEntry) \
|
---|
934 | ( (a_pCurEntry)->aBits[IEMLIVENESS_BIT_WRITE].bm64 \
|
---|
935 | & ~( (a_pCurEntry)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 \
|
---|
936 | | (a_pCurEntry)->aBits[IEMLIVENESS_BIT_READ].bm64 \
|
---|
937 | | (a_pCurEntry)->aBits[IEMLIVENESS_BIT_CALL].bm64) )
|
---|
938 |
|
---|
939 | /**
|
---|
940 | * Construct a mask of what (EFLAGS) which can be postponed.
|
---|
941 | *
|
---|
942 | * The postponement is for the avoiding EFLAGS status bits calculations in the
|
---|
943 | * primary code stream whenever possible, and instead only do these in the TLB
|
---|
944 | * load and TB exit code paths which shouldn't be traveled quite as often.
|
---|
945 | * A requirement, though, is that the status bits will be clobbered later in the
|
---|
946 | * TB.
|
---|
947 | *
|
---|
948 | * User need to apply IEMLIVENESSBIT_STATUS_EFL_MASK if appropriate/necessary.
|
---|
949 | *
|
---|
950 | * @param a_pCurEntry The current liveness entry.
|
---|
951 | * @note Used by actual code.
|
---|
952 | */
|
---|
953 | # define IEMLIVENESS_STATE_GET_CAN_BE_POSTPONED_SET(a_pCurEntry) \
|
---|
954 | ( (a_pCurEntry)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 \
|
---|
955 | & (a_pCurEntry)->aBits[IEMLIVENESS_BIT_WRITE].bm64 \
|
---|
956 | & ~( (a_pCurEntry)->aBits[IEMLIVENESS_BIT_READ].bm64 \
|
---|
957 | | (a_pCurEntry)->aBits[IEMLIVENESS_BIT_CALL].bm64) )
|
---|
958 |
|
---|
959 | #endif /* IEMLIVENESS_EXTENDED_LAYOUT */
|
---|
960 | /** @} */
|
---|
961 |
|
---|
962 | /** @name Liveness helpers for builtin functions and similar.
|
---|
963 | *
|
---|
964 | * These are not used by IEM_MC_BEGIN/END blocks, IEMAllN8veLiveness.cpp has its
|
---|
965 | * own set of manipulator macros for those.
|
---|
966 | *
|
---|
967 | * @{ */
|
---|
968 | /** Initializing the state as all unused. */
|
---|
969 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
970 | # define IEM_LIVENESS_RAW_INIT_AS_UNUSED(a_pOutgoing) \
|
---|
971 | do { \
|
---|
972 | (a_pOutgoing)->Bit0.bm64 = IEMLIVENESSBIT0_ALL_UNUSED; \
|
---|
973 | (a_pOutgoing)->Bit1.bm64 = IEMLIVENESSBIT1_ALL_UNUSED; \
|
---|
974 | } while (0)
|
---|
975 | #else
|
---|
976 | # define IEM_LIVENESS_RAW_INIT_AS_UNUSED(a_pOutgoing) \
|
---|
977 | do { \
|
---|
978 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 = 0; \
|
---|
979 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ ].bm64 = 0; \
|
---|
980 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE ].bm64 = 0; \
|
---|
981 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL ].bm64 = 0; \
|
---|
982 | } while (0)
|
---|
983 | #endif
|
---|
984 |
|
---|
985 | /** Initializing the outgoing state with a potential xcpt or call state.
|
---|
986 | * This only works when all later changes will be IEMLIVENESS_STATE_INPUT.
|
---|
987 | *
|
---|
988 | * @note Must invoke IEM_LIVENESS_RAW_FINISH_WITH_POTENTIAL_CALL when done!
|
---|
989 | */
|
---|
990 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
991 | # define IEM_LIVENESS_RAW_INIT_WITH_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) \
|
---|
992 | do { \
|
---|
993 | (a_pOutgoing)->Bit0.bm64 = (a_pIncoming)->Bit0.bm64 & (a_pIncoming)->Bit1.bm64; \
|
---|
994 | (a_pOutgoing)->Bit1.bm64 = IEMLIVENESSBIT1_XCPT_OR_CALL; \
|
---|
995 | } while (0)
|
---|
996 | #else
|
---|
997 | # define IEM_LIVENESS_RAW_INIT_WITH_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) \
|
---|
998 | do { \
|
---|
999 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 = IEMLIVENESSBIT_MASK; \
|
---|
1000 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ ].bm64 = 0; \
|
---|
1001 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE ].bm64 = 0; \
|
---|
1002 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL ].bm64 = 0; \
|
---|
1003 | } while (0)
|
---|
1004 | #endif
|
---|
1005 |
|
---|
1006 | /** Completes IEM_LIVENESS_RAW_INIT_WITH_POTENTIAL_CALL after applying any
|
---|
1007 | * other state modifications.
|
---|
1008 | */
|
---|
1009 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1010 | # define IEM_LIVENESS_RAW_FINISH_WITH_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) ((void)0)
|
---|
1011 | #else
|
---|
1012 | # define IEM_LIVENESS_RAW_FINISH_WITH_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) \
|
---|
1013 | do { \
|
---|
1014 | uint64_t const fInhMask = ~( (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL].bm64 \
|
---|
1015 | | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE].bm64); \
|
---|
1016 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 |= (a_pIncoming)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 & fInhMask; \
|
---|
1017 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ ].bm64 |= (a_pIncoming)->aBits[IEMLIVENESS_BIT_READ].bm64 & fInhMask; \
|
---|
1018 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE ].bm64 |= (a_pIncoming)->aBits[IEMLIVENESS_BIT_WRITE].bm64 & fInhMask; \
|
---|
1019 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL ].bm64 |= (a_pIncoming)->aBits[IEMLIVENESS_BIT_CALL].bm64 & fInhMask; \
|
---|
1020 | } while (0)
|
---|
1021 | #endif
|
---|
1022 |
|
---|
1023 | /** Initializing the outgoing state with an unconditional call state.
|
---|
1024 | * This should only really be used alone. */
|
---|
1025 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1026 | # define IEM_LIVENESS_RAW_INIT_WITH_CALL(a_pOutgoing, a_pIncoming) \
|
---|
1027 | do { \
|
---|
1028 | (a_pOutgoing)->Bit0.bm64 = (a_pIncoming)->Bit0.bm64 & (a_pIncoming)->Bit1.bm64; \
|
---|
1029 | (a_pOutgoing)->Bit1.bm64 = IEMLIVENESSBIT1_XCPT_OR_CALL; \
|
---|
1030 | } while (0)
|
---|
1031 | #else
|
---|
1032 | # define IEM_LIVENESS_RAW_INIT_WITH_CALL(a_pOutgoing, a_pIncoming) \
|
---|
1033 | do { \
|
---|
1034 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL ].bm64 = IEMLIVENESSBIT_MASK; \
|
---|
1035 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 = 0; \
|
---|
1036 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ ].bm64 = 0; \
|
---|
1037 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE ].bm64 = 0; \
|
---|
1038 | RT_NOREF(a_pIncoming); \
|
---|
1039 | } while (0)
|
---|
1040 | #endif
|
---|
1041 |
|
---|
1042 | #if 0 /* unused */
|
---|
1043 | /** Initializing the outgoing state with an unconditional call state as well as
|
---|
1044 | * an potential call/exception preceeding it.
|
---|
1045 | * This should only really be used alone. */
|
---|
1046 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1047 | # define IEM_LIVENESS_RAW_INIT_WITH_CALL_AND_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) \
|
---|
1048 | do { \
|
---|
1049 | (a_pOutgoing)->Bit0.bm64 = (a_pIncoming)->Bit0.bm64 & (a_pIncoming)->Bit1.bm64; \
|
---|
1050 | (a_pOutgoing)->Bit1.bm64 = IEMLIVENESSBIT1_XCPT_OR_CALL; \
|
---|
1051 | } while (0)
|
---|
1052 | #else
|
---|
1053 | # define IEM_LIVENESS_RAW_INIT_WITH_CALL_AND_POTENTIAL_CALL(a_pOutgoing, a_pIncoming) \
|
---|
1054 | do { \
|
---|
1055 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_POTENTIAL_CALL].bm64 = IEMLIVENESSBIT_MASK; \
|
---|
1056 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_CALL ].bm64 = IEMLIVENESSBIT_MASK; \
|
---|
1057 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ ].bm64 = 0; \
|
---|
1058 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_WRITE ].bm64 = 0; \
|
---|
1059 | } while (0)
|
---|
1060 | #endif
|
---|
1061 | #endif
|
---|
1062 |
|
---|
1063 | /** Adds a segment base register as input to the outgoing state. */
|
---|
1064 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1065 | # define IEM_LIVENESS_RAW_SEG_BASE_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1066 | (a_pOutgoing)->Bit0.bmSegBase |= RT_BIT_64(a_iSReg); \
|
---|
1067 | (a_pOutgoing)->Bit1.bmSegBase |= RT_BIT_64(a_iSReg); \
|
---|
1068 | } while (0)
|
---|
1069 | #else
|
---|
1070 | # define IEM_LIVENESS_RAW_SEG_BASE_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1071 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ].bmSegBase |= RT_BIT_64(a_iSReg); \
|
---|
1072 | } while (0)
|
---|
1073 | #endif
|
---|
1074 |
|
---|
1075 | /** Adds a segment attribute register as input to the outgoing state. */
|
---|
1076 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1077 | # define IEM_LIVENESS_RAW_SEG_ATTRIB_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1078 | (a_pOutgoing)->Bit0.bmSegAttrib |= RT_BIT_64(a_iSReg); \
|
---|
1079 | (a_pOutgoing)->Bit1.bmSegAttrib |= RT_BIT_64(a_iSReg); \
|
---|
1080 | } while (0)
|
---|
1081 | #else
|
---|
1082 | # define IEM_LIVENESS_RAW_SEG_ATTRIB_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1083 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ].bmSegAttrib |= RT_BIT_64(a_iSReg); \
|
---|
1084 | } while (0)
|
---|
1085 | #endif
|
---|
1086 |
|
---|
1087 | /** Adds a segment limit register as input to the outgoing state. */
|
---|
1088 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1089 | # define IEM_LIVENESS_RAW_SEG_LIMIT_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1090 | (a_pOutgoing)->Bit0.bmSegLimit |= RT_BIT_64(a_iSReg); \
|
---|
1091 | (a_pOutgoing)->Bit1.bmSegLimit |= RT_BIT_64(a_iSReg); \
|
---|
1092 | } while (0)
|
---|
1093 | #else
|
---|
1094 | # define IEM_LIVENESS_RAW_SEG_LIMIT_INPUT(a_pOutgoing, a_iSReg) do { \
|
---|
1095 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ].bmSegLimit |= RT_BIT_64(a_iSReg); \
|
---|
1096 | } while (0)
|
---|
1097 | #endif
|
---|
1098 |
|
---|
1099 | /** Adds a segment limit register as input to the outgoing state. */
|
---|
1100 | #ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
1101 | # define IEM_LIVENESS_RAW_EFLAGS_ONE_INPUT(a_pOutgoing, a_fEflMember) do { \
|
---|
1102 | (a_pOutgoing)->Bit0.a_fEflMember |= 1; \
|
---|
1103 | (a_pOutgoing)->Bit1.a_fEflMember |= 1; \
|
---|
1104 | } while (0)
|
---|
1105 | #else
|
---|
1106 | # define IEM_LIVENESS_RAW_EFLAGS_ONE_INPUT(a_pOutgoing, a_fEflMember) do { \
|
---|
1107 | (a_pOutgoing)->aBits[IEMLIVENESS_BIT_READ].a_fEflMember |= 1; \
|
---|
1108 | } while (0)
|
---|
1109 | #endif
|
---|
1110 | /** @} */
|
---|
1111 |
|
---|
1112 | /** @def IEMNATIVE_ASSERT_EFLAGS_SKIPPING_ONLY
|
---|
1113 | * Debug assertion that the required flags are available and not incorrectly skipped.
|
---|
1114 | */
|
---|
1115 | #ifdef IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
1116 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_ONLY(a_pReNative, a_fEflNeeded) \
|
---|
1117 | AssertMsg(!((a_pReNative)->fSkippingEFlags & (a_fEflNeeded)), \
|
---|
1118 | ("%#x & %#x -> %#x\n", (a_pReNative)->fSkippingEFlags, \
|
---|
1119 | a_fEflNeeded, (a_pReNative)->fSkippingEFlags & (a_fEflNeeded) ))
|
---|
1120 | #else
|
---|
1121 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_ONLY(a_pReNative, a_fEflNeeded) ((void)0)
|
---|
1122 | #endif
|
---|
1123 |
|
---|
1124 | /** @def IEMNATIVE_ASSERT_EFLAGS_POSTPONING_ONLY
|
---|
1125 | * Debug assertion that the required flags are available and not incorrectly postponed.
|
---|
1126 | */
|
---|
1127 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1128 | # define IEMNATIVE_ASSERT_EFLAGS_POSTPONING_ONLY(a_pReNative, a_fEflNeeded) \
|
---|
1129 | AssertMsg(!((a_pReNative)->PostponedEfl.fEFlags & (a_fEflNeeded)), \
|
---|
1130 | ("%#x & %#x -> %#x\n", (a_pReNative)->PostponedEfl.fEFlags, \
|
---|
1131 | a_fEflNeeded, (a_pReNative)->PostponedEfl.fEFlags & (a_fEflNeeded) ))
|
---|
1132 | #else
|
---|
1133 | # define IEMNATIVE_ASSERT_EFLAGS_POSTPONING_ONLY(a_pReNative, a_fEflNeeded) ((void)0)
|
---|
1134 | #endif
|
---|
1135 |
|
---|
1136 | /** @def IEMNATIVE_ASSERT_EFLAGS_SKIPPING_AND_POSTPONING
|
---|
1137 | * Debug assertion that the required flags are available and not incorrectly
|
---|
1138 | * skipped or postponed.
|
---|
1139 | */
|
---|
1140 | #if defined(IEMNATIVE_WITH_EFLAGS_SKIPPING) && defined(IEMNATIVE_WITH_EFLAGS_POSTPONING)
|
---|
1141 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_AND_POSTPONING(a_pReNative, a_fEflNeeded) \
|
---|
1142 | AssertMsg(!(((a_pReNative)->fSkippingEFlags | (a_pReNative)->PostponedEfl.fEFlags) & (a_fEflNeeded)), \
|
---|
1143 | ("(%#x | %#x) & %#x -> %#x\n", (a_pReNative)->fSkippingEFlags, (a_pReNative)->PostponedEfl.fEFlags, \
|
---|
1144 | a_fEflNeeded, ((a_pReNative)->fSkippingEFlags | (a_pReNative)->PostponedEfl.fEFlags) & (a_fEflNeeded) ))
|
---|
1145 | #elif defined(IEMNATIVE_WITH_EFLAGS_SKIPPING)
|
---|
1146 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_AND_POSTPONING(a_pReNative, a_fEflNeeded) \
|
---|
1147 | IEMNATIVE_ASSERT_EFLAGS_SKIPPING_ONLY(a_pReNative, a_fEflNeeded)
|
---|
1148 | #elif defined(IEMNATIVE_WITH_EFLAGS_POSTPONING) \
|
---|
1149 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_AND_POSTPONING(a_pReNative, a_fEflNeeded) \
|
---|
1150 | IEMNATIVE_ASSERT_EFLAGS_POSTPONING_ONLY(a_pReNative, a_fEflNeeded)
|
---|
1151 | #else
|
---|
1152 | # define IEMNATIVE_ASSERT_EFLAGS_SKIPPING_AND_POSTPONING(a_pReNative, a_fEflNeeded) ((void)0)
|
---|
1153 | #endif
|
---|
1154 |
|
---|
1155 | /** @def IEMNATIVE_STRICT_EFLAGS_SKIPPING_EMIT_CHECK
|
---|
1156 | * Checks that the EFLAGS bits specified by @a a_fEflNeeded are actually
|
---|
1157 | * calculated and up to date. This is to double check that we haven't skipped
|
---|
1158 | * EFLAGS calculations when we actually need them. NOP in non-strict builds.
|
---|
1159 | * @note has to be placed in
|
---|
1160 | */
|
---|
1161 | #ifdef IEMNATIVE_STRICT_EFLAGS_SKIPPING
|
---|
1162 | # define IEMNATIVE_STRICT_EFLAGS_SKIPPING_EMIT_CHECK(a_pReNative, a_off, a_fEflNeeded) do { \
|
---|
1163 | (a_off) = iemNativeEmitEFlagsSkippingCheck(a_pReNative, a_off, a_fEflNeeded); \
|
---|
1164 | } while (0)
|
---|
1165 | #else
|
---|
1166 | # define IEMNATIVE_STRICT_EFLAGS_SKIPPING_EMIT_CHECK(a_pReNative, a_off, a_fEflNeeded) do { } while (0)
|
---|
1167 | #endif
|
---|
1168 |
|
---|
1169 |
|
---|
1170 | /** @def IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS
|
---|
1171 | * Number of extra instructions to allocate for each TB exit to account for
|
---|
1172 | * postponed EFLAGS calculations.
|
---|
1173 | */
|
---|
1174 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1175 | # ifdef RT_ARCH_AMD64
|
---|
1176 | # ifdef VBOX_STRICT
|
---|
1177 | # define IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS 64
|
---|
1178 | # else
|
---|
1179 | # define IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS 32
|
---|
1180 | # endif
|
---|
1181 | # elif defined(RT_ARCH_ARM64) || defined(DOXYGEN_RUNNING)
|
---|
1182 | # ifdef VBOX_STRICT
|
---|
1183 | # define IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS 48
|
---|
1184 | # else
|
---|
1185 | # define IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS 32
|
---|
1186 | # endif
|
---|
1187 | # else
|
---|
1188 | # error "port me"
|
---|
1189 | # endif
|
---|
1190 | #else
|
---|
1191 | # define IEMNATIVE_MAX_POSTPONED_EFLAGS_INSTRUCTIONS 0
|
---|
1192 | #endif
|
---|
1193 |
|
---|
1194 | /** @def IEMNATIVE_CLEAR_POSTPONED_EFLAGS
|
---|
1195 | * Helper macro function for calling iemNativeClearPostponedEFlags() when
|
---|
1196 | * IEMNATIVE_WITH_EFLAGS_POSTPONING is enabled.
|
---|
1197 | */
|
---|
1198 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1199 | # define IEMNATIVE_CLEAR_POSTPONED_EFLAGS(a_pReNative, a_fEflClobbered) iemNativeClearPostponedEFlags<a_fEflClobbered>(a_pReNative)
|
---|
1200 | #else
|
---|
1201 | # define IEMNATIVE_CLEAR_POSTPONED_EFLAGS(a_pReNative, a_fEflClobbered) ((void)0)
|
---|
1202 | #endif
|
---|
1203 |
|
---|
1204 | /** @def IEMNATIVE_HAS_POSTPONED_EFLAGS_CALCS
|
---|
1205 | * Macro for testing whether there are currently any postponed EFLAGS calcs w/o
|
---|
1206 | * needing to \#ifdef the check.
|
---|
1207 | */
|
---|
1208 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1209 | # define IEMNATIVE_HAS_POSTPONED_EFLAGS_CALCS(a_pReNative) ((a_pReNative)->PostponedEfl.fEFlags != 0)
|
---|
1210 | #else
|
---|
1211 | # define IEMNATIVE_HAS_POSTPONED_EFLAGS_CALCS(a_pReNative) false
|
---|
1212 | #endif
|
---|
1213 |
|
---|
1214 |
|
---|
1215 | /**
|
---|
1216 | * Translation block debug info entry type.
|
---|
1217 | */
|
---|
1218 | typedef enum IEMTBDBGENTRYTYPE
|
---|
1219 | {
|
---|
1220 | kIemTbDbgEntryType_Invalid = 0,
|
---|
1221 | /** The entry is for marking a native code position.
|
---|
1222 | * Entries following this all apply to this position. */
|
---|
1223 | kIemTbDbgEntryType_NativeOffset,
|
---|
1224 | /** The entry is for a new guest instruction. */
|
---|
1225 | kIemTbDbgEntryType_GuestInstruction,
|
---|
1226 | /** Marks the start of a threaded call. */
|
---|
1227 | kIemTbDbgEntryType_ThreadedCall,
|
---|
1228 | /** Marks the location of a label. */
|
---|
1229 | kIemTbDbgEntryType_Label,
|
---|
1230 | /** Info about a host register shadowing a guest register. */
|
---|
1231 | kIemTbDbgEntryType_GuestRegShadowing,
|
---|
1232 | /** Info about a host SIMD register shadowing a guest SIMD register. */
|
---|
1233 | kIemTbDbgEntryType_GuestSimdRegShadowing,
|
---|
1234 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
1235 | /** Info about a delayed RIP update. */
|
---|
1236 | kIemTbDbgEntryType_DelayedPcUpdate,
|
---|
1237 | #endif
|
---|
1238 | /** Info about a shadowed guest register becoming dirty. */
|
---|
1239 | kIemTbDbgEntryType_GuestRegDirty,
|
---|
1240 | /** Info about register writeback/flush oepration. */
|
---|
1241 | kIemTbDbgEntryType_GuestRegWriteback,
|
---|
1242 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1243 | /** Info about a delayed EFLAGS calculation. */
|
---|
1244 | kIemTbDbgEntryType_PostponedEFlagsCalc,
|
---|
1245 | #endif
|
---|
1246 | kIemTbDbgEntryType_End
|
---|
1247 | } IEMTBDBGENTRYTYPE;
|
---|
1248 |
|
---|
1249 | /**
|
---|
1250 | * Translation block debug info entry.
|
---|
1251 | */
|
---|
1252 | typedef union IEMTBDBGENTRY
|
---|
1253 | {
|
---|
1254 | /** Plain 32-bit view. */
|
---|
1255 | uint32_t u;
|
---|
1256 |
|
---|
1257 | /** Generic view for getting at the type field. */
|
---|
1258 | struct
|
---|
1259 | {
|
---|
1260 | /** IEMTBDBGENTRYTYPE */
|
---|
1261 | uint32_t uType : 4;
|
---|
1262 | uint32_t uTypeSpecific : 28;
|
---|
1263 | } Gen;
|
---|
1264 |
|
---|
1265 | struct
|
---|
1266 | {
|
---|
1267 | /** kIemTbDbgEntryType_ThreadedCall1. */
|
---|
1268 | uint32_t uType : 4;
|
---|
1269 | /** Native code offset. */
|
---|
1270 | uint32_t offNative : 28;
|
---|
1271 | } NativeOffset;
|
---|
1272 |
|
---|
1273 | struct
|
---|
1274 | {
|
---|
1275 | /** kIemTbDbgEntryType_GuestInstruction. */
|
---|
1276 | uint32_t uType : 4;
|
---|
1277 | uint32_t uUnused : 4;
|
---|
1278 | /** The IEM_F_XXX flags. */
|
---|
1279 | uint32_t fExec : 24;
|
---|
1280 | } GuestInstruction;
|
---|
1281 |
|
---|
1282 | struct
|
---|
1283 | {
|
---|
1284 | /* kIemTbDbgEntryType_ThreadedCall. */
|
---|
1285 | uint32_t uType : 4;
|
---|
1286 | /** Set if the call was recompiled to native code, clear if just calling
|
---|
1287 | * threaded function. */
|
---|
1288 | uint32_t fRecompiled : 1;
|
---|
1289 | uint32_t uUnused : 11;
|
---|
1290 | /** The threaded call number (IEMTHREADEDFUNCS). */
|
---|
1291 | uint32_t enmCall : 16;
|
---|
1292 | } ThreadedCall;
|
---|
1293 |
|
---|
1294 | struct
|
---|
1295 | {
|
---|
1296 | /* kIemTbDbgEntryType_Label. */
|
---|
1297 | uint32_t uType : 4;
|
---|
1298 | uint32_t uUnused : 4;
|
---|
1299 | /** The label type (IEMNATIVELABELTYPE). */
|
---|
1300 | uint32_t enmLabel : 8;
|
---|
1301 | /** The label data. */
|
---|
1302 | uint32_t uData : 16;
|
---|
1303 | } Label;
|
---|
1304 |
|
---|
1305 | struct
|
---|
1306 | {
|
---|
1307 | /* kIemTbDbgEntryType_GuestRegShadowing. */
|
---|
1308 | uint32_t uType : 4;
|
---|
1309 | uint32_t uUnused : 4;
|
---|
1310 | /** The guest register being shadowed (IEMNATIVEGSTREG). */
|
---|
1311 | uint32_t idxGstReg : 8;
|
---|
1312 | /** The host new register number, UINT8_MAX if dropped. */
|
---|
1313 | uint32_t idxHstReg : 8;
|
---|
1314 | /** The previous host register number, UINT8_MAX if new. */
|
---|
1315 | uint32_t idxHstRegPrev : 8;
|
---|
1316 | } GuestRegShadowing;
|
---|
1317 |
|
---|
1318 | struct
|
---|
1319 | {
|
---|
1320 | /* kIemTbDbgEntryType_GuestSimdRegShadowing. */
|
---|
1321 | uint32_t uType : 4;
|
---|
1322 | uint32_t uUnused : 4;
|
---|
1323 | /** The guest register being shadowed (IEMNATIVEGSTSIMDREG). */
|
---|
1324 | uint32_t idxGstSimdReg : 8;
|
---|
1325 | /** The host new register number, UINT8_MAX if dropped. */
|
---|
1326 | uint32_t idxHstSimdReg : 8;
|
---|
1327 | /** The previous host register number, UINT8_MAX if new. */
|
---|
1328 | uint32_t idxHstSimdRegPrev : 8;
|
---|
1329 | } GuestSimdRegShadowing;
|
---|
1330 |
|
---|
1331 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
1332 | struct
|
---|
1333 | {
|
---|
1334 | /* kIemTbDbgEntryType_DelayedPcUpdate. */
|
---|
1335 | uint32_t uType : 4;
|
---|
1336 | /** Number of instructions skipped. */
|
---|
1337 | uint32_t cInstrSkipped : 8;
|
---|
1338 | /* The instruction offset added to the program counter. */
|
---|
1339 | int32_t offPc : 20;
|
---|
1340 | } DelayedPcUpdate;
|
---|
1341 | #endif
|
---|
1342 |
|
---|
1343 | struct
|
---|
1344 | {
|
---|
1345 | /* kIemTbDbgEntryType_GuestRegDirty. */
|
---|
1346 | uint32_t uType : 4;
|
---|
1347 | uint32_t uUnused : 11;
|
---|
1348 | /** Flag whether this is about a SIMD (true) or general (false) register. */
|
---|
1349 | uint32_t fSimdReg : 1;
|
---|
1350 | /** The guest register index being marked as dirty. */
|
---|
1351 | uint32_t idxGstReg : 8;
|
---|
1352 | /** The host register number this register is shadowed in .*/
|
---|
1353 | uint32_t idxHstReg : 8;
|
---|
1354 | } GuestRegDirty;
|
---|
1355 |
|
---|
1356 | struct
|
---|
1357 | {
|
---|
1358 | /* kIemTbDbgEntryType_GuestRegWriteback. */
|
---|
1359 | uint32_t uType : 4;
|
---|
1360 | /** Flag whether this is about a SIMD (true) or general (false) register flush. */
|
---|
1361 | uint32_t fSimdReg : 1;
|
---|
1362 | /** The mask shift. */
|
---|
1363 | uint32_t cShift : 2;
|
---|
1364 | /** The guest register mask being written back. */
|
---|
1365 | uint32_t fGstReg : 25;
|
---|
1366 | } GuestRegWriteback;
|
---|
1367 |
|
---|
1368 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1369 | struct
|
---|
1370 | {
|
---|
1371 | /* kIemTbDbgEntryType_PostponedEFlagsCalc. */
|
---|
1372 | uint32_t uType : 4;
|
---|
1373 | /** The EFLAGS operation (IEMNATIVE_POSTPONED_EFL_OP_T). */
|
---|
1374 | uint32_t enmOp : 4;
|
---|
1375 | /** The mask shift. */
|
---|
1376 | uint32_t cOpBits : 8;
|
---|
1377 | /** The emit instance number (0-based). */
|
---|
1378 | uint32_t idxEmit : 8;
|
---|
1379 | /** Unused. */
|
---|
1380 | uint32_t uUnused : 8;
|
---|
1381 | } PostponedEflCalc;
|
---|
1382 | #endif
|
---|
1383 | } IEMTBDBGENTRY;
|
---|
1384 | AssertCompileSize(IEMTBDBGENTRY, sizeof(uint32_t));
|
---|
1385 | /** Pointer to a debug info entry. */
|
---|
1386 | typedef IEMTBDBGENTRY *PIEMTBDBGENTRY;
|
---|
1387 | /** Pointer to a const debug info entry. */
|
---|
1388 | typedef IEMTBDBGENTRY const *PCIEMTBDBGENTRY;
|
---|
1389 |
|
---|
1390 | /**
|
---|
1391 | * Translation block debug info.
|
---|
1392 | */
|
---|
1393 | typedef struct IEMTBDBG
|
---|
1394 | {
|
---|
1395 | /** This is the flat PC corresponding to IEMTB::GCPhysPc. */
|
---|
1396 | RTGCPTR FlatPc;
|
---|
1397 | /** Number of entries in aEntries. */
|
---|
1398 | uint32_t cEntries;
|
---|
1399 | /** The offset of the last kIemTbDbgEntryType_NativeOffset record. */
|
---|
1400 | uint32_t offNativeLast;
|
---|
1401 | /** Debug info entries. */
|
---|
1402 | RT_FLEXIBLE_ARRAY_EXTENSION
|
---|
1403 | IEMTBDBGENTRY aEntries[RT_FLEXIBLE_ARRAY];
|
---|
1404 | } IEMTBDBG;
|
---|
1405 | /** Pointer to TB debug info. */
|
---|
1406 | typedef IEMTBDBG *PIEMTBDBG;
|
---|
1407 | /** Pointer to const TB debug info. */
|
---|
1408 | typedef IEMTBDBG const *PCIEMTBDBG;
|
---|
1409 |
|
---|
1410 | /**
|
---|
1411 | * Guest registers that can be shadowed in GPRs.
|
---|
1412 | *
|
---|
1413 | * This runs parallel to the liveness state (IEMLIVENESSBIT, ++). The EFlags
|
---|
1414 | * must be placed last, as the liveness state tracks it as 7 subcomponents and
|
---|
1415 | * we don't want to waste space here.
|
---|
1416 | *
|
---|
1417 | * @note Make sure to update IEMLIVENESSBIT, IEMLIVENESSBIT_ALL_EFL_MASK and
|
---|
1418 | * friends as well as IEMAllN8veLiveness.cpp.
|
---|
1419 | */
|
---|
1420 | typedef enum IEMNATIVEGSTREG : uint8_t
|
---|
1421 | {
|
---|
1422 | kIemNativeGstReg_GprFirst = 0,
|
---|
1423 | kIemNativeGstReg_Rax = kIemNativeGstReg_GprFirst + 0,
|
---|
1424 | kIemNativeGstReg_Rcx = kIemNativeGstReg_GprFirst + 1,
|
---|
1425 | kIemNativeGstReg_Rdx = kIemNativeGstReg_GprFirst + 2,
|
---|
1426 | kIemNativeGstReg_Rbx = kIemNativeGstReg_GprFirst + 3,
|
---|
1427 | kIemNativeGstReg_Rsp = kIemNativeGstReg_GprFirst + 4,
|
---|
1428 | kIemNativeGstReg_Rbp = kIemNativeGstReg_GprFirst + 5,
|
---|
1429 | kIemNativeGstReg_Rsi = kIemNativeGstReg_GprFirst + 6,
|
---|
1430 | kIemNativeGstReg_Rdi = kIemNativeGstReg_GprFirst + 7,
|
---|
1431 | kIemNativeGstReg_GprLast = kIemNativeGstReg_GprFirst + 15,
|
---|
1432 | kIemNativeGstReg_Cr0,
|
---|
1433 | kIemNativeGstReg_Cr4,
|
---|
1434 | kIemNativeGstReg_FpuFcw,
|
---|
1435 | kIemNativeGstReg_FpuFsw,
|
---|
1436 | kIemNativeGstReg_SegBaseFirst,
|
---|
1437 | kIemNativeGstReg_CsBase = kIemNativeGstReg_SegBaseFirst + X86_SREG_CS,
|
---|
1438 | kIemNativeGstReg_SegBaseLast = kIemNativeGstReg_SegBaseFirst + 5,
|
---|
1439 | kIemNativeGstReg_SegAttribFirst,
|
---|
1440 | kIemNativeGstReg_SegAttribLast = kIemNativeGstReg_SegAttribFirst + 5,
|
---|
1441 | kIemNativeGstReg_SegLimitFirst,
|
---|
1442 | kIemNativeGstReg_SegLimitLast = kIemNativeGstReg_SegLimitFirst + 5,
|
---|
1443 | kIemNativeGstReg_SegSelFirst,
|
---|
1444 | kIemNativeGstReg_SegSelLast = kIemNativeGstReg_SegSelFirst + 5,
|
---|
1445 | kIemNativeGstReg_Xcr0,
|
---|
1446 | kIemNativeGstReg_MxCsr,
|
---|
1447 | kIemNativeGstReg_EFlags, /**< 32-bit, includes internal flags. */
|
---|
1448 | /* 6 entry gap for liveness EFlags subdivisions. */
|
---|
1449 | kIemNativeGstReg_Pc = kIemNativeGstReg_EFlags + 7,
|
---|
1450 | kIemNativeGstReg_End
|
---|
1451 | } IEMNATIVEGSTREG;
|
---|
1452 | AssertCompile((int)kIemNativeGstReg_SegLimitFirst == 32);
|
---|
1453 | AssertCompile((UINT64_C(0x7f) << kIemNativeGstReg_EFlags) == IEMLIVENESSBIT_ALL_EFL_MASK);
|
---|
1454 | AssertCompile(RT_BIT_64(kIemNativeGstReg_Pc) - UINT64_C(1) == IEMLIVENESSBIT_MASK);
|
---|
1455 |
|
---|
1456 | /** @name Helpers for converting register numbers to IEMNATIVEGSTREG values.
|
---|
1457 | * @{ */
|
---|
1458 | #define IEMNATIVEGSTREG_GPR(a_iGpr) ((IEMNATIVEGSTREG)(kIemNativeGstReg_GprFirst + (a_iGpr) ))
|
---|
1459 | #define IEMNATIVEGSTREG_SEG_SEL(a_iSegReg) ((IEMNATIVEGSTREG)(kIemNativeGstReg_SegSelFirst + (a_iSegReg) ))
|
---|
1460 | #define IEMNATIVEGSTREG_SEG_BASE(a_iSegReg) ((IEMNATIVEGSTREG)(kIemNativeGstReg_SegBaseFirst + (a_iSegReg) ))
|
---|
1461 | #define IEMNATIVEGSTREG_SEG_LIMIT(a_iSegReg) ((IEMNATIVEGSTREG)(kIemNativeGstReg_SegLimitFirst + (a_iSegReg) ))
|
---|
1462 | #define IEMNATIVEGSTREG_SEG_ATTRIB(a_iSegReg) ((IEMNATIVEGSTREG)(kIemNativeGstReg_SegAttribFirst + (a_iSegReg) ))
|
---|
1463 | /** @} */
|
---|
1464 |
|
---|
1465 |
|
---|
1466 | /**
|
---|
1467 | * Guest registers that can be shadowed in host SIMD registers.
|
---|
1468 | *
|
---|
1469 | * @todo r=aeichner Liveness tracking
|
---|
1470 | * @todo r=aeichner Given that we can only track xmm/ymm here does this actually make sense?
|
---|
1471 | */
|
---|
1472 | typedef enum IEMNATIVEGSTSIMDREG : uint8_t
|
---|
1473 | {
|
---|
1474 | kIemNativeGstSimdReg_SimdRegFirst = 0,
|
---|
1475 | kIemNativeGstSimdReg_SimdRegLast = kIemNativeGstSimdReg_SimdRegFirst + 15,
|
---|
1476 | kIemNativeGstSimdReg_End
|
---|
1477 | } IEMNATIVEGSTSIMDREG;
|
---|
1478 |
|
---|
1479 | /** @name Helpers for converting register numbers to IEMNATIVEGSTSIMDREG values.
|
---|
1480 | * @{ */
|
---|
1481 | #define IEMNATIVEGSTSIMDREG_SIMD(a_iSimdReg) ((IEMNATIVEGSTSIMDREG)(kIemNativeGstSimdReg_SimdRegFirst + (a_iSimdReg)))
|
---|
1482 | /** @} */
|
---|
1483 |
|
---|
1484 | /**
|
---|
1485 | * The Load/store size for a SIMD guest register.
|
---|
1486 | */
|
---|
1487 | typedef enum IEMNATIVEGSTSIMDREGLDSTSZ : uint8_t
|
---|
1488 | {
|
---|
1489 | /** Invalid size. */
|
---|
1490 | kIemNativeGstSimdRegLdStSz_Invalid = 0,
|
---|
1491 | /** Loads the low 128-bit of a guest SIMD register. */
|
---|
1492 | kIemNativeGstSimdRegLdStSz_Low128,
|
---|
1493 | /** Loads the high 128-bit of a guest SIMD register. */
|
---|
1494 | kIemNativeGstSimdRegLdStSz_High128,
|
---|
1495 | /** Loads the whole 256-bits of a guest SIMD register. */
|
---|
1496 | kIemNativeGstSimdRegLdStSz_256,
|
---|
1497 | /** End value. */
|
---|
1498 | kIemNativeGstSimdRegLdStSz_End
|
---|
1499 | } IEMNATIVEGSTSIMDREGLDSTSZ;
|
---|
1500 |
|
---|
1501 |
|
---|
1502 | /**
|
---|
1503 | * Intended use statement for iemNativeRegAllocTmpForGuestReg().
|
---|
1504 | */
|
---|
1505 | typedef enum IEMNATIVEGSTREGUSE
|
---|
1506 | {
|
---|
1507 | /** The usage is read-only, the register holding the guest register
|
---|
1508 | * shadow copy will not be modified by the caller. */
|
---|
1509 | kIemNativeGstRegUse_ReadOnly = 0,
|
---|
1510 | /** The caller will update the guest register (think: PC += cbInstr).
|
---|
1511 | * The guest shadow copy will follow the returned register. */
|
---|
1512 | kIemNativeGstRegUse_ForUpdate,
|
---|
1513 | /** The call will put an entirely new value in the guest register, so
|
---|
1514 | * if new register is allocate it will be returned uninitialized. */
|
---|
1515 | kIemNativeGstRegUse_ForFullWrite,
|
---|
1516 | /** The caller will use the guest register value as input in a calculation
|
---|
1517 | * and the host register will be modified.
|
---|
1518 | * This means that the returned host register will not be marked as a shadow
|
---|
1519 | * copy of the guest register. */
|
---|
1520 | kIemNativeGstRegUse_Calculation
|
---|
1521 | } IEMNATIVEGSTREGUSE;
|
---|
1522 |
|
---|
1523 | /**
|
---|
1524 | * Guest registers (classes) that can be referenced.
|
---|
1525 | */
|
---|
1526 | typedef enum IEMNATIVEGSTREGREF : uint8_t
|
---|
1527 | {
|
---|
1528 | kIemNativeGstRegRef_Invalid = 0,
|
---|
1529 | kIemNativeGstRegRef_Gpr,
|
---|
1530 | kIemNativeGstRegRef_GprHighByte, /**< AH, CH, DH, BH*/
|
---|
1531 | kIemNativeGstRegRef_EFlags,
|
---|
1532 | kIemNativeGstRegRef_MxCsr,
|
---|
1533 | kIemNativeGstRegRef_FpuReg,
|
---|
1534 | kIemNativeGstRegRef_MReg,
|
---|
1535 | kIemNativeGstRegRef_XReg,
|
---|
1536 | kIemNativeGstRegRef_X87,
|
---|
1537 | kIemNativeGstRegRef_XState,
|
---|
1538 | //kIemNativeGstRegRef_YReg, - doesn't work.
|
---|
1539 | kIemNativeGstRegRef_End
|
---|
1540 | } IEMNATIVEGSTREGREF;
|
---|
1541 |
|
---|
1542 |
|
---|
1543 | /** Variable kinds. */
|
---|
1544 | typedef enum IEMNATIVEVARKIND : uint8_t
|
---|
1545 | {
|
---|
1546 | /** Customary invalid zero value. */
|
---|
1547 | kIemNativeVarKind_Invalid = 0,
|
---|
1548 | /** This is either in a register or on the stack. */
|
---|
1549 | kIemNativeVarKind_Stack,
|
---|
1550 | /** Immediate value - loaded into register when needed, or can live on the
|
---|
1551 | * stack if referenced (in theory). */
|
---|
1552 | kIemNativeVarKind_Immediate,
|
---|
1553 | /** Variable reference - loaded into register when needed, never stack. */
|
---|
1554 | kIemNativeVarKind_VarRef,
|
---|
1555 | /** Guest register reference - loaded into register when needed, never stack. */
|
---|
1556 | kIemNativeVarKind_GstRegRef,
|
---|
1557 | /** End of valid values. */
|
---|
1558 | kIemNativeVarKind_End
|
---|
1559 | } IEMNATIVEVARKIND;
|
---|
1560 |
|
---|
1561 |
|
---|
1562 | /** Variable or argument. */
|
---|
1563 | typedef struct IEMNATIVEVAR
|
---|
1564 | {
|
---|
1565 | RT_GCC_EXTENSION
|
---|
1566 | union
|
---|
1567 | {
|
---|
1568 | struct
|
---|
1569 | {
|
---|
1570 | /** The kind of variable. */
|
---|
1571 | IEMNATIVEVARKIND enmKind;
|
---|
1572 | /** The variable size in bytes. */
|
---|
1573 | uint8_t cbVar;
|
---|
1574 | /** Set if the registered is currently used exclusively, false if the
|
---|
1575 | * variable is idle and the register can be grabbed. */
|
---|
1576 | bool fRegAcquired;
|
---|
1577 | /** Flag whether this variable is held in a SIMD register (only supported for
|
---|
1578 | * 128-bit and 256-bit variables), only valid when idxReg is not UINT8_MAX. */
|
---|
1579 | bool fSimdReg;
|
---|
1580 | };
|
---|
1581 | uint32_t u32Init0; /**< Init optimzation - cbVar is set, the other are initialized with zeros. */
|
---|
1582 | };
|
---|
1583 |
|
---|
1584 | RT_GCC_EXTENSION
|
---|
1585 | union
|
---|
1586 | {
|
---|
1587 | struct
|
---|
1588 | {
|
---|
1589 | /** The host register allocated for the variable, UINT8_MAX if not. */
|
---|
1590 | uint8_t idxReg;
|
---|
1591 | /** The argument number if argument, UINT8_MAX if regular variable. */
|
---|
1592 | uint8_t uArgNo;
|
---|
1593 | /** The first stack slot (uint64_t), except for immediate and references
|
---|
1594 | * where it usually is UINT8_MAX. This is allocated lazily, so if a variable
|
---|
1595 | * has a stack slot it has been initialized and has a value. Unused variables
|
---|
1596 | * has neither a stack slot nor a host register assignment. */
|
---|
1597 | uint8_t idxStackSlot;
|
---|
1598 | /** If referenced, the index (unpacked) of the variable referencing this one,
|
---|
1599 | * otherwise UINT8_MAX. A referenced variable must only be placed on the stack
|
---|
1600 | * and must be either kIemNativeVarKind_Stack or kIemNativeVarKind_Immediate. */
|
---|
1601 | uint8_t idxReferrerVar;
|
---|
1602 | };
|
---|
1603 | uint32_t u32Init1; /**< Init optimization; all these are initialized to 0xff. */
|
---|
1604 | };
|
---|
1605 |
|
---|
1606 | union
|
---|
1607 | {
|
---|
1608 | /** kIemNativeVarKind_Immediate: The immediate value. */
|
---|
1609 | uint64_t uValue;
|
---|
1610 | /** kIemNativeVarKind_VarRef: The index (unpacked) of the variable being referenced. */
|
---|
1611 | uint8_t idxRefVar;
|
---|
1612 | /** kIemNativeVarKind_GstRegRef: The guest register being referrenced. */
|
---|
1613 | struct
|
---|
1614 | {
|
---|
1615 | /** The class of register. */
|
---|
1616 | IEMNATIVEGSTREGREF enmClass;
|
---|
1617 | /** Index within the class. */
|
---|
1618 | uint8_t idx;
|
---|
1619 | } GstRegRef;
|
---|
1620 | } u;
|
---|
1621 | } IEMNATIVEVAR;
|
---|
1622 | AssertCompileSize(IEMNATIVEVAR, 16);
|
---|
1623 | /** Pointer to a variable or argument. */
|
---|
1624 | typedef IEMNATIVEVAR *PIEMNATIVEVAR;
|
---|
1625 | /** Pointer to a const variable or argument. */
|
---|
1626 | typedef IEMNATIVEVAR const *PCIEMNATIVEVAR;
|
---|
1627 |
|
---|
1628 | /** What is being kept in a host register. */
|
---|
1629 | typedef enum IEMNATIVEWHAT : uint8_t
|
---|
1630 | {
|
---|
1631 | /** The traditional invalid zero value. */
|
---|
1632 | kIemNativeWhat_Invalid = 0,
|
---|
1633 | /** Mapping a variable (IEMNATIVEHSTREG::idxVar). */
|
---|
1634 | kIemNativeWhat_Var,
|
---|
1635 | /** Temporary register, this is typically freed when a MC completes. */
|
---|
1636 | kIemNativeWhat_Tmp,
|
---|
1637 | /** Call argument w/o a variable mapping. This is free (via
|
---|
1638 | * IEMNATIVE_CALL_VOLATILE_GREG_MASK) after the call is emitted. */
|
---|
1639 | kIemNativeWhat_Arg,
|
---|
1640 | /** Return status code.
|
---|
1641 | * @todo not sure if we need this... */
|
---|
1642 | kIemNativeWhat_rc,
|
---|
1643 | /** The fixed pVCpu (PVMCPUCC) register.
|
---|
1644 | * @todo consider offsetting this on amd64 to use negative offsets to access
|
---|
1645 | * more members using 8-byte disp. */
|
---|
1646 | kIemNativeWhat_pVCpuFixed,
|
---|
1647 | /** The fixed pCtx (PCPUMCTX) register.
|
---|
1648 | * @todo consider offsetting this on amd64 to use negative offsets to access
|
---|
1649 | * more members using 8-byte disp. */
|
---|
1650 | kIemNativeWhat_pCtxFixed,
|
---|
1651 | /** Fixed temporary register. */
|
---|
1652 | kIemNativeWhat_FixedTmp,
|
---|
1653 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
1654 | /** Shadow RIP for the delayed RIP updating debugging. */
|
---|
1655 | kIemNativeWhat_PcShadow,
|
---|
1656 | #endif
|
---|
1657 | /** Register reserved by the CPU or OS architecture. */
|
---|
1658 | kIemNativeWhat_FixedReserved,
|
---|
1659 | /** End of valid values. */
|
---|
1660 | kIemNativeWhat_End
|
---|
1661 | } IEMNATIVEWHAT;
|
---|
1662 |
|
---|
1663 | /**
|
---|
1664 | * Host general register entry.
|
---|
1665 | *
|
---|
1666 | * The actual allocation status is kept in IEMRECOMPILERSTATE::bmHstRegs.
|
---|
1667 | *
|
---|
1668 | * @todo Track immediate values in host registers similarlly to how we track the
|
---|
1669 | * guest register shadow copies. For it to be real helpful, though,
|
---|
1670 | * we probably need to know which will be reused and put them into
|
---|
1671 | * non-volatile registers, otherwise it's going to be more or less
|
---|
1672 | * restricted to an instruction or two.
|
---|
1673 | */
|
---|
1674 | typedef struct IEMNATIVEHSTREG
|
---|
1675 | {
|
---|
1676 | /** Set of guest registers this one shadows.
|
---|
1677 | *
|
---|
1678 | * Using a bitmap here so we can designate the same host register as a copy
|
---|
1679 | * for more than one guest register. This is expected to be useful in
|
---|
1680 | * situations where one value is copied to several registers in a sequence.
|
---|
1681 | * If the mapping is 1:1, then we'd have to pick which side of a 'MOV SRC,DST'
|
---|
1682 | * sequence we'd want to let this register follow to be a copy of and there
|
---|
1683 | * will always be places where we'd be picking the wrong one.
|
---|
1684 | */
|
---|
1685 | uint64_t fGstRegShadows;
|
---|
1686 | /** What is being kept in this register. */
|
---|
1687 | IEMNATIVEWHAT enmWhat;
|
---|
1688 | /** Variable index (packed) if holding a variable, otherwise UINT8_MAX. */
|
---|
1689 | uint8_t idxVar;
|
---|
1690 | /** Stack slot assigned by iemNativeVarSaveVolatileRegsPreHlpCall and freed
|
---|
1691 | * by iemNativeVarRestoreVolatileRegsPostHlpCall. This is not valid outside
|
---|
1692 | * that scope. */
|
---|
1693 | uint8_t idxStackSlot;
|
---|
1694 | /** Alignment padding. */
|
---|
1695 | uint8_t abAlign[5];
|
---|
1696 | } IEMNATIVEHSTREG;
|
---|
1697 |
|
---|
1698 |
|
---|
1699 | /**
|
---|
1700 | * Host SIMD register entry - this tracks a virtual 256-bit register split into two 128-bit
|
---|
1701 | * halves, on architectures where there is no 256-bit register available this entry will track
|
---|
1702 | * two adjacent 128-bit host registers.
|
---|
1703 | *
|
---|
1704 | * The actual allocation status is kept in IEMRECOMPILERSTATE::bmHstSimdRegs.
|
---|
1705 | */
|
---|
1706 | typedef struct IEMNATIVEHSTSIMDREG
|
---|
1707 | {
|
---|
1708 | /** Set of guest registers this one shadows.
|
---|
1709 | *
|
---|
1710 | * Using a bitmap here so we can designate the same host register as a copy
|
---|
1711 | * for more than one guest register. This is expected to be useful in
|
---|
1712 | * situations where one value is copied to several registers in a sequence.
|
---|
1713 | * If the mapping is 1:1, then we'd have to pick which side of a 'MOV SRC,DST'
|
---|
1714 | * sequence we'd want to let this register follow to be a copy of and there
|
---|
1715 | * will always be places where we'd be picking the wrong one.
|
---|
1716 | */
|
---|
1717 | uint64_t fGstRegShadows;
|
---|
1718 | /** What is being kept in this register. */
|
---|
1719 | IEMNATIVEWHAT enmWhat;
|
---|
1720 | /** Variable index (packed) if holding a variable, otherwise UINT8_MAX. */
|
---|
1721 | uint8_t idxVar;
|
---|
1722 | /** Flag what is currently loaded, low 128-bits, high 128-bits or complete 256-bits. */
|
---|
1723 | IEMNATIVEGSTSIMDREGLDSTSZ enmLoaded;
|
---|
1724 | /** Alignment padding. */
|
---|
1725 | uint8_t abAlign[5];
|
---|
1726 | } IEMNATIVEHSTSIMDREG;
|
---|
1727 |
|
---|
1728 |
|
---|
1729 | /**
|
---|
1730 | * Core state for the native recompiler, that is, things that needs careful
|
---|
1731 | * handling when dealing with branches.
|
---|
1732 | */
|
---|
1733 | typedef struct IEMNATIVECORESTATE
|
---|
1734 | {
|
---|
1735 | /** Allocation bitmap for aHstRegs. */
|
---|
1736 | uint32_t bmHstRegs;
|
---|
1737 |
|
---|
1738 | /** Bitmap marking which host register contains guest register shadow copies.
|
---|
1739 | * This is used during register allocation to try preserve copies. */
|
---|
1740 | uint32_t bmHstRegsWithGstShadow;
|
---|
1741 | /** Bitmap marking valid entries in aidxGstRegShadows. */
|
---|
1742 | uint64_t bmGstRegShadows;
|
---|
1743 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
1744 | /** Bitmap marking the shadowed guest register as dirty and needing writeback when flushing. */
|
---|
1745 | uint64_t bmGstRegShadowDirty;
|
---|
1746 | #endif
|
---|
1747 |
|
---|
1748 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
1749 | /** The current instruction offset in bytes from when the guest program counter
|
---|
1750 | * was updated last. Used for delaying the write to the guest context program counter
|
---|
1751 | * as long as possible. */
|
---|
1752 | int64_t offPc;
|
---|
1753 | # ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING_DEBUG
|
---|
1754 | /** Set after we've loaded PC into uPcUpdatingDebug at the first update. */
|
---|
1755 | bool fDebugPcInitialized;
|
---|
1756 | # endif
|
---|
1757 | #endif
|
---|
1758 |
|
---|
1759 | /** Allocation bitmap for aHstSimdRegs. */
|
---|
1760 | uint32_t bmHstSimdRegs;
|
---|
1761 |
|
---|
1762 | /** Bitmap marking which host SIMD register contains guest SIMD register shadow copies.
|
---|
1763 | * This is used during register allocation to try preserve copies. */
|
---|
1764 | uint32_t bmHstSimdRegsWithGstShadow;
|
---|
1765 | /** Bitmap marking valid entries in aidxSimdGstRegShadows. */
|
---|
1766 | uint64_t bmGstSimdRegShadows;
|
---|
1767 | /** Bitmap marking whether the low 128-bit of the shadowed guest register are dirty and need writeback. */
|
---|
1768 | uint64_t bmGstSimdRegShadowDirtyLo128;
|
---|
1769 | /** Bitmap marking whether the high 128-bit of the shadowed guest register are dirty and need writeback. */
|
---|
1770 | uint64_t bmGstSimdRegShadowDirtyHi128;
|
---|
1771 |
|
---|
1772 | union
|
---|
1773 | {
|
---|
1774 | /** Index of variable (unpacked) arguments, UINT8_MAX if not valid. */
|
---|
1775 | uint8_t aidxArgVars[8];
|
---|
1776 | /** For more efficient resetting. */
|
---|
1777 | uint64_t u64ArgVars;
|
---|
1778 | };
|
---|
1779 |
|
---|
1780 | /** Allocation bitmap for the stack. */
|
---|
1781 | uint32_t bmStack;
|
---|
1782 | /** Allocation bitmap for aVars. */
|
---|
1783 | uint32_t bmVars;
|
---|
1784 |
|
---|
1785 | /** Maps a guest register to a host GPR (index by IEMNATIVEGSTREG).
|
---|
1786 | * Entries are only valid if the corresponding bit in bmGstRegShadows is set.
|
---|
1787 | * (A shadow copy of a guest register can only be held in a one host register,
|
---|
1788 | * there are no duplicate copies or ambiguities like that). */
|
---|
1789 | uint8_t aidxGstRegShadows[kIemNativeGstReg_End];
|
---|
1790 | /** Maps a guest SIMD register to a host SIMD register (index by IEMNATIVEGSTSIMDREG).
|
---|
1791 | * Entries are only valid if the corresponding bit in bmGstSimdRegShadows is set.
|
---|
1792 | * (A shadow copy of a guest register can only be held in a one host register,
|
---|
1793 | * there are no duplicate copies or ambiguities like that). */
|
---|
1794 | uint8_t aidxGstSimdRegShadows[kIemNativeGstSimdReg_End];
|
---|
1795 |
|
---|
1796 | /** Host register allocation tracking. */
|
---|
1797 | IEMNATIVEHSTREG aHstRegs[IEMNATIVE_HST_GREG_COUNT];
|
---|
1798 | /** Host SIMD register allocation tracking. */
|
---|
1799 | IEMNATIVEHSTSIMDREG aHstSimdRegs[IEMNATIVE_HST_SIMD_REG_COUNT];
|
---|
1800 |
|
---|
1801 | /** Variables and arguments. */
|
---|
1802 | IEMNATIVEVAR aVars[9];
|
---|
1803 | } IEMNATIVECORESTATE;
|
---|
1804 | /** Pointer to core state. */
|
---|
1805 | typedef IEMNATIVECORESTATE *PIEMNATIVECORESTATE;
|
---|
1806 | /** Pointer to const core state. */
|
---|
1807 | typedef IEMNATIVECORESTATE const *PCIEMNATIVECORESTATE;
|
---|
1808 |
|
---|
1809 | /** @def IEMNATIVE_VAR_IDX_UNPACK
|
---|
1810 | * @returns Index into IEMNATIVECORESTATE::aVars.
|
---|
1811 | * @param a_idxVar Variable index w/ magic (in strict builds).
|
---|
1812 | */
|
---|
1813 | /** @def IEMNATIVE_VAR_IDX_PACK
|
---|
1814 | * @returns Variable index w/ magic (in strict builds).
|
---|
1815 | * @param a_idxVar Index into IEMNATIVECORESTATE::aVars.
|
---|
1816 | */
|
---|
1817 | #ifdef VBOX_STRICT
|
---|
1818 | # define IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) ((a_idxVar) & IEMNATIVE_VAR_IDX_MASK)
|
---|
1819 | # define IEMNATIVE_VAR_IDX_PACK(a_idxVar) ((a_idxVar) | IEMNATIVE_VAR_IDX_MAGIC)
|
---|
1820 | # define IEMNATIVE_VAR_IDX_MAGIC UINT8_C(0xd0)
|
---|
1821 | # define IEMNATIVE_VAR_IDX_MAGIC_MASK UINT8_C(0xf0)
|
---|
1822 | # define IEMNATIVE_VAR_IDX_MASK UINT8_C(0x0f)
|
---|
1823 | #else
|
---|
1824 | # define IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) (a_idxVar)
|
---|
1825 | # define IEMNATIVE_VAR_IDX_PACK(a_idxVar) (a_idxVar)
|
---|
1826 | #endif
|
---|
1827 |
|
---|
1828 |
|
---|
1829 | /** Clear the dirty state of the given guest SIMD register. */
|
---|
1830 | #define IEMNATIVE_SIMD_REG_STATE_CLR_DIRTY(a_pReNative, a_iSimdReg) \
|
---|
1831 | do { \
|
---|
1832 | (a_pReNative)->Core.bmGstSimdRegShadowDirtyLo128 &= ~RT_BIT_64(a_iSimdReg); \
|
---|
1833 | (a_pReNative)->Core.bmGstSimdRegShadowDirtyHi128 &= ~RT_BIT_64(a_iSimdReg); \
|
---|
1834 | } while (0)
|
---|
1835 |
|
---|
1836 | /** Returns whether the low 128-bits of the given guest SIMD register are dirty. */
|
---|
1837 | #define IEMNATIVE_SIMD_REG_STATE_IS_DIRTY_LO_U128(a_pReNative, a_iSimdReg) \
|
---|
1838 | RT_BOOL((a_pReNative)->Core.bmGstSimdRegShadowDirtyLo128 & RT_BIT_64(a_iSimdReg))
|
---|
1839 | /** Returns whether the high 128-bits of the given guest SIMD register are dirty. */
|
---|
1840 | #define IEMNATIVE_SIMD_REG_STATE_IS_DIRTY_HI_U128(a_pReNative, a_iSimdReg) \
|
---|
1841 | RT_BOOL((a_pReNative)->Core.bmGstSimdRegShadowDirtyHi128 & RT_BIT_64(a_iSimdReg))
|
---|
1842 | /** Returns whether the given guest SIMD register is dirty. */
|
---|
1843 | #define IEMNATIVE_SIMD_REG_STATE_IS_DIRTY_U256(a_pReNative, a_iSimdReg) \
|
---|
1844 | RT_BOOL(((a_pReNative)->Core.bmGstSimdRegShadowDirtyLo128 | (a_pReNative)->Core.bmGstSimdRegShadowDirtyHi128) & RT_BIT_64(a_iSimdReg))
|
---|
1845 |
|
---|
1846 | /** Set the low 128-bits of the given guest SIMD register to the dirty state. */
|
---|
1847 | #define IEMNATIVE_SIMD_REG_STATE_SET_DIRTY_LO_U128(a_pReNative, a_iSimdReg) \
|
---|
1848 | ((a_pReNative)->Core.bmGstSimdRegShadowDirtyLo128 |= RT_BIT_64(a_iSimdReg))
|
---|
1849 | /** Set the high 128-bits of the given guest SIMD register to the dirty state. */
|
---|
1850 | #define IEMNATIVE_SIMD_REG_STATE_SET_DIRTY_HI_U128(a_pReNative, a_iSimdReg) \
|
---|
1851 | ((a_pReNative)->Core.bmGstSimdRegShadowDirtyHi128 |= RT_BIT_64(a_iSimdReg))
|
---|
1852 |
|
---|
1853 | /** Flag for indicating that IEM_MC_MAYBE_RAISE_DEVICE_NOT_AVAILABLE() has emitted code in the current TB. */
|
---|
1854 | #define IEMNATIVE_SIMD_RAISE_XCPT_CHECKS_EMITTED_MAYBE_DEVICE_NOT_AVAILABLE RT_BIT_32(0)
|
---|
1855 | /** Flag for indicating that IEM_MC_MAYBE_RAISE_DEVICE_NOT_AVAILABLE() has emitted code in the current TB. */
|
---|
1856 | #define IEMNATIVE_SIMD_RAISE_XCPT_CHECKS_EMITTED_MAYBE_WAIT_DEVICE_NOT_AVAILABLE RT_BIT_32(1)
|
---|
1857 | /** Flag for indicating that IEM_MC_MAYBE_RAISE_SSE_RELATED_XCPT() has emitted code in the current TB. */
|
---|
1858 | #define IEMNATIVE_SIMD_RAISE_XCPT_CHECKS_EMITTED_MAYBE_SSE RT_BIT_32(2)
|
---|
1859 | /** Flag for indicating that IEM_MC_MAYBE_RAISE_AVX_RELATED_XCPT() has emitted code in the current TB. */
|
---|
1860 | #define IEMNATIVE_SIMD_RAISE_XCPT_CHECKS_EMITTED_MAYBE_AVX RT_BIT_32(3)
|
---|
1861 | # ifdef IEMNATIVE_WITH_SIMD_FP_NATIVE_EMITTERS
|
---|
1862 | /** Flag indicating that the guest MXCSR was synced to the host floating point control register. */
|
---|
1863 | # define IEMNATIVE_SIMD_HOST_FP_CTRL_REG_SYNCED RT_BIT_32(4)
|
---|
1864 | /** Flag indicating whether the host floating point control register was saved before overwriting it. */
|
---|
1865 | # define IEMNATIVE_SIMD_HOST_FP_CTRL_REG_SAVED RT_BIT_32(5)
|
---|
1866 | #endif
|
---|
1867 |
|
---|
1868 |
|
---|
1869 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
1870 | typedef enum IEMNATIVE_POSTPONED_EFL_OP_T : uint8_t
|
---|
1871 | {
|
---|
1872 | kIemNativePostponedEflOp_Invalid = 0,
|
---|
1873 | /** Logical operation.
|
---|
1874 | * Operands: result register.
|
---|
1875 | * @note This clears OF, CF and (undefined) AF, thus no need for inputs. */
|
---|
1876 | kIemNativePostponedEflOp_Logical,
|
---|
1877 | kIemNativePostponedEflOp_End
|
---|
1878 | } IEMNATIVE_POSTPONED_EFL_OP_T;
|
---|
1879 | #endif /* IEMNATIVE_WITH_EFLAGS_POSTPONING */
|
---|
1880 |
|
---|
1881 | /**
|
---|
1882 | * Conditional stack entry.
|
---|
1883 | */
|
---|
1884 | typedef struct IEMNATIVECOND
|
---|
1885 | {
|
---|
1886 | /** Set if we're in the "else" part, clear if we're in the "if" before it. */
|
---|
1887 | bool fInElse;
|
---|
1888 | union
|
---|
1889 | {
|
---|
1890 | RT_GCC_EXTENSION struct
|
---|
1891 | {
|
---|
1892 | /** Set if the if-block unconditionally exited the TB. */
|
---|
1893 | bool fIfExitTb;
|
---|
1894 | /** Set if the else-block unconditionally exited the TB. */
|
---|
1895 | bool fElseExitTb;
|
---|
1896 | };
|
---|
1897 | /** Indexed by fInElse. */
|
---|
1898 | bool afExitTb[2];
|
---|
1899 | };
|
---|
1900 | bool afPadding[5];
|
---|
1901 | /** The label for the IEM_MC_ELSE. */
|
---|
1902 | uint32_t idxLabelElse;
|
---|
1903 | /** The label for the IEM_MC_ENDIF. */
|
---|
1904 | uint32_t idxLabelEndIf;
|
---|
1905 | /** The initial state snapshot as the if-block starts executing. */
|
---|
1906 | IEMNATIVECORESTATE InitialState;
|
---|
1907 | /** The state snapshot at the end of the if-block. */
|
---|
1908 | IEMNATIVECORESTATE IfFinalState;
|
---|
1909 | } IEMNATIVECOND;
|
---|
1910 | /** Pointer to a condition stack entry. */
|
---|
1911 | typedef IEMNATIVECOND *PIEMNATIVECOND;
|
---|
1912 |
|
---|
1913 |
|
---|
1914 | /**
|
---|
1915 | * Native recompiler state.
|
---|
1916 | */
|
---|
1917 | typedef struct IEMRECOMPILERSTATE
|
---|
1918 | {
|
---|
1919 | /** Size of the buffer that pbNativeRecompileBufR3 points to in
|
---|
1920 | * IEMNATIVEINSTR units. */
|
---|
1921 | uint32_t cInstrBufAlloc;
|
---|
1922 | #ifdef VBOX_STRICT
|
---|
1923 | /** Strict: How far the last iemNativeInstrBufEnsure() checked. */
|
---|
1924 | uint32_t offInstrBufChecked;
|
---|
1925 | #else
|
---|
1926 | uint32_t uPadding1; /* We don't keep track of the size here... */
|
---|
1927 | #endif
|
---|
1928 | /** Fixed temporary code buffer for native recompilation. */
|
---|
1929 | PIEMNATIVEINSTR pInstrBuf;
|
---|
1930 |
|
---|
1931 | /** Bitmaps with the label types used. */
|
---|
1932 | uint64_t bmLabelTypes;
|
---|
1933 | /** Actual number of labels in paLabels. */
|
---|
1934 | uint32_t cLabels;
|
---|
1935 | /** Max number of entries allowed in paLabels before reallocating it. */
|
---|
1936 | uint32_t cLabelsAlloc;
|
---|
1937 | /** Labels defined while recompiling (referenced by fixups). */
|
---|
1938 | PIEMNATIVELABEL paLabels;
|
---|
1939 | /** Array with indexes of unique labels (uData always 0). */
|
---|
1940 | uint32_t aidxUniqueLabels[kIemNativeLabelType_FirstWithMultipleInstances];
|
---|
1941 |
|
---|
1942 | /** Actual number of fixups paFixups. */
|
---|
1943 | uint32_t cFixups;
|
---|
1944 | /** Max number of entries allowed in paFixups before reallocating it. */
|
---|
1945 | uint32_t cFixupsAlloc;
|
---|
1946 | /** Buffer used by the recompiler for recording fixups when generating code. */
|
---|
1947 | PIEMNATIVEFIXUP paFixups;
|
---|
1948 |
|
---|
1949 | /** Actual number of fixups in paTbExitFixups. */
|
---|
1950 | uint32_t cTbExitFixups;
|
---|
1951 | /** Max number of entries allowed in paTbExitFixups before reallocating it. */
|
---|
1952 | uint32_t cTbExitFixupsAlloc;
|
---|
1953 | /** Buffer used by the recompiler for recording fixups when generating code. */
|
---|
1954 | PIEMNATIVEEXITFIXUP paTbExitFixups;
|
---|
1955 |
|
---|
1956 | #if defined(IEMNATIVE_WITH_TB_DEBUG_INFO) || defined(VBOX_WITH_STATISTICS)
|
---|
1957 | /** Statistics: The idxInstr+1 value at the last PC update. */
|
---|
1958 | uint8_t idxInstrPlusOneOfLastPcUpdate;
|
---|
1959 | #endif
|
---|
1960 |
|
---|
1961 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
1962 | /** Number of debug info entries allocated for pDbgInfo. */
|
---|
1963 | uint32_t cDbgInfoAlloc;
|
---|
1964 | /** Debug info. */
|
---|
1965 | PIEMTBDBG pDbgInfo;
|
---|
1966 | #endif
|
---|
1967 |
|
---|
1968 | #ifdef IEMNATIVE_WITH_LIVENESS_ANALYSIS
|
---|
1969 | /** The current call index (liveness array and threaded calls in TB). */
|
---|
1970 | uint32_t idxCurCall;
|
---|
1971 | /** Number of liveness entries allocated. */
|
---|
1972 | uint32_t cLivenessEntriesAlloc;
|
---|
1973 | /** Liveness entries for all the calls in the TB begin recompiled.
|
---|
1974 | * The entry for idxCurCall contains the info for what the next call will
|
---|
1975 | * require wrt registers. (Which means the last entry is the initial liveness
|
---|
1976 | * state.) */
|
---|
1977 | PIEMLIVENESSENTRY paLivenessEntries;
|
---|
1978 | #endif
|
---|
1979 |
|
---|
1980 | /** The translation block being recompiled. */
|
---|
1981 | PCIEMTB pTbOrg;
|
---|
1982 | /** The VMCPU structure of the EMT. */
|
---|
1983 | PVMCPUCC pVCpu;
|
---|
1984 |
|
---|
1985 | /** Condition sequence number (for generating unique labels). */
|
---|
1986 | uint16_t uCondSeqNo;
|
---|
1987 | /** Check IRQ sequence number (for generating unique labels). */
|
---|
1988 | uint16_t uCheckIrqSeqNo;
|
---|
1989 | /** TLB load sequence number (for generating unique labels). */
|
---|
1990 | uint16_t uTlbSeqNo;
|
---|
1991 | /** The current condition stack depth (aCondStack). */
|
---|
1992 | uint8_t cCondDepth;
|
---|
1993 |
|
---|
1994 | /** The argument count + hidden regs from the IEM_MC_BEGIN_EX statement. */
|
---|
1995 | uint8_t cArgsX;
|
---|
1996 | /** The IEM_CIMPL_F_XXX flags from the IEM_MC_BEGIN statement. */
|
---|
1997 | uint32_t fCImpl;
|
---|
1998 | /** The IEM_MC_F_XXX flags from the IEM_MC_BEGIN statement. */
|
---|
1999 | uint32_t fMc;
|
---|
2000 | /** The expected IEMCPU::fExec value for the current call/instruction. */
|
---|
2001 | uint32_t fExec;
|
---|
2002 | /** IEMNATIVE_SIMD_RAISE_XCPT_CHECKS_EMITTED_XXX flags for exception flags
|
---|
2003 | * we only emit once per TB (or when the cr0/cr4/xcr0 register changes).
|
---|
2004 | *
|
---|
2005 | * This is an optimization because these control registers can only be changed from
|
---|
2006 | * by calling a C helper we can catch. Should reduce the number of instructions in a TB
|
---|
2007 | * consisting of multiple SIMD instructions.
|
---|
2008 | */
|
---|
2009 | uint32_t fSimdRaiseXcptChecksEmitted;
|
---|
2010 | /** The call number of the last CheckIrq, UINT32_MAX if not seen. */
|
---|
2011 | uint32_t idxLastCheckIrqCallNo;
|
---|
2012 | #ifdef IEMNATIVE_WITH_EFLAGS_SKIPPING
|
---|
2013 | uint32_t fSkippingEFlags;
|
---|
2014 | #endif
|
---|
2015 | #ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
2016 | struct
|
---|
2017 | {
|
---|
2018 | /** EFLAGS status bits that we're currently postponing the calculcation of. */
|
---|
2019 | uint32_t fEFlags;
|
---|
2020 | /** The postponed EFLAGS status bits calculation operation. */
|
---|
2021 | IEMNATIVE_POSTPONED_EFL_OP_T enmOp;
|
---|
2022 | /** The bit-width of the postponed EFLAGS calculation. */
|
---|
2023 | uint8_t cOpBits;
|
---|
2024 | /** Host register holding result or first source for the delayed operation,
|
---|
2025 | * UINT8_MAX if not in use. */
|
---|
2026 | uint8_t idxReg1;
|
---|
2027 | /** Host register holding second source for the delayed operation,
|
---|
2028 | * UINT8_MAX if not in use. */
|
---|
2029 | uint8_t idxReg2;
|
---|
2030 | # if defined(VBOX_WITH_STATISTICS) || defined(IEMNATIVE_WITH_TB_DEBUG_INFO)
|
---|
2031 | /** Number of times the delayed calculation was emitted. */
|
---|
2032 | uint8_t cEmits;
|
---|
2033 | # endif
|
---|
2034 | } PostponedEfl;
|
---|
2035 | #endif
|
---|
2036 |
|
---|
2037 | /** Core state requiring care with branches. */
|
---|
2038 | IEMNATIVECORESTATE Core;
|
---|
2039 |
|
---|
2040 | /** The condition nesting stack. */
|
---|
2041 | IEMNATIVECOND aCondStack[2];
|
---|
2042 |
|
---|
2043 | #ifndef IEM_WITH_THROW_CATCH
|
---|
2044 | /** Pointer to the setjmp/longjmp buffer if we're not using C++ exceptions
|
---|
2045 | * for recompilation error handling. */
|
---|
2046 | jmp_buf JmpBuf;
|
---|
2047 | #endif
|
---|
2048 | } IEMRECOMPILERSTATE;
|
---|
2049 | /** Pointer to a native recompiler state. */
|
---|
2050 | typedef IEMRECOMPILERSTATE *PIEMRECOMPILERSTATE;
|
---|
2051 |
|
---|
2052 |
|
---|
2053 | /** @def IEMNATIVE_TRY_SETJMP
|
---|
2054 | * Wrapper around setjmp / try, hiding all the ugly differences.
|
---|
2055 | *
|
---|
2056 | * @note Use with extreme care as this is a fragile macro.
|
---|
2057 | * @param a_pReNative The native recompile state.
|
---|
2058 | * @param a_rcTarget The variable that should receive the status code in case
|
---|
2059 | * of a longjmp/throw.
|
---|
2060 | */
|
---|
2061 | /** @def IEMNATIVE_CATCH_LONGJMP_BEGIN
|
---|
2062 | * Start wrapper for catch / setjmp-else.
|
---|
2063 | *
|
---|
2064 | * This will set up a scope.
|
---|
2065 | *
|
---|
2066 | * @note Use with extreme care as this is a fragile macro.
|
---|
2067 | * @param a_pReNative The native recompile state.
|
---|
2068 | * @param a_rcTarget The variable that should receive the status code in case
|
---|
2069 | * of a longjmp/throw.
|
---|
2070 | */
|
---|
2071 | /** @def IEMNATIVE_CATCH_LONGJMP_END
|
---|
2072 | * End wrapper for catch / setjmp-else.
|
---|
2073 | *
|
---|
2074 | * This will close the scope set up by IEMNATIVE_CATCH_LONGJMP_BEGIN and clean
|
---|
2075 | * up the state.
|
---|
2076 | *
|
---|
2077 | * @note Use with extreme care as this is a fragile macro.
|
---|
2078 | * @param a_pReNative The native recompile state.
|
---|
2079 | */
|
---|
2080 | /** @def IEMNATIVE_DO_LONGJMP
|
---|
2081 | *
|
---|
2082 | * Wrapper around longjmp / throw.
|
---|
2083 | *
|
---|
2084 | * @param a_pReNative The native recompile state.
|
---|
2085 | * @param a_rc The status code jump back with / throw.
|
---|
2086 | */
|
---|
2087 | #ifdef IEM_WITH_THROW_CATCH
|
---|
2088 | # define IEMNATIVE_TRY_SETJMP(a_pReNative, a_rcTarget) \
|
---|
2089 | a_rcTarget = VINF_SUCCESS; \
|
---|
2090 | try
|
---|
2091 | # define IEMNATIVE_CATCH_LONGJMP_BEGIN(a_pReNative, a_rcTarget) \
|
---|
2092 | catch (int rcThrown) \
|
---|
2093 | { \
|
---|
2094 | a_rcTarget = rcThrown
|
---|
2095 | # define IEMNATIVE_CATCH_LONGJMP_END(a_pReNative) \
|
---|
2096 | } \
|
---|
2097 | ((void)0)
|
---|
2098 | # define IEMNATIVE_DO_LONGJMP(a_pReNative, a_rc) throw int(a_rc)
|
---|
2099 | #else /* !IEM_WITH_THROW_CATCH */
|
---|
2100 | # define IEMNATIVE_TRY_SETJMP(a_pReNative, a_rcTarget) \
|
---|
2101 | if ((a_rcTarget = setjmp((a_pReNative)->JmpBuf)) == 0)
|
---|
2102 | # define IEMNATIVE_CATCH_LONGJMP_BEGIN(a_pReNative, a_rcTarget) \
|
---|
2103 | else \
|
---|
2104 | { \
|
---|
2105 | ((void)0)
|
---|
2106 | # define IEMNATIVE_CATCH_LONGJMP_END(a_pReNative) \
|
---|
2107 | }
|
---|
2108 | # define IEMNATIVE_DO_LONGJMP(a_pReNative, a_rc) longjmp((a_pReNative)->JmpBuf, (a_rc))
|
---|
2109 | #endif /* !IEM_WITH_THROW_CATCH */
|
---|
2110 |
|
---|
2111 |
|
---|
2112 | /**
|
---|
2113 | * Native recompiler worker for a threaded function.
|
---|
2114 | *
|
---|
2115 | * @returns New code buffer offset; throws VBox status code in case of a failure.
|
---|
2116 | * @param pReNative The native recompiler state.
|
---|
2117 | * @param off The current code buffer offset.
|
---|
2118 | * @param pCallEntry The threaded call entry.
|
---|
2119 | *
|
---|
2120 | * @note This may throw/longjmp VBox status codes (int) to abort compilation, so no RT_NOEXCEPT!
|
---|
2121 | */
|
---|
2122 | typedef uint32_t (VBOXCALL FNIEMNATIVERECOMPFUNC)(PIEMRECOMPILERSTATE pReNative, uint32_t off, PCIEMTHRDEDCALLENTRY pCallEntry);
|
---|
2123 | /** Pointer to a native recompiler worker for a threaded function. */
|
---|
2124 | typedef FNIEMNATIVERECOMPFUNC *PFNIEMNATIVERECOMPFUNC;
|
---|
2125 |
|
---|
2126 | /** Defines a native recompiler worker for a threaded function.
|
---|
2127 | * @see FNIEMNATIVERECOMPFUNC */
|
---|
2128 | #define IEM_DECL_IEMNATIVERECOMPFUNC_DEF(a_Name) \
|
---|
2129 | IEM_DECL_MSC_GUARD_IGNORE uint32_t VBOXCALL \
|
---|
2130 | a_Name(PIEMRECOMPILERSTATE pReNative, uint32_t off, PCIEMTHRDEDCALLENTRY pCallEntry)
|
---|
2131 |
|
---|
2132 | /** Prototypes a native recompiler function for a threaded function.
|
---|
2133 | * @see FNIEMNATIVERECOMPFUNC */
|
---|
2134 | #define IEM_DECL_IEMNATIVERECOMPFUNC_PROTO(a_Name) FNIEMNATIVERECOMPFUNC a_Name
|
---|
2135 |
|
---|
2136 |
|
---|
2137 | /**
|
---|
2138 | * Native recompiler liveness analysis worker for a threaded function.
|
---|
2139 | *
|
---|
2140 | * @param pCallEntry The threaded call entry.
|
---|
2141 | * @param pIncoming The incoming liveness state entry.
|
---|
2142 | * @param pOutgoing The outgoing liveness state entry.
|
---|
2143 | */
|
---|
2144 | typedef DECLCALLBACKTYPE(void, FNIEMNATIVELIVENESSFUNC, (PCIEMTHRDEDCALLENTRY pCallEntry,
|
---|
2145 | PCIEMLIVENESSENTRY pIncoming, PIEMLIVENESSENTRY pOutgoing));
|
---|
2146 | /** Pointer to a native recompiler liveness analysis worker for a threaded function. */
|
---|
2147 | typedef FNIEMNATIVELIVENESSFUNC *PFNIEMNATIVELIVENESSFUNC;
|
---|
2148 |
|
---|
2149 | /** Defines a native recompiler liveness analysis worker for a threaded function.
|
---|
2150 | * @see FNIEMNATIVELIVENESSFUNC */
|
---|
2151 | #define IEM_DECL_IEMNATIVELIVENESSFUNC_DEF(a_Name) \
|
---|
2152 | IEM_DECL_MSC_GUARD_IGNORE DECLCALLBACK(void) \
|
---|
2153 | a_Name(PCIEMTHRDEDCALLENTRY pCallEntry, PCIEMLIVENESSENTRY pIncoming, PIEMLIVENESSENTRY pOutgoing)
|
---|
2154 |
|
---|
2155 | /** Prototypes a native recompiler liveness analysis function for a threaded function.
|
---|
2156 | * @see FNIEMNATIVELIVENESSFUNC */
|
---|
2157 | #define IEM_DECL_IEMNATIVELIVENESSFUNC_PROTO(a_Name) FNIEMNATIVELIVENESSFUNC a_Name
|
---|
2158 |
|
---|
2159 |
|
---|
2160 | /** Define a native recompiler helper function, safe to call from the TB code. */
|
---|
2161 | #define IEM_DECL_NATIVE_HLP_DEF(a_RetType, a_Name, a_ArgList) \
|
---|
2162 | DECL_HIDDEN_THROW(a_RetType) VBOXCALL a_Name a_ArgList
|
---|
2163 | /** Prototype a native recompiler helper function, safe to call from the TB code. */
|
---|
2164 | #define IEM_DECL_NATIVE_HLP_PROTO(a_RetType, a_Name, a_ArgList) \
|
---|
2165 | DECL_HIDDEN_THROW(a_RetType) VBOXCALL a_Name a_ArgList
|
---|
2166 | /** Pointer typedef a native recompiler helper function, safe to call from the TB code. */
|
---|
2167 | #define IEM_DECL_NATIVE_HLP_PTR(a_RetType, a_Name, a_ArgList) \
|
---|
2168 | a_RetType (VBOXCALL *a_Name) a_ArgList
|
---|
2169 |
|
---|
2170 |
|
---|
2171 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
2172 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddNativeOffset(PIEMRECOMPILERSTATE pReNative, uint32_t off);
|
---|
2173 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddGuestRegShadowing(PIEMRECOMPILERSTATE pReNative, IEMNATIVEGSTREG enmGstReg,
|
---|
2174 | uint8_t idxHstReg = UINT8_MAX, uint8_t idxHstRegPrev = UINT8_MAX);
|
---|
2175 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddGuestSimdRegShadowing(PIEMRECOMPILERSTATE pReNative,
|
---|
2176 | IEMNATIVEGSTSIMDREG enmGstSimdReg,
|
---|
2177 | uint8_t idxHstSimdReg = UINT8_MAX,
|
---|
2178 | uint8_t idxHstSimdRegPrev = UINT8_MAX);
|
---|
2179 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddGuestRegDirty(PIEMRECOMPILERSTATE pReNative, bool fSimdReg,
|
---|
2180 | uint8_t idxGstReg, uint8_t idxHstReg);
|
---|
2181 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddGuestRegWriteback(PIEMRECOMPILERSTATE pReNative, bool fSimdReg,
|
---|
2182 | uint64_t fGstReg);
|
---|
2183 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddDelayedPcUpdate(PIEMRECOMPILERSTATE pReNative,
|
---|
2184 | uint64_t offPc, uint32_t cInstrSkipped);
|
---|
2185 | # ifdef IEMNATIVE_WITH_EFLAGS_POSTPONING
|
---|
2186 | DECL_HIDDEN_THROW(void) iemNativeDbgInfoAddPostponedEFlagsCalc(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2187 | IEMNATIVE_POSTPONED_EFL_OP_T enmOp, uint8_t cOpBits,
|
---|
2188 | uint8_t idxInstance);
|
---|
2189 | # endif
|
---|
2190 | #endif /* IEMNATIVE_WITH_TB_DEBUG_INFO */
|
---|
2191 |
|
---|
2192 | DECL_HIDDEN_THROW(uint32_t) iemNativeLabelCreate(PIEMRECOMPILERSTATE pReNative, IEMNATIVELABELTYPE enmType,
|
---|
2193 | uint32_t offWhere = UINT32_MAX, uint16_t uData = 0);
|
---|
2194 | DECL_HIDDEN_THROW(void) iemNativeLabelDefine(PIEMRECOMPILERSTATE pReNative, uint32_t idxLabel, uint32_t offWhere);
|
---|
2195 | DECLHIDDEN(uint32_t) iemNativeLabelFind(PIEMRECOMPILERSTATE pReNative, IEMNATIVELABELTYPE enmType,
|
---|
2196 | uint32_t offWhere = UINT32_MAX, uint16_t uData = 0) RT_NOEXCEPT;
|
---|
2197 | DECL_HIDDEN_THROW(void) iemNativeAddFixup(PIEMRECOMPILERSTATE pReNative, uint32_t offWhere, uint32_t idxLabel,
|
---|
2198 | IEMNATIVEFIXUPTYPE enmType, int8_t offAddend = 0);
|
---|
2199 | DECL_HIDDEN_THROW(void) iemNativeAddTbExitFixup(PIEMRECOMPILERSTATE pReNative, uint32_t offWhere,
|
---|
2200 | IEMNATIVELABELTYPE enmExitReason);
|
---|
2201 | DECL_HIDDEN_THROW(PIEMNATIVEINSTR) iemNativeInstrBufEnsureSlow(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t cInstrReq);
|
---|
2202 |
|
---|
2203 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff);
|
---|
2204 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff);
|
---|
2205 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask);
|
---|
2206 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpExPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask);
|
---|
2207 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpImm(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t uImm);
|
---|
2208 |
|
---|
2209 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegReadOnly(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2210 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegUpdate(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2211 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegFullWrite(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2212 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegCalculation(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2213 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegReadOnlyNoVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2214 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegUpdateNoVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2215 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegFullWriteNoVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2216 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegCalculationNoVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
|
---|
2217 |
|
---|
2218 | #if defined(IEMNATIVE_WITH_LIVENESS_ANALYSIS) && defined(VBOX_STRICT)
|
---|
2219 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestEFlagsReadOnly(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2220 | uint64_t fRead, uint64_t fWrite = 0, uint64_t fPotentialCall = 0);
|
---|
2221 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestEFlagsForUpdate(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2222 | uint64_t fRead, uint64_t fWrite = 0, uint64_t fPotentialCall = 0);
|
---|
2223 | #endif
|
---|
2224 |
|
---|
2225 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestRegIfAlreadyPresent(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2226 | IEMNATIVEGSTREG enmGstReg);
|
---|
2227 | #if defined(IEMNATIVE_WITH_LIVENESS_ANALYSIS) && defined(VBOX_STRICT)
|
---|
2228 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpForGuestEFlagsIfAlreadyPresent(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2229 | uint64_t fRead, uint64_t fWrite = 0);
|
---|
2230 | #else
|
---|
2231 | DECL_FORCE_INLINE_THROW(uint8_t)
|
---|
2232 | iemNativeRegAllocTmpForGuestEFlagsIfAlreadyPresent(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2233 | uint64_t fRead, uint64_t fWrite = 0)
|
---|
2234 | {
|
---|
2235 | RT_NOREF(fRead, fWrite);
|
---|
2236 | return iemNativeRegAllocTmpForGuestRegIfAlreadyPresent(pReNative, poff, kIemNativeGstReg_EFlags);
|
---|
2237 | }
|
---|
2238 | #endif
|
---|
2239 |
|
---|
2240 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegAllocArgs(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs);
|
---|
2241 | DECL_HIDDEN_THROW(uint8_t) iemNativeRegAssignRc(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg);
|
---|
2242 | #if (defined(IPRT_INCLUDED_x86_h) && defined(RT_ARCH_AMD64)) || (defined(IPRT_INCLUDED_armv8_h) && defined(RT_ARCH_ARM64))
|
---|
2243 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegMoveOrSpillStackVar(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar,
|
---|
2244 | uint32_t fForbiddenRegs = IEMNATIVE_CALL_VOLATILE_GREG_MASK);
|
---|
2245 | DECL_HIDDEN_THROW(uint32_t) iemNativeSimdRegMoveOrSpillStackVar(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar,
|
---|
2246 | uint32_t fForbiddenRegs = IEMNATIVE_CALL_VOLATILE_SIMD_REG_MASK);
|
---|
2247 | #endif
|
---|
2248 | DECLHIDDEN(void) iemNativeRegFree(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg) RT_NOEXCEPT;
|
---|
2249 | DECLHIDDEN(void) iemNativeRegFreeTmp(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg) RT_NOEXCEPT;
|
---|
2250 | DECLHIDDEN(void) iemNativeRegFreeTmpImm(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg) RT_NOEXCEPT;
|
---|
2251 | DECLHIDDEN(void) iemNativeRegFreeVar(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg, bool fFlushShadows) RT_NOEXCEPT;
|
---|
2252 | DECLHIDDEN(void) iemNativeSimdRegFreeVar(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstSimdReg, bool fFlushShadows) RT_NOEXCEPT;
|
---|
2253 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
2254 | DECL_HIDDEN_THROW(uint32_t) iemNativeSimdRegFlushDirtyGuestByHostSimdRegShadow(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxHstReg);
|
---|
2255 | #endif
|
---|
2256 | DECLHIDDEN(void) iemNativeRegFreeAndFlushMask(PIEMRECOMPILERSTATE pReNative, uint32_t fHstRegMask) RT_NOEXCEPT;
|
---|
2257 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegMoveAndFreeAndFlushAtCall(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs,
|
---|
2258 | uint32_t fKeepVars = 0);
|
---|
2259 | DECLHIDDEN(void) iemNativeRegFlushGuestShadows(PIEMRECOMPILERSTATE pReNative, uint64_t fGstRegs) RT_NOEXCEPT;
|
---|
2260 | DECLHIDDEN(void) iemNativeRegFlushGuestShadowsByHostMask(PIEMRECOMPILERSTATE pReNative, uint32_t fHstRegs) RT_NOEXCEPT;
|
---|
2261 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegRestoreGuestShadowsInVolatileRegs(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2262 | uint32_t fHstRegsActiveShadows);
|
---|
2263 | #ifdef VBOX_STRICT
|
---|
2264 | DECLHIDDEN(void) iemNativeRegAssertSanity(PIEMRECOMPILERSTATE pReNative);
|
---|
2265 | #endif
|
---|
2266 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWritesSlow(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint64_t fGstShwExcept,
|
---|
2267 | uint64_t fGstSimdShwExcept);
|
---|
2268 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
2269 | # ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING_DEBUG
|
---|
2270 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitPcDebugCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off);
|
---|
2271 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitPcDebugCheckWithReg(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxPcReg);
|
---|
2272 | # endif
|
---|
2273 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitPcWritebackSlow(PIEMRECOMPILERSTATE pReNative, uint32_t off);
|
---|
2274 | #endif
|
---|
2275 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
2276 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWrite(PIEMRECOMPILERSTATE pReNative, uint32_t off, IEMNATIVEGSTREG enmGstReg);
|
---|
2277 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushPendingWriteEx(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2278 | PIEMNATIVECORESTATE pCore, IEMNATIVEGSTREG enmGstReg);
|
---|
2279 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushDirtyGuest(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2280 | uint64_t fFlushGstReg = UINT64_MAX);
|
---|
2281 | DECL_HIDDEN_THROW(uint32_t) iemNativeRegFlushDirtyGuestByHostRegShadow(PIEMRECOMPILERSTATE pReNative,
|
---|
2282 | uint32_t off, uint8_t idxHstReg);
|
---|
2283 | #endif
|
---|
2284 |
|
---|
2285 |
|
---|
2286 | DECL_HIDDEN_THROW(uint8_t) iemNativeSimdRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, bool fPreferVolatile = true);
|
---|
2287 | DECL_HIDDEN_THROW(uint8_t) iemNativeSimdRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask,
|
---|
2288 | bool fPreferVolatile = true);
|
---|
2289 | DECL_HIDDEN_THROW(uint8_t) iemNativeSimdRegAllocTmpForGuestSimdReg(PIEMRECOMPILERSTATE pReNative, uint32_t *poff,
|
---|
2290 | IEMNATIVEGSTSIMDREG enmGstSimdReg,
|
---|
2291 | IEMNATIVEGSTSIMDREGLDSTSZ enmLoadSz,
|
---|
2292 | IEMNATIVEGSTREGUSE enmIntendedUse = kIemNativeGstRegUse_ReadOnly,
|
---|
2293 | bool fNoVolatileRegs = false);
|
---|
2294 | DECLHIDDEN(void) iemNativeSimdRegFreeTmp(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstSimdReg) RT_NOEXCEPT;
|
---|
2295 | DECLHIDDEN(void) iemNativeSimdRegFlushGuestShadows(PIEMRECOMPILERSTATE pReNative, uint64_t fGstSimdRegs) RT_NOEXCEPT;
|
---|
2296 | DECL_HIDDEN_THROW(uint32_t) iemNativeSimdRegFlushPendingWrite(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2297 | IEMNATIVEGSTSIMDREG enmGstSimdReg);
|
---|
2298 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitLoadSimdRegWithGstShadowSimdReg(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2299 | uint8_t idxHstSimdReg, IEMNATIVEGSTSIMDREG enmGstSimdReg,
|
---|
2300 | IEMNATIVEGSTSIMDREGLDSTSZ enmLoadSz);
|
---|
2301 |
|
---|
2302 | DECL_HIDDEN_THROW(uint8_t) iemNativeArgAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType);
|
---|
2303 | DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType, uint64_t uValue);
|
---|
2304 | DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocLocalRef(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t idxOtherVar);
|
---|
2305 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t cbType);
|
---|
2306 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t cbType, uint64_t uValue);
|
---|
2307 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarAllocAssign(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint8_t cbType, uint8_t idxVarOther);
|
---|
2308 | DECL_HIDDEN_THROW(void) iemNativeVarSetKindToStack(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar);
|
---|
2309 | DECL_HIDDEN_THROW(void) iemNativeVarSetKindToConst(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint64_t uValue);
|
---|
2310 | DECL_HIDDEN_THROW(void) iemNativeVarSetKindToGstRegRef(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
|
---|
2311 | IEMNATIVEGSTREGREF enmRegClass, uint8_t idxReg);
|
---|
2312 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarGetStackSlot(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar);
|
---|
2313 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
|
---|
2314 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
|
---|
2315 | uint32_t *poff, uint8_t idxRegPref);
|
---|
2316 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireInitedSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
|
---|
2317 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireInitedWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
|
---|
2318 | uint32_t *poff, uint8_t idxRegPref);
|
---|
2319 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarSimdRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff,
|
---|
2320 | bool fInitialized = false, uint8_t idxRegPref = UINT8_MAX);
|
---|
2321 | DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireForGuestReg(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
|
---|
2322 | IEMNATIVEGSTREG enmGstReg, uint32_t *poff);
|
---|
2323 | DECL_HIDDEN_THROW(uint32_t) iemNativeVarSaveVolatileRegsPreHlpCall(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2324 | uint32_t fHstGprNotToSave);
|
---|
2325 | DECL_HIDDEN_THROW(uint32_t) iemNativeVarRestoreVolatileRegsPostHlpCall(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2326 | uint32_t fHstGprNotToSave);
|
---|
2327 | DECLHIDDEN(void) iemNativeVarFreeOneWorker(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar);
|
---|
2328 | DECLHIDDEN(void) iemNativeVarFreeAllSlow(PIEMRECOMPILERSTATE pReNative, uint32_t bmVars);
|
---|
2329 |
|
---|
2330 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitLoadGprWithGstShadowReg(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2331 | uint8_t idxHstReg, IEMNATIVEGSTREG enmGstReg);
|
---|
2332 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitLoadGprWithGstShadowRegEx(PIEMNATIVEINSTR pCodeBuf, uint32_t off,
|
---|
2333 | uint8_t idxHstReg, IEMNATIVEGSTREG enmGstReg);
|
---|
2334 | #ifdef VBOX_STRICT
|
---|
2335 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitTop32BitsClearCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxReg);
|
---|
2336 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitGuestRegValueCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxReg,
|
---|
2337 | IEMNATIVEGSTREG enmGstReg);
|
---|
2338 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitGuestRegValueCheckEx(PIEMRECOMPILERSTATE pReNative, PIEMNATIVEINSTR pCodeBuf,
|
---|
2339 | uint32_t off, uint8_t idxReg, IEMNATIVEGSTREG enmGstReg);
|
---|
2340 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitGuestSimdRegValueCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxSimdReg,
|
---|
2341 | IEMNATIVEGSTSIMDREG enmGstSimdReg,
|
---|
2342 | IEMNATIVEGSTSIMDREGLDSTSZ enmLoadSz);
|
---|
2343 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitExecFlagsCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t fExec);
|
---|
2344 | #endif
|
---|
2345 | #ifdef IEMNATIVE_STRICT_EFLAGS_SKIPPING
|
---|
2346 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitEFlagsSkippingCheck(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t fEflNeeded);
|
---|
2347 | #endif
|
---|
2348 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitCheckCallRetAndPassUp(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxInstr);
|
---|
2349 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitCallCommon(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs, uint8_t cHiddenArgs, bool fFlushPendingWrites = true);
|
---|
2350 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitCImplCall(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxInstr,
|
---|
2351 | uint64_t fGstShwFlush, uintptr_t pfnCImpl, uint8_t cbInstr, uint8_t cAddParams,
|
---|
2352 | uint64_t uParam0, uint64_t uParam1, uint64_t uParam2);
|
---|
2353 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitThreadedCall(PIEMRECOMPILERSTATE pReNative, uint32_t off,
|
---|
2354 | PCIEMTHRDEDCALLENTRY pCallEntry);
|
---|
2355 | IEM_DECL_IEMNATIVELIVENESSFUNC_PROTO(iemNativeLivenessFunc_ThreadedCall);
|
---|
2356 | DECL_HIDDEN_THROW(uint32_t) iemNativeEmitLeaGprByGstRegRef(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxGprDst,
|
---|
2357 | IEMNATIVEGSTREGREF enmClass, uint8_t idxRegInClass);
|
---|
2358 |
|
---|
2359 |
|
---|
2360 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecStatusCodeFiddling,(PVMCPUCC pVCpu, int rc, uint8_t idxInstr));
|
---|
2361 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseGp0,(PVMCPUCC pVCpu));
|
---|
2362 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseNm,(PVMCPUCC pVCpu));
|
---|
2363 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseUd,(PVMCPUCC pVCpu));
|
---|
2364 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseMf,(PVMCPUCC pVCpu));
|
---|
2365 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseXf,(PVMCPUCC pVCpu));
|
---|
2366 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseDe,(PVMCPUCC pVCpu));
|
---|
2367 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpObsoleteTb,(PVMCPUCC pVCpu));
|
---|
2368 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpNeedCsLimChecking,(PVMCPUCC pVCpu));
|
---|
2369 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpCheckBranchMiss,(PVMCPUCC pVCpu));
|
---|
2370 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseAvxRelated,(PVMCPUCC pVCpu));
|
---|
2371 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseSseRelated,(PVMCPUCC pVCpu));
|
---|
2372 | IEM_DECL_NATIVE_HLP_PROTO(int, iemNativeHlpExecRaiseSseAvxFpRelated,(PVMCPUCC pVCpu));
|
---|
2373 |
|
---|
2374 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU8,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2375 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU8_Sx_U16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2376 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU8_Sx_U32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2377 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU8_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2378 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2379 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU16_Sx_U32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2380 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU16_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2381 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2382 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU32_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2383 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFetchDataU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2384 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFetchDataU128,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PRTUINT128U pu128Dst));
|
---|
2385 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFetchDataU128AlignedSse,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PRTUINT128U pu128Dst));
|
---|
2386 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFetchDataU128NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PRTUINT128U pu128Dst));
|
---|
2387 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFetchDataU256NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PRTUINT256U pu256Dst));
|
---|
2388 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFetchDataU256AlignedAvx,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PRTUINT256U pu256Dst));
|
---|
2389 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU8,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, uint8_t u8Value));
|
---|
2390 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, uint16_t u16Value));
|
---|
2391 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, uint32_t u32Value));
|
---|
2392 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, uint64_t u64Value));
|
---|
2393 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU128AlignedSse,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PCRTUINT128U pu128Src));
|
---|
2394 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU128NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PCRTUINT128U pu128Src));
|
---|
2395 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU256NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PCRTUINT256U pu256Src));
|
---|
2396 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemStoreDataU256AlignedAvx,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t iSegReg, PCRTUINT256U pu256Src));
|
---|
2397 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackStoreU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint16_t u16Value));
|
---|
2398 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackStoreU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint32_t u32Value));
|
---|
2399 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackStoreU32SReg,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint32_t u32Value));
|
---|
2400 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackStoreU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint64_t u64Value));
|
---|
2401 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t, iemNativeHlpStackFetchU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2402 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t, iemNativeHlpStackFetchU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2403 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpStackFetchU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2404 |
|
---|
2405 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU8,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2406 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU8_Sx_U16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2407 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU8_Sx_U32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2408 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU8_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2409 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2410 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU16_Sx_U32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2411 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU16_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2412 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2413 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU32_Sx_U64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2414 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpMemFlatFetchDataU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2415 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatFetchDataU128,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PRTUINT128U pu128Dst));
|
---|
2416 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatFetchDataU128AlignedSse,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PRTUINT128U pu128Dst));
|
---|
2417 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatFetchDataU128NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PRTUINT128U pu128Dst));
|
---|
2418 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatFetchDataU256NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PRTUINT256U pu256Dst));
|
---|
2419 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatFetchDataU256AlignedAvx,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PRTUINT256U pu256Dst));
|
---|
2420 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU8,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint8_t u8Value));
|
---|
2421 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint16_t u16Value));
|
---|
2422 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint32_t u32Value));
|
---|
2423 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint64_t u64Value));
|
---|
2424 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU128AlignedSse,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PCRTUINT128U pu128Src));
|
---|
2425 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU128NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PCRTUINT128U pu128Src));
|
---|
2426 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU256NoAc,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PCRTUINT256U pu256Src));
|
---|
2427 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemFlatStoreDataU256AlignedAvx,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, PCRTUINT256U pu256Src));
|
---|
2428 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackFlatStoreU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint16_t u16Value));
|
---|
2429 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackFlatStoreU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint32_t u32Value));
|
---|
2430 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackFlatStoreU32SReg,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint32_t u32Value));
|
---|
2431 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpStackFlatStoreU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem, uint64_t u64Value));
|
---|
2432 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t, iemNativeHlpStackFlatFetchU16,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2433 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t, iemNativeHlpStackFlatFetchU32,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2434 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t, iemNativeHlpStackFlatFetchU64,(PVMCPUCC pVCpu, RTGCPTR GCPtrMem));
|
---|
2435 |
|
---|
2436 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemMapDataU8Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2437 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemMapDataU8Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2438 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemMapDataU8Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2439 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t const *, iemNativeHlpMemMapDataU8Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2440 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemMapDataU16Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2441 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemMapDataU16Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2442 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemMapDataU16Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2443 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t const *, iemNativeHlpMemMapDataU16Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2444 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemMapDataU32Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2445 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemMapDataU32Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2446 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemMapDataU32Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2447 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t const *, iemNativeHlpMemMapDataU32Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2448 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemMapDataU64Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2449 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemMapDataU64Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2450 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemMapDataU64Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2451 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t const *, iemNativeHlpMemMapDataU64Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2452 | IEM_DECL_NATIVE_HLP_PROTO(RTFLOAT80U *, iemNativeHlpMemMapDataR80Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2453 | IEM_DECL_NATIVE_HLP_PROTO(RTPBCD80U *, iemNativeHlpMemMapDataD80Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2454 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemMapDataU128Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2455 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemMapDataU128Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2456 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemMapDataU128Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2457 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U const *, iemNativeHlpMemMapDataU128Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem, uint8_t iSegReg));
|
---|
2458 |
|
---|
2459 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemFlatMapDataU8Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2460 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemFlatMapDataU8Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2461 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t *, iemNativeHlpMemFlatMapDataU8Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2462 | IEM_DECL_NATIVE_HLP_PROTO(uint8_t const *, iemNativeHlpMemFlatMapDataU8Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2463 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemFlatMapDataU16Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2464 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemFlatMapDataU16Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2465 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t *, iemNativeHlpMemFlatMapDataU16Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2466 | IEM_DECL_NATIVE_HLP_PROTO(uint16_t const *, iemNativeHlpMemFlatMapDataU16Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2467 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemFlatMapDataU32Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2468 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemFlatMapDataU32Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2469 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t *, iemNativeHlpMemFlatMapDataU32Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2470 | IEM_DECL_NATIVE_HLP_PROTO(uint32_t const *, iemNativeHlpMemFlatMapDataU32Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2471 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemFlatMapDataU64Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2472 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemFlatMapDataU64Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2473 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t *, iemNativeHlpMemFlatMapDataU64Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2474 | IEM_DECL_NATIVE_HLP_PROTO(uint64_t const *, iemNativeHlpMemFlatMapDataU64Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2475 | IEM_DECL_NATIVE_HLP_PROTO(RTFLOAT80U *, iemNativeHlpMemFlatMapDataR80Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2476 | IEM_DECL_NATIVE_HLP_PROTO(RTPBCD80U *, iemNativeHlpMemFlatMapDataD80Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2477 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemFlatMapDataU128Atomic,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2478 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemFlatMapDataU128Rw,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2479 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U *, iemNativeHlpMemFlatMapDataU128Wo,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2480 | IEM_DECL_NATIVE_HLP_PROTO(RTUINT128U const *, iemNativeHlpMemFlatMapDataU128Ro,(PVMCPUCC pVCpu, uint8_t *pbUnmapInfo, RTGCPTR GCPtrMem));
|
---|
2481 |
|
---|
2482 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemCommitAndUnmapAtomic,(PVMCPUCC pVCpu, uint8_t bUnmapInfo));
|
---|
2483 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemCommitAndUnmapRw,(PVMCPUCC pVCpu, uint8_t bUnmapInfo));
|
---|
2484 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemCommitAndUnmapWo,(PVMCPUCC pVCpu, uint8_t bUnmapInfo));
|
---|
2485 | IEM_DECL_NATIVE_HLP_PROTO(void, iemNativeHlpMemCommitAndUnmapRo,(PVMCPUCC pVCpu, uint8_t bUnmapInfo));
|
---|
2486 |
|
---|
2487 |
|
---|
2488 | /**
|
---|
2489 | * Info about shadowed guest register values.
|
---|
2490 | * @see IEMNATIVEGSTREG
|
---|
2491 | */
|
---|
2492 | typedef struct IEMANTIVEGSTREGINFO
|
---|
2493 | {
|
---|
2494 | /** Offset in VMCPU. */
|
---|
2495 | uint32_t off;
|
---|
2496 | /** The field size. */
|
---|
2497 | uint8_t cb;
|
---|
2498 | /** Name (for logging). */
|
---|
2499 | const char *pszName;
|
---|
2500 | } IEMANTIVEGSTREGINFO;
|
---|
2501 | extern DECL_HIDDEN_DATA(IEMANTIVEGSTREGINFO const) g_aGstShadowInfo[];
|
---|
2502 | extern DECL_HIDDEN_DATA(const char * const) g_apszIemNativeHstRegNames[];
|
---|
2503 | extern DECL_HIDDEN_DATA(int32_t const) g_aoffIemNativeCallStackArgBpDisp[];
|
---|
2504 | extern DECL_HIDDEN_DATA(uint32_t const) g_afIemNativeCallRegs[];
|
---|
2505 | extern DECL_HIDDEN_DATA(uint8_t const) g_aidxIemNativeCallRegs[];
|
---|
2506 |
|
---|
2507 |
|
---|
2508 |
|
---|
2509 | /**
|
---|
2510 | * Ensures that there is sufficient space in the instruction output buffer.
|
---|
2511 | *
|
---|
2512 | * This will reallocate the buffer if needed and allowed.
|
---|
2513 | *
|
---|
2514 | * @note Always use IEMNATIVE_ASSERT_INSTR_BUF_ENSURE when done to check the
|
---|
2515 | * allocation size.
|
---|
2516 | *
|
---|
2517 | * @returns Pointer to the instruction output buffer on success; throws VBox
|
---|
2518 | * status code on failure, so no need to check it.
|
---|
2519 | * @param pReNative The native recompile state.
|
---|
2520 | * @param off Current instruction offset. Works safely for UINT32_MAX
|
---|
2521 | * as well.
|
---|
2522 | * @param cInstrReq Number of instruction about to be added. It's okay to
|
---|
2523 | * overestimate this a bit.
|
---|
2524 | */
|
---|
2525 | DECL_FORCE_INLINE_THROW(PIEMNATIVEINSTR)
|
---|
2526 | iemNativeInstrBufEnsure(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t cInstrReq)
|
---|
2527 | {
|
---|
2528 | uint64_t const offChecked = off + (uint64_t)cInstrReq; /** @todo may reconsider the need for UINT32_MAX safety... */
|
---|
2529 | if (RT_LIKELY(offChecked <= pReNative->cInstrBufAlloc))
|
---|
2530 | {
|
---|
2531 | #ifdef VBOX_STRICT
|
---|
2532 | pReNative->offInstrBufChecked = offChecked;
|
---|
2533 | #endif
|
---|
2534 | return pReNative->pInstrBuf;
|
---|
2535 | }
|
---|
2536 | return iemNativeInstrBufEnsureSlow(pReNative, off, cInstrReq);
|
---|
2537 | }
|
---|
2538 |
|
---|
2539 | /**
|
---|
2540 | * Checks that we didn't exceed the space requested in the last
|
---|
2541 | * iemNativeInstrBufEnsure() call.
|
---|
2542 | */
|
---|
2543 | #define IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(a_pReNative, a_off) \
|
---|
2544 | AssertMsg((a_off) <= (a_pReNative)->offInstrBufChecked, \
|
---|
2545 | ("off=%#x offInstrBufChecked=%#x\n", (a_off), (a_pReNative)->offInstrBufChecked))
|
---|
2546 |
|
---|
2547 | /**
|
---|
2548 | * Checks that a variable index is valid.
|
---|
2549 | */
|
---|
2550 | #ifdef IEMNATIVE_VAR_IDX_MAGIC
|
---|
2551 | # define IEMNATIVE_ASSERT_VAR_IDX(a_pReNative, a_idxVar) \
|
---|
2552 | AssertMsg( ((a_idxVar) & IEMNATIVE_VAR_IDX_MAGIC_MASK) == IEMNATIVE_VAR_IDX_MAGIC \
|
---|
2553 | && (unsigned)IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
|
---|
2554 | && ((a_pReNative)->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar))), \
|
---|
2555 | ("%s=%#x\n", #a_idxVar, a_idxVar))
|
---|
2556 | #else
|
---|
2557 | # define IEMNATIVE_ASSERT_VAR_IDX(a_pReNative, a_idxVar) \
|
---|
2558 | AssertMsg( (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
|
---|
2559 | && ((a_pReNative)->Core.bmVars & RT_BIT_32(a_idxVar)), ("%s=%d\n", #a_idxVar, a_idxVar))
|
---|
2560 | #endif
|
---|
2561 |
|
---|
2562 | /**
|
---|
2563 | * Checks that a variable index is valid and that the variable is assigned the
|
---|
2564 | * correct argument number.
|
---|
2565 | * This also adds a RT_NOREF of a_idxVar.
|
---|
2566 | */
|
---|
2567 | #ifdef IEMNATIVE_VAR_IDX_MAGIC
|
---|
2568 | # define IEMNATIVE_ASSERT_ARG_VAR_IDX(a_pReNative, a_idxVar, a_uArgNo) do { \
|
---|
2569 | RT_NOREF_PV(a_idxVar); \
|
---|
2570 | AssertMsg( ((a_idxVar) & IEMNATIVE_VAR_IDX_MAGIC_MASK) == IEMNATIVE_VAR_IDX_MAGIC \
|
---|
2571 | && (unsigned)IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
|
---|
2572 | && ((a_pReNative)->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar))) \
|
---|
2573 | && (a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].uArgNo == (a_uArgNo), \
|
---|
2574 | ("%s=%d; uArgNo=%d, expected %u\n", #a_idxVar, a_idxVar, \
|
---|
2575 | (a_pReNative)->Core.aVars[RT_MIN(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar), \
|
---|
2576 | RT_ELEMENTS((a_pReNative)->Core.aVars)) - 1].uArgNo, \
|
---|
2577 | a_uArgNo)); \
|
---|
2578 | } while (0)
|
---|
2579 | #else
|
---|
2580 | # define IEMNATIVE_ASSERT_ARG_VAR_IDX(a_pReNative, a_idxVar, a_uArgNo) do { \
|
---|
2581 | RT_NOREF_PV(a_idxVar); \
|
---|
2582 | AssertMsg( (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
|
---|
2583 | && ((a_pReNative)->Core.bmVars & RT_BIT_32(a_idxVar))\
|
---|
2584 | && (a_pReNative)->Core.aVars[a_idxVar].uArgNo == (a_uArgNo) \
|
---|
2585 | , ("%s=%d; uArgNo=%d, expected %u\n", #a_idxVar, a_idxVar, \
|
---|
2586 | (a_pReNative)->Core.aVars[RT_MIN(a_idxVar, RT_ELEMENTS((a_pReNative)->Core.aVars)) - 1].uArgNo, a_uArgNo)); \
|
---|
2587 | } while (0)
|
---|
2588 | #endif
|
---|
2589 |
|
---|
2590 |
|
---|
2591 | /**
|
---|
2592 | * Checks that a variable has the expected size.
|
---|
2593 | */
|
---|
2594 | #define IEMNATIVE_ASSERT_VAR_SIZE(a_pReNative, a_idxVar, a_cbVar) \
|
---|
2595 | AssertMsg((a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].cbVar == (a_cbVar), \
|
---|
2596 | ("%s=%#x: cbVar=%#x, expected %#x!\n", #a_idxVar, a_idxVar, \
|
---|
2597 | (a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].cbVar, (a_cbVar)))
|
---|
2598 |
|
---|
2599 |
|
---|
2600 | /**
|
---|
2601 | * Calculates the stack address of a variable as a [r]BP displacement value.
|
---|
2602 | */
|
---|
2603 | DECL_FORCE_INLINE(int32_t)
|
---|
2604 | iemNativeStackCalcBpDisp(uint8_t idxStackSlot)
|
---|
2605 | {
|
---|
2606 | Assert(idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS);
|
---|
2607 | return idxStackSlot * sizeof(uint64_t) + IEMNATIVE_FP_OFF_STACK_VARS;
|
---|
2608 | }
|
---|
2609 |
|
---|
2610 |
|
---|
2611 | /**
|
---|
2612 | * Releases the variable's register.
|
---|
2613 | *
|
---|
2614 | * The register must have been previously acquired calling
|
---|
2615 | * iemNativeVarRegisterAcquire(), iemNativeVarRegisterAcquireForGuestReg() or
|
---|
2616 | * iemNativeVarRegisterSetAndAcquire().
|
---|
2617 | */
|
---|
2618 | DECL_INLINE_THROW(void) iemNativeVarRegisterRelease(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar)
|
---|
2619 | {
|
---|
2620 | IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
|
---|
2621 | Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired);
|
---|
2622 | pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired = false;
|
---|
2623 | }
|
---|
2624 |
|
---|
2625 |
|
---|
2626 | DECL_INLINE_THROW(void) iemNativeVarSimdRegisterRelease(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar)
|
---|
2627 | {
|
---|
2628 | Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fSimdReg);
|
---|
2629 | iemNativeVarRegisterRelease(pReNative, idxVar);
|
---|
2630 | }
|
---|
2631 |
|
---|
2632 |
|
---|
2633 | /**
|
---|
2634 | * Makes sure variable @a idxVar has a register assigned to it and that it stays
|
---|
2635 | * fixed till we call iemNativeVarRegisterRelease.
|
---|
2636 | *
|
---|
2637 | * @returns The host register number.
|
---|
2638 | * @param pReNative The recompiler state.
|
---|
2639 | * @param idxVar The variable.
|
---|
2640 | * @param poff Pointer to the instruction buffer offset.
|
---|
2641 | * In case a register needs to be freed up or the value
|
---|
2642 | * loaded off the stack.
|
---|
2643 | * @note Must not modify the host status flags!
|
---|
2644 | */
|
---|
2645 | DECL_INLINE_THROW(uint8_t) iemNativeVarRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
|
---|
2646 | {
|
---|
2647 | IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
|
---|
2648 | PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
|
---|
2649 | Assert(pVar->cbVar <= 8);
|
---|
2650 | Assert(!pVar->fRegAcquired);
|
---|
2651 | uint8_t const idxReg = pVar->idxReg;
|
---|
2652 | if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
|
---|
2653 | {
|
---|
2654 | Assert( pVar->enmKind > kIemNativeVarKind_Invalid
|
---|
2655 | && pVar->enmKind < kIemNativeVarKind_End);
|
---|
2656 | pVar->fRegAcquired = true;
|
---|
2657 | return idxReg;
|
---|
2658 | }
|
---|
2659 | return iemNativeVarRegisterAcquireSlow(pReNative, idxVar, poff);
|
---|
2660 | }
|
---|
2661 |
|
---|
2662 |
|
---|
2663 | /**
|
---|
2664 | * Makes sure variable @a idxVar has a register assigned to it and that it stays
|
---|
2665 | * fixed till we call iemNativeVarRegisterRelease.
|
---|
2666 | *
|
---|
2667 | * @returns The host register number.
|
---|
2668 | * @param pReNative The recompiler state.
|
---|
2669 | * @param idxVar The variable.
|
---|
2670 | * @param poff Pointer to the instruction buffer offset.
|
---|
2671 | * In case a register needs to be freed up or the value
|
---|
2672 | * loaded off the stack.
|
---|
2673 | * @param idxRegPref Preferred register number.
|
---|
2674 | * @note Must not modify the host status flags!
|
---|
2675 | */
|
---|
2676 | DECL_INLINE_THROW(uint8_t)
|
---|
2677 | iemNativeVarRegisterAcquireWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
|
---|
2678 | {
|
---|
2679 | IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
|
---|
2680 | PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
|
---|
2681 | Assert(pVar->cbVar <= 8);
|
---|
2682 | Assert(!pVar->fRegAcquired);
|
---|
2683 | Assert(idxRegPref < RT_ELEMENTS(pReNative->Core.aHstRegs));
|
---|
2684 | uint8_t const idxReg = pVar->idxReg;
|
---|
2685 | if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
|
---|
2686 | {
|
---|
2687 | Assert( pVar->enmKind > kIemNativeVarKind_Invalid
|
---|
2688 | && pVar->enmKind < kIemNativeVarKind_End);
|
---|
2689 | pVar->fRegAcquired = true;
|
---|
2690 | return idxReg;
|
---|
2691 | }
|
---|
2692 | return iemNativeVarRegisterAcquireWithPrefSlow(pReNative, idxVar, poff, idxRegPref);
|
---|
2693 | }
|
---|
2694 |
|
---|
2695 |
|
---|
2696 | /**
|
---|
2697 | * Makes sure variable @a idxVar has a register assigned to it and that it stays
|
---|
2698 | * fixed till we call iemNativeVarRegisterRelease.
|
---|
2699 | *
|
---|
2700 | * The variable must be initialized or VERR_IEM_VAR_NOT_INITIALIZED will be
|
---|
2701 | * thrown.
|
---|
2702 | *
|
---|
2703 | * @returns The host register number.
|
---|
2704 | * @param pReNative The recompiler state.
|
---|
2705 | * @param idxVar The variable.
|
---|
2706 | * @param poff Pointer to the instruction buffer offset.
|
---|
2707 | * In case a register needs to be freed up or the value
|
---|
2708 | * loaded off the stack.
|
---|
2709 | * @note Must not modify the host status flags!
|
---|
2710 | */
|
---|
2711 | DECL_INLINE_THROW(uint8_t) iemNativeVarRegisterAcquireInited(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
|
---|
2712 | {
|
---|
2713 | IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
|
---|
2714 | PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
|
---|
2715 | Assert(pVar->cbVar <= 8);
|
---|
2716 | Assert(!pVar->fRegAcquired);
|
---|
2717 | uint8_t const idxReg = pVar->idxReg;
|
---|
2718 | if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
|
---|
2719 | {
|
---|
2720 | Assert( pVar->enmKind > kIemNativeVarKind_Invalid
|
---|
2721 | && pVar->enmKind < kIemNativeVarKind_End);
|
---|
2722 | pVar->fRegAcquired = true;
|
---|
2723 | return idxReg;
|
---|
2724 | }
|
---|
2725 | return iemNativeVarRegisterAcquireInitedSlow(pReNative, idxVar, poff);
|
---|
2726 | }
|
---|
2727 |
|
---|
2728 |
|
---|
2729 | /**
|
---|
2730 | * Makes sure variable @a idxVar has a register assigned to it and that it stays
|
---|
2731 | * fixed till we call iemNativeVarRegisterRelease.
|
---|
2732 | *
|
---|
2733 | * The variable must be initialized or VERR_IEM_VAR_NOT_INITIALIZED will be
|
---|
2734 | * thrown.
|
---|
2735 | *
|
---|
2736 | * @returns The host register number.
|
---|
2737 | * @param pReNative The recompiler state.
|
---|
2738 | * @param idxVar The variable.
|
---|
2739 | * @param poff Pointer to the instruction buffer offset.
|
---|
2740 | * In case a register needs to be freed up or the value
|
---|
2741 | * loaded off the stack.
|
---|
2742 | * @param idxRegPref Preferred register number.
|
---|
2743 | * @note Must not modify the host status flags!
|
---|
2744 | */
|
---|
2745 | DECL_INLINE_THROW(uint8_t)
|
---|
2746 | iemNativeVarRegisterAcquireInitedWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
|
---|
2747 | {
|
---|
2748 | IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
|
---|
2749 | PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
|
---|
2750 | Assert(pVar->cbVar <= 8);
|
---|
2751 | Assert(!pVar->fRegAcquired);
|
---|
2752 | Assert(idxRegPref < RT_ELEMENTS(pReNative->Core.aHstRegs));
|
---|
2753 | uint8_t const idxReg = pVar->idxReg;
|
---|
2754 | if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
|
---|
2755 | {
|
---|
2756 | Assert( pVar->enmKind > kIemNativeVarKind_Invalid
|
---|
2757 | && pVar->enmKind < kIemNativeVarKind_End);
|
---|
2758 | pVar->fRegAcquired = true;
|
---|
2759 | return idxReg;
|
---|
2760 | }
|
---|
2761 | return iemNativeVarRegisterAcquireInitedWithPrefSlow(pReNative, idxVar, poff, idxRegPref);
|
---|
2762 | }
|
---|
2763 |
|
---|
2764 |
|
---|
2765 | /**
|
---|
2766 | * Converts IEM_CIMPL_F_XXX flags into a guest register shadow copy flush mask.
|
---|
2767 | *
|
---|
2768 | * @returns The flush mask.
|
---|
2769 | * @param fCImpl The IEM_CIMPL_F_XXX flags.
|
---|
2770 | * @param fGstShwFlush The starting flush mask.
|
---|
2771 | */
|
---|
2772 | DECL_FORCE_INLINE(uint64_t) iemNativeCImplFlagsToGuestShadowFlushMask(uint32_t fCImpl, uint64_t fGstShwFlush)
|
---|
2773 | {
|
---|
2774 | if (fCImpl & IEM_CIMPL_F_BRANCH_FAR)
|
---|
2775 | fGstShwFlush |= RT_BIT_64(kIemNativeGstReg_SegSelFirst + X86_SREG_CS)
|
---|
2776 | | RT_BIT_64(kIemNativeGstReg_SegBaseFirst + X86_SREG_CS)
|
---|
2777 | | RT_BIT_64(kIemNativeGstReg_SegLimitFirst + X86_SREG_CS);
|
---|
2778 | if (fCImpl & IEM_CIMPL_F_BRANCH_STACK_FAR)
|
---|
2779 | fGstShwFlush |= RT_BIT_64(kIemNativeGstReg_GprFirst + X86_GREG_xSP)
|
---|
2780 | | RT_BIT_64(kIemNativeGstReg_SegSelFirst + X86_SREG_SS)
|
---|
2781 | | RT_BIT_64(kIemNativeGstReg_SegBaseFirst + X86_SREG_SS)
|
---|
2782 | | RT_BIT_64(kIemNativeGstReg_SegLimitFirst + X86_SREG_SS);
|
---|
2783 | else if (fCImpl & IEM_CIMPL_F_BRANCH_STACK)
|
---|
2784 | fGstShwFlush |= RT_BIT_64(kIemNativeGstReg_GprFirst + X86_GREG_xSP);
|
---|
2785 | if (fCImpl & (IEM_CIMPL_F_RFLAGS | IEM_CIMPL_F_STATUS_FLAGS | IEM_CIMPL_F_INHIBIT_SHADOW))
|
---|
2786 | fGstShwFlush |= RT_BIT_64(kIemNativeGstReg_EFlags);
|
---|
2787 | return fGstShwFlush;
|
---|
2788 | }
|
---|
2789 |
|
---|
2790 |
|
---|
2791 | /** Number of hidden arguments for CIMPL calls.
|
---|
2792 | * @note We're sufferning from the usual VBOXSTRICTRC fun on Windows. */
|
---|
2793 | #if defined(VBOXSTRICTRC_STRICT_ENABLED) && defined(RT_OS_WINDOWS) && defined(RT_ARCH_AMD64)
|
---|
2794 | # define IEM_CIMPL_HIDDEN_ARGS 3
|
---|
2795 | #else
|
---|
2796 | # define IEM_CIMPL_HIDDEN_ARGS 2
|
---|
2797 | #endif
|
---|
2798 |
|
---|
2799 |
|
---|
2800 | /** Number of hidden arguments for SSE_AIMPL calls. */
|
---|
2801 | #define IEM_SSE_AIMPL_HIDDEN_ARGS 1
|
---|
2802 | /** Number of hidden arguments for AVX_AIMPL calls. */
|
---|
2803 | #define IEM_AVX_AIMPL_HIDDEN_ARGS 1
|
---|
2804 |
|
---|
2805 |
|
---|
2806 | #ifdef IEMNATIVE_WITH_LIVENESS_ANALYSIS
|
---|
2807 |
|
---|
2808 | # ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
2809 | /**
|
---|
2810 | * Helper for iemNativeLivenessGetStateByGstReg.
|
---|
2811 | *
|
---|
2812 | * @returns IEMLIVENESS_STATE_XXX
|
---|
2813 | * @param fMergedStateExp2 This is the RT_BIT_32() of each sub-state
|
---|
2814 | * ORed together.
|
---|
2815 | */
|
---|
2816 | DECL_FORCE_INLINE(uint32_t)
|
---|
2817 | iemNativeLivenessMergeExpandedEFlagsState(uint32_t fMergedStateExp2)
|
---|
2818 | {
|
---|
2819 | /* INPUT trumps anything else. */
|
---|
2820 | if (fMergedStateExp2 & RT_BIT_32(IEMLIVENESS_STATE_INPUT))
|
---|
2821 | return IEMLIVENESS_STATE_INPUT;
|
---|
2822 |
|
---|
2823 | /* CLOBBERED trumps XCPT_OR_CALL and UNUSED. */
|
---|
2824 | if (fMergedStateExp2 & RT_BIT_32(IEMLIVENESS_STATE_CLOBBERED))
|
---|
2825 | {
|
---|
2826 | /* If not all sub-fields are clobbered they must be considered INPUT. */
|
---|
2827 | if (fMergedStateExp2 & (RT_BIT_32(IEMLIVENESS_STATE_UNUSED) | RT_BIT_32(IEMLIVENESS_STATE_XCPT_OR_CALL)))
|
---|
2828 | return IEMLIVENESS_STATE_INPUT;
|
---|
2829 | return IEMLIVENESS_STATE_CLOBBERED;
|
---|
2830 | }
|
---|
2831 |
|
---|
2832 | /* XCPT_OR_CALL trumps UNUSED. */
|
---|
2833 | if (fMergedStateExp2 & RT_BIT_32(IEMLIVENESS_STATE_XCPT_OR_CALL))
|
---|
2834 | return IEMLIVENESS_STATE_XCPT_OR_CALL;
|
---|
2835 |
|
---|
2836 | return IEMLIVENESS_STATE_UNUSED;
|
---|
2837 | }
|
---|
2838 | # endif /* !IEMLIVENESS_EXTENDED_LAYOUT */
|
---|
2839 |
|
---|
2840 |
|
---|
2841 | DECL_FORCE_INLINE(uint32_t)
|
---|
2842 | iemNativeLivenessGetStateByGstRegEx(PCIEMLIVENESSENTRY pLivenessEntry, unsigned enmGstRegEx)
|
---|
2843 | {
|
---|
2844 | # ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
2845 | return ((pLivenessEntry->Bit0.bm64 >> enmGstRegEx) & 1)
|
---|
2846 | | (((pLivenessEntry->Bit1.bm64 >> enmGstRegEx) << 1) & 2);
|
---|
2847 | # else
|
---|
2848 | return ( (pLivenessEntry->Bit0.bm64 >> enmGstRegEx) & 1)
|
---|
2849 | | (((pLivenessEntry->Bit1.bm64 >> enmGstRegEx) << 1) & 2)
|
---|
2850 | | (((pLivenessEntry->Bit2.bm64 >> enmGstRegEx) << 2) & 4)
|
---|
2851 | | (((pLivenessEntry->Bit3.bm64 >> enmGstRegEx) << 3) & 8);
|
---|
2852 | # endif
|
---|
2853 | }
|
---|
2854 |
|
---|
2855 |
|
---|
2856 | DECL_FORCE_INLINE(uint32_t)
|
---|
2857 | iemNativeLivenessGetStateByGstReg(PCIEMLIVENESSENTRY pLivenessEntry, IEMNATIVEGSTREG enmGstReg)
|
---|
2858 | {
|
---|
2859 | uint32_t uRet = iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, (unsigned)enmGstReg);
|
---|
2860 | if (enmGstReg == kIemNativeGstReg_EFlags)
|
---|
2861 | {
|
---|
2862 | /* Merge the eflags states to one. */
|
---|
2863 | # ifndef IEMLIVENESS_EXTENDED_LAYOUT
|
---|
2864 | uRet = RT_BIT_32(uRet);
|
---|
2865 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflCf | (pLivenessEntry->Bit1.fEflCf << 1));
|
---|
2866 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflPf | (pLivenessEntry->Bit1.fEflPf << 1));
|
---|
2867 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflAf | (pLivenessEntry->Bit1.fEflAf << 1));
|
---|
2868 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflZf | (pLivenessEntry->Bit1.fEflZf << 1));
|
---|
2869 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflSf | (pLivenessEntry->Bit1.fEflSf << 1));
|
---|
2870 | uRet |= RT_BIT_32(pLivenessEntry->Bit0.fEflOf | (pLivenessEntry->Bit1.fEflOf << 1));
|
---|
2871 | uRet = iemNativeLivenessMergeExpandedEFlagsState(uRet);
|
---|
2872 | # else
|
---|
2873 | AssertCompile(IEMLIVENESSBIT_IDX_EFL_OTHER == (unsigned)kIemNativeGstReg_EFlags);
|
---|
2874 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_CF);
|
---|
2875 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_PF);
|
---|
2876 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_AF);
|
---|
2877 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_ZF);
|
---|
2878 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_SF);
|
---|
2879 | uRet |= iemNativeLivenessGetStateByGstRegEx(pLivenessEntry, IEMLIVENESSBIT_IDX_EFL_OF);
|
---|
2880 | # endif
|
---|
2881 | }
|
---|
2882 | return uRet;
|
---|
2883 | }
|
---|
2884 |
|
---|
2885 | # ifdef VBOX_STRICT
|
---|
2886 |
|
---|
2887 | /** For assertions only - caller checks that idxCurCall isn't zero. */
|
---|
2888 | DECL_FORCE_INLINE(uint32_t)
|
---|
2889 | iemNativeLivenessGetPrevStateByGstReg(PIEMRECOMPILERSTATE pReNative, IEMNATIVEGSTREG enmGstReg)
|
---|
2890 | {
|
---|
2891 | return iemNativeLivenessGetStateByGstReg(&pReNative->paLivenessEntries[pReNative->idxCurCall - 1], enmGstReg);
|
---|
2892 | }
|
---|
2893 |
|
---|
2894 |
|
---|
2895 | /** For assertions only - caller checks that idxCurCall isn't zero. */
|
---|
2896 | DECL_FORCE_INLINE(uint32_t)
|
---|
2897 | iemNativeLivenessGetPrevStateByGstRegEx(PIEMRECOMPILERSTATE pReNative, IEMNATIVEGSTREG enmGstReg)
|
---|
2898 | {
|
---|
2899 | return iemNativeLivenessGetStateByGstRegEx(&pReNative->paLivenessEntries[pReNative->idxCurCall - 1], enmGstReg);
|
---|
2900 | }
|
---|
2901 |
|
---|
2902 | # endif /* VBOX_STRICT */
|
---|
2903 | #endif /* IEMNATIVE_WITH_LIVENESS_ANALYSIS */
|
---|
2904 |
|
---|
2905 |
|
---|
2906 | /**
|
---|
2907 | * Gets the number of hidden arguments for an expected IEM_MC_CALL statement.
|
---|
2908 | */
|
---|
2909 | DECL_FORCE_INLINE(uint8_t) iemNativeArgGetHiddenArgCount(PIEMRECOMPILERSTATE pReNative)
|
---|
2910 | {
|
---|
2911 | if (pReNative->fCImpl & IEM_CIMPL_F_CALLS_CIMPL)
|
---|
2912 | return IEM_CIMPL_HIDDEN_ARGS;
|
---|
2913 | if (pReNative->fCImpl & (IEM_CIMPL_F_CALLS_AIMPL_WITH_FXSTATE | IEM_CIMPL_F_CALLS_AIMPL_WITH_XSTATE))
|
---|
2914 | return 1;
|
---|
2915 | return 0;
|
---|
2916 | }
|
---|
2917 |
|
---|
2918 |
|
---|
2919 | DECL_FORCE_INLINE(uint8_t) iemNativeRegMarkAllocated(PIEMRECOMPILERSTATE pReNative, unsigned idxReg,
|
---|
2920 | IEMNATIVEWHAT enmWhat, uint8_t idxVar = UINT8_MAX) RT_NOEXCEPT
|
---|
2921 | {
|
---|
2922 | pReNative->Core.bmHstRegs |= RT_BIT_32(idxReg);
|
---|
2923 |
|
---|
2924 | pReNative->Core.aHstRegs[idxReg].enmWhat = enmWhat;
|
---|
2925 | pReNative->Core.aHstRegs[idxReg].fGstRegShadows = 0;
|
---|
2926 | pReNative->Core.aHstRegs[idxReg].idxVar = idxVar;
|
---|
2927 | return (uint8_t)idxReg;
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 |
|
---|
2931 |
|
---|
2932 | /*********************************************************************************************************************************
|
---|
2933 | * Register Allocator (GPR) *
|
---|
2934 | *********************************************************************************************************************************/
|
---|
2935 |
|
---|
2936 | #ifdef RT_ARCH_ARM64
|
---|
2937 | # include <iprt/armv8.h>
|
---|
2938 | #endif
|
---|
2939 |
|
---|
2940 |
|
---|
2941 | /**
|
---|
2942 | * Marks host register @a idxHstReg as containing a shadow copy of guest
|
---|
2943 | * register @a enmGstReg.
|
---|
2944 | *
|
---|
2945 | * ASSUMES that caller has made sure @a enmGstReg is not associated with any
|
---|
2946 | * host register before calling.
|
---|
2947 | */
|
---|
2948 | DECL_FORCE_INLINE(void)
|
---|
2949 | iemNativeRegMarkAsGstRegShadow(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg, IEMNATIVEGSTREG enmGstReg, uint32_t off)
|
---|
2950 | {
|
---|
2951 | Assert(!(pReNative->Core.bmGstRegShadows & RT_BIT_64(enmGstReg)));
|
---|
2952 | Assert(!pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows);
|
---|
2953 | Assert((unsigned)enmGstReg < (unsigned)kIemNativeGstReg_End);
|
---|
2954 |
|
---|
2955 | pReNative->Core.aidxGstRegShadows[enmGstReg] = idxHstReg;
|
---|
2956 | pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows = RT_BIT_64(enmGstReg); /** @todo why? not OR? */
|
---|
2957 | pReNative->Core.bmGstRegShadows |= RT_BIT_64(enmGstReg);
|
---|
2958 | pReNative->Core.bmHstRegsWithGstShadow |= RT_BIT_32(idxHstReg);
|
---|
2959 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
2960 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
2961 | iemNativeDbgInfoAddGuestRegShadowing(pReNative, enmGstReg, idxHstReg);
|
---|
2962 | #else
|
---|
2963 | RT_NOREF(off);
|
---|
2964 | #endif
|
---|
2965 | }
|
---|
2966 |
|
---|
2967 |
|
---|
2968 | /**
|
---|
2969 | * Clear any guest register shadow claims from @a idxHstReg.
|
---|
2970 | *
|
---|
2971 | * The register does not need to be shadowing any guest registers.
|
---|
2972 | */
|
---|
2973 | DECL_FORCE_INLINE(void)
|
---|
2974 | iemNativeRegClearGstRegShadowing(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg, uint32_t off)
|
---|
2975 | {
|
---|
2976 | Assert( (pReNative->Core.bmGstRegShadows & pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows)
|
---|
2977 | == pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows
|
---|
2978 | && pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
2979 | Assert( RT_BOOL(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxHstReg))
|
---|
2980 | == RT_BOOL(pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows));
|
---|
2981 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
2982 | Assert(!(pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows & pReNative->Core.bmGstRegShadowDirty));
|
---|
2983 | #endif
|
---|
2984 |
|
---|
2985 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
2986 | uint64_t fGstRegs = pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows;
|
---|
2987 | if (fGstRegs)
|
---|
2988 | {
|
---|
2989 | Assert(fGstRegs < RT_BIT_64(kIemNativeGstReg_End));
|
---|
2990 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
2991 | while (fGstRegs)
|
---|
2992 | {
|
---|
2993 | unsigned const iGstReg = ASMBitFirstSetU64(fGstRegs) - 1;
|
---|
2994 | fGstRegs &= ~RT_BIT_64(iGstReg);
|
---|
2995 | iemNativeDbgInfoAddGuestRegShadowing(pReNative, (IEMNATIVEGSTREG)iGstReg, UINT8_MAX, idxHstReg);
|
---|
2996 | }
|
---|
2997 | }
|
---|
2998 | #else
|
---|
2999 | RT_NOREF(off);
|
---|
3000 | #endif
|
---|
3001 |
|
---|
3002 | pReNative->Core.bmHstRegsWithGstShadow &= ~RT_BIT_32(idxHstReg);
|
---|
3003 | pReNative->Core.bmGstRegShadows &= ~pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows;
|
---|
3004 | pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows = 0;
|
---|
3005 | }
|
---|
3006 |
|
---|
3007 |
|
---|
3008 | /**
|
---|
3009 | * Clear guest register shadow claim regarding @a enmGstReg from @a idxHstReg
|
---|
3010 | * and global overview flags.
|
---|
3011 | */
|
---|
3012 | DECL_FORCE_INLINE(void)
|
---|
3013 | iemNativeRegClearGstRegShadowingOne(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg, IEMNATIVEGSTREG enmGstReg, uint32_t off)
|
---|
3014 | {
|
---|
3015 | Assert(pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3016 | Assert( (pReNative->Core.bmGstRegShadows & pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows)
|
---|
3017 | == pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows
|
---|
3018 | && pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3019 | Assert(pReNative->Core.bmGstRegShadows & RT_BIT_64(enmGstReg));
|
---|
3020 | Assert(pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows & RT_BIT_64(enmGstReg));
|
---|
3021 | Assert(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxHstReg));
|
---|
3022 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
3023 | Assert(!(pReNative->Core.bmGstRegShadowDirty & RT_BIT_64(enmGstReg)));
|
---|
3024 | #endif
|
---|
3025 |
|
---|
3026 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
3027 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
3028 | iemNativeDbgInfoAddGuestRegShadowing(pReNative, enmGstReg, UINT8_MAX, idxHstReg);
|
---|
3029 | #else
|
---|
3030 | RT_NOREF(off);
|
---|
3031 | #endif
|
---|
3032 |
|
---|
3033 | uint64_t const fGstRegShadowsNew = pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows & ~RT_BIT_64(enmGstReg);
|
---|
3034 | pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows = fGstRegShadowsNew;
|
---|
3035 | if (!fGstRegShadowsNew)
|
---|
3036 | pReNative->Core.bmHstRegsWithGstShadow &= ~RT_BIT_32(idxHstReg);
|
---|
3037 | pReNative->Core.bmGstRegShadows &= ~RT_BIT_64(enmGstReg);
|
---|
3038 | }
|
---|
3039 |
|
---|
3040 |
|
---|
3041 | #if 0 /* unused */
|
---|
3042 | /**
|
---|
3043 | * Clear any guest register shadow claim for @a enmGstReg.
|
---|
3044 | */
|
---|
3045 | DECL_FORCE_INLINE(void)
|
---|
3046 | iemNativeRegClearGstRegShadowingByGstReg(PIEMRECOMPILERSTATE pReNative, IEMNATIVEGSTREG enmGstReg, uint32_t off)
|
---|
3047 | {
|
---|
3048 | Assert(pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3049 | if (pReNative->Core.bmGstRegShadows & RT_BIT_64(enmGstReg))
|
---|
3050 | {
|
---|
3051 | Assert(pReNative->Core.aidxGstRegShadows[enmGstReg] < RT_ELEMENTS(pReNative->Core.aHstRegs));
|
---|
3052 | iemNativeRegClearGstRegShadowingOne(pReNative, pReNative->Core.aidxGstRegShadows[enmGstReg], enmGstReg, off);
|
---|
3053 | }
|
---|
3054 | }
|
---|
3055 | #endif
|
---|
3056 |
|
---|
3057 |
|
---|
3058 | /**
|
---|
3059 | * Clear any guest register shadow claim for @a enmGstReg and mark @a idxHstRegNew
|
---|
3060 | * as the new shadow of it.
|
---|
3061 | *
|
---|
3062 | * Unlike the other guest reg shadow helpers, this does the logging for you.
|
---|
3063 | * However, it is the liveness state is not asserted here, the caller must do
|
---|
3064 | * that.
|
---|
3065 | */
|
---|
3066 | DECL_FORCE_INLINE(void)
|
---|
3067 | iemNativeRegClearAndMarkAsGstRegShadow(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstRegNew,
|
---|
3068 | IEMNATIVEGSTREG enmGstReg, uint32_t off)
|
---|
3069 | {
|
---|
3070 | Assert(pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3071 | if (pReNative->Core.bmGstRegShadows & RT_BIT_64(enmGstReg))
|
---|
3072 | {
|
---|
3073 | uint8_t const idxHstRegOld = pReNative->Core.aidxGstRegShadows[enmGstReg];
|
---|
3074 | Assert(idxHstRegOld < RT_ELEMENTS(pReNative->Core.aHstRegs));
|
---|
3075 | if (idxHstRegOld == idxHstRegNew)
|
---|
3076 | return;
|
---|
3077 | Log12(("iemNativeRegClearAndMarkAsGstRegShadow: %s for guest %s (from %s)\n", g_apszIemNativeHstRegNames[idxHstRegNew],
|
---|
3078 | g_aGstShadowInfo[enmGstReg].pszName, g_apszIemNativeHstRegNames[idxHstRegOld]));
|
---|
3079 | iemNativeRegClearGstRegShadowingOne(pReNative, pReNative->Core.aidxGstRegShadows[enmGstReg], enmGstReg, off);
|
---|
3080 | }
|
---|
3081 | else
|
---|
3082 | Log12(("iemNativeRegClearAndMarkAsGstRegShadow: %s for guest %s\n", g_apszIemNativeHstRegNames[idxHstRegNew],
|
---|
3083 | g_aGstShadowInfo[enmGstReg].pszName));
|
---|
3084 | iemNativeRegMarkAsGstRegShadow(pReNative, idxHstRegNew, enmGstReg, off);
|
---|
3085 | }
|
---|
3086 |
|
---|
3087 |
|
---|
3088 | /**
|
---|
3089 | * Transfers the guest register shadow claims of @a enmGstReg from @a idxRegFrom
|
---|
3090 | * to @a idxRegTo.
|
---|
3091 | */
|
---|
3092 | DECL_FORCE_INLINE(void)
|
---|
3093 | iemNativeRegTransferGstRegShadowing(PIEMRECOMPILERSTATE pReNative, uint8_t idxRegFrom, uint8_t idxRegTo,
|
---|
3094 | IEMNATIVEGSTREG enmGstReg, uint32_t off)
|
---|
3095 | {
|
---|
3096 | Assert(pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows & RT_BIT_64(enmGstReg));
|
---|
3097 | Assert(pReNative->Core.aidxGstRegShadows[enmGstReg] == idxRegFrom);
|
---|
3098 | Assert( (pReNative->Core.bmGstRegShadows & pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows)
|
---|
3099 | == pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows
|
---|
3100 | && pReNative->Core.bmGstRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3101 | Assert( (pReNative->Core.bmGstRegShadows & pReNative->Core.aHstRegs[idxRegTo].fGstRegShadows)
|
---|
3102 | == pReNative->Core.aHstRegs[idxRegTo].fGstRegShadows);
|
---|
3103 | Assert( RT_BOOL(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxRegFrom))
|
---|
3104 | == RT_BOOL(pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows));
|
---|
3105 |
|
---|
3106 | uint64_t const fGstRegShadowsFrom = pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows & ~RT_BIT_64(enmGstReg);
|
---|
3107 | pReNative->Core.aHstRegs[idxRegFrom].fGstRegShadows = fGstRegShadowsFrom;
|
---|
3108 | if (!fGstRegShadowsFrom)
|
---|
3109 | pReNative->Core.bmHstRegsWithGstShadow &= ~RT_BIT_32(idxRegFrom);
|
---|
3110 | pReNative->Core.bmHstRegsWithGstShadow |= RT_BIT_32(idxRegTo);
|
---|
3111 | pReNative->Core.aHstRegs[idxRegTo].fGstRegShadows |= RT_BIT_64(enmGstReg);
|
---|
3112 | pReNative->Core.aidxGstRegShadows[enmGstReg] = idxRegTo;
|
---|
3113 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
3114 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
3115 | iemNativeDbgInfoAddGuestRegShadowing(pReNative, enmGstReg, idxRegTo, idxRegFrom);
|
---|
3116 | #else
|
---|
3117 | RT_NOREF(off);
|
---|
3118 | #endif
|
---|
3119 | }
|
---|
3120 |
|
---|
3121 |
|
---|
3122 | /**
|
---|
3123 | * Flushes any delayed guest register writes.
|
---|
3124 | *
|
---|
3125 | * This must be called prior to calling CImpl functions and any helpers that use
|
---|
3126 | * the guest state (like raising exceptions) and such.
|
---|
3127 | *
|
---|
3128 | * This optimization has not yet been implemented. The first target would be
|
---|
3129 | * RIP updates, since these are the most common ones.
|
---|
3130 | *
|
---|
3131 | * @note This function does not flush any shadowing information for guest
|
---|
3132 | * registers. This needs to be done by the caller if it wishes to do so.
|
---|
3133 | */
|
---|
3134 | DECL_INLINE_THROW(uint32_t)
|
---|
3135 | iemNativeRegFlushPendingWrites(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint64_t fGstShwExcept = 0,
|
---|
3136 | uint64_t fGstSimdShwExcept = 0)
|
---|
3137 | {
|
---|
3138 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
3139 | uint64_t const fWritebackPc = ~fGstShwExcept & RT_BIT_64(kIemNativeGstReg_Pc);
|
---|
3140 | #else
|
---|
3141 | uint64_t const fWritebackPc = 0;
|
---|
3142 | #endif
|
---|
3143 | #ifdef IEMNATIVE_WITH_DELAYED_REGISTER_WRITEBACK
|
---|
3144 | uint64_t const bmGstRegShadowDirty = pReNative->Core.bmGstRegShadowDirty & ~fGstShwExcept;
|
---|
3145 | #else
|
---|
3146 | uint64_t const bmGstRegShadowDirty = 0;
|
---|
3147 | #endif
|
---|
3148 | uint64_t const bmGstSimdRegShadowDirty = ( pReNative->Core.bmGstSimdRegShadowDirtyLo128
|
---|
3149 | | pReNative->Core.bmGstSimdRegShadowDirtyHi128)
|
---|
3150 | & ~fGstSimdShwExcept;
|
---|
3151 | if (bmGstRegShadowDirty | bmGstSimdRegShadowDirty | fWritebackPc)
|
---|
3152 | return iemNativeRegFlushPendingWritesSlow(pReNative, off, fGstShwExcept, fGstSimdShwExcept);
|
---|
3153 |
|
---|
3154 | return off;
|
---|
3155 | }
|
---|
3156 |
|
---|
3157 |
|
---|
3158 | /**
|
---|
3159 | * Allocates a temporary host general purpose register for keeping a guest
|
---|
3160 | * register value.
|
---|
3161 | *
|
---|
3162 | * Since we may already have a register holding the guest register value,
|
---|
3163 | * code will be emitted to do the loading if that's not the case. Code may also
|
---|
3164 | * be emitted if we have to free up a register to satify the request.
|
---|
3165 | *
|
---|
3166 | * @returns The host register number; throws VBox status code on failure, so no
|
---|
3167 | * need to check the return value.
|
---|
3168 | * @param pReNative The native recompile state.
|
---|
3169 | * @param poff Pointer to the variable with the code buffer
|
---|
3170 | * position. This will be update if we need to move a
|
---|
3171 | * variable from register to stack in order to satisfy
|
---|
3172 | * the request.
|
---|
3173 | * @param enmGstReg The guest register that will is to be updated.
|
---|
3174 | * @param enmIntendedUse How the caller will be using the host register.
|
---|
3175 | * @param fNoVolatileRegs Set if no volatile register allowed, clear if any
|
---|
3176 | * register is okay (default). The ASSUMPTION here is
|
---|
3177 | * that the caller has already flushed all volatile
|
---|
3178 | * registers, so this is only applied if we allocate a
|
---|
3179 | * new register.
|
---|
3180 | * @sa iemNativeRegAllocTmpForGuestEFlags
|
---|
3181 | * iemNativeRegAllocTmpForGuestRegIfAlreadyPresent
|
---|
3182 | * iemNativeRegAllocTmpForGuestRegInt
|
---|
3183 | */
|
---|
3184 | DECL_FORCE_INLINE_THROW(uint8_t)
|
---|
3185 | iemNativeRegAllocTmpForGuestReg(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg,
|
---|
3186 | IEMNATIVEGSTREGUSE const enmIntendedUse = kIemNativeGstRegUse_ReadOnly,
|
---|
3187 | bool const fNoVolatileRegs = false)
|
---|
3188 | {
|
---|
3189 | if (enmIntendedUse == kIemNativeGstRegUse_ReadOnly)
|
---|
3190 | return !fNoVolatileRegs
|
---|
3191 | ? iemNativeRegAllocTmpForGuestRegReadOnly(pReNative, poff, enmGstReg)
|
---|
3192 | : iemNativeRegAllocTmpForGuestRegReadOnlyNoVolatile(pReNative, poff, enmGstReg);
|
---|
3193 | if (enmIntendedUse == kIemNativeGstRegUse_ForUpdate)
|
---|
3194 | return !fNoVolatileRegs
|
---|
3195 | ? iemNativeRegAllocTmpForGuestRegUpdate(pReNative, poff, enmGstReg)
|
---|
3196 | : iemNativeRegAllocTmpForGuestRegUpdateNoVolatile(pReNative, poff, enmGstReg);
|
---|
3197 | if (enmIntendedUse == kIemNativeGstRegUse_ForFullWrite)
|
---|
3198 | return !fNoVolatileRegs
|
---|
3199 | ? iemNativeRegAllocTmpForGuestRegFullWrite(pReNative, poff, enmGstReg)
|
---|
3200 | : iemNativeRegAllocTmpForGuestRegFullWriteNoVolatile(pReNative, poff, enmGstReg);
|
---|
3201 | Assert(enmIntendedUse == kIemNativeGstRegUse_Calculation);
|
---|
3202 | return !fNoVolatileRegs
|
---|
3203 | ? iemNativeRegAllocTmpForGuestRegCalculation(pReNative, poff, enmGstReg)
|
---|
3204 | : iemNativeRegAllocTmpForGuestRegCalculationNoVolatile(pReNative, poff, enmGstReg);
|
---|
3205 | }
|
---|
3206 |
|
---|
3207 | #if !defined(IEMNATIVE_WITH_LIVENESS_ANALYSIS) || !defined(VBOX_STRICT)
|
---|
3208 |
|
---|
3209 | DECL_FORCE_INLINE_THROW(uint8_t)
|
---|
3210 | iemNativeRegAllocTmpForGuestEFlagsReadOnly(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t fRead,
|
---|
3211 | uint64_t fWrite = 0, uint64_t fPotentialCall = 0)
|
---|
3212 | {
|
---|
3213 | RT_NOREF(fRead, fWrite, fPotentialCall);
|
---|
3214 | return iemNativeRegAllocTmpForGuestRegReadOnly(pReNative, poff, kIemNativeGstReg_EFlags);
|
---|
3215 | }
|
---|
3216 |
|
---|
3217 | DECL_FORCE_INLINE_THROW(uint8_t)
|
---|
3218 | iemNativeRegAllocTmpForGuestEFlagsForUpdate(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t fRead,
|
---|
3219 | uint64_t fWrite = 0, uint64_t fPotentialCall = 0)
|
---|
3220 | {
|
---|
3221 | RT_NOREF(fRead, fWrite, fPotentialCall);
|
---|
3222 | return iemNativeRegAllocTmpForGuestRegUpdate(pReNative, poff, kIemNativeGstReg_EFlags);
|
---|
3223 | }
|
---|
3224 |
|
---|
3225 | #endif
|
---|
3226 |
|
---|
3227 |
|
---|
3228 |
|
---|
3229 | /*********************************************************************************************************************************
|
---|
3230 | * SIMD register allocator (largely code duplication of the GPR allocator for now but might diverge) *
|
---|
3231 | *********************************************************************************************************************************/
|
---|
3232 |
|
---|
3233 | DECL_FORCE_INLINE(uint8_t)
|
---|
3234 | iemNativeSimdRegMarkAllocated(PIEMRECOMPILERSTATE pReNative, uint8_t idxSimdReg,
|
---|
3235 | IEMNATIVEWHAT enmWhat, uint8_t idxVar = UINT8_MAX) RT_NOEXCEPT
|
---|
3236 | {
|
---|
3237 | pReNative->Core.bmHstSimdRegs |= RT_BIT_32(idxSimdReg);
|
---|
3238 |
|
---|
3239 | pReNative->Core.aHstSimdRegs[idxSimdReg].enmWhat = enmWhat;
|
---|
3240 | pReNative->Core.aHstSimdRegs[idxSimdReg].idxVar = idxVar;
|
---|
3241 | pReNative->Core.aHstSimdRegs[idxSimdReg].fGstRegShadows = 0;
|
---|
3242 | return idxSimdReg;
|
---|
3243 | }
|
---|
3244 |
|
---|
3245 |
|
---|
3246 | /**
|
---|
3247 | * Marks host SIMD register @a idxHstSimdReg as containing a shadow copy of guest
|
---|
3248 | * SIMD register @a enmGstSimdReg.
|
---|
3249 | *
|
---|
3250 | * ASSUMES that caller has made sure @a enmGstSimdReg is not associated with any
|
---|
3251 | * host register before calling.
|
---|
3252 | */
|
---|
3253 | DECL_FORCE_INLINE(void)
|
---|
3254 | iemNativeSimdRegMarkAsGstSimdRegShadow(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstSimdReg,
|
---|
3255 | IEMNATIVEGSTSIMDREG enmGstSimdReg, uint32_t off)
|
---|
3256 | {
|
---|
3257 | Assert(!(pReNative->Core.bmGstSimdRegShadows & RT_BIT_64(enmGstSimdReg)));
|
---|
3258 | Assert(!pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows);
|
---|
3259 | Assert((unsigned)enmGstSimdReg < (unsigned)kIemNativeGstSimdReg_End);
|
---|
3260 |
|
---|
3261 | pReNative->Core.aidxGstSimdRegShadows[enmGstSimdReg] = idxHstSimdReg;
|
---|
3262 | pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows |= RT_BIT_64(enmGstSimdReg);
|
---|
3263 | pReNative->Core.bmGstSimdRegShadows |= RT_BIT_64(enmGstSimdReg);
|
---|
3264 | pReNative->Core.bmHstSimdRegsWithGstShadow |= RT_BIT_32(idxHstSimdReg);
|
---|
3265 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
3266 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
3267 | iemNativeDbgInfoAddGuestSimdRegShadowing(pReNative, enmGstSimdReg, idxHstSimdReg);
|
---|
3268 | #else
|
---|
3269 | RT_NOREF(off);
|
---|
3270 | #endif
|
---|
3271 | }
|
---|
3272 |
|
---|
3273 |
|
---|
3274 | /**
|
---|
3275 | * Transfers the guest SIMD register shadow claims of @a enmGstSimdReg from @a idxSimdRegFrom
|
---|
3276 | * to @a idxSimdRegTo.
|
---|
3277 | */
|
---|
3278 | DECL_FORCE_INLINE(void)
|
---|
3279 | iemNativeSimdRegTransferGstSimdRegShadowing(PIEMRECOMPILERSTATE pReNative, uint8_t idxSimdRegFrom, uint8_t idxSimdRegTo,
|
---|
3280 | IEMNATIVEGSTSIMDREG enmGstSimdReg, uint32_t off)
|
---|
3281 | {
|
---|
3282 | Assert(pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows & RT_BIT_64(enmGstSimdReg));
|
---|
3283 | Assert(pReNative->Core.aidxGstSimdRegShadows[enmGstSimdReg] == idxSimdRegFrom);
|
---|
3284 | Assert( (pReNative->Core.bmGstSimdRegShadows & pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows)
|
---|
3285 | == pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows
|
---|
3286 | && pReNative->Core.bmGstSimdRegShadows < RT_BIT_64(kIemNativeGstReg_End));
|
---|
3287 | Assert( (pReNative->Core.bmGstSimdRegShadows & pReNative->Core.aHstSimdRegs[idxSimdRegTo].fGstRegShadows)
|
---|
3288 | == pReNative->Core.aHstSimdRegs[idxSimdRegTo].fGstRegShadows);
|
---|
3289 | Assert( RT_BOOL(pReNative->Core.bmHstSimdRegsWithGstShadow & RT_BIT_32(idxSimdRegFrom))
|
---|
3290 | == RT_BOOL(pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows));
|
---|
3291 | Assert( pReNative->Core.aHstSimdRegs[idxSimdRegFrom].enmLoaded
|
---|
3292 | == pReNative->Core.aHstSimdRegs[idxSimdRegTo].enmLoaded);
|
---|
3293 |
|
---|
3294 | uint64_t const fGstRegShadowsFrom = pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows & ~RT_BIT_64(enmGstSimdReg);
|
---|
3295 | pReNative->Core.aHstSimdRegs[idxSimdRegFrom].fGstRegShadows = fGstRegShadowsFrom;
|
---|
3296 | if (!fGstRegShadowsFrom)
|
---|
3297 | {
|
---|
3298 | pReNative->Core.bmHstSimdRegsWithGstShadow &= ~RT_BIT_32(idxSimdRegFrom);
|
---|
3299 | pReNative->Core.aHstSimdRegs[idxSimdRegFrom].enmLoaded = kIemNativeGstSimdRegLdStSz_Invalid;
|
---|
3300 | }
|
---|
3301 | pReNative->Core.bmHstSimdRegsWithGstShadow |= RT_BIT_32(idxSimdRegTo);
|
---|
3302 | pReNative->Core.aHstSimdRegs[idxSimdRegTo].fGstRegShadows |= RT_BIT_64(enmGstSimdReg);
|
---|
3303 | pReNative->Core.aidxGstSimdRegShadows[enmGstSimdReg] = idxSimdRegTo;
|
---|
3304 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
3305 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
3306 | iemNativeDbgInfoAddGuestSimdRegShadowing(pReNative, enmGstSimdReg, idxSimdRegTo, idxSimdRegFrom);
|
---|
3307 | #else
|
---|
3308 | RT_NOREF(off);
|
---|
3309 | #endif
|
---|
3310 | }
|
---|
3311 |
|
---|
3312 |
|
---|
3313 | /**
|
---|
3314 | * Clear any guest register shadow claims from @a idxHstSimdReg.
|
---|
3315 | *
|
---|
3316 | * The register does not need to be shadowing any guest registers.
|
---|
3317 | */
|
---|
3318 | DECL_FORCE_INLINE(void)
|
---|
3319 | iemNativeSimdRegClearGstSimdRegShadowing(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstSimdReg, uint32_t off)
|
---|
3320 | {
|
---|
3321 | Assert( (pReNative->Core.bmGstSimdRegShadows & pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows)
|
---|
3322 | == pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows
|
---|
3323 | && pReNative->Core.bmGstSimdRegShadows < RT_BIT_64(kIemNativeGstSimdReg_End));
|
---|
3324 | Assert( RT_BOOL(pReNative->Core.bmHstSimdRegsWithGstShadow & RT_BIT_32(idxHstSimdReg))
|
---|
3325 | == RT_BOOL(pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows));
|
---|
3326 | Assert( !(pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows & pReNative->Core.bmGstSimdRegShadowDirtyLo128)
|
---|
3327 | && !(pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows & pReNative->Core.bmGstSimdRegShadowDirtyHi128));
|
---|
3328 |
|
---|
3329 | #ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
|
---|
3330 | uint64_t fGstRegs = pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows;
|
---|
3331 | if (fGstRegs)
|
---|
3332 | {
|
---|
3333 | Assert(fGstRegs < RT_BIT_64(kIemNativeGstSimdReg_End));
|
---|
3334 | iemNativeDbgInfoAddNativeOffset(pReNative, off);
|
---|
3335 | while (fGstRegs)
|
---|
3336 | {
|
---|
3337 | unsigned const iGstReg = ASMBitFirstSetU64(fGstRegs) - 1;
|
---|
3338 | fGstRegs &= ~RT_BIT_64(iGstReg);
|
---|
3339 | iemNativeDbgInfoAddGuestSimdRegShadowing(pReNative, (IEMNATIVEGSTSIMDREG)iGstReg, UINT8_MAX, idxHstSimdReg);
|
---|
3340 | }
|
---|
3341 | }
|
---|
3342 | #else
|
---|
3343 | RT_NOREF(off);
|
---|
3344 | #endif
|
---|
3345 |
|
---|
3346 | pReNative->Core.bmHstSimdRegsWithGstShadow &= ~RT_BIT_32(idxHstSimdReg);
|
---|
3347 | pReNative->Core.bmGstSimdRegShadows &= ~pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows;
|
---|
3348 | pReNative->Core.aHstSimdRegs[idxHstSimdReg].fGstRegShadows = 0;
|
---|
3349 | pReNative->Core.aHstSimdRegs[idxHstSimdReg].enmLoaded = kIemNativeGstSimdRegLdStSz_Invalid;
|
---|
3350 | }
|
---|
3351 |
|
---|
3352 |
|
---|
3353 |
|
---|
3354 | #ifdef IEMNATIVE_WITH_DELAYED_PC_UPDATING
|
---|
3355 | /**
|
---|
3356 | * Emits code to update the guest RIP value by adding the current offset since the start of the last RIP update.
|
---|
3357 | */
|
---|
3358 | DECL_INLINE_THROW(uint32_t) iemNativeEmitPcWriteback(PIEMRECOMPILERSTATE pReNative, uint32_t off)
|
---|
3359 | {
|
---|
3360 | if (pReNative->Core.offPc)
|
---|
3361 | return iemNativeEmitPcWritebackSlow(pReNative, off);
|
---|
3362 | return off;
|
---|
3363 | }
|
---|
3364 | #endif /* IEMNATIVE_WITH_DELAYED_PC_UPDATING */
|
---|
3365 |
|
---|
3366 |
|
---|
3367 | /** @note iemNativeTbEntry returns VBOXSTRICTRC, but we don't declare it as
|
---|
3368 | * it saves us the trouble of a hidden parameter on MSC/amd64. */
|
---|
3369 | #ifdef RT_ARCH_AMD64
|
---|
3370 | extern "C" IEM_DECL_NATIVE_HLP_DEF(int, iemNativeTbEntry, (PVMCPUCC pVCpu, uintptr_t pfnTbBody));
|
---|
3371 | #elif defined(RT_ARCH_ARM64)
|
---|
3372 | extern "C" IEM_DECL_NATIVE_HLP_DEF(int, iemNativeTbEntry, (PVMCPUCC pVCpu, PCPUMCTX pCpumCtx, uintptr_t pfnTbBody));
|
---|
3373 | #endif
|
---|
3374 |
|
---|
3375 | #ifdef IEMNATIVE_WITH_SIMD_FP_NATIVE_EMITTERS
|
---|
3376 | extern "C" IEM_DECL_NATIVE_HLP_DEF(int, iemNativeFpCtrlRegRestore, (uint64_t u64RegFpCtrl));
|
---|
3377 | #endif
|
---|
3378 |
|
---|
3379 | #endif /* !RT_IN_ASSEMBLER - ASM-NOINC-END */
|
---|
3380 |
|
---|
3381 | /** @} */
|
---|
3382 |
|
---|
3383 | #endif /* !VMM_INCLUDED_SRC_include_IEMN8veRecompiler_h */
|
---|
3384 |
|
---|