4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
30 /* #pragma ident "@(#)dis_tables.c 1.13 06/06/15 SMI" */
32 #if !defined(__APPLE__)
33 #include "dis_tables.h"
35 #include <sys/dtrace.h>
36 #include <sys/dtrace_glue.h>
38 #include <sys/dis_tables.h>
39 #endif /* __APPLE__ */
44 * Disassembly begins in dis_distable, which is equivalent to the One-byte
45 * Opcode Map in the Intel IA32 ISA Reference (page A-6 in my copy). The
46 * decoding loops then traverse out through the other tables as necessary to
47 * decode a given instruction.
49 * The behavior of this file can be controlled by one of the following flags:
51 * DIS_TEXT Include text for disassembly
52 * DIS_MEM Include memory-size calculations
54 * Either or both of these can be defined.
56 * This file is not, and will never be, cstyled. If anything, the tables should
57 * be taken out another tab stop or two so nothing overlaps.
61 * These functions must be provided for the consumer to do disassembly.
64 extern char *strncpy(char *, const char *, size_t);
65 extern size_t strlen(const char *);
66 extern int strcmp(const char *, const char *);
67 extern int strncmp(const char *, const char *, size_t);
68 extern size_t strlcat(char *, const char *, size_t);
72 #define TERM 0 /* used to indicate that the 'indirect' */
73 /* field terminates - no pointer. */
75 /* Used to decode instructions. */
76 typedef struct instable
{
77 struct instable
*it_indirect
; /* for decode op codes */
81 uint_t it_suffix
:1; /* mnem + "w", "l", or "d" */
86 uint_t it_invalid64
:1; /* opcode invalid in amd64 */
87 uint_t it_always64
:1; /* 64 bit when in 64 bit mode */
88 uint_t it_invalid32
:1; /* invalid in IA32 */
89 uint_t it_stackop
:1; /* push/pop stack operation */
93 * Instruction formats.
107 M
, /* register or memory */
108 Mb
, /* register or memory, always byte sized */
109 MO
, /* memory only (no registers) */
129 DSHIFT
, /* for double shift that has an 8-bit immediate */
132 NORM
, /* instructions w/o ModR/M byte, no memory access */
133 IMPLMEM
, /* instructions w/o ModR/M byte, implicit mem access */
135 JTAB
, /* jump table */
136 IMUL
, /* for 186 iimul instr */
137 CBW
, /* so data16 can be evaluated for cbw and variants */
138 MvI
, /* for 186 logicals */
139 ENTER
, /* for 186 enter instr */
140 RMw
, /* for 286 arpl instr */
141 Ib
, /* for push immediate byte */
142 F
, /* for 287 instructions */
143 FF
, /* for 287 instructions */
144 FFC
, /* for 287 instructions */
145 DM
, /* 16-bit data */
146 AM
, /* 16-bit addr */
147 LSEG
, /* for 3-bit seg reg encoding */
148 MIb
, /* for 386 logicals */
149 SREG
, /* for 386 special registers */
150 PREFIX
, /* a REP instruction prefix */
151 LOCK
, /* a LOCK instruction prefix */
152 INT3
, /* The int 3 instruction, which has a fake operand */
153 INTx
, /* The normal int instruction, with explicit int num */
154 DSHIFTcl
, /* for double shift that implicitly uses %cl */
155 CWD
, /* so data16 can be evaluated for cwd and variants */
156 RET
, /* single immediate 16-bit operand */
157 MOVZ
, /* for movs and movz, with different size operands */
158 XADDB
, /* for xaddb */
159 MOVSXZ
, /* AMD64 mov sign extend 32 to 64 bit instruction */
162 * MMX/SIMD addressing modes.
165 MMO
, /* Prefixable MMX/SIMD-Int mm/mem -> mm */
166 MMOIMPL
, /* Prefixable MMX/SIMD-Int mm -> mm (mem) */
167 MMO3P
, /* Prefixable MMX/SIMD-Int mm -> r32,imm8 */
168 MMOM3
, /* Prefixable MMX/SIMD-Int mm -> r32 */
169 MMOS
, /* Prefixable MMX/SIMD-Int mm -> mm/mem */
170 MMOMS
, /* Prefixable MMX/SIMD-Int mm -> mem */
171 MMOPM
, /* MMX/SIMD-Int mm/mem -> mm,imm8 */
172 MMOPRM
, /* Prefixable MMX/SIMD-Int r32/mem -> mm,imm8 */
173 MMOSH
, /* Prefixable MMX mm,imm8 */
174 MM
, /* MMX/SIMD-Int mm/mem -> mm */
175 MMS
, /* MMX/SIMD-Int mm -> mm/mem */
176 MMSH
, /* MMX mm,imm8 */
177 XMMO
, /* Prefixable SIMD xmm/mem -> xmm */
178 XMMOS
, /* Prefixable SIMD xmm -> xmm/mem */
179 XMMOPM
, /* Prefixable SIMD xmm/mem w/to xmm,imm8 */
180 XMMOMX
, /* Prefixable SIMD mm/mem -> xmm */
181 XMMOX3
, /* Prefixable SIMD xmm -> r32 */
182 XMMOXMM
, /* Prefixable SIMD xmm/mem -> mm */
183 XMMOM
, /* Prefixable SIMD xmm -> mem */
184 XMMOMS
, /* Prefixable SIMD mem -> xmm */
185 XMM
, /* SIMD xmm/mem -> xmm */
186 XMMXIMPL
, /* SIMD xmm -> xmm (mem) */
187 XMM3P
, /* SIMD xmm -> r32,imm8 */
188 XMMP
, /* SIMD xmm/mem w/to xmm,imm8 */
189 XMMPRM
, /* SIMD r32/mem -> xmm,imm8 */
190 XMMS
, /* SIMD xmm -> xmm/mem */
191 XMMM
, /* SIMD mem -> xmm */
192 XMMMS
, /* SIMD xmm -> mem */
193 XMM3MX
, /* SIMD r32/mem -> xmm */
194 XMM3MXS
, /* SIMD xmm -> r32/mem */
195 XMMSH
, /* SIMD xmm,imm8 */
196 XMMXM3
, /* SIMD xmm/mem -> r32 */
197 XMMX3
, /* SIMD xmm -> r32 */
198 XMMXMM
, /* SIMD xmm/mem -> mm */
199 XMMMX
, /* SIMD mm -> xmm */
200 XMMXM
, /* SIMD xmm -> mm */
201 XMMFENCE
, /* SIMD lfence or mfence */
202 XMMSFNC
/* SIMD sfence (none or mem) */
205 #define FILL 0x90 /* Fill byte used for alignment (nop) */
208 ** Register numbers for the i386
220 * modes for immediate values
223 #define MODE_IPREL 1 /* signed IP relative value */
224 #define MODE_SIGNED 2 /* sign extended immediate */
225 #define MODE_IMPLIED 3 /* constant value implied from opcode */
226 #define MODE_OFFSET 4 /* offset part of an address */
227 #define MODE_RIPREL 5 /* like IPREL, but from %rip (amd64) */
230 * The letters used in these macros are:
231 * IND - indirect to another to another table
232 * "T" - means to Terminate indirections (this is the final opcode)
233 * "S" - means "operand length suffix required"
234 * "NS" - means "no suffix" which is the operand length suffix of the opcode
235 * "Z" - means instruction size arg required
236 * "u" - means the opcode is invalid in IA32 but valid in amd64
237 * "x" - means the opcode is invalid in amd64, but not IA32
238 * "y" - means the operand size is always 64 bits in 64 bit mode
239 * "p" - means push/pop stack operation
242 #if defined(DIS_TEXT) && defined(DIS_MEM)
243 #define IND(table) {(instable_t *)table, 0, "", 0, 0, 0, 0, 0, 0}
244 #define INDx(table) {(instable_t *)table, 0, "", 0, 0, 1, 0, 0, 0}
245 #define TNS(name, amode) {TERM, amode, name, 0, 0, 0, 0, 0, 0}
246 #define TNSu(name, amode) {TERM, amode, name, 0, 0, 0, 0, 1, 0}
247 #define TNSx(name, amode) {TERM, amode, name, 0, 0, 1, 0, 0, 0}
248 #define TNSy(name, amode) {TERM, amode, name, 0, 0, 0, 1, 0, 0}
249 #define TNSyp(name, amode) {TERM, amode, name, 0, 0, 0, 1, 0, 1}
250 #define TNSZ(name, amode, sz) {TERM, amode, name, 0, sz, 0, 0, 0, 0}
251 #define TNSZy(name, amode, sz) {TERM, amode, name, 0, sz, 0, 1, 0, 0}
252 #define TS(name, amode) {TERM, amode, name, 1, 0, 0, 0, 0, 0}
253 #define TSx(name, amode) {TERM, amode, name, 1, 0, 1, 0, 0, 0}
254 #define TSy(name, amode) {TERM, amode, name, 1, 0, 0, 1, 0, 0}
255 #define TSp(name, amode) {TERM, amode, name, 1, 0, 0, 0, 0, 1}
256 #define TSZ(name, amode, sz) {TERM, amode, name, 1, sz, 0, 0, 0, 0}
257 #define TSZx(name, amode, sz) {TERM, amode, name, 1, sz, 1, 0, 0, 0}
258 #define TSZy(name, amode, sz) {TERM, amode, name, 1, sz, 0, 1, 0, 0}
259 #define INVALID {TERM, UNKNOWN, "", 0, 0, 0, 0, 0}
260 #elif defined(DIS_TEXT)
261 #define IND(table) {(instable_t *)table, 0, "", 0, 0, 0, 0, 0}
262 #define INDx(table) {(instable_t *)table, 0, "", 0, 1, 0, 0, 0}
263 #define TNS(name, amode) {TERM, amode, name, 0, 0, 0, 0, 0}
264 #define TNSu(name, amode) {TERM, amode, name, 0, 0, 0, 1, 0}
265 #define TNSx(name, amode) {TERM, amode, name, 0, 1, 0, 0, 0}
266 #define TNSy(name, amode) {TERM, amode, name, 0, 0, 1, 0, 0}
267 #define TNSyp(name, amode) {TERM, amode, name, 0, 0, 1, 0, 1}
268 #define TNSZ(name, amode, sz) {TERM, amode, name, 0, 0, 0, 0, 0}
269 #define TNSZy(name, amode, sz) {TERM, amode, name, 0, 0, 1, 0, 0}
270 #define TS(name, amode) {TERM, amode, name, 1, 0, 0, 0, 0}
271 #define TSx(name, amode) {TERM, amode, name, 1, 1, 0, 0, 0}
272 #define TSy(name, amode) {TERM, amode, name, 1, 0, 1, 0, 0}
273 #define TSp(name, amode) {TERM, amode, name, 1, 0, 0, 0, 1}
274 #define TSZ(name, amode, sz) {TERM, amode, name, 1, 0, 0, 0, 0}
275 #define TSZx(name, amode, sz) {TERM, amode, name, 1, 1, 0, 0, 0}
276 #define TSZy(name, amode, sz) {TERM, amode, name, 1, 0, 1, 0, 0}
277 #define INVALID {TERM, UNKNOWN, "", 0, 0, 0, 0, 0}
278 #elif defined(DIS_MEM)
279 #define IND(table) {(instable_t *)table, 0, 0, 0, 0, 0, 0}
280 #define INDx(table) {(instable_t *)table, 0, 0, 1, 0, 0, 0}
281 #define TNS(name, amode) {TERM, amode, 0, 0, 0, 0, 0}
282 #define TNSu(name, amode) {TERM, amode, 0, 0, 0, 1, 0}
283 #define TNSy(name, amode) {TERM, amode, 0, 0, 1, 0, 0}
284 #define TNSyp(name, amode) {TERM, amode, 0, 0, 1, 0, 1}
285 #define TNSx(name, amode) {TERM, amode, 0, 1, 0, 0, 0}
286 #define TNSZ(name, amode, sz) {TERM, amode, sz, 0, 0, 0, 0}
287 #define TNSZy(name, amode, sz) {TERM, amode, sz, 0, 1, 0, 0}
288 #define TS(name, amode) {TERM, amode, 0, 0, 0, 0, 0}
289 #define TSx(name, amode) {TERM, amode, 0, 1, 0, 0, 0}
290 #define TSy(name, amode) {TERM, amode, 0, 0, 1, 0, 0}
291 #define TSp(name, amode) {TERM, amode, 0, 0, 0, 0, 1}
292 #define TSZ(name, amode, sz) {TERM, amode, sz, 0, 0, 0, 0}
293 #define TSZx(name, amode, sz) {TERM, amode, sz, 1, 0, 0, 0}
294 #define TSZy(name, amode, sz) {TERM, amode, sz, 0, 1, 0, 0}
295 #define INVALID {TERM, UNKNOWN, 0, 0, 0, 0, 0}
297 #define IND(table) {(instable_t *)table, 0, 0, 0, 0, 0}
298 #define INDx(table) {(instable_t *)table, 0, 1, 0, 0, 0}
299 #define TNS(name, amode) {TERM, amode, 0, 0, 0, 0}
300 #define TNSu(name, amode) {TERM, amode, 0, 0, 1, 0}
301 #define TNSy(name, amode) {TERM, amode, 0, 1, 0, 0}
302 #define TNSyp(name, amode) {TERM, amode, 0, 1, 0, 1}
303 #define TNSx(name, amode) {TERM, amode, 1, 0, 0, 0}
304 #define TNSZ(name, amode, sz) {TERM, amode, 0, 0, 0, 0}
305 #define TNSZy(name, amode, sz) {TERM, amode, 0, 1, 0, 0}
306 #define TS(name, amode) {TERM, amode, 0, 0, 0, 0}
307 #define TSx(name, amode) {TERM, amode, 1, 0, 0, 0}
308 #define TSy(name, amode) {TERM, amode, 0, 1, 0, 0}
309 #define TSp(name, amode) {TERM, amode, 0, 0, 0, 1}
310 #define TSZ(name, amode, sz) {TERM, amode, 0, 0, 0, 0}
311 #define TSZx(name, amode, sz) {TERM, amode, 1, 0, 0, 0}
312 #define TSZy(name, amode, sz) {TERM, amode, 0, 1, 0, 0}
313 #define INVALID {TERM, UNKNOWN, 0, 0, 0, 0}
318 * this decodes the r_m field for mode's 0, 1, 2 in 16 bit mode
320 const char *const dis_addr16
[3][8] = {
321 "(%bx,%si)", "(%bx,%di)", "(%bp,%si)", "(%bp,%di)", "(%si)", "(%di)", "",
323 "(%bx,%si)", "(%bx,%di)", "(%bp,%si)", "(%bp,%di)", "(%si)", "(%di", "(%bp)",
325 "(%bx,%si)", "(%bx,%di)", "(%bp,%si)", "(%bp,%di)", "(%si)", "(%di)", "(%bp)",
331 * This decodes 32 bit addressing mode r_m field for modes 0, 1, 2
333 const char *const dis_addr32_mode0
[16] = {
334 "(%eax)", "(%ecx)", "(%edx)", "(%ebx)", "", "", "(%esi)", "(%edi)",
335 "(%r8d)", "(%r9d)", "(%r10d)", "(%r11d)", "", "", "(%r14d)", "(%r15d)"
338 const char *const dis_addr32_mode12
[16] = {
339 "(%eax)", "(%ecx)", "(%edx)", "(%ebx)", "", "(%ebp)", "(%esi)", "(%edi)",
340 "(%r8d)", "(%r9d)", "(%r10d)", "(%r11d)", "", "(%r13d)", "(%r14d)", "(%r15d)"
344 * This decodes 64 bit addressing mode r_m field for modes 0, 1, 2
346 const char *const dis_addr64_mode0
[16] = {
347 "(%rax)", "(%rcx)", "(%rdx)", "(%rbx)", "", "(%rip)", "(%rsi)", "(%rdi)",
348 "(%r8)", "(%r9)", "(%r10)", "(%r11)", "(%r12)", "(%rip)", "(%r14)", "(%r15)"
350 const char *const dis_addr64_mode12
[16] = {
351 "(%rax)", "(%rcx)", "(%rdx)", "(%rbx)", "", "(%rbp)", "(%rsi)", "(%rdi)",
352 "(%r8)", "(%r9)", "(%r10)", "(%r11)", "(%r12)", "(%r13)", "(%r14)", "(%r15)"
356 * decode for scale from SIB byte
358 const char *const dis_scale_factor
[4] = { ")", ",2)", ",4)", ",8)" };
361 * register decoding for normal references to registers (ie. not addressing)
363 const char *const dis_REG8
[16] = {
364 "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
365 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
368 const char *const dis_REG8_REX
[16] = {
369 "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
370 "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
373 const char *const dis_REG16
[16] = {
374 "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
375 "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
378 const char *const dis_REG32
[16] = {
379 "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
380 "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
383 const char *const dis_REG64
[16] = {
384 "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
385 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
388 const char *const dis_DEBUGREG
[16] = {
389 "%db0", "%db1", "%db2", "%db3", "%db4", "%db5", "%db6", "%db7",
390 "%db8", "%db9", "%db10", "%db11", "%db12", "%db13", "%db14", "%db15"
393 const char *const dis_CONTROLREG
[16] = {
394 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5?", "%cr6?", "%cr7?",
395 "%cr8", "%cr9?", "%cr10?", "%cr11?", "%cr12?", "%cr13?", "%cr14?", "%cr15?"
398 const char *const dis_TESTREG
[16] = {
399 "%tr0?", "%tr1?", "%tr2?", "%tr3", "%tr4", "%tr5", "%tr6", "%tr7",
400 "%tr0?", "%tr1?", "%tr2?", "%tr3", "%tr4", "%tr5", "%tr6", "%tr7"
403 const char *const dis_MMREG
[16] = {
404 "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7",
405 "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7"
408 const char *const dis_XMMREG
[16] = {
409 "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7",
410 "%xmm8", "%xmm9", "%xmm10", "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15"
413 const char *const dis_SEGREG
[16] = {
414 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "<reserved>", "<reserved>",
415 "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "<reserved>", "<reserved>"
419 * SIMD predicate suffixes
421 const char *const dis_PREDSUFFIX
[8] = {
422 "eq", "lt", "le", "unord", "neq", "nlt", "nle", "ord"
427 #endif /* DIS_TEXT */
433 * "decode table" for 64 bit mode MOVSXD instruction (opcode 0x63)
435 const instable_t dis_opMOVSLD
= TNS("movslq",MOVSXZ
);
438 * "decode table" for pause and clflush instructions
440 const instable_t dis_opPause
= TNS("pause", NORM
);
443 * Decode table for 0x0F00 opcodes
445 const instable_t dis_op0F00
[8] = {
447 /* [0] */ TNS("sldt",M
), TNS("str",M
), TNSy("lldt",M
), TNSy("ltr",M
),
448 /* [4] */ TNSZ("verr",M
,2), TNSZ("verw",M
,2), INVALID
, INVALID
,
453 * Decode table for 0x0F01 opcodes
455 const instable_t dis_op0F01
[8] = {
457 /* [0] */ TNSZ("sgdt",MO
,6), TNSZ("sidt",MO
,6), TNSZ("lgdt",MO
,6), TNSZ("lidt",MO
,6),
458 /* [4] */ TNSZ("smsw",M
,2), INVALID
, TNSZ("lmsw",M
,2), TNS("invlpg",SWAPGS
),
462 * Decode table for 0x0F18 opcodes -- SIMD prefetch
464 const instable_t dis_op0F18
[8] = {
466 /* [0] */ TNS("prefetchnta",PREF
),TNS("prefetcht0",PREF
), TNS("prefetcht1",PREF
), TNS("prefetcht2",PREF
),
467 /* [4] */ INVALID
, INVALID
, INVALID
, INVALID
,
471 * Decode table for 0x0FAE opcodes -- SIMD state save/restore
473 const instable_t dis_op0FAE
[8] = {
474 /* [0] */ TNSZ("fxsave",M
,512), TNSZ("fxrstor",M
,512), TNS("ldmxcsr",M
), TNS("stmxcsr",M
),
475 /* [4] */ INVALID
, TNS("lfence",XMMFENCE
), TNS("mfence",XMMFENCE
), TNS("sfence",XMMSFNC
),
479 * Decode table for 0x0FBA opcodes
482 const instable_t dis_op0FBA
[8] = {
484 /* [0] */ INVALID
, INVALID
, INVALID
, INVALID
,
485 /* [4] */ TS("bt",MIb
), TS("bts",MIb
), TS("btr",MIb
), TS("btc",MIb
),
489 * Decode table for 0x0FC7 opcode
492 const instable_t dis_op0FC7
[8] = {
494 /* [0] */ INVALID
, TNS("cmpxchg8b",M
), INVALID
, INVALID
,
495 /* [4] */ INVALID
, INVALID
, INVALID
, INVALID
,
500 * Decode table for 0x0FC8 opcode -- 486 bswap instruction
502 *bit pattern: 0000 1111 1100 1reg
504 const instable_t dis_op0FC8
[4] = {
505 /* [0] */ TNS("bswap",R
), INVALID
, INVALID
, INVALID
,
509 * Decode table for 0x0F71, 0x0F72, and 0x0F73 opcodes -- MMX instructions
511 const instable_t dis_op0F7123
[4][8] = {
513 /* [70].0 */ INVALID
, INVALID
, INVALID
, INVALID
,
514 /* .4 */ INVALID
, INVALID
, INVALID
, INVALID
,
516 /* [71].0 */ INVALID
, INVALID
, TNS("psrlw",MMOSH
), INVALID
,
517 /* .4 */ TNS("psraw",MMOSH
), INVALID
, TNS("psllw",MMOSH
), INVALID
,
519 /* [72].0 */ INVALID
, INVALID
, TNS("psrld",MMOSH
), INVALID
,
520 /* .4 */ TNS("psrad",MMOSH
), INVALID
, TNS("pslld",MMOSH
), INVALID
,
522 /* [73].0 */ INVALID
, INVALID
, TNS("psrlq",MMOSH
), TNS("INVALID",MMOSH
),
523 /* .4 */ INVALID
, INVALID
, TNS("psllq",MMOSH
), TNS("INVALID",MMOSH
),
527 * Decode table for SIMD extensions to above 0x0F71-0x0F73 opcodes.
529 const instable_t dis_opSIMD7123
[32] = {
530 /* [70].0 */ INVALID
, INVALID
, INVALID
, INVALID
,
531 /* .4 */ INVALID
, INVALID
, INVALID
, INVALID
,
533 /* [71].0 */ INVALID
, INVALID
, TNS("psrlw",XMMSH
), INVALID
,
534 /* .4 */ TNS("psraw",XMMSH
), INVALID
, TNS("psllw",XMMSH
), INVALID
,
536 /* [72].0 */ INVALID
, INVALID
, TNS("psrld",XMMSH
), INVALID
,
537 /* .4 */ TNS("psrad",XMMSH
), INVALID
, TNS("pslld",XMMSH
), INVALID
,
539 /* [73].0 */ INVALID
, INVALID
, TNS("psrlq",XMMSH
), TNS("psrldq",XMMSH
),
540 /* .4 */ INVALID
, INVALID
, TNS("psllq",XMMSH
), TNS("pslldq",XMMSH
),
544 * SIMD instructions have been wedged into the existing IA32 instruction
545 * set through the use of prefixes. That is, while 0xf0 0x58 may be
546 * addps, 0xf3 0xf0 0x58 (literally, repz addps) is a completely different
547 * instruction - addss. At present, three prefixes have been coopted in
548 * this manner - address size (0x66), repnz (0xf2) and repz (0xf3). The
549 * following tables are used to provide the prefixed instruction names.
550 * The arrays are sparse, but they're fast.
554 * Decode table for SIMD instructions with the address size (0x66) prefix.
556 const instable_t dis_opSIMDdata16
[256] = {
557 /* [00] */ INVALID
, INVALID
, INVALID
, INVALID
,
558 /* [04] */ INVALID
, INVALID
, INVALID
, INVALID
,
559 /* [08] */ INVALID
, INVALID
, INVALID
, INVALID
,
560 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
562 /* [10] */ TNSZ("movupd",XMM
,16), TNSZ("movupd",XMMS
,16), TNSZ("movlpd",XMMM
,8), TNSZ("movlpd",XMMMS
,8),
563 /* [14] */ TNSZ("unpcklpd",XMM
,16),TNSZ("unpckhpd",XMM
,16),TNSZ("movhpd",XMMM
,8), TNSZ("movhpd",XMMMS
,8),
564 /* [18] */ INVALID
, INVALID
, INVALID
, INVALID
,
565 /* [1C] */ INVALID
, INVALID
, INVALID
, INVALID
,
567 /* [20] */ INVALID
, INVALID
, INVALID
, INVALID
,
568 /* [24] */ INVALID
, INVALID
, INVALID
, INVALID
,
569 /* [28] */ TNSZ("movapd",XMM
,16), TNSZ("movapd",XMMS
,16), TNSZ("cvtpi2pd",XMMOMX
,8),TNSZ("movntpd",XMMOMS
,16),
570 /* [2C] */ TNSZ("cvttpd2pi",XMMXMM
,16),TNSZ("cvtpd2pi",XMMXMM
,16),TNSZ("ucomisd",XMM
,8),TNSZ("comisd",XMM
,8),
572 /* [30] */ INVALID
, INVALID
, INVALID
, INVALID
,
573 /* [34] */ INVALID
, INVALID
, INVALID
, INVALID
,
574 /* [38] */ INVALID
, INVALID
, INVALID
, INVALID
,
575 /* [3C] */ INVALID
, INVALID
, INVALID
, INVALID
,
577 /* [40] */ INVALID
, INVALID
, INVALID
, INVALID
,
578 /* [44] */ INVALID
, INVALID
, INVALID
, INVALID
,
579 /* [48] */ INVALID
, INVALID
, INVALID
, INVALID
,
580 /* [4C] */ INVALID
, INVALID
, INVALID
, INVALID
,
582 /* [50] */ TNS("movmskpd",XMMOX3
), TNSZ("sqrtpd",XMM
,16), INVALID
, INVALID
,
583 /* [54] */ TNSZ("andpd",XMM
,16), TNSZ("andnpd",XMM
,16), TNSZ("orpd",XMM
,16), TNSZ("xorpd",XMM
,16),
584 /* [58] */ TNSZ("addpd",XMM
,16), TNSZ("mulpd",XMM
,16), TNSZ("cvtpd2ps",XMM
,16),TNSZ("cvtps2dq",XMM
,16),
585 /* [5C] */ TNSZ("subpd",XMM
,16), TNSZ("minpd",XMM
,16), TNSZ("divpd",XMM
,16), TNSZ("maxpd",XMM
,16),
587 /* [60] */ TNSZ("punpcklbw",XMM
,16),TNSZ("punpcklwd",XMM
,16),TNSZ("punpckldq",XMM
,16),TNSZ("packsswb",XMM
,16),
588 /* [64] */ TNSZ("pcmpgtb",XMM
,16), TNSZ("pcmpgtw",XMM
,16), TNSZ("pcmpgtd",XMM
,16), TNSZ("packuswb",XMM
,16),
589 /* [68] */ TNSZ("punpckhbw",XMM
,16),TNSZ("punpckhwd",XMM
,16),TNSZ("punpckhdq",XMM
,16),TNSZ("packssdw",XMM
,16),
590 /* [6C] */ TNSZ("punpcklqdq",XMM
,16),TNSZ("punpckhqdq",XMM
,16),TNSZ("movd",XMM3MX
,4),TNSZ("movdqa",XMM
,16),
592 /* [70] */ TNSZ("pshufd",XMMP
,16), INVALID
, INVALID
, INVALID
,
593 /* [74] */ TNSZ("pcmpeqb",XMM
,16), TNSZ("pcmpeqw",XMM
,16), TNSZ("pcmpeqd",XMM
,16), INVALID
,
594 /* [78] */ INVALID
, INVALID
, INVALID
, INVALID
,
595 /* [7C] */ INVALID
, INVALID
, TNSZ("movd",XMM3MXS
,4), TNSZ("movdqa",XMMS
,16),
597 /* [80] */ INVALID
, INVALID
, INVALID
, INVALID
,
598 /* [84] */ INVALID
, INVALID
, INVALID
, INVALID
,
599 /* [88] */ INVALID
, INVALID
, INVALID
, INVALID
,
600 /* [8C] */ INVALID
, INVALID
, INVALID
, INVALID
,
602 /* [90] */ INVALID
, INVALID
, INVALID
, INVALID
,
603 /* [94] */ INVALID
, INVALID
, INVALID
, INVALID
,
604 /* [98] */ INVALID
, INVALID
, INVALID
, INVALID
,
605 /* [9C] */ INVALID
, INVALID
, INVALID
, INVALID
,
607 /* [A0] */ INVALID
, INVALID
, INVALID
, INVALID
,
608 /* [A4] */ INVALID
, INVALID
, INVALID
, INVALID
,
609 /* [A8] */ INVALID
, INVALID
, INVALID
, INVALID
,
610 /* [AC] */ INVALID
, INVALID
, INVALID
, INVALID
,
612 /* [B0] */ INVALID
, INVALID
, INVALID
, INVALID
,
613 /* [B4] */ INVALID
, INVALID
, INVALID
, INVALID
,
614 /* [B8] */ INVALID
, INVALID
, INVALID
, INVALID
,
615 /* [BC] */ INVALID
, INVALID
, INVALID
, INVALID
,
617 /* [C0] */ INVALID
, INVALID
, TNSZ("cmppd",XMMP
,16), INVALID
,
618 /* [C4] */ TNSZ("pinsrw",XMMPRM
,2),TNS("pextrw",XMM3P
), TNSZ("shufpd",XMMP
,16), INVALID
,
619 /* [C8] */ INVALID
, INVALID
, INVALID
, INVALID
,
620 /* [CC] */ INVALID
, INVALID
, INVALID
, INVALID
,
622 /* [D0] */ INVALID
, TNSZ("psrlw",XMM
,16), TNSZ("psrld",XMM
,16), TNSZ("psrlq",XMM
,16),
623 /* [D4] */ TNSZ("paddq",XMM
,16), TNSZ("pmullw",XMM
,16), TNSZ("movq",XMMS
,8), TNS("pmovmskb",XMMX3
),
624 /* [D8] */ TNSZ("psubusb",XMM
,16), TNSZ("psubusw",XMM
,16), TNSZ("pminub",XMM
,16), TNSZ("pand",XMM
,16),
625 /* [DC] */ TNSZ("paddusb",XMM
,16), TNSZ("paddusw",XMM
,16), TNSZ("pmaxub",XMM
,16), TNSZ("pandn",XMM
,16),
627 /* [E0] */ TNSZ("pavgb",XMM
,16), TNSZ("psraw",XMM
,16), TNSZ("psrad",XMM
,16), TNSZ("pavgw",XMM
,16),
628 /* [E4] */ TNSZ("pmulhuw",XMM
,16), TNSZ("pmulhw",XMM
,16), TNSZ("cvttpd2dq",XMM
,16),TNSZ("movntdq",XMMS
,16),
629 /* [E8] */ TNSZ("psubsb",XMM
,16), TNSZ("psubsw",XMM
,16), TNSZ("pminsw",XMM
,16), TNSZ("por",XMM
,16),
630 /* [EC] */ TNSZ("paddsb",XMM
,16), TNSZ("paddsw",XMM
,16), TNSZ("pmaxsw",XMM
,16), TNSZ("pxor",XMM
,16),
632 /* [F0] */ INVALID
, TNSZ("psllw",XMM
,16), TNSZ("pslld",XMM
,16), TNSZ("psllq",XMM
,16),
633 /* [F4] */ TNSZ("pmuludq",XMM
,16), TNSZ("pmaddwd",XMM
,16), TNSZ("psadbw",XMM
,16), TNSZ("maskmovdqu", XMMXIMPL
,16),
634 /* [F8] */ TNSZ("psubb",XMM
,16), TNSZ("psubw",XMM
,16), TNSZ("psubd",XMM
,16), TNSZ("psubq",XMM
,16),
635 /* [FC] */ TNSZ("paddb",XMM
,16), TNSZ("paddw",XMM
,16), TNSZ("paddd",XMM
,16), INVALID
,
639 * Decode table for SIMD instructions with the repnz (0xf2) prefix.
641 const instable_t dis_opSIMDrepnz
[256] = {
642 /* [00] */ INVALID
, INVALID
, INVALID
, INVALID
,
643 /* [04] */ INVALID
, INVALID
, INVALID
, INVALID
,
644 /* [08] */ INVALID
, INVALID
, INVALID
, INVALID
,
645 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
647 /* [10] */ TNSZ("movsd",XMM
,8), TNSZ("movsd",XMMS
,8), INVALID
, INVALID
,
648 /* [14] */ INVALID
, INVALID
, INVALID
, INVALID
,
649 /* [18] */ INVALID
, INVALID
, INVALID
, INVALID
,
650 /* [1C] */ INVALID
, INVALID
, INVALID
, INVALID
,
652 /* [20] */ INVALID
, INVALID
, INVALID
, INVALID
,
653 /* [24] */ INVALID
, INVALID
, INVALID
, INVALID
,
654 /* [28] */ INVALID
, INVALID
, TNSZ("cvtsi2sd",XMM3MX
,4),INVALID
,
655 /* [2C] */ TNSZ("cvttsd2si",XMMXM3
,8),TNSZ("cvtsd2si",XMMXM3
,8),INVALID
, INVALID
,
657 /* [30] */ INVALID
, INVALID
, INVALID
, INVALID
,
658 /* [34] */ INVALID
, INVALID
, INVALID
, INVALID
,
659 /* [38] */ INVALID
, INVALID
, INVALID
, INVALID
,
660 /* [3C] */ INVALID
, INVALID
, INVALID
, INVALID
,
662 /* [40] */ INVALID
, INVALID
, INVALID
, INVALID
,
663 /* [44] */ INVALID
, INVALID
, INVALID
, INVALID
,
664 /* [48] */ INVALID
, INVALID
, INVALID
, INVALID
,
665 /* [4C] */ INVALID
, INVALID
, INVALID
, INVALID
,
667 /* [50] */ INVALID
, TNSZ("sqrtsd",XMM
,8), INVALID
, INVALID
,
668 /* [54] */ INVALID
, INVALID
, INVALID
, INVALID
,
669 /* [58] */ TNSZ("addsd",XMM
,8), TNSZ("mulsd",XMM
,8), TNSZ("cvtsd2ss",XMM
,8), INVALID
,
670 /* [5C] */ TNSZ("subsd",XMM
,8), TNSZ("minsd",XMM
,8), TNSZ("divsd",XMM
,8), TNSZ("maxsd",XMM
,8),
672 /* [60] */ INVALID
, INVALID
, INVALID
, INVALID
,
673 /* [64] */ INVALID
, INVALID
, INVALID
, INVALID
,
674 /* [68] */ INVALID
, INVALID
, INVALID
, INVALID
,
675 /* [6C] */ INVALID
, INVALID
, INVALID
, INVALID
,
677 /* [70] */ TNSZ("pshuflw",XMMP
,16),INVALID
, INVALID
, INVALID
,
678 /* [74] */ INVALID
, INVALID
, INVALID
, INVALID
,
679 /* [78] */ INVALID
, INVALID
, INVALID
, INVALID
,
680 /* [7C] */ INVALID
, INVALID
, INVALID
, INVALID
,
682 /* [80] */ INVALID
, INVALID
, INVALID
, INVALID
,
683 /* [84] */ INVALID
, INVALID
, INVALID
, INVALID
,
684 /* [88] */ INVALID
, INVALID
, INVALID
, INVALID
,
685 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
687 /* [90] */ INVALID
, INVALID
, INVALID
, INVALID
,
688 /* [94] */ INVALID
, INVALID
, INVALID
, INVALID
,
689 /* [98] */ INVALID
, INVALID
, INVALID
, INVALID
,
690 /* [9C] */ INVALID
, INVALID
, INVALID
, INVALID
,
692 /* [A0] */ INVALID
, INVALID
, INVALID
, INVALID
,
693 /* [A4] */ INVALID
, INVALID
, INVALID
, INVALID
,
694 /* [A8] */ INVALID
, INVALID
, INVALID
, INVALID
,
695 /* [AC] */ INVALID
, INVALID
, INVALID
, INVALID
,
697 /* [B0] */ INVALID
, INVALID
, INVALID
, INVALID
,
698 /* [B4] */ INVALID
, INVALID
, INVALID
, INVALID
,
699 /* [B8] */ INVALID
, INVALID
, INVALID
, INVALID
,
700 /* [BC] */ INVALID
, INVALID
, INVALID
, INVALID
,
702 /* [C0] */ INVALID
, INVALID
, TNSZ("cmpsd",XMMP
,8), INVALID
,
703 /* [C4] */ INVALID
, INVALID
, INVALID
, INVALID
,
704 /* [C8] */ INVALID
, INVALID
, INVALID
, INVALID
,
705 /* [CC] */ INVALID
, INVALID
, INVALID
, INVALID
,
707 /* [D0] */ INVALID
, INVALID
, INVALID
, INVALID
,
708 /* [D4] */ INVALID
, INVALID
, TNS("movdq2q",XMMXM
), INVALID
,
709 /* [D8] */ INVALID
, INVALID
, INVALID
, INVALID
,
710 /* [DC] */ INVALID
, INVALID
, INVALID
, INVALID
,
712 /* [E0] */ INVALID
, INVALID
, INVALID
, INVALID
,
713 /* [E4] */ INVALID
, INVALID
, TNSZ("cvtpd2dq",XMM
,16),INVALID
,
714 /* [E8] */ INVALID
, INVALID
, INVALID
, INVALID
,
715 /* [EC] */ INVALID
, INVALID
, INVALID
, INVALID
,
717 /* [F0] */ INVALID
, INVALID
, INVALID
, INVALID
,
718 /* [F4] */ INVALID
, INVALID
, INVALID
, INVALID
,
719 /* [F8] */ INVALID
, INVALID
, INVALID
, INVALID
,
720 /* [FC] */ INVALID
, INVALID
, INVALID
, INVALID
,
724 * Decode table for SIMD instructions with the repz (0xf3) prefix.
726 const instable_t dis_opSIMDrepz
[256] = {
727 /* [00] */ INVALID
, INVALID
, INVALID
, INVALID
,
728 /* [04] */ INVALID
, INVALID
, INVALID
, INVALID
,
729 /* [08] */ INVALID
, INVALID
, INVALID
, INVALID
,
730 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
732 /* [10] */ TNSZ("movss",XMM
,4), TNSZ("movss",XMMS
,4), INVALID
, INVALID
,
733 /* [14] */ INVALID
, INVALID
, INVALID
, INVALID
,
734 /* [18] */ INVALID
, INVALID
, INVALID
, INVALID
,
735 /* [1C] */ INVALID
, INVALID
, INVALID
, INVALID
,
737 /* [20] */ INVALID
, INVALID
, INVALID
, INVALID
,
738 /* [24] */ INVALID
, INVALID
, INVALID
, INVALID
,
739 /* [28] */ INVALID
, INVALID
, TNSZ("cvtsi2ss",XMM3MX
,4),INVALID
,
740 /* [2C] */ TNSZ("cvttss2si",XMMXM3
,4),TNSZ("cvtss2si",XMMXM3
,4),INVALID
, INVALID
,
742 /* [30] */ INVALID
, INVALID
, INVALID
, INVALID
,
743 /* [34] */ INVALID
, INVALID
, INVALID
, INVALID
,
744 /* [38] */ INVALID
, INVALID
, INVALID
, INVALID
,
745 /* [3C] */ INVALID
, INVALID
, INVALID
, INVALID
,
747 /* [40] */ INVALID
, INVALID
, INVALID
, INVALID
,
748 /* [44] */ INVALID
, INVALID
, INVALID
, INVALID
,
749 /* [48] */ INVALID
, INVALID
, INVALID
, INVALID
,
750 /* [4C] */ INVALID
, INVALID
, INVALID
, INVALID
,
752 /* [50] */ INVALID
, TNSZ("sqrtss",XMM
,4), TNSZ("rsqrtss",XMM
,4), TNSZ("rcpss",XMM
,4),
753 /* [54] */ INVALID
, INVALID
, INVALID
, INVALID
,
754 /* [58] */ TNSZ("addss",XMM
,4), TNSZ("mulss",XMM
,4), TNSZ("cvtss2sd",XMM
,4), TNSZ("cvttps2dq",XMM
,16),
755 /* [5C] */ TNSZ("subss",XMM
,4), TNSZ("minss",XMM
,4), TNSZ("divss",XMM
,4), TNSZ("maxss",XMM
,4),
757 /* [60] */ INVALID
, INVALID
, INVALID
, INVALID
,
758 /* [64] */ INVALID
, INVALID
, INVALID
, INVALID
,
759 /* [68] */ INVALID
, INVALID
, INVALID
, INVALID
,
760 /* [6C] */ INVALID
, INVALID
, INVALID
, TNSZ("movdqu",XMM
,16),
762 /* [70] */ TNSZ("pshufhw",XMMP
,16),INVALID
, INVALID
, INVALID
,
763 /* [74] */ INVALID
, INVALID
, INVALID
, INVALID
,
764 /* [78] */ INVALID
, INVALID
, INVALID
, INVALID
,
765 /* [7C] */ INVALID
, INVALID
, TNSZ("movq",XMM
,8), TNSZ("movdqu",XMMS
,16),
767 /* [80] */ INVALID
, INVALID
, INVALID
, INVALID
,
768 /* [84] */ INVALID
, INVALID
, INVALID
, INVALID
,
769 /* [88] */ INVALID
, INVALID
, INVALID
, INVALID
,
770 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
772 /* [90] */ INVALID
, INVALID
, INVALID
, INVALID
,
773 /* [94] */ INVALID
, INVALID
, INVALID
, INVALID
,
774 /* [98] */ INVALID
, INVALID
, INVALID
, INVALID
,
775 /* [9C] */ INVALID
, INVALID
, INVALID
, INVALID
,
777 /* [A0] */ INVALID
, INVALID
, INVALID
, INVALID
,
778 /* [A4] */ INVALID
, INVALID
, INVALID
, INVALID
,
779 /* [A8] */ INVALID
, INVALID
, INVALID
, INVALID
,
780 /* [AC] */ INVALID
, INVALID
, INVALID
, INVALID
,
782 /* [B0] */ INVALID
, INVALID
, INVALID
, INVALID
,
783 /* [B4] */ INVALID
, INVALID
, INVALID
, INVALID
,
784 /* [B8] */ INVALID
, INVALID
, INVALID
, INVALID
,
785 /* [BC] */ INVALID
, INVALID
, INVALID
, INVALID
,
787 /* [C0] */ INVALID
, INVALID
, TNSZ("cmpss",XMMP
,4), INVALID
,
788 /* [C4] */ INVALID
, INVALID
, INVALID
, INVALID
,
789 /* [C8] */ INVALID
, INVALID
, INVALID
, INVALID
,
790 /* [CC] */ INVALID
, INVALID
, INVALID
, INVALID
,
792 /* [D0] */ INVALID
, INVALID
, INVALID
, INVALID
,
793 /* [D4] */ INVALID
, INVALID
, TNS("movq2dq",XMMMX
), INVALID
,
794 /* [D8] */ INVALID
, INVALID
, INVALID
, INVALID
,
795 /* [DC] */ INVALID
, INVALID
, INVALID
, INVALID
,
797 /* [E0] */ INVALID
, INVALID
, INVALID
, INVALID
,
798 /* [E4] */ INVALID
, INVALID
, TNSZ("cvtdq2pd",XMM
,8), INVALID
,
799 /* [E8] */ INVALID
, INVALID
, INVALID
, INVALID
,
800 /* [EC] */ INVALID
, INVALID
, INVALID
, INVALID
,
802 /* [F0] */ INVALID
, INVALID
, INVALID
, INVALID
,
803 /* [F4] */ INVALID
, INVALID
, INVALID
, INVALID
,
804 /* [F8] */ INVALID
, INVALID
, INVALID
, INVALID
,
805 /* [FC] */ INVALID
, INVALID
, INVALID
, INVALID
,
809 * Decode table for 0x0F opcodes
812 const instable_t dis_op0F
[16][16] = {
814 /* [00] */ IND(dis_op0F00
), IND(dis_op0F01
), TNS("lar",MR
), TNS("lsl",MR
),
815 /* [04] */ INVALID
, TNS("syscall",NORM
), TNS("clts",NORM
), TNS("sysret",NORM
),
816 /* [08] */ TNS("invd",NORM
), TNS("wbinvd",NORM
), INVALID
, TNS("ud2",NORM
),
817 /* [0C] */ INVALID
, INVALID
, INVALID
, INVALID
,
819 /* [10] */ TNSZ("movups",XMMO
,16), TNSZ("movups",XMMOS
,16),TNSZ("movlps",XMMO
,8), TNSZ("movlps",XMMOS
,8),
820 /* [14] */ TNSZ("unpcklps",XMMO
,16),TNSZ("unpckhps",XMMO
,16),TNSZ("movhps",XMMOM
,8),TNSZ("movhps",XMMOMS
,8),
821 /* [18] */ IND(dis_op0F18
), INVALID
, INVALID
, INVALID
,
822 /* [1C] */ INVALID
, INVALID
, INVALID
, TS("nop",Mw
),
824 /* [20] */ TSy("mov",SREG
), TSy("mov",SREG
), TSy("mov",SREG
), TSy("mov",SREG
),
825 /* [24] */ TSx("mov",SREG
), INVALID
, TSx("mov",SREG
), INVALID
,
826 /* [28] */ TNSZ("movaps",XMMO
,16), TNSZ("movaps",XMMOS
,16),TNSZ("cvtpi2ps",XMMOMX
,8),TNSZ("movntps",XMMOS
,16),
827 /* [2C] */ TNSZ("cvttps2pi",XMMOXMM
,8),TNSZ("cvtps2pi",XMMOXMM
,8),TNSZ("ucomiss",XMMO
,4),TNSZ("comiss",XMMO
,4),
829 /* [30] */ TNS("wrmsr",NORM
), TNS("rdtsc",NORM
), TNS("rdmsr",NORM
), TNS("rdpmc",NORM
),
830 /* [34] */ TNSx("sysenter",NORM
), TNSx("sysexit",NORM
), INVALID
, INVALID
,
831 /* [38] */ INVALID
, INVALID
, INVALID
, INVALID
,
832 /* [3C] */ INVALID
, INVALID
, INVALID
, INVALID
,
834 /* [40] */ TS("cmovx.o",MR
), TS("cmovx.no",MR
), TS("cmovx.b",MR
), TS("cmovx.ae",MR
),
835 /* [44] */ TS("cmovx.e",MR
), TS("cmovx.ne",MR
), TS("cmovx.be",MR
), TS("cmovx.a",MR
),
836 /* [48] */ TS("cmovx.s",MR
), TS("cmovx.ns",MR
), TS("cmovx.pe",MR
), TS("cmovx.po",MR
),
837 /* [4C] */ TS("cmovx.l",MR
), TS("cmovx.ge",MR
), TS("cmovx.le",MR
), TS("cmovx.g",MR
),
839 /* [50] */ TNS("movmskps",XMMOX3
), TNSZ("sqrtps",XMMO
,16), TNSZ("rsqrtps",XMMO
,16),TNSZ("rcpps",XMMO
,16),
840 /* [54] */ TNSZ("andps",XMMO
,16), TNSZ("andnps",XMMO
,16), TNSZ("orps",XMMO
,16), TNSZ("xorps",XMMO
,16),
841 /* [58] */ TNSZ("addps",XMMO
,16), TNSZ("mulps",XMMO
,16), TNSZ("cvtps2pd",XMMO
,8),TNSZ("cvtdq2ps",XMMO
,16),
842 /* [5C] */ TNSZ("subps",XMMO
,16), TNSZ("minps",XMMO
,16), TNSZ("divps",XMMO
,16), TNSZ("maxps",XMMO
,16),
844 /* [60] */ TNSZ("punpcklbw",MMO
,4),TNSZ("punpcklwd",MMO
,4),TNSZ("punpckldq",MMO
,4),TNSZ("packsswb",MMO
,8),
845 /* [64] */ TNSZ("pcmpgtb",MMO
,8), TNSZ("pcmpgtw",MMO
,8), TNSZ("pcmpgtd",MMO
,8), TNSZ("packuswb",MMO
,8),
846 /* [68] */ TNSZ("punpckhbw",MMO
,8),TNSZ("punpckhwd",MMO
,8),TNSZ("punpckhdq",MMO
,8),TNSZ("packssdw",MMO
,8),
847 /* [6C] */ TNSZ("INVALID",MMO
,0), TNSZ("INVALID",MMO
,0), TNSZ("movd",MMO
,4), TNSZ("movq",MMO
,8),
849 /* [70] */ TNSZ("pshufw",MMOPM
,8), TNS("psrXXX",MR
), TNS("psrXXX",MR
), TNS("psrXXX",MR
),
850 /* [74] */ TNSZ("pcmpeqb",MMO
,8), TNSZ("pcmpeqw",MMO
,8), TNSZ("pcmpeqd",MMO
,8), TNS("emms",NORM
),
851 /* [78] */ INVALID
, INVALID
, INVALID
, INVALID
,
852 /* [7C] */ INVALID
, INVALID
, TNSZ("movd",MMOS
,4), TNSZ("movq",MMOS
,8),
854 /* [80] */ TNS("jo",D
), TNS("jno",D
), TNS("jb",D
), TNS("jae",D
),
855 /* [84] */ TNS("je",D
), TNS("jne",D
), TNS("jbe",D
), TNS("ja",D
),
856 /* [88] */ TNS("js",D
), TNS("jns",D
), TNS("jp",D
), TNS("jnp",D
),
857 /* [8C] */ TNS("jl",D
), TNS("jge",D
), TNS("jle",D
), TNS("jg",D
),
859 /* [90] */ TNS("seto",Mb
), TNS("setno",Mb
), TNS("setb",Mb
), TNS("setae",Mb
),
860 /* [94] */ TNS("sete",Mb
), TNS("setne",Mb
), TNS("setbe",Mb
), TNS("seta",Mb
),
861 /* [98] */ TNS("sets",Mb
), TNS("setns",Mb
), TNS("setp",Mb
), TNS("setnp",Mb
),
862 /* [9C] */ TNS("setl",Mb
), TNS("setge",Mb
), TNS("setle",Mb
), TNS("setg",Mb
),
864 /* [A0] */ TSp("push",LSEG
), TSp("pop",LSEG
), TNS("cpuid",NORM
), TS("bt",RMw
),
865 /* [A4] */ TS("shld",DSHIFT
), TS("shld",DSHIFTcl
), INVALID
, INVALID
,
866 /* [A8] */ TSp("push",LSEG
), TSp("pop",LSEG
), TNS("rsm",NORM
), TS("bts",RMw
),
867 /* [AC] */ TS("shrd",DSHIFT
), TS("shrd",DSHIFTcl
), IND(dis_op0FAE
), TS("imul",MRw
),
869 /* [B0] */ TNS("cmpxchgb",RMw
), TS("cmpxchg",RMw
), TS("lss",MR
), TS("btr",RMw
),
870 /* [B4] */ TS("lfs",MR
), TS("lgs",MR
), TS("movzb",MOVZ
), TNS("movzwl",MOVZ
),
871 /* [B8] */ INVALID
, INVALID
, IND(dis_op0FBA
), TS("btc",RMw
),
872 /* [BC] */ TS("bsf",MRw
), TS("bsr",MRw
), TS("movsb",MOVZ
), TNS("movswl",MOVZ
),
874 /* [C0] */ TNS("xaddb",XADDB
), TS("xadd",RMw
), TNSZ("cmpps",XMMOPM
,16),TNS("movnti",RM
),
875 /* [C4] */ TNSZ("pinsrw",MMOPRM
,2),TNS("pextrw",MMO3P
), TNSZ("shufps",XMMOPM
,16),IND(dis_op0FC7
),
876 /* [C8] */ INVALID
, INVALID
, INVALID
, INVALID
,
877 /* [CC] */ INVALID
, INVALID
, INVALID
, INVALID
,
879 /* [D0] */ INVALID
, TNSZ("psrlw",MMO
,8), TNSZ("psrld",MMO
,8), TNSZ("psrlq",MMO
,8),
880 /* [D4] */ TNSZ("paddq",MMO
,8), TNSZ("pmullw",MMO
,8), TNSZ("INVALID",MMO
,0), TNS("pmovmskb",MMOM3
),
881 /* [D8] */ TNSZ("psubusb",MMO
,8), TNSZ("psubusw",MMO
,8), TNSZ("pminub",MMO
,8), TNSZ("pand",MMO
,8),
882 /* [DC] */ TNSZ("paddusb",MMO
,8), TNSZ("paddusw",MMO
,8), TNSZ("pmaxub",MMO
,8), TNSZ("pandn",MMO
,8),
884 /* [E0] */ TNSZ("pavgb",MMO
,8), TNSZ("psraw",MMO
,8), TNSZ("psrad",MMO
,8), TNSZ("pavgw",MMO
,8),
885 /* [E4] */ TNSZ("pmulhuw",MMO
,8), TNSZ("pmulhw",MMO
,8), TNS("INVALID",XMMO
), TNSZ("movntq",MMOMS
,8),
886 /* [E8] */ TNSZ("psubsb",MMO
,8), TNSZ("psubsw",MMO
,8), TNSZ("pminsw",MMO
,8), TNSZ("por",MMO
,8),
887 /* [EC] */ TNSZ("paddsb",MMO
,8), TNSZ("paddsw",MMO
,8), TNSZ("pmaxsw",MMO
,8), TNSZ("pxor",MMO
,8),
889 /* [F0] */ INVALID
, TNSZ("psllw",MMO
,8), TNSZ("pslld",MMO
,8), TNSZ("psllq",MMO
,8),
890 /* [F4] */ TNSZ("pmuludq",MMO
,8), TNSZ("pmaddwd",MMO
,8), TNSZ("psadbw",MMO
,8), TNSZ("maskmovq",MMOIMPL
,8),
891 /* [F8] */ TNSZ("psubb",MMO
,8), TNSZ("psubw",MMO
,8), TNSZ("psubd",MMO
,8), TNSZ("psubq",MMO
,8),
892 /* [FC] */ TNSZ("paddb",MMO
,8), TNSZ("paddw",MMO
,8), TNSZ("paddd",MMO
,8), INVALID
,
897 * Decode table for 0x80 opcodes
900 const instable_t dis_op80
[8] = {
902 /* [0] */ TNS("addb",IMlw
), TNS("orb",IMw
), TNS("adcb",IMlw
), TNS("sbbb",IMlw
),
903 /* [4] */ TNS("andb",IMw
), TNS("subb",IMlw
), TNS("xorb",IMw
), TNS("cmpb",IMlw
),
908 * Decode table for 0x81 opcodes.
911 const instable_t dis_op81
[8] = {
913 /* [0] */ TS("add",IMlw
), TS("or",IMw
), TS("adc",IMlw
), TS("sbb",IMlw
),
914 /* [4] */ TS("and",IMw
), TS("sub",IMlw
), TS("xor",IMw
), TS("cmp",IMlw
),
919 * Decode table for 0x82 opcodes.
922 const instable_t dis_op82
[8] = {
924 /* [0] */ TNSx("addb",IMlw
), TNSx("orb",IMlw
), TNSx("adcb",IMlw
), TNSx("sbbb",IMlw
),
925 /* [4] */ TNSx("andb",IMlw
), TNSx("subb",IMlw
), TNSx("xorb",IMlw
), TNSx("cmpb",IMlw
),
928 * Decode table for 0x83 opcodes.
931 const instable_t dis_op83
[8] = {
933 /* [0] */ TS("add",IMlw
), TS("or",IMlw
), TS("adc",IMlw
), TS("sbb",IMlw
),
934 /* [4] */ TS("and",IMlw
), TS("sub",IMlw
), TS("xor",IMlw
), TS("cmp",IMlw
),
938 * Decode table for 0xC0 opcodes.
941 const instable_t dis_opC0
[8] = {
943 /* [0] */ TNS("rolb",MvI
), TNS("rorb",MvI
), TNS("rclb",MvI
), TNS("rcrb",MvI
),
944 /* [4] */ TNS("shlb",MvI
), TNS("shrb",MvI
), INVALID
, TNS("sarb",MvI
),
948 * Decode table for 0xD0 opcodes.
951 const instable_t dis_opD0
[8] = {
953 /* [0] */ TNS("rolb",Mv
), TNS("rorb",Mv
), TNS("rclb",Mv
), TNS("rcrb",Mv
),
954 /* [4] */ TNS("shlb",Mv
), TNS("shrb",Mv
), TNS("salb",Mv
), TNS("sarb",Mv
),
958 * Decode table for 0xC1 opcodes.
959 * 186 instruction set
962 const instable_t dis_opC1
[8] = {
964 /* [0] */ TS("rol",MvI
), TS("ror",MvI
), TS("rcl",MvI
), TS("rcr",MvI
),
965 /* [4] */ TS("shl",MvI
), TS("shr",MvI
), TS("sal",MvI
), TS("sar",MvI
),
969 * Decode table for 0xD1 opcodes.
972 const instable_t dis_opD1
[8] = {
974 /* [0] */ TS("rol",Mv
), TS("ror",Mv
), TS("rcl",Mv
), TS("rcr",Mv
),
975 /* [4] */ TS("shl",Mv
), TS("shr",Mv
), TS("sal",Mv
), TS("sar",Mv
),
980 * Decode table for 0xD2 opcodes.
983 const instable_t dis_opD2
[8] = {
985 /* [0] */ TNS("rolb",Mv
), TNS("rorb",Mv
), TNS("rclb",Mv
), TNS("rcrb",Mv
),
986 /* [4] */ TNS("shlb",Mv
), TNS("shrb",Mv
), TNS("salb",Mv
), TNS("sarb",Mv
),
989 * Decode table for 0xD3 opcodes.
992 const instable_t dis_opD3
[8] = {
994 /* [0] */ TS("rol",Mv
), TS("ror",Mv
), TS("rcl",Mv
), TS("rcr",Mv
),
995 /* [4] */ TS("shl",Mv
), TS("shr",Mv
), TS("salb",Mv
), TS("sar",Mv
),
1000 * Decode table for 0xF6 opcodes.
1003 const instable_t dis_opF6
[8] = {
1005 /* [0] */ TNS("testb",IMw
), TNS("testb",IMw
), TNS("notb",Mw
), TNS("negb",Mw
),
1006 /* [4] */ TNS("mulb",MA
), TNS("imulb",MA
), TNS("divb",MA
), TNS("idivb",MA
),
1011 * Decode table for 0xF7 opcodes.
1014 const instable_t dis_opF7
[8] = {
1016 /* [0] */ TS("test",IMw
), TS("test",IMw
), TS("not",Mw
), TS("neg",Mw
),
1017 /* [4] */ TS("mul",MA
), TS("imul",MA
), TS("div",MA
), TS("idiv",MA
),
1022 * Decode table for 0xFE opcodes.
1025 const instable_t dis_opFE
[8] = {
1027 /* [0] */ TNS("incb",Mw
), TNS("decb",Mw
), INVALID
, INVALID
,
1028 /* [4] */ INVALID
, INVALID
, INVALID
, INVALID
,
1031 * Decode table for 0xFF opcodes.
1034 const instable_t dis_opFF
[8] = {
1036 /* [0] */ TS("inc",Mw
), TS("dec",Mw
), TNSyp("call",INM
), TNS("lcall",INM
),
1037 /* [4] */ TNSy("jmp",INM
), TNS("ljmp",INM
), TSp("push",M
), INVALID
,
1040 /* for 287 instructions, which are a mess to decode */
1042 const instable_t dis_opFP1n2
[8][8] = {
1044 /* bit pattern: 1101 1xxx MODxx xR/M */
1045 /* [0,0] */ TNS("fadds",M
), TNS("fmuls",M
), TNS("fcoms",M
), TNS("fcomps",M
),
1046 /* [0,4] */ TNS("fsubs",M
), TNS("fsubrs",M
), TNS("fdivs",M
), TNS("fdivrs",M
),
1048 /* [1,0] */ TNS("flds",M
), INVALID
, TNS("fsts",M
), TNS("fstps",M
),
1049 /* [1,4] */ TNSZ("fldenv",M
,28), TNSZ("fldcw",M
,2), TNSZ("fnstenv",M
,28), TNSZ("fnstcw",M
,2),
1051 /* [2,0] */ TNS("fiaddl",M
), TNS("fimull",M
), TNS("ficoml",M
), TNS("ficompl",M
),
1052 /* [2,4] */ TNS("fisubl",M
), TNS("fisubrl",M
), TNS("fidivl",M
), TNS("fidivrl",M
),
1054 /* [3,0] */ TNS("fildl",M
), INVALID
, TNS("fistl",M
), TNS("fistpl",M
),
1055 /* [3,4] */ INVALID
, TNSZ("fldt",M
,10), INVALID
, TNSZ("fstpt",M
,10),
1057 /* [4,0] */ TNSZ("faddl",M
,8), TNSZ("fmull",M
,8), TNSZ("fcoml",M
,8), TNSZ("fcompl",M
,8),
1058 /* [4,1] */ TNSZ("fsubl",M
,8), TNSZ("fsubrl",M
,8), TNSZ("fdivl",M
,8), TNSZ("fdivrl",M
,8),
1060 /* [5,0] */ TNSZ("fldl",M
,8), INVALID
, TNSZ("fstl",M
,8), TNSZ("fstpl",M
,8),
1061 /* [5,4] */ TNSZ("frstor",M
,108), INVALID
, TNSZ("fnsave",M
,108), TNSZ("fnstsw",M
,2),
1063 /* [6,0] */ TNSZ("fiadd",M
,2), TNSZ("fimul",M
,2), TNSZ("ficom",M
,2), TNSZ("ficomp",M
,2),
1064 /* [6,4] */ TNSZ("fisub",M
,2), TNSZ("fisubr",M
,2), TNSZ("fidiv",M
,2), TNSZ("fidivr",M
,2),
1066 /* [7,0] */ TNSZ("fild",M
,2), INVALID
, TNSZ("fist",M
,2), TNSZ("fistp",M
,2),
1067 /* [7,4] */ TNSZ("fbld",M
,10), TNSZ("fildll",M
,8), TNSZ("fbstp",M
,10), TNSZ("fistpll",M
,8),
1070 const instable_t dis_opFP3
[8][8] = {
1072 /* bit pattern: 1101 1xxx 11xx xREG */
1073 /* [0,0] */ TNS("fadd",FF
), TNS("fmul",FF
), TNS("fcom",F
), TNS("fcomp",F
),
1074 /* [0,4] */ TNS("fsub",FF
), TNS("fsubr",FF
), TNS("fdiv",FF
), TNS("fdivr",FF
),
1076 /* [1,0] */ TNS("fld",F
), TNS("fxch",F
), TNS("fnop",NORM
), TNS("fstp",F
),
1077 /* [1,4] */ INVALID
, INVALID
, INVALID
, INVALID
,
1079 /* [2,0] */ INVALID
, INVALID
, INVALID
, INVALID
,
1080 /* [2,4] */ INVALID
, TNS("fucompp",NORM
), INVALID
, INVALID
,
1082 /* [3,0] */ INVALID
, INVALID
, INVALID
, INVALID
,
1083 /* [3,4] */ INVALID
, INVALID
, INVALID
, INVALID
,
1085 /* [4,0] */ TNS("fadd",FF
), TNS("fmul",FF
), TNS("fcom",F
), TNS("fcomp",F
),
1086 /* [4,4] */ TNS("fsub",FF
), TNS("fsubr",FF
), TNS("fdiv",FF
), TNS("fdivr",FF
),
1088 /* [5,0] */ TNS("ffree",F
), TNS("fxch",F
), TNS("fst",F
), TNS("fstp",F
),
1089 /* [5,4] */ TNS("fucom",F
), TNS("fucomp",F
), INVALID
, INVALID
,
1091 /* [6,0] */ TNS("faddp",FF
), TNS("fmulp",FF
), TNS("fcomp",F
), TNS("fcompp",NORM
),
1092 /* [6,4] */ TNS("fsubp",FF
), TNS("fsubrp",FF
), TNS("fdivp",FF
), TNS("fdivrp",FF
),
1094 /* [7,0] */ TNS("ffreep",F
), TNS("fxch",F
), TNS("fstp",F
), TNS("fstp",F
),
1095 /* [7,4] */ TNS("fnstsw",M
), TNS("fucomip",FFC
), TNS("fcomip",FFC
), INVALID
,
1098 const instable_t dis_opFP4
[4][8] = {
1100 /* bit pattern: 1101 1001 111x xxxx */
1101 /* [0,0] */ TNS("fchs",NORM
), TNS("fabs",NORM
), INVALID
, INVALID
,
1102 /* [0,4] */ TNS("ftst",NORM
), TNS("fxam",NORM
), TNS("ftstp",NORM
), INVALID
,
1104 /* [1,0] */ TNS("fld1",NORM
), TNS("fldl2t",NORM
), TNS("fldl2e",NORM
), TNS("fldpi",NORM
),
1105 /* [1,4] */ TNS("fldlg2",NORM
), TNS("fldln2",NORM
), TNS("fldz",NORM
), INVALID
,
1107 /* [2,0] */ TNS("f2xm1",NORM
), TNS("fyl2x",NORM
), TNS("fptan",NORM
), TNS("fpatan",NORM
),
1108 /* [2,4] */ TNS("fxtract",NORM
), TNS("fprem1",NORM
), TNS("fdecstp",NORM
), TNS("fincstp",NORM
),
1110 /* [3,0] */ TNS("fprem",NORM
), TNS("fyl2xp1",NORM
), TNS("fsqrt",NORM
), TNS("fsincos",NORM
),
1111 /* [3,4] */ TNS("frndint",NORM
), TNS("fscale",NORM
), TNS("fsin",NORM
), TNS("fcos",NORM
),
1114 const instable_t dis_opFP5
[8] = {
1115 /* bit pattern: 1101 1011 111x xxxx */
1116 /* [0] */ TNS("feni",NORM
), TNS("fdisi",NORM
), TNS("fnclex",NORM
), TNS("fninit",NORM
),
1117 /* [4] */ TNS("fsetpm",NORM
), TNS("frstpm",NORM
), INVALID
, INVALID
,
1120 const instable_t dis_opFP6
[8] = {
1121 /* bit pattern: 1101 1011 11yy yxxx */
1122 /* [00] */ TNS("fcmov.nb",FF
), TNS("fcmov.ne",FF
), TNS("fcmov.nbe",FF
), TNS("fcmov.nu",FF
),
1123 /* [04] */ INVALID
, TNS("fucomi",F
), TNS("fcomi",F
), INVALID
,
1126 const instable_t dis_opFP7
[8] = {
1127 /* bit pattern: 1101 1010 11yy yxxx */
1128 /* [00] */ TNS("fcmov.b",FF
), TNS("fcmov.e",FF
), TNS("fcmov.be",FF
), TNS("fcmov.u",FF
),
1129 /* [04] */ INVALID
, INVALID
, INVALID
, INVALID
,
1133 * Main decode table for the op codes. The first two nibbles
1134 * will be used as an index into the table. If there is a
1135 * a need to further decode an instruction, the array to be
1136 * referenced is indicated with the other two entries being
1140 const instable_t dis_distable
[16][16] = {
1142 /* [0,0] */ TNS("addb",RMw
), TS("add",RMw
), TNS("addb",MRw
), TS("add",MRw
),
1143 /* [0,4] */ TNS("addb",IA
), TS("add",IA
), TSx("push",SEG
), TSx("pop",SEG
),
1144 /* [0,8] */ TNS("orb",RMw
), TS("or",RMw
), TNS("orb",MRw
), TS("or",MRw
),
1145 /* [0,C] */ TNS("orb",IA
), TS("or",IA
), TSx("push",SEG
), IND(dis_op0F
),
1147 /* [1,0] */ TNS("adcb",RMw
), TS("adc",RMw
), TNS("adcb",MRw
), TS("adc",MRw
),
1148 /* [1,4] */ TNS("adcb",IA
), TS("adc",IA
), TSx("push",SEG
), TSx("pop",SEG
),
1149 /* [1,8] */ TNS("sbbb",RMw
), TS("sbb",RMw
), TNS("sbbb",MRw
), TS("sbb",MRw
),
1150 /* [1,C] */ TNS("sbbb",IA
), TS("sbb",IA
), TSx("push",SEG
), TSx("pop",SEG
),
1152 /* [2,0] */ TNS("andb",RMw
), TS("and",RMw
), TNS("andb",MRw
), TS("and",MRw
),
1153 /* [2,4] */ TNS("andb",IA
), TS("and",IA
), TNSx("%es:",OVERRIDE
), TNSx("daa",NORM
),
1154 /* [2,8] */ TNS("subb",RMw
), TS("sub",RMw
), TNS("subb",MRw
), TS("sub",MRw
),
1155 /* [2,C] */ TNS("subb",IA
), TS("sub",IA
), TNSx("%cs:",OVERRIDE
), TNSx("das",NORM
),
1157 /* [3,0] */ TNS("xorb",RMw
), TS("xor",RMw
), TNS("xorb",MRw
), TS("xor",MRw
),
1158 /* [3,4] */ TNS("xorb",IA
), TS("xor",IA
), TNSx("%ss:",OVERRIDE
), TNSx("aaa",NORM
),
1159 /* [3,8] */ TNS("cmpb",RMw
), TS("cmp",RMw
), TNS("cmpb",MRw
), TS("cmp",MRw
),
1160 /* [3,C] */ TNS("cmpb",IA
), TS("cmp",IA
), TNSx("%ds:",OVERRIDE
), TNSx("aas",NORM
),
1162 /* [4,0] */ TSx("inc",R
), TSx("inc",R
), TSx("inc",R
), TSx("inc",R
),
1163 /* [4,4] */ TSx("inc",R
), TSx("inc",R
), TSx("inc",R
), TSx("inc",R
),
1164 /* [4,8] */ TSx("dec",R
), TSx("dec",R
), TSx("dec",R
), TSx("dec",R
),
1165 /* [4,C] */ TSx("dec",R
), TSx("dec",R
), TSx("dec",R
), TSx("dec",R
),
1167 /* [5,0] */ TSp("push",R
), TSp("push",R
), TSp("push",R
), TSp("push",R
),
1168 /* [5,4] */ TSp("push",R
), TSp("push",R
), TSp("push",R
), TSp("push",R
),
1169 /* [5,8] */ TSp("pop",R
), TSp("pop",R
), TSp("pop",R
), TSp("pop",R
),
1170 /* [5,C] */ TSp("pop",R
), TSp("pop",R
), TSp("pop",R
), TSp("pop",R
),
1172 /* [6,0] */ TSZx("pusha",IMPLMEM
,28),TSZx("popa",IMPLMEM
,28), TSx("bound",MR
), TNS("arpl",RMw
),
1173 /* [6,4] */ TNS("%fs:",OVERRIDE
), TNS("%gs:",OVERRIDE
), TNS("data16",DM
), TNS("addr16",AM
),
1174 /* [6,8] */ TSp("push",I
), TS("imul",IMUL
), TSp("push",Ib
), TS("imul",IMUL
),
1175 /* [6,C] */ TNSZ("insb",IMPLMEM
,1), TSZ("ins",IMPLMEM
,4), TNSZ("outsb",IMPLMEM
,1),TSZ("outs",IMPLMEM
,4),
1177 /* [7,0] */ TNSy("jo",BD
), TNSy("jno",BD
), TNSy("jb",BD
), TNSy("jae",BD
),
1178 /* [7,4] */ TNSy("je",BD
), TNSy("jne",BD
), TNSy("jbe",BD
), TNSy("ja",BD
),
1179 /* [7,8] */ TNSy("js",BD
), TNSy("jns",BD
), TNSy("jp",BD
), TNSy("jnp",BD
),
1180 /* [7,C] */ TNSy("jl",BD
), TNSy("jge",BD
), TNSy("jle",BD
), TNSy("jg",BD
),
1182 /* [8,0] */ IND(dis_op80
), IND(dis_op81
), INDx(dis_op82
), IND(dis_op83
),
1183 /* [8,4] */ TNS("testb",RMw
), TS("test",RMw
), TNS("xchgb",RMw
), TS("xchg",RMw
),
1184 /* [8,8] */ TNS("movb",RMw
), TS("mov",RMw
), TNS("movb",MRw
), TS("mov",MRw
),
1185 /* [8,C] */ TNS("movw",SM
), TS("lea",MR
), TNS("movw",MS
), TSp("pop",M
),
1187 /* [9,0] */ TNS("nop",NORM
), TS("xchg",RA
), TS("xchg",RA
), TS("xchg",RA
),
1188 /* [9,4] */ TS("xchg",RA
), TS("xchg",RA
), TS("xchg",RA
), TS("xchg",RA
),
1189 /* [9,8] */ TNS("cXtX",CBW
), TNS("cXtX",CWD
), TNSx("lcall",SO
), TNS("fwait",NORM
),
1190 /* [9,C] */ TSZy("pushf",IMPLMEM
,4),TSZy("popf",IMPLMEM
,4), TNSx("sahf",NORM
), TNSx("lahf",NORM
),
1192 /* [A,0] */ TNS("movb",OA
), TS("mov",OA
), TNS("movb",AO
), TS("mov",AO
),
1193 /* [A,4] */ TNSZ("movsb",SD
,1), TS("movs",SD
), TNSZ("cmpsb",SD
,1), TS("cmps",SD
),
1194 /* [A,8] */ TNS("testb",IA
), TS("test",IA
), TNS("stosb",AD
), TS("stos",AD
),
1195 /* [A,C] */ TNS("lodsb",SA
), TS("lods",SA
), TNS("scasb",AD
), TS("scas",AD
),
1197 /* [B,0] */ TNS("movb",IR
), TNS("movb",IR
), TNS("movb",IR
), TNS("movb",IR
),
1198 /* [B,4] */ TNS("movb",IR
), TNS("movb",IR
), TNS("movb",IR
), TNS("movb",IR
),
1199 /* [B,8] */ TS("mov",IR
), TS("mov",IR
), TS("mov",IR
), TS("mov",IR
),
1200 /* [B,C] */ TS("mov",IR
), TS("mov",IR
), TS("mov",IR
), TS("mov",IR
),
1202 /* [C,0] */ IND(dis_opC0
), IND(dis_opC1
), TNSyp("ret",RET
), TNSyp("ret",NORM
),
1203 /* [C,4] */ TNSx("les",MR
), TNSx("lds",MR
), TNS("movb",IMw
), TS("mov",IMw
),
1204 /* [C,8] */ TNSyp("enter",ENTER
), TNSyp("leave",NORM
), TNS("lret",RET
), TNS("lret",NORM
),
1205 /* [C,C] */ TNS("int",INT3
), TNS("int",INTx
), TNSx("into",NORM
), TNS("iret",NORM
),
1207 /* [D,0] */ IND(dis_opD0
), IND(dis_opD1
), IND(dis_opD2
), IND(dis_opD3
),
1208 /* [D,4] */ TNSx("aam",U
), TNSx("aad",U
), TNSx("falc",NORM
), TNSZ("xlat",IMPLMEM
,1),
1210 /* 287 instructions. Note that although the indirect field */
1211 /* indicates opFP1n2 for further decoding, this is not necessarily */
1212 /* the case since the opFP arrays are not partitioned according to key1 */
1213 /* and key2. opFP1n2 is given only to indicate that we haven't */
1214 /* finished decoding the instruction. */
1215 /* [D,8] */ IND(dis_opFP1n2
), IND(dis_opFP1n2
), IND(dis_opFP1n2
), IND(dis_opFP1n2
),
1216 /* [D,C] */ IND(dis_opFP1n2
), IND(dis_opFP1n2
), IND(dis_opFP1n2
), IND(dis_opFP1n2
),
1218 /* [E,0] */ TNSy("loopnz",BD
), TNSy("loopz",BD
), TNSy("loop",BD
), TNSy("jcxz",BD
),
1219 /* [E,4] */ TNS("inb",P
), TS("in",P
), TNS("outb",P
), TS("out",P
),
1220 /* [E,8] */ TNSyp("call",D
), TNSy("jmp",D
), TNSx("ljmp",SO
), TNSy("jmp",BD
),
1221 /* [E,C] */ TNS("inb",V
), TS("in",V
), TNS("outb",V
), TS("out",V
),
1223 /* [F,0] */ TNS("lock",LOCK
), TNS("icebp", NORM
), TNS("repnz",PREFIX
), TNS("repz",PREFIX
),
1224 /* [F,4] */ TNS("hlt",NORM
), TNS("cmc",NORM
), IND(dis_opF6
), IND(dis_opF7
),
1225 /* [F,8] */ TNS("clc",NORM
), TNS("stc",NORM
), TNS("cli",NORM
), TNS("sti",NORM
),
1226 /* [F,C] */ TNS("cld",NORM
), TNS("std",NORM
), IND(dis_opFE
), IND(dis_opFF
),
1232 * common functions to decode and disassemble an x86 or amd64 instruction
1236 * These are the individual fields of a REX prefix. Note that a REX
1237 * prefix with none of these set is still needed to:
1238 * - use the MOVSXD (sign extend 32 to 64 bits) instruction
1239 * - access the %sil, %dil, %bpl, %spl registers
1241 #define REX_W 0x08 /* 64 bit operand size when set */
1242 #define REX_R 0x04 /* high order bit extension of ModRM reg field */
1243 #define REX_X 0x02 /* high order bit extension of SIB index field */
1244 #define REX_B 0x01 /* extends ModRM r_m, SIB base, or opcode reg */
1246 static uint_t opnd_size
; /* SIZE16, SIZE32 or SIZE64 */
1247 static uint_t addr_size
; /* SIZE16, SIZE32 or SIZE64 */
1250 * Even in 64 bit mode, usually only 4 byte immediate operands are supported.
1252 static int isize
[] = {1, 2, 4, 4};
1253 static int isize64
[] = {1, 2, 4, 8};
1256 * Just a bunch of useful macros.
1258 #define WBIT(x) (x & 0x1) /* to get w bit */
1259 #define REGNO(x) (x & 0x7) /* to get 3 bit register */
1260 #define VBIT(x) ((x)>>1 & 0x1) /* to get 'v' bit */
1261 #define OPSIZE(osize, wbit) ((wbit) ? isize[osize] : 1)
1262 #define OPSIZE64(osize, wbit) ((wbit) ? isize64[osize] : 1)
1264 #define REG_ONLY 3 /* mode to indicate a register operand (not memory) */
1266 #define BYTE_OPND 0 /* w-bit value indicating byte register */
1267 #define LONG_OPND 1 /* w-bit value indicating opnd_size register */
1268 #define MM_OPND 2 /* "value" used to indicate a mmx reg */
1269 #define XMM_OPND 3 /* "value" used to indicate a xmm reg */
1270 #define SEG_OPND 4 /* "value" used to indicate a segment reg */
1271 #define CONTROL_OPND 5 /* "value" used to indicate a control reg */
1272 #define DEBUG_OPND 6 /* "value" used to indicate a debug reg */
1273 #define TEST_OPND 7 /* "value" used to indicate a test reg */
1274 #define WORD_OPND 8 /* w-bit value indicating word size reg */
1277 * Get the next byte and separate the op code into the high and low nibbles.
1280 dtrace_get_opcode(dis86_t
*x
, uint_t
*high
, uint_t
*low
)
1285 * x86 instructions have a maximum length of 15 bytes. Bail out if
1286 * we try to read more.
1288 if (x
->d86_len
>= 15)
1289 return (x
->d86_error
= 1);
1293 byte
= x
->d86_get_byte(x
->d86_data
);
1295 return (x
->d86_error
= 1);
1296 x
->d86_bytes
[x
->d86_len
++] = byte
;
1297 *low
= byte
& 0xf; /* ----xxxx low 4 bits */
1298 *high
= byte
>> 4 & 0xf; /* xxxx---- bits 7 to 4 */
1303 * Get and decode an SIB (scaled index base) byte
1306 dtrace_get_SIB(dis86_t
*x
, uint_t
*ss
, uint_t
*index
, uint_t
*base
)
1313 byte
= x
->d86_get_byte(x
->d86_data
);
1318 x
->d86_bytes
[x
->d86_len
++] = byte
;
1321 *index
= (byte
>> 3) & 0x7;
1322 *ss
= (byte
>> 6) & 0x3;
1326 * Get the byte following the op code and separate it into the
1327 * mode, register, and r/m fields.
1330 dtrace_get_modrm(dis86_t
*x
, uint_t
*mode
, uint_t
*reg
, uint_t
*r_m
)
1332 if (x
->d86_got_modrm
== 0) {
1333 if (x
->d86_rmindex
== -1)
1334 x
->d86_rmindex
= x
->d86_len
;
1335 dtrace_get_SIB(x
, mode
, reg
, r_m
);
1336 x
->d86_got_modrm
= 1;
1341 * Adjust register selection based on any REX prefix bits present.
1345 dtrace_rex_adjust(uint_t rex_prefix
, uint_t mode
, uint_t
*reg
, uint_t
*r_m
)
1347 if (reg
!= NULL
&& r_m
== NULL
) {
1348 if (rex_prefix
& REX_B
)
1351 if (reg
!= NULL
&& (REX_R
& rex_prefix
) != 0)
1353 if (r_m
!= NULL
&& (REX_B
& rex_prefix
) != 0)
1359 * Get an immediate operand of the given size, with sign extension.
1362 dtrace_imm_opnd(dis86_t
*x
, int wbit
, int size
, int opindex
)
1368 if (x
->d86_numopnds
< opindex
+ 1)
1369 x
->d86_numopnds
= opindex
+ 1;
1376 if (x
->d86_opnd_size
== SIZE16
)
1378 else if (x
->d86_opnd_size
== SIZE32
)
1400 x
->d86_opnd
[opindex
].d86_value
= 0;
1401 for (i
= 0; i
< size
; ++i
) {
1402 byte
= x
->d86_get_byte(x
->d86_data
);
1407 x
->d86_bytes
[x
->d86_len
++] = byte
;
1408 x
->d86_opnd
[opindex
].d86_value
|= (uint64_t)byte
<< (i
* 8);
1410 /* Do sign extension */
1411 if (x
->d86_bytes
[x
->d86_len
- 1] & 0x80) {
1412 for (; i
< sizeof (uint64_t); i
++)
1413 x
->d86_opnd
[opindex
].d86_value
|=
1414 (uint64_t)0xff << (i
* 8);
1417 x
->d86_opnd
[opindex
].d86_mode
= MODE_SIGNED
;
1418 x
->d86_opnd
[opindex
].d86_value_size
= valsize
;
1419 x
->d86_imm_bytes
+= size
;
1424 * Get an ip relative operand of the given size, with sign extension.
1427 dtrace_disp_opnd(dis86_t
*x
, int wbit
, int size
, int opindex
)
1429 dtrace_imm_opnd(x
, wbit
, size
, opindex
);
1431 x
->d86_opnd
[opindex
].d86_mode
= MODE_IPREL
;
1436 * Check to see if there is a segment override prefix pending.
1437 * If so, print it in the current 'operand' location and set
1438 * the override flag back to false.
1442 dtrace_check_override(dis86_t
*x
, int opindex
)
1445 if (x
->d86_seg_prefix
) {
1446 (void) strlcat(x
->d86_opnd
[opindex
].d86_prefix
,
1447 x
->d86_seg_prefix
, PFIXLEN
);
1450 x
->d86_seg_prefix
= NULL
;
1455 * Process a single instruction Register or Memory operand.
1457 * mode = addressing mode from ModRM byte
1458 * r_m = r_m (or reg if mode == 3) field from ModRM byte
1459 * wbit = indicates which register (8bit, 16bit, ... MMX, etc.) set to use.
1460 * o = index of operand that we are processing (0, 1 or 2)
1462 * the value of reg or r_m must have already been adjusted for any REX prefix.
1466 dtrace_get_operand(dis86_t
*x
, uint_t mode
, uint_t r_m
, int wbit
, int opindex
)
1468 int have_SIB
= 0; /* flag presence of scale-index-byte */
1469 uint_t ss
; /* scale-factor from opcode */
1470 uint_t index
; /* index register number */
1471 uint_t base
; /* base register number */
1472 int dispsize
; /* size of displacement in bytes */
1474 char *opnd
= x
->d86_opnd
[opindex
].d86_opnd
;
1477 if (x
->d86_numopnds
< opindex
+ 1)
1478 x
->d86_numopnds
= opindex
+ 1;
1484 * first handle a simple register
1486 if (mode
== REG_ONLY
) {
1490 (void) strlcat(opnd
, dis_MMREG
[r_m
], OPLEN
);
1493 (void) strlcat(opnd
, dis_XMMREG
[r_m
], OPLEN
);
1496 (void) strlcat(opnd
, dis_SEGREG
[r_m
], OPLEN
);
1499 (void) strlcat(opnd
, dis_CONTROLREG
[r_m
], OPLEN
);
1502 (void) strlcat(opnd
, dis_DEBUGREG
[r_m
], OPLEN
);
1505 (void) strlcat(opnd
, dis_TESTREG
[r_m
], OPLEN
);
1508 if (x
->d86_rex_prefix
== 0)
1509 (void) strlcat(opnd
, dis_REG8
[r_m
], OPLEN
);
1511 (void) strlcat(opnd
, dis_REG8_REX
[r_m
], OPLEN
);
1514 (void) strlcat(opnd
, dis_REG16
[r_m
], OPLEN
);
1517 if (x
->d86_opnd_size
== SIZE16
)
1518 (void) strlcat(opnd
, dis_REG16
[r_m
], OPLEN
);
1519 else if (x
->d86_opnd_size
== SIZE32
)
1520 (void) strlcat(opnd
, dis_REG32
[r_m
], OPLEN
);
1522 (void) strlcat(opnd
, dis_REG64
[r_m
], OPLEN
);
1525 #endif /* DIS_TEXT */
1530 * if symbolic representation, skip override prefix, if any
1532 dtrace_check_override(x
, opindex
);
1535 * Handle 16 bit memory references first, since they decode
1536 * the mode values more simply.
1537 * mode 1 is r_m + 8 bit displacement
1538 * mode 2 is r_m + 16 bit displacement
1539 * mode 0 is just r_m, unless r_m is 6 which is 16 bit disp
1541 if (x
->d86_addr_size
== SIZE16
) {
1542 if ((mode
== 0 && r_m
== 6) || mode
== 2)
1543 dtrace_imm_opnd(x
, WORD_OPND
, 2, opindex
);
1545 dtrace_imm_opnd(x
, BYTE_OPND
, 1, opindex
);
1547 if (mode
== 0 && r_m
== 6)
1548 x
->d86_opnd
[opindex
].d86_mode
= MODE_SIGNED
;
1550 x
->d86_opnd
[opindex
].d86_mode
= MODE_NONE
;
1552 x
->d86_opnd
[opindex
].d86_mode
= MODE_OFFSET
;
1553 (void) strlcat(opnd
, dis_addr16
[mode
][r_m
], OPLEN
);
1559 * 32 and 64 bit addressing modes are more complex since they
1560 * can involve an SIB (scaled index and base) byte to decode.
1562 if (r_m
== ESP_REGNO
|| r_m
== ESP_REGNO
+ 8) {
1564 dtrace_get_SIB(x
, &ss
, &index
, &base
);
1567 if (base
!= 5 || mode
!= 0)
1568 if (x
->d86_rex_prefix
& REX_B
)
1570 if (x
->d86_rex_prefix
& REX_X
)
1577 * Compute the displacement size and get its bytes
1585 else if ((r_m
& 7) == EBP_REGNO
||
1586 (have_SIB
&& (base
& 7) == EBP_REGNO
))
1590 dtrace_imm_opnd(x
, dispsize
== 4 ? LONG_OPND
: BYTE_OPND
,
1598 x
->d86_opnd
[opindex
].d86_mode
= MODE_OFFSET
;
1600 if (have_SIB
== 0) {
1601 if (x
->d86_mode
== SIZE32
) {
1603 (void) strlcat(opnd
, dis_addr32_mode0
[r_m
],
1606 (void) strlcat(opnd
, dis_addr32_mode12
[r_m
],
1610 (void) strlcat(opnd
, dis_addr64_mode0
[r_m
],
1613 x
->d86_opnd
[opindex
].d86_mode
=
1617 (void) strlcat(opnd
, dis_addr64_mode12
[r_m
],
1622 uint_t need_paren
= 0;
1624 if (x
->d86_mode
== SIZE32
) /* NOTE this is not addr_size! */
1625 regs
= (char **)dis_REG32
;
1627 regs
= (char **)dis_REG64
;
1630 * print the base (if any)
1632 if (base
== EBP_REGNO
&& mode
== 0) {
1633 if (index
!= ESP_REGNO
) {
1634 (void) strlcat(opnd
, "(", OPLEN
);
1638 (void) strlcat(opnd
, "(", OPLEN
);
1639 (void) strlcat(opnd
, regs
[base
], OPLEN
);
1644 * print the index (if any)
1646 if (index
!= ESP_REGNO
) {
1647 (void) strlcat(opnd
, ",", OPLEN
);
1648 (void) strlcat(opnd
, regs
[index
], OPLEN
);
1649 (void) strlcat(opnd
, dis_scale_factor
[ss
], OPLEN
);
1652 (void) strlcat(opnd
, ")", OPLEN
);
1658 * Operand sequence for standard instruction involving one register
1659 * and one register/memory operand.
1660 * wbit indicates a byte(0) or opnd_size(1) operation
1661 * vbit indicates direction (0 for "opcode r,r_m") or (1 for "opcode r_m, r")
1663 #define STANDARD_MODRM(x, mode, reg, r_m, rex_prefix, wbit, vbit) { \
1664 dtrace_get_modrm(x, &mode, ®, &r_m); \
1665 dtrace_rex_adjust(rex_prefix, mode, ®, &r_m); \
1666 dtrace_get_operand(x, mode, r_m, wbit, vbit); \
1667 dtrace_get_operand(x, REG_ONLY, reg, wbit, 1 - vbit); \
1671 * Similar to above, but allows for the two operands to be of different
1672 * classes (ie. wbit).
1673 * wbit is for the r_m operand
1674 * w2 is for the reg operand
1676 #define MIXED_MM(x, mode, reg, r_m, rex_prefix, wbit, w2, vbit) { \
1677 dtrace_get_modrm(x, &mode, ®, &r_m); \
1678 dtrace_rex_adjust(rex_prefix, mode, ®, &r_m); \
1679 dtrace_get_operand(x, mode, r_m, wbit, vbit); \
1680 dtrace_get_operand(x, REG_ONLY, reg, w2, 1 - vbit); \
1684 * Similar, but for 2 operands plus an immediate.
1686 #define THREEOPERAND(x, mode, reg, r_m, rex_prefix, wbit, w2, immsize) { \
1687 dtrace_get_modrm(x, &mode, ®, &r_m); \
1688 dtrace_rex_adjust(rex_prefix, mode, ®, &r_m); \
1689 dtrace_get_operand(x, mode, r_m, wbit, 1); \
1690 dtrace_get_operand(x, REG_ONLY, reg, w2, 2); \
1691 dtrace_imm_opnd(x, wbit, immsize, 0); \
1695 * Dissassemble a single x86 or amd64 instruction.
1697 * Mode determines the default operating mode (SIZE16, SIZE32 or SIZE64)
1698 * for interpreting instructions.
1700 * returns non-zero for bad opcode
1703 dtrace_disx86(dis86_t
*x
, uint_t cpu_mode
)
1705 instable_t
*dp
; /* decode table being used */
1711 #define NOMEM (nomem = 1)
1713 #define NOMEM /* nothing */
1715 uint_t wbit
; /* opcode wbit, 0 is 8 bit, !0 for opnd_size */
1716 uint_t w2
; /* wbit value for second operand */
1718 uint_t mode
= 0; /* mode value from ModRM byte */
1719 uint_t reg
; /* reg value from ModRM byte */
1720 uint_t r_m
; /* r_m value from ModRM byte */
1722 uint_t opcode1
; /* high nibble of 1st byte */
1723 uint_t opcode2
; /* low nibble of 1st byte */
1724 uint_t opcode3
; /* extra opcode bits usually from ModRM byte */
1725 uint_t opcode4
; /* high nibble of 2nd byte */
1726 uint_t opcode5
; /* low nibble of 2nd byte */
1727 uint_t opcode6
; /* high nibble of 3rd byte */
1728 uint_t opcode7
; /* low nibble of 3rd byte */
1729 uint_t opcode_bytes
= 1;
1732 * legacy prefixes come in 5 flavors, you should have only one of each
1734 uint_t opnd_size_prefix
= 0;
1735 uint_t addr_size_prefix
= 0;
1736 uint_t segment_prefix
= 0;
1737 uint_t lock_prefix
= 0;
1738 uint_t rep_prefix
= 0;
1739 uint_t rex_prefix
= 0; /* amd64 register extension prefix */
1743 x
->d86_rmindex
= -1;
1746 x
->d86_numopnds
= 0;
1747 x
->d86_seg_prefix
= NULL
;
1749 for (i
= 0; i
< 3; ++i
) {
1750 x
->d86_opnd
[i
].d86_opnd
[0] = 0;
1751 x
->d86_opnd
[i
].d86_prefix
[0] = 0;
1752 x
->d86_opnd
[i
].d86_value_size
= 0;
1753 x
->d86_opnd
[i
].d86_value
= 0;
1754 x
->d86_opnd
[i
].d86_mode
= MODE_NONE
;
1760 if (cpu_mode
== SIZE16
) {
1763 } else if (cpu_mode
== SIZE32
) {
1772 * Get one opcode byte and check for zero padding that follows
1775 if (dtrace_get_opcode(x
, &opcode1
, &opcode2
) != 0)
1778 if (opcode1
== 0 && opcode2
== 0 &&
1779 x
->d86_check_func
!= NULL
&& x
->d86_check_func(x
->d86_data
)) {
1781 (void) strncpy(x
->d86_mnem
, ".byte\t0", OPLEN
);
1787 * Gather up legacy x86 prefix bytes.
1790 uint_t
*which_prefix
= NULL
;
1792 dp
= (instable_t
*)&dis_distable
[opcode1
][opcode2
];
1794 switch (dp
->it_adrmode
) {
1796 which_prefix
= &rep_prefix
;
1799 which_prefix
= &lock_prefix
;
1802 which_prefix
= &segment_prefix
;
1804 x
->d86_seg_prefix
= (char *)dp
->it_name
;
1806 if (dp
->it_invalid64
&& cpu_mode
== SIZE64
)
1810 which_prefix
= &addr_size_prefix
;
1813 which_prefix
= &opnd_size_prefix
;
1816 if (which_prefix
== NULL
)
1818 *which_prefix
= (opcode1
<< 4) | opcode2
;
1819 if (dtrace_get_opcode(x
, &opcode1
, &opcode2
) != 0)
1824 * Handle amd64 mode PREFIX values.
1825 * Some of the segment prefixes are no-ops. (only FS/GS actually work)
1826 * We might have a REX prefix (opcodes 0x40-0x4f)
1828 if (cpu_mode
== SIZE64
) {
1829 if (segment_prefix
!= 0x64 && segment_prefix
!= 0x65)
1832 if (opcode1
== 0x4) {
1833 rex_prefix
= (opcode1
<< 4) | opcode2
;
1834 if (dtrace_get_opcode(x
, &opcode1
, &opcode2
) != 0)
1836 dp
= (instable_t
*)&dis_distable
[opcode1
][opcode2
];
1841 * Deal with selection of operand and address size now.
1842 * Note that the REX.W bit being set causes opnd_size_prefix to be
1845 if (cpu_mode
== SIZE64
) {
1846 if (rex_prefix
& REX_W
)
1848 else if (opnd_size_prefix
)
1851 if (addr_size_prefix
)
1853 } else if (cpu_mode
== SIZE32
) {
1854 if (opnd_size_prefix
)
1856 if (addr_size_prefix
)
1859 if (opnd_size_prefix
)
1861 if (addr_size_prefix
)
1866 * The pause instruction - a repz'd nop. This doesn't fit
1867 * with any of the other prefix goop added for SSE, so we'll
1868 * special-case it here.
1870 if (rep_prefix
== 0xf3 && opcode1
== 0x9 && opcode2
== 0x0) {
1872 dp
= (instable_t
*)&dis_opPause
;
1876 * Some 386 instructions have 2 bytes of opcode before the mod_r/m
1877 * byte so we may need to perform a table indirection.
1879 if (dp
->it_indirect
== (instable_t
*)dis_op0F
) {
1880 if (dtrace_get_opcode(x
, &opcode4
, &opcode5
) != 0)
1883 if (opcode4
== 0x7 && opcode5
>= 0x1 && opcode5
<= 0x3) {
1886 if (dtrace_get_opcode(x
, &opcode6
, &opcode7
) != 0)
1889 subcode
= ((opcode6
& 0x3) << 1) |
1890 ((opcode7
& 0x8) >> 3);
1891 dp
= (instable_t
*)&dis_op0F7123
[opcode5
][subcode
];
1892 } else if ((opcode4
== 0xc) && (opcode5
>= 0x8)) {
1893 dp
= (instable_t
*)&dis_op0FC8
[0];
1895 dp
= (instable_t
*)&dis_op0F
[opcode4
][opcode5
];
1900 * If still not at a TERM decode entry, then a ModRM byte
1901 * exists and its fields further decode the instruction.
1903 x
->d86_got_modrm
= 0;
1904 if (dp
->it_indirect
!= TERM
) {
1905 dtrace_get_modrm(x
, &mode
, &opcode3
, &r_m
);
1911 * decode 287 instructions (D8-DF) from opcodeN
1913 if (opcode1
== 0xD && opcode2
>= 0x8) {
1914 if (opcode2
== 0xB && mode
== 0x3 && opcode3
== 4)
1915 dp
= (instable_t
*)&dis_opFP5
[r_m
];
1916 else if (opcode2
== 0xA && mode
== 0x3 && opcode3
< 4)
1917 dp
= (instable_t
*)&dis_opFP7
[opcode3
];
1918 else if (opcode2
== 0xB && mode
== 0x3)
1919 dp
= (instable_t
*)&dis_opFP6
[opcode3
];
1920 else if (opcode2
== 0x9 && mode
== 0x3 && opcode3
>= 4)
1921 dp
= (instable_t
*)&dis_opFP4
[opcode3
- 4][r_m
];
1922 else if (mode
== 0x3)
1924 &dis_opFP3
[opcode2
- 8][opcode3
];
1927 &dis_opFP1n2
[opcode2
- 8][opcode3
];
1929 dp
= (instable_t
*)dp
->it_indirect
+ opcode3
;
1934 * In amd64 bit mode, ARPL opcode is changed to MOVSXD
1935 * (sign extend 32bit to 64 bit)
1937 if (cpu_mode
== SIZE64
&& opcode1
== 0x6 && opcode2
== 0x3)
1938 dp
= (instable_t
*)&dis_opMOVSLD
;
1941 * at this point we should have a correct (or invalid) opcode
1943 if (cpu_mode
== SIZE64
&& dp
->it_invalid64
||
1944 cpu_mode
!= SIZE64
&& dp
->it_invalid32
)
1946 if (dp
->it_indirect
!= TERM
)
1950 * deal with MMX/SSE opcodes which are changed by prefixes
1952 switch (dp
->it_adrmode
) {
1970 * This is horrible. Some SIMD instructions take the
1971 * form 0x0F 0x?? ..., which is easily decoded using the
1972 * existing tables. Other SIMD instructions use various
1973 * prefix bytes to overload existing instructions. For
1974 * Example, addps is F0, 58, whereas addss is F3 (repz),
1975 * F0, 58. Presumably someone got a raise for this.
1977 * If we see one of the instructions which can be
1978 * modified in this way (if we've got one of the SIMDO*
1979 * address modes), we'll check to see if the last prefix
1980 * was a repz. If it was, we strip the prefix from the
1981 * mnemonic, and we indirect using the dis_opSIMDrepz
1986 * Calculate our offset in dis_op0F
1988 if ((uintptr_t)dp
- (uintptr_t)dis_op0F
> sizeof (dis_op0F
))
1991 off
= ((uintptr_t)dp
- (uintptr_t)dis_op0F
) /
1992 sizeof (instable_t
);
1995 * Rewrite if this instruction used one of the magic prefixes.
1998 if (rep_prefix
== 0xf2)
1999 dp
= (instable_t
*)&dis_opSIMDrepnz
[off
];
2001 dp
= (instable_t
*)&dis_opSIMDrepz
[off
];
2003 } else if (opnd_size_prefix
) {
2004 dp
= (instable_t
*)&dis_opSIMDdata16
[off
];
2005 opnd_size_prefix
= 0;
2006 if (opnd_size
== SIZE16
)
2013 * As with the "normal" SIMD instructions, the MMX
2014 * shuffle instructions are overloaded. These
2015 * instructions, however, are special in that they use
2016 * an extra byte, and thus an extra table. As of this
2017 * writing, they only use the opnd_size prefix.
2021 * Calculate our offset in dis_op0F7123
2023 if ((uintptr_t)dp
- (uintptr_t)dis_op0F7123
>
2024 sizeof (dis_op0F7123
))
2027 if (opnd_size_prefix
) {
2028 off
= ((uintptr_t)dp
- (uintptr_t)dis_op0F7123
) /
2029 sizeof (instable_t
);
2030 dp
= (instable_t
*)&dis_opSIMD7123
[off
];
2031 opnd_size_prefix
= 0;
2032 if (opnd_size
== SIZE16
)
2039 * In 64 bit mode, some opcodes automatically use opnd_size == SIZE64.
2041 if (cpu_mode
== SIZE64
)
2042 if (dp
->it_always64
|| (opnd_size
== SIZE32
&& dp
->it_stackop
))
2047 * At this point most instructions can format the opcode mnemonic
2048 * including the prefixes.
2051 (void) strlcat(x
->d86_mnem
, "lock ", OPLEN
);
2053 if (rep_prefix
== 0xf2)
2054 (void) strlcat(x
->d86_mnem
, "repnz ", OPLEN
);
2055 else if (rep_prefix
== 0xf3)
2056 (void) strlcat(x
->d86_mnem
, "repz ", OPLEN
);
2058 if (cpu_mode
== SIZE64
&& addr_size_prefix
)
2059 (void) strlcat(x
->d86_mnem
, "addr32 ", OPLEN
);
2061 if (dp
->it_adrmode
!= CBW
&&
2062 dp
->it_adrmode
!= CWD
&&
2063 dp
->it_adrmode
!= XMMSFNC
) {
2064 if (strcmp(dp
->it_name
, "INVALID") == 0)
2066 (void) strlcat(x
->d86_mnem
, dp
->it_name
, OPLEN
);
2067 if (dp
->it_suffix
) {
2068 char *types
[] = {"", "w", "l", "q"};
2069 if (opcode_bytes
== 2 && opcode4
== 4) {
2070 /* It's a cmovx.yy. Replace the suffix x */
2071 for (i
= 5; i
< OPLEN
; i
++) {
2072 if (x
->d86_mnem
[i
] == '.')
2075 x
->d86_mnem
[i
- 1] = *types
[opnd_size
];
2077 (void) strlcat(x
->d86_mnem
, types
[opnd_size
],
2085 * Process operands based on the addressing modes.
2087 x
->d86_mode
= cpu_mode
;
2088 x
->d86_rex_prefix
= rex_prefix
;
2089 x
->d86_opnd_size
= opnd_size
;
2090 x
->d86_addr_size
= addr_size
;
2091 vbit
= 0; /* initialize for mem/reg -> reg */
2092 switch (dp
->it_adrmode
) {
2094 * amd64 instruction to sign extend 32 bit reg/mem operands
2095 * into 64 bit register values
2099 if (rex_prefix
== 0)
2100 (void) strncpy(x
->d86_mnem
, "movzld", OPLEN
);
2102 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2103 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2104 x
->d86_opnd_size
= SIZE64
;
2105 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 1);
2106 x
->d86_opnd_size
= opnd_size
= SIZE32
;
2108 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2112 * movsbl movsbw movsbq (0x0FBE) or movswl movswq (0x0FBF)
2113 * movzbl movzbw movzbq (0x0FB6) or movzwl movzwq (0x0FB7)
2114 * wbit lives in 2nd byte, note that operands
2115 * are different sized
2118 if (rex_prefix
& REX_W
) {
2119 /* target register size = 64 bit */
2120 x
->d86_mnem
[5] = 'q';
2122 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2123 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2124 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 1);
2125 x
->d86_opnd_size
= opnd_size
= SIZE16
;
2126 wbit
= WBIT(opcode5
);
2127 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2131 * imul instruction, with either 8-bit or longer immediate
2132 * opcode 0x6B for byte, sign-extended displacement, 0x69 for word(s)
2136 THREEOPERAND(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, LONG_OPND
,
2137 OPSIZE(opnd_size
, opcode2
== 0x9));
2140 /* memory or register operand to register, with 'w' bit */
2142 wbit
= WBIT(opcode2
);
2143 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 0);
2146 /* register to memory or register operand, with 'w' bit */
2147 /* arpl happens to fit here also because it is odd */
2149 if (opcode_bytes
== 2)
2150 wbit
= WBIT(opcode5
);
2152 wbit
= WBIT(opcode2
);
2153 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 1);
2156 /* xaddb instruction */
2159 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 1);
2162 /* MMX register to memory or register operand */
2166 wbit
= strcmp(dp
->it_name
, "movd") ? MM_OPND
: LONG_OPND
;
2170 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, MM_OPND
, 1);
2173 /* MMX register to memory */
2175 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2176 if (mode
== REG_ONLY
)
2179 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, MM_OPND
, 1);
2182 /* Double shift. Has immediate operand specifying the shift. */
2185 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2186 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2187 dtrace_get_operand(x
, mode
, r_m
, wbit
, 2);
2188 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 1);
2189 dtrace_imm_opnd(x
, wbit
, 1, 0);
2193 * Double shift. With no immediate operand, specifies using %cl.
2197 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 1);
2200 /* immediate to memory or register operand */
2202 wbit
= WBIT(opcode2
);
2203 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2204 dtrace_get_operand(x
, mode
, r_m
, wbit
, 1);
2206 * Have long immediate for opcode 0x81, but not 0x80 nor 0x83
2208 dtrace_imm_opnd(x
, wbit
, OPSIZE(opnd_size
, opcode2
== 1), 0);
2211 /* immediate to memory or register operand with the */
2212 /* 'w' bit present */
2214 wbit
= WBIT(opcode2
);
2215 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2216 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2217 dtrace_get_operand(x
, mode
, r_m
, wbit
, 1);
2218 dtrace_imm_opnd(x
, wbit
, OPSIZE(opnd_size
, wbit
), 0);
2221 /* immediate to register with register in low 3 bits */
2224 /* w-bit here (with regs) is bit 3 */
2225 wbit
= opcode2
>>3 & 0x1;
2226 reg
= REGNO(opcode2
);
2227 dtrace_rex_adjust(rex_prefix
, mode
, ®
, NULL
);
2230 dtrace_get_operand(x
, mode
, r_m
, wbit
, 1);
2231 dtrace_imm_opnd(x
, wbit
, OPSIZE64(opnd_size
, wbit
), 0);
2234 /* MMX immediate shift of register */
2238 goto mm_shift
; /* in next case */
2240 /* SIMD immediate shift of register */
2244 reg
= REGNO(opcode7
);
2245 dtrace_rex_adjust(rex_prefix
, mode
, ®
, NULL
);
2246 dtrace_get_operand(x
, REG_ONLY
, reg
, wbit
, 1);
2247 dtrace_imm_opnd(x
, wbit
, 1, 0);
2251 /* accumulator to memory operand */
2256 /* memory operand to accumulator */
2258 wbit
= WBIT(opcode2
);
2259 dtrace_get_operand(x
, REG_ONLY
, EAX_REGNO
, wbit
, 1 - vbit
);
2260 dtrace_imm_opnd(x
, wbit
, OPSIZE64(addr_size
, LONG_OPND
), vbit
);
2262 x
->d86_opnd
[vbit
].d86_mode
= MODE_OFFSET
;
2267 /* segment register to memory or register operand */
2272 /* memory or register operand to segment register */
2274 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2275 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2276 dtrace_get_operand(x
, mode
, r_m
, LONG_OPND
, vbit
);
2277 dtrace_get_operand(x
, REG_ONLY
, reg
, SEG_OPND
, 1 - vbit
);
2281 * rotate or shift instructions, which may shift by 1 or
2282 * consult the cl register, depending on the 'v' bit
2285 vbit
= VBIT(opcode2
);
2286 wbit
= WBIT(opcode2
);
2287 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2288 dtrace_get_operand(x
, mode
, r_m
, wbit
, 1);
2291 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "%cl", OPLEN
);
2293 x
->d86_opnd
[0].d86_mode
= MODE_SIGNED
;
2294 x
->d86_opnd
[0].d86_value_size
= 1;
2295 x
->d86_opnd
[0].d86_value
= 1;
2300 * immediate rotate or shift instructions
2303 wbit
= WBIT(opcode2
);
2305 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2306 dtrace_get_operand(x
, mode
, r_m
, wbit
, 1);
2307 dtrace_imm_opnd(x
, wbit
, 1, 0);
2310 /* bit test instructions */
2313 goto normal_imm_mem
;
2315 /* single memory or register operand with 'w' bit present */
2317 wbit
= WBIT(opcode2
);
2319 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2320 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2321 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2325 if (cpu_mode
== SIZE64
&& mode
== 3 && r_m
== 0) {
2327 (void) strncpy(x
->d86_mnem
, "swapgs", OPLEN
);
2334 /* prefetch instruction - memory operand, but no memory acess */
2339 /* single memory or register operand */
2344 /* single memory or register byte operand */
2350 /* Similar to M, but only memory (no direct registers) */
2352 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2355 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2356 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2359 /* move special register to register or reverse if vbit */
2367 wbit
= CONTROL_OPND
;
2385 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2386 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2387 dtrace_get_operand(x
, REG_ONLY
, reg
, wbit
, vbit
);
2388 dtrace_get_operand(x
, REG_ONLY
, r_m
, LONG_OPND
, 1 - vbit
);
2393 * single register operand with register in the low 3
2397 if (opcode_bytes
== 2)
2398 reg
= REGNO(opcode5
);
2400 reg
= REGNO(opcode2
);
2401 dtrace_rex_adjust(rex_prefix
, mode
, ®
, NULL
);
2402 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 0);
2407 * register to accumulator with register in the low 3
2408 * bits of op code, xchg instructions
2412 reg
= REGNO(opcode2
);
2413 dtrace_rex_adjust(rex_prefix
, mode
, ®
, NULL
);
2414 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 0);
2415 dtrace_get_operand(x
, REG_ONLY
, EAX_REGNO
, LONG_OPND
, 1);
2419 * single segment register operand, with register in
2420 * bits 3-4 of op code byte
2424 reg
= (x
->d86_bytes
[x
->d86_len
- 1] >> 3) & 0x3;
2425 dtrace_get_operand(x
, REG_ONLY
, reg
, SEG_OPND
, 0);
2429 * single segment register operand, with register in
2430 * bits 3-5 of op code
2434 /* long seg reg from opcode */
2435 reg
= (x
->d86_bytes
[x
->d86_len
- 1] >> 3) & 0x7;
2436 dtrace_get_operand(x
, REG_ONLY
, reg
, SEG_OPND
, 0);
2439 /* memory or register operand to register */
2442 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 0);
2447 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 1);
2450 /* MMX/SIMD-Int memory or mm reg to mm reg */
2454 wbit
= strcmp(dp
->it_name
, "movd") ? MM_OPND
: LONG_OPND
;
2458 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, MM_OPND
, 0);
2463 wbit
= strcmp(dp
->it_name
, "movd") ? MM_OPND
: LONG_OPND
;
2467 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2468 if (mode
!= REG_ONLY
)
2471 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2472 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2473 dtrace_get_operand(x
, REG_ONLY
, reg
, MM_OPND
, 1);
2474 mode
= 0; /* change for memory access size... */
2477 /* MMX/SIMD-Int and SIMD-FP predicated mm reg to r32 */
2484 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2485 if (mode
!= REG_ONLY
)
2488 THREEOPERAND(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, LONG_OPND
, 1);
2492 /* MMX/SIMD-Int predicated r32/mem to mm reg */
2501 THREEOPERAND(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, w2
, 1);
2504 /* MMX/SIMD-Int predicated mm/mem to mm reg */
2506 wbit
= w2
= MM_OPND
;
2509 /* MMX/SIMD-Int mm reg to r32 */
2512 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2513 if (mode
!= REG_ONLY
)
2516 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, LONG_OPND
, 0);
2519 /* SIMD memory or xmm reg operand to xmm reg */
2524 STANDARD_MODRM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, 0);
2526 if (dp
->it_adrmode
== XMMXIMPL
&& mode
!= REG_ONLY
)
2531 * movlps and movhlps share opcodes. They differ in the
2532 * addressing modes allowed for their operands.
2533 * movhps and movlhps behave similarly.
2535 if (mode
== REG_ONLY
) {
2536 if (strcmp(dp
->it_name
, "movlps") == 0)
2537 (void) strncpy(x
->d86_mnem
, "movhlps", OPLEN
);
2538 else if (strcmp(dp
->it_name
, "movhps") == 0)
2539 (void) strncpy(x
->d86_mnem
, "movlhps", OPLEN
);
2542 if (dp
->it_adrmode
== XMMXIMPL
)
2543 mode
= 0; /* change for memory access size... */
2546 /* SIMD xmm reg to memory or xmm reg */
2551 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2553 if ((strcmp(dp
->it_name
, "movlps") == 0 ||
2554 strcmp(dp
->it_name
, "movhps") == 0 ||
2555 strcmp(dp
->it_name
, "movntps") == 0) &&
2560 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 1);
2563 /* SIMD memory to xmm reg */
2567 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2569 if (mode
== REG_ONLY
) {
2570 if (strcmp(dp
->it_name
, "movhps") == 0)
2571 (void) strncpy(x
->d86_mnem
, "movlhps", OPLEN
);
2576 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 0);
2579 /* SIMD memory or r32 to xmm reg */
2582 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 0);
2587 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 1);
2590 /* SIMD memory or mm reg to xmm reg */
2592 /* SIMD mm to xmm */
2595 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 0);
2598 /* SIMD memory or xmm reg to mm reg */
2603 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, MM_OPND
, 0);
2607 /* SIMD memory or xmm reg to r32 */
2610 MIXED_MM(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, LONG_OPND
, 0);
2613 /* SIMD xmm to r32 */
2616 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2617 if (mode
!= REG_ONLY
)
2619 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2620 dtrace_get_operand(x
, mode
, r_m
, XMM_OPND
, 0);
2621 dtrace_get_operand(x
, REG_ONLY
, reg
, LONG_OPND
, 1);
2625 /* SIMD predicated memory or xmm reg with/to xmm reg */
2629 THREEOPERAND(x
, mode
, reg
, r_m
, rex_prefix
, wbit
, XMM_OPND
, 1);
2633 * cmpps and cmpss vary their instruction name based
2634 * on the value of imm8. Other XMMP instructions,
2635 * such as shufps, require explicit specification of
2638 if (dp
->it_name
[0] == 'c' &&
2639 dp
->it_name
[1] == 'm' &&
2640 dp
->it_name
[2] == 'p' &&
2641 strlen(dp
->it_name
) == 5) {
2642 uchar_t pred
= x
->d86_opnd
[0].d86_value
& 0xff;
2644 if (pred
>= (sizeof (dis_PREDSUFFIX
) / sizeof (char *)))
2647 (void) strncpy(x
->d86_mnem
, "cmp", OPLEN
);
2648 (void) strlcat(x
->d86_mnem
, dis_PREDSUFFIX
[pred
],
2650 (void) strlcat(x
->d86_mnem
,
2651 dp
->it_name
+ strlen(dp
->it_name
) - 2,
2653 x
->d86_opnd
[0] = x
->d86_opnd
[1];
2654 x
->d86_opnd
[1] = x
->d86_opnd
[2];
2655 x
->d86_numopnds
= 2;
2660 /* immediate operand to accumulator */
2662 wbit
= WBIT(opcode2
);
2663 dtrace_get_operand(x
, REG_ONLY
, EAX_REGNO
, wbit
, 1);
2664 dtrace_imm_opnd(x
, wbit
, OPSIZE(opnd_size
, wbit
), 0);
2668 /* memory or register operand to accumulator */
2670 wbit
= WBIT(opcode2
);
2671 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2672 dtrace_get_operand(x
, mode
, r_m
, wbit
, 0);
2675 /* si register to di register used to reference memory */
2678 dtrace_check_override(x
, 0);
2679 x
->d86_numopnds
= 2;
2680 if (addr_size
== SIZE64
) {
2681 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%rsi)",
2683 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%rdi)",
2685 } else if (addr_size
== SIZE32
) {
2686 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%esi)",
2688 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%edi)",
2691 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%si)",
2693 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%di)",
2700 /* accumulator to di register */
2702 wbit
= WBIT(opcode2
);
2704 dtrace_check_override(x
, 1);
2705 x
->d86_numopnds
= 2;
2706 dtrace_get_operand(x
, REG_ONLY
, EAX_REGNO
, wbit
, 0);
2707 if (addr_size
== SIZE64
)
2708 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%rdi)",
2710 else if (addr_size
== SIZE32
)
2711 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%edi)",
2714 (void) strlcat(x
->d86_opnd
[1].d86_opnd
, "(%di)",
2719 /* si register to accumulator */
2721 wbit
= WBIT(opcode2
);
2723 dtrace_check_override(x
, 0);
2724 x
->d86_numopnds
= 2;
2725 if (addr_size
== SIZE64
)
2726 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%rsi)",
2728 else if (addr_size
== SIZE32
)
2729 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%esi)",
2732 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%si)",
2734 dtrace_get_operand(x
, REG_ONLY
, EAX_REGNO
, wbit
, 1);
2739 * single operand, a 16/32 bit displacement
2743 dtrace_disp_opnd(x
, wbit
, OPSIZE(opnd_size
, LONG_OPND
), 0);
2747 /* jmp/call indirect to memory or register operand */
2750 (void) strlcat(x
->d86_opnd
[0].d86_prefix
, "*", OPLEN
);
2752 dtrace_rex_adjust(rex_prefix
, mode
, NULL
, &r_m
);
2753 dtrace_get_operand(x
, mode
, r_m
, LONG_OPND
, 0);
2758 * for long jumps and long calls -- a new code segment
2759 * register and an offset in IP -- stored in object
2760 * code in reverse order. Note - not valid in amd64
2763 dtrace_check_override(x
, 1);
2765 dtrace_imm_opnd(x
, wbit
, OPSIZE(opnd_size
, LONG_OPND
), 1);
2767 x
->d86_opnd
[1].d86_mode
= MODE_SIGNED
;
2769 /* will now get segment operand */
2770 dtrace_imm_opnd(x
, wbit
, 2, 0);
2774 * jmp/call. single operand, 8 bit displacement.
2775 * added to current EIP in 'compofff'
2778 dtrace_disp_opnd(x
, BYTE_OPND
, 1, 0);
2782 /* single 32/16 bit immediate operand */
2785 dtrace_imm_opnd(x
, wbit
, OPSIZE(opnd_size
, LONG_OPND
), 0);
2788 /* single 8 bit immediate operand */
2791 dtrace_imm_opnd(x
, wbit
, 1, 0);
2796 dtrace_imm_opnd(x
, wbit
, 2, 0);
2797 dtrace_imm_opnd(x
, wbit
, 1, 1);
2798 switch (opnd_size
) {
2800 x
->d86_memsize
= (x
->d86_opnd
[1].d86_value
+ 1) * 8;
2803 x
->d86_memsize
= (x
->d86_opnd
[1].d86_value
+ 1) * 4;
2806 x
->d86_memsize
= (x
->d86_opnd
[1].d86_value
+ 1) * 2;
2812 /* 16-bit immediate operand */
2815 dtrace_imm_opnd(x
, wbit
, 2, 0);
2818 /* single 8 bit port operand */
2820 dtrace_check_override(x
, 0);
2821 dtrace_imm_opnd(x
, BYTE_OPND
, 1, 0);
2825 /* single operand, dx register (variable port instruction) */
2827 x
->d86_numopnds
= 1;
2828 dtrace_check_override(x
, 0);
2830 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "(%dx)", OPLEN
);
2836 * The int instruction, which has two forms:
2837 * int 3 (breakpoint) or
2838 * int n, where n is indicated in the subsequent
2839 * byte (format Ib). The int 3 instruction (opcode 0xCC),
2840 * where, although the 3 looks like an operand,
2841 * it is implied by the opcode. It must be converted
2842 * to the correct base and output.
2846 x
->d86_numopnds
= 1;
2847 x
->d86_opnd
[0].d86_mode
= MODE_SIGNED
;
2848 x
->d86_opnd
[0].d86_value_size
= 1;
2849 x
->d86_opnd
[0].d86_value
= 3;
2854 /* single 8 bit immediate operand */
2856 dtrace_imm_opnd(x
, BYTE_OPND
, 1, 0);
2860 /* an unused byte must be discarded */
2862 if (x
->d86_get_byte(x
->d86_data
) < 0)
2870 if (opnd_size
== SIZE16
)
2871 (void) strlcat(x
->d86_mnem
, "cbtw", OPLEN
);
2872 else if (opnd_size
== SIZE32
)
2873 (void) strlcat(x
->d86_mnem
, "cwtl", OPLEN
);
2875 (void) strlcat(x
->d86_mnem
, "cltq", OPLEN
);
2883 if (opnd_size
== SIZE16
)
2884 (void) strlcat(x
->d86_mnem
, "cwtd", OPLEN
);
2885 else if (opnd_size
== SIZE32
)
2886 (void) strlcat(x
->d86_mnem
, "cltd", OPLEN
);
2888 (void) strlcat(x
->d86_mnem
, "cqtd", OPLEN
);
2896 * sfence is sfence if mode is REG_ONLY. If mode isn't
2897 * REG_ONLY, mnemonic should be 'clflush'.
2899 dtrace_get_modrm(x
, &mode
, ®
, &r_m
);
2901 /* sfence doesn't take operands */
2903 if (mode
== REG_ONLY
) {
2904 (void) strlcat(x
->d86_mnem
, "sfence", OPLEN
);
2906 (void) strlcat(x
->d86_mnem
, "clflush", OPLEN
);
2907 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2908 dtrace_get_operand(x
, mode
, r_m
, BYTE_OPND
, 0);
2912 if (mode
!= REG_ONLY
) {
2913 dtrace_rex_adjust(rex_prefix
, mode
, ®
, &r_m
);
2914 dtrace_get_operand(x
, mode
, r_m
, BYTE_OPND
, 0);
2921 * no disassembly, the mnemonic was all there was so go on
2924 if (dp
->it_invalid32
&& cpu_mode
!= SIZE64
)
2933 * Only the following exact byte sequences are allowed:
2938 if ((uint8_t)x
->d86_bytes
[x
->d86_len
- 1] != 0xe8 &&
2939 (uint8_t)x
->d86_bytes
[x
->d86_len
- 1] != 0xf0)
2948 x
->d86_numopnds
= 1;
2949 (void) strlcat(x
->d86_opnd
[0].d86_opnd
, "%st(X)", OPLEN
);
2950 x
->d86_opnd
[0].d86_opnd
[4] = r_m
+ '0';
2955 /* float reg to float reg, with ret bit present */
2957 vbit
= opcode2
>> 2 & 0x1; /* vbit = 1: st -> st(i) */
2959 case FFC
: /* case for vbit always = 0 */
2961 x
->d86_numopnds
= 2;
2962 (void) strlcat(x
->d86_opnd
[1 - vbit
].d86_opnd
, "%st", OPLEN
);
2963 (void) strlcat(x
->d86_opnd
[vbit
].d86_opnd
, "%st(X)", OPLEN
);
2964 x
->d86_opnd
[vbit
].d86_opnd
[4] = r_m
+ '0';
2969 /* an invalid op code */
2985 * compute the size of any memory accessed by the instruction
2987 if (x
->d86_memsize
!= 0) {
2989 } else if (dp
->it_stackop
) {
2990 switch (opnd_size
) {
3001 } else if (nomem
|| mode
== REG_ONLY
) {
3004 } else if (dp
->it_size
!= 0) {
3006 * In 64 bit mode descriptor table entries
3007 * go up to 10 bytes and popf/pushf are always 8 bytes
3009 if (x
->d86_mode
== SIZE64
&& dp
->it_size
== 6)
3010 x
->d86_memsize
= 10;
3011 else if (x
->d86_mode
== SIZE64
&& opcode1
== 0x9 &&
3012 (opcode2
== 0xc || opcode2
== 0xd))
3015 x
->d86_memsize
= dp
->it_size
;
3017 } else if (wbit
== 0) {
3020 } else if (wbit
== LONG_OPND
) {
3021 if (opnd_size
== SIZE64
)
3023 else if (opnd_size
== SIZE32
)
3028 } else if (wbit
== SEG_OPND
) {
3039 (void) strlcat(x
->d86_mnem
, "undef", OPLEN
);
3047 * Some instructions should have immediate operands printed
3048 * as unsigned integers. We compare against this table.
3050 static char *unsigned_ops
[] = {
3051 "or", "and", "xor", "test", "in", "out", "lcall", "ljmp",
3052 "rcr", "rcl", "ror", "rol", "shl", "shr", "sal", "psr", "psl",
3058 isunsigned_op(char *opcode
)
3062 int is_unsigned
= 0;
3065 * Work back to start of last mnemonic, since we may have
3066 * prefixes on some opcodes.
3068 where
= opcode
+ strlen(opcode
) - 1;
3069 while (where
> opcode
&& *where
!= ' ')
3074 for (i
= 0; unsigned_ops
[i
]; ++i
) {
3075 if (strncmp(where
, unsigned_ops
[i
],
3076 strlen(unsigned_ops
[i
])))
3081 return (is_unsigned
);
3085 * Print a numeric immediate into end of buf, maximum length buflen.
3086 * The immediate may be an address or a displacement. Mask is set
3087 * for address size. If the immediate is a "small negative", or
3088 * if it's a negative displacement of any magnitude, print as -<absval>.
3089 * Respect the "octal" flag. "Small negative" is defined as "in the
3090 * interval [NEG_LIMIT, 0)".
3092 * Also, "isunsigned_op()" instructions never print negatives.
3094 * Return whether we decided to print a negative value or not.
3097 #define NEG_LIMIT -255
3099 enum {POS
, TRY_NEG
};
3102 print_imm(dis86_t
*dis
, uint64_t usv
, uint64_t mask
, char *buf
,
3103 size_t buflen
, int disp
, int try_neg
)
3106 int64_t sv
= (int64_t)usv
;
3107 int octal
= dis
->d86_flags
& DIS_F_OCTAL
;
3109 curlen
= strlen(buf
);
3111 if (try_neg
== TRY_NEG
&& sv
< 0 &&
3112 (disp
|| sv
>= NEG_LIMIT
) &&
3113 !isunsigned_op(dis
->d86_mnem
)) {
3114 dis
->d86_sprintf_func(buf
+ curlen
, buflen
- curlen
,
3115 octal
? "-0%llo" : "-0x%llx", (-sv
) & mask
);
3119 dis
->d86_sprintf_func(buf
+ curlen
, buflen
- curlen
,
3120 octal
? "+0%llo" : "+0x%llx", usv
& mask
);
3122 dis
->d86_sprintf_func(buf
+ curlen
, buflen
- curlen
,
3123 octal
? "0%llo" : "0x%llx", usv
& mask
);
3144 dtrace_disx86_str(dis86_t
*dis
, uint_t mode
, uint64_t pc
, char *buf
,
3147 uint64_t reltgt
= 0;
3150 int (*lookup
)(void *, uint64_t, char *, size_t);
3153 uint64_t usv
, mask
, save_mask
, save_usv
;
3154 static uint64_t masks
[] =
3155 {0xffU
, 0xffffU
, 0xffffffffU
, 0xffffffffffffffffULL
};
3158 dis
->d86_sprintf_func(buf
, buflen
, "%-6s ", dis
->d86_mnem
);
3161 * For PC-relative jumps, the pc is really the next pc after executing
3162 * this instruction, so increment it appropriately.
3166 for (i
= 0; i
< dis
->d86_numopnds
; i
++) {
3167 d86opnd_t
*op
= &dis
->d86_opnd
[i
];
3170 (void) strlcat(buf
, ",", buflen
);
3172 (void) strlcat(buf
, op
->d86_prefix
, buflen
);
3175 * sv is for the signed, possibly-truncated immediate or
3176 * displacement; usv retains the original size and
3177 * unsignedness for symbol lookup.
3180 sv
= usv
= op
->d86_value
;
3183 * About masks: for immediates that represent
3184 * addresses, the appropriate display size is
3185 * the effective address size of the instruction.
3186 * This includes MODE_OFFSET, MODE_IPREL, and
3187 * MODE_RIPREL. Immediates that are simply
3188 * immediate values should display in the operand's
3189 * size, however, since they don't represent addresses.
3192 /* d86_addr_size is SIZEnn, which is log2(real size) */
3193 mask
= masks
[dis
->d86_addr_size
];
3195 /* d86_value_size and d86_imm_bytes are in bytes */
3196 if (op
->d86_mode
== MODE_SIGNED
||
3197 op
->d86_mode
== MODE_IMPLIED
)
3198 mask
= masks
[log2(op
->d86_value_size
)];
3200 switch (op
->d86_mode
) {
3204 (void) strlcat(buf
, op
->d86_opnd
, buflen
);
3213 if (dis
->d86_seg_prefix
)
3214 (void) strlcat(buf
, dis
->d86_seg_prefix
,
3217 if (op
->d86_mode
== MODE_SIGNED
||
3218 op
->d86_mode
== MODE_IMPLIED
) {
3219 (void) strlcat(buf
, "$", buflen
);
3222 if (print_imm(dis
, usv
, mask
, buf
, buflen
,
3224 (op
->d86_mode
== MODE_SIGNED
||
3225 op
->d86_mode
== MODE_IMPLIED
)) {
3228 * We printed a negative value for an
3229 * immediate that wasn't a
3230 * displacement. Note that fact so we can
3231 * print the positive value as an
3238 (void) strlcat(buf
, op
->d86_opnd
, buflen
);
3249 reltgt
= (uint16_t)reltgt
;
3252 reltgt
= (uint32_t)reltgt
;
3256 (void) print_imm(dis
, usv
, mask
, buf
, buflen
,
3259 if (op
->d86_mode
== MODE_RIPREL
)
3260 (void) strlcat(buf
, "(%rip)", buflen
);
3266 * The symbol lookups may result in false positives,
3267 * particularly on object files, where small numbers may match
3268 * the 0-relative non-relocated addresses of symbols.
3271 lookup
= dis
->d86_sym_lookup
;
3273 /* Print symbol, if found, for tgt */
3274 if (lookup(dis
->d86_data
, tgt
, NULL
, 0) == 0) {
3275 (void) strlcat(buf
, "\t<", buflen
);
3276 curlen
= strlen(buf
);
3277 lookup(dis
->d86_data
, tgt
, buf
+ curlen
,
3279 (void) strlcat(buf
, ">", buflen
);
3283 * If we printed a negative immediate above, print the
3284 * positive in case our heuristic was unhelpful
3287 (void) strlcat(buf
, "\t<", buflen
);
3288 (void) print_imm(dis
, save_usv
, save_mask
, buf
, buflen
,
3290 (void) strlcat(buf
, ">", buflen
);
3295 /* Print symbol or effective address for reltgt */
3297 (void) strlcat(buf
, "\t<", buflen
);
3298 curlen
= strlen(buf
);
3299 lookup(dis
->d86_data
, reltgt
, buf
+ curlen
,
3301 (void) strlcat(buf
, ">", buflen
);
3305 #endif /* DIS_TEXT */