1 /* r8c.opc --- semantics for r8c opcodes. -*- mode: c -*-
3 Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #define AU __attribute__((unused))
32 #define tprintf if (trace) printf
48 #define M16C_ONLY() /* FIXME: add something here */
50 #define GETBYTE() (op[opi++] = getbyte())
52 #define UNSUPPORTED() unsupported("unsupported", orig_pc)
53 #define NOTYET() unsupported("unimplemented", orig_pc)
56 unsupported (char *tag, int orig_pc)
59 printf("%s opcode at %08x\n", tag, orig_pc);
64 printf(" %s", bits(b>>4, 4));
65 printf(" %s", bits(b, 4));
72 printf(" %02x", mem_get_pc ());
84 rv = rv + 256 * getbyte();
86 rv = rv + 65536 * getbyte();
90 #define IMM4() (immm >= 8 ? 7 - immm : immm + 1)
93 dc = decode_srcdest4 (dest, w); \
94 v = sign_ext (get_src (dc), w?16:8);
97 dc = decode_srcdest4 (dest, w); \
101 sc = decode_srcdest4 (srcx, w); \
102 dc = decode_srcdest4 (dest, w); \
103 a = sign_ext (get_src (sc), w?16:8); \
104 b = sign_ext (get_src (dc), w?16:8);
107 sc = decode_srcdest4 (srcx, w); \
108 dc = decode_srcdest4 (dest, w); \
112 #define carry (FLAG_C ? 1 : 0)
115 cmp (int d, int s, int w)
118 int mask = w ? 0xffff : 0xff;
120 b = sign_ext (d, w?16:8) - sign_ext (s, w?16:8);
121 tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
123 sign_ext(d,w?16:8), sign_ext(s,w?16:8), b);
127 if (b & (w ? 0x8000 : 0x80))
129 if ((d & mask) >= (s & mask))
131 if (b < (w ? -32768 : -128) || b > (w ? 32767 : 127))
134 set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
138 div_op (int s, int u, int x, int w)
147 sc = decode_srcdest4 (s, w);
151 v = get_reg (w ? r2r0 : r0);
155 s = sign_ext (s, w ? 16 : 8);
156 v = sign_ext (v, w ? 16 : 8);
161 set_flags (FLAGBIT_O, FLAGBIT_O);
167 a = (unsigned int)v / (unsigned int)s;
168 b = (unsigned int)v % (unsigned int)s;
184 tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
185 if ((!u && (a > (w ? 32767 : 127)
186 || a < (w ? -32768 : -129)))
187 || (u && (a > (w ? 65536 : 255))))
188 set_flags (FLAGBIT_O, FLAGBIT_O);
190 set_flags (FLAGBIT_O, 0);
192 put_reg (w ? r0 : r0l, a);
193 put_reg (w ? r2 : r0h, b);
197 rot_op (srcdest sd, int rotc, int count)
199 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
200 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
201 int v = get_src (sd);
204 tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
205 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
208 ct = (v & msb) ? 1 : 0;
213 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
220 v |= (rotc ? c : ct) * msb;
222 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
226 set_szc (v, sd.bytes, c);
230 shift_op (srcdest sd, int arith, int count)
232 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
233 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
234 int v = get_src (sd);
241 if (count > 16 || count < -16)
243 fprintf(stderr, "Error: SI shift of %d undefined\n", count);
247 count = (count - 1) % 16 + 1;
249 count = -((-count - 1) % 16 + 1);
252 tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
253 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
256 c = (v & msb) ? 1 : 0;
259 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
266 v = (v & msb) | (v >> 1);
268 v = (v >> 1) & (msb - 1);
269 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
273 set_szc (v, sd.bytes, c);
276 #define MATH_OP(dc,s,c,op,carryrel) \
278 b = s & b2mask[dc.bytes]; \
280 tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%x\n", a, b, c, v2); \
281 a = sign_ext (a, dc.bytes * 8); \
282 b = sign_ext (s, dc.bytes * 8); \
284 tprintf("%d " #op " %d " #op " %d = %d\n", a, b, c, v); \
285 set_oszc (v, dc.bytes, v2 carryrel); \
288 #define BIT_OP(field,expr) \
289 dc = decode_bit (field); \
292 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
295 #define BIT_OPC(field,expr) \
296 dc = decode_bit (field); \
299 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
302 /* The "BMcnd dest" opcode uses a different encoding for the */
303 /* condition than other opcodes. */
304 static int bmcnd_cond_map[] = {
305 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15
311 unsigned char op[40];
314 int orig_pc = get_reg (pc);
318 step_result = M32C_MAKE_STEPPED ();
320 tprintf("trace: decode pc = %05x\n", orig_pc);
322 /** VARY dst 011 100 101 110 111 */
324 /** 0111 011w 1111 dest ABS.size dest */
328 tprintf("abs(%d) = %d\n", v, a);
332 /** 0111 011w 0110 dest ADC.size #IMM,dest */
334 dc = decode_srcdest4(dest, w);
336 MATH_OP (dc, imm, carry, +, > (w?0xffff:0xff));
338 /** 1011 000w srcx dest ADC.size src,dest */
340 sc = decode_srcdest4(srcx, w);
341 dc = decode_srcdest4(dest, w);
343 MATH_OP (dc, b, carry, +, > (w?0xffff:0xff));
345 /** 0111 011w 1110 dest ADCF.size dest */
347 dc = decode_srcdest4(dest, w);
348 MATH_OP (dc, 0, carry, +, > (w?0xffff:0xff));
350 /** 0111 011w 0100 dest ADD.size:G #imm,dest */
352 dc = decode_srcdest4(dest, w);
354 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
356 /** 1100 100w immm dest ADD.size:Q #IMM,dest */
358 dc = decode_srcdest4(dest, w);
359 imm = sign_ext (immm, 4);
360 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
362 /** 1000 0dst ADD.B:S #IMM8,dst */
365 dc = decode_dest3 (dst, 0);
366 MATH_OP (dc, imm, 0, +, > 0xff);
368 /** 1010 000w srcx dest ADD.size:G src,dest */
370 sc = decode_srcdest4(srcx, w);
371 dc = decode_srcdest4(dest, w);
373 MATH_OP (dc, b, 0, +, > (w?0xffff:0xff));
375 /** 0010 0d sr ADD.B:S src,R0L/R0H */
377 sc = decode_src2 (sr, 0, d);
378 dc = decode_dest1 (d, 0);
380 MATH_OP (dc, b, 0, +, > 0xff);
382 /** 0111 110w 1110 1011 ADD.size:G #IMM,sp */
385 imm = sign_ext (IMM(w), w?16:8);
386 MATH_OP (dc, imm, 0, +, > 0xffff);
388 /** 0111 1101 1011 immm ADD.size:Q #IMM,sp */
391 imm = sign_ext (immm, 4);
392 MATH_OP (dc, imm, 0, +, > 0xffff);
394 /** 1111 100w immm dest ADJNZ.size #IMM,dest,label */
397 imm = sign_ext(immm, 4);
398 tprintf("%x + %d = %x\n", v, imm, v+imm);
401 a = sign_ext (IMM(0), 8);
402 if ((v & (w ? 0xffff : 0xff)) != 0)
404 tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
405 put_reg (pc, orig_pc + 2 + a);
406 tprintf("%x\n", get_reg (pc));
409 /** 0111 011w 0010 dest AND.size:G #IMM,dest */
413 tprintf ("%x & %x = %x\n", v, imm, v & imm);
418 /** 1001 0dst AND.B:S #IMM8,dest */
421 dc = decode_dest3 (dst, 0);
423 tprintf("%x & %x = %x\n", v, imm, v & imm);
428 /** 1001 000w srcx dest AND.size:G src.dest */
431 tprintf ("%x & %x = %x\n", a, b, a & b);
436 /** 0001 0d sr AND.B:S src,R0L/R0H */
438 sc = decode_src2 (sr, 0, d);
439 dc = decode_dest1 (d, 0);
443 tprintf("%x & %x = %x\n", a, b, v);
447 /** 0111 1110 0100 srcx BAND src */
449 BIT_OPC (srcx, b & carry);
451 /** 0111 1110 1000 dest BCLR:G dest */
453 dc = decode_bit (dest);
456 /** 0100 0bit BCLR:S bit,base:11[SB] */
458 dc = decode_bit11 (bit);
461 /** 0111 1110 0010 dest BMcnd dest */
463 dc = decode_bit (dest);
464 if (condition_true (bmcnd_cond_map [IMM (0) & 15]))
469 /** 0111 1101 1101 cond BMcnd C */
471 if (condition_true (cond))
476 /** 0111 1110 0101 srcx BNAND src */
478 BIT_OPC (srcx, !b & carry);
480 /** 0111 1110 0111 srcx BNOR src */
482 BIT_OPC (srcx, !b | carry);
484 /** 0111 1110 1010 dest BNOT:G dest */
488 /** 0101 0bit BNOT:S bit,base:11[SB] */
490 dc = decode_bit11 (bit);
491 put_bit (dc, !get_bit (dc));
493 /** 0111 1110 0011 srcx BNTST src */
495 dc = decode_bit (srcx);
499 /** 0111 1110 1101 srcx BNXOR src */
501 BIT_OPC (srcx, !b ^ carry);
503 /** 0111 1110 0110 srcx BOR src */
505 BIT_OPC (srcx, b | carry);
509 /* We report the break to our caller with the PC still pointing at the
510 breakpoint instruction. */
511 put_reg (pc, orig_pc);
514 return M32C_MAKE_HIT_BREAK ();
516 /** 0111 1110 1001 dest BSET:G dest */
518 dc = decode_bit (dest);
521 /** 0100 1bit BSET:S bit,base:11[SB] */
523 dc = decode_bit11 (bit);
526 /** 0111 1110 1011 srcx BTST:G src */
528 dc = decode_bit (srcx);
532 /** 0101 1bit BTST:S bit,base:11[SB] */
534 dc = decode_bit11 (bit);
538 /** 0111 1110 0000 dest BTSTC dest */
540 dc = decode_bit (dest);
545 /** 0111 1110 0001 dest BTSTS dest */
547 dc = decode_bit (dest);
552 /** 0111 1110 1100 srcx BXOR src */
554 BIT_OPC (srcx, b ^ carry);
556 /** 0111 011w 1000 dest CMP.size:G #IMM,dest */
562 /** 1101 000w immm dest CMP.size:Q #IMM,dest */
565 immm = sign_ext (immm, 4);
568 /** 1110 0dst CMP.B:S #IMM8,dest */
571 dc = decode_dest3 (dst, 0);
575 /** 1100 000w srcx dest CMP.size:G src,dest */
580 /** 0011 1d sr CMP.B:S src,R0L/R0H */
582 sc = decode_src2 (sr, 0, d);
583 dc = decode_dest1 (d, 0);
588 /** 0111 110w 1110 i1c s DADC,DADD,DSBB,DSUB */
590 /* w = width, i = immediate, c = carry, s = subtract */
592 int src = i ? IMM(w) : get_reg (w ? r1 : r0h);
593 int dest = get_reg (w ? r0 : r0l);
596 src = bcd2int(src, w);
597 dest = bcd2int(dest, w);
599 tprintf("decimal: %d %s %d", dest, s?"-":"+", src);
601 tprintf(" c=%d", carry);
608 c = res > (w ? 9999 : 99);
617 res += w ? 10000 : 100;
620 res = int2bcd (res, w);
621 tprintf(" = %x\n", res);
623 set_szc (res, w+1, c);
625 put_reg (w ? r0 : r0l, res);
627 /** 1010 1dst DEC.B dest */
629 dc = decode_dest3 (dst, 0);
631 tprintf("%x -- = %x\n", v, v-1);
636 /** 1111 d010 DEC.W dest */
638 v = get_reg (d ? a1 : a0);
639 tprintf("%x -- = %x\n", v, v-1);
642 put_reg (d ? a1 : a0, v);
644 /** 0111 110w 1110 0001 DIV.size #IMM */
646 div_op (-1, 0, 0, w);
648 /** 0111 011w 1101 srcx DIV.size src */
650 div_op (srcx, 0, 0, w);
652 /** 0111 110w 1110 0000 DIVU.size #IMM */
654 div_op (-1, 1, 0, w);
656 /** 0111 011w 1100 srcx DIVU.size src */
658 div_op (srcx, 1, 0, w);
660 /** 0111 110w 1110 0011 DIVX.size #IMM */
662 div_op (-1, 0, 1, w);
664 /** 0111 011w 1001 srcx DIVX.size src */
666 div_op (srcx, 0, 1, w);
668 /** 0111 1100 1111 0010 ENTER #IMM8 */
671 put_reg (sp, get_reg (sp) - 2);
672 mem_put_hi (get_reg (sp), get_reg (fb));
673 put_reg (fb, get_reg (sp));
674 put_reg (sp, get_reg (sp) - imm);
676 /** 0111 1101 1111 0010 EXITD */
678 put_reg (sp, get_reg (fb));
679 put_reg (fb, mem_get_hi (get_reg (sp)));
680 put_reg (sp, get_reg (sp) + 2);
681 put_reg (pc, mem_get_psi (get_reg (sp)));
682 put_reg (sp, get_reg (sp) + 3);
684 /** 0111 1100 0110 dest EXTS.B dest */
686 dc = decode_srcdest4 (dest, 0);
687 v = sign_ext (get_src (dc), 8);
692 /** 0111 1100 1111 0011 EXTS.W R0 */
694 v = sign_ext (get_reg (r0), 16);
698 /** 1110 1011 0flg 0101 FCLR dest */
700 set_flags (1 << flg, 0);
702 /** 1110 1011 0flg 0100 FSET dest */
704 set_flags (1 << flg, 1 << flg);
706 /** 1010 0dst INC.B dest */
708 dc = decode_dest3 (dst, 0);
710 tprintf("%x ++ = %x\n", v, v+1);
715 /** 1011 d010 INC.W dest */
717 v = get_reg (d ? a1 : a0);
718 tprintf("%x ++ = %x\n", v, v+1);
721 put_reg (d ? a1 : a0, v);
723 /** 1110 1011 11vector INT #imm */
725 trigger_based_interrupt (vector);
727 /** 1111 0110 INTO */
730 trigger_fixed_interrupt (0xffe0);
732 /** 0110 1cnd Jcnd label */
734 v = sign_ext (IMM(0), 8);
735 if (condition_true (cnd))
736 put_reg (pc, orig_pc + 1 + v);
738 /** 0111 1101 1100 cond Jcnd label */
740 v = sign_ext (IMM(0), 8);
741 if (condition_true (cond))
742 put_reg (pc, orig_pc + 2 + v);
744 /** 0110 0dsp JMP.S label */
746 put_reg (pc, orig_pc + 2 + dsp);
748 /** 1111 1110 JMP.B label */
750 imm = sign_ext (IMM(0), 8);
754 printf("[jmp-to-self detected as exit]\n");
755 return M32C_MAKE_HIT_BREAK ();
757 put_reg (pc, orig_pc + 1 + imm);
759 /** 1111 0100 JMP.W label */
761 imm = sign_ext (IMM(1), 16);
762 put_reg (pc, orig_pc + 1 + imm);
764 /** 1111 1100 JMP.A label */
769 /** 0111 1101 0010 srcx JMPI.W src */
771 sc = decode_jumpdest (srcx, 1);
773 a = sign_ext (a, 16);
774 put_reg (pc, orig_pc + a);
776 /** 0111 1101 0000 srcx JMPI.A src */
778 sc = decode_jumpdest (srcx, 0);
782 /** 1110 1110 JMPS #IMM8 */
787 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
790 /** 1111 0101 JSR.W label */
792 imm = sign_ext (IMM(1), 16);
793 put_reg (sp, get_reg (sp) - 3);
794 mem_put_psi (get_reg (sp), get_reg (pc));
795 put_reg (pc, orig_pc + imm + 1);
797 /** 1111 1101 JSR.A label */
800 put_reg (sp, get_reg (sp) - 3);
801 mem_put_psi (get_reg (sp), get_reg (pc));
804 /** 0111 1101 0011 srcx JSRI.W src */
806 sc = decode_jumpdest (srcx, 1);
808 a = sign_ext (a, 16);
810 put_reg (sp, get_reg (sp) - 3);
811 mem_put_psi (get_reg (sp), get_reg (pc));
812 put_reg (pc, orig_pc + a);
814 /** 0111 1101 0001 srcx JSRI.A src */
816 sc = decode_jumpdest (srcx, 0);
819 put_reg (sp, get_reg (sp) - 3);
820 mem_put_psi (get_reg (sp), get_reg (pc));
823 /** 1110 1111 JSRS #IMM8 */
828 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
830 put_reg (sp, get_reg (sp) - 3);
831 mem_put_psi (get_reg (sp), get_reg (pc));
834 /** 1110 1011 0reg 0000 LDC #IMM16,dest */
836 dc = decode_cr (reg);
840 /** 0111 1010 1reg srcx LDC src,dest */
842 dc = decode_cr (reg);
843 sc = decode_srcdest4 (srcx,1);
844 put_dest (dc, get_src (sc));
846 /** 0111 1100 1111 0000 LDCTX abs16,abs20 */
850 /** 0111 010w 1000 dest LDE.size abs20,dest */
852 dc = decode_srcdest4 (dest, w);
855 v = mem_get_hi (imm);
857 v = mem_get_qi (imm);
860 /** 0111 010w 1001 dest LDE.size dsp:20[a0], dest */
862 dc = decode_srcdest4 (dest, w);
863 imm = IMM(2) + get_reg (a0);
865 v = mem_get_hi (imm);
867 v = mem_get_qi (imm);
870 /** 0111 010w 1010 dest LDE.size [a1a0],dest */
872 dc = decode_srcdest4 (dest, w);
873 imm = get_reg (a1a0);
875 v = mem_get_hi (imm);
877 v = mem_get_qi (imm);
880 /** 0111 1101 1010 0imm LDIPL #IMM */
882 set_flags (0x700, imm*0x100);
884 /** 0111 010w 1100 dest MOV.size:G #IMM,dest */
886 dc = decode_srcdest4 (dest, w);
889 tprintf("%x = %x\n", v, v);
893 /** 1101 100w immm dest MOV.size:Q #IMM,dest */
895 dc = decode_srcdest4 (dest, w);
896 v = sign_ext (immm, 4);
897 tprintf ("%x = %x\n", v, v);
901 /** 1100 0dst MOV.B:S #IMM8,dest */
904 dc = decode_dest3 (dst, 0);
906 tprintf("%x = %x\n", v, v);
910 /** 1w10 d010 MOV.size:S #IMM,dest */
912 /* Note that for w, 0=W and 1=B unlike the usual meaning. */
914 tprintf("%x = %x\n", v, v);
916 put_reg (d ? a1 : a0, v);
918 /** 1011 0dst MOV.B:Z #0,dest */
920 dc = decode_dest3 (dst, 0);
925 /** 0111 001w srcx dest MOV.size:G src,dest */
927 sc = decode_srcdest4 (srcx, w);
928 dc = decode_srcdest4 (dest, w);
933 /** 0011 0d sr MOV.B:S src,dest */
935 sc = decode_src2 (sr, 0, d);
938 put_reg (d ? a1 : a0, v);
940 /** 0000 0s ds MOV.B:S R0L/R0H,dest */
944 dc = decode_src2 (ds, 0, s);
945 v = get_reg (s ? r0h : r0l);
949 /** 0000 1d sr MOV.B:S src,R0L/R0H */
951 sc = decode_src2 (sr, 0, d);
954 put_reg (d ? r0h : r0l, v);
956 /** 0111 010w 1011 dest MOV.size:G dsp:8[SP], dest */
958 dc = decode_srcdest4 (dest, w);
960 a = get_reg (sp) + sign_ext (imm, 8);
969 /** 0111 010w 0011 srcx MOV.size:G src, disp8[SP] */
971 sc = decode_srcdest4 (srcx, w);
973 a = get_reg (sp) + sign_ext (imm, 8);
982 /** 1110 1011 0reg 1src MOVA src,dest */
984 static reg_id map[] = { r0, r1, r2, r3, a0, a1, 0, 0 };
985 sc = decode_srcdest4 (8 + src, 0);
986 put_reg (map[reg], sc.u.addr);
988 /** 0111 1100 10hl dest MOVdir R0L,dest */
990 if (dest == 0 || dest == 4 || dest == 5)
992 dc = decode_srcdest4 (dest, 0);
997 case 0: a = (a & 0xf0) | (b & 0x0f); break;
998 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
999 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1000 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1004 /** 0111 1100 00hl srcx MOVdir src,R0L */
1006 if (srcx == 0 || srcx == 4 || srcx == 5)
1008 sc = decode_srcdest4 (srcx, 0);
1013 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1014 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1015 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1016 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1020 /** 0111 110w 0101 dest MUL.size #IMM,dest */
1023 imm = sign_ext (IMM(w), w?16:8);
1024 tprintf("%d * %d = %d\n", v, imm, v*imm);
1029 /** 0111 100w srcx dest MUL.size src,dest */
1033 tprintf("%d * %d = %d\n", a, b, v);
1037 /** 0111 110w 0100 dest MULU.size #IMM,dest */
1041 tprintf("%u * %u = %u\n", v, imm, v*imm);
1046 /** 0111 000w srcx dest MULU.size src,dest */
1050 tprintf("%u * %u = %u\n", a, b, v);
1054 /** 0111 010w 0101 dest NEG.size dest */
1057 tprintf("%d * -1 = %d\n", v, -v);
1059 set_oszc (v, w+1, v == 0);
1062 /** 0000 0100 NOP */
1066 /** 0111 010w 0111 dest NOT.size:G */
1069 tprintf("~ %x = %x\n", v, ~v);
1074 /** 1011 1dst NOT.B:S dest */
1076 dc = decode_dest3 (dst, 0);
1078 tprintf("~ %x = %x\n", v, ~v);
1083 /** 0111 011w 0011 dest OR.size:G #IMM,dest */
1087 tprintf ("%x | %x = %x\n", v, imm, v | imm);
1092 /** 1001 1dst OR.B:S #IMM8,dest */
1095 dc = decode_dest3 (dst, 0);
1097 tprintf("%x | %x = %x\n", v, imm, v|imm);
1102 /** 1001 100w srcx dest OR.size:G src,dest */
1105 tprintf ("%x | %x = %x\n", a, b, a | b);
1110 /** 0001 1d sr OR.B:S src,R0L/R0H */
1112 sc = decode_src2 (sr, 0, d);
1113 dc = decode_dest1 (d, 0);
1117 tprintf("%x | %x = %x\n", a, b, v);
1121 /** 0111 010w 1101 dest POP.size:G dest */
1123 dc = decode_srcdest4 (dest, w);
1126 v = mem_get_hi (get_reg (sp));
1127 put_reg (sp, get_reg (sp) + 2);
1128 tprintf("pophi: %x\n", v);
1132 v = mem_get_qi (get_reg (sp));
1133 put_reg (sp, get_reg (sp) + 1);
1134 tprintf("popqi: %x\n", v);
1138 /** 1001 d010 POP.B:S dest */
1140 v = mem_get_qi (get_reg (sp));
1141 put_reg (d ? r0h : r0l, v);
1142 put_reg (sp, get_reg (sp) + 1);
1143 tprintf("popqi: %x\n", v);
1145 /** 1101 d010 POP.W:S dest */
1147 v = mem_get_hi (get_reg (sp));
1148 put_reg (d ? a1 : a0, v);
1149 put_reg (sp, get_reg (sp) + 2);
1150 tprintf("pophi: %x\n", v);
1152 /** 1110 1011 0reg 0011 POPC dest */
1154 dc = decode_cr (reg);
1155 v = mem_get_hi (get_reg (sp));
1157 put_reg (sp, get_reg (sp) + 2);
1158 tprintf("popc: %x\n", v);
1160 /** 1110 1101 POPM dest */
1162 static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1164 tprintf("popm: %x\n", imm);
1168 v = mem_get_hi (get_reg (sp));
1169 put_reg (map[a], v);
1170 put_reg (sp, get_reg (sp) + 2);
1173 /** 0111 110w 1110 0010 PUSH.size:G #IMM */
1178 put_reg (sp, get_reg (sp) - 2);
1179 mem_put_hi (get_reg (sp), imm);
1180 tprintf("pushhi %04x\n", imm);
1184 put_reg (sp, get_reg (sp) - 1);
1185 mem_put_qi (get_reg (sp), imm);
1186 tprintf("pushqi %02x\n", imm);
1189 /** 0111 010w 0100 srcx PUSH.size:G src */
1191 sc = decode_srcdest4 (srcx, w);
1195 put_reg (sp, get_reg (sp) - 2);
1196 mem_put_hi (get_reg (sp), v);
1197 tprintf("pushhi: %x\n", v);
1201 put_reg (sp, get_reg (sp) - 1);
1202 mem_put_qi (get_reg (sp), v);
1203 tprintf("pushqi: %x\n", v);
1206 /** 1000 s010 PUSH.B:S src */
1208 v = get_reg (s ? r0h : r0l);
1209 put_reg (sp, get_reg (sp) - 1);
1210 mem_put_qi (get_reg (sp), v);
1211 tprintf("pushqi: %x\n", v);
1213 /** 1100 s010 PUSH.W:S src */
1215 v = get_reg (s ? a1 : a0);
1216 put_reg (sp, get_reg (sp) - 2);
1217 mem_put_hi (get_reg (sp), v);
1218 tprintf("pushhi: %x\n", v);
1220 /** 0111 1101 1001 srcx PUSHA src */
1222 sc = decode_srcdest4 (srcx, 0);
1223 put_reg (sp, get_reg (sp) - 2);
1224 mem_put_hi (get_reg (sp), sc.u.addr);
1225 tprintf("pushhi: %x\n", sc.u.addr);
1227 /** 1110 1011 0src 0010 PUSHC src */
1229 sc = decode_cr (src);
1230 put_reg (sp, get_reg (sp) - 2);
1232 mem_put_hi (get_reg (sp), v);
1233 tprintf("pushc: %x\n", v);
1235 /** 1110 1100 PUSHM src */
1237 static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1239 tprintf("pushm: %x\n", imm);
1243 put_reg (sp, get_reg (sp) - 2);
1244 v = get_reg (map[a]);
1245 mem_put_hi (get_reg (sp), v);
1248 /** 1111 1011 REIT */
1252 + 65536 * (mem_get_qi (a+3) & 0x0f));
1253 b = (mem_get_qi (a+2)
1254 + 16 * (mem_get_qi (a+3) & 0xf0));
1257 put_reg (sp, get_reg (sp) + 4);
1259 /** 0111 110w 1111 0001 RMPA.size */
1261 int count = get_reg (r3);
1262 int list1 = get_reg (a0);
1263 int list2 = get_reg (a1);
1264 int sum = get_reg (w ? r2r0 : r0);
1270 a = sign_ext (mem_get_hi (list1), 16);
1271 b = sign_ext (mem_get_hi (list2), 16);
1275 a = sign_ext (mem_get_qi (list1), 8);
1276 b = sign_ext (mem_get_qi (list2), 8);
1278 tprintf("%d + %d * %d = ", sum, a, b);
1280 tprintf("%d\n", sum);
1285 put_reg (r3, count);
1286 put_reg (a0, list1);
1287 put_reg (a1, list2);
1288 put_reg (w ? r2r0 : r0, sum);
1290 /** 0111 011w 1010 dest ROLC.size dest */
1292 dc = decode_srcdest4 (dest, w);
1295 /** 0111 011w 1011 dest RORC.size dest */
1297 dc = decode_srcdest4 (dest, w);
1300 /** 1110 000w immm dest ROT.size #IMM,dest */
1302 dc = decode_srcdest4 (dest, w);
1303 rot_op (dc, 0, IMM4());
1305 /** 0111 010w 0110 dest ROT.size R1H,dest */
1307 dc = decode_srcdest4 (dest, w);
1308 rot_op (dc, 0, sign_ext (get_reg (r1h), 8));
1310 /** 1111 0011 RTS */
1312 put_reg (pc, mem_get_psi (get_reg (sp)));
1313 put_reg (sp, get_reg (sp) + 3);
1315 /** 0111 011w 0111 dest SBB.size #IMM,dest */
1317 dc = decode_srcdest4 (dest, w);
1319 MATH_OP (dc, imm, !carry, -, >= 0);
1321 /** 1011 100w srcx dest SBB.size src,dest */
1323 sc = decode_srcdest4(srcx, w);
1324 dc = decode_srcdest4(dest, w);
1326 MATH_OP (dc, b, !carry, -, >= 0);
1328 /** 1111 000w immm dest SHA.size #IMM, dest */
1330 dc = decode_srcdest4(dest, w);
1331 shift_op (dc, 1, IMM4());
1333 /** 0111 010w 1111 dest SHA.size R1H,dest */
1335 dc = decode_srcdest4(dest, w);
1336 a = sign_ext (get_reg (r1h), 8);
1337 shift_op (dc, 1, a);
1339 /** 1110 1011 101d immm SHA.L #IMM, dest */
1341 dc = reg_sd (d ? r3r1 : r2r0);
1342 shift_op (dc, 1, IMM4());
1344 /** 1110 1011 001d 0001 SHA.L R1H,dest */
1346 dc = reg_sd (d ? r3r1 : r2r0);
1347 a = sign_ext (get_reg (r1h), 8);
1348 shift_op (dc, 1, a);
1350 /** 1110 100w immm dest SHL.size #IMM, dest */
1352 dc = decode_srcdest4(dest, w);
1353 shift_op (dc, 0, IMM4());
1355 /** 0111 010w 1110 dest SHL.size R1H,dest */
1357 dc = decode_srcdest4(dest, w);
1358 a = sign_ext (get_reg (r1h), 8);
1359 shift_op (dc, 0, a);
1361 /** 1110 1011 100d immm SHL.L #IMM,dest */
1363 dc = reg_sd (d ? r3r1 : r2r0);
1364 shift_op (dc, 0, IMM4());
1366 /** 1110 1011 000d 0001 SHL.L R1H,dest */
1368 dc = reg_sd (d ? r3r1 : r2r0);
1369 a = sign_ext (get_reg (r1h), 8);
1370 shift_op (dc, 0, a);
1372 /** 0111 110w 1110 100b SMOVB.size */
1374 int count = get_reg (r3);
1375 int s1 = get_reg (a0) + (get_reg (r1h) << 16);
1376 int s2 = get_reg (a1);
1377 int inc = (w ? 2 : 1) * (b ? -1 : 1);
1383 v = mem_get_hi (s1);
1388 v = mem_get_qi (s1);
1395 put_reg (r3, count);
1396 put_reg (a0, s1 & 0xffff);
1398 put_reg (r1h, s1 >> 16);
1400 /** 0111 110w 1110 1010 SSTR.size */
1402 int count = get_reg (r3);
1403 int s1 = get_reg (a1);
1404 v = get_reg (w ? r0 : r0h);
1420 put_reg (r3, count);
1423 /** 0111 1011 1src dest STC src,dest */
1425 dc = decode_srcdest4 (dest, 1);
1426 sc = decode_cr (src);
1427 put_dest (dc, get_src(sc));
1429 /** 0111 1100 1100 dest STC PC,dest */
1431 dc = decode_srcdest4 (dest, 1);
1433 put_dest (dc, orig_pc);
1435 /** 0111 1101 1111 0000 STCTX abs16,abs20 */
1439 /** 0111 010w 0000 srcx STE.size src,abs20 */
1441 sc = decode_srcdest4 (srcx, w);
1448 if (srcx == 4 || srcx == 5)
1450 v = get_reg (sc.u.reg);
1456 /** 0111 010w 0001 srcx STE.size src,disp20[a0] */
1458 sc = decode_srcdest4 (srcx, w);
1459 a = get_reg(a0) + IMM(2);
1465 if (srcx == 4 || srcx == 5)
1467 v = get_reg (sc.u.reg);
1473 /** 0111 010w 0010 srcx STE.size src,[a1a0] */
1475 sc = decode_srcdest4 (srcx, w);
1482 if (srcx == 4 || srcx == 5)
1484 v = get_reg (sc.u.reg);
1490 /** 1101 0dst STNZ #IMM8,dest */
1493 dc = decode_dest3(dst, 0);
1497 /** 1100 1dst STZ #IMM8,dest */
1500 dc = decode_dest3(dst, 0);
1504 /** 1101 1dst STZX #IMM81,#IMM82,dest */
1507 dc = decode_dest3(dst, 0);
1514 /** 0111 011w 0101 dest SUB.size:G #IMM,dest */
1516 dc = decode_srcdest4 (dest, w);
1518 MATH_OP (dc, imm, 0, -, >= 0);
1520 /** 1000 1dst SUB.B:S #IMM8,dest */
1523 dc = decode_dest3 (dst, 0);
1524 MATH_OP (dc, imm, 0, -, >= 0);
1526 /** 1010 100w srcx dest SUB.size:G src,dest */
1528 sc = decode_srcdest4(srcx, w);
1529 dc = decode_srcdest4(dest, w);
1531 MATH_OP (dc, b, 0, -, >= 0);
1533 /** 0010 1d sr SUB.B:S src,R0L/R0H */
1535 sc = decode_src2 (sr, 0, d);
1536 dc = decode_dest1 (d, 0);
1538 MATH_OP (dc, b, 0, -, >= 0);
1540 /** 0111 011w 0000 dest TST.size #IMM, dest */
1544 tprintf ("%x & %x = %x\n", v, imm, v & imm);
1548 /** 1000 000w srcx dest TST.size src,dest */
1551 tprintf ("%x & %x = %x\n", a, b, a & b);
1555 /** 1111 1111 UND */
1557 trigger_fixed_interrupt (0xffdc);
1559 /** 0111 1101 1111 0011 WAIT */
1561 tprintf("waiting...\n");
1563 /** 0111 101w 00sr dest XCHG.size src,dest */
1565 sc = decode_srcdest4 (sr, w);
1566 dc = decode_srcdest4 (dest, w);
1572 /** 0111 011w 0001 dest XOR.size #IMM,dest */
1576 tprintf ("%x ^ %x = %x\n", v, imm, v ^ imm);
1581 /** 1000 100w srcx dest XOR.size src,dest */
1584 tprintf ("%x ^ %x = %x\n", a, b, a ^ b);