20 #include "x86emu/x86emui.h" 31 static void x86emuOp2_illegal_op(u8 op2)
34 DECODE_PRINTF(
"ILLEGAL EXTENDED X86 OPCODE\n");
37 "%04x:%04x: %02X ILLEGAL EXTENDED X86 OPCODE!\n", M.x86.R_CS,
43 #define xorl(a, b) ((a) && !(b)) || (!(a) && (b)) 49 static void x86emuOp2_rdtsc(u8 X86EMU_UNUSED(op2))
51 #ifdef __HAS_LONG_LONG__ 52 static u64 counter = 0;
54 static u32 counter = 0;
66 DECODE_PRINTF(
"RDTSC\n");
68 #ifdef __HAS_LONG_LONG__ 69 M.x86.R_EAX = counter & 0xffffffff;
70 M.x86.R_EDX = counter >> 32;
72 M.x86.R_EAX = counter;
75 DECODE_CLEAR_SEGOVR();
83 static void x86emuOp2_long_jump(u8 op2)
95 cond = ACCESS_FLAG(F_OF);
99 cond = !ACCESS_FLAG(F_OF);
103 cond = ACCESS_FLAG(F_CF);
107 cond = !ACCESS_FLAG(F_CF);
111 cond = ACCESS_FLAG(F_ZF);
115 cond = !ACCESS_FLAG(F_ZF);
119 cond = ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF);
123 cond = !(ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF));
127 cond = ACCESS_FLAG(F_SF);
131 cond = !ACCESS_FLAG(F_SF);
135 cond = ACCESS_FLAG(F_PF);
139 cond = !ACCESS_FLAG(F_PF);
143 cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF));
147 cond = !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)));
152 (xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) ||
158 !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) ||
164 target = (s16) fetch_word_imm();
165 target += (s16) M.x86.R_IP;
166 DECODE_PRINTF2(
"%04x\n", target);
169 M.x86.R_IP = (u16) target;
170 DECODE_CLEAR_SEGOVR();
178 static void x86emuOp2_set_byte(u8 op2)
183 const char *name = 0;
191 cond = ACCESS_FLAG(F_OF);
195 cond = !ACCESS_FLAG(F_OF);
199 cond = ACCESS_FLAG(F_CF);
203 cond = !ACCESS_FLAG(F_CF);
207 cond = ACCESS_FLAG(F_ZF);
211 cond = !ACCESS_FLAG(F_ZF);
215 cond = ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF);
219 cond = !(ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF));
223 cond = ACCESS_FLAG(F_SF);
227 cond = !ACCESS_FLAG(F_SF);
231 cond = ACCESS_FLAG(F_PF);
235 cond = !ACCESS_FLAG(F_PF);
239 cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF));
243 cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF));
248 (xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) ||
254 !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) ||
260 FETCH_DECODE_MODRM(mod, rh, rl);
264 destoffset = decode_rm00_address(rl);
266 store_data_byte(destoffset, cond ? 0x01 : 0x00);
269 destoffset = decode_rm01_address(rl);
271 store_data_byte(destoffset, cond ? 0x01 : 0x00);
274 destoffset = decode_rm10_address(rl);
276 store_data_byte(destoffset, cond ? 0x01 : 0x00);
279 destreg = DECODE_RM_BYTE_REGISTER(rl);
281 *destreg = cond ? 0x01 : 0x00;
284 DECODE_CLEAR_SEGOVR();
292 static void x86emuOp2_push_FS(u8 X86EMU_UNUSED(op2))
295 DECODE_PRINTF(
"PUSH\tFS\n");
297 push_word(M.x86.R_FS);
298 DECODE_CLEAR_SEGOVR();
306 static void x86emuOp2_pop_FS(u8 X86EMU_UNUSED(op2))
309 DECODE_PRINTF(
"POP\tFS\n");
311 M.x86.R_FS = pop_word();
312 DECODE_CLEAR_SEGOVR();
320 static void x86emuOp2_bt_R(u8 X86EMU_UNUSED(op2))
327 DECODE_PRINTF(
"BT\t");
328 FETCH_DECODE_MODRM(mod, rh, rl);
332 if (M.x86.mode & SYSMODE_PREFIX_DATA)
337 srcoffset = decode_rm00_address(rl);
339 shiftreg = DECODE_RM_LONG_REGISTER(rh);
341 bit = *shiftreg & 0x1F;
342 disp = (s16) *shiftreg >> 5;
343 srcval = fetch_data_long(srcoffset + disp);
344 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
351 srcoffset = decode_rm00_address(rl);
353 shiftreg = DECODE_RM_WORD_REGISTER(rh);
355 bit = *shiftreg & 0xF;
356 disp = (s16) *shiftreg >> 4;
357 srcval = fetch_data_word(srcoffset + disp);
358 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
362 if (M.x86.mode & SYSMODE_PREFIX_DATA)
367 srcoffset = decode_rm01_address(rl);
369 shiftreg = DECODE_RM_LONG_REGISTER(rh);
371 bit = *shiftreg & 0x1F;
372 disp = (s16) *shiftreg >> 5;
373 srcval = fetch_data_long(srcoffset + disp);
374 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
381 srcoffset = decode_rm01_address(rl);
383 shiftreg = DECODE_RM_WORD_REGISTER(rh);
385 bit = *shiftreg & 0xF;
386 disp = (s16) *shiftreg >> 4;
387 srcval = fetch_data_word(srcoffset + disp);
388 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
392 if (M.x86.mode & SYSMODE_PREFIX_DATA)
397 srcoffset = decode_rm10_address(rl);
399 shiftreg = DECODE_RM_LONG_REGISTER(rh);
401 bit = *shiftreg & 0x1F;
402 disp = (s16) *shiftreg >> 5;
403 srcval = fetch_data_long(srcoffset + disp);
404 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
411 srcoffset = decode_rm10_address(rl);
413 shiftreg = DECODE_RM_WORD_REGISTER(rh);
415 bit = *shiftreg & 0xF;
416 disp = (s16) *shiftreg >> 4;
417 srcval = fetch_data_word(srcoffset + disp);
418 CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF);
422 if (M.x86.mode & SYSMODE_PREFIX_DATA)
424 u32 *srcreg, *shiftreg;
426 srcreg = DECODE_RM_LONG_REGISTER(rl);
428 shiftreg = DECODE_RM_LONG_REGISTER(rh);
430 bit = *shiftreg & 0x1F;
431 CONDITIONAL_SET_FLAG(*srcreg & (0x1 << bit), F_CF);
435 u16 *srcreg, *shiftreg;
437 srcreg = DECODE_RM_WORD_REGISTER(rl);
439 shiftreg = DECODE_RM_WORD_REGISTER(rh);
441 bit = *shiftreg & 0xF;
442 CONDITIONAL_SET_FLAG(*srcreg & (0x1 << bit), F_CF);
446 DECODE_CLEAR_SEGOVR();
454 static void x86emuOp2_shld_IMM(u8 X86EMU_UNUSED(op2))
461 DECODE_PRINTF(
"SHLD\t");
462 FETCH_DECODE_MODRM(mod, rh, rl);
466 if (M.x86.mode & SYSMODE_PREFIX_DATA)
471 destoffset = decode_rm00_address(rl);
473 shiftreg = DECODE_RM_LONG_REGISTER(rh);
475 shift = fetch_byte_imm();
476 DECODE_PRINTF2(
"%d\n", shift);
478 destval = fetch_data_long(destoffset);
479 destval = shld_long(destval, *shiftreg, shift);
480 store_data_long(destoffset, destval);
487 destoffset = decode_rm00_address(rl);
489 shiftreg = DECODE_RM_WORD_REGISTER(rh);
491 shift = fetch_byte_imm();
492 DECODE_PRINTF2(
"%d\n", shift);
494 destval = fetch_data_word(destoffset);
495 destval = shld_word(destval, *shiftreg, shift);
496 store_data_word(destoffset, destval);
500 if (M.x86.mode & SYSMODE_PREFIX_DATA)
505 destoffset = decode_rm01_address(rl);
507 shiftreg = DECODE_RM_LONG_REGISTER(rh);
509 shift = fetch_byte_imm();
510 DECODE_PRINTF2(
"%d\n", shift);
512 destval = fetch_data_long(destoffset);
513 destval = shld_long(destval, *shiftreg, shift);
514 store_data_long(destoffset, destval);
521 destoffset = decode_rm01_address(rl);
523 shiftreg = DECODE_RM_WORD_REGISTER(rh);
525 shift = fetch_byte_imm();
526 DECODE_PRINTF2(
"%d\n", shift);
528 destval = fetch_data_word(destoffset);
529 destval = shld_word(destval, *shiftreg, shift);
530 store_data_word(destoffset, destval);
534 if (M.x86.mode & SYSMODE_PREFIX_DATA)
539 destoffset = decode_rm10_address(rl);
541 shiftreg = DECODE_RM_LONG_REGISTER(rh);
543 shift = fetch_byte_imm();
544 DECODE_PRINTF2(
"%d\n", shift);
546 destval = fetch_data_long(destoffset);
547 destval = shld_long(destval, *shiftreg, shift);
548 store_data_long(destoffset, destval);
555 destoffset = decode_rm10_address(rl);
557 shiftreg = DECODE_RM_WORD_REGISTER(rh);
559 shift = fetch_byte_imm();
560 DECODE_PRINTF2(
"%d\n", shift);
562 destval = fetch_data_word(destoffset);
563 destval = shld_word(destval, *shiftreg, shift);
564 store_data_word(destoffset, destval);
568 if (M.x86.mode & SYSMODE_PREFIX_DATA)
570 u32 *destreg, *shiftreg;
572 destreg = DECODE_RM_LONG_REGISTER(rl);
574 shiftreg = DECODE_RM_LONG_REGISTER(rh);
576 shift = fetch_byte_imm();
577 DECODE_PRINTF2(
"%d\n", shift);
579 *destreg = shld_long(*destreg, *shiftreg, shift);
583 u16 *destreg, *shiftreg;
585 destreg = DECODE_RM_WORD_REGISTER(rl);
587 shiftreg = DECODE_RM_WORD_REGISTER(rh);
589 shift = fetch_byte_imm();
590 DECODE_PRINTF2(
"%d\n", shift);
592 *destreg = shld_word(*destreg, *shiftreg, shift);
596 DECODE_CLEAR_SEGOVR();
604 static void x86emuOp2_shld_CL(u8 X86EMU_UNUSED(op2))
610 DECODE_PRINTF(
"SHLD\t");
611 FETCH_DECODE_MODRM(mod, rh, rl);
615 if (M.x86.mode & SYSMODE_PREFIX_DATA)
620 destoffset = decode_rm00_address(rl);
622 shiftreg = DECODE_RM_LONG_REGISTER(rh);
623 DECODE_PRINTF(
",CL\n");
625 destval = fetch_data_long(destoffset);
626 destval = shld_long(destval, *shiftreg, M.x86.R_CL);
627 store_data_long(destoffset, destval);
634 destoffset = decode_rm00_address(rl);
636 shiftreg = DECODE_RM_WORD_REGISTER(rh);
637 DECODE_PRINTF(
",CL\n");
639 destval = fetch_data_word(destoffset);
640 destval = shld_word(destval, *shiftreg, M.x86.R_CL);
641 store_data_word(destoffset, destval);
645 if (M.x86.mode & SYSMODE_PREFIX_DATA)
650 destoffset = decode_rm01_address(rl);
652 shiftreg = DECODE_RM_LONG_REGISTER(rh);
653 DECODE_PRINTF(
",CL\n");
655 destval = fetch_data_long(destoffset);
656 destval = shld_long(destval, *shiftreg, M.x86.R_CL);
657 store_data_long(destoffset, destval);
664 destoffset = decode_rm01_address(rl);
666 shiftreg = DECODE_RM_WORD_REGISTER(rh);
667 DECODE_PRINTF(
",CL\n");
669 destval = fetch_data_word(destoffset);
670 destval = shld_word(destval, *shiftreg, M.x86.R_CL);
671 store_data_word(destoffset, destval);
675 if (M.x86.mode & SYSMODE_PREFIX_DATA)
680 destoffset = decode_rm10_address(rl);
682 shiftreg = DECODE_RM_LONG_REGISTER(rh);
683 DECODE_PRINTF(
",CL\n");
685 destval = fetch_data_long(destoffset);
686 destval = shld_long(destval, *shiftreg, M.x86.R_CL);
687 store_data_long(destoffset, destval);
694 destoffset = decode_rm10_address(rl);
696 shiftreg = DECODE_RM_WORD_REGISTER(rh);
697 DECODE_PRINTF(
",CL\n");
699 destval = fetch_data_word(destoffset);
700 destval = shld_word(destval, *shiftreg, M.x86.R_CL);
701 store_data_word(destoffset, destval);
705 if (M.x86.mode & SYSMODE_PREFIX_DATA)
707 u32 *destreg, *shiftreg;
709 destreg = DECODE_RM_LONG_REGISTER(rl);
711 shiftreg = DECODE_RM_LONG_REGISTER(rh);
712 DECODE_PRINTF(
",CL\n");
714 *destreg = shld_long(*destreg, *shiftreg, M.x86.R_CL);
718 u16 *destreg, *shiftreg;
720 destreg = DECODE_RM_WORD_REGISTER(rl);
722 shiftreg = DECODE_RM_WORD_REGISTER(rh);
723 DECODE_PRINTF(
",CL\n");
725 *destreg = shld_word(*destreg, *shiftreg, M.x86.R_CL);
729 DECODE_CLEAR_SEGOVR();
737 static void x86emuOp2_push_GS(u8 X86EMU_UNUSED(op2))
740 DECODE_PRINTF(
"PUSH\tGS\n");
742 push_word(M.x86.R_GS);
743 DECODE_CLEAR_SEGOVR();
751 static void x86emuOp2_pop_GS(u8 X86EMU_UNUSED(op2))
754 DECODE_PRINTF(
"POP\tGS\n");
756 M.x86.R_GS = pop_word();
757 DECODE_CLEAR_SEGOVR();
765 static void x86emuOp2_bts_R(u8 X86EMU_UNUSED(op2))
772 DECODE_PRINTF(
"BTS\t");
773 FETCH_DECODE_MODRM(mod, rh, rl);
777 if (M.x86.mode & SYSMODE_PREFIX_DATA)
782 srcoffset = decode_rm00_address(rl);
784 shiftreg = DECODE_RM_LONG_REGISTER(rh);
786 bit = *shiftreg & 0x1F;
787 disp = (s16) *shiftreg >> 5;
788 srcval = fetch_data_long(srcoffset + disp);
790 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
791 store_data_long(srcoffset + disp, srcval | mask);
798 srcoffset = decode_rm00_address(rl);
800 shiftreg = DECODE_RM_WORD_REGISTER(rh);
802 bit = *shiftreg & 0xF;
803 disp = (s16) *shiftreg >> 4;
804 srcval = fetch_data_word(srcoffset + disp);
805 mask = (u16)(0x1 << bit);
806 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
807 store_data_word(srcoffset + disp, srcval | mask);
811 if (M.x86.mode & SYSMODE_PREFIX_DATA)
816 srcoffset = decode_rm01_address(rl);
818 shiftreg = DECODE_RM_LONG_REGISTER(rh);
820 bit = *shiftreg & 0x1F;
821 disp = (s16) *shiftreg >> 5;
822 srcval = fetch_data_long(srcoffset + disp);
824 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
825 store_data_long(srcoffset + disp, srcval | mask);
832 srcoffset = decode_rm01_address(rl);
834 shiftreg = DECODE_RM_WORD_REGISTER(rh);
836 bit = *shiftreg & 0xF;
837 disp = (s16) *shiftreg >> 4;
838 srcval = fetch_data_word(srcoffset + disp);
839 mask = (u16)(0x1 << bit);
840 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
841 store_data_word(srcoffset + disp, srcval | mask);
845 if (M.x86.mode & SYSMODE_PREFIX_DATA)
850 srcoffset = decode_rm10_address(rl);
852 shiftreg = DECODE_RM_LONG_REGISTER(rh);
854 bit = *shiftreg & 0x1F;
855 disp = (s16) *shiftreg >> 5;
856 srcval = fetch_data_long(srcoffset + disp);
858 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
859 store_data_long(srcoffset + disp, srcval | mask);
866 srcoffset = decode_rm10_address(rl);
868 shiftreg = DECODE_RM_WORD_REGISTER(rh);
870 bit = *shiftreg & 0xF;
871 disp = (s16) *shiftreg >> 4;
872 srcval = fetch_data_word(srcoffset + disp);
873 mask = (u16)(0x1 << bit);
874 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
875 store_data_word(srcoffset + disp, srcval | mask);
879 if (M.x86.mode & SYSMODE_PREFIX_DATA)
881 u32 *srcreg, *shiftreg;
884 srcreg = DECODE_RM_LONG_REGISTER(rl);
886 shiftreg = DECODE_RM_LONG_REGISTER(rh);
888 bit = *shiftreg & 0x1F;
890 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
895 u16 *srcreg, *shiftreg;
898 srcreg = DECODE_RM_WORD_REGISTER(rl);
900 shiftreg = DECODE_RM_WORD_REGISTER(rh);
902 bit = *shiftreg & 0xF;
903 mask = (u16)(0x1 << bit);
904 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
909 DECODE_CLEAR_SEGOVR();
917 static void x86emuOp2_shrd_IMM(u8 X86EMU_UNUSED(op2))
924 DECODE_PRINTF(
"SHLD\t");
925 FETCH_DECODE_MODRM(mod, rh, rl);
929 if (M.x86.mode & SYSMODE_PREFIX_DATA)
934 destoffset = decode_rm00_address(rl);
936 shiftreg = DECODE_RM_LONG_REGISTER(rh);
938 shift = fetch_byte_imm();
939 DECODE_PRINTF2(
"%d\n", shift);
941 destval = fetch_data_long(destoffset);
942 destval = shrd_long(destval, *shiftreg, shift);
943 store_data_long(destoffset, destval);
950 destoffset = decode_rm00_address(rl);
952 shiftreg = DECODE_RM_WORD_REGISTER(rh);
954 shift = fetch_byte_imm();
955 DECODE_PRINTF2(
"%d\n", shift);
957 destval = fetch_data_word(destoffset);
958 destval = shrd_word(destval, *shiftreg, shift);
959 store_data_word(destoffset, destval);
963 if (M.x86.mode & SYSMODE_PREFIX_DATA)
968 destoffset = decode_rm01_address(rl);
970 shiftreg = DECODE_RM_LONG_REGISTER(rh);
972 shift = fetch_byte_imm();
973 DECODE_PRINTF2(
"%d\n", shift);
975 destval = fetch_data_long(destoffset);
976 destval = shrd_long(destval, *shiftreg, shift);
977 store_data_long(destoffset, destval);
984 destoffset = decode_rm01_address(rl);
986 shiftreg = DECODE_RM_WORD_REGISTER(rh);
988 shift = fetch_byte_imm();
989 DECODE_PRINTF2(
"%d\n", shift);
991 destval = fetch_data_word(destoffset);
992 destval = shrd_word(destval, *shiftreg, shift);
993 store_data_word(destoffset, destval);
997 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1002 destoffset = decode_rm10_address(rl);
1004 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1006 shift = fetch_byte_imm();
1007 DECODE_PRINTF2(
"%d\n", shift);
1009 destval = fetch_data_long(destoffset);
1010 destval = shrd_long(destval, *shiftreg, shift);
1011 store_data_long(destoffset, destval);
1018 destoffset = decode_rm10_address(rl);
1020 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1022 shift = fetch_byte_imm();
1023 DECODE_PRINTF2(
"%d\n", shift);
1025 destval = fetch_data_word(destoffset);
1026 destval = shrd_word(destval, *shiftreg, shift);
1027 store_data_word(destoffset, destval);
1031 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1033 u32 *destreg, *shiftreg;
1035 destreg = DECODE_RM_LONG_REGISTER(rl);
1037 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1039 shift = fetch_byte_imm();
1040 DECODE_PRINTF2(
"%d\n", shift);
1042 *destreg = shrd_long(*destreg, *shiftreg, shift);
1046 u16 *destreg, *shiftreg;
1048 destreg = DECODE_RM_WORD_REGISTER(rl);
1050 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1052 shift = fetch_byte_imm();
1053 DECODE_PRINTF2(
"%d\n", shift);
1055 *destreg = shrd_word(*destreg, *shiftreg, shift);
1059 DECODE_CLEAR_SEGOVR();
1067 static void x86emuOp2_shrd_CL(u8 X86EMU_UNUSED(op2))
1073 DECODE_PRINTF(
"SHLD\t");
1074 FETCH_DECODE_MODRM(mod, rh, rl);
1078 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1083 destoffset = decode_rm00_address(rl);
1085 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1086 DECODE_PRINTF(
",CL\n");
1088 destval = fetch_data_long(destoffset);
1089 destval = shrd_long(destval, *shiftreg, M.x86.R_CL);
1090 store_data_long(destoffset, destval);
1097 destoffset = decode_rm00_address(rl);
1099 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1100 DECODE_PRINTF(
",CL\n");
1102 destval = fetch_data_word(destoffset);
1103 destval = shrd_word(destval, *shiftreg, M.x86.R_CL);
1104 store_data_word(destoffset, destval);
1108 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1113 destoffset = decode_rm01_address(rl);
1115 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1116 DECODE_PRINTF(
",CL\n");
1118 destval = fetch_data_long(destoffset);
1119 destval = shrd_long(destval, *shiftreg, M.x86.R_CL);
1120 store_data_long(destoffset, destval);
1127 destoffset = decode_rm01_address(rl);
1129 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1130 DECODE_PRINTF(
",CL\n");
1132 destval = fetch_data_word(destoffset);
1133 destval = shrd_word(destval, *shiftreg, M.x86.R_CL);
1134 store_data_word(destoffset, destval);
1138 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1143 destoffset = decode_rm10_address(rl);
1145 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1146 DECODE_PRINTF(
",CL\n");
1148 destval = fetch_data_long(destoffset);
1149 destval = shrd_long(destval, *shiftreg, M.x86.R_CL);
1150 store_data_long(destoffset, destval);
1157 destoffset = decode_rm10_address(rl);
1159 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1160 DECODE_PRINTF(
",CL\n");
1162 destval = fetch_data_word(destoffset);
1163 destval = shrd_word(destval, *shiftreg, M.x86.R_CL);
1164 store_data_word(destoffset, destval);
1168 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1170 u32 *destreg, *shiftreg;
1172 destreg = DECODE_RM_LONG_REGISTER(rl);
1174 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1175 DECODE_PRINTF(
",CL\n");
1177 *destreg = shrd_long(*destreg, *shiftreg, M.x86.R_CL);
1181 u16 *destreg, *shiftreg;
1183 destreg = DECODE_RM_WORD_REGISTER(rl);
1185 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1186 DECODE_PRINTF(
",CL\n");
1188 *destreg = shrd_word(*destreg, *shiftreg, M.x86.R_CL);
1192 DECODE_CLEAR_SEGOVR();
1200 static void x86emuOp2_imul_R_RM(u8 X86EMU_UNUSED(op2))
1206 DECODE_PRINTF(
"IMUL\t");
1207 FETCH_DECODE_MODRM(mod, rh, rl);
1211 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1217 destreg = DECODE_RM_LONG_REGISTER(rh);
1219 srcoffset = decode_rm00_address(rl);
1220 srcval = fetch_data_long(srcoffset);
1223 &res_lo, &res_hi, (s32) *destreg, (s32) srcval);
1234 *destreg = (u32) res_lo;
1242 destreg = DECODE_RM_WORD_REGISTER(rh);
1244 srcoffset = decode_rm00_address(rl);
1245 srcval = fetch_data_word(srcoffset);
1247 res = (s16) *destreg * (s16) srcval;
1258 *destreg = (u16) res;
1262 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1268 destreg = DECODE_RM_LONG_REGISTER(rh);
1270 srcoffset = decode_rm01_address(rl);
1271 srcval = fetch_data_long(srcoffset);
1274 &res_lo, &res_hi, (s32) *destreg, (s32) srcval);
1285 *destreg = (u32) res_lo;
1293 destreg = DECODE_RM_WORD_REGISTER(rh);
1295 srcoffset = decode_rm01_address(rl);
1296 srcval = fetch_data_word(srcoffset);
1298 res = (s16) *destreg * (s16) srcval;
1309 *destreg = (u16) res;
1313 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1319 destreg = DECODE_RM_LONG_REGISTER(rh);
1321 srcoffset = decode_rm10_address(rl);
1322 srcval = fetch_data_long(srcoffset);
1325 &res_lo, &res_hi, (s32) *destreg, (s32) srcval);
1336 *destreg = (u32) res_lo;
1344 destreg = DECODE_RM_WORD_REGISTER(rh);
1346 srcoffset = decode_rm10_address(rl);
1347 srcval = fetch_data_word(srcoffset);
1349 res = (s16) *destreg * (s16) srcval;
1360 *destreg = (u16) res;
1364 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1366 u32 *destreg, *srcreg;
1369 destreg = DECODE_RM_LONG_REGISTER(rh);
1371 srcreg = DECODE_RM_LONG_REGISTER(rl);
1374 &res_lo, &res_hi, (s32) *destreg, (s32) *srcreg);
1385 *destreg = (u32) res_lo;
1389 u16 *destreg, *srcreg;
1392 destreg = DECODE_RM_WORD_REGISTER(rh);
1394 srcreg = DECODE_RM_WORD_REGISTER(rl);
1395 res = (s16) *destreg * (s16) *srcreg;
1406 *destreg = (u16) res;
1410 DECODE_CLEAR_SEGOVR();
1418 static void x86emuOp2_lss_R_IMM(u8 X86EMU_UNUSED(op2))
1425 DECODE_PRINTF(
"LSS\t");
1426 FETCH_DECODE_MODRM(mod, rh, rl);
1430 dstreg = DECODE_RM_WORD_REGISTER(rh);
1432 srcoffset = decode_rm00_address(rl);
1433 DECODE_PRINTF(
"\n");
1435 *dstreg = fetch_data_word(srcoffset);
1436 M.x86.R_SS = fetch_data_word(srcoffset + 2);
1439 dstreg = DECODE_RM_WORD_REGISTER(rh);
1441 srcoffset = decode_rm01_address(rl);
1442 DECODE_PRINTF(
"\n");
1444 *dstreg = fetch_data_word(srcoffset);
1445 M.x86.R_SS = fetch_data_word(srcoffset + 2);
1448 dstreg = DECODE_RM_WORD_REGISTER(rh);
1450 srcoffset = decode_rm10_address(rl);
1451 DECODE_PRINTF(
"\n");
1453 *dstreg = fetch_data_word(srcoffset);
1454 M.x86.R_SS = fetch_data_word(srcoffset + 2);
1460 DECODE_CLEAR_SEGOVR();
1468 static void x86emuOp2_btr_R(u8 X86EMU_UNUSED(op2))
1475 DECODE_PRINTF(
"BTR\t");
1476 FETCH_DECODE_MODRM(mod, rh, rl);
1480 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1485 srcoffset = decode_rm00_address(rl);
1487 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1489 bit = *shiftreg & 0x1F;
1490 disp = (s16) *shiftreg >> 5;
1491 srcval = fetch_data_long(srcoffset + disp);
1492 mask = (0x1 << bit);
1493 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1494 store_data_long(srcoffset + disp, srcval & ~mask);
1501 srcoffset = decode_rm00_address(rl);
1503 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1505 bit = *shiftreg & 0xF;
1506 disp = (s16) *shiftreg >> 4;
1507 srcval = fetch_data_word(srcoffset + disp);
1508 mask = (u16)(0x1 << bit);
1509 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1510 store_data_word(srcoffset + disp, (u16)(srcval & ~mask));
1514 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1519 srcoffset = decode_rm01_address(rl);
1521 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1523 bit = *shiftreg & 0x1F;
1524 disp = (s16) *shiftreg >> 5;
1525 srcval = fetch_data_long(srcoffset + disp);
1526 mask = (0x1 << bit);
1527 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1528 store_data_long(srcoffset + disp, srcval & ~mask);
1535 srcoffset = decode_rm01_address(rl);
1537 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1539 bit = *shiftreg & 0xF;
1540 disp = (s16) *shiftreg >> 4;
1541 srcval = fetch_data_word(srcoffset + disp);
1542 mask = (u16)(0x1 << bit);
1543 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1544 store_data_word(srcoffset + disp, (u16)(srcval & ~mask));
1548 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1553 srcoffset = decode_rm10_address(rl);
1555 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1557 bit = *shiftreg & 0x1F;
1558 disp = (s16) *shiftreg >> 5;
1559 srcval = fetch_data_long(srcoffset + disp);
1560 mask = (0x1 << bit);
1561 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1562 store_data_long(srcoffset + disp, srcval & ~mask);
1569 srcoffset = decode_rm10_address(rl);
1571 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1573 bit = *shiftreg & 0xF;
1574 disp = (s16) *shiftreg >> 4;
1575 srcval = fetch_data_word(srcoffset + disp);
1576 mask = (u16)(0x1 << bit);
1577 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1578 store_data_word(srcoffset + disp, (u16)(srcval & ~mask));
1582 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1584 u32 *srcreg, *shiftreg;
1587 srcreg = DECODE_RM_LONG_REGISTER(rl);
1589 shiftreg = DECODE_RM_LONG_REGISTER(rh);
1591 bit = *shiftreg & 0x1F;
1592 mask = (0x1 << bit);
1593 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
1598 u16 *srcreg, *shiftreg;
1601 srcreg = DECODE_RM_WORD_REGISTER(rl);
1603 shiftreg = DECODE_RM_WORD_REGISTER(rh);
1605 bit = *shiftreg & 0xF;
1606 mask = (u16)(0x1 << bit);
1607 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
1612 DECODE_CLEAR_SEGOVR();
1620 static void x86emuOp2_lfs_R_IMM(u8 X86EMU_UNUSED(op2))
1627 DECODE_PRINTF(
"LFS\t");
1628 FETCH_DECODE_MODRM(mod, rh, rl);
1632 dstreg = DECODE_RM_WORD_REGISTER(rh);
1634 srcoffset = decode_rm00_address(rl);
1635 DECODE_PRINTF(
"\n");
1637 *dstreg = fetch_data_word(srcoffset);
1638 M.x86.R_FS = fetch_data_word(srcoffset + 2);
1641 dstreg = DECODE_RM_WORD_REGISTER(rh);
1643 srcoffset = decode_rm01_address(rl);
1644 DECODE_PRINTF(
"\n");
1646 *dstreg = fetch_data_word(srcoffset);
1647 M.x86.R_FS = fetch_data_word(srcoffset + 2);
1650 dstreg = DECODE_RM_WORD_REGISTER(rh);
1652 srcoffset = decode_rm10_address(rl);
1653 DECODE_PRINTF(
"\n");
1655 *dstreg = fetch_data_word(srcoffset);
1656 M.x86.R_FS = fetch_data_word(srcoffset + 2);
1662 DECODE_CLEAR_SEGOVR();
1670 static void x86emuOp2_lgs_R_IMM(u8 X86EMU_UNUSED(op2))
1677 DECODE_PRINTF(
"LGS\t");
1678 FETCH_DECODE_MODRM(mod, rh, rl);
1682 dstreg = DECODE_RM_WORD_REGISTER(rh);
1684 srcoffset = decode_rm00_address(rl);
1685 DECODE_PRINTF(
"\n");
1687 *dstreg = fetch_data_word(srcoffset);
1688 M.x86.R_GS = fetch_data_word(srcoffset + 2);
1691 dstreg = DECODE_RM_WORD_REGISTER(rh);
1693 srcoffset = decode_rm01_address(rl);
1694 DECODE_PRINTF(
"\n");
1696 *dstreg = fetch_data_word(srcoffset);
1697 M.x86.R_GS = fetch_data_word(srcoffset + 2);
1700 dstreg = DECODE_RM_WORD_REGISTER(rh);
1702 srcoffset = decode_rm10_address(rl);
1703 DECODE_PRINTF(
"\n");
1705 *dstreg = fetch_data_word(srcoffset);
1706 M.x86.R_GS = fetch_data_word(srcoffset + 2);
1712 DECODE_CLEAR_SEGOVR();
1720 static void x86emuOp2_movzx_byte_R_RM(u8 X86EMU_UNUSED(op2))
1726 DECODE_PRINTF(
"MOVZX\t");
1727 FETCH_DECODE_MODRM(mod, rh, rl);
1731 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1736 destreg = DECODE_RM_LONG_REGISTER(rh);
1738 srcoffset = decode_rm00_address(rl);
1739 srcval = fetch_data_byte(srcoffset);
1740 DECODE_PRINTF(
"\n");
1749 destreg = DECODE_RM_WORD_REGISTER(rh);
1751 srcoffset = decode_rm00_address(rl);
1752 srcval = fetch_data_byte(srcoffset);
1753 DECODE_PRINTF(
"\n");
1759 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1764 destreg = DECODE_RM_LONG_REGISTER(rh);
1766 srcoffset = decode_rm01_address(rl);
1767 srcval = fetch_data_byte(srcoffset);
1768 DECODE_PRINTF(
"\n");
1777 destreg = DECODE_RM_WORD_REGISTER(rh);
1779 srcoffset = decode_rm01_address(rl);
1780 srcval = fetch_data_byte(srcoffset);
1781 DECODE_PRINTF(
"\n");
1787 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1792 destreg = DECODE_RM_LONG_REGISTER(rh);
1794 srcoffset = decode_rm10_address(rl);
1795 srcval = fetch_data_byte(srcoffset);
1796 DECODE_PRINTF(
"\n");
1805 destreg = DECODE_RM_WORD_REGISTER(rh);
1807 srcoffset = decode_rm10_address(rl);
1808 srcval = fetch_data_byte(srcoffset);
1809 DECODE_PRINTF(
"\n");
1815 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1820 destreg = DECODE_RM_LONG_REGISTER(rh);
1822 srcreg = DECODE_RM_BYTE_REGISTER(rl);
1823 DECODE_PRINTF(
"\n");
1832 destreg = DECODE_RM_WORD_REGISTER(rh);
1834 srcreg = DECODE_RM_BYTE_REGISTER(rl);
1835 DECODE_PRINTF(
"\n");
1841 DECODE_CLEAR_SEGOVR();
1849 static void x86emuOp2_movzx_word_R_RM(u8 X86EMU_UNUSED(op2))
1858 DECODE_PRINTF(
"MOVZX\t");
1859 FETCH_DECODE_MODRM(mod, rh, rl);
1863 destreg = DECODE_RM_LONG_REGISTER(rh);
1865 srcoffset = decode_rm00_address(rl);
1866 srcval = fetch_data_word(srcoffset);
1867 DECODE_PRINTF(
"\n");
1872 destreg = DECODE_RM_LONG_REGISTER(rh);
1874 srcoffset = decode_rm01_address(rl);
1875 srcval = fetch_data_word(srcoffset);
1876 DECODE_PRINTF(
"\n");
1881 destreg = DECODE_RM_LONG_REGISTER(rh);
1883 srcoffset = decode_rm10_address(rl);
1884 srcval = fetch_data_word(srcoffset);
1885 DECODE_PRINTF(
"\n");
1890 destreg = DECODE_RM_LONG_REGISTER(rh);
1892 srcreg = DECODE_RM_WORD_REGISTER(rl);
1893 DECODE_PRINTF(
"\n");
1898 DECODE_CLEAR_SEGOVR();
1906 static void x86emuOp2_btX_I(u8 X86EMU_UNUSED(op2))
1913 FETCH_DECODE_MODRM(mod, rh, rl);
1917 DECODE_PRINTF(
"BT\t");
1920 DECODE_PRINTF(
"BTS\t");
1923 DECODE_PRINTF(
"BTR\t");
1926 DECODE_PRINTF(
"BTC\t");
1929 DECODE_PRINTF(
"ILLEGAL EXTENDED X86 OPCODE\n");
1932 "%04x:%04x: %02X%02X ILLEGAL EXTENDED X86 OPCODE EXTENSION!\n",
1933 M.x86.R_CS, M.x86.R_IP - 3, op2, (mod << 6) | (rh << 3) | rl);
1939 if (M.x86.mode & SYSMODE_PREFIX_DATA)
1944 srcoffset = decode_rm00_address(rl);
1946 shift = fetch_byte_imm();
1949 srcval = fetch_data_long(srcoffset);
1950 mask = (0x1 << bit);
1951 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1955 store_data_long(srcoffset, srcval | mask);
1958 store_data_long(srcoffset, srcval & ~mask);
1961 store_data_long(srcoffset, srcval ^ mask);
1972 srcoffset = decode_rm00_address(rl);
1974 shift = fetch_byte_imm();
1977 srcval = fetch_data_word(srcoffset);
1978 mask = (0x1 << bit);
1979 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
1983 store_data_word(srcoffset, srcval | mask);
1986 store_data_word(srcoffset, srcval & ~mask);
1989 store_data_word(srcoffset, srcval ^ mask);
1997 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2002 srcoffset = decode_rm01_address(rl);
2004 shift = fetch_byte_imm();
2007 srcval = fetch_data_long(srcoffset);
2008 mask = (0x1 << bit);
2009 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2013 store_data_long(srcoffset, srcval | mask);
2016 store_data_long(srcoffset, srcval & ~mask);
2019 store_data_long(srcoffset, srcval ^ mask);
2030 srcoffset = decode_rm01_address(rl);
2032 shift = fetch_byte_imm();
2035 srcval = fetch_data_word(srcoffset);
2036 mask = (0x1 << bit);
2037 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2041 store_data_word(srcoffset, srcval | mask);
2044 store_data_word(srcoffset, srcval & ~mask);
2047 store_data_word(srcoffset, srcval ^ mask);
2055 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2060 srcoffset = decode_rm10_address(rl);
2062 shift = fetch_byte_imm();
2065 srcval = fetch_data_long(srcoffset);
2066 mask = (0x1 << bit);
2067 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2071 store_data_long(srcoffset, srcval | mask);
2074 store_data_long(srcoffset, srcval & ~mask);
2077 store_data_long(srcoffset, srcval ^ mask);
2088 srcoffset = decode_rm10_address(rl);
2090 shift = fetch_byte_imm();
2093 srcval = fetch_data_word(srcoffset);
2094 mask = (0x1 << bit);
2095 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2099 store_data_word(srcoffset, srcval | mask);
2102 store_data_word(srcoffset, srcval & ~mask);
2105 store_data_word(srcoffset, srcval ^ mask);
2113 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2119 srcreg = DECODE_RM_LONG_REGISTER(rl);
2121 shift = fetch_byte_imm();
2124 mask = (0x1 << bit);
2125 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
2147 srcreg = DECODE_RM_WORD_REGISTER(rl);
2149 shift = fetch_byte_imm();
2152 mask = (0x1 << bit);
2153 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
2171 DECODE_CLEAR_SEGOVR();
2179 static void x86emuOp2_btc_R(u8 X86EMU_UNUSED(op2))
2186 DECODE_PRINTF(
"BTC\t");
2187 FETCH_DECODE_MODRM(mod, rh, rl);
2191 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2196 srcoffset = decode_rm00_address(rl);
2198 shiftreg = DECODE_RM_LONG_REGISTER(rh);
2200 bit = *shiftreg & 0x1F;
2201 disp = (s16) *shiftreg >> 5;
2202 srcval = fetch_data_long(srcoffset + disp);
2203 mask = (0x1 << bit);
2204 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2205 store_data_long(srcoffset + disp, srcval ^ mask);
2212 srcoffset = decode_rm00_address(rl);
2214 shiftreg = DECODE_RM_WORD_REGISTER(rh);
2216 bit = *shiftreg & 0xF;
2217 disp = (s16) *shiftreg >> 4;
2218 srcval = fetch_data_word(srcoffset + disp);
2219 mask = (u16)(0x1 << bit);
2220 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2221 store_data_word(srcoffset + disp, (u16)(srcval ^ mask));
2225 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2230 srcoffset = decode_rm01_address(rl);
2232 shiftreg = DECODE_RM_LONG_REGISTER(rh);
2234 bit = *shiftreg & 0x1F;
2235 disp = (s16) *shiftreg >> 5;
2236 srcval = fetch_data_long(srcoffset + disp);
2237 mask = (0x1 << bit);
2238 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2239 store_data_long(srcoffset + disp, srcval ^ mask);
2246 srcoffset = decode_rm01_address(rl);
2248 shiftreg = DECODE_RM_WORD_REGISTER(rh);
2250 bit = *shiftreg & 0xF;
2251 disp = (s16) *shiftreg >> 4;
2252 srcval = fetch_data_word(srcoffset + disp);
2253 mask = (u16)(0x1 << bit);
2254 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2255 store_data_word(srcoffset + disp, (u16)(srcval ^ mask));
2259 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2264 srcoffset = decode_rm10_address(rl);
2266 shiftreg = DECODE_RM_LONG_REGISTER(rh);
2268 bit = *shiftreg & 0x1F;
2269 disp = (s16) *shiftreg >> 5;
2270 srcval = fetch_data_long(srcoffset + disp);
2271 mask = (0x1 << bit);
2272 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2273 store_data_long(srcoffset + disp, srcval ^ mask);
2280 srcoffset = decode_rm10_address(rl);
2282 shiftreg = DECODE_RM_WORD_REGISTER(rh);
2284 bit = *shiftreg & 0xF;
2285 disp = (s16) *shiftreg >> 4;
2286 srcval = fetch_data_word(srcoffset + disp);
2287 mask = (u16)(0x1 << bit);
2288 CONDITIONAL_SET_FLAG(srcval & mask, F_CF);
2289 store_data_word(srcoffset + disp, (u16)(srcval ^ mask));
2293 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2295 u32 *srcreg, *shiftreg;
2298 srcreg = DECODE_RM_LONG_REGISTER(rl);
2300 shiftreg = DECODE_RM_LONG_REGISTER(rh);
2302 bit = *shiftreg & 0x1F;
2303 mask = (0x1 << bit);
2304 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
2309 u16 *srcreg, *shiftreg;
2312 srcreg = DECODE_RM_WORD_REGISTER(rl);
2314 shiftreg = DECODE_RM_WORD_REGISTER(rh);
2316 bit = *shiftreg & 0xF;
2317 mask = (u16)(0x1 << bit);
2318 CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF);
2323 DECODE_CLEAR_SEGOVR();
2331 static void x86emuOp2_bsf(u8 X86EMU_UNUSED(op2))
2337 DECODE_PRINTF(
"BSF\t");
2338 FETCH_DECODE_MODRM(mod, rh, rl);
2342 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2344 u32 srcval, *dstreg;
2346 srcoffset = decode_rm00_address(rl);
2348 dstreg = DECODE_RM_LONG_REGISTER(rh);
2350 srcval = fetch_data_long(srcoffset);
2351 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2352 for (*dstreg = 0; *dstreg < 32; (*dstreg)++)
2353 if ((srcval >> *dstreg) & 1)
2358 u16 srcval, *dstreg;
2360 srcoffset = decode_rm00_address(rl);
2362 dstreg = DECODE_RM_WORD_REGISTER(rh);
2364 srcval = fetch_data_word(srcoffset);
2365 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2366 for (*dstreg = 0; *dstreg < 16; (*dstreg)++)
2367 if ((srcval >> *dstreg) & 1)
2372 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2374 u32 srcval, *dstreg;
2376 srcoffset = decode_rm01_address(rl);
2378 dstreg = DECODE_RM_LONG_REGISTER(rh);
2380 srcval = fetch_data_long(srcoffset);
2381 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2382 for (*dstreg = 0; *dstreg < 32; (*dstreg)++)
2383 if ((srcval >> *dstreg) & 1)
2388 u16 srcval, *dstreg;
2390 srcoffset = decode_rm01_address(rl);
2392 dstreg = DECODE_RM_WORD_REGISTER(rh);
2394 srcval = fetch_data_word(srcoffset);
2395 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2396 for (*dstreg = 0; *dstreg < 16; (*dstreg)++)
2397 if ((srcval >> *dstreg) & 1)
2402 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2404 u32 srcval, *dstreg;
2406 srcoffset = decode_rm10_address(rl);
2408 dstreg = DECODE_RM_LONG_REGISTER(rh);
2410 srcval = fetch_data_long(srcoffset);
2411 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2412 for (*dstreg = 0; *dstreg < 32; (*dstreg)++)
2413 if ((srcval >> *dstreg) & 1)
2418 u16 srcval, *dstreg;
2420 srcoffset = decode_rm10_address(rl);
2422 dstreg = DECODE_RM_WORD_REGISTER(rh);
2424 srcval = fetch_data_word(srcoffset);
2425 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2426 for (*dstreg = 0; *dstreg < 16; (*dstreg)++)
2427 if ((srcval >> *dstreg) & 1)
2432 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2434 u32 srcval, *dstreg;
2436 srcval = *DECODE_RM_LONG_REGISTER(rl);
2438 dstreg = DECODE_RM_LONG_REGISTER(rh);
2440 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2441 for (*dstreg = 0; *dstreg < 32; (*dstreg)++)
2442 if ((srcval >> *dstreg) & 1)
2447 u16 srcval, *dstreg;
2449 srcval = *DECODE_RM_WORD_REGISTER(rl);
2451 dstreg = DECODE_RM_WORD_REGISTER(rh);
2453 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2454 for (*dstreg = 0; *dstreg < 16; (*dstreg)++)
2455 if ((srcval >> *dstreg) & 1)
2460 DECODE_CLEAR_SEGOVR();
2468 static void x86emuOp2_bsr(u8 X86EMU_UNUSED(op2))
2474 DECODE_PRINTF(
"BSR\t");
2475 FETCH_DECODE_MODRM(mod, rh, rl);
2479 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2481 u32 srcval, *dstreg;
2483 srcoffset = decode_rm00_address(rl);
2485 dstreg = DECODE_RM_LONG_REGISTER(rh);
2487 srcval = fetch_data_long(srcoffset);
2488 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2489 for (*dstreg = 31; *dstreg > 0; (*dstreg)--)
2490 if ((srcval >> *dstreg) & 1)
2495 u16 srcval, *dstreg;
2497 srcoffset = decode_rm00_address(rl);
2499 dstreg = DECODE_RM_WORD_REGISTER(rh);
2501 srcval = fetch_data_word(srcoffset);
2502 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2503 for (*dstreg = 15; *dstreg > 0; (*dstreg)--)
2504 if ((srcval >> *dstreg) & 1)
2509 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2511 u32 srcval, *dstreg;
2513 srcoffset = decode_rm01_address(rl);
2515 dstreg = DECODE_RM_LONG_REGISTER(rh);
2517 srcval = fetch_data_long(srcoffset);
2518 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2519 for (*dstreg = 31; *dstreg > 0; (*dstreg)--)
2520 if ((srcval >> *dstreg) & 1)
2525 u16 srcval, *dstreg;
2527 srcoffset = decode_rm01_address(rl);
2529 dstreg = DECODE_RM_WORD_REGISTER(rh);
2531 srcval = fetch_data_word(srcoffset);
2532 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2533 for (*dstreg = 15; *dstreg > 0; (*dstreg)--)
2534 if ((srcval >> *dstreg) & 1)
2539 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2541 u32 srcval, *dstreg;
2543 srcoffset = decode_rm10_address(rl);
2545 dstreg = DECODE_RM_LONG_REGISTER(rh);
2547 srcval = fetch_data_long(srcoffset);
2548 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2549 for (*dstreg = 31; *dstreg > 0; (*dstreg)--)
2550 if ((srcval >> *dstreg) & 1)
2555 u16 srcval, *dstreg;
2557 srcoffset = decode_rm10_address(rl);
2559 dstreg = DECODE_RM_WORD_REGISTER(rh);
2561 srcval = fetch_data_word(srcoffset);
2562 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2563 for (*dstreg = 15; *dstreg > 0; (*dstreg)--)
2564 if ((srcval >> *dstreg) & 1)
2569 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2571 u32 srcval, *dstreg;
2573 srcval = *DECODE_RM_LONG_REGISTER(rl);
2575 dstreg = DECODE_RM_LONG_REGISTER(rh);
2577 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2578 for (*dstreg = 31; *dstreg > 0; (*dstreg)--)
2579 if ((srcval >> *dstreg) & 1)
2584 u16 srcval, *dstreg;
2586 srcval = *DECODE_RM_WORD_REGISTER(rl);
2588 dstreg = DECODE_RM_WORD_REGISTER(rh);
2590 CONDITIONAL_SET_FLAG(srcval == 0, F_ZF);
2591 for (*dstreg = 15; *dstreg > 0; (*dstreg)--)
2592 if ((srcval >> *dstreg) & 1)
2597 DECODE_CLEAR_SEGOVR();
2605 static void x86emuOp2_movsx_byte_R_RM(u8 X86EMU_UNUSED(op2))
2611 DECODE_PRINTF(
"MOVSX\t");
2612 FETCH_DECODE_MODRM(mod, rh, rl);
2616 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2621 destreg = DECODE_RM_LONG_REGISTER(rh);
2623 srcoffset = decode_rm00_address(rl);
2624 srcval = (s32)((s8) fetch_data_byte(srcoffset));
2625 DECODE_PRINTF(
"\n");
2634 destreg = DECODE_RM_WORD_REGISTER(rh);
2636 srcoffset = decode_rm00_address(rl);
2637 srcval = (s16)((s8) fetch_data_byte(srcoffset));
2638 DECODE_PRINTF(
"\n");
2644 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2649 destreg = DECODE_RM_LONG_REGISTER(rh);
2651 srcoffset = decode_rm01_address(rl);
2652 srcval = (s32)((s8) fetch_data_byte(srcoffset));
2653 DECODE_PRINTF(
"\n");
2662 destreg = DECODE_RM_WORD_REGISTER(rh);
2664 srcoffset = decode_rm01_address(rl);
2665 srcval = (s16)((s8) fetch_data_byte(srcoffset));
2666 DECODE_PRINTF(
"\n");
2672 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2677 destreg = DECODE_RM_LONG_REGISTER(rh);
2679 srcoffset = decode_rm10_address(rl);
2680 srcval = (s32)((s8) fetch_data_byte(srcoffset));
2681 DECODE_PRINTF(
"\n");
2690 destreg = DECODE_RM_WORD_REGISTER(rh);
2692 srcoffset = decode_rm10_address(rl);
2693 srcval = (s16)((s8) fetch_data_byte(srcoffset));
2694 DECODE_PRINTF(
"\n");
2700 if (M.x86.mode & SYSMODE_PREFIX_DATA)
2705 destreg = DECODE_RM_LONG_REGISTER(rh);
2707 srcreg = DECODE_RM_BYTE_REGISTER(rl);
2708 DECODE_PRINTF(
"\n");
2710 *destreg = (s32)((s8) *srcreg);
2717 destreg = DECODE_RM_WORD_REGISTER(rh);
2719 srcreg = DECODE_RM_BYTE_REGISTER(rl);
2720 DECODE_PRINTF(
"\n");
2722 *destreg = (s16)((s8) *srcreg);
2726 DECODE_CLEAR_SEGOVR();
2734 static void x86emuOp2_movsx_word_R_RM(u8 X86EMU_UNUSED(op2))
2743 DECODE_PRINTF(
"MOVSX\t");
2744 FETCH_DECODE_MODRM(mod, rh, rl);
2748 destreg = DECODE_RM_LONG_REGISTER(rh);
2750 srcoffset = decode_rm00_address(rl);
2751 srcval = (s32)((s16) fetch_data_word(srcoffset));
2752 DECODE_PRINTF(
"\n");
2757 destreg = DECODE_RM_LONG_REGISTER(rh);
2759 srcoffset = decode_rm01_address(rl);
2760 srcval = (s32)((s16) fetch_data_word(srcoffset));
2761 DECODE_PRINTF(
"\n");
2766 destreg = DECODE_RM_LONG_REGISTER(rh);
2768 srcoffset = decode_rm10_address(rl);
2769 srcval = (s32)((s16) fetch_data_word(srcoffset));
2770 DECODE_PRINTF(
"\n");
2775 destreg = DECODE_RM_LONG_REGISTER(rh);
2777 srcreg = DECODE_RM_WORD_REGISTER(rl);
2778 DECODE_PRINTF(
"\n");
2780 *destreg = (s32)((s16) *srcreg);
2783 DECODE_CLEAR_SEGOVR();
2790 void (*x86emu_optab2[256])(u8) = {
2791 x86emuOp2_illegal_op,
2792 x86emuOp2_illegal_op,
2793 x86emuOp2_illegal_op,
2794 x86emuOp2_illegal_op,
2795 x86emuOp2_illegal_op,
2796 x86emuOp2_illegal_op,
2797 x86emuOp2_illegal_op,
2798 x86emuOp2_illegal_op,
2799 x86emuOp2_illegal_op,
2800 x86emuOp2_illegal_op,
2801 x86emuOp2_illegal_op,
2802 x86emuOp2_illegal_op,
2803 x86emuOp2_illegal_op,
2804 x86emuOp2_illegal_op,
2805 x86emuOp2_illegal_op,
2806 x86emuOp2_illegal_op,
2808 x86emuOp2_illegal_op,
2809 x86emuOp2_illegal_op,
2810 x86emuOp2_illegal_op,
2811 x86emuOp2_illegal_op,
2812 x86emuOp2_illegal_op,
2813 x86emuOp2_illegal_op,
2814 x86emuOp2_illegal_op,
2815 x86emuOp2_illegal_op,
2816 x86emuOp2_illegal_op,
2817 x86emuOp2_illegal_op,
2818 x86emuOp2_illegal_op,
2819 x86emuOp2_illegal_op,
2820 x86emuOp2_illegal_op,
2821 x86emuOp2_illegal_op,
2822 x86emuOp2_illegal_op,
2823 x86emuOp2_illegal_op,
2825 x86emuOp2_illegal_op,
2826 x86emuOp2_illegal_op,
2827 x86emuOp2_illegal_op,
2828 x86emuOp2_illegal_op,
2829 x86emuOp2_illegal_op,
2830 x86emuOp2_illegal_op,
2831 x86emuOp2_illegal_op,
2832 x86emuOp2_illegal_op,
2833 x86emuOp2_illegal_op,
2834 x86emuOp2_illegal_op,
2835 x86emuOp2_illegal_op,
2836 x86emuOp2_illegal_op,
2837 x86emuOp2_illegal_op,
2838 x86emuOp2_illegal_op,
2839 x86emuOp2_illegal_op,
2840 x86emuOp2_illegal_op,
2842 x86emuOp2_illegal_op,
2844 x86emuOp2_illegal_op,
2845 x86emuOp2_illegal_op,
2846 x86emuOp2_illegal_op,
2847 x86emuOp2_illegal_op,
2848 x86emuOp2_illegal_op,
2849 x86emuOp2_illegal_op,
2850 x86emuOp2_illegal_op,
2851 x86emuOp2_illegal_op,
2852 x86emuOp2_illegal_op,
2853 x86emuOp2_illegal_op,
2854 x86emuOp2_illegal_op,
2855 x86emuOp2_illegal_op,
2856 x86emuOp2_illegal_op,
2857 x86emuOp2_illegal_op,
2859 x86emuOp2_illegal_op,
2860 x86emuOp2_illegal_op,
2861 x86emuOp2_illegal_op,
2862 x86emuOp2_illegal_op,
2863 x86emuOp2_illegal_op,
2864 x86emuOp2_illegal_op,
2865 x86emuOp2_illegal_op,
2866 x86emuOp2_illegal_op,
2867 x86emuOp2_illegal_op,
2868 x86emuOp2_illegal_op,
2869 x86emuOp2_illegal_op,
2870 x86emuOp2_illegal_op,
2871 x86emuOp2_illegal_op,
2872 x86emuOp2_illegal_op,
2873 x86emuOp2_illegal_op,
2874 x86emuOp2_illegal_op,
2876 x86emuOp2_illegal_op,
2877 x86emuOp2_illegal_op,
2878 x86emuOp2_illegal_op,
2879 x86emuOp2_illegal_op,
2880 x86emuOp2_illegal_op,
2881 x86emuOp2_illegal_op,
2882 x86emuOp2_illegal_op,
2883 x86emuOp2_illegal_op,
2884 x86emuOp2_illegal_op,
2885 x86emuOp2_illegal_op,
2886 x86emuOp2_illegal_op,
2887 x86emuOp2_illegal_op,
2888 x86emuOp2_illegal_op,
2889 x86emuOp2_illegal_op,
2890 x86emuOp2_illegal_op,
2891 x86emuOp2_illegal_op,
2893 x86emuOp2_illegal_op,
2894 x86emuOp2_illegal_op,
2895 x86emuOp2_illegal_op,
2896 x86emuOp2_illegal_op,
2897 x86emuOp2_illegal_op,
2898 x86emuOp2_illegal_op,
2899 x86emuOp2_illegal_op,
2900 x86emuOp2_illegal_op,
2901 x86emuOp2_illegal_op,
2902 x86emuOp2_illegal_op,
2903 x86emuOp2_illegal_op,
2904 x86emuOp2_illegal_op,
2905 x86emuOp2_illegal_op,
2906 x86emuOp2_illegal_op,
2907 x86emuOp2_illegal_op,
2908 x86emuOp2_illegal_op,
2910 x86emuOp2_illegal_op,
2911 x86emuOp2_illegal_op,
2912 x86emuOp2_illegal_op,
2913 x86emuOp2_illegal_op,
2914 x86emuOp2_illegal_op,
2915 x86emuOp2_illegal_op,
2916 x86emuOp2_illegal_op,
2917 x86emuOp2_illegal_op,
2918 x86emuOp2_illegal_op,
2919 x86emuOp2_illegal_op,
2920 x86emuOp2_illegal_op,
2921 x86emuOp2_illegal_op,
2922 x86emuOp2_illegal_op,
2923 x86emuOp2_illegal_op,
2924 x86emuOp2_illegal_op,
2925 x86emuOp2_illegal_op,
2927 x86emuOp2_long_jump,
2928 x86emuOp2_long_jump,
2929 x86emuOp2_long_jump,
2930 x86emuOp2_long_jump,
2931 x86emuOp2_long_jump,
2932 x86emuOp2_long_jump,
2933 x86emuOp2_long_jump,
2934 x86emuOp2_long_jump,
2935 x86emuOp2_long_jump,
2936 x86emuOp2_long_jump,
2937 x86emuOp2_long_jump,
2938 x86emuOp2_long_jump,
2939 x86emuOp2_long_jump,
2940 x86emuOp2_long_jump,
2941 x86emuOp2_long_jump,
2942 x86emuOp2_long_jump,
2963 x86emuOp2_illegal_op,
2967 x86emuOp2_illegal_op,
2968 x86emuOp2_illegal_op,
2971 x86emuOp2_illegal_op,
2975 x86emuOp2_illegal_op,
2976 x86emuOp2_imul_R_RM,
2978 x86emuOp2_illegal_op,
2979 x86emuOp2_illegal_op,
2980 x86emuOp2_lss_R_IMM,
2982 x86emuOp2_lfs_R_IMM,
2983 x86emuOp2_lgs_R_IMM,
2984 x86emuOp2_movzx_byte_R_RM,
2985 x86emuOp2_movzx_word_R_RM,
2986 x86emuOp2_illegal_op,
2987 x86emuOp2_illegal_op,
2992 x86emuOp2_movsx_byte_R_RM,
2993 x86emuOp2_movsx_word_R_RM,
2995 x86emuOp2_illegal_op,
2996 x86emuOp2_illegal_op,
2997 x86emuOp2_illegal_op,
2998 x86emuOp2_illegal_op,
2999 x86emuOp2_illegal_op,
3000 x86emuOp2_illegal_op,
3001 x86emuOp2_illegal_op,
3002 x86emuOp2_illegal_op,
3003 x86emuOp2_illegal_op,
3004 x86emuOp2_illegal_op,
3005 x86emuOp2_illegal_op,
3006 x86emuOp2_illegal_op,
3007 x86emuOp2_illegal_op,
3008 x86emuOp2_illegal_op,
3009 x86emuOp2_illegal_op,
3010 x86emuOp2_illegal_op,
3012 x86emuOp2_illegal_op,
3013 x86emuOp2_illegal_op,
3014 x86emuOp2_illegal_op,
3015 x86emuOp2_illegal_op,
3016 x86emuOp2_illegal_op,
3017 x86emuOp2_illegal_op,
3018 x86emuOp2_illegal_op,
3019 x86emuOp2_illegal_op,
3020 x86emuOp2_illegal_op,
3021 x86emuOp2_illegal_op,
3022 x86emuOp2_illegal_op,
3023 x86emuOp2_illegal_op,
3024 x86emuOp2_illegal_op,
3025 x86emuOp2_illegal_op,
3026 x86emuOp2_illegal_op,
3027 x86emuOp2_illegal_op,
3029 x86emuOp2_illegal_op,
3030 x86emuOp2_illegal_op,
3031 x86emuOp2_illegal_op,
3032 x86emuOp2_illegal_op,
3033 x86emuOp2_illegal_op,
3034 x86emuOp2_illegal_op,
3035 x86emuOp2_illegal_op,
3036 x86emuOp2_illegal_op,
3037 x86emuOp2_illegal_op,
3038 x86emuOp2_illegal_op,
3039 x86emuOp2_illegal_op,
3040 x86emuOp2_illegal_op,
3041 x86emuOp2_illegal_op,
3042 x86emuOp2_illegal_op,
3043 x86emuOp2_illegal_op,
3044 x86emuOp2_illegal_op,
3046 x86emuOp2_illegal_op,
3047 x86emuOp2_illegal_op,
3048 x86emuOp2_illegal_op,
3049 x86emuOp2_illegal_op,
3050 x86emuOp2_illegal_op,
3051 x86emuOp2_illegal_op,
3052 x86emuOp2_illegal_op,
3053 x86emuOp2_illegal_op,
3054 x86emuOp2_illegal_op,
3055 x86emuOp2_illegal_op,
3056 x86emuOp2_illegal_op,
3057 x86emuOp2_illegal_op,
3058 x86emuOp2_illegal_op,
3059 x86emuOp2_illegal_op,
3060 x86emuOp2_illegal_op,
3061 x86emuOp2_illegal_op,