1 /* r8c.opc --- semantics for r8c opcodes. -*- mode: c -*-
3 Copyright (C) 2005-2023 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/>. */
21 /* This must come before any other includes. */
33 #define tprintf if (trace) printf
49 #define M16C_ONLY() /* FIXME: add something here */
51 #define GETBYTE() (op[opi++] = getbyte())
53 #define UNSUPPORTED() unsupported("unsupported", orig_pc)
54 #define NOTYET() unsupported("unimplemented", orig_pc)
57 unsupported (char *tag, int orig_pc)
60 printf("%s opcode at %08x\n", tag, orig_pc);
65 printf(" %s", bits(b>>4, 4));
66 printf(" %s", bits(b, 4));
73 printf(" %02x", mem_get_pc ());
85 rv = rv + 256 * getbyte();
87 rv = rv + 65536 * getbyte();
91 #define IMM4() (immm >= 8 ? 7 - immm : immm + 1)
94 dc = decode_srcdest4 (dest, w); \
95 v = sign_ext (get_src (dc), w?16:8);
98 dc = decode_srcdest4 (dest, w); \
102 sc = decode_srcdest4 (srcx, w); \
103 dc = decode_srcdest4 (dest, w); \
104 a = sign_ext (get_src (sc), w?16:8); \
105 b = sign_ext (get_src (dc), w?16:8);
108 sc = decode_srcdest4 (srcx, w); \
109 dc = decode_srcdest4 (dest, w); \
113 #define carry (FLAG_C ? 1 : 0)
116 cmp (int d, int s, int w)
119 int mask = w ? 0xffff : 0xff;
121 b = sign_ext (d, w?16:8) - sign_ext (s, w?16:8);
122 tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
124 sign_ext(d,w?16:8), sign_ext(s,w?16:8), b);
128 if (b & (w ? 0x8000 : 0x80))
130 if ((d & mask) >= (s & mask))
132 if (b < (w ? -32768 : -128) || b > (w ? 32767 : 127))
135 set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
139 div_op (int s, int u, int x, int w)
148 sc = decode_srcdest4 (s, w);
152 v = get_reg (w ? r2r0 : r0);
156 s = sign_ext (s, w ? 16 : 8);
157 v = sign_ext (v, w ? 16 : 8);
162 set_flags (FLAGBIT_O, FLAGBIT_O);
168 a = (unsigned int)v / (unsigned int)s;
169 b = (unsigned int)v % (unsigned int)s;
185 tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
186 if ((!u && (a > (w ? 32767 : 127)
187 || a < (w ? -32768 : -129)))
188 || (u && (a > (w ? 65536 : 255))))
189 set_flags (FLAGBIT_O, FLAGBIT_O);
191 set_flags (FLAGBIT_O, 0);
193 put_reg (w ? r0 : r0l, a);
194 put_reg (w ? r2 : r0h, b);
198 rot_op (srcdest sd, int rotc, int count)
200 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
201 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
202 int v = get_src (sd);
205 tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
206 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
209 ct = (v & msb) ? 1 : 0;
214 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
221 v |= (rotc ? c : ct) * msb;
223 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
227 set_szc (v, sd.bytes, c);
231 shift_op (srcdest sd, int arith, int count)
233 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
234 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
235 int v = get_src (sd);
242 if (count > 16 || count < -16)
244 fprintf(stderr, "Error: SI shift of %d undefined\n", count);
248 count = (count - 1) % 16 + 1;
250 count = -((-count - 1) % 16 + 1);
253 tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
254 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
257 c = (v & msb) ? 1 : 0;
260 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
267 v = (v & msb) | (v >> 1);
269 v = (v >> 1) & (msb - 1);
270 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
274 set_szc (v, sd.bytes, c);
277 #define MATH_OP(dc,s,c,op,carryrel) \
279 b = s & b2mask[dc.bytes]; \
281 tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%x\n", a, b, c, v2); \
282 a = sign_ext (a, dc.bytes * 8); \
283 b = sign_ext (s, dc.bytes * 8); \
285 tprintf("%d " #op " %d " #op " %d = %d\n", a, b, c, v); \
286 set_oszc (v, dc.bytes, v2 carryrel); \
289 #define BIT_OP(field,expr) \
290 dc = decode_bit (field); \
293 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
296 #define BIT_OPC(field,expr) \
297 dc = decode_bit (field); \
300 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
303 /* The "BMcnd dest" opcode uses a different encoding for the */
304 /* condition than other opcodes. */
305 static int bmcnd_cond_map[] = {
306 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15
312 unsigned char op[40];
315 int orig_pc = get_reg (pc);
319 step_result = M32C_MAKE_STEPPED ();
321 tprintf("trace: decode pc = %05x\n", orig_pc);
323 /** VARY dst 011 100 101 110 111 */
325 /** 0111 011w 1111 dest ABS.size dest */
329 tprintf("abs(%d) = %d\n", v, a);
333 /** 0111 011w 0110 dest ADC.size #IMM,dest */
335 dc = decode_srcdest4(dest, w);
337 MATH_OP (dc, imm, carry, +, > (w?0xffff:0xff));
339 /** 1011 000w srcx dest ADC.size src,dest */
341 sc = decode_srcdest4(srcx, w);
342 dc = decode_srcdest4(dest, w);
344 MATH_OP (dc, b, carry, +, > (w?0xffff:0xff));
346 /** 0111 011w 1110 dest ADCF.size dest */
348 dc = decode_srcdest4(dest, w);
349 MATH_OP (dc, 0, carry, +, > (w?0xffff:0xff));
351 /** 0111 011w 0100 dest ADD.size:G #imm,dest */
353 dc = decode_srcdest4(dest, w);
355 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
357 /** 1100 100w immm dest ADD.size:Q #IMM,dest */
359 dc = decode_srcdest4(dest, w);
360 imm = sign_ext (immm, 4);
361 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
363 /** 1000 0dst ADD.B:S #IMM8,dst */
366 dc = decode_dest3 (dst, 0);
367 MATH_OP (dc, imm, 0, +, > 0xff);
369 /** 1010 000w srcx dest ADD.size:G src,dest */
371 sc = decode_srcdest4(srcx, w);
372 dc = decode_srcdest4(dest, w);
374 MATH_OP (dc, b, 0, +, > (w?0xffff:0xff));
376 /** 0010 0d sr ADD.B:S src,R0L/R0H */
378 sc = decode_src2 (sr, 0, d);
379 dc = decode_dest1 (d, 0);
381 MATH_OP (dc, b, 0, +, > 0xff);
383 /** 0111 110w 1110 1011 ADD.size:G #IMM,sp */
386 imm = sign_ext (IMM(w), w?16:8);
387 MATH_OP (dc, imm, 0, +, > 0xffff);
389 /** 0111 1101 1011 immm ADD.size:Q #IMM,sp */
392 imm = sign_ext (immm, 4);
393 MATH_OP (dc, imm, 0, +, > 0xffff);
395 /** 1111 100w immm dest ADJNZ.size #IMM,dest,label */
398 imm = sign_ext(immm, 4);
399 tprintf("%x + %d = %x\n", v, imm, v+imm);
402 a = sign_ext (IMM(0), 8);
403 if ((v & (w ? 0xffff : 0xff)) != 0)
405 tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
406 put_reg (pc, orig_pc + 2 + a);
407 tprintf("%x\n", get_reg (pc));
410 /** 0111 011w 0010 dest AND.size:G #IMM,dest */
414 tprintf ("%x & %x = %x\n", v, imm, v & imm);
419 /** 1001 0dst AND.B:S #IMM8,dest */
422 dc = decode_dest3 (dst, 0);
424 tprintf("%x & %x = %x\n", v, imm, v & imm);
429 /** 1001 000w srcx dest AND.size:G src.dest */
432 tprintf ("%x & %x = %x\n", a, b, a & b);
437 /** 0001 0d sr AND.B:S src,R0L/R0H */
439 sc = decode_src2 (sr, 0, d);
440 dc = decode_dest1 (d, 0);
444 tprintf("%x & %x = %x\n", a, b, v);
448 /** 0111 1110 0100 srcx BAND src */
450 BIT_OPC (srcx, b & carry);
452 /** 0111 1110 1000 dest BCLR:G dest */
454 dc = decode_bit (dest);
457 /** 0100 0bit BCLR:S bit,base:11[SB] */
459 dc = decode_bit11 (bit);
462 /** 0111 1110 0010 dest BMcnd dest */
464 dc = decode_bit (dest);
465 if (condition_true (bmcnd_cond_map [IMM (0) & 15]))
470 /** 0111 1101 1101 cond BMcnd C */
472 if (condition_true (cond))
477 /** 0111 1110 0101 srcx BNAND src */
479 BIT_OPC (srcx, (!b) & carry);
481 /** 0111 1110 0111 srcx BNOR src */
483 BIT_OPC (srcx, (!b) | carry);
485 /** 0111 1110 1010 dest BNOT:G dest */
489 /** 0101 0bit BNOT:S bit,base:11[SB] */
491 dc = decode_bit11 (bit);
492 put_bit (dc, !get_bit (dc));
494 /** 0111 1110 0011 srcx BNTST src */
496 dc = decode_bit (srcx);
500 /** 0111 1110 1101 srcx BNXOR src */
502 BIT_OPC (srcx, !b ^ carry);
504 /** 0111 1110 0110 srcx BOR src */
506 BIT_OPC (srcx, b | carry);
510 /* We report the break to our caller with the PC still pointing at the
511 breakpoint instruction. */
512 put_reg (pc, orig_pc);
515 return M32C_MAKE_HIT_BREAK ();
517 /** 0111 1110 1001 dest BSET:G dest */
519 dc = decode_bit (dest);
522 /** 0100 1bit BSET:S bit,base:11[SB] */
524 dc = decode_bit11 (bit);
527 /** 0111 1110 1011 srcx BTST:G src */
529 dc = decode_bit (srcx);
533 /** 0101 1bit BTST:S bit,base:11[SB] */
535 dc = decode_bit11 (bit);
539 /** 0111 1110 0000 dest BTSTC dest */
541 dc = decode_bit (dest);
546 /** 0111 1110 0001 dest BTSTS dest */
548 dc = decode_bit (dest);
553 /** 0111 1110 1100 srcx BXOR src */
555 BIT_OPC (srcx, b ^ carry);
557 /** 0111 011w 1000 dest CMP.size:G #IMM,dest */
563 /** 1101 000w immm dest CMP.size:Q #IMM,dest */
566 immm = sign_ext (immm, 4);
569 /** 1110 0dst CMP.B:S #IMM8,dest */
572 dc = decode_dest3 (dst, 0);
576 /** 1100 000w srcx dest CMP.size:G src,dest */
581 /** 0011 1d sr CMP.B:S src,R0L/R0H */
583 sc = decode_src2 (sr, 0, d);
584 dc = decode_dest1 (d, 0);
589 /** 0111 110w 1110 i1c s DADC,DADD,DSBB,DSUB */
591 /* 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);
630 /** 1010 1dst DEC.B dest */
632 dc = decode_dest3 (dst, 0);
634 tprintf("%x -- = %x\n", v, v-1);
639 /** 1111 d010 DEC.W dest */
641 v = get_reg (d ? a1 : a0);
642 tprintf("%x -- = %x\n", v, v-1);
645 put_reg (d ? a1 : a0, v);
647 /** 0111 110w 1110 0001 DIV.size #IMM */
649 div_op (-1, 0, 0, w);
651 /** 0111 011w 1101 srcx DIV.size src */
653 div_op (srcx, 0, 0, w);
655 /** 0111 110w 1110 0000 DIVU.size #IMM */
657 div_op (-1, 1, 0, w);
659 /** 0111 011w 1100 srcx DIVU.size src */
661 div_op (srcx, 1, 0, w);
663 /** 0111 110w 1110 0011 DIVX.size #IMM */
665 div_op (-1, 0, 1, w);
667 /** 0111 011w 1001 srcx DIVX.size src */
669 div_op (srcx, 0, 1, w);
671 /** 0111 1100 1111 0010 ENTER #IMM8 */
674 put_reg (sp, get_reg (sp) - 2);
675 mem_put_hi (get_reg (sp), get_reg (fb));
676 put_reg (fb, get_reg (sp));
677 put_reg (sp, get_reg (sp) - imm);
679 /** 0111 1101 1111 0010 EXITD */
681 put_reg (sp, get_reg (fb));
682 put_reg (fb, mem_get_hi (get_reg (sp)));
683 put_reg (sp, get_reg (sp) + 2);
684 put_reg (pc, mem_get_psi (get_reg (sp)));
685 put_reg (sp, get_reg (sp) + 3);
687 /** 0111 1100 0110 dest EXTS.B dest */
689 dc = decode_srcdest4 (dest, 0);
690 v = sign_ext (get_src (dc), 8);
695 /** 0111 1100 1111 0011 EXTS.W R0 */
697 v = sign_ext (get_reg (r0), 16);
701 /** 1110 1011 0flg 0101 FCLR dest */
703 set_flags (1 << flg, 0);
705 /** 1110 1011 0flg 0100 FSET dest */
707 set_flags (1 << flg, 1 << flg);
709 /** 1010 0dst INC.B dest */
711 dc = decode_dest3 (dst, 0);
713 tprintf("%x ++ = %x\n", v, v+1);
718 /** 1011 d010 INC.W dest */
720 v = get_reg (d ? a1 : a0);
721 tprintf("%x ++ = %x\n", v, v+1);
724 put_reg (d ? a1 : a0, v);
726 /** 1110 1011 11vector INT #imm */
728 trigger_based_interrupt (vector);
730 /** 1111 0110 INTO */
733 trigger_fixed_interrupt (0xffe0);
735 /** 0110 1cnd Jcnd label */
737 v = sign_ext (IMM(0), 8);
738 if (condition_true (cnd))
739 put_reg (pc, orig_pc + 1 + v);
741 /** 0111 1101 1100 cond Jcnd label */
743 v = sign_ext (IMM(0), 8);
744 if (condition_true (cond))
745 put_reg (pc, orig_pc + 2 + v);
747 /** 0110 0dsp JMP.S label */
749 put_reg (pc, orig_pc + 2 + dsp);
751 /** 1111 1110 JMP.B label */
753 imm = sign_ext (IMM(0), 8);
757 printf("[jmp-to-self detected as exit]\n");
758 return M32C_MAKE_HIT_BREAK ();
760 put_reg (pc, orig_pc + 1 + imm);
762 /** 1111 0100 JMP.W label */
764 imm = sign_ext (IMM(1), 16);
765 put_reg (pc, orig_pc + 1 + imm);
767 /** 1111 1100 JMP.A label */
772 /** 0111 1101 0010 srcx JMPI.W src */
774 sc = decode_jumpdest (srcx, 1);
776 a = sign_ext (a, 16);
777 put_reg (pc, orig_pc + a);
779 /** 0111 1101 0000 srcx JMPI.A src */
781 sc = decode_jumpdest (srcx, 0);
785 /** 1110 1110 JMPS #IMM8 */
790 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
793 /** 1111 0101 JSR.W label */
795 imm = sign_ext (IMM(1), 16);
796 put_reg (sp, get_reg (sp) - 3);
797 mem_put_psi (get_reg (sp), get_reg (pc));
798 put_reg (pc, orig_pc + imm + 1);
800 /** 1111 1101 JSR.A label */
803 put_reg (sp, get_reg (sp) - 3);
804 mem_put_psi (get_reg (sp), get_reg (pc));
807 /** 0111 1101 0011 srcx JSRI.W src */
809 sc = decode_jumpdest (srcx, 1);
811 a = sign_ext (a, 16);
813 put_reg (sp, get_reg (sp) - 3);
814 mem_put_psi (get_reg (sp), get_reg (pc));
815 put_reg (pc, orig_pc + a);
817 /** 0111 1101 0001 srcx JSRI.A src */
819 sc = decode_jumpdest (srcx, 0);
822 put_reg (sp, get_reg (sp) - 3);
823 mem_put_psi (get_reg (sp), get_reg (pc));
826 /** 1110 1111 JSRS #IMM8 */
831 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
833 put_reg (sp, get_reg (sp) - 3);
834 mem_put_psi (get_reg (sp), get_reg (pc));
837 /** 1110 1011 0reg 0000 LDC #IMM16,dest */
839 dc = decode_cr (reg);
843 /** 0111 1010 1reg srcx LDC src,dest */
845 dc = decode_cr (reg);
846 sc = decode_srcdest4 (srcx,1);
847 put_dest (dc, get_src (sc));
849 /** 0111 1100 1111 0000 LDCTX abs16,abs20 */
853 /** 0111 010w 1000 dest LDE.size abs20,dest */
855 dc = decode_srcdest4 (dest, w);
858 v = mem_get_hi (imm);
860 v = mem_get_qi (imm);
863 /** 0111 010w 1001 dest LDE.size dsp:20[a0], dest */
865 dc = decode_srcdest4 (dest, w);
866 imm = IMM(2) + get_reg (a0);
868 v = mem_get_hi (imm);
870 v = mem_get_qi (imm);
873 /** 0111 010w 1010 dest LDE.size [a1a0],dest */
875 dc = decode_srcdest4 (dest, w);
876 imm = get_reg (a1a0);
878 v = mem_get_hi (imm);
880 v = mem_get_qi (imm);
883 /** 0111 1101 1010 0imm LDIPL #IMM */
885 set_flags (0x700, imm*0x100);
887 /** 0111 010w 1100 dest MOV.size:G #IMM,dest */
889 dc = decode_srcdest4 (dest, w);
892 tprintf("%x = %x\n", v, v);
896 /** 1101 100w immm dest MOV.size:Q #IMM,dest */
898 dc = decode_srcdest4 (dest, w);
899 v = sign_ext (immm, 4);
900 tprintf ("%x = %x\n", v, v);
904 /** 1100 0dst MOV.B:S #IMM8,dest */
907 dc = decode_dest3 (dst, 0);
909 tprintf("%x = %x\n", v, v);
913 /** 1w10 d010 MOV.size:S #IMM,dest */
915 /* Note that for w, 0=W and 1=B unlike the usual meaning. */
917 tprintf("%x = %x\n", v, v);
919 put_reg (d ? a1 : a0, v);
921 /** 1011 0dst MOV.B:Z #0,dest */
923 dc = decode_dest3 (dst, 0);
928 /** 0111 001w srcx dest MOV.size:G src,dest */
930 sc = decode_srcdest4 (srcx, w);
931 dc = decode_srcdest4 (dest, w);
936 /** 0011 0d sr MOV.B:S src,dest */
938 sc = decode_src2 (sr, 0, d);
941 put_reg (d ? a1 : a0, v);
943 /** 0000 0s ds MOV.B:S R0L/R0H,dest */
947 dc = decode_src2 (ds, 0, s);
948 v = get_reg (s ? r0h : r0l);
952 /** 0000 1d sr MOV.B:S src,R0L/R0H */
954 sc = decode_src2 (sr, 0, d);
957 put_reg (d ? r0h : r0l, v);
959 /** 0111 010w 1011 dest MOV.size:G dsp:8[SP], dest */
961 dc = decode_srcdest4 (dest, w);
963 a = get_reg (sp) + sign_ext (imm, 8);
972 /** 0111 010w 0011 srcx MOV.size:G src, disp8[SP] */
974 sc = decode_srcdest4 (srcx, w);
976 a = get_reg (sp) + sign_ext (imm, 8);
985 /** 1110 1011 0reg 1src MOVA src,dest */
988 static reg_id map[] = { r0, r1, r2, r3, a0, a1, 0, 0 };
989 sc = decode_srcdest4 (8 + src, 0);
990 put_reg (map[reg], sc.u.addr);
993 /** 0111 1100 10hl dest MOVdir R0L,dest */
995 if (dest == 0 || dest == 4 || dest == 5)
997 dc = decode_srcdest4 (dest, 0);
1002 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1003 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1004 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1005 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1009 /** 0111 1100 00hl srcx MOVdir src,R0L */
1011 if (srcx == 0 || srcx == 4 || srcx == 5)
1013 sc = decode_srcdest4 (srcx, 0);
1018 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1019 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1020 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1021 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1025 /** 0111 110w 0101 dest MUL.size #IMM,dest */
1028 imm = sign_ext (IMM(w), w?16:8);
1029 tprintf("%d * %d = %d\n", v, imm, v*imm);
1034 /** 0111 100w srcx dest MUL.size src,dest */
1038 tprintf("%d * %d = %d\n", a, b, v);
1042 /** 0111 110w 0100 dest MULU.size #IMM,dest */
1046 tprintf("%u * %u = %u\n", v, imm, v*imm);
1051 /** 0111 000w srcx dest MULU.size src,dest */
1055 tprintf("%u * %u = %u\n", a, b, v);
1059 /** 0111 010w 0101 dest NEG.size dest */
1062 tprintf("%d * -1 = %d\n", v, -v);
1064 set_oszc (v, w+1, v == 0);
1067 /** 0000 0100 NOP */
1071 /** 0111 010w 0111 dest NOT.size:G */
1074 tprintf("~ %x = %x\n", v, ~v);
1079 /** 1011 1dst NOT.B:S dest */
1081 dc = decode_dest3 (dst, 0);
1083 tprintf("~ %x = %x\n", v, ~v);
1088 /** 0111 011w 0011 dest OR.size:G #IMM,dest */
1092 tprintf ("%x | %x = %x\n", v, imm, v | imm);
1097 /** 1001 1dst OR.B:S #IMM8,dest */
1100 dc = decode_dest3 (dst, 0);
1102 tprintf("%x | %x = %x\n", v, imm, v|imm);
1107 /** 1001 100w srcx dest OR.size:G src,dest */
1110 tprintf ("%x | %x = %x\n", a, b, a | b);
1115 /** 0001 1d sr OR.B:S src,R0L/R0H */
1117 sc = decode_src2 (sr, 0, d);
1118 dc = decode_dest1 (d, 0);
1122 tprintf("%x | %x = %x\n", a, b, v);
1126 /** 0111 010w 1101 dest POP.size:G dest */
1128 dc = decode_srcdest4 (dest, w);
1131 v = mem_get_hi (get_reg (sp));
1132 put_reg (sp, get_reg (sp) + 2);
1133 tprintf("pophi: %x\n", v);
1137 v = mem_get_qi (get_reg (sp));
1138 put_reg (sp, get_reg (sp) + 1);
1139 tprintf("popqi: %x\n", v);
1143 /** 1001 d010 POP.B:S dest */
1145 v = mem_get_qi (get_reg (sp));
1146 put_reg (d ? r0h : r0l, v);
1147 put_reg (sp, get_reg (sp) + 1);
1148 tprintf("popqi: %x\n", v);
1150 /** 1101 d010 POP.W:S dest */
1152 v = mem_get_hi (get_reg (sp));
1153 put_reg (d ? a1 : a0, v);
1154 put_reg (sp, get_reg (sp) + 2);
1155 tprintf("pophi: %x\n", v);
1157 /** 1110 1011 0reg 0011 POPC dest */
1159 dc = decode_cr (reg);
1160 v = mem_get_hi (get_reg (sp));
1162 put_reg (sp, get_reg (sp) + 2);
1163 tprintf("popc: %x\n", v);
1165 /** 1110 1101 POPM dest */
1168 static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1170 tprintf("popm: %x\n", imm);
1174 v = mem_get_hi (get_reg (sp));
1175 put_reg (map[a], v);
1176 put_reg (sp, get_reg (sp) + 2);
1180 /** 0111 110w 1110 0010 PUSH.size:G #IMM */
1185 put_reg (sp, get_reg (sp) - 2);
1186 mem_put_hi (get_reg (sp), imm);
1187 tprintf("pushhi %04x\n", imm);
1191 put_reg (sp, get_reg (sp) - 1);
1192 mem_put_qi (get_reg (sp), imm);
1193 tprintf("pushqi %02x\n", imm);
1196 /** 0111 010w 0100 srcx PUSH.size:G src */
1198 sc = decode_srcdest4 (srcx, w);
1202 put_reg (sp, get_reg (sp) - 2);
1203 mem_put_hi (get_reg (sp), v);
1204 tprintf("pushhi: %x\n", v);
1208 put_reg (sp, get_reg (sp) - 1);
1209 mem_put_qi (get_reg (sp), v);
1210 tprintf("pushqi: %x\n", v);
1213 /** 1000 s010 PUSH.B:S src */
1215 v = get_reg (s ? r0h : r0l);
1216 put_reg (sp, get_reg (sp) - 1);
1217 mem_put_qi (get_reg (sp), v);
1218 tprintf("pushqi: %x\n", v);
1220 /** 1100 s010 PUSH.W:S src */
1222 v = get_reg (s ? a1 : a0);
1223 put_reg (sp, get_reg (sp) - 2);
1224 mem_put_hi (get_reg (sp), v);
1225 tprintf("pushhi: %x\n", v);
1227 /** 0111 1101 1001 srcx PUSHA src */
1229 sc = decode_srcdest4 (srcx, 0);
1230 put_reg (sp, get_reg (sp) - 2);
1231 mem_put_hi (get_reg (sp), sc.u.addr);
1232 tprintf("pushhi: %x\n", sc.u.addr);
1234 /** 1110 1011 0src 0010 PUSHC src */
1236 sc = decode_cr (src);
1237 put_reg (sp, get_reg (sp) - 2);
1239 mem_put_hi (get_reg (sp), v);
1240 tprintf("pushc: %x\n", v);
1242 /** 1110 1100 PUSHM src */
1245 static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1247 tprintf("pushm: %x\n", imm);
1251 put_reg (sp, get_reg (sp) - 2);
1252 v = get_reg (map[a]);
1253 mem_put_hi (get_reg (sp), v);
1257 /** 1111 1011 REIT */
1261 + 4096 * (mem_get_qi (a+3) & 0xf0));
1262 b = (mem_get_qi (a+2)
1263 + 256 * (mem_get_qi (a+3) & 0xff));
1266 put_reg (sp, get_reg (sp) + 4);
1268 /** 0111 110w 1111 0001 RMPA.size */
1271 int count = get_reg (r3);
1272 int list1 = get_reg (a0);
1273 int list2 = get_reg (a1);
1274 int sum = get_reg (w ? r2r0 : r0);
1280 a = sign_ext (mem_get_hi (list1), 16);
1281 b = sign_ext (mem_get_hi (list2), 16);
1285 a = sign_ext (mem_get_qi (list1), 8);
1286 b = sign_ext (mem_get_qi (list2), 8);
1288 tprintf("%d + %d * %d = ", sum, a, b);
1290 tprintf("%d\n", sum);
1295 put_reg (r3, count);
1296 put_reg (a0, list1);
1297 put_reg (a1, list2);
1298 put_reg (w ? r2r0 : r0, sum);
1301 /** 0111 011w 1010 dest ROLC.size dest */
1303 dc = decode_srcdest4 (dest, w);
1306 /** 0111 011w 1011 dest RORC.size dest */
1308 dc = decode_srcdest4 (dest, w);
1311 /** 1110 000w immm dest ROT.size #IMM,dest */
1313 dc = decode_srcdest4 (dest, w);
1314 rot_op (dc, 0, IMM4());
1316 /** 0111 010w 0110 dest ROT.size R1H,dest */
1318 dc = decode_srcdest4 (dest, w);
1319 rot_op (dc, 0, sign_ext (get_reg (r1h), 8));
1321 /** 1111 0011 RTS */
1323 put_reg (pc, mem_get_psi (get_reg (sp)));
1324 put_reg (sp, get_reg (sp) + 3);
1326 /** 0111 011w 0111 dest SBB.size #IMM,dest */
1328 dc = decode_srcdest4 (dest, w);
1330 MATH_OP (dc, imm, !carry, -, >= 0);
1332 /** 1011 100w srcx dest SBB.size src,dest */
1334 sc = decode_srcdest4(srcx, w);
1335 dc = decode_srcdest4(dest, w);
1337 MATH_OP (dc, b, !carry, -, >= 0);
1339 /** 1111 000w immm dest SHA.size #IMM, dest */
1341 dc = decode_srcdest4(dest, w);
1342 shift_op (dc, 1, IMM4());
1344 /** 0111 010w 1111 dest SHA.size R1H,dest */
1346 dc = decode_srcdest4(dest, w);
1347 a = sign_ext (get_reg (r1h), 8);
1348 shift_op (dc, 1, a);
1350 /** 1110 1011 101d immm SHA.L #IMM, dest */
1352 dc = reg_sd (d ? r3r1 : r2r0);
1353 shift_op (dc, 1, IMM4());
1355 /** 1110 1011 001d 0001 SHA.L R1H,dest */
1357 dc = reg_sd (d ? r3r1 : r2r0);
1358 a = sign_ext (get_reg (r1h), 8);
1359 shift_op (dc, 1, a);
1361 /** 1110 100w immm dest SHL.size #IMM, dest */
1363 dc = decode_srcdest4(dest, w);
1364 shift_op (dc, 0, IMM4());
1366 /** 0111 010w 1110 dest SHL.size R1H,dest */
1368 dc = decode_srcdest4(dest, w);
1369 a = sign_ext (get_reg (r1h), 8);
1370 shift_op (dc, 0, a);
1372 /** 1110 1011 100d immm SHL.L #IMM,dest */
1374 dc = reg_sd (d ? r3r1 : r2r0);
1375 shift_op (dc, 0, IMM4());
1377 /** 1110 1011 000d 0001 SHL.L R1H,dest */
1379 dc = reg_sd (d ? r3r1 : r2r0);
1380 a = sign_ext (get_reg (r1h), 8);
1381 shift_op (dc, 0, a);
1383 /** 0111 110w 1110 100b SMOVB.size */
1386 int count = get_reg (r3);
1387 int s1 = get_reg (a0) + (get_reg (r1h) << 16);
1388 int s2 = get_reg (a1);
1389 int inc = (w ? 2 : 1) * (b ? -1 : 1);
1395 v = mem_get_hi (s1);
1400 v = mem_get_qi (s1);
1407 put_reg (r3, count);
1408 put_reg (a0, s1 & 0xffff);
1410 put_reg (r1h, s1 >> 16);
1413 /** 0111 110w 1110 1010 SSTR.size */
1416 int count = get_reg (r3);
1417 int s1 = get_reg (a1);
1418 v = get_reg (w ? r0 : r0l);
1434 put_reg (r3, count);
1438 /** 0111 1011 1src dest STC src,dest */
1440 dc = decode_srcdest4 (dest, 1);
1441 sc = decode_cr (src);
1442 put_dest (dc, get_src(sc));
1444 /** 0111 1100 1100 dest STC PC,dest */
1446 dc = decode_srcdest4 (dest, 1);
1448 put_dest (dc, orig_pc);
1450 /** 0111 1101 1111 0000 STCTX abs16,abs20 */
1454 /** 0111 010w 0000 srcx STE.size src,abs20 */
1456 sc = decode_srcdest4 (srcx, w);
1463 if (srcx == 4 || srcx == 5)
1465 v = get_reg (sc.u.reg);
1471 /** 0111 010w 0001 srcx STE.size src,disp20[a0] */
1473 sc = decode_srcdest4 (srcx, w);
1474 a = get_reg(a0) + IMM(2);
1480 if (srcx == 4 || srcx == 5)
1482 v = get_reg (sc.u.reg);
1488 /** 0111 010w 0010 srcx STE.size src,[a1a0] */
1490 sc = decode_srcdest4 (srcx, w);
1497 if (srcx == 4 || srcx == 5)
1499 v = get_reg (sc.u.reg);
1505 /** 1101 0dst STNZ #IMM8,dest */
1508 dc = decode_dest3(dst, 0);
1512 /** 1100 1dst STZ #IMM8,dest */
1515 dc = decode_dest3(dst, 0);
1519 /** 1101 1dst STZX #IMM81,#IMM82,dest */
1522 dc = decode_dest3(dst, 0);
1529 /** 0111 011w 0101 dest SUB.size:G #IMM,dest */
1531 dc = decode_srcdest4 (dest, w);
1533 MATH_OP (dc, imm, 0, -, >= 0);
1535 /** 1000 1dst SUB.B:S #IMM8,dest */
1538 dc = decode_dest3 (dst, 0);
1539 MATH_OP (dc, imm, 0, -, >= 0);
1541 /** 1010 100w srcx dest SUB.size:G src,dest */
1543 sc = decode_srcdest4(srcx, w);
1544 dc = decode_srcdest4(dest, w);
1546 MATH_OP (dc, b, 0, -, >= 0);
1548 /** 0010 1d sr SUB.B:S src,R0L/R0H */
1550 sc = decode_src2 (sr, 0, d);
1551 dc = decode_dest1 (d, 0);
1553 MATH_OP (dc, b, 0, -, >= 0);
1555 /** 0111 011w 0000 dest TST.size #IMM, dest */
1559 tprintf ("%x & %x = %x\n", v, imm, v & imm);
1563 /** 1000 000w srcx dest TST.size src,dest */
1566 tprintf ("%x & %x = %x\n", a, b, a & b);
1570 /** 1111 1111 UND */
1572 trigger_fixed_interrupt (0xffdc);
1574 /** 0111 1101 1111 0011 WAIT */
1576 tprintf("waiting...\n");
1578 /** 0111 101w 00sr dest XCHG.size src,dest */
1580 sc = decode_srcdest4 (sr, w);
1581 dc = decode_srcdest4 (dest, w);
1587 /** 0111 011w 0001 dest XOR.size #IMM,dest */
1591 tprintf ("%x ^ %x = %x\n", v, imm, v ^ imm);
1596 /** 1000 100w srcx dest XOR.size src,dest */
1599 tprintf ("%x ^ %x = %x\n", a, b, a ^ b);