1 /* r8c.opc --- semantics for r8c opcodes. -*- mode: c -*-
3 Copyright (C) 2005 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 The GNU simulators are free software; you can redistribute them and/or
9 modify them under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The GNU simulators are distributed in the hope that they will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the GNU simulators; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32 #define AU __attribute__((unused))
34 #define tprintf if (trace) printf
50 #define M16C_ONLY() /* FIXME: add something here */
52 #define GETBYTE() (op[opi++] = getbyte())
54 #define UNSUPPORTED() unsupported("unsupported", orig_pc)
55 #define NOTYET() unsupported("unimplemented", orig_pc)
58 unsupported (char *tag, int orig_pc)
61 printf("%s opcode at %08x\n", tag, orig_pc);
66 printf(" %s", bits(b>>4, 4));
67 printf(" %s", bits(b, 4));
74 printf(" %02x", mem_get_pc ());
86 rv = rv + 256 * getbyte();
88 rv = rv + 65536 * getbyte();
92 #define IMM4() (immm >= 8 ? 7 - immm : immm + 1)
95 dc = decode_srcdest4 (dest, w); \
96 v = sign_ext (get_src (dc), w?16:8);
99 dc = decode_srcdest4 (dest, w); \
103 sc = decode_srcdest4 (srcx, w); \
104 dc = decode_srcdest4 (dest, w); \
105 a = sign_ext (get_src (sc), w?16:8); \
106 b = sign_ext (get_src (dc), w?16:8);
109 sc = decode_srcdest4 (srcx, w); \
110 dc = decode_srcdest4 (dest, w); \
114 #define carry (FLAG_C ? 1 : 0)
117 cmp (int d, int s, int w)
120 int mask = w ? 0xffff : 0xff;
122 b = sign_ext (d, w?16:8) - sign_ext (s, w?16:8);
123 tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
125 sign_ext(d,w?16:8), sign_ext(s,w?16:8), b);
129 if (b & (w ? 0x8000 : 0x80))
131 if ((d & mask) >= (s & mask))
133 if (b < (w ? -32768 : -128) || b > (w ? 32767 : 127))
136 set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
140 div_op (int s, int u, int x, int w)
149 sc = decode_srcdest4 (s, w);
153 v = get_reg (w ? r2r0 : r0);
157 s = sign_ext (s, w ? 16 : 8);
158 v = sign_ext (v, w ? 16 : 8);
163 set_flags (FLAGBIT_O, FLAGBIT_O);
169 a = (unsigned int)v / (unsigned int)s;
170 b = (unsigned int)v % (unsigned int)s;
186 tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
187 if ((!u && (a > (w ? 32767 : 127)
188 || a < (w ? -32768 : -129)))
189 || (u && (a > (w ? 65536 : 255))))
190 set_flags (FLAGBIT_O, FLAGBIT_O);
192 set_flags (FLAGBIT_O, 0);
194 put_reg (w ? r0 : r0l, a);
195 put_reg (w ? r2 : r0h, b);
199 rot_op (srcdest sd, int rotc, int count)
201 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
202 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
203 int v = get_src (sd);
206 tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
207 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
210 ct = (v & msb) ? 1 : 0;
215 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
222 v |= (rotc ? c : ct) * msb;
224 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
228 set_szc (v, sd.bytes, c);
232 shift_op (srcdest sd, int arith, int count)
234 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
235 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
236 int v = get_src (sd);
243 if (count > 16 || count < -16)
245 fprintf(stderr, "Error: SI shift of %d undefined\n", count);
249 count = (count - 1) % 16 + 1;
251 count = -((-count - 1) % 16 + 1);
254 tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
255 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
258 c = (v & msb) ? 1 : 0;
261 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
268 v = (v & msb) | (v >> 1);
270 v = (v >> 1) & (msb - 1);
271 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
275 set_szc (v, sd.bytes, c);
278 #define MATH_OP(dc,s,c,op,carryrel) \
280 b = s & b2mask[dc.bytes]; \
282 tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%x\n", a, b, c, v2); \
283 a = sign_ext (a, dc.bytes * 8); \
284 b = sign_ext (s, dc.bytes * 8); \
286 tprintf("%d " #op " %d " #op " %d = %d\n", a, b, c, v); \
287 set_oszc (v, dc.bytes, v2 carryrel); \
290 #define BIT_OP(field,expr) \
291 dc = decode_bit (field); \
294 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
297 #define BIT_OPC(field,expr) \
298 dc = decode_bit (field); \
301 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
304 /* The "BMcnd dest" opcode uses a different encoding for the */
305 /* condition than other opcodes. */
306 static int bmcnd_cond_map[] = {
307 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15
313 unsigned char op[40];
316 int orig_pc = get_reg (pc);
320 step_result = M32C_MAKE_STEPPED ();
322 tprintf("trace: decode pc = %05x\n", orig_pc);
324 /** VARY dst 011 100 101 110 111 */
326 /** 0111 011w 1111 dest ABS.size dest */
330 tprintf("abs(%d) = %d\n", v, a);
334 /** 0111 011w 0110 dest ADC.size #IMM,dest */
336 dc = decode_srcdest4(dest, w);
338 MATH_OP (dc, imm, carry, +, > (w?0xffff:0xff));
340 /** 1011 000w srcx dest ADC.size src,dest */
342 sc = decode_srcdest4(srcx, w);
343 dc = decode_srcdest4(dest, w);
345 MATH_OP (dc, b, carry, +, > (w?0xffff:0xff));
347 /** 0111 011w 1110 dest ADCF.size dest */
349 dc = decode_srcdest4(dest, w);
350 MATH_OP (dc, 0, carry, +, > (w?0xffff:0xff));
352 /** 0111 011w 0100 dest ADD.size:G #imm,dest */
354 dc = decode_srcdest4(dest, w);
356 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
358 /** 1100 100w immm dest ADD.size:Q #IMM,dest */
360 dc = decode_srcdest4(dest, w);
361 imm = sign_ext (immm, 4);
362 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
364 /** 1000 0dst ADD.B:S #IMM8,dst */
367 dc = decode_dest3 (dst, 0);
368 MATH_OP (dc, imm, 0, +, > 0xff);
370 /** 1010 000w srcx dest ADD.size:G src,dest */
372 sc = decode_srcdest4(srcx, w);
373 dc = decode_srcdest4(dest, w);
375 MATH_OP (dc, b, 0, +, > (w?0xffff:0xff));
377 /** 0010 0d sr ADD.B:S src,R0L/R0H */
379 sc = decode_src2 (sr, 0, d);
380 dc = decode_dest1 (d, 0);
382 MATH_OP (dc, b, 0, +, > 0xff);
384 /** 0111 110w 1110 1011 ADD.size:G #IMM,sp */
387 imm = sign_ext (IMM(w), w?16:8);
388 MATH_OP (dc, imm, 0, +, > 0xffff);
390 /** 0111 1101 1011 immm ADD.size:Q #IMM,sp */
393 imm = sign_ext (immm, 4);
394 MATH_OP (dc, imm, 0, +, > 0xffff);
396 /** 1111 100w immm dest ADJNZ.size #IMM,dest,label */
399 imm = sign_ext(immm, 4);
400 tprintf("%x + %d = %x\n", v, imm, v+imm);
403 a = sign_ext (IMM(0), 8);
404 if ((v & (w ? 0xffff : 0xff)) != 0)
406 tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
407 put_reg (pc, orig_pc + 2 + a);
408 tprintf("%x\n", get_reg (pc));
411 /** 0111 011w 0010 dest AND.size:G #IMM,dest */
415 tprintf ("%x & %x = %x\n", v, imm, v & imm);
420 /** 1001 0dst AND.B:S #IMM8,dest */
423 dc = decode_dest3 (dst, 0);
425 tprintf("%x & %x = %x\n", v, imm, v & imm);
430 /** 1001 000w srcx dest AND.size:G src.dest */
433 tprintf ("%x & %x = %x\n", a, b, a & b);
438 /** 0001 0d sr AND.B:S src,R0L/R0H */
440 sc = decode_src2 (sr, 0, d);
441 dc = decode_dest1 (d, 0);
445 tprintf("%x & %x = %x\n", a, b, v);
449 /** 0111 1110 0100 srcx BAND src */
451 BIT_OPC (srcx, b & carry);
453 /** 0111 1110 1000 dest BCLR:G dest */
455 dc = decode_bit (dest);
458 /** 0100 0bit BCLR:S bit,base:11[SB] */
460 dc = decode_bit11 (bit);
463 /** 0111 1110 0010 dest BMcnd dest */
465 dc = decode_bit (dest);
466 if (condition_true (bmcnd_cond_map [IMM (0) & 15]))
471 /** 0111 1101 1101 cond BMcnd C */
473 if (condition_true (cond))
478 /** 0111 1110 0101 srcx BNAND src */
480 BIT_OPC (srcx, !b & carry);
482 /** 0111 1110 0111 srcx BNOR src */
484 BIT_OPC (srcx, !b | carry);
486 /** 0111 1110 1010 dest BNOT:G dest */
490 /** 0101 0bit BNOT:S bit,base:11[SB] */
492 dc = decode_bit11 (bit);
493 put_bit (dc, !get_bit (dc));
495 /** 0111 1110 0011 srcx BNTST src */
497 dc = decode_bit (srcx);
501 /** 0111 1110 1101 srcx BNXOR src */
503 BIT_OPC (srcx, !b ^ carry);
505 /** 0111 1110 0110 srcx BOR src */
507 BIT_OPC (srcx, b | carry);
511 /* We report the break to our caller with the PC still pointing at the
512 breakpoint instruction. */
513 put_reg (pc, orig_pc);
516 return M32C_MAKE_HIT_BREAK ();
518 /** 0111 1110 1001 dest BSET:G dest */
520 dc = decode_bit (dest);
523 /** 0100 1bit BSET:S bit,base:11[SB] */
525 dc = decode_bit11 (bit);
528 /** 0111 1110 1011 srcx BTST:G src */
530 dc = decode_bit (srcx);
534 /** 0101 1bit BTST:S bit,base:11[SB] */
536 dc = decode_bit11 (bit);
540 /** 0111 1110 0000 dest BTSTC dest */
542 dc = decode_bit (dest);
547 /** 0111 1110 0001 dest BTSTS dest */
549 dc = decode_bit (dest);
554 /** 0111 1110 1100 srcx BXOR src */
556 BIT_OPC (srcx, b ^ carry);
558 /** 0111 011w 1000 dest CMP.size:G #IMM,dest */
564 /** 1101 000w immm dest CMP.size:Q #IMM,dest */
567 immm = sign_ext (immm, 4);
570 /** 1110 0dst CMP.B:S #IMM8,dest */
573 dc = decode_dest3 (dst, 0);
577 /** 1100 000w srcx dest CMP.size:G src,dest */
582 /** 0011 1d sr CMP.B:S src,R0L/R0H */
584 sc = decode_src2 (sr, 0, d);
585 dc = decode_dest1 (d, 0);
590 /** 0111 110w 1110 i1c s DADC,DADD,DSBB,DSUB */
592 /* w = width, i = immediate, c = carry, s = subtract */
594 int src = i ? IMM(w) : get_reg (w ? r1 : r0h);
595 int dest = get_reg (w ? r0 : r0l);
598 src = bcd2int(src, w);
599 dest = bcd2int(dest, w);
601 tprintf("decimal: %d %s %d", dest, s?"-":"+", src);
603 tprintf(" c=%d", carry);
610 c = res > (w ? 9999 : 99);
619 res += w ? 10000 : 100;
622 res = int2bcd (res, w);
623 tprintf(" = %x\n", res);
625 set_szc (res, w+1, c);
627 put_reg (w ? r0 : r0l, res);
629 /** 1010 1dst DEC.B dest */
631 dc = decode_dest3 (dst, 0);
633 tprintf("%x -- = %x\n", v, v-1);
638 /** 1111 d010 DEC.W dest */
640 v = get_reg (d ? a1 : a0);
641 tprintf("%x -- = %x\n", v, v-1);
644 put_reg (d ? a1 : a0, v);
646 /** 0111 110w 1110 0001 DIV.size #IMM */
648 div_op (-1, 0, 0, w);
650 /** 0111 011w 1101 srcx DIV.size src */
652 div_op (srcx, 0, 0, w);
654 /** 0111 110w 1110 0000 DIVU.size #IMM */
656 div_op (-1, 1, 0, w);
658 /** 0111 011w 1100 srcx DIVU.size src */
660 div_op (srcx, 1, 0, w);
662 /** 0111 110w 1110 0011 DIVX.size #IMM */
664 div_op (-1, 0, 1, w);
666 /** 0111 011w 1001 srcx DIVX.size src */
668 div_op (srcx, 0, 1, w);
670 /** 0111 1100 1111 0010 ENTER #IMM8 */
673 put_reg (sp, get_reg (sp) - 2);
674 mem_put_hi (get_reg (sp), get_reg (fb));
675 put_reg (fb, get_reg (sp));
676 put_reg (sp, get_reg (sp) - imm);
678 /** 0111 1101 1111 0010 EXITD */
680 put_reg (sp, get_reg (fb));
681 put_reg (fb, mem_get_hi (get_reg (sp)));
682 put_reg (sp, get_reg (sp) + 2);
683 put_reg (pc, mem_get_psi (get_reg (sp)));
684 put_reg (sp, get_reg (sp) + 3);
686 /** 0111 1100 0110 dest EXTS.B dest */
688 dc = decode_srcdest4 (dest, 0);
689 v = sign_ext (get_src (dc), 8);
694 /** 0111 1100 1111 0011 EXTS.W R0 */
696 v = sign_ext (get_reg (r0), 16);
700 /** 1110 1011 0flg 0101 FCLR dest */
702 set_flags (1 << flg, 0);
704 /** 1110 1011 0flg 0100 FSET dest */
706 set_flags (1 << flg, 1 << flg);
708 /** 1010 0dst INC.B dest */
710 dc = decode_dest3 (dst, 0);
712 tprintf("%x ++ = %x\n", v, v+1);
717 /** 1011 d010 INC.W dest */
719 v = get_reg (d ? a1 : a0);
720 tprintf("%x ++ = %x\n", v, v+1);
723 put_reg (d ? a1 : a0, v);
725 /** 1110 1011 11vector INT #imm */
727 trigger_based_interrupt (vector);
729 /** 1111 0110 INTO */
732 trigger_fixed_interrupt (0xffe0);
734 /** 0110 1cnd Jcnd label */
736 v = sign_ext (IMM(0), 8);
737 if (condition_true (cnd))
738 put_reg (pc, orig_pc + 1 + v);
740 /** 0111 1101 1100 cond Jcnd label */
742 v = sign_ext (IMM(0), 8);
743 if (condition_true (cond))
744 put_reg (pc, orig_pc + 2 + v);
746 /** 0110 0dsp JMP.S label */
748 put_reg (pc, orig_pc + 2 + dsp);
750 /** 1111 1110 JMP.B label */
752 imm = sign_ext (IMM(0), 8);
756 printf("[jmp-to-self detected as exit]\n");
757 return M32C_MAKE_HIT_BREAK ();
759 put_reg (pc, orig_pc + 1 + imm);
761 /** 1111 0100 JMP.W label */
763 imm = sign_ext (IMM(1), 16);
764 put_reg (pc, orig_pc + 1 + imm);
766 /** 1111 1100 JMP.A label */
771 /** 0111 1101 0010 srcx JMPI.W src */
773 sc = decode_jumpdest (srcx, 1);
775 a = sign_ext (a, 16);
776 put_reg (pc, orig_pc + a);
778 /** 0111 1101 0000 srcx JMPI.A src */
780 sc = decode_jumpdest (srcx, 0);
784 /** 1110 1110 JMPS #IMM8 */
789 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
792 /** 1111 0101 JSR.W label */
794 imm = sign_ext (IMM(1), 16);
795 put_reg (sp, get_reg (sp) - 3);
796 mem_put_psi (get_reg (sp), get_reg (pc));
797 put_reg (pc, orig_pc + imm + 1);
799 /** 1111 1101 JSR.A label */
802 put_reg (sp, get_reg (sp) - 3);
803 mem_put_psi (get_reg (sp), get_reg (pc));
806 /** 0111 1101 0011 srcx JSRI.W src */
808 sc = decode_jumpdest (srcx, 1);
810 a = sign_ext (a, 16);
812 put_reg (sp, get_reg (sp) - 3);
813 mem_put_psi (get_reg (sp), get_reg (pc));
814 put_reg (pc, orig_pc + a);
816 /** 0111 1101 0001 srcx JSRI.A src */
818 sc = decode_jumpdest (srcx, 0);
821 put_reg (sp, get_reg (sp) - 3);
822 mem_put_psi (get_reg (sp), get_reg (pc));
825 /** 1110 1111 JSRS #IMM8 */
830 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
832 put_reg (sp, get_reg (sp) - 3);
833 mem_put_psi (get_reg (sp), get_reg (pc));
836 /** 1110 1011 0reg 0000 LDC #IMM16,dest */
838 dc = decode_cr (reg);
842 /** 0111 1010 1reg srcx LDC src,dest */
844 dc = decode_cr (reg);
845 sc = decode_srcdest4 (srcx,1);
846 put_dest (dc, get_src (sc));
848 /** 0111 1100 1111 0000 LDCTX abs16,abs20 */
852 /** 0111 010w 1000 dest LDE.size abs20,dest */
854 dc = decode_srcdest4 (dest, w);
857 v = mem_get_hi (imm);
859 v = mem_get_qi (imm);
862 /** 0111 010w 1001 dest LDE.size dsp:20[a0], dest */
864 dc = decode_srcdest4 (dest, w);
865 imm = IMM(2) + get_reg (a0);
867 v = mem_get_hi (imm);
869 v = mem_get_qi (imm);
872 /** 0111 010w 1010 dest LDE.size [a1a0],dest */
874 dc = decode_srcdest4 (dest, w);
875 imm = get_reg (a1a0);
877 v = mem_get_hi (imm);
879 v = mem_get_qi (imm);
882 /** 0111 1101 1010 0imm LDIPL #IMM */
884 set_flags (0x700, imm*0x100);
886 /** 0111 010w 1100 dest MOV.size:G #IMM,dest */
891 tprintf("%x = %x\n", v, v);
895 /** 1101 100w immm dest MOV.size:Q #IMM,dest */
898 v = sign_ext (immm, 4);
899 tprintf ("%x = %x\n", v, v);
903 /** 1100 0dst MOV.B:S #IMM8,dest */
906 dc = decode_dest3 (dst, 0);
908 tprintf("%x = %x\n", v, v);
912 /** 1w10 d010 MOV.size:S #IMM,dest */
914 /* Note that for w, 0=W and 1=B unlike the usual meaning. */
916 tprintf("%x = %x\n", v, v);
918 put_reg (d ? a1 : a0, v);
920 /** 1011 0dst MOV.B:Z #0,dest */
922 dc = decode_dest3 (dst, 0);
927 /** 0111 001w srcx dest MOV.size:G src,dest */
929 sc = decode_srcdest4 (srcx, w);
930 dc = decode_srcdest4 (dest, w);
935 /** 0011 0d sr MOV.B:S src,dest */
937 sc = decode_src2 (sr, 0, d);
940 put_reg (d ? a1 : a0, v);
942 /** 0000 0s ds MOV.B:S R0L/R0H,dest */
946 dc = decode_src2 (ds, 0, s);
947 v = get_reg (s ? r0h : r0l);
951 /** 0000 1d sr MOV.B:S src,R0L/R0H */
953 sc = decode_src2 (sr, 0, d);
956 put_reg (d ? r0h : r0l, v);
958 /** 0111 010w 1011 dest MOV.size:G dsp:8[SP], dest */
960 dc = decode_srcdest4 (dest, w);
962 a = get_reg (sp) + sign_ext (imm, 8);
971 /** 0111 010w 0011 srcx MOV.size:G src, disp8[SP] */
973 sc = decode_srcdest4 (srcx, w);
975 a = get_reg (sp) + sign_ext (imm, 8);
984 /** 1110 1011 0reg 1src MOVA src,dest */
986 static reg_id map[] = { r0, r1, r2, r3, a0, a1, 0, 0 };
987 sc = decode_srcdest4 (8 + src, 0);
988 put_reg (map[reg], sc.u.addr);
990 /** 0111 1100 10hl dest MOVdir R0L,dest */
992 if (dest == 0 || dest == 4 || dest == 5)
994 dc = decode_srcdest4 (dest, 0);
999 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1000 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1001 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1002 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1006 /** 0111 1100 00hl srcx MOVdir src,R0L */
1008 if (srcx == 0 || srcx == 4 || srcx == 5)
1010 sc = decode_srcdest4 (srcx, 0);
1015 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1016 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1017 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1018 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1022 /** 0111 110w 0101 dest MUL.size #IMM,dest */
1025 imm = sign_ext (IMM(w), w?16:8);
1026 tprintf("%d * %d = %d\n", v, imm, v*imm);
1031 /** 0111 100w srcx dest MUL.size src,dest */
1035 tprintf("%d * %d = %d\n", a, b, v);
1039 /** 0111 110w 0100 dest MULU.size #IMM,dest */
1043 tprintf("%u * %u = %u\n", v, imm, v*imm);
1048 /** 0111 000w srcx dest MULU.size src,dest */
1052 tprintf("%u * %u = %u\n", a, b, v);
1056 /** 0111 010w 0101 dest NEG.size dest */
1059 tprintf("%d * -1 = %d\n", v, -v);
1061 set_oszc (v, w+1, v == 0);
1064 /** 0000 0100 NOP */
1068 /** 0111 010w 0111 dest NOT.size:G */
1071 tprintf("~ %x = %x\n", v, ~v);
1076 /** 1011 1dst NOT.B:S dest */
1078 dc = decode_dest3 (dst, 0);
1080 tprintf("~ %x = %x\n", v, ~v);
1085 /** 0111 011w 0011 dest OR.size:G #IMM,dest */
1089 tprintf ("%x | %x = %x\n", v, imm, v | imm);
1094 /** 1001 1dst OR.B:S #IMM8,dest */
1097 dc = decode_dest3 (dst, 0);
1099 tprintf("%x | %x = %x\n", v, imm, v|imm);
1104 /** 1001 100w srcx dest OR.size:G src,dest */
1107 tprintf ("%x | %x = %x\n", a, b, a | b);
1112 /** 0001 1d sr OR.B:S src,R0L/R0H */
1114 sc = decode_src2 (sr, 0, d);
1115 dc = decode_dest1 (d, 0);
1119 tprintf("%x | %x = %x\n", a, b, v);
1123 /** 0111 010w 1101 dest POP.size:G dest */
1125 dc = decode_srcdest4 (dest, w);
1128 v = mem_get_hi (get_reg (sp));
1129 put_reg (sp, get_reg (sp) + 2);
1130 tprintf("pophi: %x\n", v);
1134 v = mem_get_qi (get_reg (sp));
1135 put_reg (sp, get_reg (sp) + 1);
1136 tprintf("popqi: %x\n", v);
1140 /** 1001 d010 POP.B:S dest */
1142 v = mem_get_qi (get_reg (sp));
1143 put_reg (d ? r0h : r0l, v);
1144 put_reg (sp, get_reg (sp) + 1);
1145 tprintf("popqi: %x\n", v);
1147 /** 1101 d010 POP.W:S dest */
1149 v = mem_get_hi (get_reg (sp));
1150 put_reg (d ? a1 : a0, v);
1151 put_reg (sp, get_reg (sp) + 2);
1152 tprintf("pophi: %x\n", v);
1154 /** 1110 1011 0reg 0011 POPC dest */
1156 dc = decode_cr (reg);
1157 v = mem_get_hi (get_reg (sp));
1159 put_reg (sp, get_reg (sp) + 2);
1160 tprintf("popc: %x\n", v);
1162 /** 1110 1101 POPM dest */
1164 static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1166 tprintf("popm: %x\n", imm);
1170 v = mem_get_hi (get_reg (sp));
1171 put_reg (map[a], v);
1172 put_reg (sp, get_reg (sp) + 2);
1175 /** 0111 110w 1110 0010 PUSH.size:G #IMM */
1180 put_reg (sp, get_reg (sp) - 2);
1181 mem_put_hi (get_reg (sp), imm);
1182 tprintf("pushhi %04x\n", imm);
1186 put_reg (sp, get_reg (sp) - 1);
1187 mem_put_qi (get_reg (sp), imm);
1188 tprintf("pushqi %02x\n", imm);
1191 /** 0111 010w 0100 srcx PUSH.size:G src */
1193 sc = decode_srcdest4 (srcx, w);
1197 put_reg (sp, get_reg (sp) - 2);
1198 mem_put_hi (get_reg (sp), v);
1199 tprintf("pushhi: %x\n", v);
1203 put_reg (sp, get_reg (sp) - 1);
1204 mem_put_qi (get_reg (sp), v);
1205 tprintf("pushqi: %x\n", v);
1208 /** 1000 s010 PUSH.B:S src */
1210 v = get_reg (s ? r0h : r0l);
1211 put_reg (sp, get_reg (sp) - 1);
1212 mem_put_qi (get_reg (sp), v);
1213 tprintf("pushqi: %x\n", v);
1215 /** 1100 s010 PUSH.W:S src */
1217 v = get_reg (s ? a1 : a0);
1218 put_reg (sp, get_reg (sp) - 2);
1219 mem_put_hi (get_reg (sp), v);
1220 tprintf("pushhi: %x\n", v);
1222 /** 0111 1101 1001 srcx PUSHA src */
1224 sc = decode_srcdest4 (srcx, 0);
1225 put_reg (sp, get_reg (sp) - 2);
1226 mem_put_hi (get_reg (sp), sc.u.addr);
1227 tprintf("pushhi: %x\n", sc.u.addr);
1229 /** 1110 1011 0src 0010 PUSHC src */
1231 sc = decode_cr (src);
1232 put_reg (sp, get_reg (sp) - 2);
1234 mem_put_hi (get_reg (sp), v);
1235 tprintf("pushc: %x\n", v);
1237 /** 1110 1100 PUSHM src */
1239 static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1241 tprintf("pushm: %x\n", imm);
1245 put_reg (sp, get_reg (sp) - 2);
1246 v = get_reg (map[a]);
1247 mem_put_hi (get_reg (sp), v);
1250 /** 1111 1011 REIT */
1254 + 65536 * (mem_get_qi (a+3) & 0x0f));
1255 b = (mem_get_qi (a+2)
1256 + 16 * (mem_get_qi (a+3) & 0xf0));
1259 put_reg (sp, get_reg (sp) + 4);
1261 /** 0111 110w 1111 0001 RMPA.size */
1263 int count = get_reg (r3);
1264 int list1 = get_reg (a0);
1265 int list2 = get_reg (a1);
1266 int sum = get_reg (w ? r2r0 : r0);
1272 a = sign_ext (mem_get_hi (list1), 16);
1273 b = sign_ext (mem_get_hi (list2), 16);
1277 a = sign_ext (mem_get_qi (list1), 8);
1278 b = sign_ext (mem_get_qi (list2), 8);
1280 tprintf("%d + %d * %d = ", sum, a, b);
1282 tprintf("%d\n", sum);
1287 put_reg (r3, count);
1288 put_reg (a0, list1);
1289 put_reg (a1, list2);
1290 put_reg (w ? r2r0 : r0, sum);
1292 /** 0111 011w 1010 dest ROLC.size dest */
1294 dc = decode_srcdest4 (dest, w);
1297 /** 0111 011w 1011 dest RORC.size dest */
1299 dc = decode_srcdest4 (dest, w);
1302 /** 1110 000w immm dest ROT.size #IMM,dest */
1304 dc = decode_srcdest4 (dest, w);
1305 rot_op (dc, 0, IMM4());
1307 /** 0111 010w 0110 dest ROT.size R1H,dest */
1309 dc = decode_srcdest4 (dest, w);
1310 rot_op (dc, 0, sign_ext (get_reg (r1h), 8));
1312 /** 1111 0011 RTS */
1314 put_reg (pc, mem_get_psi (get_reg (sp)));
1315 put_reg (sp, get_reg (sp) + 3);
1317 /** 0111 011w 0111 dest SBB.size #IMM,dest */
1319 dc = decode_srcdest4 (dest, w);
1321 MATH_OP (dc, imm, !carry, -, >= 0);
1323 /** 1011 100w srcx dest SBB.size src,dest */
1325 sc = decode_srcdest4(srcx, w);
1326 dc = decode_srcdest4(dest, w);
1328 MATH_OP (dc, b, !carry, -, >= 0);
1330 /** 1111 000w immm dest SHA.size #IMM, dest */
1332 dc = decode_srcdest4(dest, w);
1333 shift_op (dc, 1, IMM4());
1335 /** 0111 010w 1111 dest SHA.size R1H,dest */
1337 dc = decode_srcdest4(dest, w);
1338 a = sign_ext (get_reg (r1h), 8);
1339 shift_op (dc, 1, a);
1341 /** 1110 1011 101d immm SHA.L #IMM, dest */
1343 dc = reg_sd (d ? r3r1 : r2r0);
1344 shift_op (dc, 1, IMM4());
1346 /** 1110 1011 001d 0001 SHA.L R1H,dest */
1348 dc = reg_sd (d ? r3r1 : r2r0);
1349 a = sign_ext (get_reg (r1h), 8);
1350 shift_op (dc, 1, a);
1352 /** 1110 100w immm dest SHL.size #IMM, dest */
1354 dc = decode_srcdest4(dest, w);
1355 shift_op (dc, 0, IMM4());
1357 /** 0111 010w 1110 dest SHL.size R1H,dest */
1359 dc = decode_srcdest4(dest, w);
1360 a = sign_ext (get_reg (r1h), 8);
1361 shift_op (dc, 0, a);
1363 /** 1110 1011 100d immm SHL.L #IMM,dest */
1365 dc = reg_sd (d ? r3r1 : r2r0);
1366 shift_op (dc, 0, IMM4());
1368 /** 1110 1011 000d 0001 SHL.L R1H,dest */
1370 dc = reg_sd (d ? r3r1 : r2r0);
1371 a = sign_ext (get_reg (r1h), 8);
1372 shift_op (dc, 0, a);
1374 /** 0111 110w 1110 100b SMOVB.size */
1376 int count = get_reg (r3);
1377 int s1 = get_reg (a0) + (get_reg (r1h) << 16);
1378 int s2 = get_reg (a1);
1379 int inc = (w ? 2 : 1) * (b ? -1 : 1);
1385 v = mem_get_hi (s1);
1390 v = mem_get_qi (s1);
1397 put_reg (r3, count);
1398 put_reg (a0, s1 & 0xffff);
1400 put_reg (r1h, s1 >> 16);
1402 /** 0111 110w 1110 1010 SSTR.size */
1404 int count = get_reg (r3);
1405 int s1 = get_reg (a1);
1406 v = get_reg (w ? r0 : r0h);
1422 put_reg (r3, count);
1425 /** 0111 1011 1src dest STC src,dest */
1427 dc = decode_srcdest4 (dest, 1);
1428 sc = decode_cr (src);
1429 put_dest (dc, get_src(sc));
1431 /** 0111 1100 1100 dest STC PC,dest */
1433 dc = decode_srcdest4 (dest, 1);
1435 put_dest (dc, orig_pc);
1437 /** 0111 1101 1111 0000 STCTX abs16,abs20 */
1441 /** 0111 010w 0000 srcx STE.size src,abs20 */
1443 sc = decode_srcdest4 (srcx, w);
1450 if (srcx == 4 || srcx == 5)
1452 v = get_reg (sc.u.reg);
1458 /** 0111 010w 0001 srcx STE.size src,disp20[a0] */
1460 sc = decode_srcdest4 (srcx, w);
1461 a = get_reg(a0) + IMM(2);
1467 if (srcx == 4 || srcx == 5)
1469 v = get_reg (sc.u.reg);
1475 /** 0111 010w 0010 srcx STE.size src,[a1a0] */
1477 sc = decode_srcdest4 (srcx, w);
1484 if (srcx == 4 || srcx == 5)
1486 v = get_reg (sc.u.reg);
1492 /** 1101 0dst STNZ #IMM8,dest */
1495 dc = decode_dest3(dst, 0);
1499 /** 1100 1dst STZ #IMM8,dest */
1502 dc = decode_dest3(dst, 0);
1506 /** 1101 1dst STZX #IMM81,#IMM82,dest */
1509 dc = decode_dest3(dst, 0);
1516 /** 0111 011w 0101 dest SUB.size:G #IMM,dest */
1518 dc = decode_srcdest4 (dest, w);
1520 MATH_OP (dc, imm, 0, -, >= 0);
1522 /** 1000 1dst SUB.B:S #IMM8,dest */
1525 dc = decode_dest3 (dst, 0);
1526 MATH_OP (dc, imm, 0, -, >= 0);
1528 /** 1010 100w srcx dest SUB.size:G src,dest */
1530 sc = decode_srcdest4(srcx, w);
1531 dc = decode_srcdest4(dest, w);
1533 MATH_OP (dc, b, 0, -, > 0);
1535 /** 0010 1d sr SUB.B:S src,R0L/R0H */
1537 sc = decode_src2 (sr, 0, d);
1538 dc = decode_dest1 (d, 0);
1540 MATH_OP (dc, b, 0, -, > 0);
1542 /** 0111 011w 0000 dest TST.size #IMM, dest */
1546 tprintf ("%x & %x = %x\n", v, imm, v & imm);
1550 /** 1000 000w srcx dest TST.size src,dest */
1553 tprintf ("%x & %x = %x\n", a, b, a & b);
1557 /** 1111 1111 UND */
1559 trigger_fixed_interrupt (0xffdc);
1561 /** 0111 1101 1111 0011 WAIT */
1563 tprintf("waiting...\n");
1565 /** 0111 101w 00sr dest XCHG.size src,dest */
1567 sc = decode_srcdest4 (sr, w);
1568 dc = decode_srcdest4 (dest, w);
1574 /** 0111 011w 0001 dest XOR.size #IMM,dest */
1578 tprintf ("%x ^ %x = %x\n", v, imm, v ^ imm);
1583 /** 1000 100w srcx dest XOR.size src,dest */
1586 tprintf ("%x ^ %x = %x\n", a, b, a ^ b);