VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/cpu/cidet.h@ 71214

Last change on this file since 71214 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.0 KB
Line 
1/* $Id: cidet.h 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * CPU Instruction Decoding & Execution Tests - C/C++ Header.
4 */
5
6/*
7 * Copyright (C) 2014-2017 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28#ifndef ___cidet_h___
29#define ___cidet_h___
30
31#include <iprt/types.h>
32#include <iprt/x86.h>
33
34
35/** @name CIDET - Operand flags.
36 * @{ */
37#define CIDET_OF_FIXED_MASK UINT32_C(0x0000001f) /**< Fixed register/whatever mask. */
38
39#define CIDET_OF_Z_SHIFT 8 /**< Size shift. */
40#define CIDET_OF_Z_MASK UINT32_C(0x00000f00) /**< Size mask. */
41#define CIDET_OF_Z_NONE UINT32_C(0x00000000) /**< Unused zero value. */
42#define CIDET_OF_Z_BYTE UINT32_C(0x00000100) /**< Byte size. */
43#define CIDET_OF_Z_WORD UINT32_C(0x00000200) /**< Word (2 bytes) size. */
44#define CIDET_OF_Z_DWORD UINT32_C(0x00000300) /**< Double word (4 bytes) size. */
45#define CIDET_OF_Z_QWORD UINT32_C(0x00000400) /**< Quad word (8 bytes) size. */
46#define CIDET_OF_Z_TBYTE UINT32_C(0x00000500) /**< Ten byte (10 bytes) size - aka TWORD. */
47#define CIDET_OF_Z_OWORD UINT32_C(0x00000600) /**< Octa word (16 bytes) size - aka DQWORD. */
48#define CIDET_OF_Z_YWORD UINT32_C(0x00000700) /**< Yxx sized, i.e. 32 bytes. */
49#define CIDET_OF_Z_ZWORD UINT32_C(0x00000800) /**< Zxx sized, i.e. 64 bytes. */
50#define CIDET_OF_Z_VAR_WDQ UINT32_C(0x00000900) /**< Variable size depending on size prefix (2, 4, or 8 bytes). */
51#define CIDET_OF_Z_SPECIAL UINT32_C(0x00000f00) /**< Special size, see instruction flags or smth. */
52
53#define CIDET_OF_K_MASK UINT32_C(0x0000f000) /**< Kind of operand. */
54#define CIDET_OF_K_NONE UINT32_C(0x00000000) /**< Unused zero value. */
55#define CIDET_OF_K_GPR UINT32_C(0x00001000) /**< General purpose register. Includes memory when used with CIDET_OF_M_RM. */
56#define CIDET_OF_K_SREG UINT32_C(0x00002000) /**< Segment register. */
57#define CIDET_OF_K_CR UINT32_C(0x00003000) /**< Control register. */
58#define CIDET_OF_K_SSE UINT32_C(0x00004000) /**< SSE register. */
59#define CIDET_OF_K_AVX UINT32_C(0x00005000) /**< AVX register. */
60#define CIDET_OF_K_AVX512 UINT32_C(0x00006000) /**< AVX-512 register. */
61#define CIDET_OF_K_AVXFUTURE UINT32_C(0x00007000) /**< Reserved for future AVX register set. */
62#define CIDET_OF_K_VRX_TST_MASK UINT32_C(0x0000c000) /**< Used for testing for VRX register kind, see CIDET_OF_K_IS_VRX. */
63#define CIDET_OF_K_VRX_TST_RES UINT32_C(0x00004000) /**< Used for testing for VRX register kind, see CIDET_OF_K_IS_VRX. */
64#define CIDET_OF_K_FPU UINT32_C(0x00008000) /**< FPU register. */
65#define CIDET_OF_K_MMX UINT32_C(0x00009000) /**< MMX register. */
66#define CIDET_OF_K_TEST UINT32_C(0x0000a000) /**< Test register. */
67#define CIDET_OF_K_IMM UINT32_C(0x0000d000) /**< Immediate. */
68#define CIDET_OF_K_MEM UINT32_C(0x0000e000) /**< Memory. */
69#define CIDET_OF_K_SPECIAL UINT32_C(0x0000f000) /**< Special. */
70/** Check if @a a_fOp is a general purpose register. */
71#define CIDET_OF_K_IS_GPR(a_fOp) ( ((a_fOp) & CIDET_OF_K_MASK) == CIDET_OF_K_GPR )
72/** Check if @a a_fOp is a XMM (SSE), YMM (AVX), ZMM (AVX-512) or similar register. */
73#define CIDET_OF_K_IS_VRX(a_fOp) ( ((a_fOp) & CIDET_OF_K_VRX_TST_MASK) == CIDET_OF_K_VRX_TST_RES )
74/** Check if @a a_fOp1 and @a a_fOp2 specify the same kind of register,
75 * treating SSE, AVX, AVX-512 and AVX-future as the same kind and ignoring the
76 * special register kind. */
77#define CIDET_OF_K_IS_SAME(a_fOp1, a_fOp2) \
78 ( ((a_fOp1) & CIDET_OF_K_MASK) == ((a_fOp2) & CIDET_OF_K_MASK) \
79 ? ((a_fOp1) & CIDET_OF_K_MASK) != CIDET_OF_K_SPECIAL \
80 : (CIDET_OF_K_IS_VRX(a_fOp1) && CIDET_OF_K_IS_VRX(a_fOp2)) )
81
82#define CIDET_OF_M_RM_ONLY_R UINT32_C(0x00010000)
83#define CIDET_OF_M_RM_ONLY_M UINT32_C(0x00020000)
84#define CIDET_OF_M_RM (CIDET_OF_M_RM_ONLY_R | CIDET_OF_M_RM_ONLY_M)
85#define CIDET_OF_M_REG UINT32_C(0x00040000)
86
87#define CIDET_OF_A_R UINT32_C(0x00080000) /**< Read access. */
88#define CIDET_OF_A_W UINT32_C(0x00100000) /**< Write access. */
89#define CIDET_OF_A_RW UINT32_C(0x00180000) /**< Read & write access. */
90
91/** The operand defaults to 64-bit width in 64-bit mode, making 32-bit width
92 * inaccessible. */
93#define CIDET_OF_DEFAULT_64BIT UINT32_C(0x40000000)
94/** Operand always uses the ES segment for memory accesses. */
95#define CIDET_OF_ALWAYS_SEG_ES UINT32_C(0x80000000)
96/** @} */
97
98
99/** @name CIDET - Instruction flags.
100 * @{ */
101#define CIDET_IF_MODRM RT_BIT_64(0) /**< ModR/M encoded. */
102#define CIDET_IF_PRIVILEGED RT_BIT_64(1) /**< Privileged. */
103/** @} */
104
105
106/**
107 * Callback function for setting up the input and expected output CPU contexts.
108 *
109 * @returns VBox status code.
110 * @retval VINF_EOF when static test data wraps (first entry is returned).
111 * @retval VERR_NO_DATA if @a fInvalid is set and there are no invalid operand
112 * values for this instruction.
113 * @retval VERR_NOT_SUPPORTED if something in the setup prevents us from
114 * comming up with working set of inputs and outputs.
115 *
116 * @param pThis The core CIDET state structure. The InCtx
117 * and ExpectedCtx members will be modified.
118 * @param fInvalid When set, get the next invalid operands that will
119 * cause exceptions/faults.
120 */
121typedef DECLCALLBACK(int) FNCIDETSETUPINOUT(struct CIDETCORE *pThis, bool fInvalid);
122/** Pointer to a FNCIDETSETUPINOUT function. */
123typedef FNCIDETSETUPINOUT *PFNCIDETSETUPINOUT;
124
125
126/**
127 * Instruction test descriptor.
128 */
129typedef struct CIDETINSTR
130{
131 /** The mnemonic (kind of). */
132 const char *pszMnemonic;
133 /** Setup input and outputs. */
134 PFNCIDETSETUPINOUT pfnSetupInOut;
135 /** Number of opcode bytes. */
136 uint8_t cbOpcode;
137 /** Opcode byte(s). */
138 uint8_t abOpcode[3];
139 /** Mandatory prefix (zero if not applicable). */
140 uint8_t bMandatoryPrefix;
141 /** Number of operands. */
142 uint8_t cOperands;
143 /** Operand flags. */
144 uint32_t afOperands[4];
145 /** Flags. */
146 uint64_t fFlags;
147} CIDETINSTR;
148/** Pointer to an instruction test descriptor. */
149typedef CIDETINSTR const *PCCIDETINSTR;
150
151
152/**
153 * CPU Context with a few extra bits for expectations and results.
154 */
155typedef struct CIDETCPUCTX
156{
157 uint64_t rip;
158 uint64_t rfl;
159 uint64_t aGRegs[16];
160 uint16_t aSRegs[6];
161
162#ifndef CIDET_REDUCED_CTX
163 uint16_t tr;
164 uint16_t ldtr;
165 uint64_t cr0;
166#else
167 uint16_t au16Padding[2];
168#endif
169 uint64_t cr2;
170#ifndef CIDET_REDUCED_CTX
171 uint64_t cr3;
172 uint64_t cr4;
173 uint64_t cr8;
174 uint64_t dr0;
175 uint64_t dr1;
176 uint64_t dr2;
177 uint64_t dr3;
178 uint64_t dr6;
179 uint64_t dr7;
180#endif
181
182 uint64_t uErr; /**< Exception error code. UINT64_MAX if not applicable. (Not for input context.) */
183 uint32_t uXcpt; /**< Exception number. UINT32_MAX if no exception. (Not for input context.) */
184
185 uint32_t fIgnoredRFlags; /**< Only for expected result. */
186 bool fTrickyStack; /**< Set if the stack might be bad. May come at the cost of accurate flags (32-bit). */
187} CIDETCPUCTX;
188typedef CIDETCPUCTX *PCIDETCPUCTX;
189typedef CIDETCPUCTX const *PCCIDETCPUCTX;
190
191/** Number of bytes of CIDETCPUCTX that can be compared quickly using memcmp.
192 * Anything following these bytes are not relevant to the compare. */
193#define CIDETCPUCTX_COMPARE_SIZE RT_UOFFSETOF(CIDETCPUCTX, fIgnoredRFlags)
194
195
196/** @name CPU mode + bits + environment.
197 * @{ */
198#define CIDETMODE_BIT_MASK UINT8_C(0x0e) /**< The instruction bit count. Results in byte size when masked. */
199#define CIDETMODE_BIT_16 UINT8_C(0x02) /**< 16-bit instructions. */
200#define CIDETMODE_BIT_32 UINT8_C(0x04) /**< 32-bit instructions. */
201#define CIDETMODE_BIT_64 UINT8_C(0x08) /**< 64-bit instructions. */
202#define CIDETMODE_MODE_MASK UINT8_C(0x70) /**< CPU mode mask. */
203#define CIDETMODE_MODE_RM UINT8_C(0x00) /**< Real mode. */
204#define CIDETMODE_MODE_PE UINT8_C(0x10) /**< Protected mode without paging. */
205#define CIDETMODE_MODE_PP UINT8_C(0x20) /**< Paged protected mode. */
206#define CIDETMODE_MODE_PAE UINT8_C(0x30) /**< PAE protected mode (paged). */
207#define CIDETMODE_MODE_LM UINT8_C(0x40) /**< Long mode (paged). */
208#define CIDETMODE_ENV_MASK UINT8_C(0x81) /**< Execution environment. */
209#define CIDETMODE_ENV_NORMAL UINT8_C(0x01) /**< Normal environment. */
210#define CIDETMODE_ENV_V86 UINT8_C(0x80) /**< V8086 environment. */
211#define CIDETMODE_RM (CIDETMODE_MODE_RM | CIDETMODE_BIT_16 | CIDETMODE_ENV_NORMAL)
212#define CIDETMODE_PE_16 (CIDETMODE_MODE_PE | CIDETMODE_BIT_16 | CIDETMODE_ENV_NORMAL)
213#define CIDETMODE_PE_32 (CIDETMODE_MODE_PE | CIDETMODE_BIT_32 | CIDETMODE_ENV_NORMAL)
214#define CIDETMODE_PE_V86 (CIDETMODE_MODE_PE | CIDETMODE_BIT_16 | CIDETMODE_ENV_V86)
215#define CIDETMODE_PP_16 (CIDETMODE_MODE_PP | CIDETMODE_BIT_16 | CIDETMODE_ENV_NORMAL)
216#define CIDETMODE_PP_32 (CIDETMODE_MODE_PP | CIDETMODE_BIT_32 | CIDETMODE_ENV_NORMAL)
217#define CIDETMODE_PP_V86 (CIDETMODE_MODE_PP | CIDETMODE_BIT_16 | CIDETMODE_ENV_V86)
218#define CIDETMODE_PAE_16 (CIDETMODE_MODE_PAE | CIDETMODE_BIT_16 | CIDETMODE_ENV_NORMAL)
219#define CIDETMODE_PAE_32 (CIDETMODE_MODE_PAE | CIDETMODE_BIT_32 | CIDETMODE_ENV_NORMAL)
220#define CIDETMODE_PAE_V86 (CIDETMODE_MODE_PAE | CIDETMODE_BIT_16 | CIDETMODE_ENV_V86)
221#define CIDETMODE_LM_16 (CIDETMODE_MODE_LM | CIDETMODE_BIT_16 | CIDETMODE_ENV_NORMAL)
222#define CIDETMODE_LM_32 (CIDETMODE_MODE_LM | CIDETMODE_BIT_32 | CIDETMODE_ENV_NORMAL)
223#define CIDETMODE_LM_64 (CIDETMODE_MODE_LM | CIDETMODE_BIT_64 | CIDETMODE_ENV_NORMAL)
224/** Test if @a a_bMode is a 16-bit mode. */
225#define CIDETMODE_IS_16BIT(a_bMode) ( ((a_bMode) & CIDETMODE_BIT_MASK) == CIDETMODE_BIT_16 )
226/** Test if @a a_bMode is a 32-bit mode. */
227#define CIDETMODE_IS_32BIT(a_bMode) ( ((a_bMode) & CIDETMODE_BIT_MASK) == CIDETMODE_BIT_32 )
228/** Test if @a a_bMode is a 64-bit mode. */
229#define CIDETMODE_IS_64BIT(a_bMode) ( ((a_bMode) & CIDETMODE_BIT_MASK) == CIDETMODE_BIT_64 )
230/** Get the instruction bit count. */
231#define CIDETMODE_GET_BIT_COUNT(a_bMode) ( CIDETMODE_GET_BYTE_COUNT(a_bMode) * 8 )
232/** Get the instruction byte count. */
233#define CIDETMODE_GET_BYTE_COUNT(a_bMode) ( (a_bMode) & CIDETMODE_BIT_MASK )
234/** Test if @a a_bMode long mode. */
235#define CIDETMODE_IS_LM(a_bMode) ( ((a_bMode) & CIDETMODE_MODE_MASK) == CIDETMODE_MODE_LM )
236/** Test if @a a_bMode some kind of protected mode. */
237#define CIDETMODE_IS_PROT(a_bMode) ( ((a_bMode) & CIDETMODE_MODE_MASK) >= CIDETMODE_MODE_PE )
238
239/** @} */
240
241
242/** @name Test Configuration Flags.
243 * @{ */
244#define CIDET_TESTCFG_SEG_PRF_CS UINT64_C(0x0000000000000001)
245#define CIDET_TESTCFG_SEG_PRF_SS UINT64_C(0x0000000000000002)
246#define CIDET_TESTCFG_SEG_PRF_DS UINT64_C(0x0000000000000004)
247#define CIDET_TESTCFG_SEG_PRF_ES UINT64_C(0x0000000000000008)
248#define CIDET_TESTCFG_SEG_PRF_FS UINT64_C(0x0000000000000010)
249#define CIDET_TESTCFG_SEG_PRF_GS UINT64_C(0x0000000000000020)
250#define CIDET_TESTCFG_SEG_PRF_MASK UINT64_C(0x000000000000003f)
251/** @} */
252
253/** */
254typedef enum CIDETREG
255{
256 kCidetReg_Gpr_Invalid = 0,
257
258 kCidetReg_Gpr_al,
259 kCidetReg_Gpr_cl,
260 kCidetReg_Gpr_dl,
261 kCidetReg_Gpr_bl,
262 kCidetReg_Gpr_spl,
263 kCidetReg_Gpr_bpl,
264 kCidetReg_Gpr_sil,
265 kCidetReg_Gpr_dil,
266 kCidetReg_Gpr_r8b,
267 kCidetReg_Gpr_r9b,
268 kCidetReg_Gpr_r10b,
269 kCidetReg_Gpr_r11b,
270 kCidetReg_Gpr_r12b,
271 kCidetReg_Gpr_r13b,
272 kCidetReg_Gpr_r14b,
273 kCidetReg_Gpr_r15b,
274 kCidetReg_Gpr_ah,
275 kCidetReg_Gpr_ch,
276 kCidetReg_Gpr_dh,
277 kCidetReg_Gpr_bh,
278#define kCidetReg_Gpr_Byte_First kCidetReg_Gpr_al
279#define kCidetReg_Gpr_Byte_First_Upper kCidetReg_Gpr_ah
280#define kCidetReg_Gpr_Byte_Last kCidetReg_Gpr_bh
281
282 kCidetReg_Gpr_ax,
283 kCidetReg_Gpr_cx,
284 kCidetReg_Gpr_dx,
285 kCidetReg_Gpr_bx,
286 kCidetReg_Gpr_sp,
287 kCidetReg_Gpr_bp,
288 kCidetReg_Gpr_si,
289 kCidetReg_Gpr_di,
290 kCidetReg_Gpr_r8w,
291 kCidetReg_Gpr_r9w,
292 kCidetReg_Gpr_r10w,
293 kCidetReg_Gpr_r11w,
294 kCidetReg_Gpr_r12w,
295 kCidetReg_Gpr_r13w,
296 kCidetReg_Gpr_r14w,
297 kCidetReg_Gpr_r15w,
298#define kCidetReg_Gpr_Word_First kCidetReg_Gpr_ax
299#define kCidetReg_Gpr_Word_Last kCidetReg_Gpr_r15w
300
301 kCidetReg_Gpr_eax,
302 kCidetReg_Gpr_ecx,
303 kCidetReg_Gpr_edx,
304 kCidetReg_Gpr_ebx,
305 kCidetReg_Gpr_esp,
306 kCidetReg_Gpr_ebp,
307 kCidetReg_Gpr_esi,
308 kCidetReg_Gpr_edi,
309 kCidetReg_Gpr_r8d,
310 kCidetReg_Gpr_r9d,
311 kCidetReg_Gpr_r10d,
312 kCidetReg_Gpr_r11d,
313 kCidetReg_Gpr_r12d,
314 kCidetReg_Gpr_r13d,
315 kCidetReg_Gpr_r14d,
316 kCidetReg_Gpr_r15d,
317#define kCidetReg_Gpr_DWord_First kCidetReg_Gpr_eax
318#define kCidetReg_Gpr_DWord_Last kCidetReg_Gpr_r15d
319
320 kCidetReg_Gpr_rax,
321 kCidetReg_Gpr_rcx,
322 kCidetReg_Gpr_rdx,
323 kCidetReg_Gpr_rbx,
324 kCidetReg_Gpr_rsp,
325 kCidetReg_Gpr_rbp,
326 kCidetReg_Gpr_rsi,
327 kCidetReg_Gpr_rdi,
328 kCidetReg_Gpr_r8,
329 kCidetReg_Gpr_r9,
330 kCidetReg_Gpr_r10,
331 kCidetReg_Gpr_r11,
332 kCidetReg_Gpr_r12,
333 kCidetReg_Gpr_r13,
334 kCidetReg_Gpr_r14,
335 kCidetReg_Gpr_r15,
336#define kCidetReg_Gpr_QWord_First kCidetReg_Gpr_rax
337#define kCidetReg_Gpr_QWord_Last kCidetReg_Gpr_r15
338
339 kCidetReg_Seg_es,
340 kCidetReg_Seg_cs,
341 kCidetReg_Seg_ss,
342 kCidetReg_Seg_ds,
343 kCidetReg_Seg_fs,
344 kCidetReg_Seg_gs,
345 kCidetReg_Seg_Inv6,
346 kCidetReg_Seg_Inv7,
347#define kCidetReg_Seg_First kCidetReg_Seg_es
348#define kCidetReg_Seg_Last kCidetReg_Seg_gs
349#define kCidetReg_Seg_Last_Inv kCidetReg_Seg_Inv7
350
351 kCidetReg_Misc_ip,
352 kCidetReg_Misc_eip,
353 kCidetReg_Misc_rip,
354 kCidetReg_Misc_flags,
355 kCidetReg_Misc_eflags,
356 kCidetReg_Misc_rflags,
357 kCidetReg_Misc_tr,
358 kCidetReg_Misc_ldtr,
359 kCidetReg_Misc_gdtr,
360 kCidetReg_Misc_idtr,
361
362 kCidetReg_Ctrl_cr0,
363 kCidetReg_Ctrl_cr1,
364 kCidetReg_Ctrl_cr2,
365 kCidetReg_Ctrl_cr3,
366 kCidetReg_Ctrl_cr4,
367 kCidetReg_Ctrl_cr5,
368 kCidetReg_Ctrl_cr6,
369 kCidetReg_Ctrl_cr7,
370 kCidetReg_Ctrl_cr8,
371 kCidetReg_Ctrl_cr9,
372 kCidetReg_Ctrl_cr10,
373 kCidetReg_Ctrl_cr11,
374 kCidetReg_Ctrl_cr12,
375 kCidetReg_Ctrl_cr13,
376 kCidetReg_Ctrl_cr14,
377 kCidetReg_Ctrl_cr15,
378#define kCidetReg_Ctrl_First kCidetReg_Ctrl_cr0
379#define kCidetReg_Ctrl_Last kCidetReg_Ctrl_cr15
380#define CIDETREG_CTRL_IS_VALID(a_iReg) ( (a_iReg) == kCidetReg_Ctrl_cr0 \
381 && (a_iReg) == kCidetReg_Ctrl_cr2 \
382 && (a_iReg) == kCidetReg_Ctrl_cr3 \
383 && (a_iReg) == kCidetReg_Ctrl_cr4 \
384 && (a_iReg) == kCidetReg_Ctrl_cr8 )
385
386 kCidetReg_Dbg_dr0,
387 kCidetReg_Dbg_dr1,
388 kCidetReg_Dbg_dr2,
389 kCidetReg_Dbg_dr3,
390 kCidetReg_Dbg_dr4,
391 kCidetReg_Dbg_dr5,
392 kCidetReg_Dbg_dr6,
393 kCidetReg_Dbg_dr7,
394 kCidetReg_Dbg_dr8,
395 kCidetReg_Dbg_dr9,
396 kCidetReg_Dbg_dr10,
397 kCidetReg_Dbg_dr11,
398 kCidetReg_Dbg_dr12,
399 kCidetReg_Dbg_dr13,
400 kCidetReg_Dbg_dr14,
401 kCidetReg_Dbg_dr15,
402#define kCidetReg_Dbg_First kCidetReg_Dbg_dr0
403#define kCidetReg_Dbg_Last kCidetReg_Dbg_dr15
404#define CIDETREG_DBG_IS_VALID(a_iReg) ((a_iReg) < kCidetReg_Dbg_dr8 && (a_iReg) >= kCidetReg_Dbg_First)
405
406 kCidetReg_Test_tr0,
407 kCidetReg_Test_tr1,
408 kCidetReg_Test_tr2,
409 kCidetReg_Test_tr3,
410 kCidetReg_Test_tr4,
411 kCidetReg_Test_tr5,
412 kCidetReg_Test_tr6,
413 kCidetReg_Test_tr7,
414 kCidetReg_Test_tr8,
415 kCidetReg_Test_tr9,
416 kCidetReg_Test_tr10,
417 kCidetReg_Test_tr11,
418 kCidetReg_Test_tr12,
419 kCidetReg_Test_tr13,
420 kCidetReg_Test_tr14,
421 kCidetReg_Test_tr15,
422#define kCidetReg_Test_First kCidetReg_Test_tr0
423#define kCidetReg_Test_Last kCidetReg_Test_tr15
424
425 kCidetReg_Fpu_st0,
426 kCidetReg_Fpu_st1,
427 kCidetReg_Fpu_st2,
428 kCidetReg_Fpu_st3,
429 kCidetReg_Fpu_st4,
430 kCidetReg_Fpu_st5,
431 kCidetReg_Fpu_st6,
432 kCidetReg_Fpu_st7,
433#define kCidetReg_Fpu_First kCidetReg_Mmx_st0
434#define kCidetReg_Fpu_Last kCidetReg_Mmx_st7
435
436 kCidetReg_FpuMisc_cs,
437 kCidetReg_FpuMisc_ip,
438 kCidetReg_FpuMisc_ds,
439 kCidetReg_FpuMisc_dp,
440 kCidetReg_FpuMisc_fop,
441 kCidetReg_FpuMisc_ftw,
442 kCidetReg_FpuMisc_fsw,
443 kCidetReg_FpuMisc_fcw,
444 kCidetReg_FpuMisc_mxcsr_mask,
445 kCidetReg_FpuMisc_mxcsr,
446
447 kCidetReg_Mmx_mm0,
448 kCidetReg_Mmx_mm1,
449 kCidetReg_Mmx_mm2,
450 kCidetReg_Mmx_mm3,
451 kCidetReg_Mmx_mm4,
452 kCidetReg_Mmx_mm5,
453 kCidetReg_Mmx_mm6,
454 kCidetReg_Mmx_mm7,
455#define kCidetReg_Mmx_First kCidetReg_Mmx_mm0
456#define kCidetReg_Mmx_Last kCidetReg_Mmx_mm7
457
458 kCidetReg_Sse_xmm0,
459 kCidetReg_Sse_xmm1,
460 kCidetReg_Sse_xmm2,
461 kCidetReg_Sse_xmm3,
462 kCidetReg_Sse_xmm4,
463 kCidetReg_Sse_xmm5,
464 kCidetReg_Sse_xmm6,
465 kCidetReg_Sse_xmm7,
466 kCidetReg_Sse_xmm8,
467 kCidetReg_Sse_xmm9,
468 kCidetReg_Sse_xmm10,
469 kCidetReg_Sse_xmm11,
470 kCidetReg_Sse_xmm12,
471 kCidetReg_Sse_xmm13,
472 kCidetReg_Sse_xmm14,
473 kCidetReg_Sse_xmm15,
474 kCidetReg_Sse_xmm16,
475 kCidetReg_Sse_xmm17,
476 kCidetReg_Sse_xmm18,
477 kCidetReg_Sse_xmm19,
478 kCidetReg_Sse_xmm20,
479 kCidetReg_Sse_xmm21,
480 kCidetReg_Sse_xmm22,
481 kCidetReg_Sse_xmm23,
482 kCidetReg_Sse_xmm24,
483 kCidetReg_Sse_xmm25,
484 kCidetReg_Sse_xmm26,
485 kCidetReg_Sse_xmm27,
486 kCidetReg_Sse_xmm28,
487 kCidetReg_Sse_xmm29,
488 kCidetReg_Sse_xmm30,
489 kCidetReg_Sse_xmm31,
490#define kCidetReg_Sse_First kCidetReg_Mmx_Xmm0
491#define kCidetReg_Sse_Last kCidetReg_Mmx_Xmm15
492#define kCidetReg_Sse_Last_Avx512 kCidetReg_Mmx_Xmm31
493
494 kCidetReg_Avx_Ymm0,
495 kCidetReg_Avx_Ymm1,
496 kCidetReg_Avx_Ymm2,
497 kCidetReg_Avx_Ymm3,
498 kCidetReg_Avx_Ymm4,
499 kCidetReg_Avx_Ymm5,
500 kCidetReg_Avx_Ymm6,
501 kCidetReg_Avx_Ymm7,
502 kCidetReg_Avx_Ymm8,
503 kCidetReg_Avx_Ymm9,
504 kCidetReg_Avx_Ymm10,
505 kCidetReg_Avx_Ymm11,
506 kCidetReg_Avx_Ymm12,
507 kCidetReg_Avx_Ymm13,
508 kCidetReg_Avx_Ymm14,
509 kCidetReg_Avx_Ymm15,
510 kCidetReg_Avx_Ymm16,
511 kCidetReg_Avx_Ymm17,
512 kCidetReg_Avx_Ymm18,
513 kCidetReg_Avx_Ymm19,
514 kCidetReg_Avx_Ymm20,
515 kCidetReg_Avx_Ymm21,
516 kCidetReg_Avx_Ymm22,
517 kCidetReg_Avx_Ymm23,
518 kCidetReg_Avx_Ymm24,
519 kCidetReg_Avx_Ymm25,
520 kCidetReg_Avx_Ymm26,
521 kCidetReg_Avx_Ymm27,
522 kCidetReg_Avx_Ymm28,
523 kCidetReg_Avx_Ymm29,
524 kCidetReg_Avx_Ymm30,
525 kCidetReg_Avx_Ymm31,
526#define kCidetReg_Avx_First kCidetReg_Avx_Ymm0
527#define kCidetReg_Avx_Last kCidetReg_Avx_Ymm15
528#define kCidetReg_Avx_Last_Avx512 kCidetReg_Avx_Ymm31
529
530 kCidetReg_Avx512_Zmm0,
531 kCidetReg_Avx512_Zmm1,
532 kCidetReg_Avx512_Zmm2,
533 kCidetReg_Avx512_Zmm3,
534 kCidetReg_Avx512_Zmm4,
535 kCidetReg_Avx512_Zmm5,
536 kCidetReg_Avx512_Zmm6,
537 kCidetReg_Avx512_Zmm7,
538 kCidetReg_Avx512_Zmm8,
539 kCidetReg_Avx512_Zmm9,
540 kCidetReg_Avx512_Zmm10,
541 kCidetReg_Avx512_Zmm11,
542 kCidetReg_Avx512_Zmm12,
543 kCidetReg_Avx512_Zmm13,
544 kCidetReg_Avx512_Zmm14,
545 kCidetReg_Avx512_Zmm15,
546 kCidetReg_Avx512_Zmm16,
547 kCidetReg_Avx512_Zmm17,
548 kCidetReg_Avx512_Zmm18,
549 kCidetReg_Avx512_Zmm19,
550 kCidetReg_Avx512_Zmm20,
551 kCidetReg_Avx512_Zmm21,
552 kCidetReg_Avx512_Zmm22,
553 kCidetReg_Avx512_Zmm23,
554 kCidetReg_Avx512_Zmm24,
555 kCidetReg_Avx512_Zmm25,
556 kCidetReg_Avx512_Zmm26,
557 kCidetReg_Avx512_Zmm27,
558 kCidetReg_Avx512_Zmm28,
559 kCidetReg_Avx512_Zmm29,
560 kCidetReg_Avx512_Zmm30,
561 kCidetReg_Avx512_Zmm31,
562#define kCidetReg_Avx512_First kCidetReg_Avx512_Zmm0
563#define kCidetReg_Avx512_Last kCidetReg_Avx512_Zmm31
564
565 kCidetReg_End
566} CIDETREG;
567
568
569/** @name CIDETBUF_XXX - buffer flags.
570 * @{ */
571#define CIDETBUF_PROT_MASK UINT32_C(0x0000000f) /**< Page protection mask. */
572#define CIDETBUF_PROT_RWX UINT32_C(0x00000001) /**< Read + write + execute. */
573#define CIDETBUF_PROT_RWNX UINT32_C(0x00000002) /**< Read + write + no execute. */
574#define CIDETBUF_PROT_RX UINT32_C(0x00000003) /**< Read + execute. */
575#define CIDETBUF_PROT_RNX UINT32_C(0x00000004) /**< Read + no execute. */
576#define CIDETBUF_PROT_RWX_1NP UINT32_C(0x00000005) /**< Read + write + execute; 1 page not present. */
577#define CIDETBUF_PROT_RWX_1RWNX UINT32_C(0x00000006) /**< Read + write + execute; 1 page read + write + no execute. */
578#define CIDETBUF_PROT_RWX_1RNX UINT32_C(0x00000007) /**< Read + write + execute; 1 page read + no execute. */
579#define CIDETBUF_PROT_RWX_1RWXS UINT32_C(0x00000008) /**< Read + write + execute; 1 page read + execute + supervisor. */
580
581#define CIDETBUF_LOC_MASK UINT32_C(0x000000f0) /**< Location mask. */
582/** Buffer located at top and start of the 32-bit address space. */
583#define CIDETBUF_LOC_32BIT_WRAP UINT32_C(0x00000010)
584/** Buffer located at the low canonical boundrary (AMD64). */
585#define CIDETBUF_LOC_CANON_LO UINT32_C(0x00000020)
586/** Buffer located at the high canonical boundrary (AMD64). */
587#define CIDETBUF_LOC_CANON_HI UINT32_C(0x00000030)
588
589/** Segment protection mask. */
590#define CIDETBUF_SEG_MASK UINT32_C(0x00000f00)
591#define CIDETBUF_SEG_EO UINT32_C(0x00000100) /**< Execute only */
592#define CIDETBUF_SEG_ER UINT32_C(0x00000200) /**< Execute + read */
593#define CIDETBUF_SEG_EO_CONF UINT32_C(0x00000300) /**< Execute only + conforming. */
594#define CIDETBUF_SEG_ER_CONF UINT32_C(0x00000400) /**< Execute + read + conforming. */
595#define CIDETBUF_SEG_RO UINT32_C(0x00000500) /**< Read only. */
596#define CIDETBUF_SEG_RW UINT32_C(0x00000600) /**< Read + write. */
597#define CIDETBUF_SEG_RO_DOWN UINT32_C(0x00000700) /**< Read only + expand down. */
598#define CIDETBUF_SEG_RW_DOWN UINT32_C(0x00000800) /**< Read + write + expand down. */
599
600#define CIDETBUF_DPL_MASK UINT32_C(0x00003000) /**< DPL mask. */
601#define CIDETBUF_DPL_0 UINT32_C(0x00000000) /**< DPL=0. */
602#define CIDETBUF_DPL_1 UINT32_C(0x00001000) /**< DPL=1. */
603#define CIDETBUF_DPL_2 UINT32_C(0x00002000) /**< DPL=2. */
604#define CIDETBUF_DPL_3 UINT32_C(0x00003000) /**< DPL=3. */
605#define CIDETBUF_DPL_SAME UINT32_C(0x00004000) /**< Same DPL as the execution environment. */
606
607#define CIDETBUF_SEG_LIMIT_BASE_CAP UINT32_C(0x00008000) /**< Capability to change segment limit and base. */
608
609#define CIDETBUF_KIND_DATA UINT32_C(0x00000000) /**< Data buffer. */
610#define CIDETBUF_KIND_CODE UINT32_C(0x80000000) /**< Code buffer. */
611/** Checks if @a a_fFlags describes a code buffer. */
612#define CIDETBUF_IS_CODE(a_fFlags) (((a_fFlags) & CIDETBUF_KIND_CODE) != 0)
613/** Checks if @a a_fFlags describes a data buffer. */
614#define CIDETBUF_IS_DATA(a_fFlags) (((a_fFlags) & CIDETBUF_KIND_CODE) == 0)
615/** @} */
616
617/** Code buffer size. (At least two pages.) */
618#define CIDET_CODE_BUF_SIZE (PAGE_SIZE * 2)
619/** Data buffer size. (At least two pages.) */
620#define CIDET_DATA_BUF_SIZE (PAGE_SIZE * 3)
621
622
623/**
624 * Detailed expected exception.
625 *
626 * This is used to internally in the core to calculate the expected exception
627 * considering all the things that may cause exceptions.
628 */
629typedef enum CIDETEXPECTXCPT
630{
631 kCidetExpectXcpt_Invalid = 0,
632 /** No exception expected. */
633 kCidetExpectXcpt_None,
634
635 /** Page not present. */
636 kCidetExpectXcpt_PageNotPresent,
637 /** Write access to a non-writable page. */
638 kCidetExpectXcpt_PageNotWritable,
639 /** Executable access to a non-executable page. */
640 kCidetExpectXcpt_PageNotExecutable,
641 /** Access to supervisor page from user mode code. */
642 kCidetExpectXcpt_PagePrivileged,
643#define kCidetExpectXcpt_First_PageFault kCidetExpectXcpt_PageNotPresent
644#define kCidetExpectXcpt_Last_PageFault kCidetExpectXcpt_PagePrivileged
645
646 /** Read or write access to an execute only segment. */
647 kCidetExpectXcpt_SegExecuteOnly,
648 /** Write to a read only or execute+read segment. */
649 kCidetExpectXcpt_SegNotWritable,
650 /** Exceeded the limit of a non-stack access. */
651 kCidetExpectXcpt_SegExceededLimit,
652 /** Non-canonical address via any segment other than the stack. */
653 kCidetExpectXcpt_AddrNotCanonical,
654 /** Misaligned 16 or 32 byte SSE or AVX operand. */
655 kCidetExpectXcpt_MisalignedSseAvx,
656 /** Privileged instruction. */
657 kCidetExpectXcpt_PrivilegedInstruction,
658#define kCidetExpectXcpt_First_GeneralProtectionFault kCidetExpectXcpt_SegExecuteOnly
659#define kCidetExpectXcpt_Last_GeneralProtectionFault kCidetExpectXcpt_PrivilegedInstruction
660
661 /** Exceeded the limit of a stack access. */
662 kCidetExpectXcpt_StackExceededLimit,
663 /** Non-canonical stack address. */
664 kCidetExpectXcpt_StackAddrNotCanonical,
665#define kCidetExpectXcpt_First_StackFault kCidetExpectXcpt_StackExceededLimit
666#define kCidetExpectXcpt_Last_StackFault kCidetExpectXcpt_StackAddrNotCanonical
667
668 /** Misaligned memory operand (and alignment checking is in effect) if AC is
669 * enabled (executing in ring-3). */
670 kCidetExpectXcpt_MisalignedIfAcEnabled,
671 /** Misaligned 16 byte memory operand resulting in \#AC if ring-3 and
672 * enable, otherwise \#GP(0). */
673 kCidetExpectXcpt_Misaligned16ByteAcEnabledOrGp,
674#define kCidetExpectXcpt_First_AlignmentCheckFault kCidetExpectXcpt_MisalignedIfAcEnabled
675#define kCidetExpectXcpt_Last_AlignmentCheckFault kCidetExpectXcpt_Misaligned16ByteAcEnabledOrGp
676
677 kCidetExpectXcpt_End
678} CIDETEXPECTXCPT;
679
680
681/**
682 * Buffer configuration.
683 */
684typedef struct CIDETBUFCFG
685{
686 /** The name of this buffer configuration. */
687 const char *pszName;
688 /** The buffer flags (CIDETBUF_XXX) */
689 uint32_t fFlags;
690} CIDETBUFCFG;
691/** Pointer to a constant buffer configuration. */
692typedef CIDETBUFCFG const *PCCIDETBUFCFG;
693
694
695/**
696 * CIDET buffer for code or data.
697 *
698 * ASSUMES page aligned buffers.
699 */
700typedef struct CIDETBUF
701{
702 /** @name Owned & modified by the front end.
703 * @{ */
704 /** Effective buffer address. */
705 uint64_t uEffBufAddr;
706 /** The segment base address. */
707 uint64_t uSegBase;
708 /** The active segment limit (see also cbSegLimit). UINT64_MAX if flat. */
709 uint64_t cbActiveSegLimit;
710 /** This specifies the selector to use if a non-flat segment limit or special
711 * segment flags was requested via pfnSetupBuf. UINT32_MAX if any segment is
712 * selector works. */
713 uint32_t uSeg;
714 /** The off value at the last pfnReinitBuf call. */
715 uint16_t offActive;
716 /** The cb value at the last pfnReinitBuf call. */
717 uint16_t cbActive;
718 /** Prologue (or front fence) size. */
719 uint16_t cbPrologue;
720 /** Epilogue (or tail fence) size. */
721 uint16_t cbEpilogue;
722 /** @} */
723
724 /** @name Set by the core before pfnReinitBuf call.
725 * @{ */
726 /** Pointer to the buffer config. */
727 PCCIDETBUFCFG pCfg;
728 /** The configuration index. */
729 uint32_t idxCfg;
730 /** The offset into the buffer of the data / code. */
731 uint16_t off;
732 /** The number of bytes of data / code. */
733 uint16_t cb;
734 /** The segment limit relative to the start of the buffer (last byte included
735 * in count). UINT16_MAX if maximum segment size should be used. */
736 uint16_t cbSegLimit;
737 /** Desired segment base offset.
738 * This is for checking where the alignment checks are performed. */
739 uint8_t offSegBase;
740
741 /** Set if this buffer is actively being used. */
742 bool fActive : 1;
743 /** The operand index (if data), 7 if not active. */
744 uint8_t idxOp : 3;
745 /** Code: Set if the expected exception is supposed to occur on the
746 * following insturction, not the instruction unter test. */
747 bool fXcptAfterInstruction : 1;
748 /** Set if the instruction will read from the buffer. */
749 bool fRead : 1;
750 /** Set if the instruction will write to the buffer. */
751 bool fWrite : 1;
752 /** The expected exception. */
753 CIDETEXPECTXCPT enmExpectXcpt;
754 /** @} */
755} CIDETBUF;
756/** Pointer to a CIDET buffer for code or data. */
757typedef CIDETBUF *PCIDETBUF;
758
759
760/**
761 * CPU Instruction Decoding & Execution Testing (CIDET) state.
762 */
763typedef struct CIDETCORE
764{
765 /** Magic number (CIDETCORE_MAGIC). */
766 uint32_t u32Magic;
767
768 /** The target CPU mode / environment. */
769 uint8_t bMode;
770 /** The target ring. */
771 uint8_t iRing;
772 /** Unused padding bytes. */
773 uint8_t abPadding1[2];
774
775 /** Test configuration. */
776 uint64_t fTestCfg;
777
778 /** Code buffer configurations to test.
779 * The first buffer must be a normal buffer that does not cause any problems. */
780 PCCIDETBUFCFG paCodeBufConfigs;
781 /** The number of code buffer configurations to test (pafCodeBufConfigs). */
782 uint32_t cCodeBufConfigs;
783 /** The number of data buffer configurations to test (pafDataBufConfigs). */
784 uint32_t cDataBufConfigs;
785 /** Data buffer configurations to test.
786 * The first buffer must be a normal buffer that does not cause any problems. */
787 PCCIDETBUFCFG paDataBufConfigs;
788
789 /** The instruction currently under testing. */
790 PCCIDETINSTR pCurInstr;
791
792 /** Primary data buffer. */
793 CIDETBUF DataBuf;
794 /** Secondary data buffer. */
795 CIDETBUF DataBuf2;
796
797 /** Handle to the random number source. */
798 RTRAND hRand;
799
800 /**
801 * Re-initializes one of the data buffers.
802 *
803 * @returns true on succes, false if the request cannot be satisfied.
804 * @param pThis The core state.
805 * @param pBuf Pointer to the buffer structure.
806 */
807 DECLCALLBACKMEMBER(bool, pfnReInitDataBuf)(struct CIDETCORE *pThis, PCIDETBUF pBuf);
808
809 /**
810 * Copies bytes into the data buffer and sets it up for execution.
811 *
812 * @returns true on succes, false if the request cannot be satisfied.
813 * @param pThis The core state.
814 * @param pBuf Pointer to the buffer structure.
815 * @param pvSrc The source bytes (size and destination offset
816 * given in pfnReinitBuf call).
817 */
818 DECLCALLBACKMEMBER(bool, pfnSetupDataBuf)(struct CIDETCORE *pThis, PCIDETBUF pBuf, void const *pvSrc);
819
820 /**
821 * Compares buffer content after test execution.
822 *
823 * This also checks any fill bytes in the buffer that the front end may
824 * have put up. The front end will double buffer the content of supposedly
825 * inaccessible pages as well as non-existing pages to simplify things for
826 * the core code.
827 *
828 * @returns true if equal, false if not.
829 * @param pThis The core state.
830 * @param pBuf Pointer to the buffer structure.
831 * @param pvExpected Pointer to the expected source bytes (size and
832 * buffer offset given in pfnReinitBuf call).
833 */
834 DECLCALLBACKMEMBER(bool, pfnIsBufEqual)(struct CIDETCORE *pThis, struct CIDETBUF *pBuf, void const *pvExpected);
835
836 /**
837 * Re-initializes the code buffer.
838 *
839 * @returns true on succes, false if the request cannot be satisfied.
840 * @param pThis The core state.
841 * @param pBuf Pointer to the CodeBuf member. The off and cb
842 * members represent what the core wants to
843 * execute.
844 */
845 DECLCALLBACKMEMBER(bool, pfnReInitCodeBuf)(struct CIDETCORE *pThis, PCIDETBUF pBuf);
846
847 /**
848 * Emit code into the code buffer, making everything ready for pfnExecute.
849 *
850 * @returns VBox status code.
851 * @param pThis Pointer to the core structure.
852 * @param pBuf Pointer to the CodeBuf member.
853 * @param pvInstr Pointer to the encoded instruction bytes.
854 */
855 DECLCALLBACKMEMBER(bool, pfnSetupCodeBuf)(struct CIDETCORE *pThis, PCIDETBUF pBuf, void const *pvInstr);
856
857 /**
858 * Executes the code indicated by InCtx, returning the result in ActualCtx.
859 *
860 * @returns true if execute, false if skipped.
861 * @param pThis Pointer to the core structure.
862 */
863 DECLCALLBACKMEMBER(bool, pfnExecute)(struct CIDETCORE *pThis);
864
865 /**
866 * Report a test failure.
867 *
868 * @param pThis Pointer to the core structure.
869 * @param pszFormat Format string containing failure details.
870 * @param va Arguments referenced in @a pszFormat.
871 */
872 DECLCALLBACKMEMBER(void, pfnFailure)(struct CIDETCORE *pThis, const char *pszFormat, va_list va);
873
874 /** Array of indexes for use by FNCIDETSETUPINOUT.
875 * Reset when changing instruction or switching between valid and invalid
876 * inputs. */
877 uint32_t aiInOut[4];
878
879 /** @name Copyied and extracted instruction information.
880 * @{ */
881 /** The flags (CIDET_OF_XXX) for the MODRM.REG operand, 0 if not applicable. */
882 uint32_t fMrmRegOp;
883 /** The flags (CIDET_OF_XXX) for the MODRM.RM operand, 0 if not applicable. */
884 uint32_t fMrmRmOp;
885 /** Instruction flags (CIDETINSTR::fFlags). */
886 uint64_t fInstrFlags;
887 /** Number of operands (CIDETINSTR::cOperands). */
888 uint8_t cOperands;
889 /** Number of memory operands (set by CidetCoreSetupFirstMemoryOperandConfig). */
890 uint8_t cMemoryOperands : 3;
891 /** Set if we're working on a MOD R/M byte. */
892 bool fUsesModRm : 1;
893 /** The index of the MODRM.REG operand, 7 if not applicable. */
894 uint8_t idxMrmRegOp : 3;
895 /** The index of the MODRM.RM operand, 7 if not applicable. */
896 uint8_t idxMrmRmOp : 3;
897 /** Set if the SIB byte uses VEX registers for indexing. */
898 bool fUsesVexIndexRegs : 1;
899 /** @} */
900
901 /** @name Basic encoding knobs, wheels and indicators.
902 * @{ */
903 /** Set if we're working on a SIB byte. */
904 bool fSib : 1;
905 /** Required segment prefix (X86_SREG_XXX), X86_SREG_COUNT if not. */
906 uint8_t uSegPrf : 3;
907 /** The address size prefix. */
908 bool fAddrSizePrf : 1;
909 /** The operand size prefix. */
910 bool fOpSizePrf : 1;
911 /** The REX.W prefix value. */
912 bool fRexW : 1;
913 /** The REX.R prefix value. */
914 bool fRexR : 1;
915 /** The REX.X prefix value. */
916 bool fRexX : 1;
917 /** The REX.B prefix value. */
918 bool fRexB : 1;
919 /** Set if a REX prefix is required with or without flags (for byte regs). */
920 bool fRex : 1;
921 /** Use VEX encoding. */
922 bool fVex : 1;
923 /** Use EVEX encoding. */
924 bool fEvex : 1;
925 /** Indicator: Effective addressing mode in bytes (2, 4, 8). */
926 uint8_t cbAddrMode : 4;
927 /** Indicator: Set if there is an operand accessing memory. */
928 bool fHasMemoryOperand : 1;
929 /** Indicator: Set if a register is used in two or more operands, and one of
930 * them being for addressing. */
931 bool fHasRegCollisionMem : 1;
932 /** Indicator: Helper indicator for tracking SIB.BASE collision. */
933 bool fHasRegCollisionMemBase : 1;
934 /** Indicator: Helper indicator for tracking SIB.INDEX collision. */
935 bool fHasRegCollisionMemIndex : 1;
936 /** Indicator: Set if a register is used directly in more than one operand. */
937 bool fHasRegCollisionDirect : 1;
938
939 /** Indicator: Set if MODRM.REG is the stack register. */
940 bool fHasStackRegInMrmReg : 1;
941 /** Indicator: Set if MODRM.RM or SIB.BASE is the stack register. */
942 bool fHasStackRegInMrmRmBase: 1;
943
944 /** Indicator: High byte-register specified by MODRM.REG. */
945 bool fHasHighByteRegInMrmReg : 1;
946 /** Indicator: High byte-register specified by MODRM.RM. */
947 bool fHasHighByteRegInMrmRm : 1;
948 /** Indicator: Set if REX prefixes are incompatible with the byte-register
949 * specified by MODRM.REG. */
950 bool fNoRexPrefixMrmReg : 1;
951 /** Indicator: Set if REX prefixes are incompatible with the byte-register
952 * specified by MODRM.RM. */
953 bool fNoRexPrefixMrmRm : 1;
954 /** Indicator: fNoRexPrefixMrmReg || fNoRexPrefixMrmMr. */
955 bool fNoRexPrefix : 1;
956 /** The MOD R/M byte we're working on (if fUsesModRm is set). */
957 uint8_t bModRm;
958 /** The SIB/VSIB byte we're working on (if fSib is set). */
959 uint8_t bSib;
960 /** @} */
961
962 /** The effective instruction address. (See InCtx.rip and InCtx.cs for the
963 * rest of the instruction addressing stuff.) */
964 uint64_t uInstrEffAddr;
965
966 /** Operand information, mainly for the FNCIDETSETUPINOUT and similar. */
967 struct
968 {
969 /** The operand flags copied from (CIDETINSTR::afOperands). */
970 uint32_t fFlags;
971 /** The encoded register number, if register, UINT8_MAX if not. */
972 uint8_t iReg;
973 /** The actual operand size (encoded). */
974 uint8_t cb;
975 /** Set if immediate value. */
976 bool fIsImmediate : 1;
977 /** Set if memory access. */
978 bool fIsMem : 1;
979 /** Set if addressing is relative to RIP. */
980 bool fIsRipRelative : 1;
981 /** Set if it's a high byte register. */
982 bool fIsHighByteRegister : 1;
983 /** Size of the disposition, 0 if none. */
984 uint8_t cbMemDisp;
985 /** Base register, UINT8_MAX if not applicable. */
986 uint8_t iMemBaseReg;
987 /** Index register, UINT8_MAX if not applicable. */
988 uint8_t iMemIndexReg;
989 /** Index register, 1 if not applicable. */
990 uint8_t uMemScale;
991 /** Effective segment register, UINT8_MAX if not memory access. */
992 uint8_t iEffSeg;
993 /** Segment offset if memory access. Undefined if not memory access. */
994 uint64_t offSeg;
995 /** The effective address if memory access. */
996 uint64_t uEffAddr;
997 /** Immediate or displacement value. */
998 uint64_t uImmDispValue;
999 /** Base register value, undefined if irrelevant. */
1000 uint64_t uMemBaseRegValue;
1001 /** Index register value, undefined if irrelevant. */
1002 uint64_t uMemIndexRegValue;
1003 /** Points to where the input data for this operand should be placed,
1004 * when possible. In the fIsMem = true case, it either points directly
1005 * to the input buffer or to a temporary one. While in the other case,
1006 * it'll point into InCtx when possible. */
1007 RTPTRUNION In;
1008 /** Points to where the expected output data for this operand should be
1009 * stored, when possible. In the fIsMem = false case, it'll point into
1010 * ExpectedCtx when possible. */
1011 RTPTRUNION Expected;
1012 /** Pointer to the data buffer for this operand. */
1013 PCIDETBUF pDataBuf;
1014 } aOperands[4];
1015
1016 /** Buffer where we assemble the instruction. */
1017 uint8_t abInstr[45];
1018 /** The size of the instruction in abInstr. */
1019 uint8_t cbInstr;
1020 /** Offset of the instruction into the buffer. */
1021 uint16_t offInstr;
1022 /** Current code buffer. */
1023 CIDETBUF CodeBuf;
1024
1025 /** The input context. Initalized by driver and FNCIDETSETUPINOUT. */
1026 CIDETCPUCTX InCtx;
1027 /** The expected output context. */
1028 CIDETCPUCTX ExpectedCtx;
1029 /** The actual output context. */
1030 CIDETCPUCTX ActualCtx;
1031 /** Template input context, initialized when setting the mode. */
1032 CIDETCPUCTX InTemplateCtx;
1033
1034 /** Input and expected output temporary memory buffers. */
1035 uint8_t abBuf[0x2000];
1036
1037
1038 /** Number of skipped tests because of pfnSetupInOut failures. */
1039 uint32_t cSkippedSetupInOut;
1040 /** Number of skipped tests because of pfnReInitDataBuf failures. */
1041 uint32_t cSkippedReInitDataBuf;
1042 /** Number of skipped tests because of pfnSetupDataBuf failures. */
1043 uint32_t cSkippedSetupDataBuf;
1044 /** Number of skipped tests because RIP relative addressing constraints. */
1045 uint32_t cSkippedDataBufWrtRip;
1046 /** Number of skipped tests because of assemble failures. */
1047 uint32_t cSkippedAssemble;
1048 /** Number of skipped tests because of pfnReInitCodeBuf failures. */
1049 uint32_t cSkippedReInitCodeBuf;
1050 /** Number of skipped tests because of pfnSetupCodeBuf failures. */
1051 uint32_t cSkippedSetupCodeBuf;
1052 /** Number of skipped tests because the base and index registers are the same
1053 * one and there was a remainder when trying to point to the data buffer. */
1054 uint32_t cSkippedSameBaseIndexRemainder;
1055 /** Number of skipped tests because index-only addressing left a remainder. */
1056 uint32_t cSkippedOnlyIndexRemainder;
1057 /** Number of skipped tests because of direct addressing overflowed. */
1058 uint32_t cSkippedDirectAddressingOverflow;
1059
1060
1061} CIDETCORE;
1062/** Pointer to the CIDET core state. */
1063typedef CIDETCORE *PCIDETCORE;
1064
1065/** Magic number for CIDETCORE (Lee Konitz). */
1066#define CIDETCORE_MAGIC UINT32_C(0x19271013)
1067
1068
1069int CidetCoreInit(PCIDETCORE pThis, RTRAND hRand);
1070void CidetCoreDelete(PCIDETCORE pThis);
1071int CidetCoreSetTargetMode(PCIDETCORE pThis, uint8_t bMode);
1072uint32_t CidetCoreGetOperandSize(PCIDETCORE pThis, uint8_t iOp);
1073bool CidetCoreTestInstruction(PCIDETCORE pThis, PCCIDETINSTR pInstr);
1074
1075
1076extern const CIDETINSTR g_aCidetInstructions1[];
1077extern const uint32_t g_cCidetInstructions1;
1078
1079#endif
1080
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