]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m32c/r8c.opc
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / sim / m32c / r8c.opc
CommitLineData
d45a4bef
JB
1/* r8c.opc --- semantics for r8c opcodes. -*- mode: c -*-
2
6aba47ca 3Copyright (C) 2005, 2007 Free Software Foundation, Inc.
d45a4bef
JB
4Contributed by Red Hat, Inc.
5
6This file is part of the GNU simulators.
7
8The GNU simulators are free software; you can redistribute them and/or
9modify them under the terms of the GNU General Public License as
10published by the Free Software Foundation; either version 2 of the
11License, or (at your option) any later version.
12
13The GNU simulators are distributed in the hope that they will be
14useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with the GNU simulators; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2102110-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
36static unsigned char
37getbyte ()
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 M16C_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
57static void
58unsupported (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
81static int
82IMM(bw)
83{
84 int rv = getbyte ();
85 if (bw)
86 rv = rv + 256 * getbyte();
87 if (bw == 2)
88 rv = rv + 65536 * getbyte();
89 return rv;
90}
91
92#define IMM4() (immm >= 8 ? 7 - immm : immm + 1)
93
94#define UNARY_SOP \
95 dc = decode_srcdest4 (dest, w); \
96 v = sign_ext (get_src (dc), w?16:8);
97
98#define UNARY_UOP \
99 dc = decode_srcdest4 (dest, w); \
100 v = get_src (dc);
101
102#define BINARY_SOP \
103 sc = decode_srcdest4 (srcx, w); \
104 dc = decode_srcdest4 (dest, w); \
105 a = sign_ext (get_src (sc), w?16:8); \
106 b = sign_ext (get_src (dc), w?16:8);
107
108#define BINARY_UOP \
109 sc = decode_srcdest4 (srcx, w); \
110 dc = decode_srcdest4 (dest, w); \
111 a = get_src (sc); \
112 b = get_src (dc);
113
114#define carry (FLAG_C ? 1 : 0)
115
116static void
117cmp (int d, int s, int w)
118{
119 int a, b, f=0;
120 int mask = w ? 0xffff : 0xff;
121 a = d - s;
122 b = sign_ext (d, w?16:8) - sign_ext (s, w?16:8);
123 tprintf ("cmp: %x - %x = %08x, %x - %x = %d\n",
124 d, s, a,
125 sign_ext(d,w?16:8), sign_ext(s,w?16:8), b);
126
127 if (b == 0)
128 f |= FLAGBIT_Z;
129 if (b & (w ? 0x8000 : 0x80))
130 f |= FLAGBIT_S;
131 if ((d & mask) >= (s & mask))
132 f |= FLAGBIT_C;
133 if (b < (w ? -32768 : -128) || b > (w ? 32767 : 127))
134 f |= FLAGBIT_O;
135
136 set_flags (FLAGBIT_Z | FLAGBIT_S | FLAGBIT_O | FLAGBIT_C, f);
137}
138
139static void
140div_op (int s, int u, int x, int w)
141{
142 srcdest sc;
143 int v, a, b;
144
145 if (s == -1)
146 s = IMM(w);
147 else
148 {
149 sc = decode_srcdest4 (s, w);
150 s = get_src (sc);
151 }
152
153 v = get_reg (w ? r2r0 : r0);
154
155 if (!u)
156 {
157 s = sign_ext (s, w ? 16 : 8);
158 v = sign_ext (v, w ? 16 : 8);
159 }
160
161 if (s == 0)
162 {
163 set_flags (FLAGBIT_O, FLAGBIT_O);
164 return;
165 }
166
167 if (u)
168 {
169 a = (unsigned int)v / (unsigned int)s;
170 b = (unsigned int)v % (unsigned int)s;
171 }
172 else
173 {
174 a = v / s;
175 b = v % s;
176 }
177 if (x)
178 {
179 if ((s > 0 && b < 0)
180 || (s < 0 && b > 0))
181 {
182 a --;
183 b += s;
184 }
185 }
186 tprintf ("%d / %d = %d rem %d\n", v, s, a, b);
187 if ((!u && (a > (w ? 32767 : 127)
188 || a < (w ? -32768 : -129)))
189 || (u && (a > (w ? 65536 : 255))))
190 set_flags (FLAGBIT_O, FLAGBIT_O);
191 else
192 set_flags (FLAGBIT_O, 0);
193
194 put_reg (w ? r0 : r0l, a);
195 put_reg (w ? r2 : r0h, b);
196}
197
198static void
199rot_op (srcdest sd, int rotc, int count)
200{
201 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
202 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
203 int v = get_src (sd);
204 int c = carry, ct;
205
206 tprintf("%s %x by %d\n", rotc ? "rotc" : "rot", v, count);
207 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
208 while (count > 0)
209 {
210 ct = (v & msb) ? 1 : 0;
211 v <<= 1;
212 v |= rotc ? c : ct;
213 v &= mask;
214 c = ct;
215 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
216 count --;
217 }
218 while (count < 0)
219 {
220 ct = v & 1;
221 v >>= 1;
222 v |= (rotc ? c : ct) * msb;
223 c = ct;
224 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
225 count ++;
226 }
227 put_dest (sd, v);
228 set_szc (v, sd.bytes, c);
229}
230
231static void
232shift_op (srcdest sd, int arith, int count)
233{
234 int mask = (sd.bytes == 2) ? 0xffff : 0xff;
235 int msb = (sd.bytes == 2) ? 0x8000 : 0x80;
236 int v = get_src (sd);
237 int c = 0;
238
239 if (sd.bytes == 4)
240 {
241 mask = 0xffffffffU;
242 msb = 0x80000000U;
727b6b4b
DD
243 if (count > 16 || count < -16)
244 {
245 fprintf(stderr, "Error: SI shift of %d undefined\n", count);
246 exit(1);
247 }
248 if (count > 16)
249 count = (count - 1) % 16 + 1;
250 if (count < -16)
251 count = -((-count - 1) % 16 + 1);
d45a4bef
JB
252 }
253
254 tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
255 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
256 while (count > 0)
257 {
258 c = (v & msb) ? 1 : 0;
259 v <<= 1;
260 v &= mask;
261 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
262 count --;
263 }
264 while (count < 0)
265 {
266 c = v & 1;
267 if (arith)
268 v = (v & msb) | (v >> 1);
269 else
270 v = (v >> 1) & (msb - 1);
271 tprintf (": %s %d\n", bits(v, 8*sd.bytes), c);
272 count ++;
273 }
274 put_dest (sd, v);
275 set_szc (v, sd.bytes, c);
276}
277
278#define MATH_OP(dc,s,c,op,carryrel) \
279 a = get_src(dc); \
280 b = s & b2mask[dc.bytes]; \
281 v2 = a op b op c; \
282 tprintf("0x%x " #op " 0x%x " #op " 0x%x = 0x%x\n", a, b, c, v2); \
283 a = sign_ext (a, dc.bytes * 8); \
284 b = sign_ext (s, dc.bytes * 8); \
285 v = a op b op c; \
286 tprintf("%d " #op " %d " #op " %d = %d\n", a, b, c, v); \
287 set_oszc (v, dc.bytes, v2 carryrel); \
288 put_dest (dc, v2);
289
290#define BIT_OP(field,expr) \
291 dc = decode_bit (field); \
292 b = get_bit (dc); \
293 v = expr; \
294 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
295 put_bit (dc, v);
296
297#define BIT_OPC(field,expr) \
298 dc = decode_bit (field); \
299 b = get_bit (dc); \
300 v = expr; \
301 tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
302 set_c (v);
303
727b6b4b
DD
304/* The "BMcnd dest" opcode uses a different encoding for the */
305/* condition than other opcodes. */
306static int bmcnd_cond_map[] = {
307 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15
308};
309
d45a4bef
JB
310int
311decode_r8c()
312{
313 unsigned char op[40];
314 int opi = 0;
315 int v, v2, a, b;
316 int orig_pc = get_reg (pc);
317 srcdest sc, dc;
318 int imm;
319
320 step_result = M32C_MAKE_STEPPED ();
321
322 tprintf("trace: decode pc = %05x\n", orig_pc);
323
324 /** VARY dst 011 100 101 110 111 */
325
326 /** 0111 011w 1111 dest ABS.size dest */
327
328 UNARY_SOP;
329 a = v<0 ? -v : v;
330 tprintf("abs(%d) = %d\n", v, a);
331 set_osz(a, w+1);
332 put_dest (dc, a);
333
334 /** 0111 011w 0110 dest ADC.size #IMM,dest */
335
336 dc = decode_srcdest4(dest, w);
337 imm = IMM(w);
338 MATH_OP (dc, imm, carry, +, > (w?0xffff:0xff));
339
340 /** 1011 000w srcx dest ADC.size src,dest */
341
342 sc = decode_srcdest4(srcx, w);
343 dc = decode_srcdest4(dest, w);
344 b = get_src (sc);
345 MATH_OP (dc, b, carry, +, > (w?0xffff:0xff));
346
347 /** 0111 011w 1110 dest ADCF.size dest */
348
349 dc = decode_srcdest4(dest, w);
350 MATH_OP (dc, 0, carry, +, > (w?0xffff:0xff));
351
352 /** 0111 011w 0100 dest ADD.size:G #imm,dest */
353
354 dc = decode_srcdest4(dest, w);
355 imm = IMM(w);
356 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
357
358 /** 1100 100w immm dest ADD.size:Q #IMM,dest */
359
360 dc = decode_srcdest4(dest, w);
361 imm = sign_ext (immm, 4);
362 MATH_OP (dc, imm, 0, +, > (w?0xffff:0xff));
363
364 /** 1000 0dst ADD.B:S #IMM8,dst */
365
366 imm = IMM(0);
367 dc = decode_dest3 (dst, 0);
368 MATH_OP (dc, imm, 0, +, > 0xff);
369
370 /** 1010 000w srcx dest ADD.size:G src,dest */
371
372 sc = decode_srcdest4(srcx, w);
373 dc = decode_srcdest4(dest, w);
374 b = get_src (sc);
375 MATH_OP (dc, b, 0, +, > (w?0xffff:0xff));
376
377 /** 0010 0d sr ADD.B:S src,R0L/R0H */
378
379 sc = decode_src2 (sr, 0, d);
380 dc = decode_dest1 (d, 0);
381 b = get_src (sc);
382 MATH_OP (dc, b, 0, +, > 0xff);
383
384 /** 0111 110w 1110 1011 ADD.size:G #IMM,sp */
385
386 dc = reg_sd (sp);
387 imm = sign_ext (IMM(w), w?16:8);
388 MATH_OP (dc, imm, 0, +, > 0xffff);
389
390 /** 0111 1101 1011 immm ADD.size:Q #IMM,sp */
391
392 dc = reg_sd (sp);
393 imm = sign_ext (immm, 4);
394 MATH_OP (dc, imm, 0, +, > 0xffff);
395
396 /** 1111 100w immm dest ADJNZ.size #IMM,dest,label */
397
398 UNARY_UOP;
399 imm = sign_ext(immm, 4);
400 tprintf("%x + %d = %x\n", v, imm, v+imm);
401 v += imm;
402 put_dest (dc, v);
403 a = sign_ext (IMM(0), 8);
404 if ((v & (w ? 0xffff : 0xff)) != 0)
405 {
406 tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
407 put_reg (pc, orig_pc + 2 + a);
408 tprintf("%x\n", get_reg (pc));
409 }
410
411 /** 0111 011w 0010 dest AND.size:G #IMM,dest */
412
413 UNARY_UOP;
414 imm = IMM(w);
415 tprintf ("%x & %x = %x\n", v, imm, v & imm);
416 v &= imm;
417 set_sz (v, w+1);
418 put_dest (dc, v);
419
420 /** 1001 0dst AND.B:S #IMM8,dest */
421
422 imm = IMM(0);
423 dc = decode_dest3 (dst, 0);
424 v = get_src (dc);
425 tprintf("%x & %x = %x\n", v, imm, v & imm);
426 v &= imm;
427 set_sz (v, 1);
428 put_dest (dc, v);
429
430 /** 1001 000w srcx dest AND.size:G src.dest */
431
432 BINARY_UOP;
433 tprintf ("%x & %x = %x\n", a, b, a & b);
434 v = a & b;
435 set_sz (v, w+1);
436 put_dest (dc, v);
437
438 /** 0001 0d sr AND.B:S src,R0L/R0H */
439
440 sc = decode_src2 (sr, 0, d);
441 dc = decode_dest1 (d, 0);
442 a = get_src (sc);
443 b = get_src (dc);
444 v = a & b;
445 tprintf("%x & %x = %x\n", a, b, v);
446 set_sz (v, 1);
447 put_dest (dc, v);
448
449 /** 0111 1110 0100 srcx BAND src */
450
451 BIT_OPC (srcx, b & carry);
452
453 /** 0111 1110 1000 dest BCLR:G dest */
454
455 dc = decode_bit (dest);
456 put_bit (dc, 0);
457
458 /** 0100 0bit BCLR:S bit,base:11[SB] */
459
460 dc = decode_bit11 (bit);
461 put_bit (dc, 0);
462
463 /** 0111 1110 0010 dest BMcnd dest */
464
465 dc = decode_bit (dest);
727b6b4b 466 if (condition_true (bmcnd_cond_map [IMM (0) & 15]))
d45a4bef
JB
467 put_bit (dc, 1);
468 else
469 put_bit (dc, 0);
470
471 /** 0111 1101 1101 cond BMcnd C */
472
473 if (condition_true (cond))
474 set_c (1);
475 else
476 set_c (0);
477
478 /** 0111 1110 0101 srcx BNAND src */
479
480 BIT_OPC (srcx, !b & carry);
481
482 /** 0111 1110 0111 srcx BNOR src */
483
484 BIT_OPC (srcx, !b | carry);
485
486 /** 0111 1110 1010 dest BNOT:G dest */
487
488 BIT_OP (dest, !b);
489
490 /** 0101 0bit BNOT:S bit,base:11[SB] */
491
492 dc = decode_bit11 (bit);
493 put_bit (dc, !get_bit (dc));
494
495 /** 0111 1110 0011 srcx BNTST src */
496
497 dc = decode_bit (srcx);
498 b = get_bit (dc);
499 set_zc (!b, !b);
500
501 /** 0111 1110 1101 srcx BNXOR src */
502
503 BIT_OPC (srcx, !b ^ carry);
504
505 /** 0111 1110 0110 srcx BOR src */
506
507 BIT_OPC (srcx, b | carry);
508
509 /** 0000 0000 BRK */
510
511 /* We report the break to our caller with the PC still pointing at the
512 breakpoint instruction. */
513 put_reg (pc, orig_pc);
514 if (verbose)
515 printf("[break]\n");
516 return M32C_MAKE_HIT_BREAK ();
517
518 /** 0111 1110 1001 dest BSET:G dest */
519
520 dc = decode_bit (dest);
521 put_bit (dc, 1);
522
523 /** 0100 1bit BSET:S bit,base:11[SB] */
524
525 dc = decode_bit11 (bit);
526 put_bit (dc, 1);
527
528 /** 0111 1110 1011 srcx BTST:G src */
529
530 dc = decode_bit (srcx);
531 b = get_bit (dc);
532 set_zc (!b, b);
533
534 /** 0101 1bit BTST:S bit,base:11[SB] */
535
536 dc = decode_bit11 (bit);
537 b = get_bit (dc);
538 set_zc (!b, b);
539
540 /** 0111 1110 0000 dest BTSTC dest */
541
542 dc = decode_bit (dest);
543 b = get_bit (dc);
544 set_zc (!b, b);
545 put_bit (dc, 0);
546
547 /** 0111 1110 0001 dest BTSTS dest */
548
549 dc = decode_bit (dest);
550 b = get_bit (dc);
551 set_zc (!b, b);
552 put_bit (dc, 1);
553
554 /** 0111 1110 1100 srcx BXOR src */
555
556 BIT_OPC (srcx, b ^ carry);
557
558 /** 0111 011w 1000 dest CMP.size:G #IMM,dest */
559
560 UNARY_UOP;
561 imm = IMM(w);
562 cmp (v, imm, w);
563
564 /** 1101 000w immm dest CMP.size:Q #IMM,dest */
565
566 UNARY_UOP;
567 immm = sign_ext (immm, 4);
568 cmp (v, immm, w);
569
570 /** 1110 0dst CMP.B:S #IMM8,dest */
571
572 imm = IMM(0);
573 dc = decode_dest3 (dst, 0);
574 v = get_src (dc);
575 cmp (v, imm, 0);
576
577 /** 1100 000w srcx dest CMP.size:G src,dest */
578
579 BINARY_UOP;
580 cmp(b, a, w);
581
582 /** 0011 1d sr CMP.B:S src,R0L/R0H */
583
584 sc = decode_src2 (sr, 0, d);
585 dc = decode_dest1 (d, 0);
586 a = get_src (sc);
587 b = get_src (dc);
588 cmp (b, a, 0);
589
590 /** 0111 110w 1110 i1c s DADC,DADD,DSBB,DSUB */
591
592 /* w = width, i = immediate, c = carry, s = subtract */
593
594 int src = i ? IMM(w) : get_reg (w ? r1 : r0h);
595 int dest = get_reg (w ? r0 : r0l);
596 int res;
597
598 src = bcd2int(src, w);
599 dest = bcd2int(dest, w);
600
601 tprintf("decimal: %d %s %d", dest, s?"-":"+", src);
602 if (c)
603 tprintf(" c=%d", carry);
604
605 if (!s)
606 {
607 res = dest + src;
608 if (c)
609 res += carry;
610 c = res > (w ? 9999 : 99);
611 }
612 else
613 {
614 res = dest - src;
615 if (c)
616 res -= (1-carry);
617 c = res >= 0;
618 if (res < 0)
619 res += w ? 10000 : 100;
620 }
621
622 res = int2bcd (res, w);
623 tprintf(" = %x\n", res);
624
625 set_szc (res, w+1, c);
626
627 put_reg (w ? r0 : r0l, res);
628
629 /** 1010 1dst DEC.B dest */
630
631 dc = decode_dest3 (dst, 0);
632 v = get_src (dc);
633 tprintf("%x -- = %x\n", v, v-1);
634 v --;
635 set_sz (v, 1);
636 put_dest (dc, v);
637
638 /** 1111 d010 DEC.W dest */
639
640 v = get_reg (d ? a1 : a0);
641 tprintf("%x -- = %x\n", v, v-1);
642 v --;
643 set_sz (v, 2);
644 put_reg (d ? a1 : a0, v);
645
646 /** 0111 110w 1110 0001 DIV.size #IMM */
647
648 div_op (-1, 0, 0, w);
649
650 /** 0111 011w 1101 srcx DIV.size src */
651
652 div_op (srcx, 0, 0, w);
653
654 /** 0111 110w 1110 0000 DIVU.size #IMM */
655
656 div_op (-1, 1, 0, w);
657
658 /** 0111 011w 1100 srcx DIVU.size src */
659
660 div_op (srcx, 1, 0, w);
661
662 /** 0111 110w 1110 0011 DIVX.size #IMM */
663
664 div_op (-1, 0, 1, w);
665
666 /** 0111 011w 1001 srcx DIVX.size src */
667
668 div_op (srcx, 0, 1, w);
669
670 /** 0111 1100 1111 0010 ENTER #IMM8 */
671
672 imm = IMM(0);
673 put_reg (sp, get_reg (sp) - 2);
674 mem_put_hi (get_reg (sp), get_reg (fb));
675 put_reg (fb, get_reg (sp));
676 put_reg (sp, get_reg (sp) - imm);
677
678 /** 0111 1101 1111 0010 EXITD */
679
680 put_reg (sp, get_reg (fb));
681 put_reg (fb, mem_get_hi (get_reg (sp)));
682 put_reg (sp, get_reg (sp) + 2);
683 put_reg (pc, mem_get_psi (get_reg (sp)));
684 put_reg (sp, get_reg (sp) + 3);
685
686 /** 0111 1100 0110 dest EXTS.B dest */
687
688 dc = decode_srcdest4 (dest, 0);
689 v = sign_ext (get_src (dc), 8);
690 dc = widen_sd (dc);
691 put_dest (dc, v);
692 set_sz (v, 1);
693
694 /** 0111 1100 1111 0011 EXTS.W R0 */
695
696 v = sign_ext (get_reg (r0), 16);
697 put_reg (r2r0, v);
698 set_sz (v, 2);
699
700 /** 1110 1011 0flg 0101 FCLR dest */
701
702 set_flags (1 << flg, 0);
703
704 /** 1110 1011 0flg 0100 FSET dest */
705
706 set_flags (1 << flg, 1 << flg);
707
708 /** 1010 0dst INC.B dest */
709
710 dc = decode_dest3 (dst, 0);
711 v = get_src (dc);
712 tprintf("%x ++ = %x\n", v, v+1);
713 v ++;
714 set_sz (v, 1);
715 put_dest (dc, v);
716
717 /** 1011 d010 INC.W dest */
718
719 v = get_reg (d ? a1 : a0);
720 tprintf("%x ++ = %x\n", v, v+1);
721 v ++;
722 set_sz (v, 2);
723 put_reg (d ? a1 : a0, v);
724
725 /** 1110 1011 11vector INT #imm */
726
727 trigger_based_interrupt (vector);
728
729 /** 1111 0110 INTO */
730
731 if (FLAG_O)
732 trigger_fixed_interrupt (0xffe0);
733
734 /** 0110 1cnd Jcnd label */
735
736 v = sign_ext (IMM(0), 8);
737 if (condition_true (cnd))
738 put_reg (pc, orig_pc + 1 + v);
739
740 /** 0111 1101 1100 cond Jcnd label */
741
742 v = sign_ext (IMM(0), 8);
743 if (condition_true (cond))
744 put_reg (pc, orig_pc + 2 + v);
745
746 /** 0110 0dsp JMP.S label */
747
748 put_reg (pc, orig_pc + 2 + dsp);
749
750 /** 1111 1110 JMP.B label */
751
752 imm = sign_ext (IMM(0), 8);
753 if (imm == -1)
754 {
755 if (verbose)
756 printf("[jmp-to-self detected as exit]\n");
757 return M32C_MAKE_HIT_BREAK ();
758 }
759 put_reg (pc, orig_pc + 1 + imm);
760
761 /** 1111 0100 JMP.W label */
762
763 imm = sign_ext (IMM(1), 16);
764 put_reg (pc, orig_pc + 1 + imm);
765
766 /** 1111 1100 JMP.A label */
767
768 imm = IMM(2);
769 put_reg (pc, imm);
770
771 /** 0111 1101 0010 srcx JMPI.W src */
772
773 sc = decode_jumpdest (srcx, 1);
774 a = get_src (sc);
775 a = sign_ext (a, 16);
776 put_reg (pc, orig_pc + a);
777
778 /** 0111 1101 0000 srcx JMPI.A src */
779
780 sc = decode_jumpdest (srcx, 0);
781 a = get_src (sc);
782 put_reg (pc, a);
783
784 /** 1110 1110 JMPS #IMM8 */
785
786 M16C_ONLY();
787
788 imm = IMM(0);
789 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
790 put_reg (pc, a);
791
792 /** 1111 0101 JSR.W label */
793
794 imm = sign_ext (IMM(1), 16);
795 put_reg (sp, get_reg (sp) - 3);
796 mem_put_psi (get_reg (sp), get_reg (pc));
797 put_reg (pc, orig_pc + imm + 1);
798
799 /** 1111 1101 JSR.A label */
800
801 imm = IMM(2);
802 put_reg (sp, get_reg (sp) - 3);
803 mem_put_psi (get_reg (sp), get_reg (pc));
804 put_reg (pc, imm);
805
806 /** 0111 1101 0011 srcx JSRI.W src */
807
808 sc = decode_jumpdest (srcx, 1);
809 a = get_src (sc);
810 a = sign_ext (a, 16);
811
812 put_reg (sp, get_reg (sp) - 3);
813 mem_put_psi (get_reg (sp), get_reg (pc));
814 put_reg (pc, orig_pc + a);
815
816 /** 0111 1101 0001 srcx JSRI.A src */
817
818 sc = decode_jumpdest (srcx, 0);
819 a = get_src (sc);
820
821 put_reg (sp, get_reg (sp) - 3);
822 mem_put_psi (get_reg (sp), get_reg (pc));
823 put_reg (pc, a);
824
825 /** 1110 1111 JSRS #IMM8 */
826
827 M16C_ONLY();
828
829 imm = IMM(0);
830 a = 0xf0000 + mem_get_hi (0xffffe - imm * 2);
831
832 put_reg (sp, get_reg (sp) - 3);
833 mem_put_psi (get_reg (sp), get_reg (pc));
834 put_reg (pc, a);
835
836 /** 1110 1011 0reg 0000 LDC #IMM16,dest */
837
838 dc = decode_cr (reg);
839 imm = IMM(1);
840 put_dest (dc, imm);
841
842 /** 0111 1010 1reg srcx LDC src,dest */
843
844 dc = decode_cr (reg);
845 sc = decode_srcdest4 (srcx,1);
846 put_dest (dc, get_src (sc));
847
848 /** 0111 1100 1111 0000 LDCTX abs16,abs20 */
849
850 NOTYET();
851
852 /** 0111 010w 1000 dest LDE.size abs20,dest */
853
854 dc = decode_srcdest4 (dest, w);
855 imm = IMM(2);
856 if (w)
857 v = mem_get_hi (imm);
858 else
859 v = mem_get_qi (imm);
860 put_dest (dc, v);
861
862 /** 0111 010w 1001 dest LDE.size dsp:20[a0], dest */
863
864 dc = decode_srcdest4 (dest, w);
865 imm = IMM(2) + get_reg (a0);
866 if (w)
867 v = mem_get_hi (imm);
868 else
869 v = mem_get_qi (imm);
870 put_dest (dc, v);
871
872 /** 0111 010w 1010 dest LDE.size [a1a0],dest */
873
874 dc = decode_srcdest4 (dest, w);
875 imm = get_reg (a1a0);
876 if (w)
877 v = mem_get_hi (imm);
878 else
879 v = mem_get_qi (imm);
880 put_dest (dc, v);
881
882 /** 0111 1101 1010 0imm LDIPL #IMM */
883
884 set_flags (0x700, imm*0x100);
885
886 /** 0111 010w 1100 dest MOV.size:G #IMM,dest */
887
f4f21c20 888 dc = decode_srcdest4 (dest, w);
d45a4bef
JB
889 imm = IMM(w);
890 v = imm;
891 tprintf("%x = %x\n", v, v);
892 set_sz(v, w+1);
893 put_dest (dc, v);
894
895 /** 1101 100w immm dest MOV.size:Q #IMM,dest */
896
f4f21c20 897 dc = decode_srcdest4 (dest, w);
d45a4bef
JB
898 v = sign_ext (immm, 4);
899 tprintf ("%x = %x\n", v, v);
900 set_sz (v, w+1);
901 put_dest (dc, v);
902
903 /** 1100 0dst MOV.B:S #IMM8,dest */
904
905 imm = IMM(0);
906 dc = decode_dest3 (dst, 0);
907 v = imm;
908 tprintf("%x = %x\n", v, v);
909 set_sz (v, 1);
910 put_dest (dc, v);
911
912 /** 1w10 d010 MOV.size:S #IMM,dest */
913
914 /* Note that for w, 0=W and 1=B unlike the usual meaning. */
915 v = IMM(1-w);
916 tprintf("%x = %x\n", v, v);
917 set_sz (v, 2-w);
918 put_reg (d ? a1 : a0, v);
919
920 /** 1011 0dst MOV.B:Z #0,dest */
921
922 dc = decode_dest3 (dst, 0);
923 v = 0;
924 set_sz (v, 1);
925 put_dest (dc, v);
926
927 /** 0111 001w srcx dest MOV.size:G src,dest */
928
929 sc = decode_srcdest4 (srcx, w);
930 dc = decode_srcdest4 (dest, w);
931 v = get_src (sc);
932 set_sz (v, w+1);
933 put_dest (dc, v);
934
935 /** 0011 0d sr MOV.B:S src,dest */
936
937 sc = decode_src2 (sr, 0, d);
938 v = get_src (sc);
939 set_sz (v, 1);
940 put_reg (d ? a1 : a0, v);
941
942 /** 0000 0s ds MOV.B:S R0L/R0H,dest */
943
944 if (ds == 0)
945 UNSUPPORTED();
946 dc = decode_src2 (ds, 0, s);
947 v = get_reg (s ? r0h : r0l);
948 set_sz (v, 1);
949 put_dest (dc, v);
950
951 /** 0000 1d sr MOV.B:S src,R0L/R0H */
952
953 sc = decode_src2 (sr, 0, d);
954 v = get_src (sc);
955 set_sz (v, 1);
956 put_reg (d ? r0h : r0l, v);
957
958 /** 0111 010w 1011 dest MOV.size:G dsp:8[SP], dest */
959
960 dc = decode_srcdest4 (dest, w);
961 imm = IMM(0);
962 a = get_reg (sp) + sign_ext (imm, 8);
963 a &= addr_mask;
964 if (w)
965 v = mem_get_hi (a);
966 else
967 v = mem_get_qi (a);
968 set_sz (v, w+1);
969 put_dest (dc, v);
970
971 /** 0111 010w 0011 srcx MOV.size:G src, disp8[SP] */
972
973 sc = decode_srcdest4 (srcx, w);
974 imm = IMM(0);
975 a = get_reg (sp) + sign_ext (imm, 8);
976 a &= addr_mask;
977 v = get_src (sc);
978 if (w)
979 mem_put_hi (a, v);
980 else
981 mem_put_qi (a, v);
982 set_sz (v, w+1);
983
984 /** 1110 1011 0reg 1src MOVA src,dest */
985
986 static reg_id map[] = { r0, r1, r2, r3, a0, a1, 0, 0 };
987 sc = decode_srcdest4 (8 + src, 0);
988 put_reg (map[reg], sc.u.addr);
989
990 /** 0111 1100 10hl dest MOVdir R0L,dest */
991
992 if (dest == 0 || dest == 4 || dest == 5)
993 UNSUPPORTED();
994 dc = decode_srcdest4 (dest, 0);
995 a = get_src (dc);
996 b = get_reg (r0l);
997 switch (hl)
998 {
999 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1000 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1001 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1002 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1003 }
1004 put_dest (dc, a);
1005
1006 /** 0111 1100 00hl srcx MOVdir src,R0L */
1007
1008 if (srcx == 0 || srcx == 4 || srcx == 5)
1009 UNSUPPORTED();
1010 sc = decode_srcdest4 (srcx, 0);
1011 a = get_reg (r0l);
1012 b = get_src (sc);
1013 switch (hl)
1014 {
1015 case 0: a = (a & 0xf0) | (b & 0x0f); break;
1016 case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1017 case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1018 case 3: a = (a & 0x0f) | (b & 0xf0); break;
1019 }
1020 put_reg (r0l, a);
1021
1022 /** 0111 110w 0101 dest MUL.size #IMM,dest */
1023
1024 UNARY_SOP;
1025 imm = sign_ext (IMM(w), w?16:8);
1026 tprintf("%d * %d = %d\n", v, imm, v*imm);
1027 v *= imm;
1028 dc = widen_sd (dc);
1029 put_dest (dc, v);
1030
1031 /** 0111 100w srcx dest MUL.size src,dest */
1032
1033 BINARY_SOP;
1034 v = a * b;
1035 tprintf("%d * %d = %d\n", a, b, v);
1036 dc = widen_sd (dc);
1037 put_dest (dc, v);
1038
1039 /** 0111 110w 0100 dest MULU.size #IMM,dest */
1040
1041 UNARY_UOP;
1042 imm = IMM(w);
1043 tprintf("%u * %u = %u\n", v, imm, v*imm);
1044 v *= imm;
1045 dc = widen_sd (dc);
1046 put_dest (dc, v);
1047
1048 /** 0111 000w srcx dest MULU.size src,dest */
1049
1050 BINARY_UOP;
1051 v = a * b;
1052 tprintf("%u * %u = %u\n", a, b, v);
1053 dc = widen_sd (dc);
1054 put_dest (dc, v);
1055
1056 /** 0111 010w 0101 dest NEG.size dest */
1057
1058 UNARY_SOP;
1059 tprintf("%d * -1 = %d\n", v, -v);
1060 v = -v;
1061 set_oszc (v, w+1, v == 0);
1062 put_dest (dc, v);
1063
1064 /** 0000 0100 NOP */
1065
1066 tprintf("nop\n");
1067
1068 /** 0111 010w 0111 dest NOT.size:G */
1069
1070 UNARY_UOP;
1071 tprintf("~ %x = %x\n", v, ~v);
1072 v = ~v;
1073 set_sz (v, w+1);
1074 put_dest (dc, v);
1075
1076 /** 1011 1dst NOT.B:S dest */
1077
1078 dc = decode_dest3 (dst, 0);
1079 v = get_src (dc);
1080 tprintf("~ %x = %x\n", v, ~v);
1081 v = ~v;
1082 set_sz (v, 1);
1083 put_dest (dc, v);
1084
1085 /** 0111 011w 0011 dest OR.size:G #IMM,dest */
1086
1087 UNARY_UOP;
1088 imm = IMM(w);
1089 tprintf ("%x | %x = %x\n", v, imm, v | imm);
1090 v |= imm;
1091 set_sz (v, w+1);
1092 put_dest (dc, v);
1093
1094 /** 1001 1dst OR.B:S #IMM8,dest */
1095
1096 imm = IMM(0);
1097 dc = decode_dest3 (dst, 0);
1098 v = get_src (dc);
1099 tprintf("%x | %x = %x\n", v, imm, v|imm);
1100 v |= imm;
1101 set_sz (v, 1);
1102 put_dest (dc, v);
1103
1104 /** 1001 100w srcx dest OR.size:G src,dest */
1105
1106 BINARY_UOP;
1107 tprintf ("%x | %x = %x\n", a, b, a | b);
1108 v = a | b;
1109 set_sz (v, w+1);
1110 put_dest (dc, v);
1111
1112 /** 0001 1d sr OR.B:S src,R0L/R0H */
1113
1114 sc = decode_src2 (sr, 0, d);
1115 dc = decode_dest1 (d, 0);
1116 a = get_src (sc);
1117 b = get_src (dc);
1118 v = a | b;
1119 tprintf("%x | %x = %x\n", a, b, v);
1120 set_sz (v, 1);
1121 put_dest (dc, v);
1122
1123 /** 0111 010w 1101 dest POP.size:G dest */
1124
1125 dc = decode_srcdest4 (dest, w);
1126 if (w)
1127 {
1128 v = mem_get_hi (get_reg (sp));
1129 put_reg (sp, get_reg (sp) + 2);
1130 tprintf("pophi: %x\n", v);
1131 }
1132 else
1133 {
1134 v = mem_get_qi (get_reg (sp));
1135 put_reg (sp, get_reg (sp) + 1);
1136 tprintf("popqi: %x\n", v);
1137 }
1138 put_dest (dc, v);
1139
1140 /** 1001 d010 POP.B:S dest */
1141
1142 v = mem_get_qi (get_reg (sp));
1143 put_reg (d ? r0h : r0l, v);
1144 put_reg (sp, get_reg (sp) + 1);
1145 tprintf("popqi: %x\n", v);
1146
1147 /** 1101 d010 POP.W:S dest */
1148
1149 v = mem_get_hi (get_reg (sp));
1150 put_reg (d ? a1 : a0, v);
1151 put_reg (sp, get_reg (sp) + 2);
1152 tprintf("pophi: %x\n", v);
1153
1154 /** 1110 1011 0reg 0011 POPC dest */
1155
1156 dc = decode_cr (reg);
1157 v = mem_get_hi (get_reg (sp));
1158 put_dest (dc, v);
1159 put_reg (sp, get_reg (sp) + 2);
1160 tprintf("popc: %x\n", v);
1161
1162 /** 1110 1101 POPM dest */
1163
1164 static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1165 imm = IMM(0);
1166 tprintf("popm: %x\n", imm);
1167 for (a=0; a<8; a++)
1168 if (imm & (1<<a))
1169 {
1170 v = mem_get_hi (get_reg (sp));
1171 put_reg (map[a], v);
1172 put_reg (sp, get_reg (sp) + 2);
1173 }
1174
1175 /** 0111 110w 1110 0010 PUSH.size:G #IMM */
1176
1177 imm = IMM(w);
1178 if (w)
1179 {
1180 put_reg (sp, get_reg (sp) - 2);
1181 mem_put_hi (get_reg (sp), imm);
1182 tprintf("pushhi %04x\n", imm);
1183 }
1184 else
1185 {
1186 put_reg (sp, get_reg (sp) - 1);
1187 mem_put_qi (get_reg (sp), imm);
1188 tprintf("pushqi %02x\n", imm);
1189 }
1190
1191 /** 0111 010w 0100 srcx PUSH.size:G src */
1192
1193 sc = decode_srcdest4 (srcx, w);
1194 v = get_src (sc);
1195 if (w)
1196 {
1197 put_reg (sp, get_reg (sp) - 2);
1198 mem_put_hi (get_reg (sp), v);
1199 tprintf("pushhi: %x\n", v);
1200 }
1201 else
1202 {
1203 put_reg (sp, get_reg (sp) - 1);
1204 mem_put_qi (get_reg (sp), v);
1205 tprintf("pushqi: %x\n", v);
1206 }
1207
1208 /** 1000 s010 PUSH.B:S src */
1209
1210 v = get_reg (s ? r0h : r0l);
1211 put_reg (sp, get_reg (sp) - 1);
1212 mem_put_qi (get_reg (sp), v);
1213 tprintf("pushqi: %x\n", v);
1214
1215 /** 1100 s010 PUSH.W:S src */
1216
1217 v = get_reg (s ? a1 : a0);
1218 put_reg (sp, get_reg (sp) - 2);
1219 mem_put_hi (get_reg (sp), v);
1220 tprintf("pushhi: %x\n", v);
1221
1222 /** 0111 1101 1001 srcx PUSHA src */
1223
1224 sc = decode_srcdest4 (srcx, 0);
1225 put_reg (sp, get_reg (sp) - 2);
1226 mem_put_hi (get_reg (sp), sc.u.addr);
1227 tprintf("pushhi: %x\n", sc.u.addr);
1228
1229 /** 1110 1011 0src 0010 PUSHC src */
1230
1231 sc = decode_cr (src);
1232 put_reg (sp, get_reg (sp) - 2);
1233 v = get_src (sc);
1234 mem_put_hi (get_reg (sp), v);
1235 tprintf("pushc: %x\n", v);
1236
1237 /** 1110 1100 PUSHM src */
1238
1239 static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1240 imm = IMM(0);
1241 tprintf("pushm: %x\n", imm);
1242 for (a=0; a<8; a++)
1243 if (imm & (1<<a))
1244 {
1245 put_reg (sp, get_reg (sp) - 2);
1246 v = get_reg (map[a]);
1247 mem_put_hi (get_reg (sp), v);
1248 }
1249
1250 /** 1111 1011 REIT */
1251
1252 a = get_reg (sp);
1253 v = (mem_get_hi (a)
1254 + 65536 * (mem_get_qi (a+3) & 0x0f));
1255 b = (mem_get_qi (a+2)
1256 + 16 * (mem_get_qi (a+3) & 0xf0));
1257 put_reg (pc, v);
1258 put_reg (flags, b);
1259 put_reg (sp, get_reg (sp) + 4);
1260
1261 /** 0111 110w 1111 0001 RMPA.size */
1262
1263 int count = get_reg (r3);
1264 int list1 = get_reg (a0);
1265 int list2 = get_reg (a1);
1266 int sum = get_reg (w ? r2r0 : r0);
1267
1268 while (count)
1269 {
1270 if (w)
1271 {
1272 a = sign_ext (mem_get_hi (list1), 16);
1273 b = sign_ext (mem_get_hi (list2), 16);
1274 }
1275 else
1276 {
1277 a = sign_ext (mem_get_qi (list1), 8);
1278 b = sign_ext (mem_get_qi (list2), 8);
1279 }
1280 tprintf("%d + %d * %d = ", sum, a, b);
1281 sum += a * b;
1282 tprintf("%d\n", sum);
1283 list1 += w ? 2 : 1;
1284 list2 += w ? 2 : 1;
1285 count --;
1286 }
1287 put_reg (r3, count);
1288 put_reg (a0, list1);
1289 put_reg (a1, list2);
1290 put_reg (w ? r2r0 : r0, sum);
1291
1292 /** 0111 011w 1010 dest ROLC.size dest */
1293
1294 dc = decode_srcdest4 (dest, w);
1295 rot_op (dc, 1, 1);
1296
1297 /** 0111 011w 1011 dest RORC.size dest */
1298
1299 dc = decode_srcdest4 (dest, w);
1300 rot_op (dc, 1, -1);
1301
1302 /** 1110 000w immm dest ROT.size #IMM,dest */
1303
1304 dc = decode_srcdest4 (dest, w);
1305 rot_op (dc, 0, IMM4());
1306
1307 /** 0111 010w 0110 dest ROT.size R1H,dest */
1308
1309 dc = decode_srcdest4 (dest, w);
1310 rot_op (dc, 0, sign_ext (get_reg (r1h), 8));
1311
1312 /** 1111 0011 RTS */
1313
1314 put_reg (pc, mem_get_psi (get_reg (sp)));
1315 put_reg (sp, get_reg (sp) + 3);
1316
1317 /** 0111 011w 0111 dest SBB.size #IMM,dest */
1318
1319 dc = decode_srcdest4 (dest, w);
1320 imm = IMM(w);
1321 MATH_OP (dc, imm, !carry, -, >= 0);
1322
1323 /** 1011 100w srcx dest SBB.size src,dest */
1324
1325 sc = decode_srcdest4(srcx, w);
1326 dc = decode_srcdest4(dest, w);
1327 b = get_src (sc);
1328 MATH_OP (dc, b, !carry, -, >= 0);
1329
1330 /** 1111 000w immm dest SHA.size #IMM, dest */
1331
1332 dc = decode_srcdest4(dest, w);
1333 shift_op (dc, 1, IMM4());
1334
1335 /** 0111 010w 1111 dest SHA.size R1H,dest */
1336
1337 dc = decode_srcdest4(dest, w);
1338 a = sign_ext (get_reg (r1h), 8);
1339 shift_op (dc, 1, a);
1340
1341 /** 1110 1011 101d immm SHA.L #IMM, dest */
1342
1343 dc = reg_sd (d ? r3r1 : r2r0);
1344 shift_op (dc, 1, IMM4());
1345
1346 /** 1110 1011 001d 0001 SHA.L R1H,dest */
1347
1348 dc = reg_sd (d ? r3r1 : r2r0);
1349 a = sign_ext (get_reg (r1h), 8);
1350 shift_op (dc, 1, a);
1351
1352 /** 1110 100w immm dest SHL.size #IMM, dest */
1353
1354 dc = decode_srcdest4(dest, w);
1355 shift_op (dc, 0, IMM4());
1356
1357 /** 0111 010w 1110 dest SHL.size R1H,dest */
1358
1359 dc = decode_srcdest4(dest, w);
1360 a = sign_ext (get_reg (r1h), 8);
1361 shift_op (dc, 0, a);
1362
1363 /** 1110 1011 100d immm SHL.L #IMM,dest */
1364
1365 dc = reg_sd (d ? r3r1 : r2r0);
1366 shift_op (dc, 0, IMM4());
1367
1368 /** 1110 1011 000d 0001 SHL.L R1H,dest */
1369
1370 dc = reg_sd (d ? r3r1 : r2r0);
1371 a = sign_ext (get_reg (r1h), 8);
1372 shift_op (dc, 0, a);
1373
1374 /** 0111 110w 1110 100b SMOVB.size */
1375
1376 int count = get_reg (r3);
1377 int s1 = get_reg (a0) + (get_reg (r1h) << 16);
1378 int s2 = get_reg (a1);
1379 int inc = (w ? 2 : 1) * (b ? -1 : 1);
1380
1381 while (count)
1382 {
1383 if (w)
1384 {
1385 v = mem_get_hi (s1);
1386 mem_put_hi (s2, v);
1387 }
1388 else
1389 {
1390 v = mem_get_qi (s1);
1391 mem_put_qi (s2, v);
1392 }
1393 s1 += inc;
1394 s2 += inc;
1395 count --;
1396 }
1397 put_reg (r3, count);
1398 put_reg (a0, s1 & 0xffff);
1399 put_reg (a1, s2);
1400 put_reg (r1h, s1 >> 16);
1401
1402 /** 0111 110w 1110 1010 SSTR.size */
1403
1404 int count = get_reg (r3);
1405 int s1 = get_reg (a1);
1406 v = get_reg (w ? r0 : r0h);
1407
1408 while (count)
1409 {
1410 if (w)
1411 {
1412 mem_put_hi (s1, v);
1413 s1 += 2;
1414 }
1415 else
1416 {
1417 mem_put_qi (s1, v);
1418 s1 += 1;
1419 }
1420 count --;
1421 }
1422 put_reg (r3, count);
1423 put_reg (a1, s1);
1424
1425 /** 0111 1011 1src dest STC src,dest */
1426
1427 dc = decode_srcdest4 (dest, 1);
1428 sc = decode_cr (src);
1429 put_dest (dc, get_src(sc));
1430
1431 /** 0111 1100 1100 dest STC PC,dest */
1432
1433 dc = decode_srcdest4 (dest, 1);
1434 dc.bytes = 3;
1435 put_dest (dc, orig_pc);
1436
1437 /** 0111 1101 1111 0000 STCTX abs16,abs20 */
1438
1439 NOTYET();
1440
1441 /** 0111 010w 0000 srcx STE.size src,abs20 */
1442
1443 sc = decode_srcdest4 (srcx, w);
1444 a = IMM(2);
1445 v = get_src (sc);
1446 if (w)
1447 mem_put_hi (a, v);
1448 else
1449 mem_put_qi (a, v);
1450 if (srcx == 4 || srcx == 5)
1451 {
1452 v = get_reg (sc.u.reg);
1453 set_sz (v, 2);
1454 }
1455 else
1456 set_sz (v, w+1);
1457
1458 /** 0111 010w 0001 srcx STE.size src,disp20[a0] */
1459
1460 sc = decode_srcdest4 (srcx, w);
1461 a = get_reg(a0) + IMM(2);
1462 v = get_src (sc);
1463 if (w)
1464 mem_put_hi (a, v);
1465 else
1466 mem_put_qi (a, v);
1467 if (srcx == 4 || srcx == 5)
1468 {
1469 v = get_reg (sc.u.reg);
1470 set_sz (v, 2);
1471 }
1472 else
1473 set_sz (v, w+1);
1474
1475 /** 0111 010w 0010 srcx STE.size src,[a1a0] */
1476
1477 sc = decode_srcdest4 (srcx, w);
1478 a = get_reg(a1a0);
1479 v = get_src (sc);
1480 if (w)
1481 mem_put_hi (a, v);
1482 else
1483 mem_put_qi (a, v);
1484 if (srcx == 4 || srcx == 5)
1485 {
1486 v = get_reg (sc.u.reg);
1487 set_sz (v, 2);
1488 }
1489 else
1490 set_sz (v, w+1);
1491
1492 /** 1101 0dst STNZ #IMM8,dest */
1493
1494 imm = IMM(0);
1495 dc = decode_dest3(dst, 0);
1496 if (!FLAG_Z)
1497 put_dest (dc, imm);
1498
1499 /** 1100 1dst STZ #IMM8,dest */
1500
1501 imm = IMM(0);
1502 dc = decode_dest3(dst, 0);
1503 if (FLAG_Z)
1504 put_dest (dc, imm);
1505
1506 /** 1101 1dst STZX #IMM81,#IMM82,dest */
1507
1508 a = IMM(0);
1509 dc = decode_dest3(dst, 0);
1510 b = IMM(0);
1511 if (FLAG_Z)
1512 put_dest (dc, a);
1513 else
1514 put_dest (dc, b);
1515
1516 /** 0111 011w 0101 dest SUB.size:G #IMM,dest */
1517
1518 dc = decode_srcdest4 (dest, w);
1519 imm = IMM(w);
1520 MATH_OP (dc, imm, 0, -, >= 0);
1521
1522 /** 1000 1dst SUB.B:S #IMM8,dest */
1523
1524 imm = IMM(0);
1525 dc = decode_dest3 (dst, 0);
1526 MATH_OP (dc, imm, 0, -, >= 0);
1527
1528 /** 1010 100w srcx dest SUB.size:G src,dest */
1529
1530 sc = decode_srcdest4(srcx, w);
1531 dc = decode_srcdest4(dest, w);
1532 b = get_src (sc);
f4f21c20 1533 MATH_OP (dc, b, 0, -, >= 0);
d45a4bef
JB
1534
1535 /** 0010 1d sr SUB.B:S src,R0L/R0H */
1536
1537 sc = decode_src2 (sr, 0, d);
1538 dc = decode_dest1 (d, 0);
1539 b = get_src (sc);
f4f21c20 1540 MATH_OP (dc, b, 0, -, >= 0);
d45a4bef
JB
1541
1542 /** 0111 011w 0000 dest TST.size #IMM, dest */
1543
1544 UNARY_UOP;
1545 imm = IMM(w);
1546 tprintf ("%x & %x = %x\n", v, imm, v & imm);
1547 v &= imm;
1548 set_sz (v, w+1);
1549
1550 /** 1000 000w srcx dest TST.size src,dest */
1551
1552 BINARY_UOP;
1553 tprintf ("%x & %x = %x\n", a, b, a & b);
1554 v = a & b;
1555 set_sz (v, w+1);
1556
1557 /** 1111 1111 UND */
1558
1559 trigger_fixed_interrupt (0xffdc);
1560
1561 /** 0111 1101 1111 0011 WAIT */
1562
1563 tprintf("waiting...\n");
1564
1565 /** 0111 101w 00sr dest XCHG.size src,dest */
1566
1567 sc = decode_srcdest4 (sr, w);
1568 dc = decode_srcdest4 (dest, w);
1569 a = get_src (sc);
1570 b = get_src (dc);
1571 put_dest (dc, a);
1572 put_dest (sc, b);
1573
1574 /** 0111 011w 0001 dest XOR.size #IMM,dest */
1575
1576 UNARY_UOP;
1577 imm = IMM(w);
1578 tprintf ("%x ^ %x = %x\n", v, imm, v ^ imm);
1579 v ^= imm;
1580 set_sz (v, w+1);
1581 put_dest (dc, v);
1582
1583 /** 1000 100w srcx dest XOR.size src,dest */
1584
1585 BINARY_UOP;
1586 tprintf ("%x ^ %x = %x\n", a, b, a ^ b);
1587 v = a ^ b;
1588 set_sz (v, w+1);
1589 put_dest (dc, v);
1590
1591 /** OP */
1592/** */
1593
1594 return step_result;
1595}