Lines Matching refs:instruction
247 ZydisDecodedInstruction* instruction, ZyanU8* value) in ZydisInputPeek() argument
250 ZYAN_ASSERT(instruction); in ZydisInputPeek()
253 if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) in ZydisInputPeek()
277 static void ZydisInputSkip(ZydisDecoderState* state, ZydisDecodedInstruction* instruction) in ZydisInputSkip() argument
280 ZYAN_ASSERT(instruction); in ZydisInputSkip()
281 ZYAN_ASSERT(instruction->length < ZYDIS_MAX_INSTRUCTION_LENGTH); in ZydisInputSkip()
283 ++instruction->length; in ZydisInputSkip()
301 ZydisDecodedInstruction* instruction, ZyanU8* value) in ZydisInputNext() argument
304 ZYAN_ASSERT(instruction); in ZydisInputNext()
307 if (instruction->length >= ZYDIS_MAX_INSTRUCTION_LENGTH) in ZydisInputNext()
315 ++instruction->length; in ZydisInputNext()
338 ZydisDecodedInstruction* instruction, ZyanU8* value, ZyanU8 number_of_bytes) in ZydisInputNextBytes() argument
341 ZYAN_ASSERT(instruction); in ZydisInputNextBytes()
344 if (instruction->length + number_of_bytes > ZYDIS_MAX_INSTRUCTION_LENGTH) in ZydisInputNextBytes()
351 instruction->length += number_of_bytes; in ZydisInputNextBytes()
374 static void ZydisDecodeREX(ZydisDecoderContext* context, ZydisDecodedInstruction* instruction, in ZydisDecodeREX() argument
377 ZYAN_ASSERT(instruction); in ZydisDecodeREX()
380 instruction->attributes |= ZYDIS_ATTRIB_HAS_REX; in ZydisDecodeREX()
381 instruction->raw.rex.W = (data >> 3) & 0x01; in ZydisDecodeREX()
382 instruction->raw.rex.R = (data >> 2) & 0x01; in ZydisDecodeREX()
383 instruction->raw.rex.X = (data >> 1) & 0x01; in ZydisDecodeREX()
384 instruction->raw.rex.B = (data >> 0) & 0x01; in ZydisDecodeREX()
387 context->vector_unified.W = instruction->raw.rex.W; in ZydisDecodeREX()
388 context->vector_unified.R = instruction->raw.rex.R; in ZydisDecodeREX()
389 context->vector_unified.X = instruction->raw.rex.X; in ZydisDecodeREX()
390 context->vector_unified.B = instruction->raw.rex.B; in ZydisDecodeREX()
403 ZydisDecodedInstruction* instruction, const ZyanU8 data[3]) in ZydisDecodeXOP() argument
405 ZYAN_ASSERT(instruction); in ZydisDecodeXOP()
408 ZYAN_ASSERT(instruction->raw.xop.offset == instruction->length - 3); in ZydisDecodeXOP()
410 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_REAL_16) in ZydisDecodeXOP()
416 instruction->attributes |= ZYDIS_ATTRIB_HAS_XOP; in ZydisDecodeXOP()
417 instruction->raw.xop.R = (data[1] >> 7) & 0x01; in ZydisDecodeXOP()
418 instruction->raw.xop.X = (data[1] >> 6) & 0x01; in ZydisDecodeXOP()
419 instruction->raw.xop.B = (data[1] >> 5) & 0x01; in ZydisDecodeXOP()
420 instruction->raw.xop.m_mmmm = (data[1] >> 0) & 0x1F; in ZydisDecodeXOP()
422 if ((instruction->raw.xop.m_mmmm < 0x08) || (instruction->raw.xop.m_mmmm > 0x0A)) in ZydisDecodeXOP()
428 instruction->raw.xop.W = (data[2] >> 7) & 0x01; in ZydisDecodeXOP()
429 instruction->raw.xop.vvvv = (data[2] >> 3) & 0x0F; in ZydisDecodeXOP()
430 instruction->raw.xop.L = (data[2] >> 2) & 0x01; in ZydisDecodeXOP()
431 instruction->raw.xop.pp = (data[2] >> 0) & 0x03; in ZydisDecodeXOP()
434 context->vector_unified.W = instruction->raw.xop.W; in ZydisDecodeXOP()
435 context->vector_unified.R = 0x01 & ~instruction->raw.xop.R; in ZydisDecodeXOP()
436 context->vector_unified.X = 0x01 & ~instruction->raw.xop.X; in ZydisDecodeXOP()
437 context->vector_unified.B = 0x01 & ~instruction->raw.xop.B; in ZydisDecodeXOP()
438 context->vector_unified.L = instruction->raw.xop.L; in ZydisDecodeXOP()
439 context->vector_unified.LL = instruction->raw.xop.L; in ZydisDecodeXOP()
440 context->vector_unified.vvvv = (0x0F & ~instruction->raw.xop.vvvv); in ZydisDecodeXOP()
455 ZydisDecodedInstruction* instruction, const ZyanU8 data[3]) in ZydisDecodeVEX() argument
457 ZYAN_ASSERT(instruction); in ZydisDecodeVEX()
460 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_REAL_16) in ZydisDecodeVEX()
466 instruction->attributes |= ZYDIS_ATTRIB_HAS_VEX; in ZydisDecodeVEX()
470 ZYAN_ASSERT(instruction->raw.vex.offset == instruction->length - 3); in ZydisDecodeVEX()
471 instruction->raw.vex.size = 3; in ZydisDecodeVEX()
472 instruction->raw.vex.R = (data[1] >> 7) & 0x01; in ZydisDecodeVEX()
473 instruction->raw.vex.X = (data[1] >> 6) & 0x01; in ZydisDecodeVEX()
474 instruction->raw.vex.B = (data[1] >> 5) & 0x01; in ZydisDecodeVEX()
475 instruction->raw.vex.m_mmmm = (data[1] >> 0) & 0x1F; in ZydisDecodeVEX()
476 instruction->raw.vex.W = (data[2] >> 7) & 0x01; in ZydisDecodeVEX()
477 instruction->raw.vex.vvvv = (data[2] >> 3) & 0x0F; in ZydisDecodeVEX()
478 instruction->raw.vex.L = (data[2] >> 2) & 0x01; in ZydisDecodeVEX()
479 instruction->raw.vex.pp = (data[2] >> 0) & 0x03; in ZydisDecodeVEX()
482 ZYAN_ASSERT(instruction->raw.vex.offset == instruction->length - 2); in ZydisDecodeVEX()
483 instruction->raw.vex.size = 2; in ZydisDecodeVEX()
484 instruction->raw.vex.R = (data[1] >> 7) & 0x01; in ZydisDecodeVEX()
485 instruction->raw.vex.X = 1; in ZydisDecodeVEX()
486 instruction->raw.vex.B = 1; in ZydisDecodeVEX()
487 instruction->raw.vex.m_mmmm = 1; in ZydisDecodeVEX()
488 instruction->raw.vex.W = 0; in ZydisDecodeVEX()
489 instruction->raw.vex.vvvv = (data[1] >> 3) & 0x0F; in ZydisDecodeVEX()
490 instruction->raw.vex.L = (data[1] >> 2) & 0x01; in ZydisDecodeVEX()
491 instruction->raw.vex.pp = (data[1] >> 0) & 0x03; in ZydisDecodeVEX()
499 if ((instruction->raw.vex.m_mmmm == 0) || (instruction->raw.vex.m_mmmm > 0x03)) in ZydisDecodeVEX()
501 if (instruction->raw.vex.m_mmmm > 0x03) in ZydisDecodeVEX()
509 context->vector_unified.W = instruction->raw.vex.W; in ZydisDecodeVEX()
510 context->vector_unified.R = 0x01 & ~instruction->raw.vex.R; in ZydisDecodeVEX()
511 context->vector_unified.X = 0x01 & ~instruction->raw.vex.X; in ZydisDecodeVEX()
512 context->vector_unified.B = 0x01 & ~instruction->raw.vex.B; in ZydisDecodeVEX()
513 context->vector_unified.L = instruction->raw.vex.L; in ZydisDecodeVEX()
514 context->vector_unified.LL = instruction->raw.vex.L; in ZydisDecodeVEX()
515 context->vector_unified.vvvv = (0x0F & ~instruction->raw.vex.vvvv); in ZydisDecodeVEX()
531 ZydisDecodedInstruction* instruction, const ZyanU8 data[4]) in ZydisDecodeEVEX() argument
533 ZYAN_ASSERT(instruction); in ZydisDecodeEVEX()
535 ZYAN_ASSERT(instruction->raw.evex.offset == instruction->length - 4); in ZydisDecodeEVEX()
537 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_REAL_16) in ZydisDecodeEVEX()
543 instruction->attributes |= ZYDIS_ATTRIB_HAS_EVEX; in ZydisDecodeEVEX()
544 instruction->raw.evex.R = (data[1] >> 7) & 0x01; in ZydisDecodeEVEX()
545 instruction->raw.evex.X = (data[1] >> 6) & 0x01; in ZydisDecodeEVEX()
546 instruction->raw.evex.B = (data[1] >> 5) & 0x01; in ZydisDecodeEVEX()
547 instruction->raw.evex.R2 = (data[1] >> 4) & 0x01; in ZydisDecodeEVEX()
555 instruction->raw.evex.mmm = (data[1] >> 0) & 0x07; in ZydisDecodeEVEX()
557 if ((instruction->raw.evex.mmm == 0x00) || in ZydisDecodeEVEX()
558 (instruction->raw.evex.mmm == 0x04) || in ZydisDecodeEVEX()
559 (instruction->raw.evex.mmm == 0x07)) in ZydisDecodeEVEX()
565 instruction->raw.evex.W = (data[2] >> 7) & 0x01; in ZydisDecodeEVEX()
566 instruction->raw.evex.vvvv = (data[2] >> 3) & 0x0F; in ZydisDecodeEVEX()
570 instruction->raw.evex.pp = (data[2] >> 0) & 0x03; in ZydisDecodeEVEX()
571 instruction->raw.evex.z = (data[3] >> 7) & 0x01; in ZydisDecodeEVEX()
572 instruction->raw.evex.L2 = (data[3] >> 6) & 0x01; in ZydisDecodeEVEX()
573 instruction->raw.evex.L = (data[3] >> 5) & 0x01; in ZydisDecodeEVEX()
574 instruction->raw.evex.b = (data[3] >> 4) & 0x01; in ZydisDecodeEVEX()
575 instruction->raw.evex.V2 = (data[3] >> 3) & 0x01; in ZydisDecodeEVEX()
577 if (!instruction->raw.evex.V2 && in ZydisDecodeEVEX()
578 (instruction->machine_mode != ZYDIS_MACHINE_MODE_LONG_64)) in ZydisDecodeEVEX()
583 instruction->raw.evex.aaa = (data[3] >> 0) & 0x07; in ZydisDecodeEVEX()
585 if (instruction->raw.evex.z && !instruction->raw.evex.aaa) in ZydisDecodeEVEX()
591 context->vector_unified.W = instruction->raw.evex.W; in ZydisDecodeEVEX()
592 context->vector_unified.R = 0x01 & ~instruction->raw.evex.R; in ZydisDecodeEVEX()
593 context->vector_unified.X = 0x01 & ~instruction->raw.evex.X; in ZydisDecodeEVEX()
594 context->vector_unified.B = 0x01 & ~instruction->raw.evex.B; in ZydisDecodeEVEX()
596 context->vector_unified.R2 = 0x01 & ~instruction->raw.evex.R2; in ZydisDecodeEVEX()
597 context->vector_unified.V2 = 0x01 & ~instruction->raw.evex.V2; in ZydisDecodeEVEX()
598 context->vector_unified.vvvv = 0x0F & ~instruction->raw.evex.vvvv; in ZydisDecodeEVEX()
599 context->vector_unified.mask = instruction->raw.evex.aaa; in ZydisDecodeEVEX()
601 if (!instruction->raw.evex.V2 && (instruction->machine_mode != ZYDIS_MACHINE_MODE_LONG_64)) in ZydisDecodeEVEX()
605 if (!instruction->raw.evex.b && (context->vector_unified.LL == 3)) in ZydisDecodeEVEX()
626 ZydisDecodedInstruction* instruction, const ZyanU8 data[4]) in ZydisDecodeMVEX() argument
628 ZYAN_ASSERT(instruction); in ZydisDecodeMVEX()
630 ZYAN_ASSERT(instruction->raw.mvex.offset == instruction->length - 4); in ZydisDecodeMVEX()
632 if (instruction->machine_mode != ZYDIS_MACHINE_MODE_LONG_64) in ZydisDecodeMVEX()
638 instruction->attributes |= ZYDIS_ATTRIB_HAS_MVEX; in ZydisDecodeMVEX()
639 instruction->raw.mvex.R = (data[1] >> 7) & 0x01; in ZydisDecodeMVEX()
640 instruction->raw.mvex.X = (data[1] >> 6) & 0x01; in ZydisDecodeMVEX()
641 instruction->raw.mvex.B = (data[1] >> 5) & 0x01; in ZydisDecodeMVEX()
642 instruction->raw.mvex.R2 = (data[1] >> 4) & 0x01; in ZydisDecodeMVEX()
643 instruction->raw.mvex.mmmm = (data[1] >> 0) & 0x0F; in ZydisDecodeMVEX()
645 if (instruction->raw.mvex.mmmm > 0x03) in ZydisDecodeMVEX()
651 instruction->raw.mvex.W = (data[2] >> 7) & 0x01; in ZydisDecodeMVEX()
652 instruction->raw.mvex.vvvv = (data[2] >> 3) & 0x0F; in ZydisDecodeMVEX()
656 instruction->raw.mvex.pp = (data[2] >> 0) & 0x03; in ZydisDecodeMVEX()
657 instruction->raw.mvex.E = (data[3] >> 7) & 0x01; in ZydisDecodeMVEX()
658 instruction->raw.mvex.SSS = (data[3] >> 4) & 0x07; in ZydisDecodeMVEX()
659 instruction->raw.mvex.V2 = (data[3] >> 3) & 0x01; in ZydisDecodeMVEX()
660 instruction->raw.mvex.kkk = (data[3] >> 0) & 0x07; in ZydisDecodeMVEX()
663 context->vector_unified.W = instruction->raw.mvex.W; in ZydisDecodeMVEX()
664 context->vector_unified.R = 0x01 & ~instruction->raw.mvex.R; in ZydisDecodeMVEX()
665 context->vector_unified.X = 0x01 & ~instruction->raw.mvex.X; in ZydisDecodeMVEX()
666 context->vector_unified.B = 0x01 & ~instruction->raw.mvex.B; in ZydisDecodeMVEX()
667 context->vector_unified.R2 = 0x01 & ~instruction->raw.mvex.R2; in ZydisDecodeMVEX()
668 context->vector_unified.V2 = 0x01 & ~instruction->raw.mvex.V2; in ZydisDecodeMVEX()
670 context->vector_unified.vvvv = 0x0F & ~instruction->raw.mvex.vvvv; in ZydisDecodeMVEX()
671 context->vector_unified.mask = instruction->raw.mvex.kkk; in ZydisDecodeMVEX()
683 static void ZydisDecodeModRM(ZydisDecodedInstruction* instruction, ZyanU8 data) in ZydisDecodeModRM() argument
685 ZYAN_ASSERT(instruction); in ZydisDecodeModRM()
686 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_MODRM)); in ZydisDecodeModRM()
687 ZYAN_ASSERT(instruction->raw.modrm.offset == instruction->length - 1); in ZydisDecodeModRM()
689 instruction->attributes |= ZYDIS_ATTRIB_HAS_MODRM; in ZydisDecodeModRM()
690 instruction->raw.modrm.mod = (data >> 6) & 0x03; in ZydisDecodeModRM()
691 instruction->raw.modrm.reg = (data >> 3) & 0x07; in ZydisDecodeModRM()
692 instruction->raw.modrm.rm = (data >> 0) & 0x07; in ZydisDecodeModRM()
701 static void ZydisDecodeSIB(ZydisDecodedInstruction* instruction, ZyanU8 data) in ZydisDecodeSIB() argument
703 ZYAN_ASSERT(instruction); in ZydisDecodeSIB()
704 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MODRM); in ZydisDecodeSIB()
705 ZYAN_ASSERT(instruction->raw.modrm.rm == 4); in ZydisDecodeSIB()
706 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_SIB)); in ZydisDecodeSIB()
707 ZYAN_ASSERT(instruction->raw.sib.offset == instruction->length - 1); in ZydisDecodeSIB()
709 instruction->attributes |= ZYDIS_ATTRIB_HAS_SIB; in ZydisDecodeSIB()
710 instruction->raw.sib.scale = (data >> 6) & 0x03; in ZydisDecodeSIB()
711 instruction->raw.sib.index = (data >> 3) & 0x07; in ZydisDecodeSIB()
712 instruction->raw.sib.base = (data >> 0) & 0x07; in ZydisDecodeSIB()
727 ZydisDecodedInstruction* instruction, ZyanU8 size) in ZydisReadDisplacement() argument
730 ZYAN_ASSERT(instruction); in ZydisReadDisplacement()
731 ZYAN_ASSERT(instruction->raw.disp.size == 0); in ZydisReadDisplacement()
733 instruction->raw.disp.size = size; in ZydisReadDisplacement()
734 instruction->raw.disp.offset = instruction->length; in ZydisReadDisplacement()
741 ZYAN_CHECK(ZydisInputNext(state, instruction, &value)); in ZydisReadDisplacement()
742 instruction->raw.disp.value = *(ZyanI8*)&value; in ZydisReadDisplacement()
748 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 2)); in ZydisReadDisplacement()
749 instruction->raw.disp.value = *(ZyanI16*)&value; in ZydisReadDisplacement()
755 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 4)); in ZydisReadDisplacement()
756 instruction->raw.disp.value = *(ZyanI32*)&value; in ZydisReadDisplacement()
762 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 8)); in ZydisReadDisplacement()
763 instruction->raw.disp.value = *(ZyanI64*)&value; in ZydisReadDisplacement()
788 ZydisDecodedInstruction* instruction, ZyanU8 id, ZyanU8 size, ZyanBool is_signed, in ZydisReadImmediate() argument
792 ZYAN_ASSERT(instruction); in ZydisReadImmediate()
795 ZYAN_ASSERT(instruction->raw.imm[id].size == 0); in ZydisReadImmediate()
797 instruction->raw.imm[id].size = size; in ZydisReadImmediate()
798 instruction->raw.imm[id].offset = instruction->length; in ZydisReadImmediate()
799 instruction->raw.imm[id].is_signed = is_signed; in ZydisReadImmediate()
800 instruction->raw.imm[id].is_relative = is_relative; in ZydisReadImmediate()
806 ZYAN_CHECK(ZydisInputNext(state, instruction, &value)); in ZydisReadImmediate()
809 instruction->raw.imm[id].value.s = (ZyanI8)value; in ZydisReadImmediate()
812 instruction->raw.imm[id].value.u = value; in ZydisReadImmediate()
819 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 2)); in ZydisReadImmediate()
822 instruction->raw.imm[id].value.s = (ZyanI16)value; in ZydisReadImmediate()
825 instruction->raw.imm[id].value.u = value; in ZydisReadImmediate()
832 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 4)); in ZydisReadImmediate()
835 instruction->raw.imm[id].value.s = (ZyanI32)value; in ZydisReadImmediate()
838 instruction->raw.imm[id].value.u = value; in ZydisReadImmediate()
845 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, (ZyanU8*)&value, 8)); in ZydisReadImmediate()
848 instruction->raw.imm[id].value.s = (ZyanI64)value; in ZydisReadImmediate()
851 instruction->raw.imm[id].value.u = value; in ZydisReadImmediate()
883 const ZydisDecodedInstruction* instruction, ZydisRegisterEncoding encoding, in ZydisCalcRegisterId() argument
887 ZYAN_ASSERT(instruction); in ZydisCalcRegisterId()
911 ZyanU8 value = (instruction->opcode & 0x0F); in ZydisCalcRegisterId()
916 if (instruction->machine_mode != ZYDIS_MACHINE_MODE_LONG_64) in ZydisCalcRegisterId()
924 if (instruction->machine_mode != ZYDIS_MACHINE_MODE_LONG_64) in ZydisCalcRegisterId()
926 return (instruction->raw.imm[0].value.u >> 4) & 0x07; in ZydisCalcRegisterId()
928 ZyanU8 value = (instruction->raw.imm[0].value.u >> 4) & 0x0F; in ZydisCalcRegisterId()
931 if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || in ZydisCalcRegisterId()
932 (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) in ZydisCalcRegisterId()
939 value |= ((instruction->raw.imm[0].value.u & 0x08) << 1); in ZydisCalcRegisterId()
964 const ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, in ZydisSetOperandSizeAndElementInfo() argument
968 ZYAN_ASSERT(instruction); in ZydisSetOperandSizeAndElementInfo()
982 operand->size = ZydisRegisterGetWidth(instruction->machine_mode, in ZydisSetOperandSizeAndElementInfo()
990 switch (instruction->encoding) in ZydisSetOperandSizeAndElementInfo()
999 operand->size = instruction->address_width; in ZydisSetOperandSizeAndElementInfo()
1004 (instruction->meta.category == ZYDIS_CATEGORY_AMX_TILE)); in ZydisSetOperandSizeAndElementInfo()
1018 ZYAN_ASSERT(instruction->avx.vector_length); in ZydisSetOperandSizeAndElementInfo()
1023 if (instruction->avx.broadcast.mode) in ZydisSetOperandSizeAndElementInfo()
1028 operand->size = instruction->avx.vector_length; in ZydisSetOperandSizeAndElementInfo()
1032 if (instruction->avx.broadcast.mode) in ZydisSetOperandSizeAndElementInfo()
1037 operand->size = (ZyanU16)instruction->avx.vector_length / 2; in ZydisSetOperandSizeAndElementInfo()
1041 if (instruction->avx.broadcast.mode) in ZydisSetOperandSizeAndElementInfo()
1047 operand->size = (ZyanU16)instruction->avx.vector_length / 4; in ZydisSetOperandSizeAndElementInfo()
1068 ZYAN_ASSERT(instruction->avx.vector_length == 512); in ZydisSetOperandSizeAndElementInfo()
1070 switch (instruction->avx.conversion.mode) in ZydisSetOperandSizeAndElementInfo()
1145 switch (instruction->avx.broadcast.mode) in ZydisSetOperandSizeAndElementInfo()
1171 ZYAN_ASSERT((instruction->raw.imm[0].size == 16) || in ZydisSetOperandSizeAndElementInfo()
1172 (instruction->raw.imm[0].size == 32)); in ZydisSetOperandSizeAndElementInfo()
1173 ZYAN_ASSERT( instruction->raw.imm[1].size == 16); in ZydisSetOperandSizeAndElementInfo()
1174 operand->size = instruction->raw.imm[0].size + instruction->raw.imm[1].size; in ZydisSetOperandSizeAndElementInfo()
1218 static ZyanStatus ZydisDecodeOperandRegister(const ZydisDecodedInstruction* instruction, in ZydisDecodeOperandRegister() argument
1221 ZYAN_ASSERT(instruction); in ZydisDecodeOperandRegister()
1228 if ((instruction->attributes & ZYDIS_ATTRIB_HAS_REX) && (register_id >= 4)) in ZydisDecodeOperandRegister()
1262 const ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operand, in ZydisDecodeOperandMemory() argument
1266 ZYAN_ASSERT(instruction); in ZydisDecodeOperandMemory()
1268 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MODRM); in ZydisDecodeOperandMemory()
1269 ZYAN_ASSERT(instruction->raw.modrm.mod != 3); in ZydisDecodeOperandMemory()
1270 ZYAN_ASSERT(!vidx_register_class || ((instruction->raw.modrm.rm == 4) && in ZydisDecodeOperandMemory()
1271 ((instruction->address_width == 32) || (instruction->address_width == 64)))); in ZydisDecodeOperandMemory()
1276 const ZyanU8 modrm_rm = instruction->raw.modrm.rm; in ZydisDecodeOperandMemory()
1278 switch (instruction->address_width) in ZydisDecodeOperandMemory()
1295 switch (instruction->raw.modrm.mod) in ZydisDecodeOperandMemory()
1317 operand->mem.base = ZYDIS_REGISTER_EAX + ZydisCalcRegisterId(context, instruction, in ZydisDecodeOperandMemory()
1319 switch (instruction->raw.modrm.mod) in ZydisDecodeOperandMemory()
1324 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisDecodeOperandMemory()
1345 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_SIB); in ZydisDecodeOperandMemory()
1348 ZydisCalcRegisterId(context, instruction, in ZydisDecodeOperandMemory()
1351 operand->mem.scale = (1 << instruction->raw.sib.scale); in ZydisDecodeOperandMemory()
1359 if (instruction->raw.modrm.mod == 0) in ZydisDecodeOperandMemory()
1363 displacement_size = (instruction->raw.modrm.mod == 1) ? 8 : 32; in ZydisDecodeOperandMemory()
1374 operand->mem.base = ZYDIS_REGISTER_RAX + ZydisCalcRegisterId(context, instruction, in ZydisDecodeOperandMemory()
1376 switch (instruction->raw.modrm.mod) in ZydisDecodeOperandMemory()
1381 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisDecodeOperandMemory()
1402 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_SIB); in ZydisDecodeOperandMemory()
1405 ZydisCalcRegisterId(context, instruction, in ZydisDecodeOperandMemory()
1408 operand->mem.scale = (1 << instruction->raw.sib.scale); in ZydisDecodeOperandMemory()
1417 if (instruction->raw.modrm.mod == 0) in ZydisDecodeOperandMemory()
1421 displacement_size = (instruction->raw.modrm.mod == 1) ? 8 : 32; in ZydisDecodeOperandMemory()
1435 ZYAN_ASSERT(instruction->raw.disp.size == displacement_size); in ZydisDecodeOperandMemory()
1437 operand->mem.disp.value = instruction->raw.disp.value; in ZydisDecodeOperandMemory()
1454 const ZydisDecoderContext* context, const ZydisDecodedInstruction* instruction, in ZydisDecodeOperandImplicitRegister() argument
1458 ZYAN_ASSERT(instruction); in ZydisDecodeOperandImplicitRegister()
1483 (instruction->address_width == 16) ? ZYDIS_REGCLASS_GPR16 : in ZydisDecodeOperandImplicitRegister()
1484 (instruction->address_width == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64, in ZydisDecodeOperandImplicitRegister()
1489 (instruction->address_width == 16) ? ZYDIS_REGISTER_IP : in ZydisDecodeOperandImplicitRegister()
1490 (instruction->address_width == 32) ? ZYDIS_REGISTER_EIP : ZYDIS_REGISTER_RIP; in ZydisDecodeOperandImplicitRegister()
1528 const ZydisDecoderContext* context, const ZydisDecodedInstruction* instruction, in ZydisDecodeOperandImplicitMemory() argument
1549 ZydisCalcRegisterId(context, instruction, ZYDIS_REG_ENCODING_REG, in ZydisDecodeOperandImplicitMemory()
1554 ZydisCalcRegisterId(context, instruction, ZYDIS_REG_ENCODING_RM, in ZydisDecodeOperandImplicitMemory()
1593 const ZydisDecodedInstruction* instruction, ZydisDecodedOperand* operands, ZyanU8 operand_count) in ZydisDecodeOperands() argument
1598 ZYAN_ASSERT(instruction); in ZydisDecodeOperands()
1601 ZYAN_ASSERT(operand_count <= instruction->operand_count); in ZydisDecodeOperands()
1629 … ZydisDecodeOperandImplicitRegister(decoder, context, instruction, &operands[i], operand); in ZydisDecodeOperands()
1632 ZydisDecodeOperandImplicitMemory(decoder, context, instruction, &operands[i], operand); in ZydisDecodeOperands()
1667 ZYAN_ASSERT((instruction->operand_width == 16) || (instruction->operand_width == 32) || in ZydisDecodeOperands()
1668 (instruction->operand_width == 64)); in ZydisDecodeOperands()
1670 (instruction->operand_width == 16) ? ZYDIS_REGCLASS_GPR16 : ( in ZydisDecodeOperands()
1671 … (instruction->operand_width == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64); in ZydisDecodeOperands()
1674 ZYAN_ASSERT((instruction->operand_width == 16) || (instruction->operand_width == 32) || in ZydisDecodeOperands()
1675 (instruction->operand_width == 64)); in ZydisDecodeOperands()
1677 (instruction->operand_width == 16) ? ZYDIS_REGCLASS_GPR32 : ( in ZydisDecodeOperands()
1678 … (instruction->operand_width == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64); in ZydisDecodeOperands()
1681 ZYAN_ASSERT((instruction->operand_width == 16) || (instruction->operand_width == 32) || in ZydisDecodeOperands()
1682 (instruction->operand_width == 64)); in ZydisDecodeOperands()
1684 (instruction->operand_width == 16) ? ZYDIS_REGCLASS_GPR16 : ZYDIS_REGCLASS_GPR32; in ZydisDecodeOperands()
1687 ZYAN_ASSERT((instruction->address_width == 16) || (instruction->address_width == 32) || in ZydisDecodeOperands()
1688 (instruction->address_width == 64)); in ZydisDecodeOperands()
1690 (instruction->address_width == 16) ? ZYDIS_REGCLASS_GPR16 : ( in ZydisDecodeOperands()
1691 … (instruction->address_width == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64); in ZydisDecodeOperands()
1736 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1738 context, instruction, ZYDIS_REG_ENCODING_REG, register_class))); in ZydisDecodeOperands()
1743 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1745 context, instruction, ZYDIS_REG_ENCODING_RM, register_class))); in ZydisDecodeOperands()
1750 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1752 context, instruction, ZYDIS_REG_ENCODING_OPCODE, register_class))); in ZydisDecodeOperands()
1757 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1759 context, instruction, ZYDIS_REG_ENCODING_NDSNDD, register_class))); in ZydisDecodeOperands()
1764 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1766 context, instruction, ZYDIS_REG_ENCODING_MASK, register_class))); in ZydisDecodeOperands()
1771 instruction, &operands[i], register_class, in ZydisDecodeOperands()
1773 context, instruction, ZYDIS_REG_ENCODING_IS4, register_class))); in ZydisDecodeOperands()
1793 context, instruction, &operands[i], ZYDIS_REGCLASS_INVALID)); in ZydisDecodeOperands()
1798 context, instruction, &operands[i], ZYDIS_REGCLASS_XMM)); in ZydisDecodeOperands()
1804 context, instruction, &operands[i], ZYDIS_REGCLASS_YMM)); in ZydisDecodeOperands()
1810 context, instruction, &operands[i], ZYDIS_REGCLASS_ZMM)); in ZydisDecodeOperands()
1814 ZYAN_ASSERT((instruction->raw.imm[0].size == 16) || in ZydisDecodeOperands()
1815 (instruction->raw.imm[0].size == 32)); in ZydisDecodeOperands()
1816 ZYAN_ASSERT(instruction->raw.imm[1].size == 16); in ZydisDecodeOperands()
1818 operands[i].ptr.offset = (ZyanU32)instruction->raw.imm[0].value.u; in ZydisDecodeOperands()
1819 operands[i].ptr.segment = (ZyanU16)instruction->raw.imm[1].value.u; in ZydisDecodeOperands()
1825 context, instruction, &operands[i], ZYDIS_REGCLASS_INVALID)); in ZydisDecodeOperands()
1829 ZYAN_ASSERT(instruction->raw.disp.size); in ZydisDecodeOperands()
1833 operands[i].mem.disp.value = instruction->raw.disp.value; in ZydisDecodeOperands()
1839 context, instruction, &operands[i], ZYDIS_REGCLASS_INVALID)); in ZydisDecodeOperands()
1849 if (((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || in ZydisDecodeOperands()
1850 (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) && in ZydisDecodeOperands()
1851 (instruction->raw.disp.size == 8)) in ZydisDecodeOperands()
1864 ZYAN_ASSERT(instruction->raw.imm[imm_id].is_relative); in ZydisDecodeOperands()
1873 ZYAN_ASSERT(instruction->raw.imm[imm_id].size == 8); in ZydisDecodeOperands()
1874 operands[i].imm.value.u = (ZyanU8)instruction->raw.imm[imm_id].value.u & 0x0F; in ZydisDecodeOperands()
1878 operands[i].imm.value.u = instruction->raw.imm[imm_id].value.u; in ZydisDecodeOperands()
1880 operands[i].imm.is_signed = instruction->raw.imm[imm_id].is_signed; in ZydisDecodeOperands()
1881 operands[i].imm.is_relative = instruction->raw.imm[imm_id].is_relative; in ZydisDecodeOperands()
1894 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_CS) in ZydisDecodeOperands()
1900 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_SS) in ZydisDecodeOperands()
1906 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_DS) in ZydisDecodeOperands()
1912 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_ES) in ZydisDecodeOperands()
1918 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_FS) in ZydisDecodeOperands()
1924 instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT_GS) in ZydisDecodeOperands()
1949 ZydisSetOperandSizeAndElementInfo(context, instruction, &operands[i], operand); in ZydisDecodeOperands()
1955 if (instruction->avx.mask.mode == ZYDIS_MASK_MODE_MERGING) in ZydisDecodeOperands()
1993 static void ZydisSetAttributes(ZydisDecoderState* state, ZydisDecodedInstruction* instruction, in ZydisSetAttributes() argument
1997 ZYAN_ASSERT(instruction); in ZydisSetAttributes()
2010 instruction->attributes |= mapping[definition->cpu_state]; in ZydisSetAttributes()
2023 instruction->attributes |= mapping[definition->fpu_state]; in ZydisSetAttributes()
2036 instruction->attributes |= mapping[definition->xmm_state]; in ZydisSetAttributes()
2039 switch (instruction->encoding) in ZydisSetAttributes()
2048 instruction->attributes |= ZYDIS_ATTRIB_IS_PRIVILEGED; in ZydisSetAttributes()
2052 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_LOCK; in ZydisSetAttributes()
2055 instruction->attributes |= ZYDIS_ATTRIB_HAS_LOCK; in ZydisSetAttributes()
2056 instruction->raw.prefixes[state->prefixes.offset_lock].type = in ZydisSetAttributes()
2062 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_REP; in ZydisSetAttributes()
2066 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_REPE; in ZydisSetAttributes()
2070 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_REPNE; in ZydisSetAttributes()
2074 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_BND; in ZydisSetAttributes()
2078 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XACQUIRE; in ZydisSetAttributes()
2082 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_XRELEASE; in ZydisSetAttributes()
2086 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_HLE_WITHOUT_LOCK; in ZydisSetAttributes()
2092 if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_REPNE) in ZydisSetAttributes()
2094 instruction->attributes |= ZYDIS_ATTRIB_HAS_REPNE; in ZydisSetAttributes()
2097 if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_XACQUIRE) in ZydisSetAttributes()
2099 if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || in ZydisSetAttributes()
2102 instruction->attributes |= ZYDIS_ATTRIB_HAS_XACQUIRE; in ZydisSetAttributes()
2107 instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_BND) in ZydisSetAttributes()
2109 instruction->attributes |= ZYDIS_ATTRIB_HAS_BND; in ZydisSetAttributes()
2114 if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_REP) in ZydisSetAttributes()
2116 instruction->attributes |= ZYDIS_ATTRIB_HAS_REP; in ZydisSetAttributes()
2119 if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_REPE) in ZydisSetAttributes()
2121 instruction->attributes |= ZYDIS_ATTRIB_HAS_REPE; in ZydisSetAttributes()
2124 if (instruction->attributes & ZYDIS_ATTRIB_ACCEPTS_XRELEASE) in ZydisSetAttributes()
2126 if ((instruction->attributes & ZYDIS_ATTRIB_HAS_LOCK) || in ZydisSetAttributes()
2129 instruction->attributes |= ZYDIS_ATTRIB_HAS_XRELEASE; in ZydisSetAttributes()
2137 if ((instruction->raw.prefixes[state->prefixes.offset_group1].type == in ZydisSetAttributes()
2139 (instruction->attributes & ( in ZydisSetAttributes()
2143 instruction->raw.prefixes[state->prefixes.offset_group1].type = in ZydisSetAttributes()
2149 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_BRANCH_HINTS; in ZydisSetAttributes()
2153 instruction->attributes |= ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN; in ZydisSetAttributes()
2154 instruction->raw.prefixes[state->prefixes.offset_group2].type = in ZydisSetAttributes()
2158 instruction->attributes |= ZYDIS_ATTRIB_HAS_BRANCH_TAKEN; in ZydisSetAttributes()
2159 instruction->raw.prefixes[state->prefixes.offset_group2].type = in ZydisSetAttributes()
2169 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_NOTRACK; in ZydisSetAttributes()
2173 instruction->attributes |= ZYDIS_ATTRIB_HAS_NOTRACK; in ZydisSetAttributes()
2174 instruction->raw.prefixes[state->prefixes.offset_notrack].type = in ZydisSetAttributes()
2181 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_SEGMENT; in ZydisSetAttributes()
2183 !(instruction->attributes & ZYDIS_ATTRIB_HAS_NOTRACK)) in ZydisSetAttributes()
2188 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_CS; in ZydisSetAttributes()
2191 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_SS; in ZydisSetAttributes()
2194 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_DS; in ZydisSetAttributes()
2197 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_ES; in ZydisSetAttributes()
2200 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_FS; in ZydisSetAttributes()
2203 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_GS; in ZydisSetAttributes()
2209 if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT) in ZydisSetAttributes()
2211 instruction->raw.prefixes[state->prefixes.offset_segment].type = in ZydisSetAttributes()
2225 instruction->attributes |= ZYDIS_ATTRIB_ACCEPTS_SEGMENT; in ZydisSetAttributes()
2231 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_CS; in ZydisSetAttributes()
2234 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_SS; in ZydisSetAttributes()
2237 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_DS; in ZydisSetAttributes()
2240 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_ES; in ZydisSetAttributes()
2243 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_FS; in ZydisSetAttributes()
2246 instruction->attributes |= ZYDIS_ATTRIB_HAS_SEGMENT_GS; in ZydisSetAttributes()
2252 if (instruction->attributes & ZYDIS_ATTRIB_HAS_SEGMENT) in ZydisSetAttributes()
2254 instruction->raw.prefixes[state->prefixes.offset_segment].type = in ZydisSetAttributes()
2297 ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) in ZydisSetAVXInformation() argument
2300 ZYAN_ASSERT(instruction); in ZydisSetAVXInformation()
2303 switch (instruction->encoding) in ZydisSetAVXInformation()
2314 instruction->avx.vector_length = lookup[context->vector_unified.LL]; in ZydisSetAVXInformation()
2326 instruction->avx.vector_length = lookup[context->vector_unified.LL]; in ZydisSetAVXInformation()
2333 instruction->avx.broadcast.is_static = ZYAN_TRUE; in ZydisSetAVXInformation()
2344 instruction->avx.broadcast.mode = broadcasts[def->broadcast]; in ZydisSetAVXInformation()
2367 instruction->avx.vector_length = lookup[vector_length]; in ZydisSetAVXInformation()
2372 ZYAN_ASSERT(instruction->raw.modrm.mod != 3); in ZydisSetAVXInformation()
2388 const ZyanU8 evex_b = instruction->raw.evex.b; in ZydisSetAVXInformation()
2450 instruction->avx.broadcast.mode = broadcasts[evex_b][size_index][vector_length]; in ZydisSetAVXInformation()
2455 const ZyanU8 evex_b = instruction->raw.evex.b; in ZydisSetAVXInformation()
2505 instruction->avx.broadcast.mode = broadcasts[evex_b][size_index][vector_length]; in ZydisSetAVXInformation()
2574 ZYAN_ASSERT((instruction->avx.vector_length == 256) || in ZydisSetAVXInformation()
2575 (instruction->avx.vector_length == 512)); in ZydisSetAVXInformation()
2587 ZYAN_ASSERT((instruction->avx.vector_length == 256) || in ZydisSetAVXInformation()
2588 (instruction->avx.vector_length == 512)); in ZydisSetAVXInformation()
2593 ZYAN_ASSERT(instruction->avx.vector_length == 512); in ZydisSetAVXInformation()
2602 ZYAN_ASSERT(instruction->avx.vector_length == 512); in ZydisSetAVXInformation()
2647 const ZyanU8 evex_b = instruction->raw.evex.b; in ZydisSetAVXInformation()
2674 instruction->avx.broadcast.mode = broadcasts[evex_b][vector_length]; in ZydisSetAVXInformation()
2682 ZYAN_ASSERT(instruction->raw.modrm.mod == 3); in ZydisSetAVXInformation()
2688 ZYAN_ASSERT(!instruction->avx.broadcast.mode); in ZydisSetAVXInformation()
2689 instruction->avx.broadcast.is_static = ZYAN_TRUE; in ZydisSetAVXInformation()
2707 instruction->avx.broadcast.mode = broadcasts[def->broadcast]; in ZydisSetAVXInformation()
2711 if (instruction->raw.evex.b) in ZydisSetAVXInformation()
2720 … instruction->avx.rounding.mode = ZYDIS_ROUNDING_MODE_RN + context->vector_unified.LL; in ZydisSetAVXInformation()
2723 instruction->avx.has_sae = ZYAN_TRUE; in ZydisSetAVXInformation()
2731 instruction->avx.mask.reg = ZYDIS_REGISTER_K0 + instruction->raw.evex.aaa; in ZydisSetAVXInformation()
2735 instruction->avx.mask.mode = ZYDIS_MASK_MODE_MERGING + instruction->raw.evex.z; in ZydisSetAVXInformation()
2738 instruction->avx.mask.mode = ZYDIS_MASK_MODE_ZEROING; in ZydisSetAVXInformation()
2741 instruction->avx.mask.mode = ZYDIS_MASK_MODE_CONTROL + instruction->raw.evex.z; in ZydisSetAVXInformation()
2746 if (!instruction->raw.evex.aaa) in ZydisSetAVXInformation()
2748 instruction->avx.mask.mode = ZYDIS_MASK_MODE_DISABLED; in ZydisSetAVXInformation()
2759 instruction->avx.vector_length = 512; in ZydisSetAVXInformation()
2769 instruction->avx.broadcast.is_static = ZYAN_TRUE; in ZydisSetAVXInformation()
2773 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_1_TO_8; in ZydisSetAVXInformation()
2777 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_1_TO_16; in ZydisSetAVXInformation()
2781 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_8; in ZydisSetAVXInformation()
2785 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16; in ZydisSetAVXInformation()
2821 ZYAN_ASSERT(instruction->raw.mvex.SSS < ZYAN_ARRAY_LENGTH(lookup[index])); in ZydisSetAVXInformation()
2822 context->cd8_scale = lookup[index][instruction->raw.mvex.SSS]; in ZydisSetAVXInformation()
2836 ZYAN_ASSERT(instruction->raw.mvex.SSS < ZYAN_ARRAY_LENGTH(lookup[index])); in ZydisSetAVXInformation()
2837 context->cd8_scale = lookup[index][instruction->raw.mvex.SSS]; in ZydisSetAVXInformation()
2851 ZYAN_ASSERT(instruction->raw.mvex.SSS < ZYAN_ARRAY_LENGTH(lookup[index])); in ZydisSetAVXInformation()
2852 context->cd8_scale = lookup[index][instruction->raw.mvex.SSS]; in ZydisSetAVXInformation()
2864 ZYAN_ASSERT(instruction->raw.mvex.SSS < ZYAN_ARRAY_LENGTH(lookup[index])); in ZydisSetAVXInformation()
2865 context->cd8_scale = lookup[index][instruction->raw.mvex.SSS]; in ZydisSetAVXInformation()
2877 ZYAN_ASSERT(instruction->raw.mvex.SSS < ZYAN_ARRAY_LENGTH(lookup[index])); in ZydisSetAVXInformation()
2878 context->cd8_scale = lookup[index][instruction->raw.mvex.SSS]; in ZydisSetAVXInformation()
2898 … instruction->avx.rounding.mode = ZYDIS_ROUNDING_MODE_RN + (instruction->raw.mvex.SSS & 3); in ZydisSetAVXInformation()
2901 if (instruction->raw.mvex.SSS >= 4) in ZydisSetAVXInformation()
2903 instruction->avx.has_sae = ZYAN_TRUE; in ZydisSetAVXInformation()
2908 instruction->avx.swizzle.mode = ZYDIS_SWIZZLE_MODE_DCBA + instruction->raw.mvex.SSS; in ZydisSetAVXInformation()
2913 switch (instruction->raw.mvex.SSS) in ZydisSetAVXInformation()
2918 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_1_TO_16; in ZydisSetAVXInformation()
2921 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16; in ZydisSetAVXInformation()
2924 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_FLOAT16; in ZydisSetAVXInformation()
2927 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8; in ZydisSetAVXInformation()
2930 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8; in ZydisSetAVXInformation()
2933 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16; in ZydisSetAVXInformation()
2936 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16; in ZydisSetAVXInformation()
2945 switch (instruction->raw.mvex.SSS) in ZydisSetAVXInformation()
2950 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_1_TO_16; in ZydisSetAVXInformation()
2953 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16; in ZydisSetAVXInformation()
2956 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8; in ZydisSetAVXInformation()
2959 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8; in ZydisSetAVXInformation()
2962 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16; in ZydisSetAVXInformation()
2965 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16; in ZydisSetAVXInformation()
2973 switch (instruction->raw.mvex.SSS) in ZydisSetAVXInformation()
2978 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_1_TO_8; in ZydisSetAVXInformation()
2981 instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_8; in ZydisSetAVXInformation()
2989 switch (instruction->raw.mvex.SSS) in ZydisSetAVXInformation()
2994 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_FLOAT16; in ZydisSetAVXInformation()
2997 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8; in ZydisSetAVXInformation()
3000 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8; in ZydisSetAVXInformation()
3003 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16; in ZydisSetAVXInformation()
3006 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16; in ZydisSetAVXInformation()
3017 switch (instruction->raw.mvex.SSS) in ZydisSetAVXInformation()
3022 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8; in ZydisSetAVXInformation()
3025 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8; in ZydisSetAVXInformation()
3028 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16; in ZydisSetAVXInformation()
3031 instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16; in ZydisSetAVXInformation()
3045 if ((instruction->raw.modrm.mod != 3) && instruction->raw.mvex.E) in ZydisSetAVXInformation()
3047 instruction->avx.has_eviction_hint = ZYAN_TRUE; in ZydisSetAVXInformation()
3051 instruction->avx.mask.mode = ZYDIS_MASK_MODE_MERGING; in ZydisSetAVXInformation()
3052 instruction->avx.mask.reg = ZYDIS_REGISTER_K0 + instruction->raw.mvex.kkk; in ZydisSetAVXInformation()
3081 ZydisDecodedInstruction* instruction) in ZydisCollectOptionalPrefixes() argument
3084 ZYAN_ASSERT(instruction); in ZydisCollectOptionalPrefixes()
3085 ZYAN_ASSERT(instruction->raw.prefix_count == 0); in ZydisCollectOptionalPrefixes()
3093 ZYAN_CHECK(ZydisInputPeek(state, instruction, &prefix_byte)); in ZydisCollectOptionalPrefixes()
3145 instruction->attributes |= ZYDIS_ATTRIB_HAS_OPERANDSIZE; in ZydisCollectOptionalPrefixes()
3150 instruction->attributes |= ZYDIS_ATTRIB_HAS_ADDRESSSIZE; in ZydisCollectOptionalPrefixes()
3157 instruction->raw.rex.offset = offset; in ZydisCollectOptionalPrefixes()
3170 instruction->raw.rex.offset = 0; in ZydisCollectOptionalPrefixes()
3172 instruction->raw.prefixes[instruction->raw.prefix_count++].value = prefix_byte; in ZydisCollectOptionalPrefixes()
3173 ZydisInputSkip(state, instruction); in ZydisCollectOptionalPrefixes()
3178 if (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) in ZydisCollectOptionalPrefixes()
3180 instruction->raw.prefixes[state->prefixes.offset_osz_override].type = in ZydisCollectOptionalPrefixes()
3183 if (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) in ZydisCollectOptionalPrefixes()
3185 instruction->raw.prefixes[state->prefixes.offset_asz_override].type = in ZydisCollectOptionalPrefixes()
3190 instruction->raw.prefixes[instruction->raw.rex.offset].type = ZYDIS_PREFIX_TYPE_EFFECTIVE; in ZydisCollectOptionalPrefixes()
3191 ZydisDecodeREX(state->context, instruction, rex); in ZydisCollectOptionalPrefixes()
3213 ZydisDecodedInstruction* instruction, const ZydisInstructionEncodingInfo* info) in ZydisDecodeOptionalInstructionParts() argument
3216 ZYAN_ASSERT(instruction); in ZydisDecodeOptionalInstructionParts()
3223 if (!instruction->raw.modrm.offset) in ZydisDecodeOptionalInstructionParts()
3225 instruction->raw.modrm.offset = instruction->length; in ZydisDecodeOptionalInstructionParts()
3227 ZYAN_CHECK(ZydisInputNext(state, instruction, &modrm_byte)); in ZydisDecodeOptionalInstructionParts()
3228 ZydisDecodeModRM(instruction, modrm_byte); in ZydisDecodeOptionalInstructionParts()
3235 switch (instruction->address_width) in ZydisDecodeOptionalInstructionParts()
3238 switch (instruction->raw.modrm.mod) in ZydisDecodeOptionalInstructionParts()
3241 if (instruction->raw.modrm.rm == 6) in ZydisDecodeOptionalInstructionParts()
3261 (instruction->raw.modrm.mod != 3) && (instruction->raw.modrm.rm == 4); in ZydisDecodeOptionalInstructionParts()
3262 switch (instruction->raw.modrm.mod) in ZydisDecodeOptionalInstructionParts()
3265 if (instruction->raw.modrm.rm == 5) in ZydisDecodeOptionalInstructionParts()
3267 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisDecodeOptionalInstructionParts()
3269 instruction->attributes |= ZYDIS_ATTRIB_IS_RELATIVE; in ZydisDecodeOptionalInstructionParts()
3291 instruction->raw.sib.offset = instruction->length; in ZydisDecodeOptionalInstructionParts()
3293 ZYAN_CHECK(ZydisInputNext(state, instruction, &sib_byte)); in ZydisDecodeOptionalInstructionParts()
3294 ZydisDecodeSIB(instruction, sib_byte); in ZydisDecodeOptionalInstructionParts()
3295 if (instruction->raw.sib.base == 5) in ZydisDecodeOptionalInstructionParts()
3297 displacement_size = (instruction->raw.modrm.mod == 1) ? 8 : 32; in ZydisDecodeOptionalInstructionParts()
3302 ZYAN_CHECK(ZydisReadDisplacement(state, instruction, displacement_size)); in ZydisDecodeOptionalInstructionParts()
3306 context->reg_info.is_mod_reg = (instruction->raw.modrm.mod == 3) || in ZydisDecodeOptionalInstructionParts()
3313 state, instruction, info->disp.size[context->easz_index])); in ZydisDecodeOptionalInstructionParts()
3320 instruction->attributes |= ZYDIS_ATTRIB_IS_RELATIVE; in ZydisDecodeOptionalInstructionParts()
3322 ZYAN_CHECK(ZydisReadImmediate(state, instruction, 0, in ZydisDecodeOptionalInstructionParts()
3330 ZYAN_CHECK(ZydisReadImmediate(state, instruction, 1, in ZydisDecodeOptionalInstructionParts()
3348 ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) in ZydisSetEffectiveOperandWidth() argument
3351 ZYAN_ASSERT(instruction); in ZydisSetEffectiveOperandWidth()
3447 ZyanU8 index = (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 1 : 0; in ZydisSetEffectiveOperandWidth()
3448 if ((instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_COMPAT_32) || in ZydisSetEffectiveOperandWidth()
3449 (instruction->machine_mode == ZYDIS_MACHINE_MODE_LEGACY_32)) in ZydisSetEffectiveOperandWidth()
3453 else if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisSetEffectiveOperandWidth()
3462 instruction->operand_width = operand_size_map[definition->operand_size_map][index]; in ZydisSetEffectiveOperandWidth()
3463 context->eosz_index = instruction->operand_width >> 5; in ZydisSetEffectiveOperandWidth()
3468 instruction->operand_width = 8; in ZydisSetEffectiveOperandWidth()
3480 ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) in ZydisSetEffectiveAddressWidth() argument
3483 ZYAN_ASSERT(instruction); in ZydisSetEffectiveAddressWidth()
3517 ZyanU8 index = (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 0; in ZydisSetEffectiveAddressWidth()
3518 if ((instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_COMPAT_32) || in ZydisSetEffectiveAddressWidth()
3519 (instruction->machine_mode == ZYDIS_MACHINE_MODE_LEGACY_32)) in ZydisSetEffectiveAddressWidth()
3523 else if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisSetEffectiveAddressWidth()
3531 instruction->address_width = address_size_map[definition->address_size_map][index]; in ZydisSetEffectiveAddressWidth()
3532 context->easz_index = instruction->address_width >> 5; in ZydisSetEffectiveAddressWidth()
3537 static ZyanStatus ZydisNodeHandlerXOP(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerXOP() argument
3539 ZYAN_ASSERT(instruction); in ZydisNodeHandlerXOP()
3542 switch (instruction->encoding) in ZydisNodeHandlerXOP()
3548 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_XOP); in ZydisNodeHandlerXOP()
3549 *index = (instruction->raw.xop.m_mmmm - 0x08) + (instruction->raw.xop.pp * 3) + 1; in ZydisNodeHandlerXOP()
3557 static ZyanStatus ZydisNodeHandlerVEX(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerVEX() argument
3559 ZYAN_ASSERT(instruction); in ZydisNodeHandlerVEX()
3562 switch (instruction->encoding) in ZydisNodeHandlerVEX()
3568 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX); in ZydisNodeHandlerVEX()
3569 *index = instruction->raw.vex.m_mmmm + (instruction->raw.vex.pp << 2) + 1; in ZydisNodeHandlerVEX()
3577 static ZyanStatus ZydisNodeHandlerEMVEX(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerEMVEX() argument
3579 ZYAN_ASSERT(instruction); in ZydisNodeHandlerEMVEX()
3582 switch (instruction->encoding) in ZydisNodeHandlerEMVEX()
3588 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX); in ZydisNodeHandlerEMVEX()
3589 *index = instruction->raw.evex.mmm + (instruction->raw.evex.pp << 3) + 1; in ZydisNodeHandlerEMVEX()
3592 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX); in ZydisNodeHandlerEMVEX()
3593 *index = instruction->raw.mvex.mmmm + (instruction->raw.mvex.pp << 2) + 33; in ZydisNodeHandlerEMVEX()
3602 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerOpcode() argument
3605 ZYAN_ASSERT(instruction); in ZydisNodeHandlerOpcode()
3609 switch (instruction->encoding) in ZydisNodeHandlerOpcode()
3612 ZYAN_CHECK(ZydisInputNext(state, instruction, &instruction->opcode)); in ZydisNodeHandlerOpcode()
3613 switch (instruction->opcode_map) in ZydisNodeHandlerOpcode()
3616 switch (instruction->opcode) in ZydisNodeHandlerOpcode()
3619 instruction->opcode_map = ZYDIS_OPCODE_MAP_0F; in ZydisNodeHandlerOpcode()
3626 ZYAN_CHECK(ZydisInputPeek(state, instruction, &next_input)); in ZydisNodeHandlerOpcode()
3628 (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64)) in ZydisNodeHandlerOpcode()
3630 if (instruction->attributes & ZYDIS_ATTRIB_HAS_REX) in ZydisNodeHandlerOpcode()
3643 prefix_bytes[0] = instruction->opcode; in ZydisNodeHandlerOpcode()
3644 switch (instruction->opcode) in ZydisNodeHandlerOpcode()
3647 instruction->raw.vex.offset = instruction->length - 1; in ZydisNodeHandlerOpcode()
3649 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX)); in ZydisNodeHandlerOpcode()
3650 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, &prefix_bytes[1], 2)); in ZydisNodeHandlerOpcode()
3653 instruction->raw.vex.offset = instruction->length - 1; in ZydisNodeHandlerOpcode()
3655 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX)); in ZydisNodeHandlerOpcode()
3656 ZYAN_CHECK(ZydisInputNext(state, instruction, &prefix_bytes[1])); in ZydisNodeHandlerOpcode()
3661 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX)); in ZydisNodeHandlerOpcode()
3662 ZYAN_ASSERT(!(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX)); in ZydisNodeHandlerOpcode()
3663 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, &prefix_bytes[1], 3)); in ZydisNodeHandlerOpcode()
3671 switch (instruction->opcode) in ZydisNodeHandlerOpcode()
3676 instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_VEX; in ZydisNodeHandlerOpcode()
3677 ZYAN_CHECK(ZydisDecodeVEX(state->context, instruction, prefix_bytes)); in ZydisNodeHandlerOpcode()
3678 instruction->opcode_map = in ZydisNodeHandlerOpcode()
3679 ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.vex.m_mmmm; in ZydisNodeHandlerOpcode()
3689 instruction->raw.mvex.offset = instruction->length - 4; in ZydisNodeHandlerOpcode()
3699 instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_MVEX; in ZydisNodeHandlerOpcode()
3700 ZYAN_CHECK(ZydisDecodeMVEX(state->context, instruction, prefix_bytes)); in ZydisNodeHandlerOpcode()
3701 instruction->opcode_map = in ZydisNodeHandlerOpcode()
3702 ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.mvex.mmmm; in ZydisNodeHandlerOpcode()
3709 instruction->raw.evex.offset = instruction->length - 4; in ZydisNodeHandlerOpcode()
3711 instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_EVEX; in ZydisNodeHandlerOpcode()
3712 ZYAN_CHECK(ZydisDecodeEVEX(state->context, instruction, prefix_bytes)); in ZydisNodeHandlerOpcode()
3713 instruction->opcode_map = in ZydisNodeHandlerOpcode()
3714 ZYDIS_OPCODE_MAP_DEFAULT + instruction->raw.evex.mmm; in ZydisNodeHandlerOpcode()
3733 ZYAN_CHECK(ZydisInputPeek(state, instruction, &next_input)); in ZydisNodeHandlerOpcode()
3736 if (instruction->attributes & ZYDIS_ATTRIB_HAS_REX) in ZydisNodeHandlerOpcode()
3748 instruction->raw.xop.offset = instruction->length - 1; in ZydisNodeHandlerOpcode()
3751 ZYAN_CHECK(ZydisInputNextBytes(state, instruction, &prefixBytes[1], 2)); in ZydisNodeHandlerOpcode()
3753 instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_XOP; in ZydisNodeHandlerOpcode()
3754 ZYAN_CHECK(ZydisDecodeXOP(state->context, instruction, prefixBytes)); in ZydisNodeHandlerOpcode()
3755 instruction->opcode_map = in ZydisNodeHandlerOpcode()
3756 ZYDIS_OPCODE_MAP_XOP8 + instruction->raw.xop.m_mmmm - 0x08; in ZydisNodeHandlerOpcode()
3765 switch (instruction->opcode) in ZydisNodeHandlerOpcode()
3772 instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_3DNOW; in ZydisNodeHandlerOpcode()
3773 instruction->opcode_map = ZYDIS_OPCODE_MAP_0F0F; in ZydisNodeHandlerOpcode()
3776 instruction->opcode_map = ZYDIS_OPCODE_MAP_0F38; in ZydisNodeHandlerOpcode()
3779 instruction->opcode_map = ZYDIS_OPCODE_MAP_0F3A; in ZydisNodeHandlerOpcode()
3802 ZYAN_CHECK(ZydisInputNext(state, instruction, &instruction->opcode)); in ZydisNodeHandlerOpcode()
3806 *index = instruction->opcode; in ZydisNodeHandlerOpcode()
3810 static ZyanStatus ZydisNodeHandlerMode(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerMode() argument
3812 ZYAN_ASSERT(instruction); in ZydisNodeHandlerMode()
3815 switch (instruction->machine_mode) in ZydisNodeHandlerMode()
3835 static ZyanStatus ZydisNodeHandlerModeCompact(const ZydisDecodedInstruction* instruction, in ZydisNodeHandlerModeCompact() argument
3838 ZYAN_ASSERT(instruction); in ZydisNodeHandlerModeCompact()
3841 *index = (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) ? 0 : 1; in ZydisNodeHandlerModeCompact()
3846 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerModrmMod() argument
3849 ZYAN_ASSERT(instruction); in ZydisNodeHandlerModrmMod()
3852 if (!instruction->raw.modrm.offset) in ZydisNodeHandlerModrmMod()
3854 instruction->raw.modrm.offset = instruction->length; in ZydisNodeHandlerModrmMod()
3856 ZYAN_CHECK(ZydisInputNext(state, instruction, &modrm_byte)); in ZydisNodeHandlerModrmMod()
3857 ZydisDecodeModRM(instruction, modrm_byte); in ZydisNodeHandlerModrmMod()
3859 *index = instruction->raw.modrm.mod; in ZydisNodeHandlerModrmMod()
3864 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerModrmModCompact() argument
3866 ZYAN_CHECK(ZydisNodeHandlerModrmMod(state, instruction, index)); in ZydisNodeHandlerModrmModCompact()
3872 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerModrmReg() argument
3875 ZYAN_ASSERT(instruction); in ZydisNodeHandlerModrmReg()
3878 if (!instruction->raw.modrm.offset) in ZydisNodeHandlerModrmReg()
3880 instruction->raw.modrm.offset = instruction->length; in ZydisNodeHandlerModrmReg()
3882 ZYAN_CHECK(ZydisInputNext(state, instruction, &modrm_byte)); in ZydisNodeHandlerModrmReg()
3883 ZydisDecodeModRM(instruction, modrm_byte); in ZydisNodeHandlerModrmReg()
3885 *index = instruction->raw.modrm.reg; in ZydisNodeHandlerModrmReg()
3890 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerModrmRm() argument
3893 ZYAN_ASSERT(instruction); in ZydisNodeHandlerModrmRm()
3896 if (!instruction->raw.modrm.offset) in ZydisNodeHandlerModrmRm()
3898 instruction->raw.modrm.offset = instruction->length; in ZydisNodeHandlerModrmRm()
3900 ZYAN_CHECK(ZydisInputNext(state, instruction, &modrm_byte)); in ZydisNodeHandlerModrmRm()
3901 ZydisDecodeModRM(instruction, modrm_byte); in ZydisNodeHandlerModrmRm()
3903 *index = instruction->raw.modrm.rm; in ZydisNodeHandlerModrmRm()
3908 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerMandatoryPrefix() argument
3911 ZYAN_ASSERT(instruction); in ZydisNodeHandlerMandatoryPrefix()
3917 instruction->raw.prefixes[state->prefixes.offset_mandatory].type = in ZydisNodeHandlerMandatoryPrefix()
3919 instruction->attributes &= ~ZYDIS_ATTRIB_HAS_OPERANDSIZE; in ZydisNodeHandlerMandatoryPrefix()
3923 instruction->raw.prefixes[state->prefixes.offset_mandatory].type = in ZydisNodeHandlerMandatoryPrefix()
3928 instruction->raw.prefixes[state->prefixes.offset_mandatory].type = in ZydisNodeHandlerMandatoryPrefix()
3942 ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerOperandSize() argument
3945 ZYAN_ASSERT(instruction); in ZydisNodeHandlerOperandSize()
3948 if ((instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) && in ZydisNodeHandlerOperandSize()
3954 if (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) in ZydisNodeHandlerOperandSize()
3956 instruction->raw.prefixes[state->prefixes.offset_osz_override].type = in ZydisNodeHandlerOperandSize()
3959 switch (instruction->machine_mode) in ZydisNodeHandlerOperandSize()
3964 *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 1 : 0; in ZydisNodeHandlerOperandSize()
3969 *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_OPERANDSIZE) ? 0 : 1; in ZydisNodeHandlerOperandSize()
3979 static ZyanStatus ZydisNodeHandlerAddressSize(ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerAddressSize() argument
3981 ZYAN_ASSERT(instruction); in ZydisNodeHandlerAddressSize()
3989 switch (instruction->machine_mode) in ZydisNodeHandlerAddressSize()
3994 *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 0; in ZydisNodeHandlerAddressSize()
3998 *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 0 : 1; in ZydisNodeHandlerAddressSize()
4001 *index = (instruction->attributes & ZYDIS_ATTRIB_HAS_ADDRESSSIZE) ? 1 : 2; in ZydisNodeHandlerAddressSize()
4011 const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerVectorLength() argument
4014 ZYAN_ASSERT(instruction); in ZydisNodeHandlerVectorLength()
4017 switch (instruction->encoding) in ZydisNodeHandlerVectorLength()
4020 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_XOP); in ZydisNodeHandlerVectorLength()
4023 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX); in ZydisNodeHandlerVectorLength()
4026 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX); in ZydisNodeHandlerVectorLength()
4029 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX); in ZydisNodeHandlerVectorLength()
4044 const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerRexW() argument
4047 ZYAN_ASSERT(instruction); in ZydisNodeHandlerRexW()
4050 switch (instruction->encoding) in ZydisNodeHandlerRexW()
4056 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_XOP); in ZydisNodeHandlerRexW()
4059 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX); in ZydisNodeHandlerRexW()
4062 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX); in ZydisNodeHandlerRexW()
4065 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX); in ZydisNodeHandlerRexW()
4075 const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerRexB() argument
4078 ZYAN_ASSERT(instruction); in ZydisNodeHandlerRexB()
4081 switch (instruction->encoding) in ZydisNodeHandlerRexB()
4087 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_XOP); in ZydisNodeHandlerRexB()
4090 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_VEX); in ZydisNodeHandlerRexB()
4093 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX); in ZydisNodeHandlerRexB()
4096 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX); in ZydisNodeHandlerRexB()
4106 static ZyanStatus ZydisNodeHandlerEvexB(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerEvexB() argument
4108 ZYAN_ASSERT(instruction); in ZydisNodeHandlerEvexB()
4111 ZYAN_ASSERT(instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX); in ZydisNodeHandlerEvexB()
4112 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_EVEX); in ZydisNodeHandlerEvexB()
4113 *index = instruction->raw.evex.b; in ZydisNodeHandlerEvexB()
4119 static ZyanStatus ZydisNodeHandlerMvexE(const ZydisDecodedInstruction* instruction, ZyanU16* index) in ZydisNodeHandlerMvexE() argument
4121 ZYAN_ASSERT(instruction); in ZydisNodeHandlerMvexE()
4124 ZYAN_ASSERT(instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX); in ZydisNodeHandlerMvexE()
4125 ZYAN_ASSERT(instruction->attributes & ZYDIS_ATTRIB_HAS_MVEX); in ZydisNodeHandlerMvexE()
4126 *index = instruction->raw.mvex.E; in ZydisNodeHandlerMvexE()
4154 const ZydisDecodedInstruction* instruction, ZyanU8 def_reg, ZyanU8 def_rm, ZyanU8 def_ndsndd) in ZydisPopulateRegisterIds() argument
4157 ZYAN_ASSERT(instruction); in ZydisPopulateRegisterIds()
4159 const ZyanBool is_64_bit = (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64); in ZydisPopulateRegisterIds()
4161 const ZyanBool has_sib = !is_reg && (instruction->raw.modrm.rm == 4); in ZydisPopulateRegisterIds()
4164 ZyanU8 id_reg = instruction->raw.modrm.reg; in ZydisPopulateRegisterIds()
4165 ZyanU8 id_rm = instruction->raw.modrm.rm; in ZydisPopulateRegisterIds()
4167 ZyanU8 id_base = has_sib ? instruction->raw.sib.base : instruction->raw.modrm.rm; in ZydisPopulateRegisterIds()
4168 ZyanU8 id_index = instruction->raw.sib.index; in ZydisPopulateRegisterIds()
4170 if (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_64) in ZydisPopulateRegisterIds()
4172 const ZyanBool is_emvex = (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || in ZydisPopulateRegisterIds()
4173 (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX); in ZydisPopulateRegisterIds()
4347 const ZydisDecodedInstruction* instruction, const ZydisInstructionDefinition* definition) in ZydisCheckErrorConditions() argument
4350 ZYAN_ASSERT(instruction); in ZydisCheckErrorConditions()
4363 switch (instruction->encoding) in ZydisCheckErrorConditions()
4371 (instruction->machine_mode == ZYDIS_MACHINE_MODE_REAL_16)) in ZydisCheckErrorConditions()
4377 ((instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_COMPAT_16) || in ZydisCheckErrorConditions()
4378 (instruction->machine_mode == ZYDIS_MACHINE_MODE_LONG_COMPAT_32))) in ZydisCheckErrorConditions()
4420 if ((instruction->raw.evex.z) && (!def->accepts_zero_mask)) in ZydisCheckErrorConditions()
4495 ZYAN_ASSERT(instruction->raw.mvex.SSS < 8); in ZydisCheckErrorConditions()
4496 if (!lookup[def->functionality][instruction->raw.mvex.SSS]) in ZydisCheckErrorConditions()
4539 (instruction->raw.modrm.mod == 0) && (instruction->raw.modrm.rm == 5); in ZydisCheckErrorConditions()
4547 ZYAN_CHECK(ZydisPopulateRegisterIds(context, instruction, def_reg, def_rm, def_ndsndd)); in ZydisCheckErrorConditions()
4563 ZYAN_ASSERT(instruction->raw.modrm.mod != 3); in ZydisCheckErrorConditions()
4564 ZYAN_ASSERT(instruction->raw.modrm.rm == 4); in ZydisCheckErrorConditions()
4570 if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_VEX) in ZydisCheckErrorConditions()
4578 if ((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || in ZydisCheckErrorConditions()
4579 (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_MVEX)) in ZydisCheckErrorConditions()
4605 ZYAN_ASSERT((instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX) || in ZydisCheckErrorConditions()
4606 (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_VEX)); in ZydisCheckErrorConditions()
4622 ZYAN_ASSERT(instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_VEX); in ZydisCheckErrorConditions()
4674 ZydisDecodedInstruction* instruction) in ZydisDecodeInstruction() argument
4677 ZYAN_ASSERT(instruction); in ZydisDecodeInstruction()
4698 instruction->raw.prefixes[state->prefixes.offset_mandatory].type = in ZydisDecodeInstruction()
4706 instruction->raw.prefixes[state->prefixes.offset_mandatory].type = in ZydisDecodeInstruction()
4709 instruction->attributes |= ZYDIS_ATTRIB_HAS_OPERANDSIZE; in ZydisDecodeInstruction()
4715 status = ZydisNodeHandlerXOP(instruction, &index); in ZydisDecodeInstruction()
4718 status = ZydisNodeHandlerVEX(instruction, &index); in ZydisDecodeInstruction()
4721 status = ZydisNodeHandlerEMVEX(instruction, &index); in ZydisDecodeInstruction()
4724 status = ZydisNodeHandlerOpcode(state, instruction, &index); in ZydisDecodeInstruction()
4727 status = ZydisNodeHandlerMode(instruction, &index); in ZydisDecodeInstruction()
4730 status = ZydisNodeHandlerModeCompact(instruction, &index); in ZydisDecodeInstruction()
4733 status = ZydisNodeHandlerModrmMod(state, instruction, &index); in ZydisDecodeInstruction()
4736 status = ZydisNodeHandlerModrmModCompact(state, instruction, &index); in ZydisDecodeInstruction()
4739 status = ZydisNodeHandlerModrmReg(state, instruction, &index); in ZydisDecodeInstruction()
4742 status = ZydisNodeHandlerModrmRm(state, instruction, &index); in ZydisDecodeInstruction()
4748 status = ZydisNodeHandlerMandatoryPrefix(state, instruction, &index); in ZydisDecodeInstruction()
4755 status = ZydisNodeHandlerOperandSize(state, instruction, &index); in ZydisDecodeInstruction()
4758 status = ZydisNodeHandlerAddressSize(instruction, &index); in ZydisDecodeInstruction()
4761 status = ZydisNodeHandlerVectorLength(state->context, instruction, &index); in ZydisDecodeInstruction()
4764 status = ZydisNodeHandlerRexW(state->context, instruction, &index); in ZydisDecodeInstruction()
4767 status = ZydisNodeHandlerRexB(state->context, instruction, &index); in ZydisDecodeInstruction()
4771 status = ZydisNodeHandlerEvexB(instruction, &index); in ZydisDecodeInstruction()
4776 status = ZydisNodeHandlerMvexE(instruction, &index); in ZydisDecodeInstruction()
4813 ZydisGetInstructionDefinition(instruction->encoding, node->value, &definition); in ZydisDecodeInstruction()
4814 ZydisSetEffectiveOperandWidth(state->context, instruction, definition); in ZydisDecodeInstruction()
4815 ZydisSetEffectiveAddressWidth(state->context, instruction, definition); in ZydisDecodeInstruction()
4819 ZYAN_CHECK(ZydisDecodeOptionalInstructionParts(state, instruction, info)); in ZydisDecodeInstruction()
4820 ZYAN_CHECK(ZydisCheckErrorConditions(state, instruction, definition)); in ZydisDecodeInstruction()
4822 if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_3DNOW) in ZydisDecodeInstruction()
4825 ZYAN_CHECK(ZydisInputNext(state, instruction, &instruction->opcode)); in ZydisDecodeInstruction()
4829 node = ZydisDecoderTreeGetChildNode(node, instruction->opcode); in ZydisDecodeInstruction()
4836 node, (instruction->raw.modrm.mod == 0x3) ? 0 : 1); in ZydisDecodeInstruction()
4838 ZydisGetInstructionDefinition(instruction->encoding, node->value, &definition); in ZydisDecodeInstruction()
4841 instruction->mnemonic = definition->mnemonic; in ZydisDecodeInstruction()
4845 instruction->operand_count = definition->operand_count; in ZydisDecodeInstruction()
4846 instruction->operand_count_visible = definition->operand_count_visible; in ZydisDecodeInstruction()
4849 instruction->meta.category = definition->category; in ZydisDecodeInstruction()
4850 instruction->meta.isa_set = definition->isa_set; in ZydisDecodeInstruction()
4851 instruction->meta.isa_ext = definition->isa_ext; in ZydisDecodeInstruction()
4852 instruction->meta.branch_type = definition->branch_type; in ZydisDecodeInstruction()
4853 ZYAN_ASSERT((instruction->meta.branch_type == ZYDIS_BRANCH_TYPE_NONE) || in ZydisDecodeInstruction()
4854 ((instruction->meta.category == ZYDIS_CATEGORY_CALL) || in ZydisDecodeInstruction()
4855 (instruction->meta.category == ZYDIS_CATEGORY_COND_BR) || in ZydisDecodeInstruction()
4856 (instruction->meta.category == ZYDIS_CATEGORY_UNCOND_BR) || in ZydisDecodeInstruction()
4857 (instruction->meta.category == ZYDIS_CATEGORY_RET))); in ZydisDecodeInstruction()
4858 instruction->meta.exception_class = definition->exception_class; in ZydisDecodeInstruction()
4862 ZydisSetAttributes(state, instruction, definition); in ZydisDecodeInstruction()
4863 switch (instruction->encoding) in ZydisDecodeInstruction()
4869 ZydisSetAVXInformation(state->context, instruction, definition); in ZydisDecodeInstruction()
4878 instruction->attributes |= ZYDIS_ATTRIB_CPUFLAG_ACCESS; in ZydisDecodeInstruction()
4880 instruction->cpu_flags = &flags->cpu_flags; in ZydisDecodeInstruction()
4881 instruction->fpu_flags = &flags->fpu_flags; in ZydisDecodeInstruction()
4978 const void* buffer, ZyanUSize length, ZydisDecodedInstruction* instruction, in ZydisDecoderDecodeFull() argument
4981 if (!decoder || !instruction || !buffer || !operands) in ZydisDecoderDecodeFull()
4995 ZYAN_CHECK(ZydisDecoderDecodeInstruction(decoder, &context, buffer, length, instruction)); in ZydisDecoderDecodeFull()
4996 ZYAN_CHECK(ZydisDecoderDecodeOperands(decoder, &context, instruction, operands, in ZydisDecoderDecodeFull()
4997 instruction->operand_count)); in ZydisDecoderDecodeFull()
4998 ZYAN_MEMSET(&operands[instruction->operand_count], 0, in ZydisDecoderDecodeFull()
4999 (ZYDIS_MAX_OPERAND_COUNT - instruction->operand_count) * sizeof(operands[0])); in ZydisDecoderDecodeFull()
5005 const void* buffer, ZyanUSize length, ZydisDecodedInstruction* instruction) in ZydisDecoderDecodeInstruction() argument
5007 if (!decoder || !instruction || !buffer) in ZydisDecoderDecodeInstruction()
5033 ZYAN_MEMSET(instruction, 0, sizeof(*instruction)); in ZydisDecoderDecodeInstruction()
5034 instruction->machine_mode = decoder->machine_mode; in ZydisDecoderDecodeInstruction()
5035 instruction->stack_width = 16 << decoder->stack_width; in ZydisDecoderDecodeInstruction()
5037 ZYAN_CHECK(ZydisCollectOptionalPrefixes(&state, instruction)); in ZydisDecoderDecodeInstruction()
5038 ZYAN_CHECK(ZydisDecodeInstruction(&state, instruction)); in ZydisDecoderDecodeInstruction()
5040 instruction->raw.encoding2 = instruction->encoding; in ZydisDecoderDecodeInstruction()
5046 const ZydisDecoderContext* context, const ZydisDecodedInstruction* instruction, in ZydisDecoderDecodeOperands() argument
5053 ZYAN_UNUSED(instruction); in ZydisDecoderDecodeOperands()
5061 if (!decoder || !context || !context->definition || !instruction || in ZydisDecoderDecodeOperands()
5072 operand_count = ZYAN_MIN(operand_count, instruction->operand_count); in ZydisDecoderDecodeOperands()
5078 return ZydisDecodeOperands(decoder, context, instruction, operands, operand_count); in ZydisDecoderDecodeOperands()