VirtualBox

source: vbox/trunk/src/VBox/VMM/include/IEMInternal.h@ 66686

Last change on this file since 66686 was 66686, checked in by vboxsync, 8 years ago

VMM/IEM: Handle raising of exceptions during delivery of a previous exception or interrupt.
The code takes into account additional info. required by HM for handling recursive exceptions as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 83.5 KB
Line 
1/* $Id: IEMInternal.h 66686 2017-04-27 12:38:17Z vboxsync $ */
2/** @file
3 * IEM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2011-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___IEMInternal_h
19#define ___IEMInternal_h
20
21#include <VBox/vmm/cpum.h>
22#include <VBox/vmm/iem.h>
23#include <VBox/vmm/stam.h>
24#include <VBox/param.h>
25
26#include <setjmp.h>
27
28
29RT_C_DECLS_BEGIN
30
31
32/** @defgroup grp_iem_int Internals
33 * @ingroup grp_iem
34 * @internal
35 * @{
36 */
37
38/** For expanding symbol in slickedit and other products tagging and
39 * crossreferencing IEM symbols. */
40#ifndef IEM_STATIC
41# define IEM_STATIC static
42#endif
43
44/** @def IEM_WITH_3DNOW
45 * Includes the 3DNow decoding. */
46#define IEM_WITH_3DNOW
47
48/** @def IEM_WITH_THREE_0F_38
49 * Includes the three byte opcode map for instrs starting with 0x0f 0x38. */
50#define IEM_WITH_THREE_0F_38
51
52/** @def IEM_WITH_THREE_0F_3A
53 * Includes the three byte opcode map for instrs starting with 0x0f 0x38. */
54#define IEM_WITH_THREE_0F_3A
55
56/** @def IEM_WITH_VEX
57 * Includes the VEX decoding. */
58#define IEM_WITH_VEX
59
60
61/** @def IEM_VERIFICATION_MODE_FULL
62 * Shorthand for:
63 * defined(IEM_VERIFICATION_MODE) && !defined(IEM_VERIFICATION_MODE_MINIMAL)
64 */
65#if (defined(IEM_VERIFICATION_MODE) && !defined(IEM_VERIFICATION_MODE_MINIMAL) && !defined(IEM_VERIFICATION_MODE_FULL)) \
66 || defined(DOXYGEN_RUNNING)
67# define IEM_VERIFICATION_MODE_FULL
68#endif
69
70
71/** @def IEM_CFG_TARGET_CPU
72 * The minimum target CPU for the IEM emulation (IEMTARGETCPU_XXX value).
73 *
74 * By default we allow this to be configured by the user via the
75 * CPUM/GuestCpuName config string, but this comes at a slight cost during
76 * decoding. So, for applications of this code where there is no need to
77 * be dynamic wrt target CPU, just modify this define.
78 */
79#if !defined(IEM_CFG_TARGET_CPU) || defined(DOXYGEN_RUNNING)
80# define IEM_CFG_TARGET_CPU IEMTARGETCPU_DYNAMIC
81#endif
82
83
84//#define IEM_WITH_CODE_TLB// - work in progress
85
86
87#if !defined(IN_TSTVMSTRUCT) && !defined(DOXYGEN_RUNNING)
88/** Instruction statistics. */
89typedef struct IEMINSTRSTATS
90{
91# define IEM_DO_INSTR_STAT(a_Name, a_szDesc) uint32_t a_Name;
92# include "IEMInstructionStatisticsTmpl.h"
93# undef IEM_DO_INSTR_STAT
94} IEMINSTRSTATS;
95#else
96struct IEMINSTRSTATS;
97typedef struct IEMINSTRSTATS IEMINSTRSTATS;
98#endif
99/** Pointer to IEM instruction statistics. */
100typedef IEMINSTRSTATS *PIEMINSTRSTATS;
101
102/** Finish and move to types.h */
103typedef union
104{
105 uint32_t u32;
106} RTFLOAT32U;
107typedef RTFLOAT32U *PRTFLOAT32U;
108typedef RTFLOAT32U const *PCRTFLOAT32U;
109
110
111/**
112 * Extended operand mode that includes a representation of 8-bit.
113 *
114 * This is used for packing down modes when invoking some C instruction
115 * implementations.
116 */
117typedef enum IEMMODEX
118{
119 IEMMODEX_16BIT = IEMMODE_16BIT,
120 IEMMODEX_32BIT = IEMMODE_32BIT,
121 IEMMODEX_64BIT = IEMMODE_64BIT,
122 IEMMODEX_8BIT
123} IEMMODEX;
124AssertCompileSize(IEMMODEX, 4);
125
126
127/**
128 * Branch types.
129 */
130typedef enum IEMBRANCH
131{
132 IEMBRANCH_JUMP = 1,
133 IEMBRANCH_CALL,
134 IEMBRANCH_TRAP,
135 IEMBRANCH_SOFTWARE_INT,
136 IEMBRANCH_HARDWARE_INT
137} IEMBRANCH;
138AssertCompileSize(IEMBRANCH, 4);
139
140
141/**
142 * INT instruction types.
143 */
144typedef enum IEMINT
145{
146 /** INT n instruction (opcode 0xcd imm). */
147 IEMINT_INTN = 0,
148 /** Single byte INT3 instruction (opcode 0xcc). */
149 IEMINT_INT3 = IEM_XCPT_FLAGS_BP_INSTR,
150 /** Single byte INTO instruction (opcode 0xce). */
151 IEMINT_INTO = IEM_XCPT_FLAGS_OF_INSTR,
152 /** Single byte INT1 (ICEBP) instruction (opcode 0xf1). */
153 IEMINT_INT1 = IEM_XCPT_FLAGS_ICEBP_INSTR
154} IEMINT;
155AssertCompileSize(IEMINT, 4);
156
157
158/**
159 * A FPU result.
160 */
161typedef struct IEMFPURESULT
162{
163 /** The output value. */
164 RTFLOAT80U r80Result;
165 /** The output status. */
166 uint16_t FSW;
167} IEMFPURESULT;
168AssertCompileMemberOffset(IEMFPURESULT, FSW, 10);
169/** Pointer to a FPU result. */
170typedef IEMFPURESULT *PIEMFPURESULT;
171/** Pointer to a const FPU result. */
172typedef IEMFPURESULT const *PCIEMFPURESULT;
173
174
175/**
176 * A FPU result consisting of two output values and FSW.
177 */
178typedef struct IEMFPURESULTTWO
179{
180 /** The first output value. */
181 RTFLOAT80U r80Result1;
182 /** The output status. */
183 uint16_t FSW;
184 /** The second output value. */
185 RTFLOAT80U r80Result2;
186} IEMFPURESULTTWO;
187AssertCompileMemberOffset(IEMFPURESULTTWO, FSW, 10);
188AssertCompileMemberOffset(IEMFPURESULTTWO, r80Result2, 12);
189/** Pointer to a FPU result consisting of two output values and FSW. */
190typedef IEMFPURESULTTWO *PIEMFPURESULTTWO;
191/** Pointer to a const FPU result consisting of two output values and FSW. */
192typedef IEMFPURESULTTWO const *PCIEMFPURESULTTWO;
193
194
195
196#ifdef IEM_VERIFICATION_MODE_FULL
197
198/**
199 * Verification event type.
200 */
201typedef enum IEMVERIFYEVENT
202{
203 IEMVERIFYEVENT_INVALID = 0,
204 IEMVERIFYEVENT_IOPORT_READ,
205 IEMVERIFYEVENT_IOPORT_WRITE,
206 IEMVERIFYEVENT_IOPORT_STR_READ,
207 IEMVERIFYEVENT_IOPORT_STR_WRITE,
208 IEMVERIFYEVENT_RAM_WRITE,
209 IEMVERIFYEVENT_RAM_READ
210} IEMVERIFYEVENT;
211
212/** Checks if the event type is a RAM read or write. */
213# define IEMVERIFYEVENT_IS_RAM(a_enmType) ((a_enmType) == IEMVERIFYEVENT_RAM_WRITE || (a_enmType) == IEMVERIFYEVENT_RAM_READ)
214
215/**
216 * Verification event record.
217 */
218typedef struct IEMVERIFYEVTREC
219{
220 /** Pointer to the next record in the list. */
221 struct IEMVERIFYEVTREC *pNext;
222 /** The event type. */
223 IEMVERIFYEVENT enmEvent;
224 /** The event data. */
225 union
226 {
227 /** IEMVERIFYEVENT_IOPORT_READ */
228 struct
229 {
230 RTIOPORT Port;
231 uint8_t cbValue;
232 } IOPortRead;
233
234 /** IEMVERIFYEVENT_IOPORT_WRITE */
235 struct
236 {
237 RTIOPORT Port;
238 uint8_t cbValue;
239 uint32_t u32Value;
240 } IOPortWrite;
241
242 /** IEMVERIFYEVENT_IOPORT_STR_READ */
243 struct
244 {
245 RTIOPORT Port;
246 uint8_t cbValue;
247 RTGCUINTREG cTransfers;
248 } IOPortStrRead;
249
250 /** IEMVERIFYEVENT_IOPORT_STR_WRITE */
251 struct
252 {
253 RTIOPORT Port;
254 uint8_t cbValue;
255 RTGCUINTREG cTransfers;
256 } IOPortStrWrite;
257
258 /** IEMVERIFYEVENT_RAM_READ */
259 struct
260 {
261 RTGCPHYS GCPhys;
262 uint32_t cb;
263 } RamRead;
264
265 /** IEMVERIFYEVENT_RAM_WRITE */
266 struct
267 {
268 RTGCPHYS GCPhys;
269 uint32_t cb;
270 uint8_t ab[512];
271 } RamWrite;
272 } u;
273} IEMVERIFYEVTREC;
274/** Pointer to an IEM event verification records. */
275typedef IEMVERIFYEVTREC *PIEMVERIFYEVTREC;
276
277#endif /* IEM_VERIFICATION_MODE_FULL */
278
279
280/**
281 * IEM TLB entry.
282 *
283 * Lookup assembly:
284 * @code{.asm}
285 ; Calculate tag.
286 mov rax, [VA]
287 shl rax, 16
288 shr rax, 16 + X86_PAGE_SHIFT
289 or rax, [uTlbRevision]
290
291 ; Do indexing.
292 movzx ecx, al
293 lea rcx, [pTlbEntries + rcx]
294
295 ; Check tag.
296 cmp [rcx + IEMTLBENTRY.uTag], rax
297 jne .TlbMiss
298
299 ; Check access.
300 movsx rax, ACCESS_FLAGS | MAPPING_R3_NOT_VALID | 0xffffff00
301 and rax, [rcx + IEMTLBENTRY.fFlagsAndPhysRev]
302 cmp rax, [uTlbPhysRev]
303 jne .TlbMiss
304
305 ; Calc address and we're done.
306 mov eax, X86_PAGE_OFFSET_MASK
307 and eax, [VA]
308 or rax, [rcx + IEMTLBENTRY.pMappingR3]
309 %ifdef VBOX_WITH_STATISTICS
310 inc qword [cTlbHits]
311 %endif
312 jmp .Done
313
314 .TlbMiss:
315 mov r8d, ACCESS_FLAGS
316 mov rdx, [VA]
317 mov rcx, [pVCpu]
318 call iemTlbTypeMiss
319 .Done:
320
321 @endcode
322 *
323 */
324typedef struct IEMTLBENTRY
325{
326 /** The TLB entry tag.
327 * Bits 35 thru 0 are made up of the virtual address shifted right 12 bits.
328 * Bits 63 thru 36 are made up of the TLB revision (zero means invalid).
329 *
330 * The TLB lookup code uses the current TLB revision, which won't ever be zero,
331 * enabling an extremely cheap TLB invalidation most of the time. When the TLB
332 * revision wraps around though, the tags needs to be zeroed.
333 *
334 * @note Try use SHRD instruction? After seeing
335 * https://gmplib.org/~tege/x86-timing.pdf, maybe not.
336 */
337 uint64_t uTag;
338 /** Access flags and physical TLB revision.
339 *
340 * - Bit 0 - page tables - not executable (X86_PTE_PAE_NX).
341 * - Bit 1 - page tables - not writable (complemented X86_PTE_RW).
342 * - Bit 2 - page tables - not user (complemented X86_PTE_US).
343 * - Bit 3 - pgm phys/virt - not directly writable.
344 * - Bit 4 - pgm phys page - not directly readable.
345 * - Bit 5 - currently unused.
346 * - Bit 6 - page tables - not dirty (complemented X86_PTE_D).
347 * - Bit 7 - tlb entry - pMappingR3 member not valid.
348 * - Bits 63 thru 8 are used for the physical TLB revision number.
349 *
350 * We're using complemented bit meanings here because it makes it easy to check
351 * whether special action is required. For instance a user mode write access
352 * would do a "TEST fFlags, (X86_PTE_RW | X86_PTE_US | X86_PTE_D)" and a
353 * non-zero result would mean special handling needed because either it wasn't
354 * writable, or it wasn't user, or the page wasn't dirty. A user mode read
355 * access would do "TEST fFlags, X86_PTE_US"; and a kernel mode read wouldn't
356 * need to check any PTE flag.
357 */
358 uint64_t fFlagsAndPhysRev;
359 /** The guest physical page address. */
360 uint64_t GCPhys;
361 /** Pointer to the ring-3 mapping (possibly also valid in ring-0). */
362#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
363 R3PTRTYPE(uint8_t *) pbMappingR3;
364#else
365 R3R0PTRTYPE(uint8_t *) pbMappingR3;
366#endif
367#if HC_ARCH_BITS == 32
368 uint32_t u32Padding1;
369#endif
370} IEMTLBENTRY;
371AssertCompileSize(IEMTLBENTRY, 32);
372/** Pointer to an IEM TLB entry. */
373typedef IEMTLBENTRY *PIEMTLBENTRY;
374
375/** @name IEMTLBE_F_XXX - TLB entry flags (IEMTLBENTRY::fFlagsAndPhysRev)
376 * @{ */
377#define IEMTLBE_F_PT_NO_EXEC RT_BIT_64(0) /**< Page tables: Not executable. */
378#define IEMTLBE_F_PT_NO_WRITE RT_BIT_64(1) /**< Page tables: Not writable. */
379#define IEMTLBE_F_PT_NO_USER RT_BIT_64(2) /**< Page tables: Not user accessible (supervisor only). */
380#define IEMTLBE_F_PG_NO_WRITE RT_BIT_64(3) /**< Phys page: Not writable (access handler, ROM, whatever). */
381#define IEMTLBE_F_PG_NO_READ RT_BIT_64(4) /**< Phys page: Not readable (MMIO / access handler, ROM) */
382#define IEMTLBE_F_PATCH_CODE RT_BIT_64(5) /**< Code TLB: Patch code (PATM). */
383#define IEMTLBE_F_PT_NO_DIRTY RT_BIT_64(6) /**< Page tables: Not dirty (needs to be made dirty on write). */
384#define IEMTLBE_F_NO_MAPPINGR3 RT_BIT_64(7) /**< TLB entry: The IEMTLBENTRY::pMappingR3 member is invalid. */
385#define IEMTLBE_F_PHYS_REV UINT64_C(0xffffffffffffff00) /**< Physical revision mask. */
386/** @} */
387
388
389/**
390 * An IEM TLB.
391 *
392 * We've got two of these, one for data and one for instructions.
393 */
394typedef struct IEMTLB
395{
396 /** The TLB entries.
397 * We've choosen 256 because that way we can obtain the result directly from a
398 * 8-bit register without an additional AND instruction. */
399 IEMTLBENTRY aEntries[256];
400 /** The TLB revision.
401 * This is actually only 28 bits wide (see IEMTLBENTRY::uTag) and is incremented
402 * by adding RT_BIT_64(36) to it. When it wraps around and becomes zero, all
403 * the tags in the TLB must be zeroed and the revision set to RT_BIT_64(36).
404 * (The revision zero indicates an invalid TLB entry.)
405 *
406 * The initial value is choosen to cause an early wraparound. */
407 uint64_t uTlbRevision;
408 /** The TLB physical address revision - shadow of PGM variable.
409 *
410 * This is actually only 56 bits wide (see IEMTLBENTRY::fFlagsAndPhysRev) and is
411 * incremented by adding RT_BIT_64(8). When it wraps around and becomes zero,
412 * a rendezvous is called and each CPU wipe the IEMTLBENTRY::pMappingR3 as well
413 * as IEMTLBENTRY::fFlagsAndPhysRev bits 63 thru 8, 4, and 3.
414 *
415 * The initial value is choosen to cause an early wraparound. */
416 uint64_t volatile uTlbPhysRev;
417
418 /* Statistics: */
419
420 /** TLB hits (VBOX_WITH_STATISTICS only). */
421 uint64_t cTlbHits;
422 /** TLB misses. */
423 uint32_t cTlbMisses;
424 /** Slow read path. */
425 uint32_t cTlbSlowReadPath;
426#if 0
427 /** TLB misses because of tag mismatch. */
428 uint32_t cTlbMissesTag;
429 /** TLB misses because of virtual access violation. */
430 uint32_t cTlbMissesVirtAccess;
431 /** TLB misses because of dirty bit. */
432 uint32_t cTlbMissesDirty;
433 /** TLB misses because of MMIO */
434 uint32_t cTlbMissesMmio;
435 /** TLB misses because of write access handlers. */
436 uint32_t cTlbMissesWriteHandler;
437 /** TLB misses because no r3(/r0) mapping. */
438 uint32_t cTlbMissesMapping;
439#endif
440 /** Alignment padding. */
441 uint32_t au32Padding[3+5];
442} IEMTLB;
443AssertCompileSizeAlignment(IEMTLB, 64);
444/** IEMTLB::uTlbRevision increment. */
445#define IEMTLB_REVISION_INCR RT_BIT_64(36)
446/** IEMTLB::uTlbPhysRev increment. */
447#define IEMTLB_PHYS_REV_INCR RT_BIT_64(8)
448
449
450/**
451 * The per-CPU IEM state.
452 */
453typedef struct IEMCPU
454{
455 /** Info status code that needs to be propagated to the IEM caller.
456 * This cannot be passed internally, as it would complicate all success
457 * checks within the interpreter making the code larger and almost impossible
458 * to get right. Instead, we'll store status codes to pass on here. Each
459 * source of these codes will perform appropriate sanity checks. */
460 int32_t rcPassUp; /* 0x00 */
461
462 /** The current CPU execution mode (CS). */
463 IEMMODE enmCpuMode; /* 0x04 */
464 /** The CPL. */
465 uint8_t uCpl; /* 0x05 */
466
467 /** Whether to bypass access handlers or not. */
468 bool fBypassHandlers; /* 0x06 */
469 /** Indicates that we're interpreting patch code - RC only! */
470 bool fInPatchCode; /* 0x07 */
471
472 /** @name Decoder state.
473 * @{ */
474#ifdef IEM_WITH_CODE_TLB
475 /** The offset of the next instruction byte. */
476 uint32_t offInstrNextByte; /* 0x08 */
477 /** The number of bytes available at pbInstrBuf for the current instruction.
478 * This takes the max opcode length into account so that doesn't need to be
479 * checked separately. */
480 uint32_t cbInstrBuf; /* 0x0c */
481 /** Pointer to the page containing RIP, user specified buffer or abOpcode.
482 * This can be NULL if the page isn't mappable for some reason, in which
483 * case we'll do fallback stuff.
484 *
485 * If we're executing an instruction from a user specified buffer,
486 * IEMExecOneWithPrefetchedByPC and friends, this is not necessarily a page
487 * aligned pointer but pointer to the user data.
488 *
489 * For instructions crossing pages, this will start on the first page and be
490 * advanced to the next page by the time we've decoded the instruction. This
491 * therefore precludes stuff like <tt>pbInstrBuf[offInstrNextByte + cbInstrBuf - cbCurInstr]</tt>
492 */
493 uint8_t const *pbInstrBuf; /* 0x10 */
494# if ARCH_BITS == 32
495 uint32_t uInstrBufHigh; /** The high dword of the host context pbInstrBuf member. */
496# endif
497 /** The program counter corresponding to pbInstrBuf.
498 * This is set to a non-canonical address when we need to invalidate it. */
499 uint64_t uInstrBufPc; /* 0x18 */
500 /** The number of bytes available at pbInstrBuf in total (for IEMExecLots).
501 * This takes the CS segment limit into account. */
502 uint16_t cbInstrBufTotal; /* 0x20 */
503 /** Offset into pbInstrBuf of the first byte of the current instruction.
504 * Can be negative to efficiently handle cross page instructions. */
505 int16_t offCurInstrStart; /* 0x22 */
506
507 /** The prefix mask (IEM_OP_PRF_XXX). */
508 uint32_t fPrefixes; /* 0x24 */
509 /** The extra REX ModR/M register field bit (REX.R << 3). */
510 uint8_t uRexReg; /* 0x28 */
511 /** The extra REX ModR/M r/m field, SIB base and opcode reg bit
512 * (REX.B << 3). */
513 uint8_t uRexB; /* 0x29 */
514 /** The extra REX SIB index field bit (REX.X << 3). */
515 uint8_t uRexIndex; /* 0x2a */
516
517 /** The effective segment register (X86_SREG_XXX). */
518 uint8_t iEffSeg; /* 0x2b */
519
520#else
521 /** The size of what has currently been fetched into abOpcode. */
522 uint8_t cbOpcode; /* 0x08 */
523 /** The current offset into abOpcode. */
524 uint8_t offOpcode; /* 0x09 */
525
526 /** The effective segment register (X86_SREG_XXX). */
527 uint8_t iEffSeg; /* 0x0a */
528
529 /** The extra REX ModR/M register field bit (REX.R << 3). */
530 uint8_t uRexReg; /* 0x0b */
531 /** The prefix mask (IEM_OP_PRF_XXX). */
532 uint32_t fPrefixes; /* 0x0c */
533 /** The extra REX ModR/M r/m field, SIB base and opcode reg bit
534 * (REX.B << 3). */
535 uint8_t uRexB; /* 0x10 */
536 /** The extra REX SIB index field bit (REX.X << 3). */
537 uint8_t uRexIndex; /* 0x11 */
538
539#endif
540
541 /** The effective operand mode. */
542 IEMMODE enmEffOpSize; /* 0x2c, 0x12 */
543 /** The default addressing mode. */
544 IEMMODE enmDefAddrMode; /* 0x2d, 0x13 */
545 /** The effective addressing mode. */
546 IEMMODE enmEffAddrMode; /* 0x2e, 0x14 */
547 /** The default operand mode. */
548 IEMMODE enmDefOpSize; /* 0x2f, 0x15 */
549
550 /** Prefix index (VEX.pp) for two byte and three byte tables. */
551 uint8_t idxPrefix; /* 0x30, 0x16 */
552 /** 3rd VEX/EVEX/XOP register. */
553 uint8_t uVex3rdReg; /* 0x31, 0x17 */
554 /** The VEX/EVEX/XOP length field. */
555 uint8_t uVexLength; /* 0x32, 0x18 */
556 /** Additional EVEX stuff. */
557 uint8_t fEvexStuff; /* 0x33, 0x19 */
558
559 /** The FPU opcode (FOP). */
560 uint16_t uFpuOpcode; /* 0x34, 0x1a */
561
562 /** Explicit alignment padding. */
563#ifdef IEM_WITH_CODE_TLB
564 uint8_t abAlignment2a[2]; /* 0x36 */
565#endif
566
567 /** The opcode bytes. */
568 uint8_t abOpcode[15]; /* 0x48, 0x1c */
569 /** Explicit alignment padding. */
570#ifdef IEM_WITH_CODE_TLB
571 uint8_t abAlignment2c[0x48 - 0x47]; /* 0x37 */
572#else
573 uint8_t abAlignment2c[0x48 - 0x2b]; /* 0x2b */
574#endif
575 /** @} */
576
577
578 /** The flags of the current exception / interrupt. */
579 uint32_t fCurXcpt; /* 0x48, 0x48 */
580 /** The current exception / interrupt. */
581 uint8_t uCurXcpt;
582 /** Exception / interrupt recursion depth. */
583 int8_t cXcptRecursions;
584
585 /** The number of active guest memory mappings. */
586 uint8_t cActiveMappings;
587 /** The next unused mapping index. */
588 uint8_t iNextMapping;
589 /** Records for tracking guest memory mappings. */
590 struct
591 {
592 /** The address of the mapped bytes. */
593 void *pv;
594#if defined(IN_RC) && HC_ARCH_BITS == 64
595 uint32_t u32Alignment3; /**< Alignment padding. */
596#endif
597 /** The access flags (IEM_ACCESS_XXX).
598 * IEM_ACCESS_INVALID if the entry is unused. */
599 uint32_t fAccess;
600#if HC_ARCH_BITS == 64
601 uint32_t u32Alignment4; /**< Alignment padding. */
602#endif
603 } aMemMappings[3];
604
605 /** Locking records for the mapped memory. */
606 union
607 {
608 PGMPAGEMAPLOCK Lock;
609 uint64_t au64Padding[2];
610 } aMemMappingLocks[3];
611
612 /** Bounce buffer info.
613 * This runs in parallel to aMemMappings. */
614 struct
615 {
616 /** The physical address of the first byte. */
617 RTGCPHYS GCPhysFirst;
618 /** The physical address of the second page. */
619 RTGCPHYS GCPhysSecond;
620 /** The number of bytes in the first page. */
621 uint16_t cbFirst;
622 /** The number of bytes in the second page. */
623 uint16_t cbSecond;
624 /** Whether it's unassigned memory. */
625 bool fUnassigned;
626 /** Explicit alignment padding. */
627 bool afAlignment5[3];
628 } aMemBbMappings[3];
629
630 /** Bounce buffer storage.
631 * This runs in parallel to aMemMappings and aMemBbMappings. */
632 struct
633 {
634 uint8_t ab[512];
635 } aBounceBuffers[3];
636
637
638 /** Pointer set jump buffer - ring-3 context. */
639 R3PTRTYPE(jmp_buf *) pJmpBufR3;
640 /** Pointer set jump buffer - ring-0 context. */
641 R0PTRTYPE(jmp_buf *) pJmpBufR0;
642 /** Pointer set jump buffer - raw-mode context. */
643 RCPTRTYPE(jmp_buf *) pJmpBufRC;
644
645 /** @todo Should move this near @a fCurXcpt later. */
646 /** The error code for the current exception / interrupt. */
647 uint32_t uCurXcptErr;
648 /** The CR2 for the current exception / interrupt. */
649 uint64_t uCurXcptCr2;
650
651 /** @name Statistics
652 * @{ */
653 /** The number of instructions we've executed. */
654 uint32_t cInstructions;
655 /** The number of potential exits. */
656 uint32_t cPotentialExits;
657 /** The number of bytes data or stack written (mostly for IEMExecOneEx).
658 * This may contain uncommitted writes. */
659 uint32_t cbWritten;
660 /** Counts the VERR_IEM_INSTR_NOT_IMPLEMENTED returns. */
661 uint32_t cRetInstrNotImplemented;
662 /** Counts the VERR_IEM_ASPECT_NOT_IMPLEMENTED returns. */
663 uint32_t cRetAspectNotImplemented;
664 /** Counts informational statuses returned (other than VINF_SUCCESS). */
665 uint32_t cRetInfStatuses;
666 /** Counts other error statuses returned. */
667 uint32_t cRetErrStatuses;
668 /** Number of times rcPassUp has been used. */
669 uint32_t cRetPassUpStatus;
670 /** Number of times RZ left with instruction commit pending for ring-3. */
671 uint32_t cPendingCommit;
672 /** Number of long jumps. */
673 uint32_t cLongJumps;
674 uint32_t uAlignment6; /**< Alignment padding. */
675#ifdef IEM_VERIFICATION_MODE_FULL
676 /** The Number of I/O port reads that has been performed. */
677 uint32_t cIOReads;
678 /** The Number of I/O port writes that has been performed. */
679 uint32_t cIOWrites;
680 /** Set if no comparison to REM is currently performed.
681 * This is used to skip past really slow bits. */
682 bool fNoRem;
683 /** Saved fNoRem flag used by #iemInitExec and #iemUninitExec. */
684 bool fNoRemSavedByExec;
685 /** Indicates that RAX and RDX differences should be ignored since RDTSC
686 * and RDTSCP are timing sensitive. */
687 bool fIgnoreRaxRdx;
688 /** Indicates that a MOVS instruction with overlapping source and destination
689 * was executed, causing the memory write records to be incorrrect. */
690 bool fOverlappingMovs;
691 /** Set if there are problematic memory accesses (MMIO, write monitored, ++). */
692 bool fProblematicMemory;
693 /** This is used to communicate a CPL changed caused by IEMInjectTrap that
694 * CPUM doesn't yet reflect. */
695 uint8_t uInjectCpl;
696 /** To prevent EMR3HmSingleInstruction from triggering endless recursion via
697 * emR3ExecuteInstruction and iemExecVerificationModeCheck. */
698 uint8_t cVerifyDepth;
699 bool afAlignment7[2];
700 /** Mask of undefined eflags.
701 * The verifier will any difference in these flags. */
702 uint32_t fUndefinedEFlags;
703 /** The CS of the instruction being interpreted. */
704 RTSEL uOldCs;
705 /** The RIP of the instruction being interpreted. */
706 uint64_t uOldRip;
707 /** The physical address corresponding to abOpcodes[0]. */
708 RTGCPHYS GCPhysOpcodes;
709#endif
710 /** @} */
711
712 /** @name Target CPU information.
713 * @{ */
714#if IEM_CFG_TARGET_CPU == IEMTARGETCPU_DYNAMIC
715 /** The target CPU. */
716 uint32_t uTargetCpu;
717#else
718 uint32_t u32TargetCpuPadding;
719#endif
720 /** The CPU vendor. */
721 CPUMCPUVENDOR enmCpuVendor;
722 /** @} */
723
724 /** @name Host CPU information.
725 * @{ */
726 /** The CPU vendor. */
727 CPUMCPUVENDOR enmHostCpuVendor;
728 /** @} */
729
730 uint32_t au32Alignment8[HC_ARCH_BITS == 64 ? 4 + 8 : 4]; /**< Alignment padding. */
731
732 /** Data TLB.
733 * @remarks Must be 64-byte aligned. */
734 IEMTLB DataTlb;
735 /** Instruction TLB.
736 * @remarks Must be 64-byte aligned. */
737 IEMTLB CodeTlb;
738
739 /** Pointer to the CPU context - ring-3 context.
740 * @todo put inside IEM_VERIFICATION_MODE_FULL++. */
741 R3PTRTYPE(PCPUMCTX) pCtxR3;
742 /** Pointer to the CPU context - ring-0 context. */
743 R0PTRTYPE(PCPUMCTX) pCtxR0;
744 /** Pointer to the CPU context - raw-mode context. */
745 RCPTRTYPE(PCPUMCTX) pCtxRC;
746
747 /** Pointer to instruction statistics for raw-mode context (same as R0). */
748 RCPTRTYPE(PIEMINSTRSTATS) pStatsRC;
749 /** Pointer to instruction statistics for ring-0 context (same as RC). */
750 R0PTRTYPE(PIEMINSTRSTATS) pStatsR0;
751 /** Pointer to instruction statistics for non-ring-3 code. */
752 R3PTRTYPE(PIEMINSTRSTATS) pStatsCCR3;
753 /** Pointer to instruction statistics for ring-3 context. */
754 R3PTRTYPE(PIEMINSTRSTATS) pStatsR3;
755
756#ifdef IEM_VERIFICATION_MODE_FULL
757 /** The event verification records for what IEM did (LIFO). */
758 R3PTRTYPE(PIEMVERIFYEVTREC) pIemEvtRecHead;
759 /** Insertion point for pIemEvtRecHead. */
760 R3PTRTYPE(PIEMVERIFYEVTREC *) ppIemEvtRecNext;
761 /** The event verification records for what the other party did (FIFO). */
762 R3PTRTYPE(PIEMVERIFYEVTREC) pOtherEvtRecHead;
763 /** Insertion point for pOtherEvtRecHead. */
764 R3PTRTYPE(PIEMVERIFYEVTREC *) ppOtherEvtRecNext;
765 /** List of free event records. */
766 R3PTRTYPE(PIEMVERIFYEVTREC) pFreeEvtRec;
767#endif
768} IEMCPU;
769AssertCompileMemberOffset(IEMCPU, fCurXcpt, 0x48);
770AssertCompileMemberAlignment(IEMCPU, DataTlb, 64);
771AssertCompileMemberAlignment(IEMCPU, CodeTlb, 64);
772/** Pointer to the per-CPU IEM state. */
773typedef IEMCPU *PIEMCPU;
774/** Pointer to the const per-CPU IEM state. */
775typedef IEMCPU const *PCIEMCPU;
776
777
778/** @def IEM_GET_CTX
779 * Gets the guest CPU context for the calling EMT.
780 * @returns PCPUMCTX
781 * @param a_pVCpu The cross context virtual CPU structure of the calling thread.
782 */
783#if !defined(IEM_VERIFICATION_MODE_FULL) && !defined(IEM_VERIFICATION_MODE) \
784 && !defined(IEM_VERIFICATION_MODE_MINIMAL) && defined(VMCPU_INCL_CPUM_GST_CTX)
785# define IEM_GET_CTX(a_pVCpu) (&(a_pVCpu)->cpum.GstCtx)
786#else
787# define IEM_GET_CTX(a_pVCpu) ((a_pVCpu)->iem.s.CTX_SUFF(pCtx))
788#endif
789
790/** Gets the current IEMTARGETCPU value.
791 * @returns IEMTARGETCPU value.
792 * @param a_pVCpu The cross context virtual CPU structure of the calling thread.
793 */
794#if IEM_CFG_TARGET_CPU != IEMTARGETCPU_DYNAMIC
795# define IEM_GET_TARGET_CPU(a_pVCpu) (IEM_CFG_TARGET_CPU)
796#else
797# define IEM_GET_TARGET_CPU(a_pVCpu) ((a_pVCpu)->iem.s.uTargetCpu)
798#endif
799
800/** @def Gets the instruction length. */
801#ifdef IEM_WITH_CODE_TLB
802# define IEM_GET_INSTR_LEN(a_pVCpu) ((a_pVCpu)->iem.s.offInstrNextByte - (uint32_t)(int32_t)(a_pVCpu)->iem.s.offCurInstrStart)
803#else
804# define IEM_GET_INSTR_LEN(a_pVCpu) ((a_pVCpu)->iem.s.offOpcode)
805#endif
806
807
808/** @name IEM_ACCESS_XXX - Access details.
809 * @{ */
810#define IEM_ACCESS_INVALID UINT32_C(0x000000ff)
811#define IEM_ACCESS_TYPE_READ UINT32_C(0x00000001)
812#define IEM_ACCESS_TYPE_WRITE UINT32_C(0x00000002)
813#define IEM_ACCESS_TYPE_EXEC UINT32_C(0x00000004)
814#define IEM_ACCESS_TYPE_MASK UINT32_C(0x00000007)
815#define IEM_ACCESS_WHAT_CODE UINT32_C(0x00000010)
816#define IEM_ACCESS_WHAT_DATA UINT32_C(0x00000020)
817#define IEM_ACCESS_WHAT_STACK UINT32_C(0x00000030)
818#define IEM_ACCESS_WHAT_SYS UINT32_C(0x00000040)
819#define IEM_ACCESS_WHAT_MASK UINT32_C(0x00000070)
820/** The writes are partial, so if initialize the bounce buffer with the
821 * orignal RAM content. */
822#define IEM_ACCESS_PARTIAL_WRITE UINT32_C(0x00000100)
823/** Used in aMemMappings to indicate that the entry is bounce buffered. */
824#define IEM_ACCESS_BOUNCE_BUFFERED UINT32_C(0x00000200)
825/** Bounce buffer with ring-3 write pending, first page. */
826#define IEM_ACCESS_PENDING_R3_WRITE_1ST UINT32_C(0x00000400)
827/** Bounce buffer with ring-3 write pending, second page. */
828#define IEM_ACCESS_PENDING_R3_WRITE_2ND UINT32_C(0x00000800)
829/** Valid bit mask. */
830#define IEM_ACCESS_VALID_MASK UINT32_C(0x00000fff)
831/** Read+write data alias. */
832#define IEM_ACCESS_DATA_RW (IEM_ACCESS_TYPE_READ | IEM_ACCESS_TYPE_WRITE | IEM_ACCESS_WHAT_DATA)
833/** Write data alias. */
834#define IEM_ACCESS_DATA_W (IEM_ACCESS_TYPE_WRITE | IEM_ACCESS_WHAT_DATA)
835/** Read data alias. */
836#define IEM_ACCESS_DATA_R (IEM_ACCESS_TYPE_READ | IEM_ACCESS_WHAT_DATA)
837/** Instruction fetch alias. */
838#define IEM_ACCESS_INSTRUCTION (IEM_ACCESS_TYPE_EXEC | IEM_ACCESS_WHAT_CODE)
839/** Stack write alias. */
840#define IEM_ACCESS_STACK_W (IEM_ACCESS_TYPE_WRITE | IEM_ACCESS_WHAT_STACK)
841/** Stack read alias. */
842#define IEM_ACCESS_STACK_R (IEM_ACCESS_TYPE_READ | IEM_ACCESS_WHAT_STACK)
843/** Stack read+write alias. */
844#define IEM_ACCESS_STACK_RW (IEM_ACCESS_TYPE_READ | IEM_ACCESS_TYPE_WRITE | IEM_ACCESS_WHAT_STACK)
845/** Read system table alias. */
846#define IEM_ACCESS_SYS_R (IEM_ACCESS_TYPE_READ | IEM_ACCESS_WHAT_SYS)
847/** Read+write system table alias. */
848#define IEM_ACCESS_SYS_RW (IEM_ACCESS_TYPE_READ | IEM_ACCESS_TYPE_WRITE | IEM_ACCESS_WHAT_SYS)
849/** @} */
850
851/** @name Prefix constants (IEMCPU::fPrefixes)
852 * @{ */
853#define IEM_OP_PRF_SEG_CS RT_BIT_32(0) /**< CS segment prefix (0x2e). */
854#define IEM_OP_PRF_SEG_SS RT_BIT_32(1) /**< SS segment prefix (0x36). */
855#define IEM_OP_PRF_SEG_DS RT_BIT_32(2) /**< DS segment prefix (0x3e). */
856#define IEM_OP_PRF_SEG_ES RT_BIT_32(3) /**< ES segment prefix (0x26). */
857#define IEM_OP_PRF_SEG_FS RT_BIT_32(4) /**< FS segment prefix (0x64). */
858#define IEM_OP_PRF_SEG_GS RT_BIT_32(5) /**< GS segment prefix (0x65). */
859#define IEM_OP_PRF_SEG_MASK UINT32_C(0x3f)
860
861#define IEM_OP_PRF_SIZE_OP RT_BIT_32(8) /**< Operand size prefix (0x66). */
862#define IEM_OP_PRF_SIZE_REX_W RT_BIT_32(9) /**< REX.W prefix (0x48-0x4f). */
863#define IEM_OP_PRF_SIZE_ADDR RT_BIT_32(10) /**< Address size prefix (0x67). */
864
865#define IEM_OP_PRF_LOCK RT_BIT_32(16) /**< Lock prefix (0xf0). */
866#define IEM_OP_PRF_REPNZ RT_BIT_32(17) /**< Repeat-not-zero prefix (0xf2). */
867#define IEM_OP_PRF_REPZ RT_BIT_32(18) /**< Repeat-if-zero prefix (0xf3). */
868
869#define IEM_OP_PRF_REX RT_BIT_32(24) /**< Any REX prefix (0x40-0x4f). */
870#define IEM_OP_PRF_REX_R RT_BIT_32(25) /**< REX.R prefix (0x44,0x45,0x46,0x47,0x4c,0x4d,0x4e,0x4f). */
871#define IEM_OP_PRF_REX_B RT_BIT_32(26) /**< REX.B prefix (0x41,0x43,0x45,0x47,0x49,0x4b,0x4d,0x4f). */
872#define IEM_OP_PRF_REX_X RT_BIT_32(27) /**< REX.X prefix (0x42,0x43,0x46,0x47,0x4a,0x4b,0x4e,0x4f). */
873/** Mask with all the REX prefix flags.
874 * This is generally for use when needing to undo the REX prefixes when they
875 * are followed legacy prefixes and therefore does not immediately preceed
876 * the first opcode byte.
877 * For testing whether any REX prefix is present, use IEM_OP_PRF_REX instead. */
878#define IEM_OP_PRF_REX_MASK (IEM_OP_PRF_REX | IEM_OP_PRF_REX_R | IEM_OP_PRF_REX_B | IEM_OP_PRF_REX_X | IEM_OP_PRF_SIZE_REX_W )
879
880#define IEM_OP_PRF_VEX RT_BIT_32(28) /**< Indiciates VEX prefix. */
881#define IEM_OP_PRF_EVEX RT_BIT_32(29) /**< Indiciates EVEX prefix. */
882#define IEM_OP_PRF_XOP RT_BIT_32(30) /**< Indiciates XOP prefix. */
883/** @} */
884
885/** @name IEMOPFORM_XXX - Opcode forms
886 * @note These are ORed together with IEMOPHINT_XXX.
887 * @{ */
888/** ModR/M: reg, r/m */
889#define IEMOPFORM_RM 0
890/** ModR/M: reg, r/m (register) */
891#define IEMOPFORM_RM_REG (IEMOPFORM_RM | IEMOPFORM_MOD3)
892/** ModR/M: reg, r/m (memory) */
893#define IEMOPFORM_RM_MEM (IEMOPFORM_RM | IEMOPFORM_NOT_MOD3)
894/** ModR/M: r/m, reg */
895#define IEMOPFORM_MR 1
896/** ModR/M: r/m (register), reg */
897#define IEMOPFORM_MR_REG (IEMOPFORM_MR | IEMOPFORM_MOD3)
898/** ModR/M: r/m (memory), reg */
899#define IEMOPFORM_MR_MEM (IEMOPFORM_MR | IEMOPFORM_NOT_MOD3)
900/** ModR/M: r/m only */
901#define IEMOPFORM_M 2
902/** ModR/M: r/m only (register). */
903#define IEMOPFORM_M_REG (IEMOPFORM_M | IEMOPFORM_MOD3)
904/** ModR/M: r/m only (memory). */
905#define IEMOPFORM_M_MEM (IEMOPFORM_M | IEMOPFORM_NOT_MOD3)
906/** ModR/M: reg only */
907#define IEMOPFORM_R 3
908
909/** VEX+ModR/M: reg, r/m */
910#define IEMOPFORM_VEX_RM 4
911/** VEX+ModR/M: reg, r/m (register) */
912#define IEMOPFORM_VEX_RM_REG (IEMOPFORM_VEX_RM | IEMOPFORM_MOD3)
913/** VEX+ModR/M: reg, r/m (memory) */
914#define IEMOPFORM_VEX_RM_MEM (IEMOPFORM_VEX_RM | IEMOPFORM_NOT_MOD3)
915/** VEX+ModR/M: r/m, reg */
916#define IEMOPFORM_VEX_MR 5
917/** VEX+ModR/M: r/m (register), reg */
918#define IEMOPFORM_VEX_MR_REG (IEMOPFORM_VEX_MR | IEMOPFORM_MOD3)
919/** VEX+ModR/M: r/m (memory), reg */
920#define IEMOPFORM_VEX_MR_MEM (IEMOPFORM_VEX_MR | IEMOPFORM_NOT_MOD3)
921/** VEX+ModR/M: r/m only */
922#define IEMOPFORM_VEX_M 6
923/** VEX+ModR/M: r/m only (register). */
924#define IEMOPFORM_VEX_M_REG (IEMOPFORM_VEX_M | IEMOPFORM_MOD3)
925/** VEX+ModR/M: r/m only (memory). */
926#define IEMOPFORM_VEX_M_MEM (IEMOPFORM_VEX_M | IEMOPFORM_NOT_MOD3)
927/** VEX+ModR/M: reg only */
928#define IEMOPFORM_VEX_R 7
929/** VEX+ModR/M: reg, vvvv, r/m */
930#define IEMOPFORM_VEX_RVM 8
931/** VEX+ModR/M: r/m, vvvv, reg */
932#define IEMOPFORM_VEX_MVR 9
933
934/** Fixed register instruction, no R/M. */
935#define IEMOPFORM_FIXED 16
936
937/** The r/m is a register. */
938#define IEMOPFORM_MOD3 RT_BIT_32(8)
939/** The r/m is a memory access. */
940#define IEMOPFORM_NOT_MOD3 RT_BIT_32(9)
941/** @} */
942
943/** @name IEMOPHINT_XXX - Additional Opcode Hints
944 * @note These are ORed together with IEMOPFORM_XXX.
945 * @{ */
946/** Both the operand size prefixes are ignored. */
947#define IEMOPHINT_IGNORES_OP_SIZE RT_BIT_32(10)
948/** Allowed with the lock prefix. */
949#define IEMOPHINT_LOCK_ALLOWED RT_BIT_32(11)
950/** Hint to IEMAllInstructionPython.py that this macro should be skipped. */
951#define IEMOPHINT_SKIP_PYTHON RT_BIT_32(31)
952/** @} */
953
954/**
955 * Possible hardware task switch sources.
956 */
957typedef enum IEMTASKSWITCH
958{
959 /** Task switch caused by an interrupt/exception. */
960 IEMTASKSWITCH_INT_XCPT = 1,
961 /** Task switch caused by a far CALL. */
962 IEMTASKSWITCH_CALL,
963 /** Task switch caused by a far JMP. */
964 IEMTASKSWITCH_JUMP,
965 /** Task switch caused by an IRET. */
966 IEMTASKSWITCH_IRET
967} IEMTASKSWITCH;
968AssertCompileSize(IEMTASKSWITCH, 4);
969
970/**
971 * Possible CrX load (write) sources.
972 */
973typedef enum IEMACCESSCRX
974{
975 /** CrX access caused by 'mov crX' instruction. */
976 IEMACCESSCRX_MOV_CRX,
977 /** CrX (CR0) write caused by 'lmsw' instruction. */
978 IEMACCESSCRX_LMSW,
979 /** CrX (CR0) write caused by 'clts' instruction. */
980 IEMACCESSCRX_CLTS,
981 /** CrX (CR0) read caused by 'smsw' instruction. */
982 IEMACCESSCRX_SMSW
983} IEMACCESSCRX;
984
985/**
986 * Tests if verification mode is enabled.
987 *
988 * This expands to @c false when IEM_VERIFICATION_MODE is not defined and
989 * should therefore cause the compiler to eliminate the verification branch
990 * of an if statement. */
991#ifdef IEM_VERIFICATION_MODE_FULL
992# define IEM_VERIFICATION_ENABLED(a_pVCpu) (!(a_pVCpu)->iem.s.fNoRem)
993#elif defined(IEM_VERIFICATION_MODE_MINIMAL)
994# define IEM_VERIFICATION_ENABLED(a_pVCpu) (true)
995#else
996# define IEM_VERIFICATION_ENABLED(a_pVCpu) (false)
997#endif
998
999/**
1000 * Tests if full verification mode is enabled.
1001 *
1002 * This expands to @c false when IEM_VERIFICATION_MODE_FULL is not defined and
1003 * should therefore cause the compiler to eliminate the verification branch
1004 * of an if statement. */
1005#ifdef IEM_VERIFICATION_MODE_FULL
1006# define IEM_FULL_VERIFICATION_ENABLED(a_pVCpu) (!(a_pVCpu)->iem.s.fNoRem)
1007#else
1008# define IEM_FULL_VERIFICATION_ENABLED(a_pVCpu) (false)
1009#endif
1010
1011/**
1012 * Tests if full verification mode is enabled again REM.
1013 *
1014 * This expands to @c false when IEM_VERIFICATION_MODE_FULL is not defined and
1015 * should therefore cause the compiler to eliminate the verification branch
1016 * of an if statement. */
1017#ifdef IEM_VERIFICATION_MODE_FULL
1018# ifdef IEM_VERIFICATION_MODE_FULL_HM
1019# define IEM_FULL_VERIFICATION_REM_ENABLED(a_pVCpu) (!(a_pVCpu)->iem.s.fNoRem && !HMIsEnabled((a_pVCpu)->CTX_SUFF(pVM)))
1020# else
1021# define IEM_FULL_VERIFICATION_REM_ENABLED(a_pVCpu) (!(a_pVCpu)->iem.s.fNoRem)
1022# endif
1023#else
1024# define IEM_FULL_VERIFICATION_REM_ENABLED(a_pVCpu) (false)
1025#endif
1026
1027/** @def IEM_VERIFICATION_MODE
1028 * Indicates that one of the verfication modes are enabled.
1029 */
1030#if (defined(IEM_VERIFICATION_MODE_FULL) || defined(IEM_VERIFICATION_MODE_MINIMAL)) && !defined(IEM_VERIFICATION_MODE) \
1031 || defined(DOXYGEN_RUNNING)
1032# define IEM_VERIFICATION_MODE
1033#endif
1034
1035/**
1036 * Indicates to the verifier that the given flag set is undefined.
1037 *
1038 * Can be invoked again to add more flags.
1039 *
1040 * This is a NOOP if the verifier isn't compiled in.
1041 */
1042#ifdef IEM_VERIFICATION_MODE_FULL
1043# define IEMOP_VERIFICATION_UNDEFINED_EFLAGS(a_fEfl) do { pVCpu->iem.s.fUndefinedEFlags |= (a_fEfl); } while (0)
1044#else
1045# define IEMOP_VERIFICATION_UNDEFINED_EFLAGS(a_fEfl) do { } while (0)
1046#endif
1047
1048
1049/** @def IEM_DECL_IMPL_TYPE
1050 * For typedef'ing an instruction implementation function.
1051 *
1052 * @param a_RetType The return type.
1053 * @param a_Name The name of the type.
1054 * @param a_ArgList The argument list enclosed in parentheses.
1055 */
1056
1057/** @def IEM_DECL_IMPL_DEF
1058 * For defining an instruction implementation function.
1059 *
1060 * @param a_RetType The return type.
1061 * @param a_Name The name of the type.
1062 * @param a_ArgList The argument list enclosed in parentheses.
1063 */
1064
1065#if defined(__GNUC__) && defined(RT_ARCH_X86)
1066# define IEM_DECL_IMPL_TYPE(a_RetType, a_Name, a_ArgList) \
1067 __attribute__((__fastcall__)) a_RetType (a_Name) a_ArgList
1068# define IEM_DECL_IMPL_DEF(a_RetType, a_Name, a_ArgList) \
1069 __attribute__((__fastcall__, __nothrow__)) a_RetType a_Name a_ArgList
1070
1071#elif defined(_MSC_VER) && defined(RT_ARCH_X86)
1072# define IEM_DECL_IMPL_TYPE(a_RetType, a_Name, a_ArgList) \
1073 a_RetType (__fastcall a_Name) a_ArgList
1074# define IEM_DECL_IMPL_DEF(a_RetType, a_Name, a_ArgList) \
1075 a_RetType __fastcall a_Name a_ArgList
1076
1077#else
1078# define IEM_DECL_IMPL_TYPE(a_RetType, a_Name, a_ArgList) \
1079 a_RetType (VBOXCALL a_Name) a_ArgList
1080# define IEM_DECL_IMPL_DEF(a_RetType, a_Name, a_ArgList) \
1081 a_RetType VBOXCALL a_Name a_ArgList
1082
1083#endif
1084
1085/** @name Arithmetic assignment operations on bytes (binary).
1086 * @{ */
1087typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLBINU8, (uint8_t *pu8Dst, uint8_t u8Src, uint32_t *pEFlags));
1088typedef FNIEMAIMPLBINU8 *PFNIEMAIMPLBINU8;
1089FNIEMAIMPLBINU8 iemAImpl_add_u8, iemAImpl_add_u8_locked;
1090FNIEMAIMPLBINU8 iemAImpl_adc_u8, iemAImpl_adc_u8_locked;
1091FNIEMAIMPLBINU8 iemAImpl_sub_u8, iemAImpl_sub_u8_locked;
1092FNIEMAIMPLBINU8 iemAImpl_sbb_u8, iemAImpl_sbb_u8_locked;
1093FNIEMAIMPLBINU8 iemAImpl_or_u8, iemAImpl_or_u8_locked;
1094FNIEMAIMPLBINU8 iemAImpl_xor_u8, iemAImpl_xor_u8_locked;
1095FNIEMAIMPLBINU8 iemAImpl_and_u8, iemAImpl_and_u8_locked;
1096/** @} */
1097
1098/** @name Arithmetic assignment operations on words (binary).
1099 * @{ */
1100typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLBINU16, (uint16_t *pu16Dst, uint16_t u16Src, uint32_t *pEFlags));
1101typedef FNIEMAIMPLBINU16 *PFNIEMAIMPLBINU16;
1102FNIEMAIMPLBINU16 iemAImpl_add_u16, iemAImpl_add_u16_locked;
1103FNIEMAIMPLBINU16 iemAImpl_adc_u16, iemAImpl_adc_u16_locked;
1104FNIEMAIMPLBINU16 iemAImpl_sub_u16, iemAImpl_sub_u16_locked;
1105FNIEMAIMPLBINU16 iemAImpl_sbb_u16, iemAImpl_sbb_u16_locked;
1106FNIEMAIMPLBINU16 iemAImpl_or_u16, iemAImpl_or_u16_locked;
1107FNIEMAIMPLBINU16 iemAImpl_xor_u16, iemAImpl_xor_u16_locked;
1108FNIEMAIMPLBINU16 iemAImpl_and_u16, iemAImpl_and_u16_locked;
1109/** @} */
1110
1111/** @name Arithmetic assignment operations on double words (binary).
1112 * @{ */
1113typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLBINU32, (uint32_t *pu32Dst, uint32_t u32Src, uint32_t *pEFlags));
1114typedef FNIEMAIMPLBINU32 *PFNIEMAIMPLBINU32;
1115FNIEMAIMPLBINU32 iemAImpl_add_u32, iemAImpl_add_u32_locked;
1116FNIEMAIMPLBINU32 iemAImpl_adc_u32, iemAImpl_adc_u32_locked;
1117FNIEMAIMPLBINU32 iemAImpl_sub_u32, iemAImpl_sub_u32_locked;
1118FNIEMAIMPLBINU32 iemAImpl_sbb_u32, iemAImpl_sbb_u32_locked;
1119FNIEMAIMPLBINU32 iemAImpl_or_u32, iemAImpl_or_u32_locked;
1120FNIEMAIMPLBINU32 iemAImpl_xor_u32, iemAImpl_xor_u32_locked;
1121FNIEMAIMPLBINU32 iemAImpl_and_u32, iemAImpl_and_u32_locked;
1122/** @} */
1123
1124/** @name Arithmetic assignment operations on quad words (binary).
1125 * @{ */
1126typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLBINU64, (uint64_t *pu64Dst, uint64_t u64Src, uint32_t *pEFlags));
1127typedef FNIEMAIMPLBINU64 *PFNIEMAIMPLBINU64;
1128FNIEMAIMPLBINU64 iemAImpl_add_u64, iemAImpl_add_u64_locked;
1129FNIEMAIMPLBINU64 iemAImpl_adc_u64, iemAImpl_adc_u64_locked;
1130FNIEMAIMPLBINU64 iemAImpl_sub_u64, iemAImpl_sub_u64_locked;
1131FNIEMAIMPLBINU64 iemAImpl_sbb_u64, iemAImpl_sbb_u64_locked;
1132FNIEMAIMPLBINU64 iemAImpl_or_u64, iemAImpl_or_u64_locked;
1133FNIEMAIMPLBINU64 iemAImpl_xor_u64, iemAImpl_xor_u64_locked;
1134FNIEMAIMPLBINU64 iemAImpl_and_u64, iemAImpl_and_u64_locked;
1135/** @} */
1136
1137/** @name Compare operations (thrown in with the binary ops).
1138 * @{ */
1139FNIEMAIMPLBINU8 iemAImpl_cmp_u8;
1140FNIEMAIMPLBINU16 iemAImpl_cmp_u16;
1141FNIEMAIMPLBINU32 iemAImpl_cmp_u32;
1142FNIEMAIMPLBINU64 iemAImpl_cmp_u64;
1143/** @} */
1144
1145/** @name Test operations (thrown in with the binary ops).
1146 * @{ */
1147FNIEMAIMPLBINU8 iemAImpl_test_u8;
1148FNIEMAIMPLBINU16 iemAImpl_test_u16;
1149FNIEMAIMPLBINU32 iemAImpl_test_u32;
1150FNIEMAIMPLBINU64 iemAImpl_test_u64;
1151/** @} */
1152
1153/** @name Bit operations operations (thrown in with the binary ops).
1154 * @{ */
1155FNIEMAIMPLBINU16 iemAImpl_bt_u16, iemAImpl_bt_u16_locked;
1156FNIEMAIMPLBINU32 iemAImpl_bt_u32, iemAImpl_bt_u32_locked;
1157FNIEMAIMPLBINU64 iemAImpl_bt_u64, iemAImpl_bt_u64_locked;
1158FNIEMAIMPLBINU16 iemAImpl_btc_u16, iemAImpl_btc_u16_locked;
1159FNIEMAIMPLBINU32 iemAImpl_btc_u32, iemAImpl_btc_u32_locked;
1160FNIEMAIMPLBINU64 iemAImpl_btc_u64, iemAImpl_btc_u64_locked;
1161FNIEMAIMPLBINU16 iemAImpl_btr_u16, iemAImpl_btr_u16_locked;
1162FNIEMAIMPLBINU32 iemAImpl_btr_u32, iemAImpl_btr_u32_locked;
1163FNIEMAIMPLBINU64 iemAImpl_btr_u64, iemAImpl_btr_u64_locked;
1164FNIEMAIMPLBINU16 iemAImpl_bts_u16, iemAImpl_bts_u16_locked;
1165FNIEMAIMPLBINU32 iemAImpl_bts_u32, iemAImpl_bts_u32_locked;
1166FNIEMAIMPLBINU64 iemAImpl_bts_u64, iemAImpl_bts_u64_locked;
1167/** @} */
1168
1169/** @name Exchange memory with register operations.
1170 * @{ */
1171IEM_DECL_IMPL_DEF(void, iemAImpl_xchg_u8, (uint8_t *pu8Mem, uint8_t *pu8Reg));
1172IEM_DECL_IMPL_DEF(void, iemAImpl_xchg_u16,(uint16_t *pu16Mem, uint16_t *pu16Reg));
1173IEM_DECL_IMPL_DEF(void, iemAImpl_xchg_u32,(uint32_t *pu32Mem, uint32_t *pu32Reg));
1174IEM_DECL_IMPL_DEF(void, iemAImpl_xchg_u64,(uint64_t *pu64Mem, uint64_t *pu64Reg));
1175/** @} */
1176
1177/** @name Exchange and add operations.
1178 * @{ */
1179IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u8, (uint8_t *pu8Dst, uint8_t *pu8Reg, uint32_t *pEFlags));
1180IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u16,(uint16_t *pu16Dst, uint16_t *pu16Reg, uint32_t *pEFlags));
1181IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u32,(uint32_t *pu32Dst, uint32_t *pu32Reg, uint32_t *pEFlags));
1182IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u64,(uint64_t *pu64Dst, uint64_t *pu64Reg, uint32_t *pEFlags));
1183IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u8_locked, (uint8_t *pu8Dst, uint8_t *pu8Reg, uint32_t *pEFlags));
1184IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u16_locked,(uint16_t *pu16Dst, uint16_t *pu16Reg, uint32_t *pEFlags));
1185IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u32_locked,(uint32_t *pu32Dst, uint32_t *pu32Reg, uint32_t *pEFlags));
1186IEM_DECL_IMPL_DEF(void, iemAImpl_xadd_u64_locked,(uint64_t *pu64Dst, uint64_t *pu64Reg, uint32_t *pEFlags));
1187/** @} */
1188
1189/** @name Compare and exchange.
1190 * @{ */
1191IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u8, (uint8_t *pu8Dst, uint8_t *puAl, uint8_t uSrcReg, uint32_t *pEFlags));
1192IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u8_locked, (uint8_t *pu8Dst, uint8_t *puAl, uint8_t uSrcReg, uint32_t *pEFlags));
1193IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u16, (uint16_t *pu16Dst, uint16_t *puAx, uint16_t uSrcReg, uint32_t *pEFlags));
1194IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u16_locked,(uint16_t *pu16Dst, uint16_t *puAx, uint16_t uSrcReg, uint32_t *pEFlags));
1195IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u32, (uint32_t *pu32Dst, uint32_t *puEax, uint32_t uSrcReg, uint32_t *pEFlags));
1196IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u32_locked,(uint32_t *pu32Dst, uint32_t *puEax, uint32_t uSrcReg, uint32_t *pEFlags));
1197#ifdef RT_ARCH_X86
1198IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u64, (uint64_t *pu64Dst, uint64_t *puRax, uint64_t *puSrcReg, uint32_t *pEFlags));
1199IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u64_locked,(uint64_t *pu64Dst, uint64_t *puRax, uint64_t *puSrcReg, uint32_t *pEFlags));
1200#else
1201IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u64, (uint64_t *pu64Dst, uint64_t *puRax, uint64_t uSrcReg, uint32_t *pEFlags));
1202IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg_u64_locked,(uint64_t *pu64Dst, uint64_t *puRax, uint64_t uSrcReg, uint32_t *pEFlags));
1203#endif
1204IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg8b,(uint64_t *pu64Dst, PRTUINT64U pu64EaxEdx, PRTUINT64U pu64EbxEcx,
1205 uint32_t *pEFlags));
1206IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg8b_locked,(uint64_t *pu64Dst, PRTUINT64U pu64EaxEdx, PRTUINT64U pu64EbxEcx,
1207 uint32_t *pEFlags));
1208IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg16b,(PRTUINT128U pu128Dst, PRTUINT128U pu128RaxRdx, PRTUINT128U pu128RbxRcx,
1209 uint32_t *pEFlags));
1210IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg16b_locked,(PRTUINT128U pu128Dst, PRTUINT128U pu128RaxRdx, PRTUINT128U pu128RbxRcx,
1211 uint32_t *pEFlags));
1212IEM_DECL_IMPL_DEF(void, iemAImpl_cmpxchg16b_fallback,(PRTUINT128U pu128Dst, PRTUINT128U pu128RaxRdx,
1213 PRTUINT128U pu128RbxRcx, uint32_t *pEFlags));
1214/** @} */
1215
1216/** @name Memory ordering
1217 * @{ */
1218typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEMFENCE,(void));
1219typedef FNIEMAIMPLMEMFENCE *PFNIEMAIMPLMEMFENCE;
1220IEM_DECL_IMPL_DEF(void, iemAImpl_mfence,(void));
1221IEM_DECL_IMPL_DEF(void, iemAImpl_sfence,(void));
1222IEM_DECL_IMPL_DEF(void, iemAImpl_lfence,(void));
1223IEM_DECL_IMPL_DEF(void, iemAImpl_alt_mem_fence,(void));
1224/** @} */
1225
1226/** @name Double precision shifts
1227 * @{ */
1228typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTDBLU16,(uint16_t *pu16Dst, uint16_t u16Src, uint8_t cShift, uint32_t *pEFlags));
1229typedef FNIEMAIMPLSHIFTDBLU16 *PFNIEMAIMPLSHIFTDBLU16;
1230typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTDBLU32,(uint32_t *pu32Dst, uint32_t u32Src, uint8_t cShift, uint32_t *pEFlags));
1231typedef FNIEMAIMPLSHIFTDBLU32 *PFNIEMAIMPLSHIFTDBLU32;
1232typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTDBLU64,(uint64_t *pu64Dst, uint64_t u64Src, uint8_t cShift, uint32_t *pEFlags));
1233typedef FNIEMAIMPLSHIFTDBLU64 *PFNIEMAIMPLSHIFTDBLU64;
1234FNIEMAIMPLSHIFTDBLU16 iemAImpl_shld_u16;
1235FNIEMAIMPLSHIFTDBLU32 iemAImpl_shld_u32;
1236FNIEMAIMPLSHIFTDBLU64 iemAImpl_shld_u64;
1237FNIEMAIMPLSHIFTDBLU16 iemAImpl_shrd_u16;
1238FNIEMAIMPLSHIFTDBLU32 iemAImpl_shrd_u32;
1239FNIEMAIMPLSHIFTDBLU64 iemAImpl_shrd_u64;
1240/** @} */
1241
1242
1243/** @name Bit search operations (thrown in with the binary ops).
1244 * @{ */
1245FNIEMAIMPLBINU16 iemAImpl_bsf_u16;
1246FNIEMAIMPLBINU32 iemAImpl_bsf_u32;
1247FNIEMAIMPLBINU64 iemAImpl_bsf_u64;
1248FNIEMAIMPLBINU16 iemAImpl_bsr_u16;
1249FNIEMAIMPLBINU32 iemAImpl_bsr_u32;
1250FNIEMAIMPLBINU64 iemAImpl_bsr_u64;
1251/** @} */
1252
1253/** @name Signed multiplication operations (thrown in with the binary ops).
1254 * @{ */
1255FNIEMAIMPLBINU16 iemAImpl_imul_two_u16;
1256FNIEMAIMPLBINU32 iemAImpl_imul_two_u32;
1257FNIEMAIMPLBINU64 iemAImpl_imul_two_u64;
1258/** @} */
1259
1260/** @name Arithmetic assignment operations on bytes (unary).
1261 * @{ */
1262typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLUNARYU8, (uint8_t *pu8Dst, uint32_t *pEFlags));
1263typedef FNIEMAIMPLUNARYU8 *PFNIEMAIMPLUNARYU8;
1264FNIEMAIMPLUNARYU8 iemAImpl_inc_u8, iemAImpl_inc_u8_locked;
1265FNIEMAIMPLUNARYU8 iemAImpl_dec_u8, iemAImpl_dec_u8_locked;
1266FNIEMAIMPLUNARYU8 iemAImpl_not_u8, iemAImpl_not_u8_locked;
1267FNIEMAIMPLUNARYU8 iemAImpl_neg_u8, iemAImpl_neg_u8_locked;
1268/** @} */
1269
1270/** @name Arithmetic assignment operations on words (unary).
1271 * @{ */
1272typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLUNARYU16, (uint16_t *pu16Dst, uint32_t *pEFlags));
1273typedef FNIEMAIMPLUNARYU16 *PFNIEMAIMPLUNARYU16;
1274FNIEMAIMPLUNARYU16 iemAImpl_inc_u16, iemAImpl_inc_u16_locked;
1275FNIEMAIMPLUNARYU16 iemAImpl_dec_u16, iemAImpl_dec_u16_locked;
1276FNIEMAIMPLUNARYU16 iemAImpl_not_u16, iemAImpl_not_u16_locked;
1277FNIEMAIMPLUNARYU16 iemAImpl_neg_u16, iemAImpl_neg_u16_locked;
1278/** @} */
1279
1280/** @name Arithmetic assignment operations on double words (unary).
1281 * @{ */
1282typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLUNARYU32, (uint32_t *pu32Dst, uint32_t *pEFlags));
1283typedef FNIEMAIMPLUNARYU32 *PFNIEMAIMPLUNARYU32;
1284FNIEMAIMPLUNARYU32 iemAImpl_inc_u32, iemAImpl_inc_u32_locked;
1285FNIEMAIMPLUNARYU32 iemAImpl_dec_u32, iemAImpl_dec_u32_locked;
1286FNIEMAIMPLUNARYU32 iemAImpl_not_u32, iemAImpl_not_u32_locked;
1287FNIEMAIMPLUNARYU32 iemAImpl_neg_u32, iemAImpl_neg_u32_locked;
1288/** @} */
1289
1290/** @name Arithmetic assignment operations on quad words (unary).
1291 * @{ */
1292typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLUNARYU64, (uint64_t *pu64Dst, uint32_t *pEFlags));
1293typedef FNIEMAIMPLUNARYU64 *PFNIEMAIMPLUNARYU64;
1294FNIEMAIMPLUNARYU64 iemAImpl_inc_u64, iemAImpl_inc_u64_locked;
1295FNIEMAIMPLUNARYU64 iemAImpl_dec_u64, iemAImpl_dec_u64_locked;
1296FNIEMAIMPLUNARYU64 iemAImpl_not_u64, iemAImpl_not_u64_locked;
1297FNIEMAIMPLUNARYU64 iemAImpl_neg_u64, iemAImpl_neg_u64_locked;
1298/** @} */
1299
1300
1301/** @name Shift operations on bytes (Group 2).
1302 * @{ */
1303typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTU8,(uint8_t *pu8Dst, uint8_t cShift, uint32_t *pEFlags));
1304typedef FNIEMAIMPLSHIFTU8 *PFNIEMAIMPLSHIFTU8;
1305FNIEMAIMPLSHIFTU8 iemAImpl_rol_u8;
1306FNIEMAIMPLSHIFTU8 iemAImpl_ror_u8;
1307FNIEMAIMPLSHIFTU8 iemAImpl_rcl_u8;
1308FNIEMAIMPLSHIFTU8 iemAImpl_rcr_u8;
1309FNIEMAIMPLSHIFTU8 iemAImpl_shl_u8;
1310FNIEMAIMPLSHIFTU8 iemAImpl_shr_u8;
1311FNIEMAIMPLSHIFTU8 iemAImpl_sar_u8;
1312/** @} */
1313
1314/** @name Shift operations on words (Group 2).
1315 * @{ */
1316typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTU16,(uint16_t *pu16Dst, uint8_t cShift, uint32_t *pEFlags));
1317typedef FNIEMAIMPLSHIFTU16 *PFNIEMAIMPLSHIFTU16;
1318FNIEMAIMPLSHIFTU16 iemAImpl_rol_u16;
1319FNIEMAIMPLSHIFTU16 iemAImpl_ror_u16;
1320FNIEMAIMPLSHIFTU16 iemAImpl_rcl_u16;
1321FNIEMAIMPLSHIFTU16 iemAImpl_rcr_u16;
1322FNIEMAIMPLSHIFTU16 iemAImpl_shl_u16;
1323FNIEMAIMPLSHIFTU16 iemAImpl_shr_u16;
1324FNIEMAIMPLSHIFTU16 iemAImpl_sar_u16;
1325/** @} */
1326
1327/** @name Shift operations on double words (Group 2).
1328 * @{ */
1329typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTU32,(uint32_t *pu32Dst, uint8_t cShift, uint32_t *pEFlags));
1330typedef FNIEMAIMPLSHIFTU32 *PFNIEMAIMPLSHIFTU32;
1331FNIEMAIMPLSHIFTU32 iemAImpl_rol_u32;
1332FNIEMAIMPLSHIFTU32 iemAImpl_ror_u32;
1333FNIEMAIMPLSHIFTU32 iemAImpl_rcl_u32;
1334FNIEMAIMPLSHIFTU32 iemAImpl_rcr_u32;
1335FNIEMAIMPLSHIFTU32 iemAImpl_shl_u32;
1336FNIEMAIMPLSHIFTU32 iemAImpl_shr_u32;
1337FNIEMAIMPLSHIFTU32 iemAImpl_sar_u32;
1338/** @} */
1339
1340/** @name Shift operations on words (Group 2).
1341 * @{ */
1342typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLSHIFTU64,(uint64_t *pu64Dst, uint8_t cShift, uint32_t *pEFlags));
1343typedef FNIEMAIMPLSHIFTU64 *PFNIEMAIMPLSHIFTU64;
1344FNIEMAIMPLSHIFTU64 iemAImpl_rol_u64;
1345FNIEMAIMPLSHIFTU64 iemAImpl_ror_u64;
1346FNIEMAIMPLSHIFTU64 iemAImpl_rcl_u64;
1347FNIEMAIMPLSHIFTU64 iemAImpl_rcr_u64;
1348FNIEMAIMPLSHIFTU64 iemAImpl_shl_u64;
1349FNIEMAIMPLSHIFTU64 iemAImpl_shr_u64;
1350FNIEMAIMPLSHIFTU64 iemAImpl_sar_u64;
1351/** @} */
1352
1353/** @name Multiplication and division operations.
1354 * @{ */
1355typedef IEM_DECL_IMPL_TYPE(int, FNIEMAIMPLMULDIVU8,(uint16_t *pu16AX, uint8_t u8FactorDivisor, uint32_t *pEFlags));
1356typedef FNIEMAIMPLMULDIVU8 *PFNIEMAIMPLMULDIVU8;
1357FNIEMAIMPLMULDIVU8 iemAImpl_mul_u8, iemAImpl_imul_u8;
1358FNIEMAIMPLMULDIVU8 iemAImpl_div_u8, iemAImpl_idiv_u8;
1359
1360typedef IEM_DECL_IMPL_TYPE(int, FNIEMAIMPLMULDIVU16,(uint16_t *pu16AX, uint16_t *pu16DX, uint16_t u16FactorDivisor, uint32_t *pEFlags));
1361typedef FNIEMAIMPLMULDIVU16 *PFNIEMAIMPLMULDIVU16;
1362FNIEMAIMPLMULDIVU16 iemAImpl_mul_u16, iemAImpl_imul_u16;
1363FNIEMAIMPLMULDIVU16 iemAImpl_div_u16, iemAImpl_idiv_u16;
1364
1365typedef IEM_DECL_IMPL_TYPE(int, FNIEMAIMPLMULDIVU32,(uint32_t *pu32EAX, uint32_t *pu32EDX, uint32_t u32FactorDivisor, uint32_t *pEFlags));
1366typedef FNIEMAIMPLMULDIVU32 *PFNIEMAIMPLMULDIVU32;
1367FNIEMAIMPLMULDIVU32 iemAImpl_mul_u32, iemAImpl_imul_u32;
1368FNIEMAIMPLMULDIVU32 iemAImpl_div_u32, iemAImpl_idiv_u32;
1369
1370typedef IEM_DECL_IMPL_TYPE(int, FNIEMAIMPLMULDIVU64,(uint64_t *pu64RAX, uint64_t *pu64RDX, uint64_t u64FactorDivisor, uint32_t *pEFlags));
1371typedef FNIEMAIMPLMULDIVU64 *PFNIEMAIMPLMULDIVU64;
1372FNIEMAIMPLMULDIVU64 iemAImpl_mul_u64, iemAImpl_imul_u64;
1373FNIEMAIMPLMULDIVU64 iemAImpl_div_u64, iemAImpl_idiv_u64;
1374/** @} */
1375
1376/** @name Byte Swap.
1377 * @{ */
1378IEM_DECL_IMPL_TYPE(void, iemAImpl_bswap_u16,(uint32_t *pu32Dst)); /* Yes, 32-bit register access. */
1379IEM_DECL_IMPL_TYPE(void, iemAImpl_bswap_u32,(uint32_t *pu32Dst));
1380IEM_DECL_IMPL_TYPE(void, iemAImpl_bswap_u64,(uint64_t *pu64Dst));
1381/** @} */
1382
1383/** @name Misc.
1384 * @{ */
1385FNIEMAIMPLBINU16 iemAImpl_arpl;
1386/** @} */
1387
1388
1389/** @name FPU operations taking a 32-bit float argument
1390 * @{ */
1391typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR32FSW,(PCX86FXSTATE pFpuState, uint16_t *pFSW,
1392 PCRTFLOAT80U pr80Val1, PCRTFLOAT32U pr32Val2));
1393typedef FNIEMAIMPLFPUR32FSW *PFNIEMAIMPLFPUR32FSW;
1394
1395typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR32,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1396 PCRTFLOAT80U pr80Val1, PCRTFLOAT32U pr32Val2));
1397typedef FNIEMAIMPLFPUR32 *PFNIEMAIMPLFPUR32;
1398
1399FNIEMAIMPLFPUR32FSW iemAImpl_fcom_r80_by_r32;
1400FNIEMAIMPLFPUR32 iemAImpl_fadd_r80_by_r32;
1401FNIEMAIMPLFPUR32 iemAImpl_fmul_r80_by_r32;
1402FNIEMAIMPLFPUR32 iemAImpl_fsub_r80_by_r32;
1403FNIEMAIMPLFPUR32 iemAImpl_fsubr_r80_by_r32;
1404FNIEMAIMPLFPUR32 iemAImpl_fdiv_r80_by_r32;
1405FNIEMAIMPLFPUR32 iemAImpl_fdivr_r80_by_r32;
1406
1407IEM_DECL_IMPL_DEF(void, iemAImpl_fld_r32_to_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, PCRTFLOAT32U pr32Val));
1408IEM_DECL_IMPL_DEF(void, iemAImpl_fst_r80_to_r32,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1409 PRTFLOAT32U pr32Val, PCRTFLOAT80U pr80Val));
1410/** @} */
1411
1412/** @name FPU operations taking a 64-bit float argument
1413 * @{ */
1414typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR64,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1415 PCRTFLOAT80U pr80Val1, PCRTFLOAT64U pr64Val2));
1416typedef FNIEMAIMPLFPUR64 *PFNIEMAIMPLFPUR64;
1417
1418FNIEMAIMPLFPUR64 iemAImpl_fadd_r80_by_r64;
1419FNIEMAIMPLFPUR64 iemAImpl_fmul_r80_by_r64;
1420FNIEMAIMPLFPUR64 iemAImpl_fsub_r80_by_r64;
1421FNIEMAIMPLFPUR64 iemAImpl_fsubr_r80_by_r64;
1422FNIEMAIMPLFPUR64 iemAImpl_fdiv_r80_by_r64;
1423FNIEMAIMPLFPUR64 iemAImpl_fdivr_r80_by_r64;
1424
1425IEM_DECL_IMPL_DEF(void, iemAImpl_fcom_r80_by_r64,(PCX86FXSTATE pFpuState, uint16_t *pFSW,
1426 PCRTFLOAT80U pr80Val1, PCRTFLOAT64U pr64Val2));
1427IEM_DECL_IMPL_DEF(void, iemAImpl_fld_r64_to_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, PCRTFLOAT64U pr64Val));
1428IEM_DECL_IMPL_DEF(void, iemAImpl_fst_r80_to_r64,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1429 PRTFLOAT64U pr32Val, PCRTFLOAT80U pr80Val));
1430/** @} */
1431
1432/** @name FPU operations taking a 80-bit float argument
1433 * @{ */
1434typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1435 PCRTFLOAT80U pr80Val1, PCRTFLOAT80U pr80Val2));
1436typedef FNIEMAIMPLFPUR80 *PFNIEMAIMPLFPUR80;
1437FNIEMAIMPLFPUR80 iemAImpl_fadd_r80_by_r80;
1438FNIEMAIMPLFPUR80 iemAImpl_fmul_r80_by_r80;
1439FNIEMAIMPLFPUR80 iemAImpl_fsub_r80_by_r80;
1440FNIEMAIMPLFPUR80 iemAImpl_fsubr_r80_by_r80;
1441FNIEMAIMPLFPUR80 iemAImpl_fdiv_r80_by_r80;
1442FNIEMAIMPLFPUR80 iemAImpl_fdivr_r80_by_r80;
1443FNIEMAIMPLFPUR80 iemAImpl_fprem_r80_by_r80;
1444FNIEMAIMPLFPUR80 iemAImpl_fprem1_r80_by_r80;
1445FNIEMAIMPLFPUR80 iemAImpl_fscale_r80_by_r80;
1446
1447FNIEMAIMPLFPUR80 iemAImpl_fpatan_r80_by_r80;
1448FNIEMAIMPLFPUR80 iemAImpl_fyl2x_r80_by_r80;
1449FNIEMAIMPLFPUR80 iemAImpl_fyl2xp1_r80_by_r80;
1450
1451typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80FSW,(PCX86FXSTATE pFpuState, uint16_t *pFSW,
1452 PCRTFLOAT80U pr80Val1, PCRTFLOAT80U pr80Val2));
1453typedef FNIEMAIMPLFPUR80FSW *PFNIEMAIMPLFPUR80FSW;
1454FNIEMAIMPLFPUR80FSW iemAImpl_fcom_r80_by_r80;
1455FNIEMAIMPLFPUR80FSW iemAImpl_fucom_r80_by_r80;
1456
1457typedef IEM_DECL_IMPL_TYPE(uint32_t, FNIEMAIMPLFPUR80EFL,(PCX86FXSTATE pFpuState, uint16_t *pu16Fsw,
1458 PCRTFLOAT80U pr80Val1, PCRTFLOAT80U pr80Val2));
1459typedef FNIEMAIMPLFPUR80EFL *PFNIEMAIMPLFPUR80EFL;
1460FNIEMAIMPLFPUR80EFL iemAImpl_fcomi_r80_by_r80;
1461FNIEMAIMPLFPUR80EFL iemAImpl_fucomi_r80_by_r80;
1462
1463typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80UNARY,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, PCRTFLOAT80U pr80Val));
1464typedef FNIEMAIMPLFPUR80UNARY *PFNIEMAIMPLFPUR80UNARY;
1465FNIEMAIMPLFPUR80UNARY iemAImpl_fabs_r80;
1466FNIEMAIMPLFPUR80UNARY iemAImpl_fchs_r80;
1467FNIEMAIMPLFPUR80UNARY iemAImpl_f2xm1_r80;
1468FNIEMAIMPLFPUR80UNARY iemAImpl_fsqrt_r80;
1469FNIEMAIMPLFPUR80UNARY iemAImpl_frndint_r80;
1470FNIEMAIMPLFPUR80UNARY iemAImpl_fsin_r80;
1471FNIEMAIMPLFPUR80UNARY iemAImpl_fcos_r80;
1472
1473typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80UNARYFSW,(PCX86FXSTATE pFpuState, uint16_t *pu16Fsw, PCRTFLOAT80U pr80Val));
1474typedef FNIEMAIMPLFPUR80UNARYFSW *PFNIEMAIMPLFPUR80UNARYFSW;
1475FNIEMAIMPLFPUR80UNARYFSW iemAImpl_ftst_r80;
1476FNIEMAIMPLFPUR80UNARYFSW iemAImpl_fxam_r80;
1477
1478typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80LDCONST,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes));
1479typedef FNIEMAIMPLFPUR80LDCONST *PFNIEMAIMPLFPUR80LDCONST;
1480FNIEMAIMPLFPUR80LDCONST iemAImpl_fld1;
1481FNIEMAIMPLFPUR80LDCONST iemAImpl_fldl2t;
1482FNIEMAIMPLFPUR80LDCONST iemAImpl_fldl2e;
1483FNIEMAIMPLFPUR80LDCONST iemAImpl_fldpi;
1484FNIEMAIMPLFPUR80LDCONST iemAImpl_fldlg2;
1485FNIEMAIMPLFPUR80LDCONST iemAImpl_fldln2;
1486FNIEMAIMPLFPUR80LDCONST iemAImpl_fldz;
1487
1488typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUR80UNARYTWO,(PCX86FXSTATE pFpuState, PIEMFPURESULTTWO pFpuResTwo,
1489 PCRTFLOAT80U pr80Val));
1490typedef FNIEMAIMPLFPUR80UNARYTWO *PFNIEMAIMPLFPUR80UNARYTWO;
1491FNIEMAIMPLFPUR80UNARYTWO iemAImpl_fptan_r80_r80;
1492FNIEMAIMPLFPUR80UNARYTWO iemAImpl_fxtract_r80_r80;
1493FNIEMAIMPLFPUR80UNARYTWO iemAImpl_fsincos_r80_r80;
1494
1495IEM_DECL_IMPL_DEF(void, iemAImpl_fld_r80_from_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, PCRTFLOAT80U pr80Val));
1496IEM_DECL_IMPL_DEF(void, iemAImpl_fst_r80_to_r80,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1497 PRTFLOAT80U pr80Dst, PCRTFLOAT80U pr80Src));
1498
1499/** @} */
1500
1501/** @name FPU operations taking a 16-bit signed integer argument
1502 * @{ */
1503typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUI16,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1504 PCRTFLOAT80U pr80Val1, int16_t const *pi16Val2));
1505typedef FNIEMAIMPLFPUI16 *PFNIEMAIMPLFPUI16;
1506
1507FNIEMAIMPLFPUI16 iemAImpl_fiadd_r80_by_i16;
1508FNIEMAIMPLFPUI16 iemAImpl_fimul_r80_by_i16;
1509FNIEMAIMPLFPUI16 iemAImpl_fisub_r80_by_i16;
1510FNIEMAIMPLFPUI16 iemAImpl_fisubr_r80_by_i16;
1511FNIEMAIMPLFPUI16 iemAImpl_fidiv_r80_by_i16;
1512FNIEMAIMPLFPUI16 iemAImpl_fidivr_r80_by_i16;
1513
1514IEM_DECL_IMPL_DEF(void, iemAImpl_ficom_r80_by_i16,(PCX86FXSTATE pFpuState, uint16_t *pu16Fsw,
1515 PCRTFLOAT80U pr80Val1, int16_t const *pi16Val2));
1516
1517IEM_DECL_IMPL_DEF(void, iemAImpl_fild_i16_to_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, int16_t const *pi16Val));
1518IEM_DECL_IMPL_DEF(void, iemAImpl_fist_r80_to_i16,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1519 int16_t *pi16Val, PCRTFLOAT80U pr80Val));
1520IEM_DECL_IMPL_DEF(void, iemAImpl_fistt_r80_to_i16,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1521 int16_t *pi16Val, PCRTFLOAT80U pr80Val));
1522/** @} */
1523
1524/** @name FPU operations taking a 32-bit signed integer argument
1525 * @{ */
1526typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUI32,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1527 PCRTFLOAT80U pr80Val1, int32_t const *pi32Val2));
1528typedef FNIEMAIMPLFPUI32 *PFNIEMAIMPLFPUI32;
1529
1530FNIEMAIMPLFPUI32 iemAImpl_fiadd_r80_by_i32;
1531FNIEMAIMPLFPUI32 iemAImpl_fimul_r80_by_i32;
1532FNIEMAIMPLFPUI32 iemAImpl_fisub_r80_by_i32;
1533FNIEMAIMPLFPUI32 iemAImpl_fisubr_r80_by_i32;
1534FNIEMAIMPLFPUI32 iemAImpl_fidiv_r80_by_i32;
1535FNIEMAIMPLFPUI32 iemAImpl_fidivr_r80_by_i32;
1536
1537IEM_DECL_IMPL_DEF(void, iemAImpl_ficom_r80_by_i32,(PCX86FXSTATE pFpuState, uint16_t *pu16Fsw,
1538 PCRTFLOAT80U pr80Val1, int32_t const *pi32Val2));
1539
1540IEM_DECL_IMPL_DEF(void, iemAImpl_fild_i32_to_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, int32_t const *pi32Val));
1541IEM_DECL_IMPL_DEF(void, iemAImpl_fist_r80_to_i32,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1542 int32_t *pi32Val, PCRTFLOAT80U pr80Val));
1543IEM_DECL_IMPL_DEF(void, iemAImpl_fistt_r80_to_i32,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1544 int32_t *pi32Val, PCRTFLOAT80U pr80Val));
1545/** @} */
1546
1547/** @name FPU operations taking a 64-bit signed integer argument
1548 * @{ */
1549typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLFPUI64,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes,
1550 PCRTFLOAT80U pr80Val1, int64_t const *pi64Val2));
1551typedef FNIEMAIMPLFPUI64 *PFNIEMAIMPLFPUI64;
1552
1553FNIEMAIMPLFPUI64 iemAImpl_fiadd_r80_by_i64;
1554FNIEMAIMPLFPUI64 iemAImpl_fimul_r80_by_i64;
1555FNIEMAIMPLFPUI64 iemAImpl_fisub_r80_by_i64;
1556FNIEMAIMPLFPUI64 iemAImpl_fisubr_r80_by_i64;
1557FNIEMAIMPLFPUI64 iemAImpl_fidiv_r80_by_i64;
1558FNIEMAIMPLFPUI64 iemAImpl_fidivr_r80_by_i64;
1559
1560IEM_DECL_IMPL_DEF(void, iemAImpl_ficom_r80_by_i64,(PCX86FXSTATE pFpuState, uint16_t *pu16Fsw,
1561 PCRTFLOAT80U pr80Val1, int64_t const *pi64Val2));
1562
1563IEM_DECL_IMPL_DEF(void, iemAImpl_fild_i64_to_r80,(PCX86FXSTATE pFpuState, PIEMFPURESULT pFpuRes, int64_t const *pi64Val));
1564IEM_DECL_IMPL_DEF(void, iemAImpl_fist_r80_to_i64,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1565 int64_t *pi64Val, PCRTFLOAT80U pr80Val));
1566IEM_DECL_IMPL_DEF(void, iemAImpl_fistt_r80_to_i64,(PCX86FXSTATE pFpuState, uint16_t *pu16FSW,
1567 int64_t *pi32Val, PCRTFLOAT80U pr80Val));
1568/** @} */
1569
1570
1571/** Temporary type representing a 256-bit vector register. */
1572typedef struct {uint64_t au64[4]; } IEMVMM256;
1573/** Temporary type pointing to a 256-bit vector register. */
1574typedef IEMVMM256 *PIEMVMM256;
1575/** Temporary type pointing to a const 256-bit vector register. */
1576typedef IEMVMM256 *PCIEMVMM256;
1577
1578
1579/** @name Media (SSE/MMX/AVX) operations: full1 + full2 -> full1.
1580 * @{ */
1581typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF2U64,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, uint64_t const *pu64Src));
1582typedef FNIEMAIMPLMEDIAF2U64 *PFNIEMAIMPLMEDIAF2U64;
1583typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF2U128,(PCX86FXSTATE pFpuState, PRTUINT128U pu128Dst, PCRTUINT128U pu128Src));
1584typedef FNIEMAIMPLMEDIAF2U128 *PFNIEMAIMPLMEDIAF2U128;
1585FNIEMAIMPLMEDIAF2U64 iemAImpl_pxor_u64, iemAImpl_pcmpeqb_u64, iemAImpl_pcmpeqw_u64, iemAImpl_pcmpeqd_u64;
1586FNIEMAIMPLMEDIAF2U128 iemAImpl_pxor_u128, iemAImpl_pcmpeqb_u128, iemAImpl_pcmpeqw_u128, iemAImpl_pcmpeqd_u128;
1587/** @} */
1588
1589/** @name Media (SSE/MMX/AVX) operations: lowhalf1 + lowhalf1 -> full1.
1590 * @{ */
1591typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF1L1U64,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, uint32_t const *pu32Src));
1592typedef FNIEMAIMPLMEDIAF1L1U64 *PFNIEMAIMPLMEDIAF1L1U64;
1593typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF1L1U128,(PCX86FXSTATE pFpuState, PRTUINT128U pu128Dst, uint64_t const *pu64Src));
1594typedef FNIEMAIMPLMEDIAF1L1U128 *PFNIEMAIMPLMEDIAF1L1U128;
1595FNIEMAIMPLMEDIAF1L1U64 iemAImpl_punpcklbw_u64, iemAImpl_punpcklwd_u64, iemAImpl_punpckldq_u64;
1596FNIEMAIMPLMEDIAF1L1U128 iemAImpl_punpcklbw_u128, iemAImpl_punpcklwd_u128, iemAImpl_punpckldq_u128, iemAImpl_punpcklqdq_u128;
1597/** @} */
1598
1599/** @name Media (SSE/MMX/AVX) operations: hihalf1 + hihalf2 -> full1.
1600 * @{ */
1601typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF1H1U64,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, uint64_t const *pu64Src));
1602typedef FNIEMAIMPLMEDIAF2U64 *PFNIEMAIMPLMEDIAF1H1U64;
1603typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAF1H1U128,(PCX86FXSTATE pFpuState, PRTUINT128U pu128Dst, PCRTUINT128U pu128Src));
1604typedef FNIEMAIMPLMEDIAF2U128 *PFNIEMAIMPLMEDIAF1H1U128;
1605FNIEMAIMPLMEDIAF1H1U64 iemAImpl_punpckhbw_u64, iemAImpl_punpckhwd_u64, iemAImpl_punpckhdq_u64;
1606FNIEMAIMPLMEDIAF1H1U128 iemAImpl_punpckhbw_u128, iemAImpl_punpckhwd_u128, iemAImpl_punpckhdq_u128, iemAImpl_punpckhqdq_u128;
1607/** @} */
1608
1609/** @name Media (SSE/MMX/AVX) operation: Packed Shuffle Stuff (evil)
1610 * @{ */
1611typedef IEM_DECL_IMPL_TYPE(void, FNIEMAIMPLMEDIAPSHUF,(PCX86FXSTATE pFpuState, PRTUINT128U pu128Dst,
1612 PCRTUINT128U pu128Src, uint8_t bEvil));
1613typedef FNIEMAIMPLMEDIAPSHUF *PFNIEMAIMPLMEDIAPSHUF;
1614FNIEMAIMPLMEDIAPSHUF iemAImpl_pshufhw, iemAImpl_pshuflw, iemAImpl_pshufd;
1615IEM_DECL_IMPL_DEF(void, iemAImpl_pshufw,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, uint64_t const *pu64Src, uint8_t bEvil));
1616/** @} */
1617
1618/** @name Media (SSE/MMX/AVX) operation: Move Byte Mask
1619 * @{ */
1620IEM_DECL_IMPL_DEF(void, iemAImpl_pmovmskb_u64,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, uint64_t const *pu64Src));
1621IEM_DECL_IMPL_DEF(void, iemAImpl_pmovmskb_u128,(PCX86FXSTATE pFpuState, uint64_t *pu64Dst, PCRTUINT128U pu128Src));
1622/** @} */
1623
1624/** @name Media (SSE/MMX/AVX) operation: Sort this later
1625 * @{ */
1626IEM_DECL_IMPL_DEF(void, iemAImpl_movsldup,(PCX86FXSTATE pFpuState, PRTUINT128U puDst, PCRTUINT128U puSrc));
1627IEM_DECL_IMPL_DEF(void, iemAImpl_movddup,(PCX86FXSTATE pFpuState, PRTUINT128U puDst, uint64_t uSrc));
1628/** @} */
1629
1630
1631/** @name Function tables.
1632 * @{
1633 */
1634
1635/**
1636 * Function table for a binary operator providing implementation based on
1637 * operand size.
1638 */
1639typedef struct IEMOPBINSIZES
1640{
1641 PFNIEMAIMPLBINU8 pfnNormalU8, pfnLockedU8;
1642 PFNIEMAIMPLBINU16 pfnNormalU16, pfnLockedU16;
1643 PFNIEMAIMPLBINU32 pfnNormalU32, pfnLockedU32;
1644 PFNIEMAIMPLBINU64 pfnNormalU64, pfnLockedU64;
1645} IEMOPBINSIZES;
1646/** Pointer to a binary operator function table. */
1647typedef IEMOPBINSIZES const *PCIEMOPBINSIZES;
1648
1649
1650/**
1651 * Function table for a unary operator providing implementation based on
1652 * operand size.
1653 */
1654typedef struct IEMOPUNARYSIZES
1655{
1656 PFNIEMAIMPLUNARYU8 pfnNormalU8, pfnLockedU8;
1657 PFNIEMAIMPLUNARYU16 pfnNormalU16, pfnLockedU16;
1658 PFNIEMAIMPLUNARYU32 pfnNormalU32, pfnLockedU32;
1659 PFNIEMAIMPLUNARYU64 pfnNormalU64, pfnLockedU64;
1660} IEMOPUNARYSIZES;
1661/** Pointer to a unary operator function table. */
1662typedef IEMOPUNARYSIZES const *PCIEMOPUNARYSIZES;
1663
1664
1665/**
1666 * Function table for a shift operator providing implementation based on
1667 * operand size.
1668 */
1669typedef struct IEMOPSHIFTSIZES
1670{
1671 PFNIEMAIMPLSHIFTU8 pfnNormalU8;
1672 PFNIEMAIMPLSHIFTU16 pfnNormalU16;
1673 PFNIEMAIMPLSHIFTU32 pfnNormalU32;
1674 PFNIEMAIMPLSHIFTU64 pfnNormalU64;
1675} IEMOPSHIFTSIZES;
1676/** Pointer to a shift operator function table. */
1677typedef IEMOPSHIFTSIZES const *PCIEMOPSHIFTSIZES;
1678
1679
1680/**
1681 * Function table for a multiplication or division operation.
1682 */
1683typedef struct IEMOPMULDIVSIZES
1684{
1685 PFNIEMAIMPLMULDIVU8 pfnU8;
1686 PFNIEMAIMPLMULDIVU16 pfnU16;
1687 PFNIEMAIMPLMULDIVU32 pfnU32;
1688 PFNIEMAIMPLMULDIVU64 pfnU64;
1689} IEMOPMULDIVSIZES;
1690/** Pointer to a multiplication or division operation function table. */
1691typedef IEMOPMULDIVSIZES const *PCIEMOPMULDIVSIZES;
1692
1693
1694/**
1695 * Function table for a double precision shift operator providing implementation
1696 * based on operand size.
1697 */
1698typedef struct IEMOPSHIFTDBLSIZES
1699{
1700 PFNIEMAIMPLSHIFTDBLU16 pfnNormalU16;
1701 PFNIEMAIMPLSHIFTDBLU32 pfnNormalU32;
1702 PFNIEMAIMPLSHIFTDBLU64 pfnNormalU64;
1703} IEMOPSHIFTDBLSIZES;
1704/** Pointer to a double precision shift function table. */
1705typedef IEMOPSHIFTDBLSIZES const *PCIEMOPSHIFTDBLSIZES;
1706
1707
1708/**
1709 * Function table for media instruction taking two full sized media registers,
1710 * optionally the 2nd being a memory reference (only modifying the first op.)
1711 */
1712typedef struct IEMOPMEDIAF2
1713{
1714 PFNIEMAIMPLMEDIAF2U64 pfnU64;
1715 PFNIEMAIMPLMEDIAF2U128 pfnU128;
1716} IEMOPMEDIAF2;
1717/** Pointer to a media operation function table for full sized ops. */
1718typedef IEMOPMEDIAF2 const *PCIEMOPMEDIAF2;
1719
1720/**
1721 * Function table for media instruction taking taking one full and one lower
1722 * half media register.
1723 */
1724typedef struct IEMOPMEDIAF1L1
1725{
1726 PFNIEMAIMPLMEDIAF1L1U64 pfnU64;
1727 PFNIEMAIMPLMEDIAF1L1U128 pfnU128;
1728} IEMOPMEDIAF1L1;
1729/** Pointer to a media operation function table for lowhalf+lowhalf -> full. */
1730typedef IEMOPMEDIAF1L1 const *PCIEMOPMEDIAF1L1;
1731
1732/**
1733 * Function table for media instruction taking taking one full and one high half
1734 * media register.
1735 */
1736typedef struct IEMOPMEDIAF1H1
1737{
1738 PFNIEMAIMPLMEDIAF1H1U64 pfnU64;
1739 PFNIEMAIMPLMEDIAF1H1U128 pfnU128;
1740} IEMOPMEDIAF1H1;
1741/** Pointer to a media operation function table for hihalf+hihalf -> full. */
1742typedef IEMOPMEDIAF1H1 const *PCIEMOPMEDIAF1H1;
1743
1744
1745/** @} */
1746
1747
1748/** @name C instruction implementations for anything slightly complicated.
1749 * @{ */
1750
1751/**
1752 * For typedef'ing or declaring a C instruction implementation function taking
1753 * no extra arguments.
1754 *
1755 * @param a_Name The name of the type.
1756 */
1757# define IEM_CIMPL_DECL_TYPE_0(a_Name) \
1758 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr))
1759/**
1760 * For defining a C instruction implementation function taking no extra
1761 * arguments.
1762 *
1763 * @param a_Name The name of the function
1764 */
1765# define IEM_CIMPL_DEF_0(a_Name) \
1766 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr))
1767/**
1768 * For calling a C instruction implementation function taking no extra
1769 * arguments.
1770 *
1771 * This special call macro adds default arguments to the call and allow us to
1772 * change these later.
1773 *
1774 * @param a_fn The name of the function.
1775 */
1776# define IEM_CIMPL_CALL_0(a_fn) a_fn(pVCpu, cbInstr)
1777
1778/**
1779 * For typedef'ing or declaring a C instruction implementation function taking
1780 * one extra argument.
1781 *
1782 * @param a_Name The name of the type.
1783 * @param a_Type0 The argument type.
1784 * @param a_Arg0 The argument name.
1785 */
1786# define IEM_CIMPL_DECL_TYPE_1(a_Name, a_Type0, a_Arg0) \
1787 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0))
1788/**
1789 * For defining a C instruction implementation function taking one extra
1790 * argument.
1791 *
1792 * @param a_Name The name of the function
1793 * @param a_Type0 The argument type.
1794 * @param a_Arg0 The argument name.
1795 */
1796# define IEM_CIMPL_DEF_1(a_Name, a_Type0, a_Arg0) \
1797 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0))
1798/**
1799 * For calling a C instruction implementation function taking one extra
1800 * argument.
1801 *
1802 * This special call macro adds default arguments to the call and allow us to
1803 * change these later.
1804 *
1805 * @param a_fn The name of the function.
1806 * @param a0 The name of the 1st argument.
1807 */
1808# define IEM_CIMPL_CALL_1(a_fn, a0) a_fn(pVCpu, cbInstr, (a0))
1809
1810/**
1811 * For typedef'ing or declaring a C instruction implementation function taking
1812 * two extra arguments.
1813 *
1814 * @param a_Name The name of the type.
1815 * @param a_Type0 The type of the 1st argument
1816 * @param a_Arg0 The name of the 1st argument.
1817 * @param a_Type1 The type of the 2nd argument.
1818 * @param a_Arg1 The name of the 2nd argument.
1819 */
1820# define IEM_CIMPL_DECL_TYPE_2(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1) \
1821 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1))
1822/**
1823 * For defining a C instruction implementation function taking two extra
1824 * arguments.
1825 *
1826 * @param a_Name The name of the function.
1827 * @param a_Type0 The type of the 1st argument
1828 * @param a_Arg0 The name of the 1st argument.
1829 * @param a_Type1 The type of the 2nd argument.
1830 * @param a_Arg1 The name of the 2nd argument.
1831 */
1832# define IEM_CIMPL_DEF_2(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1) \
1833 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1))
1834/**
1835 * For calling a C instruction implementation function taking two extra
1836 * arguments.
1837 *
1838 * This special call macro adds default arguments to the call and allow us to
1839 * change these later.
1840 *
1841 * @param a_fn The name of the function.
1842 * @param a0 The name of the 1st argument.
1843 * @param a1 The name of the 2nd argument.
1844 */
1845# define IEM_CIMPL_CALL_2(a_fn, a0, a1) a_fn(pVCpu, cbInstr, (a0), (a1))
1846
1847/**
1848 * For typedef'ing or declaring a C instruction implementation function taking
1849 * three extra arguments.
1850 *
1851 * @param a_Name The name of the type.
1852 * @param a_Type0 The type of the 1st argument
1853 * @param a_Arg0 The name of the 1st argument.
1854 * @param a_Type1 The type of the 2nd argument.
1855 * @param a_Arg1 The name of the 2nd argument.
1856 * @param a_Type2 The type of the 3rd argument.
1857 * @param a_Arg2 The name of the 3rd argument.
1858 */
1859# define IEM_CIMPL_DECL_TYPE_3(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2) \
1860 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1, a_Type2 a_Arg2))
1861/**
1862 * For defining a C instruction implementation function taking three extra
1863 * arguments.
1864 *
1865 * @param a_Name The name of the function.
1866 * @param a_Type0 The type of the 1st argument
1867 * @param a_Arg0 The name of the 1st argument.
1868 * @param a_Type1 The type of the 2nd argument.
1869 * @param a_Arg1 The name of the 2nd argument.
1870 * @param a_Type2 The type of the 3rd argument.
1871 * @param a_Arg2 The name of the 3rd argument.
1872 */
1873# define IEM_CIMPL_DEF_3(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2) \
1874 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1, a_Type2 a_Arg2))
1875/**
1876 * For calling a C instruction implementation function taking three extra
1877 * arguments.
1878 *
1879 * This special call macro adds default arguments to the call and allow us to
1880 * change these later.
1881 *
1882 * @param a_fn The name of the function.
1883 * @param a0 The name of the 1st argument.
1884 * @param a1 The name of the 2nd argument.
1885 * @param a2 The name of the 3rd argument.
1886 */
1887# define IEM_CIMPL_CALL_3(a_fn, a0, a1, a2) a_fn(pVCpu, cbInstr, (a0), (a1), (a2))
1888
1889
1890/**
1891 * For typedef'ing or declaring a C instruction implementation function taking
1892 * four extra arguments.
1893 *
1894 * @param a_Name The name of the type.
1895 * @param a_Type0 The type of the 1st argument
1896 * @param a_Arg0 The name of the 1st argument.
1897 * @param a_Type1 The type of the 2nd argument.
1898 * @param a_Arg1 The name of the 2nd argument.
1899 * @param a_Type2 The type of the 3rd argument.
1900 * @param a_Arg2 The name of the 3rd argument.
1901 * @param a_Type3 The type of the 4th argument.
1902 * @param a_Arg3 The name of the 4th argument.
1903 */
1904# define IEM_CIMPL_DECL_TYPE_4(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2, a_Type3, a_Arg3) \
1905 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1, a_Type2 a_Arg2, a_Type3 a_Arg3))
1906/**
1907 * For defining a C instruction implementation function taking four extra
1908 * arguments.
1909 *
1910 * @param a_Name The name of the function.
1911 * @param a_Type0 The type of the 1st argument
1912 * @param a_Arg0 The name of the 1st argument.
1913 * @param a_Type1 The type of the 2nd argument.
1914 * @param a_Arg1 The name of the 2nd argument.
1915 * @param a_Type2 The type of the 3rd argument.
1916 * @param a_Arg2 The name of the 3rd argument.
1917 * @param a_Type3 The type of the 4th argument.
1918 * @param a_Arg3 The name of the 4th argument.
1919 */
1920# define IEM_CIMPL_DEF_4(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2, a_Type3, a_Arg3) \
1921 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, a_Type0 a_Arg0, a_Type1 a_Arg1, \
1922 a_Type2 a_Arg2, a_Type3 a_Arg3))
1923/**
1924 * For calling a C instruction implementation function taking four extra
1925 * arguments.
1926 *
1927 * This special call macro adds default arguments to the call and allow us to
1928 * change these later.
1929 *
1930 * @param a_fn The name of the function.
1931 * @param a0 The name of the 1st argument.
1932 * @param a1 The name of the 2nd argument.
1933 * @param a2 The name of the 3rd argument.
1934 * @param a3 The name of the 4th argument.
1935 */
1936# define IEM_CIMPL_CALL_4(a_fn, a0, a1, a2, a3) a_fn(pVCpu, cbInstr, (a0), (a1), (a2), (a3))
1937
1938
1939/**
1940 * For typedef'ing or declaring a C instruction implementation function taking
1941 * five extra arguments.
1942 *
1943 * @param a_Name The name of the type.
1944 * @param a_Type0 The type of the 1st argument
1945 * @param a_Arg0 The name of the 1st argument.
1946 * @param a_Type1 The type of the 2nd argument.
1947 * @param a_Arg1 The name of the 2nd argument.
1948 * @param a_Type2 The type of the 3rd argument.
1949 * @param a_Arg2 The name of the 3rd argument.
1950 * @param a_Type3 The type of the 4th argument.
1951 * @param a_Arg3 The name of the 4th argument.
1952 * @param a_Type4 The type of the 5th argument.
1953 * @param a_Arg4 The name of the 5th argument.
1954 */
1955# define IEM_CIMPL_DECL_TYPE_5(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2, a_Type3, a_Arg3, a_Type4, a_Arg4) \
1956 IEM_DECL_IMPL_TYPE(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, \
1957 a_Type0 a_Arg0, a_Type1 a_Arg1, a_Type2 a_Arg2, \
1958 a_Type3 a_Arg3, a_Type4 a_Arg4))
1959/**
1960 * For defining a C instruction implementation function taking five extra
1961 * arguments.
1962 *
1963 * @param a_Name The name of the function.
1964 * @param a_Type0 The type of the 1st argument
1965 * @param a_Arg0 The name of the 1st argument.
1966 * @param a_Type1 The type of the 2nd argument.
1967 * @param a_Arg1 The name of the 2nd argument.
1968 * @param a_Type2 The type of the 3rd argument.
1969 * @param a_Arg2 The name of the 3rd argument.
1970 * @param a_Type3 The type of the 4th argument.
1971 * @param a_Arg3 The name of the 4th argument.
1972 * @param a_Type4 The type of the 5th argument.
1973 * @param a_Arg4 The name of the 5th argument.
1974 */
1975# define IEM_CIMPL_DEF_5(a_Name, a_Type0, a_Arg0, a_Type1, a_Arg1, a_Type2, a_Arg2, a_Type3, a_Arg3, a_Type4, a_Arg4) \
1976 IEM_DECL_IMPL_DEF(VBOXSTRICTRC, a_Name, (PVMCPU pVCpu, uint8_t cbInstr, \
1977 a_Type0 a_Arg0, a_Type1 a_Arg1, a_Type2 a_Arg2, \
1978 a_Type3 a_Arg3, a_Type4 a_Arg4))
1979/**
1980 * For calling a C instruction implementation function taking five extra
1981 * arguments.
1982 *
1983 * This special call macro adds default arguments to the call and allow us to
1984 * change these later.
1985 *
1986 * @param a_fn The name of the function.
1987 * @param a0 The name of the 1st argument.
1988 * @param a1 The name of the 2nd argument.
1989 * @param a2 The name of the 3rd argument.
1990 * @param a3 The name of the 4th argument.
1991 * @param a4 The name of the 5th argument.
1992 */
1993# define IEM_CIMPL_CALL_5(a_fn, a0, a1, a2, a3, a4) a_fn(pVCpu, cbInstr, (a0), (a1), (a2), (a3), (a4))
1994
1995/** @} */
1996
1997
1998/** @} */
1999
2000RT_C_DECLS_END
2001
2002#endif
2003
Note: See TracBrowser for help on using the repository browser.

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