]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m32c/m32c.opc
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / sim / m32c / m32c.opc
1 /* m32c.opc --- semantics for m32c opcodes. -*- mode: c -*-
2
3 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
5
6 This file is part of the GNU simulators.
7
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.
12
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.
17
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
21 02110-1301, USA */
22
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include "cpu.h"
28 #include "mem.h"
29 #include "misc.h"
30 #include "int.h"
31
32 #define AU __attribute__((unused))
33
34 #define tprintf if (trace) printf
35
36 static unsigned char
37 getbyte ()
38 {
39 int tsave = trace;
40 unsigned char b;
41
42 if (trace == 1)
43 trace = 0;
44 b = mem_get_pc ();
45 regs.r_pc ++;
46 trace = tsave;
47 return b;
48 }
49
50 #define M32C_ONLY() /* FIXME: add something here */
51
52 #define GETBYTE() (op[opi++] = getbyte())
53
54 #define UNSUPPORTED() unsupported("unsupported", orig_pc)
55 #define NOTYET() unsupported("unimplemented", orig_pc)
56
57 static void
58 unsupported (char *tag, int orig_pc)
59 {
60 int i;
61 printf("%s opcode at %08x\n", tag, orig_pc);
62 regs.r_pc = orig_pc;
63 for (i=0; i<2; i++)
64 {
65 int b = mem_get_pc();
66 printf(" %s", bits(b>>4, 4));
67 printf(" %s", bits(b, 4));
68 regs.r_pc ++;
69 }
70 printf("\n");
71 regs.r_pc = orig_pc;
72 for (i=0; i<6; i++)
73 {
74 printf(" %02x", mem_get_pc ());
75 regs.r_pc ++;
76 }
77 printf("\n");
78 exit(1);
79 }
80
81 static int
82 IMM(int bytes)
83 {
84 int rv = 0;
85 switch (bytes)
86 {
87 case 1:
88 rv = mem_get_qi (get_reg(pc));
89 break;
90 case 2:
91 rv = mem_get_hi (get_reg(pc));
92 break;
93 case 3:
94 rv = mem_get_psi (get_reg(pc));
95 break;
96 case 4:
97 rv = mem_get_si (get_reg(pc));
98 break;
99 }
100 regs.r_pc += bytes;
101 return rv;
102 }
103
104 #define IMM4() (immm >= 8 ? 7 - immm : immm + 1)
105
106 #define NO_PREFIX() PREFIX(0,0,0)
107
108 /* Indicate which sorts of prefixes are allowed for the current
109 opcode. */
110 void
111 prefix (src_allowed, dest_allowed, index_bytewidth)
112 {
113 /* At the moment, we don't do anything with this information. We
114 just wanted to get the information entered in some
115 machine-readable form while we were going through all the
116 opcodes. */
117 }
118
119 #define MATH_OP(dc,s,c,op) \
120 { \
121 int ma, mb; \
122 ma = get_src(dc); \
123 mb = s & b2mask[dc.bytes]; \
124 ll = (long long)ma op (long long)mb op c; \
125 tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%llx\n", ma, mb, c, ll); \
126 ma = sign_ext (ma, dc.bytes * 8); \
127 mb = sign_ext (s, dc.bytes * 8); \
128 v = ma op mb op c; \
129 tprintf("%d " #op " %d " #op " %d = %d\n", ma, mb, c, v); \
130 set_oszc (v, dc.bytes, ll > ((1 op 1) ? b2mask[dc.bytes] : 0)); \
131 put_dest (dc, v); \
132 }
133
134 #define LOGIC_OP(dc,s,op) \
135 { \
136 int ma, mb; \
137 ma = get_src(dc); \
138 mb = s & b2mask[dc.bytes]; \
139 v = ma op mb; \
140 tprintf("0x%x " #op " 0x%x = 0x%x\n", ma, mb, v); \
141 set_sz (v, dc.bytes); \
142 put_dest (dc, v); \
143 }
144
145 #define BIT_OP(dc,bit,expr) \
146 b = get_bit2 (dc, bitindex == -1 ? bit : bitindex); \
147 v = expr; \
148 tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n", \
149 b, bitindex == -1 ? bit : bitindex, carry, #expr, v); \
150 put_bit2 (dc, bitindex == -1 ? bit : bitindex, v);
151
152 #define BIT_OPC(dc,bit,expr) \
153 b = get_bit2 (dc, bitindex == -1 ? bit : bitindex); \
154 v = expr; \
155 tprintf ("b=%d, bit=%d, carry=%d, %s = %d\n", \
156 b, bitindex == -1 ? bit : bitindex, carry, #expr, v); \
157 set_c (v);
158
159 #define carry (FLAG_C ? 1 : 0)
160
161 static void
162 cmp (int d, int s, int bytes)
163 {
164 int a, b, f=0;
165 a = d - s;
166 b = sign_ext (d, bytes*8) - sign_ext (s, bytes*8);
167 tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
168 d, s, a,
169 sign_ext(d,bytes*8), sign_ext(s,bytes*8), b);
170
171 if (b == 0)
172 f |= FLAGBIT_Z;
173 if (b & b2signbit[bytes])
174 f |= FLAGBIT_S;
175 if ((d & b2mask[bytes]) >= (s & b2mask[bytes]))
176 f |= FLAGBIT_C;
177 if (b < b2minsigned[bytes] || b > b2maxsigned[bytes])
178 f |= FLAGBIT_O;
179
180 set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
181 }
182
183 static void
184 dadd_op (int ddd, int dd, int sss, int ss, int imm, int add, int cy, int w)
185 {
186 srcdest sc, dc;
187 int a, b=0, res;
188
189 prefix (0, 0, 0);
190
191 if (!imm)
192 {
193 sc = decode_src23 (sss, ss, w+1);
194 b = get_src (sc);
195 }
196 dc = decode_dest23 (ddd, dd, w+1);
197 a = get_src (dc);
198 if (imm)
199 b = IMM(w+1);
200
201 a = bcd2int(a, w);
202 b = bcd2int(b, w);
203
204 tprintf("decimal: %d %s %d", a, add?"+":"-", b);
205 if (cy)
206 tprintf(" c=%d", carry);
207
208 if (add)
209 {
210 res = a + b;
211 if (cy)
212 res += carry;
213 cy = res > (w ? 9999 : 99);
214 }
215 else
216 {
217 res = a - b;
218 if (cy)
219 res -= (1-carry);
220 cy = res >= 0;
221 if (res < 0)
222 res += w ? 10000 : 100;
223 }
224
225 res = int2bcd (res, w);
226 tprintf(" = %x\n", res);
227
228 set_szc (res, w+1, cy);
229
230 put_dest (dc, res);
231 }
232 #define DADDV(A,C) dadd_op(ddd, dd, sss, ss, 0, A, C, w)
233 #define DADDI(A,C) dadd_op(ddd, dd, 0, 0, 1, A, C, w)
234
235 static void
236 div_op (int sss, int ss, int u, int x, int bytes)
237 {
238 srcdest sc;
239 int s, v, a, b;
240
241 if (sss == -1)
242 s = IMM(bytes);
243 else
244 {
245 sc = decode_dest23 (sss, ss, bytes);
246 s = get_src (sc);
247 }
248
249 v = get_reg (bytes > 1 ? r2r0 : r0);
250
251 if (!u)
252 {
253 /* FIXME? do we sign extend a0/a1 to .L? Docs say zero extend. */
254 s = sign_ext (s, bytes*8);
255 v = sign_ext (v, bytes*8);
256 }
257
258 if (s == 0)
259 {
260 set_flags (FLAGBIT_O, FLAGBIT_O);
261 return;
262 }
263
264 if (u)
265 {
266 a = (unsigned int)v / (unsigned int)s;
267 b = (unsigned int)v % (unsigned int)s;
268 }
269 else
270 {
271 a = v / s;
272 b = v % s;
273 }
274 if (x)
275 {
276 if ((s > 0 && b < 0)
277 || (s < 0 && b > 0))
278 {
279 a --;
280 b += s;
281 }
282 }
283 tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
284 if ((!u && (a > b2maxsigned[bytes]
285 || a < b2minsigned[bytes]))
286 || (u && (a > b2mask[bytes])))
287 set_flags (FLAGBIT_O, FLAGBIT_O);
288 else
289 set_flags (FLAGBIT_O, 0);
290
291 switch (bytes)
292 {
293 case 1:
294 put_reg (r0l, a);
295 put_reg (r0h, b);
296 break;
297 case 2:
298 put_reg (r0, a);
299 put_reg (r2, b);
300 break;
301 case 4:
302 put_reg (r2r0, a);
303 break;
304 }
305 }
306
307 static void
308 index_op (int sss, int ss, int do_s, int do_d, int scale, int w)
309 {
310 srcdest sc = decode_src23 (sss, ss, w+1);
311 int v = get_src (sc) * scale;
312 tprintf("%d = %d * %d, %d %d\n", v, get_src(sc), scale, do_s, do_d);
313 decode_index (do_s * v, do_d * v);
314 }
315 #define INDEXOP(scale,do_s,do_d) \
316 index_op (sss, ss, do_s, do_d, scale, w); goto next_opcode
317
318 static void
319 rot_op (srcdest sd, int rotc, int count)
320 {
321 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
322 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
323 int v = get_src (sd);
324 int c = carry, ct;
325
326 tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
327 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
328 while (count > 0)
329 {
330 ct = (v & msb) ? 1 : 0;
331 v <<= 1;
332 v |= rotc ? c : ct;
333 v &= mask;
334 c = ct;
335 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
336 count --;
337 }
338 while (count < 0)
339 {
340 ct = v & 1;
341 v >>= 1;
342 v |= (rotc ? c : ct) * msb;
343 c = ct;
344 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
345 count ++;
346 }
347 put_dest (sd, v);
348 set_szc (v, sd.bytes, c);
349 }
350
351 static void
352 shift_op (srcdest sd, int arith, int count, int setc)
353 {
354 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
355 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
356 int v = get_src (sd);
357 int c = 0;
358 int o = 0;
359
360 if (sd.bytes == 4)
361 {
362 mask = 0xffffffffU;
363 msb = 0x80000000U;
364 }
365
366 tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
367 tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
368 while (count > 0)
369 {
370 c = (v & msb) ? 1 : 0;
371 v <<= 1;
372 v &= mask;
373 if (c != ((v & msb) ? 1 : 0))
374 o = 1;
375 tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
376 count --;
377 }
378 while (count < 0)
379 {
380 c = v & 1;
381 if (arith)
382 v = (v & msb) | (v >> 1);
383 else
384 v = (v >> 1) & (msb - 1);
385 tprintf (": %s %d %d\n", bits(v, 8*sd.bytes), c, o);
386 count ++;
387 }
388 put_dest (sd, v);
389 set_sz (v, sd.bytes);
390 if (setc)
391 set_c (c);
392 set_flags (FLAGBIT_O, o ? FLAGBIT_O : 0);
393 }
394
395 int
396 decode_m32c()
397 {
398 unsigned char op[40];
399 int opi;
400 int orig_pc;
401 int v, a, b;
402 long long ll;
403 srcdest sc, dc;
404 int imm;
405 int bitindex = -1;
406 int t0, t1=0, t2, t3=0;
407 int ta0, ta1, dif;
408
409 step_result = M32C_MAKE_STEPPED ();
410
411 decode_indirect (0, 0);
412 decode_index (0, 0);
413
414 next_opcode:
415 opi = 0;
416 orig_pc = get_reg (pc);
417
418 tprintf("trace: decode pc = %06x\n", orig_pc);
419
420 /** VARY sss 000 001 010 011 100 */
421 /** VARY ddd 000 001 010 011 100 */
422
423 /** 0000 1001 indirect dest */
424
425 decode_indirect (0, 1);
426 goto next_opcode;
427
428 /** 0100 0001 indirect src */
429
430 decode_indirect (1, 0);
431 goto next_opcode;
432
433 /** 0100 1001 indirect src and dest */
434
435 decode_indirect (1, 1);
436 goto next_opcode;
437
438 /** 1010 ddd w dd01 1111 ABS.size dest */
439
440 prefix (0, 1, 0);
441 dc = decode_dest23 (ddd, dd, w+1);
442 v = sign_ext (get_src (dc), w?16:8);
443 a = v<0 ? -v : v;
444 tprintf("abs(%d) = %d\n", v, a);
445 set_osz(a, w+1);
446 put_dest (dc, a);
447
448 /** 0000 0001 1000 ddd w dd10 1110 ADC.size #IMM,dest */
449
450 prefix (0, 0, 0);
451 dc = decode_dest23 (ddd, dd, w+1);
452 imm = IMM (w+1);
453 MATH_OP (dc, imm, carry, +);
454
455 /** 0000 0001 1sss ddd w dd ss 0100 ADC.size src,dest */
456
457 prefix (0, 0, 0);
458 sc = decode_src23 (sss, ss, w+1);
459 dc = decode_dest23 (ddd, dd, w+1);
460 b = get_src (sc);
461 MATH_OP (dc, b, carry, +);
462
463 /** 1011 ddd w dd01 1110 ADCF.size dest */
464
465 prefix (0, 1, 0);
466 dc = decode_dest23 (ddd, dd, w+1);
467 MATH_OP (dc, 0, carry, +);
468
469 /** 1000 ddd w dd10 1110 ADD.size:G #IMM,dest */
470
471 prefix (0, 1, 0);
472 dc = decode_dest23(ddd, dd, w+1);
473 imm = IMM(w+1);
474 MATH_OP (dc, imm, 0, +);
475
476 /** 1000 ddd0 dd11 0001 ADD.L:G #IMM,dest */
477
478 prefix (0, 1, 0);
479 dc = decode_dest23(ddd, dd, 4);
480 imm = IMM(4);
481 MATH_OP (dc, imm, 0, +);
482
483 /** 111L ddd w dd11 immm ADD.size:Q #IMM,dest */
484
485 prefix (0, 1, 0);
486 dc = decode_dest23(ddd, dd, L ? 4 : (w+1));
487 imm = sign_ext (immm, 4);
488 MATH_OP (dc, imm, 0, +);
489
490 /** 00dd 011w ADD.size:S #IMM,dest */
491
492 prefix (0, 1, 0);
493 dc = decode_dest2(dd, w+1);
494 imm = IMM (w+1);
495 MATH_OP (dc, imm, 0, +);
496
497 /** 10i0 110d ADD.L:S #IMM,A0/A1 */
498
499 prefix (0, 0, 0);
500 dc = reg_sd (d ? a1 : a0);
501 imm = i ? 2 : 1;
502 MATH_OP (dc, imm, 0, +);
503
504 /** 1sss ddd w dd ss 1000 ADD.size:G src,dest */
505
506 prefix (1, 1, 0);
507 sc = decode_src23(sss, ss, w+1);
508 dc = decode_dest23(ddd, dd, w+1);
509 b = get_src (sc);
510 MATH_OP (dc, b, 0, +);
511
512 /** 1sss ddd1 dd ss 0010 ADD.L:G src,dest */
513
514 prefix (1, 1, 0);
515 sc = decode_src23(sss, ss, 4);
516 dc = decode_dest23(ddd, dd, 4);
517 b = get_src (sc);
518 MATH_OP (dc, b, 0, +);
519
520 /** 1011 0110 0001 0011 ADD.L:G #IMM16,SP */
521
522 prefix (0, 0, 0);
523 dc = reg_sd (sp);
524 b = sign_ext (IMM(2), 16);
525 MATH_OP (dc, b, 0, +);
526
527 /** 01ii 001i ADD.L:Q #IMM3,SP */
528
529 prefix (0, 0, 0);
530 dc = reg_sd (sp);
531 b = ii * 2 + i + 1;
532 MATH_OP (dc, b, 0, +);
533
534 /** 1011 0110 0000 0011 ADD.L:S #IMM8,SP */
535
536 prefix (0, 0, 0);
537 dc = reg_sd (sp);
538 b = sign_ext (IMM(1), 8);
539 MATH_OP (dc, b, 0, +);
540
541 /** 1000 ddd0 dd01 0001 ADDX #IMM,dest */
542
543 prefix (0, 1, 0);
544 dc = decode_dest23(ddd, dd, 4);
545 imm = sign_ext (IMM(1), 8);
546 MATH_OP (dc, imm, 0, +);
547
548 /** 1sss ddd0 dd ss 0010 ADDX src,dest */
549
550 prefix (1, 1, 0);
551 sc = decode_src23(sss, ss, 1);
552 dc = decode_dest23(ddd, dd, 4);
553 b = sign_ext (get_src (sc), 8);
554 MATH_OP (dc, b, 0, +);
555
556 /** 1111 ddd w dd01 immm ADJNZ.size #IMM,dest,label */
557
558 prefix (0, 0, 0);
559 dc = decode_dest23 (ddd, dd, w+1);
560 v = get_src (dc);
561 imm = sign_ext(immm, 4);
562 tprintf("%d + %d = %d\n", v, imm, v+imm);
563 v += imm;
564 put_dest (dc, v);
565 a = sign_ext (IMM(1), 8);
566 if ((v & (w ? 0xffff : 0xff)) != 0)
567 {
568 tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
569 put_reg (pc, orig_pc + 2 + a);
570 tprintf("%x\n", get_reg (pc));
571 }
572
573 /** 1000 ddd w dd11 1111 AND.size:G #IMM,dest */
574
575 prefix (0, 1, 0);
576 dc = decode_dest23(ddd, dd, w+1);
577 imm = IMM(w+1);
578 LOGIC_OP (dc, imm, &);
579
580 /** 01dd 110w AND.size:S #IMM,dest */
581
582 prefix (0, 1, 0);
583 dc = decode_dest2(dd, w+1);
584 imm = IMM (w+1);
585 LOGIC_OP (dc, imm, &);
586
587 /** 1sss ddd w dd ss 1101 AND.size:G src,dest */
588
589 prefix (1, 1, 0);
590 sc = decode_src23(sss, ss, w+1);
591 dc = decode_dest23(ddd, dd, w+1);
592 b = get_src (sc);
593 LOGIC_OP (dc, b, &);
594
595 /** 0000 0001 1101 sss0 ss00 1bit BAND src */
596
597 sc = decode_src23 (sss, ss, 1);
598 BIT_OPC (sc, bit, b & carry);
599
600 /** 1101 ddd0 dd11 0bit BCLR dest */
601
602 dc = decode_dest23 (ddd, dd, 1);
603 BIT_OP (dc, bit, 0);
604
605 /** 1100 ddd w dd10 1110 BITINDEX.size src */
606
607 prefix (0, 0, 0);
608 dc = decode_dest23 (ddd, dd, w+1);
609 bitindex = get_src (dc);
610 tprintf ("bitindex set to %d\n", bitindex);
611 goto next_opcode;
612
613 /** 1101 ddd0 dd01 0bit BMcnd dest */
614
615 prefix (0, 0, 0);
616 dc = decode_dest23 (ddd, dd, 1);
617 if (condition_true (IMM (1)))
618 put_bit2 (dc, bit, 1);
619 else
620 put_bit2 (dc, bit, 0);
621
622 /** 1101 1001 0c10 1cnd BMcnd C */
623
624 prefix (0, 0, 0);
625 if (condition_true (c * 8 + cnd))
626 set_c (1);
627 else
628 set_c (0);
629
630 /** 0000 0001 1101 sss0 ss01 1bit BNAND src */
631
632 prefix (0, 0, 0);
633 sc = decode_src23 (sss, ss, 1);
634 BIT_OPC (sc, bit, !b & carry);
635
636 /** 0000 0001 1101 sss0 ss11 0bit BNOR src */
637
638 prefix (0, 0, 0);
639 sc = decode_src23 (sss, ss, 1);
640 BIT_OPC (sc, bit, !b | carry);
641
642 /** 1101 ddd0 dd01 1bit BNOT dest */
643
644 prefix (0, 0, 0);
645 dc = decode_dest23 (ddd, dd, 1);
646 BIT_OP (dc, bit, !b);
647
648 /** 0000 0001 1101 sss0 ss00 0bit BNTST src */
649
650 prefix (0, 0, 0);
651 sc = decode_dest23 (sss, ss, 1);
652 b = get_bit2 (sc, bit);
653 set_zc (!b, !b);
654
655 /** 0000 0001 1101 sss0 ss11 1bit BNXOR src */
656
657 prefix (0, 0, 0);
658 sc = decode_src23 (sss, ss, 1);
659 BIT_OPC (sc, bit, !b ^ carry);
660
661 /** 0000 0001 1101 sss0 ss10 0bit BOR src */
662
663 prefix (0, 0, 0);
664 sc = decode_src23 (sss, ss, 1);
665 BIT_OPC (sc, bit, b | carry);
666
667 /** 0000 0000 BRK */
668
669 /* We report the break to our caller with the PC still pointing at the
670 breakpoint instruction. */
671 put_reg (pc, orig_pc);
672 if (verbose)
673 printf("[break]\n");
674 return M32C_MAKE_HIT_BREAK ();
675
676 /** 0000 1000 BRK */
677
678 if (verbose)
679 printf("[break2]\n");
680 return M32C_MAKE_HIT_BREAK ();
681
682 /** 1101 ddd0 dd11 1bit BSET dest */
683
684 dc = decode_dest23 (ddd, dd, 1);
685 BIT_OP (dc, bit, 1);
686
687 /** 1101 sss0 ss00 0bit BTST:G src */
688
689 prefix (0, 0, 0);
690 sc = decode_src23 (sss, ss, 1);
691 b = get_bit2 (sc, bit);
692 set_zc (!b, b);
693
694 /** 00bb 101b BTST:S src */
695
696 sc = decode_src23 (3, 3, 1); /* bit,base:19 */
697 b = get_bit2 (sc, bb*2 + b);
698 set_zc (!b, b);
699
700 /** 1101 ddd0 dd10 0bit BTSTC dest */
701
702 prefix (0, 0, 0);
703 sc = decode_dest23 (ddd, dd, 1);
704 b = get_bit2 (sc, bit);
705 set_zc (!b, b);
706 put_bit2 (sc, bit, 0);
707
708 /** 1101 ddd0 dd10 1bit BTSTS dest */
709
710 prefix (0, 0, 0);
711 sc = decode_dest23 (ddd, dd, 1);
712 b = get_bit2 (sc, bit);
713 set_zc (!b, b);
714 put_bit2 (sc, bit, 1);
715
716 /** 0000 0001 1101 sss0 ss10 1bit BXOR src */
717
718 prefix (0, 0, 0);
719 sc = decode_src23 (sss, ss, 1);
720 BIT_OPC (sc, bit, b ^ carry);
721
722 /** 0000 0001 1000 ddd w dd11 1110 CLIP.size #IMM1,#IMM2,dest */
723
724 prefix (0, 0, 0);
725 dc = decode_dest23 (ddd, dd, w+1);
726 a = sign_ext (IMM(w+1), w*8+8);
727 b = sign_ext (IMM(w+1), w*8+8);
728 v = sign_ext (get_src (dc), w*8+8);
729 tprintf("clip %d <= %d <= %d : ", a, v, b);
730 if (a > v)
731 v = a;
732 if (v > b)
733 v = b;
734 tprintf("%d\n", v);
735 put_dest (dc, v);
736
737 /** 1001 ddd w dd10 1110 CMP.size:G #IMM,dest */
738
739 prefix (0, 1, 0);
740 dc = decode_dest23 (ddd, dd, w+1);
741 v = get_src (dc);
742 imm = IMM(w+1);
743 cmp (v, imm, w+1);
744
745 /** 1010 ddd0 dd11 0001 CMP.L:G #IMM32,dest */
746
747 prefix (0, 1, 0);
748 dc = decode_dest23 (ddd, dd, 4);
749 v = get_src (dc);
750 imm = IMM(4);
751 cmp (v, imm, 4);
752
753 /** 1110 ddd w dd01 immm CMP.size:Q #IMM,dest */
754
755 prefix (0, 1, 0);
756 dc = decode_dest23 (ddd, dd, w+1);
757 v = get_src (dc);
758 immm = sign_ext (immm, 4);
759 cmp (v, immm, w+1);
760
761 /** 01dd 011w CMP.size:S #IMM,dest */
762
763 prefix (0, 1, 0);
764 dc = decode_dest2 (dd, w+1);
765 v = get_src (dc);
766 imm = sign_ext (IMM(w+1),w*8+8);
767 cmp (v, imm, w+1);
768
769 /** 1sss ddd w dd ss 0110 CMP.size:G src,dest */
770
771 prefix (1, 1, 0);
772 sc = decode_src23 (sss, ss, w+1);
773 dc = decode_dest23 (ddd, dd, w+1);
774 a = get_src (dc);
775 b = get_src (sc);
776 cmp (a, b, w+1);
777
778 /** 1sss ddd1 dd ss 0001 CMP.L:G src,dest */
779
780 prefix (1, 1, 0);
781 sc = decode_src23 (sss, ss, 4);
782 dc = decode_dest23 (ddd, dd, 4);
783 a = get_src (dc);
784 b = get_src (sc);
785 cmp (a, b, 4);
786
787 /** 01dd 000w CMP.size:S src,R0/R0L */
788
789 prefix (0, 1, 0);
790 dc = decode_dest2 (dd, w+1);
791 a = get_reg (w ? r0 : r0l);
792 b = get_src (dc);
793 cmp (a, b, w+1);
794
795 /** 1010 ddd0 dd01 0001 CMPX #IMM,dest */
796
797 prefix (0, 1, 0);
798 dc = decode_dest23 (ddd, dd, 4);
799 v = get_src (dc);
800 imm = sign_ext (IMM(1), 8);
801 cmp (v, imm, 4);
802
803 /** 0000 0001 1000 ddd w dd00 1110 DADC.size #IMM,dest */
804
805 DADDI(1,1);
806
807 /** 0000 0001 1sss ddd w dd ss 1000 DADC.size src,dest */
808
809 DADDV(1,1);
810
811 /** 0000 0001 1000 ddd w dd01 1110 DADD.size #IMM,dest */
812
813 DADDI(1,0);
814
815 /** 0000 0001 1sss ddd w dd ss 0000 DADD.size src,dest */
816
817 DADDV(1,0);
818
819 /** 1011 ddd w dd00 1110 DEC.size dest */
820
821 prefix (0, 1, 0);
822 dc = decode_dest23 (ddd, dd, w+1);
823 a = get_src (dc);
824 v = a-1;
825 tprintf ("%x -- = %x\n", a, v);
826 set_sz (v, w+1);
827 put_dest (dc, v);
828
829 /** 1011 0000 010w 0011 DIV.size #IMM */
830
831 prefix (0, 0, 0);
832 div_op (-1, 0, 0, 0, w+1);
833
834 /** 1000 sss w ss01 1110 DIV.size src */
835
836 prefix (0, 1, 0);
837 div_op (sss, ss, 0, 0, w+1);
838
839 /** 0000 0001 1010 sss1 ss01 1111 DIV.L src */
840
841 M32C_ONLY();
842 prefix (0, 0, 0);
843 div_op (sss, ss, 0, 0, 4);
844
845 /** 1011 0000 000w 0011 DIVU.size #IMM */
846
847 prefix (0, 0, 0);
848 div_op (-1, 0, 1, 0, w+1);
849
850 /** 1000 sss w ss00 1110 DIVU.size src */
851
852 prefix (0, 1, 0);
853 div_op (sss, ss, 1, 0, w+1);
854
855 /** 0000 0001 1010 sss1 ss00 1111 DIVU.L src */
856
857 M32C_ONLY();
858 prefix (0, 0, 0);
859 div_op (sss, ss, 1, 0, 4);
860
861 /** 1011 0010 010w 0011 DIVX.size #IMM */
862
863 prefix (0, 0, 0);
864 div_op (-1, 0, 0, 1, w+1);
865
866 /** 1001 sss w ss01 1110 DIVX.size src */
867
868 prefix (0, 1, 0);
869 div_op (sss, ss, 0, 1, w+1);
870
871 /** 0000 0001 1010 sss1 ss10 1111 DIVX.L src */
872
873 M32C_ONLY();
874 prefix (0, 0, 0);
875 div_op (sss, ss, 0, 1, 4);
876
877 /** 0000 0001 1001 ddd w dd00 1110 DSBB.size #IMM,dest */
878
879 DADDI(0,1);
880
881 /** 0000 0001 1sss ddd w dd ss 1010 DSBB.size src,dest */
882
883 DADDV(0,1);
884
885 /** 0000 0001 1001 ddd w dd01 1110 DSUB.size #IMM,dest */
886
887 DADDI(0,0);
888
889 /** 0000 0001 1sss ddd w dd ss 0010 DSUB.size src,dest */
890
891 DADDV(0,0);
892
893 /** 1110 1100 ENTER #IMM */
894
895 imm = IMM(1);
896 put_reg (sp, get_reg (sp) - 4);
897 mem_put_si (get_reg (sp), get_reg (fb));
898 put_reg (fb, get_reg (sp));
899 put_reg (sp, get_reg (sp) - imm);
900
901 /** 1111 1100 EXITD */
902
903 put_reg (sp, get_reg (fb));
904 put_reg (fb, mem_get_si (get_reg (sp)));
905 put_reg (sp, get_reg (sp) + 4);
906 put_reg (pc, mem_get_si (get_reg (sp)));
907 put_reg (sp, get_reg (sp) + 4);
908
909 /** 1100 ddd w dd01 1110 EXTS.size dest */
910
911 prefix (0, 0, 0);
912 dc = decode_dest23 (ddd, dd, w+1);
913 v = sign_ext (get_src (dc), (w+1)*8);
914 dc = widen_sd (dc);
915 put_dest (dc, v);
916 set_sz (v, (w+1)*2);
917
918 /** 0000 0001 1sss ddd0 dd ss 0111 EXTS.B src,dest */
919
920 prefix (0, 0, 0);
921 sc = decode_src23 (sss, ss, 1);
922 dc = decode_dest23 (ddd, dd, 2);
923 v = sign_ext (get_src (sc), 8);
924 put_dest (dc, v);
925 set_sz (v, 16);
926
927 /** 0000 0001 1sss ddd0 dd ss 1011 EXTZ src,dest */
928
929 prefix (0, 0, 0);
930 sc = decode_src23 (sss, ss, 1);
931 dc = decode_dest23 (ddd, dd, 2);
932 v = get_src (sc);
933 put_dest (dc, v);
934 set_sz (v, 16);
935
936 /** 1101 0011 1110 1dst FCLR dest */
937
938 set_flags (1 << dst, 0);
939
940 /** 1001 1111 FREIT */
941
942 NOTYET();
943
944 /** 1101 0001 1110 1dst FSET dest */
945
946 set_flags (1 << dst, 1 << dst);
947
948 /** 1010 ddd w dd00 1110 INC.size dest */
949
950 prefix (0, 1, 0);
951 dc = decode_dest23 (ddd, dd, w+1);
952 a = get_src (dc);
953 v = a+1;
954 tprintf ("%x ++ = %x\n", a, v);
955 set_sz (v, w+1);
956 put_dest (dc, v);
957
958 /** 1000 sss0 ss0w 0011 INDEXB.size src */
959 INDEXOP(1, 1, 1);
960 /** 1010 sss0 ss0w 0011 INDEXBD.size src */
961 INDEXOP(1, 0, 1);
962 /** 1100 sss0 ss0w 0011 INDEXBS.size src */
963 INDEXOP(1, 1, 0);
964 /** 1001 sss0 ss1w 0011 INDEXL.size src */
965 INDEXOP(4, 1, 1);
966 /** 1011 sss0 ss1w 0011 INDEXLD.size src */
967 INDEXOP(4, 0, 1);
968 /** 1001 sss0 ss0w 0011 INDEXLS.size src */
969 INDEXOP(4, 1, 0);
970 /** 1000 sss0 ss1w 0011 INDEXW.size src */
971 INDEXOP(2, 1, 1);
972 /** 1010 sss0 ss1w 0011 INDEXWD.size src */
973 INDEXOP(2, 0, 1);
974 /** 1100 sss0 ss1w 0011 INDEXWS.size src */
975 INDEXOP(2, 1, 0);
976
977 /** 1011 1110 vector00 INT #IMM */
978
979 prefix (0, 0, 0);
980 trigger_based_interrupt (vector);
981
982 /** 1011 1111 INTO */
983
984 prefix (0, 0, 0);
985 if (FLAG_O)
986 trigger_fixed_interrupt (0xffffe0);
987
988 /** 1ccc 101c Jcnd label */
989
990 prefix (0, 0, 0);
991 v = sign_ext (IMM(1), 8);
992 if (condition_true (ccc*2+c))
993 put_reg (pc, orig_pc + 1 + v);
994
995 /** 01dd 101d JMP.S label */
996
997 prefix (0, 0, 0);
998 put_reg (pc, orig_pc + (dd*2+d) + 2);
999
1000 /** 1011 1011 JMP.B label */
1001
1002 prefix (0, 0, 0);
1003 imm = sign_ext (IMM(1), 8);
1004 if (imm == -1)
1005 {
1006 if (verbose)
1007 printf("[jmp-to-self detected as exit]\n");
1008 return M32C_MAKE_HIT_BREAK ();
1009 }
1010 put_reg (pc, orig_pc + 1 + imm);
1011
1012 /** 1100 1110 JMP.W label */
1013
1014 prefix (0, 0, 0);
1015 imm = sign_ext (IMM(2), 16);
1016 put_reg (pc, orig_pc + 1 + imm);
1017
1018 /** 1100 1100 JMP.A label */
1019
1020 prefix (0, 0, 0);
1021 imm = IMM(3);
1022 put_reg (pc, imm);
1023
1024 /** 1100 sss1 ss00 1111 JMPI.W src */
1025
1026 prefix (0, 0, 0);
1027 sc = decode_src23 (sss, ss, 2);
1028 a = get_src (sc);
1029 a = sign_ext (a, 16);
1030 put_reg (pc, orig_pc + a);
1031
1032 /** 1000 sss0 ss00 0001 JMPI.A src */
1033
1034 prefix (0, 0, 0);
1035 sc = decode_src23 (sss, ss, 3);
1036 a = get_src (sc);
1037 put_reg (pc, a);
1038
1039 /** 1101 1100 JMPS #IMM8 */
1040
1041 prefix (0, 0, 0);
1042 imm = IMM(1);
1043 a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
1044 put_reg (pc, a);
1045
1046 /** 1100 1111 JSR.W label */
1047
1048 prefix (0, 0, 0);
1049 imm = sign_ext (IMM(2), 16);
1050 put_reg (sp, get_reg (sp) - 4);
1051 mem_put_si (get_reg (sp), get_reg (pc));
1052 put_reg (pc, orig_pc + imm + 1);
1053
1054 /** 1100 1101 JSR.A label */
1055
1056 prefix (0, 0, 0);
1057 imm = IMM(3);
1058 put_reg (sp, get_reg (sp) - 4);
1059 mem_put_si (get_reg (sp), get_reg (pc));
1060 put_reg (pc, imm);
1061
1062 /** 1100 sss1 ss01 1111 JSRI.W src */
1063
1064 prefix (0, 0, 0);
1065 sc = decode_src23 (sss, ss, 2);
1066 a = get_src (sc);
1067 a = sign_ext (a, 16);
1068 put_reg (sp, get_reg (sp) - 4);
1069 mem_put_si (get_reg (sp), get_reg (pc));
1070 put_reg (pc, orig_pc + a);
1071
1072 /** 1001 sss0 ss00 0001 JSRI.A src */
1073
1074 prefix (0, 0, 0);
1075 sc = decode_src23 (sss, ss, 3);
1076 a = get_src (sc);
1077 put_reg (sp, get_reg (sp) - 4);
1078 mem_put_si (get_reg (sp), get_reg (pc));
1079 put_reg (pc, a);
1080
1081 /** 1101 1101 JSRS #IMM8 */
1082
1083 prefix (0, 0, 0);
1084 imm = IMM(1);
1085 a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
1086 put_reg (sp, get_reg (sp) - 4);
1087 mem_put_si (get_reg (sp), get_reg (pc));
1088 put_reg (pc, a);
1089
1090 /** 1101 0101 1010 1dst LDC #IMM16,dest */
1091
1092 imm = IMM(2);
1093 dc = decode_cr_b (dst, CR_B_DCT0);
1094 put_dest (dc, imm);
1095
1096 /** 1101 0101 0010 1dst LDC #IMM24,dest */
1097
1098 imm = IMM(3);
1099 dc = decode_cr_b (dst, CR_B_INTB);
1100 put_dest (dc, imm);
1101
1102 /** 1101 0101 0110 1dst LDC #IMM24,dest */
1103
1104 imm = IMM(3);
1105 dc = decode_cr_b (dst, CR_B_DMA0);
1106 put_dest (dc, imm);
1107
1108 /** 0000 0001 1101 sss1 ss00 1dst LDC src,dest */
1109
1110 prefix (0, 0, 0);
1111 sc = decode_src23 (sss, ss, 2);
1112 dc = decode_cr_b (dst, CR_B_DCT0);
1113 a = get_src (sc);
1114 put_dest (dc, a);
1115
1116 /** 1101 sss1 ss00 0dst LDC src,dest */
1117
1118 prefix (0, 0, 0);
1119 sc = decode_src23 (sss, ss, 3);
1120 dc = decode_cr_b (dst, CR_B_INTB);
1121 a = get_src (sc);
1122 put_dest (dc, a);
1123
1124 /** 0000 0001 1101 sss1 ss00 0dst LDC src,dest */
1125
1126 prefix (0, 0, 0);
1127 sc = decode_src23 (sss, ss, 3);
1128 dc = decode_cr_b (dst, CR_B_DMA0);
1129 a = get_src (sc);
1130 put_dest (dc, a);
1131
1132 /** 1011 0110 1100 0011 LDCTX */
1133
1134 NOTYET();
1135
1136 /** 1101 0101 1110 1imm LDIPL #IMM */
1137
1138 set_flags (0x7000, imm*0x1000);
1139
1140 /** 0000 0001 1000 ddd w dd11 1111 MAX.size #IMM,dest */
1141
1142 prefix (0, 0, 0);
1143 w++;
1144 dc = decode_dest23 (ddd, dd, w);
1145 imm = sign_ext (IMM(w), w*8);
1146 a = sign_ext (get_src (dc), w*8);
1147 tprintf ("max %d %d\n", imm, a);
1148 if (imm > a)
1149 put_dest (dc, imm);
1150
1151 /** 0000 0001 1sss ddd w dd ss 1101 MAX.size src,dest */
1152
1153 prefix (0, 0, 0);
1154 w++;
1155 sc = decode_src23 (sss, ss, w);
1156 dc = decode_dest23 (ddd, dd, w);
1157 b = sign_ext (get_src (sc), w*8);
1158 a = sign_ext (get_src (dc), w*8);
1159 tprintf ("max %d %d\n", b, a);
1160 if (b > a)
1161 put_dest (dc, b);
1162
1163 /** 0000 0001 1000 ddd w dd10 1111 MIN.size #IMM,dest */
1164
1165 prefix (0, 0, 0);
1166 w++;
1167 dc = decode_dest23 (ddd, dd, w);
1168 imm = sign_ext (IMM(w), w*8);
1169 a = sign_ext (get_src (dc), w*8);
1170 tprintf ("min %d %d\n", imm, a);
1171 if (imm < a)
1172 put_dest (dc, imm);
1173
1174 /** 0000 0001 1sss ddd w dd ss 1100 MIN.size src,dest */
1175
1176 prefix (0, 0, 0);
1177 w++;
1178 sc = decode_src23 (sss, ss, w);
1179 dc = decode_dest23 (ddd, dd, w);
1180 b = sign_ext (get_src (sc), w*8);
1181 a = sign_ext (get_src (dc), w*8);
1182 tprintf ("min %d %d\n", b, a);
1183 if (b < a)
1184 put_dest (dc, b);
1185
1186 /** 1001 ddd w dd10 1111 MOV.size:G #IMM,dest */
1187
1188 dc = decode_dest23 (ddd, dd, w+1);
1189 imm = IMM(w+1);
1190 v = imm;
1191 tprintf("%x = %x\n", v, v);
1192 set_sz(v, w+1);
1193 put_dest (dc, v);
1194
1195 /** 1011 ddd0 dd11 0001 MOV.L:G #IMM,dest */
1196
1197 dc = decode_dest23 (ddd, dd, 4);
1198 imm = IMM(4);
1199 v = imm;
1200 tprintf("%x = %x\n", v, v);
1201 set_sz(v, 4);
1202 put_dest (dc, v);
1203
1204 /** 1111 ddd w dd10 immm MOV.size:Q #IMM4,dest */
1205
1206 dc = decode_dest23 (ddd, dd, w+1);
1207 imm = sign_ext (immm, 4);
1208 v = imm;
1209 tprintf("%x = %d\n", v, v);
1210 set_sz(v, w+1);
1211 put_dest (dc, v);
1212
1213 /** 00dd 010w MOV.size:S #IMM,dest */
1214
1215 prefix (0, 1, 0);
1216 dc = decode_dest2 (dd, w+1);
1217 imm = IMM(w+1);
1218 put_dest (dc, imm);
1219 set_sz (imm, w+1);
1220
1221 /** 10w1 110d MOV.size:S #IMM,a0/a1 */
1222
1223 imm = IMM(w ? 3 : 2);
1224 put_reg (d ? a1 : a0, imm);
1225 set_sz (imm & addr_mask, w+1);
1226
1227 /** 00dd 001w MOV.size:Z #0,dest */
1228
1229 prefix (0, 1, 0);
1230 dc = decode_dest2 (dd, w+1);
1231 put_dest (dc, 0);
1232 set_sz (0, w+1);
1233
1234 /** 1sss ddd w dd ss 1011 MOV.size:G src,dest */
1235
1236 prefix (1, 1, 0);
1237 sc = decode_src23 (sss, ss, w+1);
1238 dc = decode_dest23 (ddd, dd, w+1);
1239 v = get_src (sc);
1240 put_dest (dc, v);
1241 set_sz (v, w+1);
1242
1243 /** 1sss ddd1 dd ss 0011 MOV.L:G src,dest */
1244
1245 prefix (1, 1, 0);
1246 sc = decode_src23 (sss, ss, 4);
1247 dc = decode_dest23 (ddd, dd, 4);
1248 v = get_src (sc);
1249 put_dest (dc, v);
1250 set_sz (v, 4);
1251
1252 /** VARY SS 01 10 11 */
1253 /** 00SS 100w MOV.size:S src,R0L/R0 */
1254
1255 prefix (0, 1, 0);
1256 sc = decode_dest2 (SS, w+1);
1257 v = get_src (sc);
1258 put_reg (w ? r0 : r0l, v);
1259 set_sz (v, w+1);
1260
1261 /** 01ss 111w MOV.size:S src,R1L/R1 */
1262
1263 prefix (0, 1, 0);
1264 sc = decode_dest2 (ss, w+1);
1265 v = get_src (sc);
1266 put_reg (w ? r1 : r1l, v);
1267 set_sz (v, w+1);
1268
1269 /** VARY DD 01 10 11 */
1270 /** 00DD 000w MOV.size:S R0L/R0,dest */
1271
1272 prefix (0, 1, 0);
1273 dc = decode_dest2 (DD, w+1);
1274 v = get_reg (w ? r0 : r0l);
1275 put_dest (dc, v);
1276 set_sz (v, w+1);
1277
1278 /** 01ss 100d MOV.L:S src,A0/A1 */
1279
1280 prefix (0, 1, 0);
1281 sc = decode_dest2 (ss, 4);
1282 v = get_src (sc);
1283 put_reg (d ? a1 : a0, v);
1284 set_sz (v, 4);
1285
1286 /** 1011 ddd w dd00 1111 MOV.size:G dsp:8[SP], dest */
1287
1288 prefix (0, 0, 0);
1289 imm = IMM(1);
1290 dc = decode_dest23 (ddd, dd, w+1);
1291 a = get_reg (sp) + sign_ext (imm, 8);
1292 a &= addr_mask;
1293 if (w)
1294 v = mem_get_hi (a);
1295 else
1296 v = mem_get_qi (a);
1297 put_dest (dc, v);
1298 set_sz (v, w+1);
1299
1300 /** 1010 sss w ss00 1111 MOV.size:G src,dsp:8[SP] */
1301
1302 prefix (0, 0, 0);
1303 sc = decode_dest23 (sss, ss, w+1);
1304 imm = IMM(1);
1305 a = get_reg (sp) + sign_ext (imm, 8);
1306 a &= addr_mask;
1307 v = get_src (sc);
1308 if (w)
1309 mem_put_hi (a, v);
1310 else
1311 mem_put_qi (a, v);
1312 set_sz (v, w+1);
1313
1314 /** 1101 sss1 ss01 1dst MOVA src,dest */
1315
1316 static reg_id map[8] = { r2r0, r3r1, a0, a1 };
1317 prefix (0, 0, 0);
1318 sc = decode_src23 (sss, ss, 1);
1319 if (!sc.mem || !map[dst])
1320 UNSUPPORTED();
1321 put_reg (map[dst], sc.u.addr);
1322
1323 /** 0000 0001 1011 ddd0 dd hl 1110 MOVdir R0L,dest */
1324
1325 prefix (0, 0, 0);
1326 dc = decode_dest23 (ddd, dd, 1);
1327 a = get_src (dc);
1328 b = get_reg (r0l);
1329 switch (hl)
1330 {
1331 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1332 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1333 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1334 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1335 }
1336 put_dest (dc, a);
1337
1338 /** 0000 0001 1010 sss0 ss hl 1110 MOVdir src,R0L */
1339
1340 prefix (0, 0, 0);
1341 sc = decode_dest23 (sss, ss, 1);
1342 a = get_reg (r0l);
1343 b = get_src (dc);
1344 switch (hl)
1345 {
1346 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1347 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1348 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1349 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1350 }
1351 put_reg (r0l, a);
1352
1353 /** 1011 ddd0 dd01 0001 MOVX #IMM,dest */
1354
1355 prefix (0, 1, 0);
1356 dc = decode_dest23 (ddd, dd, 4);
1357 imm = sign_ext (IMM(1), 8);
1358 put_dest (dc, imm);
1359 set_sz (imm, 1);
1360
1361 /** 1000 ddd w dd01 1111 MUL.size #IMM,dest */
1362
1363 prefix (0, 1, 0);
1364 w ++;
1365 dc = decode_dest23 (ddd, dd, w);
1366 v = sign_ext (get_src (dc), w*8);
1367 imm = sign_ext (IMM(w), w*8);
1368 tprintf("%d * %d = %d\n", v, imm, v*imm);
1369 v *= imm;
1370 dc = widen_sd (dc);
1371 put_dest (dc, v);
1372
1373 /** 1sss ddd w dd ss 1100 MUL.size src,dest */
1374
1375 prefix (1, 1, 0);
1376 w ++;
1377 sc = decode_src23 (sss, ss, w);
1378 dc = decode_dest23 (ddd, dd, w);
1379 a = sign_ext (get_src (sc), w*8);
1380 b = sign_ext (get_src (dc), w*8);
1381 tprintf("%d * %d = %d\n", a, b, a*b);
1382 v = a * b;
1383 dc = widen_sd (dc);
1384 put_dest (dc, v);
1385
1386 /** 0000 0001 1000 sss1 ss01 1111 MUL.L src,R2R0 */
1387
1388 M32C_ONLY();
1389 prefix (0, 0, 0);
1390 sc = decode_src23 (sss, ss, 4);
1391 a = sign_ext (get_src (sc), 32);
1392 b = sign_ext (get_reg (r2r0), 32);
1393 ll = (long long)a * (long long)b;
1394 tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1395 if (ll < b2minsigned[4] || ll > b2maxsigned[4])
1396 set_flags (FLAGBIT_O, FLAGBIT_O);
1397 else
1398 set_flags (FLAGBIT_O, 0);
1399 put_reg (r2r0, (int)ll);
1400
1401 /** 1100 sss1 ss11 1110 MULEX src */
1402
1403 prefix (0, 1, 0);
1404 sc = decode_dest23 (sss, ss, 2);
1405 a = sign_ext (get_src (sc), 16);
1406 b = sign_ext (get_reg (r2r0), 32);
1407 ll = (long long)a * (long long)b;
1408 tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1409 put_reg (r2r0, (int)ll);
1410 put_reg (r1, (int)(ll >> 32));
1411
1412 /** 1000 ddd w dd00 1111 MULU.size #IMM,dest */
1413
1414 prefix (0, 1, 0);
1415 w ++;
1416 dc = decode_dest23 (ddd, dd, w);
1417 v = get_src (dc);
1418 imm = IMM(w);
1419 tprintf("%d * %d = %d\n", v, imm, v*imm);
1420 v *= imm;
1421 dc = widen_sd (dc);
1422 put_dest (dc, v);
1423
1424 /** 1sss ddd w dd ss 0100 MULU.size src,dest */
1425
1426 prefix (1, 1, 0);
1427 w ++;
1428 sc = decode_src23 (sss, ss, w);
1429 dc = decode_dest23 (ddd, dd, w);
1430 a = get_src (sc);
1431 b = get_src (dc);
1432 tprintf("%d * %d = %d\n", a, b, a*b);
1433 v = a * b;
1434 dc = widen_sd (dc);
1435 put_dest (dc, v);
1436
1437 /** 0000 0001 1000 sss1 ss00 1111 MULU.L src,R2R0 */
1438
1439 M32C_ONLY();
1440 prefix (0, 0, 0);
1441 sc = decode_src23 (sss, ss, 4);
1442 a = get_src (sc);
1443 b = get_reg (r2r0);
1444 ll = (long long)a * (long long)b;
1445 tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1446 if (ll < b2minsigned[4] || ll > b2maxsigned[4])
1447 set_flags (FLAGBIT_O, FLAGBIT_O);
1448 else
1449 set_flags (FLAGBIT_O, 0);
1450 put_reg (r2r0, (int)ll);
1451
1452 /** 1010 ddd w dd10 1111 NEG.size dest */
1453
1454 prefix (0, 1, 0);
1455 dc = decode_dest23 (ddd, dd, w+1);
1456 a = sign_ext (get_src (dc), (w+1)*8);
1457 v = -a;
1458 tprintf("%d * -1 = %d\n", a, v);
1459 set_oszc(v, w+1, v==0);
1460 put_dest (dc, v);
1461
1462 /** 1101 1110 NOP */
1463
1464 tprintf("nop\n");
1465
1466 /** 1010 ddd w dd01 1110 NOT.size dest */
1467
1468 prefix (0, 1, 0);
1469 dc = decode_dest23 (ddd, dd, w+1);
1470 a = get_src (dc);
1471 v = ~a;
1472 tprintf("~ %x = %x\n", a, v);
1473 set_sz(v, w+1);
1474 put_dest (dc, v);
1475
1476 /** 1000 ddd w dd10 1111 OR.size:G #IMM,dest */
1477
1478 prefix (0, 1, 0);
1479 dc = decode_dest23(ddd, dd, w+1);
1480 imm = IMM(w+1);
1481 LOGIC_OP (dc, imm, |);
1482
1483 /** 01dd 010w OR.size:S #IMM,dest */
1484
1485 prefix (0, 1, 0);
1486 dc = decode_dest2(dd, w+1);
1487 imm = IMM (w+1);
1488 LOGIC_OP (dc, imm, |);
1489
1490 /** 1sss ddd w dd ss 0101 OR.size:G src,dest */
1491
1492 prefix (1, 1, 0);
1493 sc = decode_src23(sss, ss, w+1);
1494 dc = decode_dest23(ddd, dd, w+1);
1495 b = get_src (sc);
1496 LOGIC_OP (dc, b, |);
1497
1498 /** 1011 ddd w dd10 1111 POP.size dest */
1499
1500 prefix (0, 1, 0);
1501 dc = decode_dest23 (ddd, dd, w+1);
1502 if (w)
1503 a = mem_get_hi (get_reg (sp));
1504 else
1505 a = mem_get_qi (get_reg (sp));
1506 put_reg (sp, get_reg (sp) + 2);
1507 tprintf("pop%s: %x\n", w ? "hi" : "qi", a);
1508 put_dest (dc, a);
1509
1510 /** 1101 0011 1010 1dst POPC dest */
1511
1512 prefix (0, 0, 0);
1513 dc = decode_cr_b (dst, CR_B_DCT0);
1514 a = mem_get_hi (get_reg (sp));
1515 put_reg (sp, get_reg (sp) + 2);
1516 tprintf("pophi: %x\n", a);
1517 put_dest (dc, a);
1518
1519 /** 1101 0011 0010 1dst POPC dest */
1520
1521 prefix (0, 0, 0);
1522 dc = decode_cr_b (dst, CR_B_INTB);
1523 a = mem_get_si (get_reg (sp));
1524 put_reg (sp, get_reg (sp) + 4);
1525 tprintf("popsi: %x\n", a);
1526 put_dest (dc, a);
1527
1528 /** 1000 1110 POPM dest */
1529
1530 static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1531 prefix (0, 0, 0);
1532 imm = IMM(1);
1533 tprintf("popm: %x\n", imm);
1534 for (a=0; a<4; a++)
1535 if (imm & (1<<a))
1536 {
1537 v = mem_get_hi (get_reg (sp));
1538 put_reg (map[a], v);
1539 put_reg (sp, get_reg (sp) + 2);
1540 }
1541 for (; a<8; a++)
1542 if (imm & (1<<a))
1543 {
1544 v = mem_get_si (get_reg (sp));
1545 put_reg (map[a], v);
1546 put_reg (sp, get_reg (sp) + 4);
1547 }
1548
1549 /** 1010 111w PUSH.size #IMM */
1550
1551 prefix (0, 0, 0);
1552 imm = IMM(w+1);
1553 tprintf("push%s: %x\n", w ? "hi" : "qi", imm);
1554 int a = get_reg (sp) - 2;
1555 if (w)
1556 mem_put_hi (a, imm);
1557 else
1558 mem_put_qi (a, imm);
1559 put_reg (sp, a);
1560
1561 /** 1100 sss w ss00 1110 PUSH.size src */
1562
1563 prefix (0, 1, 0);
1564 sc = decode_dest23 (sss, ss, w+1);
1565 a = get_src (sc);
1566 put_reg (sp, get_reg (sp) - 2);
1567 if (w)
1568 mem_put_hi (get_reg (sp), a);
1569 else
1570 mem_put_qi (get_reg (sp), a);
1571 tprintf("push%s: %x\n", w ? "hi" : "qi", a);
1572
1573 /** 1011 0110 0101 0011 PUSH.L #IMM32 */
1574
1575 imm = IMM(4);
1576 put_reg (sp, get_reg (sp) - 4);
1577 mem_put_si (get_reg (sp), imm);
1578
1579 /** 1010 sss0 ss00 0001 PUSH.L src */
1580
1581 prefix (0, 1, 0);
1582 sc = decode_dest23 (sss, ss, 4);
1583 a = get_src (sc);
1584 put_reg (sp, get_reg (sp) - 4);
1585 mem_put_si (get_reg (sp), a);
1586
1587 /** 1011 0sa0 ss00 0001 PUSHA src */
1588
1589 prefix (0, 0, 0);
1590 sc = decode_dest23 (sa, ss, 1);
1591 put_reg (sp, get_reg (sp) - 4);
1592 mem_put_hi (get_reg (sp), sc.u.addr);
1593 tprintf("pushsi: %x\n", sc.u.addr);
1594
1595 /** 1101 0001 1010 1src PUSHC src */
1596
1597 prefix (0, 0, 0);
1598 sc = decode_cr_b (src, CR_B_DCT0);
1599 a = get_src (sc);
1600 put_reg (sp, get_reg (sp) - 2);
1601 mem_put_hi (get_reg (sp), a);
1602 tprintf("pushhi: %x\n", a);
1603
1604 /** 1101 0001 0010 1src PUSHC src */
1605
1606 prefix (0, 0, 0);
1607 sc = decode_cr_b (src, CR_B_INTB);
1608 a = get_src (sc);
1609 put_reg (sp, get_reg (sp) - 4);
1610 mem_put_si (get_reg (sp), a);
1611 tprintf("pushsi: %x\n", a);
1612
1613 /** 1000 1111 PUSHM src */
1614
1615 static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1616 imm = IMM(1);
1617 tprintf("pushm: %x\n", imm);
1618 for (a=0; a<4; a++)
1619 if (imm & (1<<a))
1620 {
1621 put_reg (sp, get_reg (sp) - 4);
1622 v = get_reg (map[a]);
1623 mem_put_si (get_reg (sp), v);
1624 }
1625 for (; a<8; a++)
1626 if (imm & (1<<a))
1627 {
1628 put_reg (sp, get_reg (sp) - 2);
1629 v = get_reg (map[a]);
1630 mem_put_hi (get_reg (sp), v);
1631 }
1632
1633 /** 1001 1110 REIT */
1634
1635 a = get_reg (sp);
1636 put_reg (pc, mem_get_si (a));
1637 a += 4;
1638 put_reg (flags, mem_get_hi (a));
1639 a += 2;
1640 put_reg (sp, a);
1641
1642 /** 1011 1000 010w 0011 RMPA.size */
1643
1644 int count = get_reg (r3);
1645 int list1 = get_reg (a0);
1646 int list2 = get_reg (a1);
1647 long long sum = get_reg_ll (r3r1r2r0) & 0xffffff;
1648
1649 while (count)
1650 {
1651 if (w)
1652 {
1653 a = sign_ext (mem_get_hi (list1), 16);
1654 b = sign_ext (mem_get_hi (list2), 16);
1655 }
1656 else
1657 {
1658 a = sign_ext (mem_get_qi (list1), 8);
1659 b = sign_ext (mem_get_qi (list2), 8);
1660 }
1661 tprintf("%lld + %d * %d = ", sum, a, b);
1662 sum += a * b;
1663 tprintf("%lld\n", sum);
1664 list1 += w ? 2 : 1;
1665 list2 += w ? 2 : 1;
1666 count --;
1667 }
1668 put_reg (r3, count);
1669 put_reg (a0, list1);
1670 put_reg (a1, list2);
1671 put_reg (r2r0, (int)(sum & 0xffffffffU));
1672 put_reg (r1, (int)(sum >> 32));
1673
1674 /** 1011 ddd w dd10 1110 ROLC.size dest */
1675
1676 prefix (0, 1, 0);
1677 dc = decode_dest23 (ddd, dd, w+1);
1678 rot_op (dc, 1, 1);
1679
1680 /** 1010 ddd w dd10 1110 RORC.size dest */
1681
1682 prefix (0, 1, 0);
1683 dc = decode_dest23 (ddd, dd, w+1);
1684 rot_op (dc, 1, -1);
1685
1686 /** 1110 ddd w dd10 immm ROT.size #IMM, dest */
1687
1688 prefix (0, 1, 0);
1689 dc = decode_dest23 (ddd, dd, w+1);
1690 rot_op (dc, IMM4(), -1);
1691
1692 /** 1010 ddd w dd11 1111 ROT.size R1H,dest */
1693
1694 prefix (0, 1, 0);
1695 dc = decode_dest23 (ddd, dd, w+1);
1696 a = sign_ext (get_reg (r1h), 8);
1697 rot_op (dc, a, -1);
1698
1699 /** 1101 1111 RTS */
1700
1701 put_reg (pc, mem_get_si (get_reg (sp)));
1702 put_reg (sp, get_reg (sp) + 4);
1703
1704 /** 0000 0001 1001 ddd w dd10 1110 SBB.size #IMM, dest */
1705
1706 prefix (0, 0, 0);
1707 dc = decode_dest23 (ddd, dd, w+1);
1708 imm = IMM (w+1);
1709 MATH_OP (dc, imm, !carry, -);
1710
1711 /** 0000 0001 1sss ddd w dd ss 0110 SBB.size src,dest */
1712
1713 prefix (0, 0, 0);
1714 sc = decode_src23 (sss, ss, w+1);
1715 dc = decode_dest23 (ddd, dd, w+1);
1716 MATH_OP (dc, get_src (sc), !carry, -);
1717
1718 /** 1101 ddd1 dd11 cond SCcond dest */
1719
1720 prefix (0, 1, 0);
1721 dc = decode_dest23 (ddd, dd, 2);
1722 if (condition_true (cond))
1723 put_dest (dc, 1);
1724 else
1725 put_dest (dc, 0);
1726
1727 /** 1011 1000 110w 0011 SCMPU.size */
1728
1729 ta0 = get_reg (a0);
1730 ta1 = get_reg (a1);
1731
1732 for (;;)
1733 {
1734 t0 = mem_get_qi (ta0);
1735 t2 = mem_get_qi (ta1);
1736 if (w)
1737 {
1738 t1 = mem_get_qi (ta0 + 1);
1739 t3 = mem_get_qi (ta1 + 1);
1740 }
1741 dif = t0 - t2;
1742 if (dif == 0 && t0 != 0 && w)
1743 dif = t1 - t3;
1744 set_oszc (dif, 1, dif > 0);
1745
1746 ta0 += w ? 2 : 1;
1747 ta1 += w ? 2 : 1;
1748
1749 if (t0 == 0 || t0 != t2)
1750 break;
1751 if (w && (t1 == 0 || t1 != t3))
1752 break;
1753 }
1754
1755 /** 1111 ddd w dd00 immm SHA.size #IMM,dest */
1756
1757 prefix (0, 1, 0);
1758 dc = decode_dest23 (ddd, dd, w+1);
1759 shift_op (dc, 1, IMM4(), 1);
1760
1761 /** 1010 ddd0 dd10 0001 SHA.L #IMM,dest */
1762
1763 prefix (0, 1, 0);
1764 dc = decode_dest23 (ddd, dd, 4);
1765 imm = sign_ext (IMM(1), 8);
1766 shift_op (dc, 1, imm, 1);
1767
1768 /** 1011 ddd w dd11 1110 SHA.size R1H,dest */
1769
1770 prefix (0, 1, 0);
1771 dc = decode_dest23 (ddd, dd, w+1);
1772 a = sign_ext (get_reg (r1h), 8);
1773 shift_op (dc, 1, a, 1);
1774
1775 /** 1100 ddd0 dd01 0001 SHA.L R1H,dest */
1776
1777 prefix (0, 1, 0);
1778 dc = decode_dest23 (ddd, dd, 4);
1779 a = sign_ext (get_reg (r1h), 8);
1780 shift_op (dc, 1, a, 1);
1781
1782 /** 1100 ddd0 dd10 0001 SHANC.L #IMM,dest */
1783
1784 M32C_ONLY();
1785 prefix (0, 1, 0);
1786 dc = decode_dest23 (ddd, dd, 4);
1787 imm = sign_ext (IMM(1), 8);
1788 shift_op (dc, 1, imm, 0);
1789
1790 /** 1110 ddd w dd00 immm SHL.size #IMM, dest */
1791
1792 prefix (0, 1, 0);
1793 dc = decode_dest23 (ddd, dd, w+1);
1794 shift_op (dc, 0, IMM4(), 1);
1795
1796 /** 1001 ddd0 dd10 0001 SHL.L #IMM, dest */
1797
1798 prefix (0, 1, 0);
1799 dc = decode_dest23 (ddd, dd, 4);
1800 imm = sign_ext (IMM(1), 8);
1801 shift_op (dc, 0, imm, 1);
1802
1803 /** 1010 ddd w dd11 1110 SHL.size R1H,dest */
1804
1805 prefix (0, 1, 0);
1806 dc = decode_dest23 (ddd, dd, w+1);
1807 a = sign_ext (get_reg (r1h), 8);
1808 shift_op (dc, 0, a, 1);
1809
1810 /** 1100 ddd0 dd00 0001 SHL.L R1H,dest */
1811
1812 prefix (0, 1, 0);
1813 dc = decode_dest23 (ddd, dd, 4);
1814 a = sign_ext (get_reg (r1h), 8);
1815 shift_op (dc, 0, a, 1);
1816
1817 /** 1000 ddd0 dd10 0001 SHLNC.L #IMM,dest */
1818
1819 M32C_ONLY();
1820 prefix (0, 1, 0);
1821 dc = decode_dest23 (ddd, dd, 4);
1822 imm = sign_ext (IMM(1), 8);
1823 shift_op (dc, 0, imm, 0);
1824
1825 /** 1011 0010 100w 0011 SIN.size */
1826
1827 v = get_reg (a0);
1828 a = get_reg (a1);
1829 b = get_reg (r3);
1830 if (b) for (;b;)
1831 {
1832 if (w)
1833 mem_put_hi(a, mem_get_hi (v));
1834 else
1835 mem_put_qi(a, mem_get_qi (v));
1836 a += w ? 2 : 1;
1837 b --;
1838 }
1839 put_reg (a0, v);
1840 put_reg (a1, a);
1841 put_reg (r3, b);
1842
1843 /** 1011 0110 100w 0011 SMOVB.size */
1844
1845 v = get_reg (a0);
1846 a = get_reg (a1);
1847 b = get_reg (r3);
1848 if (b) for (;b;)
1849 {
1850 if (w)
1851 mem_put_hi(a, mem_get_hi (v));
1852 else
1853 mem_put_qi(a, mem_get_qi (v));
1854 v -= w ? 2 : 1;
1855 a -= w ? 2 : 1;
1856 b --;
1857 }
1858 put_reg (a0, v);
1859 put_reg (a1, a);
1860 put_reg (r3, b);
1861
1862 /** 1011 0000 100w 0011 SMOVF.size */
1863
1864 v = get_reg (a0);
1865 a = get_reg (a1);
1866 b = get_reg (r3);
1867 if (b) for (;b;)
1868 {
1869 if (w)
1870 mem_put_hi(a, mem_get_hi (v));
1871 else
1872 mem_put_qi(a, mem_get_qi (v));
1873 v += w ? 2 : 1;
1874 a += w ? 2 : 1;
1875 b --;
1876 }
1877 put_reg (a0, v);
1878 put_reg (a1, a);
1879 put_reg (r3, b);
1880
1881 /** 1011 1000 100w 0011 SMOVU.size */
1882
1883 v = get_reg (a0);
1884 a = get_reg (a1);
1885 do
1886 {
1887 if (w)
1888 mem_put_hi(a, (t0 = mem_get_hi (v)));
1889 else
1890 mem_put_qi(a, (t0 = mem_get_qi (v)));
1891 v += w ? 2 : 1;
1892 a += w ? 2 : 1;
1893 if (t0 == 0
1894 || (w && ((t0 & 0xff) == 0 || (t0 & 0xff00) == 0)))
1895 break;
1896 } while (1);
1897 put_reg (a0, v);
1898 put_reg (a1, a);
1899
1900 /** 1011 0100 100w 0011 SOUT.size */
1901
1902 v = get_reg (a0);
1903 a = get_reg (a1);
1904 b = get_reg (r3);
1905 for (;b;)
1906 {
1907 if (w)
1908 mem_put_hi(a, mem_get_hi (v));
1909 else
1910 mem_put_qi(a, mem_get_qi (v));
1911 v += w ? 2 : 1;
1912 b --;
1913 }
1914 put_reg (a0, v);
1915 put_reg (a1, a);
1916 put_reg (r3, b);
1917
1918 /** 1011 1000 000w 0011 SSTR.size */
1919
1920 a = get_reg (a1);
1921 b = get_reg (r3);
1922 for (;b;)
1923 {
1924 if (w)
1925 mem_put_hi(a, r0);
1926 else
1927 mem_put_qi(a, r0 & 0xff);
1928 a += w ? 2 : 1;
1929 b --;
1930 }
1931 put_reg (a1, a);
1932 put_reg (r3, b);
1933
1934 /** 0000 0001 1101 ddd1 dd01 0src STC src,dest */
1935
1936 prefix (0, 0, 0);
1937 dc = decode_dest23 (ddd, dd, 4);
1938 sc = decode_cr_b (src, CR_B_DMA0);
1939 a = get_src (sc);
1940 put_dest (dc, a);
1941
1942 /** 0000 0001 1101 ddd1 dd01 1src STC src,dest */
1943
1944 prefix (0, 0, 0);
1945 dc = decode_dest23 (ddd, dd, 2);
1946 sc = decode_cr_b (src, CR_B_DCT0);
1947 a = get_src (sc);
1948 put_dest (dc, a);
1949
1950 /** 1101 ddd1 dd01 0src STC src,dest */
1951
1952 prefix (0, 0, 0);
1953 dc = decode_dest23 (ddd, dd, 4);
1954 sc = decode_cr_b (src, CR_B_INTB);
1955 a = get_src (sc);
1956 put_dest (dc, a);
1957
1958 /** 1011 0110 1101 0011 STCX abs16,abs24 */
1959
1960 NOTYET();
1961
1962 /** 1001 ddd w dd01 1111 STNZ.size #IMM,dest */
1963
1964 prefix (0, 1, 0);
1965 dc = decode_dest23 (ddd, dd, w+1);
1966 imm = IMM(w+1);
1967 if (! FLAG_Z)
1968 put_dest (dc, imm);
1969
1970 /** 1001 ddd w dd00 1111 STZ.size #IMM,dest */
1971
1972 prefix (0, 1, 0);
1973 dc = decode_dest23 (ddd, dd, w+1);
1974 imm = IMM(w+1);
1975 if (FLAG_Z)
1976 put_dest (dc, imm);
1977
1978 /** 1001 ddd w dd11 1111 STZX.size #IMM1,#IMM2,dest */
1979
1980 prefix (0, 1, 0);
1981 dc = decode_dest23 (ddd, dd, w+1);
1982 a = IMM(w+1);
1983 b = IMM(w+1);
1984 if (FLAG_Z)
1985 put_dest (dc, a);
1986 else
1987 put_dest (dc, b);
1988
1989 /** 1000 ddd w dd11 1110 SUB.size:G #IMM,dest */
1990
1991 prefix (0, 1, 0);
1992 dc = decode_dest23(ddd, dd, w+1);
1993 imm = IMM(w+1);
1994 MATH_OP (dc, imm, 0, -);
1995
1996 /** 1001 ddd0 dd11 0001 SUB.L:G #IMM,dest */
1997
1998 prefix (0, 1, 0);
1999 dc = decode_dest23(ddd, dd, 4);
2000 imm = IMM(4);
2001 MATH_OP (dc, imm, 0, -);
2002
2003 /** 00dd 111w SUB.size:S #IMM,dest */
2004
2005 prefix (0, 1, 0);
2006 dc = decode_dest2(dd, w+1);
2007 imm = IMM (w+1);
2008 MATH_OP (dc, imm, 0, -);
2009
2010 /** 1sss ddd w dd ss 1010 SUB.size:G src,dest */
2011
2012 prefix (1, 1, 0);
2013 sc = decode_src23(sss, ss, w+1);
2014 dc = decode_dest23(ddd, dd, w+1);
2015 b = get_src (sc);
2016 MATH_OP (dc, b, 0, -);
2017
2018 /** 1sss ddd1 dd ss 0000 SUB.L:G src,dest */
2019
2020 prefix (1, 1, 0);
2021 sc = decode_src23(sss, ss, 4);
2022 dc = decode_dest23(ddd, dd, 4);
2023 b = get_src (sc);
2024 MATH_OP (dc, b, 0, -);
2025
2026 /** 1001 ddd0 dd01 0001 SUBX #IMM,dest */
2027
2028 prefix (0, 1, 0);
2029 dc = decode_dest23(ddd, dd, 4);
2030 imm = sign_ext (IMM(1), 8);
2031 MATH_OP (dc, imm, 0, -);
2032
2033 /** 1sss ddd0 dd ss 0000 SUBX src,dest */
2034
2035 prefix (1, 1, 0);
2036 sc = decode_src23(sss, ss, 1);
2037 dc = decode_dest23(ddd, dd, 4);
2038 b = sign_ext (get_src (sc), 8);
2039 MATH_OP (dc, b, 0, -);
2040
2041 /** 1001 ddd w dd11 1110 TST.size:G #IMM,dest */
2042
2043 prefix (0, 0, 0);
2044 dc = decode_dest23 (ddd, dd, w+1);
2045 imm = IMM(w+1);
2046 a = get_src (dc);
2047 v = a & imm;
2048 set_sz (v, w+1);
2049
2050 /** 00dd 110w TST.size:S #IMM,dest */
2051
2052 prefix (0, 0, 0);
2053 dc = decode_dest2 (dd, w+1);
2054 imm = IMM(w+1);
2055 a = get_src (dc);
2056 v = a & imm;
2057 set_sz (v, w+1);
2058
2059 /** 0000 0001 1sss ddd w dd ss 1001 TST.size:G src,dest */
2060
2061 prefix (0, 0, 0);
2062 sc = decode_src23 (sss, ss, w+1);
2063 dc = decode_dest23 (ddd, dd, w+1);
2064 b = get_src (sc);
2065 a = get_src (dc);
2066 v = a & b;
2067 set_sz (v, w+1);
2068
2069 /** 1111 1111 UND */
2070
2071 trigger_fixed_interrupt (0xffffdc);
2072
2073 /** 1011 0010 0000 0011 WAIT */
2074
2075 ;
2076
2077 /** 1101 ddd w dd00 1src XCHG.size src,dest */
2078
2079 dc = decode_dest23 (ddd, dd, w+1);
2080 sc = decode_src3 (src, w+1);
2081 a = get_src (dc);
2082 b = get_src (sc);
2083 put_dest (dc, b);
2084 put_dest (sc, a);
2085
2086 /** 1001 ddd w dd00 1110 XOR.size #IMM,dest */
2087
2088 prefix (0, 1, 0);
2089 dc = decode_dest23(ddd, dd, w+1);
2090 imm = IMM(w+1);
2091 LOGIC_OP (dc, imm, ^);
2092
2093 /** 1sss ddd w dd ss 1001 XOR.size src,dest */
2094
2095 prefix (1, 1, 0);
2096 sc = decode_src23(sss, ss, w+1);
2097 dc = decode_dest23(ddd, dd, w+1);
2098 b = get_src (sc);
2099 LOGIC_OP (dc, b, ^);
2100
2101 /** */
2102
2103 return step_result;
2104 }