OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [m32c/] [m32c.opc] - Blame information for rev 325

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.