Debian Codegraph @

arch/X86/X86DisassemblerDecoder.c

raw symbols SCIP
1 /*===-- X86DisassemblerDecoder.c - Disassembler decoder ------------*- C -*-===*
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
7 *
8 *===----------------------------------------------------------------------===*
9 *
10 * This file is part of the X86 Disassembler.
11 * It contains the implementation of the instruction decoder.
12 * Documentation for the disassembler can be found in X86Disassembler.h.
13 *
14 *===----------------------------------------------------------------------===*/
15
16 /* Capstone Disassembly Engine */
17 /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */
18
19 #ifdef CAPSTONE_HAS_X86cxx . . $ `<built-in>:420:9`!
20
21 #include <stdarg.h> /* for va_*() */
22 #if defined(CAPSTONE_HAS_OSXKERNEL)
23 #include <libkern/libkern.h>
24 #else
25 #include <stdlib.h> /* for exit() */
26 #endif
27
28 #include <string.h>
29
30 #include "../../cs_priv.h"cxx . . $ `<file>/cs_priv.h`/
31 #include "../../utils.h"cxx . . $ `<file>/utils.h`/
32
33 #include "X86DisassemblerDecoder.h"cxx . . $ `<file>/arch/X86/X86DisassemblerDecoder.h`/
34 #include "X86Mapping.h"cxx . . $ `<file>/arch/X86/X86Mapping.h`/
35
36 /// Specifies whether a ModR/M byte is needed and (if so) which
37 /// instruction each possible value of the ModR/M byte corresponds to. Once
38 /// this information is known, we have narrowed down to a single instruction.
39 struct ModRMDecisioncxx . . $ ModRMDecision# {
40 uint8_tcxx . . $ uint8_t# modrm_typecxx . . $ ModRMDecision#modrm_type.;
41 uint16_tcxx . . $ uint16_t# instructionIDscxx . . $ ModRMDecision#instructionIDs.;
42 };
43
44 /// Specifies which set of ModR/M->instruction tables to look at
45 /// given a particular opcode.
46 struct OpcodeDecisioncxx . . $ OpcodeDecision# {
47 struct ModRMDecisioncxx . . $ ModRMDecision# modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[256];
48 };
49
50 /// Specifies which opcode->instruction tables to look at given
51 /// a particular context (set of attributes). Since there are many possible
52 /// contexts, the decoder first uses CONTEXTS_SYM to determine which context
53 /// applies given a specific set of attributes. Hence there are only IC_max
54 /// entries in this table, rather than 2^(ATTR_max).
55 struct ContextDecisioncxx . . $ ContextDecision# {
56 struct OpcodeDecisioncxx . . $ OpcodeDecision# opcodeDecisionscxx . . $ ContextDecision#opcodeDecisions.[IC_maxcxx . . $ IC_max.];
57 };
58
59 #ifdef CAPSTONE_X86_REDUCE
60 #include "X86GenDisassemblerTables_reduce.inc"
61 #include "X86GenDisassemblerTables_reduce2.inc"
62 #include "X86Lookup16_reduce.inc"
63 #else
64 #include "X86GenDisassemblerTables.inc"cxx . . $ `<file>/arch/X86/X86GenDisassemblerTables.inc`/
65 #include "X86GenDisassemblerTables2.inc"cxx . . $ `<file>/arch/X86/X86GenDisassemblerTables2.inc`/
66 #include "X86Lookup16.inc"cxx . . $ `<file>/arch/X86/X86Lookup16.inc`/
67 #endif
68
69 /*
70 * contextForAttrs - Client for the instruction context table. Takes a set of
71 * attributes and returns the appropriate decode context.
72 *
73 * @param attrMask - Attributes, from the enumeration attributeBits.
74 * @return - The InstructionContext to use when looking up an
75 * an instruction with these attributes.
76 */
77 static InstructionContextcxx . . $ InstructionContext# contextForAttrscxx . . $ contextForAttrs(af141ee81a9fd4e).(uint16_tcxx . . $ uint16_t# attrMask)
78 {
79 return CONTEXTS_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:29:9`![attrMask];
80 }
81
82 /*
83 * modRMRequired - Reads the appropriate instruction table to determine whether
84 * the ModR/M byte is required to decode a particular instruction.
85 *
86 * @param type - The opcode type (i.e., how many bytes it has).
87 * @param insnContext - The context for the instruction, as returned by
88 * contextForAttrs.
89 * @param opcode - The last byte of the instruction's opcode, not counting
90 * ModR/M extensions and escapes.
91 * @return - true if the ModR/M byte is required, false otherwise.
92 */
93 static int modRMRequiredcxx . . $ modRMRequired(5af57ec56d559bcc).(OpcodeTypecxx . . $ OpcodeType# type,
94 InstructionContextcxx . . $ InstructionContext# insnContext,
95 uint16_tcxx . . $ uint16_t# opcode)
96 {
97 const struct OpcodeDecisioncxx . . $ OpcodeDecision# *decision = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
98 const uint8_tcxx . . $ uint8_t# *indextable = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
99 unsigned int index;
100
101 switch (type) {
102 default:
103 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
104 case ONEBYTEcxx . . $ ONEBYTE.:
105 decision = ONEBYTE_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:30:9`!;
106 indextable = index_x86DisassemblerOneByteOpcodescxx . . $ index_x86DisassemblerOneByteOpcodes.;
107 break;
108 case TWOBYTEcxx . . $ TWOBYTE.:
109 decision = TWOBYTE_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:31:9`!;
110 indextable = index_x86DisassemblerTwoByteOpcodescxx . . $ index_x86DisassemblerTwoByteOpcodes.;
111 break;
112 case THREEBYTE_38cxx . . $ THREEBYTE_38.:
113 decision = THREEBYTE38_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:32:9`!;
114 indextable = index_x86DisassemblerThreeByte38Opcodescxx . . $ index_x86DisassemblerThreeByte38Opcodes.;
115 break;
116 case THREEBYTE_3Acxx . . $ THREEBYTE_3A.:
117 decision = THREEBYTE3A_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:33:9`!;
118 indextable = index_x86DisassemblerThreeByte3AOpcodescxx . . $ index_x86DisassemblerThreeByte3AOpcodes.;
119 break;
120 #ifndef CAPSTONE_X86_REDUCE
121 case XOP8_MAPcxx . . $ XOP8_MAP.:
122 decision = XOP8_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:34:9`!;
123 indextable = index_x86DisassemblerXOP8Opcodescxx . . $ index_x86DisassemblerXOP8Opcodes.;
124 break;
125 case XOP9_MAPcxx . . $ XOP9_MAP.:
126 decision = XOP9_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:35:9`!;
127 indextable = index_x86DisassemblerXOP9Opcodescxx . . $ index_x86DisassemblerXOP9Opcodes.;
128 break;
129 case XOPA_MAPcxx . . $ XOPA_MAP.:
130 decision = XOPA_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:36:9`!;
131 indextable = index_x86DisassemblerXOPAOpcodescxx . . $ index_x86DisassemblerXOPAOpcodes.;
132 break;
133 case THREEDNOW_MAPcxx . . $ THREEDNOW_MAP.:
134 // 3DNow instructions always have ModRM byte
135 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
136 #endif
137 }
138
139 // return decision->opcodeDecisions[insnContext].modRMDecisions[opcode].modrm_type != MODRM_ONEENTRY;
140 index = indextable[insnContext];
141 if (index)
142 return decision[index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode].modrm_typecxx . . $ ModRMDecision#modrm_type. != MODRM_ONEENTRYcxx . . $ MODRM_ONEENTRY.;
143 else
144 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
145 }
146
147 /*
148 * decode - Reads the appropriate instruction table to obtain the unique ID of
149 * an instruction.
150 *
151 * @param type - See modRMRequired().
152 * @param insnContext - See modRMRequired().
153 * @param opcode - See modRMRequired().
154 * @param modRM - The ModR/M byte if required, or any value if not.
155 * @return - The UID of the instruction, or 0 on failure.
156 */
157 static InstrUIDcxx . . $ InstrUID# decodecxx . . $ decode(107233116c3734c6).(OpcodeTypecxx . . $ OpcodeType# type,
158 InstructionContextcxx . . $ InstructionContext# insnContext,
159 uint8_tcxx . . $ uint8_t# opcode,
160 uint8_tcxx . . $ uint8_t# modRM)
161 {
162 const struct ModRMDecisioncxx . . $ ModRMDecision# *dec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
163 unsigned int index;
164 static const struct OpcodeDecisioncxx . . $ OpcodeDecision# emptyDecision = { 0 };
165
166 switch (type) {
167 default:
168 return 0;
169 case ONEBYTEcxx . . $ ONEBYTE.:
170 // dec = &ONEBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
171 index = index_x86DisassemblerOneByteOpcodescxx . . $ index_x86DisassemblerOneByteOpcodes.[insnContext];
172 if (index)
173 dec = &ONEBYTE_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:30:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
174 else
175 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
176 break;
177 case TWOBYTEcxx . . $ TWOBYTE.:
178 //dec = &TWOBYTE_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
179 index = index_x86DisassemblerTwoByteOpcodescxx . . $ index_x86DisassemblerTwoByteOpcodes.[insnContext];
180 if (index)
181 dec = &TWOBYTE_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:31:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
182 else
183 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
184 break;
185 case THREEBYTE_38cxx . . $ THREEBYTE_38.:
186 // dec = &THREEBYTE38_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
187 index = index_x86DisassemblerThreeByte38Opcodescxx . . $ index_x86DisassemblerThreeByte38Opcodes.[insnContext];
188 if (index)
189 dec = &THREEBYTE38_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:32:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
190 else
191 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
192 break;
193 case THREEBYTE_3Acxx . . $ THREEBYTE_3A.:
194 //dec = &THREEBYTE3A_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
195 index = index_x86DisassemblerThreeByte3AOpcodescxx . . $ index_x86DisassemblerThreeByte3AOpcodes.[insnContext];
196 if (index)
197 dec = &THREEBYTE3A_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:33:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
198 else
199 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
200 break;
201 #ifndef CAPSTONE_X86_REDUCE
202 case XOP8_MAPcxx . . $ XOP8_MAP.:
203 // dec = &XOP8_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
204 index = index_x86DisassemblerXOP8Opcodescxx . . $ index_x86DisassemblerXOP8Opcodes.[insnContext];
205 if (index)
206 dec = &XOP8_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:34:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
207 else
208 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
209 break;
210 case XOP9_MAPcxx . . $ XOP9_MAP.:
211 // dec = &XOP9_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
212 index = index_x86DisassemblerXOP9Opcodescxx . . $ index_x86DisassemblerXOP9Opcodes.[insnContext];
213 if (index)
214 dec = &XOP9_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:35:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
215 else
216 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
217 break;
218 case XOPA_MAPcxx . . $ XOPA_MAP.:
219 // dec = &XOPA_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
220 index = index_x86DisassemblerXOPAOpcodescxx . . $ index_x86DisassemblerXOPAOpcodes.[insnContext];
221 if (index)
222 dec = &XOPA_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:36:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
223 else
224 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
225 break;
226 case THREEDNOW_MAPcxx . . $ THREEDNOW_MAP.:
227 // dec = &THREEDNOW_MAP_SYM.opcodeDecisions[insnContext].modRMDecisions[opcode];
228 index = index_x86Disassembler3DNowOpcodescxx . . $ index_x86Disassembler3DNowOpcodes.[insnContext];
229 if (index)
230 dec = &THREEDNOW_MAP_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:37:9`![index - 1].modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
231 else
232 dec = &emptyDecision.modRMDecisionscxx . . $ OpcodeDecision#modRMDecisions.[opcode];
233 break;
234 #endif
235 }
236
237 switch (dec->modrm_typecxx . . $ ModRMDecision#modrm_type.) {
238 default:
239 // debug("Corrupt table! Unknown modrm_type");
240 return 0;
241 case MODRM_ONEENTRYcxx . . $ MODRM_ONEENTRY.:
242 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.];
243 case MODRM_SPLITRMcxx . . $ MODRM_SPLITRM.:
244 if (modFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:33:9`!(modRM) == 0x3)
245 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs. + 1];
246 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.];
247 case MODRM_SPLITREGcxx . . $ MODRM_SPLITREG.:
248 if (modFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:33:9`!(modRM) == 0x3)
249 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.+((modRM & 0x38) >> 3) + 8];
250 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.+((modRM & 0x38) >> 3)];
251 case MODRM_SPLITMISCcxx . . $ MODRM_SPLITMISC.:
252 if (modFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:33:9`!(modRM) == 0x3)
253 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.+(modRM & 0x3f) + 8];
254 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.+((modRM & 0x38) >> 3)];
255 case MODRM_FULLcxx . . $ MODRM_FULL.:
256 return modRMTablecxx . . $ modRMTable.[dec->instructionIDscxx . . $ ModRMDecision#instructionIDs.+modRM];
257 }
258 }
259
260 /*
261 * specifierForUID - Given a UID, returns the name and operand specification for
262 * that instruction.
263 *
264 * @param uid - The unique ID for the instruction. This should be returned by
265 * decode(); specifierForUID will not check bounds.
266 * @return - A pointer to the specification for that instruction.
267 */
268 static const struct InstructionSpecifiercxx . . $ InstructionSpecifier# *specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(InstrUIDcxx . . $ InstrUID# uid)
269 {
270 return &INSTRUCTIONS_SYMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:28:9`![uid];
271 }
272
273 /*
274 * consumeByte - Uses the reader function provided by the user to consume one
275 * byte from the instruction's memory and advance the cursor.
276 *
277 * @param insn - The instruction with the reader function to use. The cursor
278 * for this instruction is advanced.
279 * @param byte - A pointer to a pre-allocated memory buffer to be populated
280 * with the data read.
281 * @return - 0 if the read was successful; nonzero otherwise.
282 */
283 static int consumeBytecxx . . $ consumeByte(43568041cca0be03).(struct InternalInstructioncxx . . $ InternalInstruction#* insn, uint8_tcxx . . $ uint8_t#* byte)
284 {
285 int ret = insn->readercxx . . $ InternalInstruction#reader.(insn->readerArgcxx . . $ InternalInstruction#readerArg., byte, insn->readerCursorcxx . . $ InternalInstruction#readerCursor.);
286
287 if (!ret)
288 ++(insn->readerCursorcxx . . $ InternalInstruction#readerCursor.);
289
290 return ret;
291 }
292
293 /*
294 * lookAtByte - Like consumeByte, but does not advance the cursor.
295 *
296 * @param insn - See consumeByte().
297 * @param byte - See consumeByte().
298 * @return - See consumeByte().
299 */
300 static int lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(struct InternalInstructioncxx . . $ InternalInstruction#* insn, uint8_tcxx . . $ uint8_t#* byte)
301 {
302 return insn->readercxx . . $ InternalInstruction#reader.(insn->readerArgcxx . . $ InternalInstruction#readerArg., byte, insn->readerCursorcxx . . $ InternalInstruction#readerCursor.);
303 }
304
305 static void unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
306 {
307 insn->readerCursorcxx . . $ InternalInstruction#readerCursor.--;
308 }
309
310 #define CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(name, type) \
311 static int name(struct InternalInstruction* insn, type* ptr) { \
312 type combined = 0; \
313 unsigned offset; \
314 for (offset = 0; offset < sizeof(type); ++offset) { \
315 uint8_t byte; \
316 int ret = insn->reader(insn->readerArg, \
317 &byte, \
318 insn->readerCursor + offset); \
319 if (ret) \
320 return ret; \
321 combined = combined | ((uint64_t)byte << (offset * 8)); \
322 } \
323 *ptr = combined; \
324 insn->readerCursor += sizeof(type); \
325 return 0; \
326 }
327
328 /*
329 * consume* - Use the reader function provided by the user to consume data
330 * values of various sizes from the instruction's memory and advance the
331 * cursor appropriately. These readers perform endian conversion.
332 *
333 * @param insn - See consumeByte().
334 * @param ptr - A pointer to a pre-allocated memory of appropriate size to
335 * be populated with the data read.
336 * @return - See consumeByte().
337 */
338 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeInt8, int8_t)
339 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeInt16, int16_t)
340 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeInt32, int32_t)
341 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeUInt16, uint16_t)
342 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeUInt32, uint32_t)
343 CONSUME_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:310:9`!(consumeUInt64, uint64_t)
344
345 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! isREXcxx . . $ isREX(9561085f920b510c).(struct InternalInstructioncxx . . $ InternalInstruction# *insn, uint8_tcxx . . $ uint8_t# prefix)
346 {
347 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.)
348 return prefix >= 0x40 && prefix <= 0x4f;
349
350 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
351 }
352
353 /*
354 * setPrefixPresent - Marks that a particular prefix is present as mandatory
355 *
356 * @param insn - The instruction to be marked as having the prefix.
357 * @param prefix - The prefix that is present.
358 */
359 static void setPrefixPresentcxx . . $ setPrefixPresent(421ea0a26c783ab2).(struct InternalInstructioncxx . . $ InternalInstruction# *insn, uint8_tcxx . . $ uint8_t# prefix)
360 {
361 uint8_tcxx . . $ uint8_t# nextByte;
362
363 switch (prefix) {
364 case 0xf0: // LOCK
365 insn->hasLockPrefixcxx . . $ InternalInstruction#hasLockPrefix. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
366 insn->repeatPrefixcxx . . $ InternalInstruction#repeatPrefix. = 0;
367 break;
368
369 case 0xf2: // REPNE/REPNZ
370 case 0xf3: // REP or REPE/REPZ
371 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &nextByte))
372 break;
373 // TODO:
374 // 1. There could be several 0x66
375 // 2. if (nextByte == 0x66) and nextNextByte != 0x0f then
376 // it's not mandatory prefix
377 // 3. if (nextByte >= 0x40 && nextByte <= 0x4f) it's REX and we need
378 // 0x0f exactly after it to be mandatory prefix
379 if (isREXcxx . . $ isREX(9561085f920b510c).(insn, nextByte) || nextByte == 0x0f || nextByte == 0x66)
380 // The last of 0xf2 /0xf3 is mandatory prefix
381 insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix. = prefix;
382
383 insn->repeatPrefixcxx . . $ InternalInstruction#repeatPrefix. = prefix;
384 insn->hasLockPrefixcxx . . $ InternalInstruction#hasLockPrefix. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
385 break;
386
387 case 0x66:
388 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &nextByte))
389 break;
390 // 0x66 can't overwrite existing mandatory prefix and should be ignored
391 if (!insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix. && (nextByte == 0x0f || isREXcxx . . $ isREX(9561085f920b510c).(insn, nextByte)))
392 insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix. = prefix;
393 break;
394 }
395 }
396
397 /*
398 * readPrefixes - Consumes all of an instruction's prefix bytes, and marks the
399 * instruction as having them. Also sets the instruction's default operand,
400 * address, and other relevant data sizes to report operands correctly.
401 *
402 * @param insn - The instruction whose prefixes are to be read.
403 * @return - 0 if the instruction could be read until the end of the prefix
404 * bytes, and no prefixes conflicted; nonzero otherwise.
405 */
406 static int readPrefixescxx . . $ readPrefixes(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
407 {
408 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! isPrefix = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
409 uint8_tcxx . . $ uint8_t# byte = 0;
410 uint8_tcxx . . $ uint8_t# nextByte;
411
412 while (isPrefix) {
413 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.) {
414 // eliminate consecutive redundant REX bytes in front
415 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &byte))
416 return -1;
417
418 if ((byte & 0xf0) == 0x40) {
419 while(truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!) {
420 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &byte)) // out of input code
421 return -1;
422 if ((byte & 0xf0) == 0x40) {
423 // another REX prefix, but we only remember the last one
424 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &byte))
425 return -1;
426 } else
427 break;
428 }
429
430 // recover the last REX byte if next byte is not a legacy prefix
431 switch (byte) {
432 case 0xf2: /* REPNE/REPNZ */
433 case 0xf3: /* REP or REPE/REPZ */
434 case 0xf0: /* LOCK */
435 case 0x2e: /* CS segment override -OR- Branch not taken */
436 case 0x36: /* SS segment override -OR- Branch taken */
437 case 0x3e: /* DS segment override */
438 case 0x26: /* ES segment override */
439 case 0x64: /* FS segment override */
440 case 0x65: /* GS segment override */
441 case 0x66: /* Operand-size override */
442 case 0x67: /* Address-size override */
443 break;
444 default: /* Not a prefix byte */
445 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
446 break;
447 }
448 } else {
449 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
450 }
451 }
452
453 /* If we fail reading prefixes, just stop here and let the opcode reader deal with it */
454 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &byte))
455 return -1;
456
457 if (insn->readerCursorcxx . . $ InternalInstruction#readerCursor. - 1 == insn->startLocationcxx . . $ InternalInstruction#startLocation.
458 && (byte == 0xf2 || byte == 0xf3)) {
459 // prefix requires next byte
460 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &nextByte))
461 return -1;
462
463 /*
464 * If the byte is 0xf2 or 0xf3, and any of the following conditions are
465 * met:
466 * - it is followed by a LOCK (0xf0) prefix
467 * - it is followed by an xchg instruction
468 * then it should be disassembled as a xacquire/xrelease not repne/rep.
469 */
470 if (((nextByte == 0xf0) ||
471 ((nextByte & 0xfe) == 0x86 || (nextByte & 0xf8) == 0x90))) {
472 insn->xAcquireReleasecxx . . $ InternalInstruction#xAcquireRelease. = byte;
473 }
474
475 /*
476 * Also if the byte is 0xf3, and the following condition is met:
477 * - it is followed by a "mov mem, reg" (opcode 0x88/0x89) or
478 * "mov mem, imm" (opcode 0xc6/0xc7) instructions.
479 * then it should be disassembled as an xrelease not rep.
480 */
481 if (byte == 0xf3 && (nextByte == 0x88 || nextByte == 0x89 ||
482 nextByte == 0xc6 || nextByte == 0xc7)) {
483 insn->xAcquireReleasecxx . . $ InternalInstruction#xAcquireRelease. = byte;
484 }
485
486 if (isREXcxx . . $ isREX(9561085f920b510c).(insn, nextByte)) {
487 uint8_tcxx . . $ uint8_t# nnextByte;
488
489 // Go to REX prefix after the current one
490 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &nnextByte))
491 return -1;
492
493 // We should be able to read next byte after REX prefix
494 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &nnextByte))
495 return -1;
496
497 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
498 }
499 }
500
501 switch (byte) {
502 case 0xf0: /* LOCK */
503 case 0xf2: /* REPNE/REPNZ */
504 case 0xf3: /* REP or REPE/REPZ */
505 // only accept the last prefix
506 setPrefixPresentcxx . . $ setPrefixPresent(421ea0a26c783ab2).(insn, byte);
507 insn->prefix0cxx . . $ InternalInstruction#prefix0. = byte;
508 break;
509
510 case 0x2e: /* CS segment override -OR- Branch not taken */
511 case 0x36: /* SS segment override -OR- Branch taken */
512 case 0x3e: /* DS segment override */
513 case 0x26: /* ES segment override */
514 case 0x64: /* FS segment override */
515 case 0x65: /* GS segment override */
516 switch (byte) {
517 case 0x2e:
518 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_CScxx . . $ SEG_OVERRIDE_CS.;
519 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
520 break;
521 case 0x36:
522 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_SScxx . . $ SEG_OVERRIDE_SS.;
523 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
524 break;
525 case 0x3e:
526 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_DScxx . . $ SEG_OVERRIDE_DS.;
527 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
528 break;
529 case 0x26:
530 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_EScxx . . $ SEG_OVERRIDE_ES.;
531 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
532 break;
533 case 0x64:
534 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_FScxx . . $ SEG_OVERRIDE_FS.;
535 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
536 break;
537 case 0x65:
538 insn->segmentOverridecxx . . $ InternalInstruction#segmentOverride. = SEG_OVERRIDE_GScxx . . $ SEG_OVERRIDE_GS.;
539 insn->prefix1cxx . . $ InternalInstruction#prefix1. = byte;
540 break;
541 default:
542 // debug("Unhandled override");
543 return -1;
544 }
545 setPrefixPresentcxx . . $ setPrefixPresent(421ea0a26c783ab2).(insn, byte);
546 break;
547
548 case 0x66: /* Operand-size override */
549 insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
550 setPrefixPresentcxx . . $ setPrefixPresent(421ea0a26c783ab2).(insn, byte);
551 insn->prefix2cxx . . $ InternalInstruction#prefix2. = byte;
552 break;
553
554 case 0x67: /* Address-size override */
555 insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
556 setPrefixPresentcxx . . $ setPrefixPresent(421ea0a26c783ab2).(insn, byte);
557 insn->prefix3cxx . . $ InternalInstruction#prefix3. = byte;
558 break;
559 default: /* Not a prefix byte */
560 isPrefix = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
561 break;
562 }
563 }
564
565 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. = TYPE_NO_VEX_XOPcxx . . $ TYPE_NO_VEX_XOP.;
566
567 if (byte == 0x62) {
568 uint8_tcxx . . $ uint8_t# byte1, byte2;
569
570 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &byte1)) {
571 // dbgprintf(insn, "Couldn't read second byte of EVEX prefix");
572 return -1;
573 }
574
575 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &byte2)) {
576 // dbgprintf(insn, "Couldn't read third byte of EVEX prefix");
577 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn); /* unconsume byte1 */
578 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn); /* unconsume byte */
579 } else {
580 if ((insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT. || (byte1 & 0xc0) == 0xc0) &&
581 ((~byte1 & 0xc) == 0xc) && ((byte2 & 0x4) == 0x4)) {
582 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. = TYPE_EVEXcxx . . $ TYPE_EVEX.;
583 } else {
584 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn); /* unconsume byte1 */
585 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn); /* unconsume byte */
586 }
587 }
588
589 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX.) {
590 insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[0] = byte;
591 insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[1] = byte1;
592 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[2])) {
593 // dbgprintf(insn, "Couldn't read third byte of EVEX prefix");
594 return -1;
595 }
596
597 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[3])) {
598 // dbgprintf(insn, "Couldn't read fourth byte of EVEX prefix");
599 return -1;
600 }
601
602 /* We simulate the REX prefix for simplicity's sake */
603 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.) {
604 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. = 0x40
605 | (wFromEVEX3of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:49:9`!(insn->vectorExtensionPrefix[2]) << 3)
606 | (rFromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:44:9`!(insn->vectorExtensionPrefix[1]) << 2)
607 | (xFromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:45:9`!(insn->vectorExtensionPrefix[1]) << 1)
608 | (bFromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:46:9`!(insn->vectorExtensionPrefix[1]) << 0);
609 }
610
611 // dbgprintf(insn, "Found EVEX prefix 0x%hhx 0x%hhx 0x%hhx 0x%hhx",
612 // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1],
613 // insn->vectorExtensionPrefix[2], insn->vectorExtensionPrefix[3]);
614 }
615 } else if (byte == 0xc4) {
616 uint8_tcxx . . $ uint8_t# byte1;
617
618 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &byte1)) {
619 // dbgprintf(insn, "Couldn't read second byte of VEX");
620 return -1;
621 }
622
623 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT. || (byte1 & 0xc0) == 0xc0)
624 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. = TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B.;
625 else
626 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
627
628 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B.) {
629 insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[0] = byte;
630 consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[1]);
631 consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[2]);
632
633 /* We simulate the REX prefix for simplicity's sake */
634 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.)
635 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. = 0x40
636 | (wFromVEX3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:63:9`!(insn->vectorExtensionPrefix[2]) << 3)
637 | (rFromVEX2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:59:9`!(insn->vectorExtensionPrefix[1]) << 2)
638 | (xFromVEX2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:60:9`!(insn->vectorExtensionPrefix[1]) << 1)
639 | (bFromVEX2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:61:9`!(insn->vectorExtensionPrefix[1]) << 0);
640
641 // dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx 0x%hhx",
642 // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1],
643 // insn->vectorExtensionPrefix[2]);
644 }
645 } else if (byte == 0xc5) {
646 uint8_tcxx . . $ uint8_t# byte1;
647
648 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &byte1)) {
649 // dbgprintf(insn, "Couldn't read second byte of VEX");
650 return -1;
651 }
652
653 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT. || (byte1 & 0xc0) == 0xc0)
654 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. = TYPE_VEX_2Bcxx . . $ TYPE_VEX_2B.;
655 else
656 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
657
658 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_2Bcxx . . $ TYPE_VEX_2B.) {
659 insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[0] = byte;
660 consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[1]);
661
662 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.)
663 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. = 0x40
664 | (rFromVEX2of2cxx . . $ `arch/X86/X86DisassemblerDecoder.h:68:9`!(insn->vectorExtensionPrefix[1]) << 2);
665
666 switch (ppFromVEX2of2cxx . . $ `arch/X86/X86DisassemblerDecoder.h:71:9`!(insn->vectorExtensionPrefix[1])) {
667 default:
668 break;
669 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
670 insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
671 break;
672 }
673
674 // dbgprintf(insn, "Found VEX prefix 0x%hhx 0x%hhx",
675 // insn->vectorExtensionPrefix[0],
676 // insn->vectorExtensionPrefix[1]);
677 }
678 } else if (byte == 0x8f) {
679 uint8_tcxx . . $ uint8_t# byte1;
680
681 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &byte1)) {
682 // dbgprintf(insn, "Couldn't read second byte of XOP");
683 return -1;
684 }
685
686 if ((byte1 & 0x38) != 0x0) /* 0 in these 3 bits is a POP instruction. */
687 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. = TYPE_XOPcxx . . $ TYPE_XOP.;
688 else
689 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
690
691 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_XOPcxx . . $ TYPE_XOP.) {
692 insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[0] = byte;
693 consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[1]);
694 consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->vectorExtensionPrefixcxx . . $ InternalInstruction#vectorExtensionPrefix.[2]);
695
696 /* We simulate the REX prefix for simplicity's sake */
697 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.)
698 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. = 0x40
699 | (wFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:77:9`!(insn->vectorExtensionPrefix[2]) << 3)
700 | (rFromXOP2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:73:9`!(insn->vectorExtensionPrefix[1]) << 2)
701 | (xFromXOP2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:74:9`!(insn->vectorExtensionPrefix[1]) << 1)
702 | (bFromXOP2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:75:9`!(insn->vectorExtensionPrefix[1]) << 0);
703
704 switch (ppFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:80:9`!(insn->vectorExtensionPrefix[2])) {
705 default:
706 break;
707 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
708 insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
709 break;
710 }
711
712 // dbgprintf(insn, "Found XOP prefix 0x%hhx 0x%hhx 0x%hhx",
713 // insn->vectorExtensionPrefix[0], insn->vectorExtensionPrefix[1],
714 // insn->vectorExtensionPrefix[2]);
715 }
716 } else if (isREXcxx . . $ isREX(9561085f920b510c).(insn, byte)) {
717 if (lookAtBytecxx . . $ lookAtByte(43568041cca0be03).(insn, &nextByte))
718 return -1;
719
720 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. = byte;
721 // dbgprintf(insn, "Found REX prefix 0x%hhx", byte);
722 } else
723 unconsumeBytecxx . . $ unconsumeByte(5cef497190e8aa6f).(insn);
724
725 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_16BITcxx . . $ MODE_16BIT.) {
726 insn->registerSizecxx . . $ InternalInstruction#registerSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 4 : 2);
727 insn->addressSizecxx . . $ InternalInstruction#addressSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 4 : 2);
728 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 4 : 2);
729 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 4 : 2);
730 insn->immSizecxx . . $ InternalInstruction#immSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 4 : 2);
731 } else if (insn->modecxx . . $ InternalInstruction#mode. == MODE_32BITcxx . . $ MODE_32BIT.) {
732 insn->registerSizecxx . . $ InternalInstruction#registerSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
733 insn->addressSizecxx . . $ InternalInstruction#addressSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 2 : 4);
734 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 2 : 4);
735 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
736 insn->immSizecxx . . $ InternalInstruction#immSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
737 } else if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.) {
738 if (insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. && wFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:39:9`!(insn->rexPrefix)) {
739 insn->registerSizecxx . . $ InternalInstruction#registerSize. = 8;
740 insn->addressSizecxx . . $ InternalInstruction#addressSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 4 : 8);
741 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = 4;
742 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = 4;
743 insn->immSizecxx . . $ InternalInstruction#immSize. = 4;
744 } else {
745 insn->registerSizecxx . . $ InternalInstruction#registerSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
746 insn->addressSizecxx . . $ InternalInstruction#addressSize. = (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize. ? 4 : 8);
747 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
748 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 2 : 4);
749 insn->immSizecxx . . $ InternalInstruction#immSize. = (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. ? 4 : 8);
750 }
751 }
752
753 return 0;
754 }
755
756 static int readModRMcxx . . $ readModRM(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn);
757
758 /*
759 * readOpcode - Reads the opcode (excepting the ModR/M byte in the case of
760 * extended or escape opcodes).
761 *
762 * @param insn - The instruction whose opcode is to be read.
763 * @return - 0 if the opcode could be read successfully; nonzero otherwise.
764 */
765 static int readOpcodecxx . . $ readOpcode(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
766 {
767 uint8_tcxx . . $ uint8_t# current;
768
769 // dbgprintf(insn, "readOpcode()");
770
771 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = ONEBYTEcxx . . $ ONEBYTE.;
772
773 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX.) {
774 switch (mmFromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:48:9`!(insn->vectorExtensionPrefix[1])) {
775 default:
776 // dbgprintf(insn, "Unhandled mm field for instruction (0x%hhx)",
777 // mmFromEVEX2of4(insn->vectorExtensionPrefix[1]));
778 return -1;
779 case VEX_LOB_0Fcxx . . $ VEX_LOB_0F.:
780 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = TWOBYTEcxx . . $ TWOBYTE.;
781 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
782 case VEX_LOB_0F38cxx . . $ VEX_LOB_0F38.:
783 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_38cxx . . $ THREEBYTE_38.;
784 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
785 case VEX_LOB_0F3Acxx . . $ VEX_LOB_0F3A.:
786 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_3Acxx . . $ THREEBYTE_3A.;
787 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
788 }
789 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B.) {
790 switch (mmmmmFromVEX2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:62:9`!(insn->vectorExtensionPrefix[1])) {
791 default:
792 // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)",
793 // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1]));
794 return -1;
795 case VEX_LOB_0Fcxx . . $ VEX_LOB_0F.:
796 //insn->twoByteEscape = 0x0f;
797 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = TWOBYTEcxx . . $ TWOBYTE.;
798 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
799 case VEX_LOB_0F38cxx . . $ VEX_LOB_0F38.:
800 //insn->twoByteEscape = 0x0f;
801 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_38cxx . . $ THREEBYTE_38.;
802 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
803 case VEX_LOB_0F3Acxx . . $ VEX_LOB_0F3A.:
804 //insn->twoByteEscape = 0x0f;
805 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_3Acxx . . $ THREEBYTE_3A.;
806 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
807 }
808 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_2Bcxx . . $ TYPE_VEX_2B.) {
809 //insn->twoByteEscape = 0x0f;
810 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = TWOBYTEcxx . . $ TWOBYTE.;
811 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
812 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_XOPcxx . . $ TYPE_XOP.) {
813 switch (mmmmmFromXOP2of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:76:9`!(insn->vectorExtensionPrefix[1])) {
814 default:
815 // dbgprintf(insn, "Unhandled m-mmmm field for instruction (0x%hhx)",
816 // mmmmmFromVEX2of3(insn->vectorExtensionPrefix[1]));
817 return -1;
818 case XOP_MAP_SELECT_8cxx . . $ XOP_MAP_SELECT_8.:
819 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = XOP8_MAPcxx . . $ XOP8_MAP.;
820 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
821 case XOP_MAP_SELECT_9cxx . . $ XOP_MAP_SELECT_9.:
822 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = XOP9_MAPcxx . . $ XOP9_MAP.;
823 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
824 case XOP_MAP_SELECT_Acxx . . $ XOP_MAP_SELECT_A.:
825 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = XOPA_MAPcxx . . $ XOPA_MAP.;
826 return consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->opcodecxx . . $ InternalInstruction#opcode.);
827 }
828 }
829
830 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &current))
831 return -1;
832
833 // save this first byte for MOVcr, MOVdr, MOVrc, MOVrd
834 insn->firstBytecxx . . $ InternalInstruction#firstByte. = current;
835
836 if (current == 0x0f) {
837 // dbgprintf(insn, "Found a two-byte escape prefix (0x%hhx)", current);
838 insn->twoByteEscapecxx . . $ InternalInstruction#twoByteEscape. = current;
839
840 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &current))
841 return -1;
842
843 if (current == 0x38) {
844 // dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
845 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &current))
846 return -1;
847
848 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_38cxx . . $ THREEBYTE_38.;
849 } else if (current == 0x3a) {
850 // dbgprintf(insn, "Found a three-byte escape prefix (0x%hhx)", current);
851 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &current))
852 return -1;
853
854 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEBYTE_3Acxx . . $ THREEBYTE_3A.;
855 } else if (current == 0x0f) {
856 // dbgprintf(insn, "Found a 3dnow escape prefix (0x%hhx)", current);
857 // Consume operands before the opcode to comply with the 3DNow encoding
858 if (readModRMcxx . . $ readModRM(a95f3859aee87d23).(insn))
859 return -1;
860
861 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &current))
862 return -1;
863
864 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = THREEDNOW_MAPcxx . . $ THREEDNOW_MAP.;
865 } else {
866 // dbgprintf(insn, "Didn't find a three-byte escape prefix");
867 insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. = TWOBYTEcxx . . $ TWOBYTE.;
868 }
869 } else if (insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix.)
870 // The opcode with mandatory prefix must start with opcode escape.
871 // If not it's legacy repeat prefix
872 insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix. = 0;
873
874 /*
875 * At this point we have consumed the full opcode.
876 * Anything we consume from here on must be unconsumed.
877 */
878
879 insn->opcodecxx . . $ InternalInstruction#opcode. = current;
880
881 return 0;
882 }
883
884 // Hacky for FEMMS
885 #define GET_INSTRINFO_ENUMcxx . . $ `arch/X86/X86DisassemblerDecoder.c:885:9`!
886 #ifndef CAPSTONE_X86_REDUCE
887 #include "X86GenInstrInfo.inc"cxx . . $ `<file>/arch/X86/X86GenInstrInfo.inc`/
888 #else
889 #include "X86GenInstrInfo_reduce.inc"
890 #endif
891
892 /*
893 * getIDWithAttrMask - Determines the ID of an instruction, consuming
894 * the ModR/M byte as appropriate for extended and escape opcodes,
895 * and using a supplied attribute mask.
896 *
897 * @param instructionID - A pointer whose target is filled in with the ID of the
898 * instruction.
899 * @param insn - The instruction whose ID is to be determined.
900 * @param attrMask - The attribute mask to search.
901 * @return - 0 if the ModR/M could be read when needed or was not
902 * needed; nonzero otherwise.
903 */
904 static int getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(uint16_tcxx . . $ uint16_t# *instructionID,
905 struct InternalInstructioncxx . . $ InternalInstruction#* insn,
906 uint16_tcxx . . $ uint16_t# attrMask)
907 {
908 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! hasModRMExtension;
909
910 InstructionContextcxx . . $ InstructionContext# instructionClass = contextForAttrscxx . . $ contextForAttrs(af141ee81a9fd4e).(attrMask);
911
912 hasModRMExtension = modRMRequiredcxx . . $ modRMRequired(5af57ec56d559bcc).(insn->opcodeTypecxx . . $ InternalInstruction#opcodeType.,
913 instructionClass,
914 insn->opcodecxx . . $ InternalInstruction#opcode.);
915
916 if (hasModRMExtension) {
917 if (readModRMcxx . . $ readModRM(a95f3859aee87d23).(insn))
918 return -1;
919
920 *instructionID = decodecxx . . $ decode(107233116c3734c6).(insn->opcodeTypecxx . . $ InternalInstruction#opcodeType.,
921 instructionClass,
922 insn->opcodecxx . . $ InternalInstruction#opcode.,
923 insn->modRMcxx . . $ InternalInstruction#modRM.);
924 } else {
925 *instructionID = decodecxx . . $ decode(107233116c3734c6).(insn->opcodeTypecxx . . $ InternalInstruction#opcodeType.,
926 instructionClass,
927 insn->opcodecxx . . $ InternalInstruction#opcode.,
928 0);
929 }
930
931 return 0;
932 }
933
934 /*
935 * is16BitEquivalent - Determines whether two instruction names refer to
936 * equivalent instructions but one is 16-bit whereas the other is not.
937 *
938 * @param orig - The instruction ID that is not 16-bit
939 * @param equiv - The instruction ID that is 16-bit
940 */
941 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is16BitEquivalentcxx . . $ is16BitEquivalent(8e1b545ea3aecce3).(unsigned orig, unsigned equiv)
942 {
943 size_t i;
944 uint16_tcxx . . $ uint16_t# idx;
945
946 if ((idx = x86_16_bit_eq_lookupcxx . . $ x86_16_bit_eq_lookup.[orig]) != 0) {
947 for (i = idx - 1; i < ARR_SIZEcxx . . $ `utils.h:24:9`!(x86_16_bit_eq_tbl) && x86_16_bit_eq_tblcxx . . $ x86_16_bit_eq_tbl.[i].firstcxx . . $ x86_op_id_pair#first. == orig; i++) {
948 if (x86_16_bit_eq_tblcxx . . $ x86_16_bit_eq_tbl.[i].secondcxx . . $ x86_op_id_pair#second. == equiv)
949 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
950 }
951 }
952
953 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
954 }
955
956 /*
957 * is64Bit - Determines whether this instruction is a 64-bit instruction.
958 *
959 * @param name - The instruction that is not 16-bit
960 */
961 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is64Bitcxx . . $ is64Bit(3c978dac0e5ee2ad).(uint16_tcxx . . $ uint16_t# id)
962 {
963 unsigned int i = find_insncxx . . $ find_insn(2141b656ce2cc063).(id);
964 if (i != -1) {
965 return insnscxx . . $ insns.[i].is64bitcxx . . $ insn_map_x86#is64bit.;
966 }
967
968 // not found??
969 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
970 }
971
972 /*
973 * getID - Determines the ID of an instruction, consuming the ModR/M byte as
974 * appropriate for extended and escape opcodes. Determines the attributes and
975 * context for the instruction before doing so.
976 *
977 * @param insn - The instruction whose ID is to be determined.
978 * @return - 0 if the ModR/M could be read when needed or was not needed;
979 * nonzero otherwise.
980 */
981 static int getIDcxx . . $ getID(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction# *insn)
982 {
983 uint16_tcxx . . $ uint16_t# attrMask;
984 uint16_tcxx . . $ uint16_t# instructionID;
985
986 attrMask = ATTR_NONEcxx . . $ ATTR_NONE.;
987
988 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.)
989 attrMask |= ATTR_64BITcxx . . $ ATTR_64BIT.;
990
991 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. != TYPE_NO_VEX_XOPcxx . . $ TYPE_NO_VEX_XOP.) {
992 attrMask |= (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX.) ? ATTR_EVEXcxx . . $ ATTR_EVEX. : ATTR_VEXcxx . . $ ATTR_VEX.;
993
994 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX.) {
995 switch (ppFromEVEX3of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:51:9`!(insn->vectorExtensionPrefix[2])) {
996 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
997 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
998 break;
999 case VEX_PREFIX_F3cxx . . $ VEX_PREFIX_F3.:
1000 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1001 break;
1002 case VEX_PREFIX_F2cxx . . $ VEX_PREFIX_F2.:
1003 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1004 break;
1005 }
1006
1007 if (zFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:52:9`!(insn->vectorExtensionPrefix[3]))
1008 attrMask |= ATTR_EVEXKZcxx . . $ ATTR_EVEXKZ.;
1009 if (bFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:55:9`!(insn->vectorExtensionPrefix[3]))
1010 attrMask |= ATTR_EVEXBcxx . . $ ATTR_EVEXB.;
1011 if (aaaFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:57:9`!(insn->vectorExtensionPrefix[3]))
1012 attrMask |= ATTR_EVEXKcxx . . $ ATTR_EVEXK.;
1013 if (lFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:54:9`!(insn->vectorExtensionPrefix[3]))
1014 attrMask |= ATTR_EVEXLcxx . . $ ATTR_EVEXL.;
1015 if (l2FromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:53:9`!(insn->vectorExtensionPrefix[3]))
1016 attrMask |= ATTR_EVEXL2cxx . . $ ATTR_EVEXL2.;
1017 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B.) {
1018 switch (ppFromVEX3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:66:9`!(insn->vectorExtensionPrefix[2])) {
1019 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
1020 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1021 break;
1022 case VEX_PREFIX_F3cxx . . $ VEX_PREFIX_F3.:
1023 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1024 break;
1025 case VEX_PREFIX_F2cxx . . $ VEX_PREFIX_F2.:
1026 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1027 break;
1028 }
1029
1030 if (lFromVEX3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:65:9`!(insn->vectorExtensionPrefix[2]))
1031 attrMask |= ATTR_VEXLcxx . . $ ATTR_VEXL.;
1032 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_2Bcxx . . $ TYPE_VEX_2B.) {
1033 switch (ppFromVEX2of2cxx . . $ `arch/X86/X86DisassemblerDecoder.h:71:9`!(insn->vectorExtensionPrefix[1])) {
1034 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
1035 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1036 break;
1037 case VEX_PREFIX_F3cxx . . $ VEX_PREFIX_F3.:
1038 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1039 break;
1040 case VEX_PREFIX_F2cxx . . $ VEX_PREFIX_F2.:
1041 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1042 break;
1043 }
1044
1045 if (lFromVEX2of2cxx . . $ `arch/X86/X86DisassemblerDecoder.h:70:9`!(insn->vectorExtensionPrefix[1]))
1046 attrMask |= ATTR_VEXLcxx . . $ ATTR_VEXL.;
1047 } else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_XOPcxx . . $ TYPE_XOP.) {
1048 switch (ppFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:80:9`!(insn->vectorExtensionPrefix[2])) {
1049 case VEX_PREFIX_66cxx . . $ VEX_PREFIX_66.:
1050 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1051 break;
1052 case VEX_PREFIX_F3cxx . . $ VEX_PREFIX_F3.:
1053 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1054 break;
1055 case VEX_PREFIX_F2cxx . . $ VEX_PREFIX_F2.:
1056 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1057 break;
1058 }
1059
1060 if (lFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:79:9`!(insn->vectorExtensionPrefix[2]))
1061 attrMask |= ATTR_VEXLcxx . . $ ATTR_VEXL.;
1062 } else {
1063 return -1;
1064 }
1065 } else if (!insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix.) {
1066 // If we don't have mandatory prefix we should use legacy prefixes here
1067 if (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize. && (insn->modecxx . . $ InternalInstruction#mode. != MODE_16BITcxx . . $ MODE_16BIT.))
1068 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1069 if (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize.)
1070 attrMask |= ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1071 if (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE.) {
1072 if (insn->repeatPrefixcxx . . $ InternalInstruction#repeatPrefix. == 0xf3 && (insn->opcodecxx . . $ InternalInstruction#opcode. == 0x90))
1073 // Special support for PAUSE
1074 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1075 } else {
1076 if (insn->repeatPrefixcxx . . $ InternalInstruction#repeatPrefix. == 0xf2)
1077 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1078 else if (insn->repeatPrefixcxx . . $ InternalInstruction#repeatPrefix. == 0xf3)
1079 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1080 }
1081 } else {
1082 switch (insn->mandatoryPrefixcxx . . $ InternalInstruction#mandatoryPrefix.) {
1083 case 0xf2:
1084 attrMask |= ATTR_XDcxx . . $ ATTR_XD.;
1085 break;
1086 case 0xf3:
1087 attrMask |= ATTR_XScxx . . $ ATTR_XS.;
1088 break;
1089 case 0x66:
1090 if (insn->modecxx . . $ InternalInstruction#mode. != MODE_16BITcxx . . $ MODE_16BIT.)
1091 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1092 break;
1093 case 0x67:
1094 attrMask |= ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1095 break;
1096 }
1097
1098 }
1099
1100 if (insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. & 0x08) {
1101 attrMask |= ATTR_REXWcxx . . $ ATTR_REXW.;
1102 attrMask &= ~ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1103 }
1104
1105 /*
1106 * JCXZ/JECXZ need special handling for 16-bit mode because the meaning
1107 * of the AdSize prefix is inverted w.r.t. 32-bit mode.
1108 */
1109 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_16BITcxx . . $ MODE_16BIT. && insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE. &&
1110 insn->opcodecxx . . $ InternalInstruction#opcode. == 0xE3)
1111 attrMask ^= ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1112
1113 /*
1114 * In 64-bit mode all f64 superscripted opcodes ignore opcode size prefix
1115 * CALL/JMP/JCC instructions need to ignore 0x66 and consume 4 bytes
1116 */
1117 if ((insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.) && insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize.) {
1118 switch (insn->opcodecxx . . $ InternalInstruction#opcode.) {
1119 case 0xE8:
1120 case 0xE9:
1121 // Take care of psubsb and other mmx instructions.
1122 if (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE.) {
1123 attrMask ^= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1124 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = 4;
1125 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = 4;
1126 }
1127 break;
1128 case 0x82:
1129 case 0x83:
1130 case 0x84:
1131 case 0x85:
1132 case 0x86:
1133 case 0x87:
1134 case 0x88:
1135 case 0x89:
1136 case 0x8A:
1137 case 0x8B:
1138 case 0x8C:
1139 case 0x8D:
1140 case 0x8E:
1141 case 0x8F:
1142 // Take care of lea and three byte ops.
1143 if (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == TWOBYTEcxx . . $ TWOBYTE.) {
1144 attrMask ^= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1145 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = 4;
1146 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = 4;
1147 }
1148 break;
1149 }
1150 }
1151
1152 /* The following clauses compensate for limitations of the tables. */
1153 if (insn->modecxx . . $ InternalInstruction#mode. != MODE_64BITcxx . . $ MODE_64BIT. &&
1154 insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. != TYPE_NO_VEX_XOPcxx . . $ TYPE_NO_VEX_XOP.) {
1155 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionID, insn, attrMask)) {
1156 return -1;
1157 }
1158
1159 /*
1160 * The tables can't distinquish between cases where the W-bit is used to
1161 * select register size and cases where its a required part of the opcode.
1162 */
1163 if ((insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX. &&
1164 wFromEVEX3of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:49:9`!(insn->vectorExtensionPrefix[2])) ||
1165 (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B. &&
1166 wFromVEX3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:63:9`!(insn->vectorExtensionPrefix[2])) ||
1167 (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_XOPcxx . . $ TYPE_XOP. &&
1168 wFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:77:9`!(insn->vectorExtensionPrefix[2]))) {
1169 uint16_tcxx . . $ uint16_t# instructionIDWithREXW;
1170
1171 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionIDWithREXW,
1172 insn, attrMask | ATTR_REXWcxx . . $ ATTR_REXW.)) {
1173 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1174 insn->speccxx . . $ InternalInstruction#spec. = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionID);
1175 return 0;
1176 }
1177
1178 // If not a 64-bit instruction. Switch the opcode.
1179 if (!is64Bitcxx . . $ is64Bit(3c978dac0e5ee2ad).(instructionIDWithREXW)) {
1180 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionIDWithREXW;
1181 insn->speccxx . . $ InternalInstruction#spec. = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionIDWithREXW);
1182
1183 return 0;
1184 }
1185 }
1186 }
1187
1188 /*
1189 * Absolute moves, umonitor, and movdir64b need special handling.
1190 * -For 16-bit mode because the meaning of the AdSize and OpSize prefixes are
1191 * inverted w.r.t.
1192 * -For 32-bit mode we need to ensure the ADSIZE prefix is observed in
1193 * any position.
1194 */
1195 if ((insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE. && ((insn->opcodecxx . . $ InternalInstruction#opcode. & 0xFC) == 0xA0)) ||
1196 (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == TWOBYTEcxx . . $ TWOBYTE. && (insn->opcodecxx . . $ InternalInstruction#opcode. == 0xAE)) ||
1197 (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == THREEBYTE_38cxx . . $ THREEBYTE_38. && insn->opcodecxx . . $ InternalInstruction#opcode. == 0xF8)) {
1198 /* Make sure we observed the prefixes in any position. */
1199 if (insn->hasAdSizecxx . . $ InternalInstruction#hasAdSize.)
1200 attrMask |= ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1201
1202 if (insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize.)
1203 attrMask |= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1204
1205 /* In 16-bit, invert the attributes. */
1206 if (insn->modecxx . . $ InternalInstruction#mode. == MODE_16BITcxx . . $ MODE_16BIT.) {
1207 attrMask ^= ATTR_ADSIZEcxx . . $ ATTR_ADSIZE.;
1208
1209 /* The OpSize attribute is only valid with the absolute moves. */
1210 if (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE. && ((insn->opcodecxx . . $ InternalInstruction#opcode. & 0xFC) == 0xA0))
1211 attrMask ^= ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.;
1212 }
1213
1214 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionID, insn, attrMask)) {
1215 return -1;
1216 }
1217
1218 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1219 insn->speccxx . . $ InternalInstruction#spec. = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionID);
1220
1221 return 0;
1222 }
1223 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionID, insn, attrMask)) {
1224 return -1;
1225 }
1226
1227 if ((insn->modecxx . . $ InternalInstruction#mode. == MODE_16BITcxx . . $ MODE_16BIT. || insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize.) &&
1228 !(attrMask & ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.)) {
1229 /*
1230 * The instruction tables make no distinction between instructions that
1231 * allow OpSize anywhere (i.e., 16-bit operations) and that need it in a
1232 * particular spot (i.e., many MMX operations). In general we're
1233 * conservative, but in the specific case where OpSize is present but not
1234 * in the right place we check if there's a 16-bit operation.
1235 */
1236 const struct InstructionSpecifiercxx . . $ InstructionSpecifier# *spec;
1237 uint16_tcxx . . $ uint16_t# instructionIDWithOpsize;
1238
1239 spec = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionID);
1240
1241 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionIDWithOpsize,
1242 insn,
1243 attrMask | ATTR_OPSIZEcxx . . $ ATTR_OPSIZE.)) {
1244 /*
1245 * ModRM required with OpSize but not present; give up and return version
1246 * without OpSize set
1247 */
1248 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1249 insn->speccxx . . $ InternalInstruction#spec. = spec;
1250
1251 return 0;
1252 }
1253
1254 if (is16BitEquivalentcxx . . $ is16BitEquivalent(8e1b545ea3aecce3).(instructionID, instructionIDWithOpsize) &&
1255 (insn->modecxx . . $ InternalInstruction#mode. == MODE_16BITcxx . . $ MODE_16BIT.) ^ insn->hasOpSizecxx . . $ InternalInstruction#hasOpSize.) {
1256 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionIDWithOpsize;
1257 insn->speccxx . . $ InternalInstruction#spec. = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionIDWithOpsize);
1258 } else {
1259 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1260 insn->speccxx . . $ InternalInstruction#spec. = spec;
1261 }
1262
1263 return 0;
1264 }
1265
1266 if (insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == ONEBYTEcxx . . $ ONEBYTE. && insn->opcodecxx . . $ InternalInstruction#opcode. == 0x90 &&
1267 insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. & 0x01) {
1268 /*
1269 * NOOP shouldn't decode as NOOP if REX.b is set. Instead
1270 * it should decode as XCHG %r8, %eax.
1271 */
1272 const struct InstructionSpecifiercxx . . $ InstructionSpecifier# *spec;
1273 uint16_tcxx . . $ uint16_t# instructionIDWithNewOpcode;
1274 const struct InstructionSpecifiercxx . . $ InstructionSpecifier# *specWithNewOpcode;
1275
1276 spec = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionID);
1277
1278 /* Borrow opcode from one of the other XCHGar opcodes */
1279 insn->opcodecxx . . $ InternalInstruction#opcode. = 0x91;
1280
1281 if (getIDWithAttrMaskcxx . . $ getIDWithAttrMask(c4c738b8cc0bb348).(&instructionIDWithNewOpcode, insn, attrMask)) {
1282 insn->opcodecxx . . $ InternalInstruction#opcode. = 0x90;
1283
1284 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1285 insn->speccxx . . $ InternalInstruction#spec. = spec;
1286
1287 return 0;
1288 }
1289
1290 specWithNewOpcode = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(instructionIDWithNewOpcode);
1291
1292 /* Change back */
1293 insn->opcodecxx . . $ InternalInstruction#opcode. = 0x90;
1294
1295 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionIDWithNewOpcode;
1296 insn->speccxx . . $ InternalInstruction#spec. = specWithNewOpcode;
1297
1298 return 0;
1299 }
1300
1301 insn->instructionIDcxx . . $ InternalInstruction#instructionID. = instructionID;
1302 insn->speccxx . . $ InternalInstruction#spec. = specifierForUIDcxx . . $ specifierForUID(10538646847a0ce3).(insn->instructionIDcxx . . $ InternalInstruction#instructionID.);
1303
1304 return 0;
1305 }
1306
1307 /*
1308 * readSIB - Consumes the SIB byte to determine addressing information for an
1309 * instruction.
1310 *
1311 * @param insn - The instruction whose SIB byte is to be read.
1312 * @return - 0 if the SIB byte was successfully read; nonzero otherwise.
1313 */
1314 static int readSIBcxx . . $ readSIB(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1315 {
1316 SIBBasecxx . . $ SIBBase# sibBaseBase = SIB_BASE_NONEcxx . . $ SIB_BASE_NONE.;
1317 uint8_tcxx . . $ uint8_t# index, base;
1318
1319 // dbgprintf(insn, "readSIB()");
1320
1321 if (insn->consumedSIBcxx . . $ InternalInstruction#consumedSIB.)
1322 return 0;
1323
1324 insn->consumedSIBcxx . . $ InternalInstruction#consumedSIB. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1325
1326 switch (insn->addressSizecxx . . $ InternalInstruction#addressSize.) {
1327 case 2:
1328 // dbgprintf(insn, "SIB-based addressing doesn't work in 16-bit mode");
1329 return -1;
1330 case 4:
1331 insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase. = SIB_INDEX_EAXcxx . . $ SIB_INDEX_EAX.;
1332 sibBaseBase = SIB_BASE_EAXcxx . . $ SIB_BASE_EAX.;
1333 break;
1334 case 8:
1335 insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase. = SIB_INDEX_RAXcxx . . $ SIB_INDEX_RAX.;
1336 sibBaseBase = SIB_BASE_RAXcxx . . $ SIB_BASE_RAX.;
1337 break;
1338 }
1339
1340 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->sibcxx . . $ InternalInstruction#sib.))
1341 return -1;
1342
1343 index = indexFromSIBcxx . . $ `arch/X86/X86DisassemblerDecoder.h:37:9`!(insn->sib) | (xFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:41:9`!(insn->rexPrefix) << 3);
1344
1345 if (index == 0x4) {
1346 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = SIB_INDEX_NONEcxx . . $ SIB_INDEX_NONE.;
1347 } else {
1348 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase. + index);
1349 }
1350
1351 insn->sibScalecxx . . $ InternalInstruction#sibScale. = 1 << scaleFromSIBcxx . . $ `arch/X86/X86DisassemblerDecoder.h:36:9`!(insn->sib);
1352
1353 base = baseFromSIBcxx . . $ `arch/X86/X86DisassemblerDecoder.h:38:9`!(insn->sib) | (bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3);
1354
1355 switch (base) {
1356 case 0x5:
1357 case 0xd:
1358 switch (modFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:33:9`!(insn->modRM)) {
1359 case 0x0:
1360 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_32cxx . . $ EA_DISP_32.;
1361 insn->sibBasecxx . . $ InternalInstruction#sibBase. = SIB_BASE_NONEcxx . . $ SIB_BASE_NONE.;
1362 break;
1363 case 0x1:
1364 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_8cxx . . $ EA_DISP_8.;
1365 insn->sibBasecxx . . $ InternalInstruction#sibBase. = (SIBBasecxx . . $ SIBBase#)(sibBaseBase + base);
1366 break;
1367 case 0x2:
1368 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_32cxx . . $ EA_DISP_32.;
1369 insn->sibBasecxx . . $ InternalInstruction#sibBase. = (SIBBasecxx . . $ SIBBase#)(sibBaseBase + base);
1370 break;
1371 case 0x3:
1372 // debug("Cannot have Mod = 0b11 and a SIB byte");
1373 return -1;
1374 }
1375 break;
1376 default:
1377 insn->sibBasecxx . . $ InternalInstruction#sibBase. = (SIBBasecxx . . $ SIBBase#)(sibBaseBase + base);
1378 break;
1379 }
1380
1381 return 0;
1382 }
1383
1384 /*
1385 * readDisplacement - Consumes the displacement of an instruction.
1386 *
1387 * @param insn - The instruction whose displacement is to be read.
1388 * @return - 0 if the displacement byte was successfully read; nonzero
1389 * otherwise.
1390 */
1391 static int readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1392 {
1393 int8_tcxx . . $ int8_t# d8;
1394 int16_tcxx . . $ int16_t# d16;
1395 int32_tcxx . . $ int32_t# d32;
1396
1397 // dbgprintf(insn, "readDisplacement()");
1398
1399 if (insn->consumedDisplacementcxx . . $ InternalInstruction#consumedDisplacement.)
1400 return 0;
1401
1402 insn->consumedDisplacementcxx . . $ InternalInstruction#consumedDisplacement. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1403 insn->displacementOffsetcxx . . $ InternalInstruction#displacementOffset. = insn->readerCursorcxx . . $ InternalInstruction#readerCursor. - insn->startLocationcxx . . $ InternalInstruction#startLocation.;
1404
1405 switch (insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement.) {
1406 case EA_DISP_NONEcxx . . $ EA_DISP_NONE.:
1407 insn->consumedDisplacementcxx . . $ InternalInstruction#consumedDisplacement. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
1408 break;
1409 case EA_DISP_8cxx . . $ EA_DISP_8.:
1410 if (consumeInt8cxx . . $ consumeInt8(c18c7cd902781764).(insn, &d8))
1411 return -1;
1412 insn->displacementcxx . . $ InternalInstruction#displacement. = d8;
1413 break;
1414 case EA_DISP_16cxx . . $ EA_DISP_16.:
1415 if (consumeInt16cxx . . $ consumeInt16(3c9f6d24df4ff5a2).(insn, &d16))
1416 return -1;
1417 insn->displacementcxx . . $ InternalInstruction#displacement. = d16;
1418 break;
1419 case EA_DISP_32cxx . . $ EA_DISP_32.:
1420 if (consumeInt32cxx . . $ consumeInt32(f5bf6c52e9efef38).(insn, &d32))
1421 return -1;
1422 insn->displacementcxx . . $ InternalInstruction#displacement. = d32;
1423 break;
1424 }
1425
1426
1427 return 0;
1428 }
1429
1430 /*
1431 * readModRM - Consumes all addressing information (ModR/M byte, SIB byte, and
1432 * displacement) for an instruction and interprets it.
1433 *
1434 * @param insn - The instruction whose addressing information is to be read.
1435 * @return - 0 if the information was successfully read; nonzero otherwise.
1436 */
1437 static int readModRMcxx . . $ readModRM(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1438 {
1439 uint8_tcxx . . $ uint8_t# mod, rm, reg, evexrm;
1440
1441 // dbgprintf(insn, "readModRM()");
1442
1443 if (insn->consumedModRMcxx . . $ InternalInstruction#consumedModRM.)
1444 return 0;
1445
1446 insn->modRMOffsetcxx . . $ InternalInstruction#modRMOffset. = (uint8_tcxx . . $ uint8_t#)(insn->readerCursorcxx . . $ InternalInstruction#readerCursor. - insn->startLocationcxx . . $ InternalInstruction#startLocation.);
1447
1448 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &insn->modRMcxx . . $ InternalInstruction#modRM.))
1449 return -1;
1450
1451 insn->consumedModRMcxx . . $ InternalInstruction#consumedModRM. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
1452
1453 // save original ModRM for later reference
1454 insn->orgModRMcxx . . $ InternalInstruction#orgModRM. = insn->modRMcxx . . $ InternalInstruction#modRM.;
1455
1456 // handle MOVcr, MOVdr, MOVrc, MOVrd by pretending they have MRM.mod = 3
1457 if ((insn->firstBytecxx . . $ InternalInstruction#firstByte. == 0x0f && insn->opcodeTypecxx . . $ InternalInstruction#opcodeType. == TWOBYTEcxx . . $ TWOBYTE.) &&
1458 (insn->opcodecxx . . $ InternalInstruction#opcode. >= 0x20 && insn->opcodecxx . . $ InternalInstruction#opcode. <= 0x23 ))
1459 insn->modRMcxx . . $ InternalInstruction#modRM. |= 0xC0;
1460
1461 mod = modFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:33:9`!(insn->modRM);
1462 rm = rmFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:35:9`!(insn->modRM);
1463 reg = regFromModRMcxx . . $ `arch/X86/X86DisassemblerDecoder.h:34:9`!(insn->modRM);
1464
1465 /*
1466 * This goes by insn->registerSize to pick the correct register, which messes
1467 * up if we're using (say) XMM or 8-bit register operands. That gets fixed in
1468 * fixupReg().
1469 */
1470 switch (insn->registerSizecxx . . $ InternalInstruction#registerSize.) {
1471 case 2:
1472 insn->regBasecxx . . $ InternalInstruction#regBase. = MODRM_REG_AXcxx . . $ MODRM_REG_AX.;
1473 insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase. = EA_REG_AXcxx . . $ EA_REG_AX.;
1474 break;
1475 case 4:
1476 insn->regBasecxx . . $ InternalInstruction#regBase. = MODRM_REG_EAXcxx . . $ MODRM_REG_EAX.;
1477 insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase. = EA_REG_EAXcxx . . $ EA_REG_EAX.;
1478 break;
1479 case 8:
1480 insn->regBasecxx . . $ InternalInstruction#regBase. = MODRM_REG_RAXcxx . . $ MODRM_REG_RAX.;
1481 insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase. = EA_REG_RAXcxx . . $ EA_REG_RAX.;
1482 break;
1483 }
1484
1485 reg |= rFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:40:9`!(insn->rexPrefix) << 3;
1486 rm |= bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3;
1487
1488 evexrm = 0;
1489 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX. && insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT.) {
1490 reg |= r2FromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:47:9`!(insn->vectorExtensionPrefix[1]) << 4;
1491 evexrm = xFromEVEX2of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:45:9`!(insn->vectorExtensionPrefix[1]) << 4;
1492 }
1493
1494 insn->regcxx . . $ InternalInstruction#reg. = (Regcxx . . $ Reg#)(insn->regBasecxx . . $ InternalInstruction#regBase. + reg);
1495
1496 switch (insn->addressSizecxx . . $ InternalInstruction#addressSize.) {
1497 case 2: {
1498 EABasecxx . . $ EABase# eaBaseBase = EA_BASE_BX_SIcxx . . $ EA_BASE_BX_SI.;
1499
1500 switch (mod) {
1501 case 0x0:
1502 if (rm == 0x6) {
1503 insn->eaBasecxx . . $ InternalInstruction#eaBase. = EA_BASE_NONEcxx . . $ EA_BASE_NONE.;
1504 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_16cxx . . $ EA_DISP_16.;
1505 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1506 return -1;
1507 } else {
1508 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(eaBaseBase + rm);
1509 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_NONEcxx . . $ EA_DISP_NONE.;
1510 }
1511 break;
1512 case 0x1:
1513 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(eaBaseBase + rm);
1514 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_8cxx . . $ EA_DISP_8.;
1515 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = 1;
1516 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1517 return -1;
1518 break;
1519 case 0x2:
1520 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(eaBaseBase + rm);
1521 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_16cxx . . $ EA_DISP_16.;
1522 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1523 return -1;
1524 break;
1525 case 0x3:
1526 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase. + rm);
1527 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1528 return -1;
1529 break;
1530 }
1531 break;
1532 }
1533
1534 case 4:
1535 case 8: {
1536 EABasecxx . . $ EABase# eaBaseBase = (insn->addressSizecxx . . $ InternalInstruction#addressSize. == 4 ? EA_BASE_EAXcxx . . $ EA_BASE_EAX. : EA_BASE_RAXcxx . . $ EA_BASE_RAX.);
1537
1538 switch (mod) {
1539 default: break;
1540 case 0x0:
1541 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_NONEcxx . . $ EA_DISP_NONE.; /* readSIB may override this */
1542 // In determining whether RIP-relative mode is used (rm=5),
1543 // or whether a SIB byte is present (rm=4),
1544 // the extension bits (REX.b and EVEX.x) are ignored.
1545 switch (rm & 7) {
1546 case 0x4: // SIB byte is present
1547 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (insn->addressSizecxx . . $ InternalInstruction#addressSize. == 4 ?
1548 EA_BASE_sibcxx . . $ EA_BASE_sib. : EA_BASE_sib64cxx . . $ EA_BASE_sib64.);
1549 if (readSIBcxx . . $ readSIB(a95f3859aee87d23).(insn) || readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1550 return -1;
1551 break;
1552 case 0x5: // RIP-relative
1553 insn->eaBasecxx . . $ InternalInstruction#eaBase. = EA_BASE_NONEcxx . . $ EA_BASE_NONE.;
1554 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_32cxx . . $ EA_DISP_32.;
1555 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1556 return -1;
1557 break;
1558 default:
1559 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(eaBaseBase + rm);
1560 break;
1561 }
1562 break;
1563 case 0x1:
1564 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = 1;
1565 /* FALLTHROUGH */
1566 case 0x2:
1567 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = (mod == 0x1 ? EA_DISP_8cxx . . $ EA_DISP_8. : EA_DISP_32cxx . . $ EA_DISP_32.);
1568 switch (rm & 7) {
1569 case 0x4: // SIB byte is present
1570 insn->eaBasecxx . . $ InternalInstruction#eaBase. = EA_BASE_sibcxx . . $ EA_BASE_sib.;
1571 if (readSIBcxx . . $ readSIB(a95f3859aee87d23).(insn) || readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1572 return -1;
1573 break;
1574 default:
1575 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(eaBaseBase + rm);
1576 if (readDisplacementcxx . . $ readDisplacement(a95f3859aee87d23).(insn))
1577 return -1;
1578 break;
1579 }
1580 break;
1581 case 0x3:
1582 insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. = EA_DISP_NONEcxx . . $ EA_DISP_NONE.;
1583 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)(insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase. + rm + evexrm);
1584 break;
1585 }
1586
1587 break;
1588 }
1589 } /* switch (insn->addressSize) */
1590
1591 return 0;
1592 }
1593
1594 #define GENERIC_FIXUP_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:1594:9`!(name, base, prefix, mask) \
1595 static uint16_t name(struct InternalInstruction *insn, \
1596 OperandType type, \
1597 uint8_t index, \
1598 uint8_t *valid) { \
1599 *valid = 1; \
1600 switch (type) { \
1601 default: \
1602 *valid = 0; \
1603 return 0; \
1604 case TYPE_Rv: \
1605 return base + index; \
1606 case TYPE_R8: \
1607 index &= mask; \
1608 if (index > 0xf) \
1609 *valid = 0; \
1610 if (insn->rexPrefix && \
1611 index >= 4 && index <= 7) { \
1612 return prefix##_SPL + (index - 4); \
1613 } else { \
1614 return prefix##_AL + index; \
1615 } \
1616 case TYPE_R16: \
1617 index &= mask; \
1618 if (index > 0xf) \
1619 *valid = 0; \
1620 return prefix##_AX + index; \
1621 case TYPE_R32: \
1622 index &= mask; \
1623 if (index > 0xf) \
1624 *valid = 0; \
1625 return prefix##_EAX + index; \
1626 case TYPE_R64: \
1627 index &= mask; \
1628 if (index > 0xf) \
1629 *valid = 0; \
1630 return prefix##_RAX + index; \
1631 case TYPE_ZMM: \
1632 return prefix##_ZMM0 + index; \
1633 case TYPE_YMM: \
1634 return prefix##_YMM0 + index; \
1635 case TYPE_XMM: \
1636 return prefix##_XMM0 + index; \
1637 case TYPE_VK: \
1638 index &= 0xf; \
1639 if (index > 7) \
1640 *valid = 0; \
1641 return prefix##_K0 + index; \
1642 case TYPE_MM64: \
1643 return prefix##_MM0 + (index & 0x7); \
1644 case TYPE_SEGMENTREG: \
1645 if ((index & 7) > 5) \
1646 *valid = 0; \
1647 return prefix##_ES + (index & 7); \
1648 case TYPE_DEBUGREG: \
1649 return prefix##_DR0 + index; \
1650 case TYPE_CONTROLREG: \
1651 return prefix##_CR0 + index; \
1652 case TYPE_BNDR: \
1653 if (index > 3) \
1654 *valid = 0; \
1655 return prefix##_BND0 + index; \
1656 case TYPE_MVSIBX: \
1657 return prefix##_XMM0 + index; \
1658 case TYPE_MVSIBY: \
1659 return prefix##_YMM0 + index; \
1660 case TYPE_MVSIBZ: \
1661 return prefix##_ZMM0 + index; \
1662 } \
1663 }
1664
1665 /*
1666 * fixup*Value - Consults an operand type to determine the meaning of the
1667 * reg or R/M field. If the operand is an XMM operand, for example, an
1668 * operand would be XMM0 instead of AX, which readModRM() would otherwise
1669 * misinterpret it as.
1670 *
1671 * @param insn - The instruction containing the operand.
1672 * @param type - The operand type.
1673 * @param index - The existing value of the field as reported by readModRM().
1674 * @param valid - The address of a uint8_t. The target is set to 1 if the
1675 * field is valid for the register class; 0 if not.
1676 * @return - The proper value.
1677 */
1678 GENERIC_FIXUP_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:1594:9`!(fixupRegValue, insn->regBase, MODRM_REG, 0x1f)
1679 GENERIC_FIXUP_FUNCcxx . . $ `arch/X86/X86DisassemblerDecoder.c:1594:9`!(fixupRMValue, insn->eaRegBase, EA_REG, 0xf)
1680
1681 /*
1682 * fixupReg - Consults an operand specifier to determine which of the
1683 * fixup*Value functions to use in correcting readModRM()'ss interpretation.
1684 *
1685 * @param insn - See fixup*Value().
1686 * @param op - The operand specifier.
1687 * @return - 0 if fixup was successful; -1 if the register returned was
1688 * invalid for its class.
1689 */
1690 static int fixupRegcxx . . $ fixupReg(9c829f6f5f78572).(struct InternalInstructioncxx . . $ InternalInstruction# *insn,
1691 const struct OperandSpecifiercxx . . $ OperandSpecifier# *op)
1692 {
1693 uint8_tcxx . . $ uint8_t# valid;
1694
1695 switch ((OperandEncodingcxx . . $ OperandEncoding#)op->encodingcxx . . $ OperandSpecifier#encoding.) {
1696 default:
1697 // debug("Expected a REG or R/M encoding in fixupReg");
1698 return -1;
1699 case ENCODING_VVVVcxx . . $ ENCODING_VVVV.:
1700 insn->vvvvcxx . . $ InternalInstruction#vvvv. = (Regcxx . . $ Reg#)fixupRegValuecxx . . $ fixupRegValue(f35eb2ad61e04bee).(insn,
1701 (OperandTypecxx . . $ OperandType#)op->typecxx . . $ OperandSpecifier#type.,
1702 insn->vvvvcxx . . $ InternalInstruction#vvvv.,
1703 &valid);
1704 if (!valid)
1705 return -1;
1706 break;
1707 case ENCODING_REGcxx . . $ ENCODING_REG.:
1708 insn->regcxx . . $ InternalInstruction#reg. = (Regcxx . . $ Reg#)fixupRegValuecxx . . $ fixupRegValue(f35eb2ad61e04bee).(insn,
1709 (OperandTypecxx . . $ OperandType#)op->typecxx . . $ OperandSpecifier#type.,
1710 insn->regcxx . . $ InternalInstruction#reg. - insn->regBasecxx . . $ InternalInstruction#regBase.,
1711 &valid);
1712 if (!valid)
1713 return -1;
1714 break;
1715 CASE_ENCODING_RMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:347:9`!:
1716 if (insn->eaBasecxx . . $ InternalInstruction#eaBase. >= insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase.) {
1717 insn->eaBasecxx . . $ InternalInstruction#eaBase. = (EABasecxx . . $ EABase#)fixupRMValuecxx . . $ fixupRMValue(f35eb2ad61e04bee).(insn,
1718 (OperandTypecxx . . $ OperandType#)op->typecxx . . $ OperandSpecifier#type.,
1719 insn->eaBasecxx . . $ InternalInstruction#eaBase. - insn->eaRegBasecxx . . $ InternalInstruction#eaRegBase.,
1720 &valid);
1721 if (!valid)
1722 return -1;
1723 }
1724 break;
1725 }
1726
1727 return 0;
1728 }
1729
1730 /*
1731 * readOpcodeRegister - Reads an operand from the opcode field of an
1732 * instruction and interprets it appropriately given the operand width.
1733 * Handles AddRegFrm instructions.
1734 *
1735 * @param insn - the instruction whose opcode field is to be read.
1736 * @param size - The width (in bytes) of the register being specified.
1737 * 1 means AL and friends, 2 means AX, 4 means EAX, and 8 means
1738 * RAX.
1739 * @return - 0 on success; nonzero otherwise.
1740 */
1741 static int readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(struct InternalInstructioncxx . . $ InternalInstruction#* insn, uint8_tcxx . . $ uint8_t# size)
1742 {
1743 if (size == 0)
1744 size = insn->registerSizecxx . . $ InternalInstruction#registerSize.;
1745
1746 switch (size) {
1747 case 1:
1748 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. = (Regcxx . . $ Reg#)(MODRM_REG_ALcxx . . $ MODRM_REG_AL. + ((bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3)
1749 | (insn->opcodecxx . . $ InternalInstruction#opcode. & 7)));
1750 if (insn->rexPrefixcxx . . $ InternalInstruction#rexPrefix. &&
1751 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. >= MODRM_REG_ALcxx . . $ MODRM_REG_AL. + 0x4 &&
1752 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. < MODRM_REG_ALcxx . . $ MODRM_REG_AL. + 0x8) {
1753 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. = (Regcxx . . $ Reg#)(MODRM_REG_SPLcxx . . $ MODRM_REG_SPL.
1754 + (insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. - MODRM_REG_ALcxx . . $ MODRM_REG_AL. - 4));
1755 }
1756
1757 break;
1758 case 2:
1759 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. = (Regcxx . . $ Reg#)(MODRM_REG_AXcxx . . $ MODRM_REG_AX.
1760 + ((bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3)
1761 | (insn->opcodecxx . . $ InternalInstruction#opcode. & 7)));
1762 break;
1763 case 4:
1764 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. = (Regcxx . . $ Reg#)(MODRM_REG_EAXcxx . . $ MODRM_REG_EAX.
1765 + ((bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3)
1766 | (insn->opcodecxx . . $ InternalInstruction#opcode. & 7)));
1767 break;
1768 case 8:
1769 insn->opcodeRegistercxx . . $ InternalInstruction#opcodeRegister. = (Regcxx . . $ Reg#)(MODRM_REG_RAXcxx . . $ MODRM_REG_RAX.
1770 + ((bFromREXcxx . . $ `arch/X86/X86DisassemblerDecoder.h:42:9`!(insn->rexPrefix) << 3)
1771 | (insn->opcodecxx . . $ InternalInstruction#opcode. & 7)));
1772 break;
1773 }
1774
1775 return 0;
1776 }
1777
1778 /*
1779 * readImmediate - Consumes an immediate operand from an instruction, given the
1780 * desired operand size.
1781 *
1782 * @param insn - The instruction whose operand is to be read.
1783 * @param size - The width (in bytes) of the operand.
1784 * @return - 0 if the immediate was successfully consumed; nonzero
1785 * otherwise.
1786 */
1787 static int readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(struct InternalInstructioncxx . . $ InternalInstruction#* insn, uint8_tcxx . . $ uint8_t# size)
1788 {
1789 uint8_tcxx . . $ uint8_t# imm8;
1790 uint16_tcxx . . $ uint16_t# imm16;
1791 uint32_tcxx . . $ uint32_t# imm32;
1792 uint64_tcxx . . $ uint64_t# imm64;
1793
1794 if (insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed. == 2) {
1795 // debug("Already consumed two immediates");
1796 return -1;
1797 }
1798
1799 if (size == 0)
1800 size = insn->immediateSizecxx . . $ InternalInstruction#immediateSize.;
1801 else
1802 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = size;
1803
1804 insn->immediateOffsetcxx . . $ InternalInstruction#immediateOffset. = insn->readerCursorcxx . . $ InternalInstruction#readerCursor. - insn->startLocationcxx . . $ InternalInstruction#startLocation.;
1805
1806 switch (size) {
1807 case 1:
1808 if (consumeBytecxx . . $ consumeByte(43568041cca0be03).(insn, &imm8))
1809 return -1;
1810
1811 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.] = imm8;
1812 break;
1813 case 2:
1814 if (consumeUInt16cxx . . $ consumeUInt16(4e91f7a1fe61500d).(insn, &imm16))
1815 return -1;
1816
1817 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.] = imm16;
1818 break;
1819 case 4:
1820 if (consumeUInt32cxx . . $ consumeUInt32(d65ed2be04a10e71).(insn, &imm32))
1821 return -1;
1822
1823 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.] = imm32;
1824 break;
1825 case 8:
1826 if (consumeUInt64cxx . . $ consumeUInt64(5213fb89f558b05f).(insn, &imm64))
1827 return -1;
1828 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.] = imm64;
1829 break;
1830 }
1831
1832 insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.++;
1833
1834 return 0;
1835 }
1836
1837 /*
1838 * readVVVV - Consumes vvvv from an instruction if it has a VEX prefix.
1839 *
1840 * @param insn - The instruction whose operand is to be read.
1841 * @return - 0 if the vvvv was successfully consumed; nonzero
1842 * otherwise.
1843 */
1844 static int readVVVVcxx . . $ readVVVV(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1845 {
1846 int vvvv;
1847
1848 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX.)
1849 vvvv = (v2FromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:56:9`!(insn->vectorExtensionPrefix[3]) << 4 |
1850 vvvvFromEVEX3of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:50:9`!(insn->vectorExtensionPrefix[2]));
1851 else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_3Bcxx . . $ TYPE_VEX_3B.)
1852 vvvv = vvvvFromVEX3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:64:9`!(insn->vectorExtensionPrefix[2]);
1853 else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_VEX_2Bcxx . . $ TYPE_VEX_2B.)
1854 vvvv = vvvvFromVEX2of2cxx . . $ `arch/X86/X86DisassemblerDecoder.h:69:9`!(insn->vectorExtensionPrefix[1]);
1855 else if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_XOPcxx . . $ TYPE_XOP.)
1856 vvvv = vvvvFromXOP3of3cxx . . $ `arch/X86/X86DisassemblerDecoder.h:78:9`!(insn->vectorExtensionPrefix[2]);
1857 else
1858 return -1;
1859
1860 if (insn->modecxx . . $ InternalInstruction#mode. != MODE_64BITcxx . . $ MODE_64BIT.)
1861 vvvv &= 0xf; // Can only clear bit 4. Bit 3 must be cleared later.
1862
1863 insn->vvvvcxx . . $ InternalInstruction#vvvv. = (Regcxx . . $ Reg#)vvvv;
1864
1865 return 0;
1866 }
1867
1868 /*
1869 * readMaskRegister - Reads an mask register from the opcode field of an
1870 * instruction.
1871 *
1872 * @param insn - The instruction whose opcode field is to be read.
1873 * @return - 0 on success; nonzero otherwise.
1874 */
1875 static int readMaskRegistercxx . . $ readMaskRegister(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1876 {
1877 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. != TYPE_EVEXcxx . . $ TYPE_EVEX.)
1878 return -1;
1879
1880 insn->writemaskcxx . . $ InternalInstruction#writemask. = (Regcxx . . $ Reg#)(aaaFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:57:9`!(insn->vectorExtensionPrefix[3]));
1881
1882 return 0;
1883 }
1884
1885 /*
1886 * readOperands - Consults the specifier for an instruction and consumes all
1887 * operands for that instruction, interpreting them as it goes.
1888 *
1889 * @param insn - The instruction whose operands are to be read and interpreted.
1890 * @return - 0 if all operands could be read; nonzero otherwise.
1891 */
1892 static int readOperandscxx . . $ readOperands(a95f3859aee87d23).(struct InternalInstructioncxx . . $ InternalInstruction#* insn)
1893 {
1894 int hasVVVV, needVVVV;
1895 int sawRegImm = 0;
1896 int i;
1897
1898 /* If non-zero vvvv specified, need to make sure one of the operands
1899 uses it. */
1900 hasVVVV = !readVVVVcxx . . $ readVVVV(a95f3859aee87d23).(insn);
1901 needVVVV = hasVVVV && (insn->vvvvcxx . . $ InternalInstruction#vvvv. != 0);
1902
1903 for (i = 0; i < X86_MAX_OPERANDScxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:470:9`!; ++i) {
1904 const OperandSpecifiercxx . . $ OperandSpecifier# *op = &x86OperandSetscxx . . $ x86OperandSets.[insn->speccxx . . $ InternalInstruction#spec.->operandscxx . . $ InstructionSpecifier#operands.][i];
1905 switch (op->encodingcxx . . $ OperandSpecifier#encoding.) {
1906 case ENCODING_NONEcxx . . $ ENCODING_NONE.:
1907 case ENCODING_SIcxx . . $ ENCODING_SI.:
1908 case ENCODING_DIcxx . . $ ENCODING_DI.:
1909 break;
1910
1911 CASE_ENCODING_VSIBcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:356:9`!:
1912 // VSIB can use the V2 bit so check only the other bits.
1913 if (needVVVV)
1914 needVVVV = hasVVVV & ((insn->vvvvcxx . . $ InternalInstruction#vvvv. & 0xf) != 0);
1915
1916 if (readModRMcxx . . $ readModRM(a95f3859aee87d23).(insn))
1917 return -1;
1918
1919 // Reject if SIB wasn't used.
1920 if (insn->eaBasecxx . . $ InternalInstruction#eaBase. != EA_BASE_sibcxx . . $ EA_BASE_sib. && insn->eaBasecxx . . $ InternalInstruction#eaBase. != EA_BASE_sib64cxx . . $ EA_BASE_sib64.)
1921 return -1;
1922
1923 // If sibIndex was set to SIB_INDEX_NONE, index offset is 4.
1924 if (insn->sibIndexcxx . . $ InternalInstruction#sibIndex. == SIB_INDEX_NONEcxx . . $ SIB_INDEX_NONE.)
1925 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase. + 4);
1926
1927 // If EVEX.v2 is set this is one of the 16-31 registers.
1928 if (insn->vectorExtensionTypecxx . . $ InternalInstruction#vectorExtensionType. == TYPE_EVEXcxx . . $ TYPE_EVEX. && insn->modecxx . . $ InternalInstruction#mode. == MODE_64BITcxx . . $ MODE_64BIT. &&
1929 v2FromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:56:9`!(insn->vectorExtensionPrefix[3]))
1930 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(insn->sibIndexcxx . . $ InternalInstruction#sibIndex. + 16);
1931
1932 // Adjust the index register to the correct size.
1933 switch (op->typecxx . . $ OperandSpecifier#type.) {
1934 default:
1935 // debug("Unhandled VSIB index type");
1936 return -1;
1937 case TYPE_MVSIBXcxx . . $ TYPE_MVSIBX.:
1938 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(SIB_INDEX_XMM0cxx . . $ SIB_INDEX_XMM0. +
1939 (insn->sibIndexcxx . . $ InternalInstruction#sibIndex. - insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase.));
1940 break;
1941 case TYPE_MVSIBYcxx . . $ TYPE_MVSIBY.:
1942 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(SIB_INDEX_YMM0cxx . . $ SIB_INDEX_YMM0. +
1943 (insn->sibIndexcxx . . $ InternalInstruction#sibIndex. - insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase.));
1944 break;
1945 case TYPE_MVSIBZcxx . . $ TYPE_MVSIBZ.:
1946 insn->sibIndexcxx . . $ InternalInstruction#sibIndex. = (SIBIndexcxx . . $ SIBIndex#)(SIB_INDEX_ZMM0cxx . . $ SIB_INDEX_ZMM0. +
1947 (insn->sibIndexcxx . . $ InternalInstruction#sibIndex. - insn->sibIndexBasecxx . . $ InternalInstruction#sibIndexBase.));
1948 break;
1949 }
1950
1951 // Apply the AVX512 compressed displacement scaling factor.
1952 if (op->encodingcxx . . $ OperandSpecifier#encoding. != ENCODING_REGcxx . . $ ENCODING_REG. && insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. == EA_DISP_8cxx . . $ EA_DISP_8.)
1953 insn->displacementcxx . . $ InternalInstruction#displacement. *= 1 << (op->encodingcxx . . $ OperandSpecifier#encoding. - ENCODING_VSIBcxx . . $ ENCODING_VSIB.);
1954 break;
1955
1956 case ENCODING_REGcxx . . $ ENCODING_REG.:
1957 CASE_ENCODING_RMcxx . . $ `arch/X86/X86DisassemblerDecoderCommon.h:347:9`!:
1958 if (readModRMcxx . . $ readModRM(a95f3859aee87d23).(insn))
1959 return -1;
1960
1961 if (fixupRegcxx . . $ fixupReg(9c829f6f5f78572).(insn, op))
1962 return -1;
1963
1964 // Apply the AVX512 compressed displacement scaling factor.
1965 if (op->encodingcxx . . $ OperandSpecifier#encoding. != ENCODING_REGcxx . . $ ENCODING_REG. && insn->eaDisplacementcxx . . $ InternalInstruction#eaDisplacement. == EA_DISP_8cxx . . $ EA_DISP_8.)
1966 insn->displacementcxx . . $ InternalInstruction#displacement. *= 1 << (op->encodingcxx . . $ OperandSpecifier#encoding. - ENCODING_RMcxx . . $ ENCODING_RM.);
1967 break;
1968
1969 case ENCODING_IBcxx . . $ ENCODING_IB.:
1970 if (sawRegImm) {
1971 /* Saw a register immediate so don't read again and instead split the
1972 previous immediate. FIXME: This is a hack. */
1973 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.] =
1974 insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed. - 1] & 0xf;
1975 ++insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed.;
1976 break;
1977 }
1978 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, 1))
1979 return -1;
1980 if (op->typecxx . . $ OperandSpecifier#type. == TYPE_XMMcxx . . $ TYPE_XMM. || op->typecxx . . $ OperandSpecifier#type. == TYPE_YMMcxx . . $ TYPE_YMM.)
1981 sawRegImm = 1;
1982 break;
1983
1984 case ENCODING_IWcxx . . $ ENCODING_IW.:
1985 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, 2))
1986 return -1;
1987 break;
1988
1989 case ENCODING_IDcxx . . $ ENCODING_ID.:
1990 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, 4))
1991 return -1;
1992 break;
1993
1994 case ENCODING_IOcxx . . $ ENCODING_IO.:
1995 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, 8))
1996 return -1;
1997 break;
1998
1999 case ENCODING_Ivcxx . . $ ENCODING_Iv.:
2000 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, insn->immediateSizecxx . . $ InternalInstruction#immediateSize.))
2001 return -1;
2002 break;
2003
2004 case ENCODING_Iacxx . . $ ENCODING_Ia.:
2005 if (readImmediatecxx . . $ readImmediate(141e3a6baeb10385).(insn, insn->addressSizecxx . . $ InternalInstruction#addressSize.))
2006 return -1;
2007 /* Direct memory-offset (moffset) immediate will get mapped
2008 to memory operand later. We want the encoding info to
2009 reflect that as well. */
2010 insn->displacementOffsetcxx . . $ InternalInstruction#displacementOffset. = insn->immediateOffsetcxx . . $ InternalInstruction#immediateOffset.;
2011 insn->consumedDisplacementcxx . . $ InternalInstruction#consumedDisplacement. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2012 insn->displacementSizecxx . . $ InternalInstruction#displacementSize. = insn->immediateSizecxx . . $ InternalInstruction#immediateSize.;
2013 insn->displacementcxx . . $ InternalInstruction#displacement. = insn->immediatescxx . . $ InternalInstruction#immediates.[insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed. - 1];
2014 insn->immediateOffsetcxx . . $ InternalInstruction#immediateOffset. = 0;
2015 insn->immediateSizecxx . . $ InternalInstruction#immediateSize. = 0;
2016 break;
2017
2018 case ENCODING_IRCcxx . . $ ENCODING_IRC.:
2019 insn->RCcxx . . $ InternalInstruction#RC. = (l2FromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:53:9`!(insn->vectorExtensionPrefix[3]) << 1) |
2020 lFromEVEX4of4cxx . . $ `arch/X86/X86DisassemblerDecoder.h:54:9`!(insn->vectorExtensionPrefix[3]);
2021 break;
2022
2023 case ENCODING_RBcxx . . $ ENCODING_RB.:
2024 if (readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(insn, 1))
2025 return -1;
2026 break;
2027
2028 case ENCODING_RWcxx . . $ ENCODING_RW.:
2029 if (readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(insn, 2))
2030 return -1;
2031 break;
2032
2033 case ENCODING_RDcxx . . $ ENCODING_RD.:
2034 if (readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(insn, 4))
2035 return -1;
2036 break;
2037
2038 case ENCODING_ROcxx . . $ ENCODING_RO.:
2039 if (readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(insn, 8))
2040 return -1;
2041 break;
2042
2043 case ENCODING_Rvcxx . . $ ENCODING_Rv.:
2044 if (readOpcodeRegistercxx . . $ readOpcodeRegister(141e3a6baeb10385).(insn, 0))
2045 return -1;
2046 break;
2047
2048 case ENCODING_FPcxx . . $ ENCODING_FP.:
2049 break;
2050
2051 case ENCODING_VVVVcxx . . $ ENCODING_VVVV.:
2052 if (!hasVVVV)
2053 return -1;
2054
2055 needVVVV = 0; /* Mark that we have found a VVVV operand. */
2056
2057 if (insn->modecxx . . $ InternalInstruction#mode. != MODE_64BITcxx . . $ MODE_64BIT.)
2058 insn->vvvvcxx . . $ InternalInstruction#vvvv. = (Regcxx . . $ Reg#)(insn->vvvvcxx . . $ InternalInstruction#vvvv. & 0x7);
2059
2060 if (fixupRegcxx . . $ fixupReg(9c829f6f5f78572).(insn, op))
2061 return -1;
2062 break;
2063
2064 case ENCODING_WRITEMASKcxx . . $ ENCODING_WRITEMASK.:
2065 if (readMaskRegistercxx . . $ readMaskRegister(a95f3859aee87d23).(insn))
2066 return -1;
2067 break;
2068
2069 case ENCODING_DUPcxx . . $ ENCODING_DUP.:
2070 break;
2071
2072 default:
2073 // dbgprintf(insn, "Encountered an operand with an unknown encoding.");
2074 return -1;
2075 }
2076 }
2077
2078 /* If we didn't find ENCODING_VVVV operand, but non-zero vvvv present, fail */
2079 if (needVVVV)
2080 return -1;
2081
2082 return 0;
2083 }
2084
2085 // return True if instruction is illegal to use with prefixes
2086 // This also check & fix the isPrefixNN when a prefix is irrelevant.
2087 static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! checkPrefixcxx . . $ checkPrefix(1d2bb9784dc87cb7).(struct InternalInstructioncxx . . $ InternalInstruction# *insn)
2088 {
2089 // LOCK prefix
2090 if (insn->hasLockPrefixcxx . . $ InternalInstruction#hasLockPrefix.) {
2091 switch(insn->instructionIDcxx . . $ InternalInstruction#instructionID.) {
2092 default:
2093 // invalid LOCK
2094 return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
2095
2096 // nop dword [rax]
2097 case X86_NOOPLcxx . . $ X86_NOOPL.:
2098
2099 // DEC
2100 case X86_DEC16mcxx . . $ X86_DEC16m.:
2101 case X86_DEC32mcxx . . $ X86_DEC32m.:
2102 case X86_DEC64mcxx . . $ X86_DEC64m.:
2103 case X86_DEC8mcxx . . $ X86_DEC8m.:
2104
2105 // ADC
2106 case X86_ADC16micxx . . $ X86_ADC16mi.:
2107 case X86_ADC16mi8cxx . . $ X86_ADC16mi8.:
2108 case X86_ADC16mrcxx . . $ X86_ADC16mr.:
2109 case X86_ADC32micxx . . $ X86_ADC32mi.:
2110 case X86_ADC32mi8cxx . . $ X86_ADC32mi8.:
2111 case X86_ADC32mrcxx . . $ X86_ADC32mr.:
2112 case X86_ADC64mi32cxx . . $ X86_ADC64mi32.:
2113 case X86_ADC64mi8cxx . . $ X86_ADC64mi8.:
2114 case X86_ADC64mrcxx . . $ X86_ADC64mr.:
2115 case X86_ADC8micxx . . $ X86_ADC8mi.:
2116 case X86_ADC8mi8cxx . . $ X86_ADC8mi8.:
2117 case X86_ADC8mrcxx . . $ X86_ADC8mr.:
2118 case X86_ADC8rmcxx . . $ X86_ADC8rm.:
2119 case X86_ADC16rmcxx . . $ X86_ADC16rm.:
2120 case X86_ADC32rmcxx . . $ X86_ADC32rm.:
2121 case X86_ADC64rmcxx . . $ X86_ADC64rm.:
2122
2123 // ADD
2124 case X86_ADD16micxx . . $ X86_ADD16mi.:
2125 case X86_ADD16mi8cxx . . $ X86_ADD16mi8.:
2126 case X86_ADD16mrcxx . . $ X86_ADD16mr.:
2127 case X86_ADD32micxx . . $ X86_ADD32mi.:
2128 case X86_ADD32mi8cxx . . $ X86_ADD32mi8.:
2129 case X86_ADD32mrcxx . . $ X86_ADD32mr.:
2130 case X86_ADD64mi32cxx . . $ X86_ADD64mi32.:
2131 case X86_ADD64mi8cxx . . $ X86_ADD64mi8.:
2132 case X86_ADD64mrcxx . . $ X86_ADD64mr.:
2133 case X86_ADD8micxx . . $ X86_ADD8mi.:
2134 case X86_ADD8mi8cxx . . $ X86_ADD8mi8.:
2135 case X86_ADD8mrcxx . . $ X86_ADD8mr.:
2136 case X86_ADD8rmcxx . . $ X86_ADD8rm.:
2137 case X86_ADD16rmcxx . . $ X86_ADD16rm.:
2138 case X86_ADD32rmcxx . . $ X86_ADD32rm.:
2139 case X86_ADD64rmcxx . . $ X86_ADD64rm.:
2140
2141 // AND
2142 case X86_AND16micxx . . $ X86_AND16mi.:
2143 case X86_AND16mi8cxx . . $ X86_AND16mi8.:
2144 case X86_AND16mrcxx . . $ X86_AND16mr.:
2145 case X86_AND32micxx . . $ X86_AND32mi.:
2146 case X86_AND32mi8cxx . . $ X86_AND32mi8.:
2147 case X86_AND32mrcxx . . $ X86_AND32mr.:
2148 case X86_AND64mi32cxx . . $ X86_AND64mi32.:
2149 case X86_AND64mi8cxx . . $ X86_AND64mi8.:
2150 case X86_AND64mrcxx . . $ X86_AND64mr.:
2151 case X86_AND8micxx . . $ X86_AND8mi.:
2152 case X86_AND8mi8cxx . . $ X86_AND8mi8.:
2153 case X86_AND8mrcxx . . $ X86_AND8mr.:
2154 case X86_AND8rmcxx . . $ X86_AND8rm.:
2155 case X86_AND16rmcxx . . $ X86_AND16rm.:
2156 case X86_AND32rmcxx . . $ X86_AND32rm.:
2157 case X86_AND64rmcxx . . $ X86_AND64rm.:
2158
2159 // BTC
2160 case X86_BTC16mi8cxx . . $ X86_BTC16mi8.:
2161 case X86_BTC16mrcxx . . $ X86_BTC16mr.:
2162 case X86_BTC32mi8cxx . . $ X86_BTC32mi8.:
2163 case X86_BTC32mrcxx . . $ X86_BTC32mr.:
2164 case X86_BTC64mi8cxx . . $ X86_BTC64mi8.:
2165 case X86_BTC64mrcxx . . $ X86_BTC64mr.:
2166
2167 // BTR
2168 case X86_BTR16mi8cxx . . $ X86_BTR16mi8.:
2169 case X86_BTR16mrcxx . . $ X86_BTR16mr.:
2170 case X86_BTR32mi8cxx . . $ X86_BTR32mi8.:
2171 case X86_BTR32mrcxx . . $ X86_BTR32mr.:
2172 case X86_BTR64mi8cxx . . $ X86_BTR64mi8.:
2173 case X86_BTR64mrcxx . . $ X86_BTR64mr.:
2174
2175 // BTS
2176 case X86_BTS16mi8cxx . . $ X86_BTS16mi8.:
2177 case X86_BTS16mrcxx . . $ X86_BTS16mr.:
2178 case X86_BTS32mi8cxx . . $ X86_BTS32mi8.:
2179 case X86_BTS32mrcxx . . $ X86_BTS32mr.:
2180 case X86_BTS64mi8cxx . . $ X86_BTS64mi8.:
2181 case X86_BTS64mrcxx . . $ X86_BTS64mr.:
2182
2183 // CMPXCHG
2184 case X86_CMPXCHG16Bcxx . . $ X86_CMPXCHG16B.:
2185 case X86_CMPXCHG16rmcxx . . $ X86_CMPXCHG16rm.:
2186 case X86_CMPXCHG32rmcxx . . $ X86_CMPXCHG32rm.:
2187 case X86_CMPXCHG64rmcxx . . $ X86_CMPXCHG64rm.:
2188 case X86_CMPXCHG8rmcxx . . $ X86_CMPXCHG8rm.:
2189 case X86_CMPXCHG8Bcxx . . $ X86_CMPXCHG8B.:
2190
2191 // INC
2192 case X86_INC16mcxx . . $ X86_INC16m.:
2193 case X86_INC32mcxx . . $ X86_INC32m.:
2194 case X86_INC64mcxx . . $ X86_INC64m.:
2195 case X86_INC8mcxx . . $ X86_INC8m.:
2196
2197 // NEG
2198 case X86_NEG16mcxx . . $ X86_NEG16m.:
2199 case X86_NEG32mcxx . . $ X86_NEG32m.:
2200 case X86_NEG64mcxx . . $ X86_NEG64m.:
2201 case X86_NEG8mcxx . . $ X86_NEG8m.:
2202
2203 // NOT
2204 case X86_NOT16mcxx . . $ X86_NOT16m.:
2205 case X86_NOT32mcxx . . $ X86_NOT32m.:
2206 case X86_NOT64mcxx . . $ X86_NOT64m.:
2207 case X86_NOT8mcxx . . $ X86_NOT8m.:
2208
2209 // OR
2210 case X86_OR16micxx . . $ X86_OR16mi.:
2211 case X86_OR16mi8cxx . . $ X86_OR16mi8.:
2212 case X86_OR16mrcxx . . $ X86_OR16mr.:
2213 case X86_OR32micxx . . $ X86_OR32mi.:
2214 case X86_OR32mi8cxx . . $ X86_OR32mi8.:
2215 case X86_OR32mrcxx . . $ X86_OR32mr.:
2216 case X86_OR64mi32cxx . . $ X86_OR64mi32.:
2217 case X86_OR64mi8cxx . . $ X86_OR64mi8.:
2218 case X86_OR64mrcxx . . $ X86_OR64mr.:
2219 case X86_OR8mi8cxx . . $ X86_OR8mi8.:
2220 case X86_OR8micxx . . $ X86_OR8mi.:
2221 case X86_OR8mrcxx . . $ X86_OR8mr.:
2222 case X86_OR8rmcxx . . $ X86_OR8rm.:
2223 case X86_OR16rmcxx . . $ X86_OR16rm.:
2224 case X86_OR32rmcxx . . $ X86_OR32rm.:
2225 case X86_OR64rmcxx . . $ X86_OR64rm.:
2226
2227 // SBB
2228 case X86_SBB16micxx . . $ X86_SBB16mi.:
2229 case X86_SBB16mi8cxx . . $ X86_SBB16mi8.:
2230 case X86_SBB16mrcxx . . $ X86_SBB16mr.:
2231 case X86_SBB32micxx . . $ X86_SBB32mi.:
2232 case X86_SBB32mi8cxx . . $ X86_SBB32mi8.:
2233 case X86_SBB32mrcxx . . $ X86_SBB32mr.:
2234 case X86_SBB64mi32cxx . . $ X86_SBB64mi32.:
2235 case X86_SBB64mi8cxx . . $ X86_SBB64mi8.:
2236 case X86_SBB64mrcxx . . $ X86_SBB64mr.:
2237 case X86_SBB8micxx . . $ X86_SBB8mi.:
2238 case X86_SBB8mi8cxx . . $ X86_SBB8mi8.:
2239 case X86_SBB8mrcxx . . $ X86_SBB8mr.:
2240
2241 // SUB
2242 case X86_SUB16micxx . . $ X86_SUB16mi.:
2243 case X86_SUB16mi8cxx . . $ X86_SUB16mi8.:
2244 case X86_SUB16mrcxx . . $ X86_SUB16mr.:
2245 case X86_SUB32micxx . . $ X86_SUB32mi.:
2246 case X86_SUB32mi8cxx . . $ X86_SUB32mi8.:
2247 case X86_SUB32mrcxx . . $ X86_SUB32mr.:
2248 case X86_SUB64mi32cxx . . $ X86_SUB64mi32.:
2249 case X86_SUB64mi8cxx . . $ X86_SUB64mi8.:
2250 case X86_SUB64mrcxx . . $ X86_SUB64mr.:
2251 case X86_SUB8mi8cxx . . $ X86_SUB8mi8.:
2252 case X86_SUB8micxx . . $ X86_SUB8mi.:
2253 case X86_SUB8mrcxx . . $ X86_SUB8mr.:
2254 case X86_SUB8rmcxx . . $ X86_SUB8rm.:
2255 case X86_SUB16rmcxx . . $ X86_SUB16rm.:
2256 case X86_SUB32rmcxx . . $ X86_SUB32rm.:
2257 case X86_SUB64rmcxx . . $ X86_SUB64rm.:
2258
2259 // XADD
2260 case X86_XADD16rmcxx . . $ X86_XADD16rm.:
2261 case X86_XADD32rmcxx . . $ X86_XADD32rm.:
2262 case X86_XADD64rmcxx . . $ X86_XADD64rm.:
2263 case X86_XADD8rmcxx . . $ X86_XADD8rm.:
2264
2265 // XCHG
2266 case X86_XCHG16rmcxx . . $ X86_XCHG16rm.:
2267 case X86_XCHG32rmcxx . . $ X86_XCHG32rm.:
2268 case X86_XCHG64rmcxx . . $ X86_XCHG64rm.:
2269 case X86_XCHG8rmcxx . . $ X86_XCHG8rm.:
2270
2271 // XOR
2272 case X86_XOR16micxx . . $ X86_XOR16mi.:
2273 case X86_XOR16mi8cxx . . $ X86_XOR16mi8.:
2274 case X86_XOR16mrcxx . . $ X86_XOR16mr.:
2275 case X86_XOR32micxx . . $ X86_XOR32mi.:
2276 case X86_XOR32mi8cxx . . $ X86_XOR32mi8.:
2277 case X86_XOR32mrcxx . . $ X86_XOR32mr.:
2278 case X86_XOR64mi32cxx . . $ X86_XOR64mi32.:
2279 case X86_XOR64mi8cxx . . $ X86_XOR64mi8.:
2280 case X86_XOR64mrcxx . . $ X86_XOR64mr.:
2281 case X86_XOR8mi8cxx . . $ X86_XOR8mi8.:
2282 case X86_XOR8micxx . . $ X86_XOR8mi.:
2283 case X86_XOR8mrcxx . . $ X86_XOR8mr.:
2284 case X86_XOR8rmcxx . . $ X86_XOR8rm.:
2285 case X86_XOR16rmcxx . . $ X86_XOR16rm.:
2286 case X86_XOR32rmcxx . . $ X86_XOR32rm.:
2287 case X86_XOR64rmcxx . . $ X86_XOR64rm.:
2288
2289 // this instruction can be used with LOCK prefix
2290 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2291 }
2292 }
2293
2294 #if 0
2295 // REPNE prefix
2296 if (insn->repeatPrefix) {
2297 // 0xf2 can be a part of instruction encoding, but not really a prefix.
2298 // In such a case, clear it.
2299 if (insn->twoByteEscape == 0x0f) {
2300 insn->prefix0 = 0;
2301 }
2302 }
2303 #endif
2304
2305 // no invalid prefixes
2306 return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
2307 }
2308
2309 /*
2310 * decodeInstruction - Reads and interprets a full instruction provided by the
2311 * user.
2312 *
2313 * @param insn - A pointer to the instruction to be populated. Must be
2314 * pre-allocated.
2315 * @param reader - The function to be used to read the instruction's bytes.
2316 * @param readerArg - A generic argument to be passed to the reader to store
2317 * any internal state.
2318 * @param startLoc - The address (in the reader's address space) of the first
2319 * byte in the instruction.
2320 * @param mode - The mode (real mode, IA-32e, or IA-32e in 64-bit mode) to
2321 * decode the instruction in.
2322 * @return - 0 if instruction is valid; nonzero if not.
2323 */
2324 int decodeInstructioncxx . . $ decodeInstruction(f2be436de624c839).(struct InternalInstructioncxx . . $ InternalInstruction# *insn,
2325 byteReader_tcxx . . $ byteReader_t# reader,
2326 const void *readerArg,
2327 uint64_tcxx . . $ uint64_t# startLoc,
2328 DisassemblerModecxx . . $ DisassemblerMode# mode)
2329 {
2330 insn->readercxx . . $ InternalInstruction#reader. = reader;
2331 insn->readerArgcxx . . $ InternalInstruction#readerArg. = readerArg;
2332 insn->startLocationcxx . . $ InternalInstruction#startLocation. = startLoc;
2333 insn->readerCursorcxx . . $ InternalInstruction#readerCursor. = startLoc;
2334 insn->modecxx . . $ InternalInstruction#mode. = mode;
2335 insn->numImmediatesConsumedcxx . . $ InternalInstruction#numImmediatesConsumed. = 0;
2336
2337 if (readPrefixescxx . . $ readPrefixes(a95f3859aee87d23).(insn) ||
2338 readOpcodecxx . . $ readOpcode(a95f3859aee87d23).(insn) ||
2339 getIDcxx . . $ getID(a95f3859aee87d23).(insn) ||
2340 insn->instructionIDcxx . . $ InternalInstruction#instructionID. == 0 ||
2341 checkPrefixcxx . . $ checkPrefix(1d2bb9784dc87cb7).(insn) ||
2342 readOperandscxx . . $ readOperands(a95f3859aee87d23).(insn))
2343 return -1;
2344
2345 insn->lengthcxx . . $ InternalInstruction#length. = (size_t)(insn->readerCursorcxx . . $ InternalInstruction#readerCursor. - insn->startLocationcxx . . $ InternalInstruction#startLocation.);
2346
2347 // instruction length must be <= 15 to be valid
2348 if (insn->lengthcxx . . $ InternalInstruction#length. > 15)
2349 return -1;
2350
2351 if (insn->operandSizecxx . . $ InternalInstruction#operandSize. == 0)
2352 insn->operandSizecxx . . $ InternalInstruction#operandSize. = insn->registerSizecxx . . $ InternalInstruction#registerSize.;
2353
2354 insn->operandscxx . . $ InternalInstruction#operands. = &x86OperandSetscxx . . $ x86OperandSets.[insn->speccxx . . $ InternalInstruction#spec.->operandscxx . . $ InstructionSpecifier#operands.][0];
2355
2356 return 0;
2357 }
2358
2359 #endif
2360