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

Subversion Repositories openrisc_me

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

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

Line No. Rev Author Line
1 227 jeremybenn
/* m32c.opc --- semantics for m32c opcodes.                     -*- mode: c -*-
2
 
3
Copyright (C) 2005, 2007, 2008, 2009, 2010 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", m32c_opcode_pc)
53
#define NOTYET() unsupported("unimplemented", m32c_opcode_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, (1 op 1) ? (ll > b2mask[dc.bytes]) : (ll >= 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
static int pcs[16];
394
static int ipcs = 0;
395
 
396
int
397
decode_m32c()
398
{
399
  unsigned char op[40];
400
  int opi;
401
  int v, a, b;
402
  long long ll;
403
  srcdest sc, dc;
404
  int imm;
405
  int bitindex = -1;
406
  int t0, t1=0, t2, t3=0;
407
  int ta0, ta1, dif;
408
 
409
  step_result = M32C_MAKE_STEPPED ();
410
 
411
  decode_indirect (0, 0);
412
  decode_index (0, 0);
413
 
414
next_opcode:
415
  opi = 0;
416
  m32c_opcode_pc = get_reg (pc);
417
 
418
  tprintf("trace: decode pc = %06x\n", m32c_opcode_pc);
419
 
420
  if (m32c_opcode_pc == 0)
421
    {
422
      int i;
423
      printf("Abort: PC is zero, here from:\n");
424
      for (i=0; i<4; i++)
425
        printf("  0x%06x\n", pcs[(ipcs+15-i)%16]);
426
      return M32C_MAKE_HIT_BREAK ();
427
    }
428
  pcs[ipcs++] = m32c_opcode_pc;
429
  ipcs %= 16;
430
 
431
  /** VARY sss 000 001 010 011 100 */
432
  /** VARY ddd 000 001 010 011 100 */
433
 
434
  /** 0000 1001                         indirect dest */
435
 
436
  decode_indirect (0, 1);
437
  goto next_opcode;
438
 
439
  /** 0100 0001                         indirect src */
440
 
441
  decode_indirect (1, 0);
442
  goto next_opcode;
443
 
444
  /** 0100 1001                         indirect src and dest */
445
 
446
  decode_indirect (1, 1);
447
  goto next_opcode;
448
 
449
  /** 1010 ddd w dd01 1111              ABS.size dest */
450
 
451
  prefix (0, 1, 0);
452
  dc = decode_dest23 (ddd, dd, w+1);
453
  v = sign_ext (get_src (dc), w?16:8);
454
  a = v<0 ? -v : v;
455
  tprintf("abs(%d) = %d\n", v, a);
456
  set_osz(a, w+1);
457
  put_dest (dc, a);
458
 
459
  /** 0000 0001 1000 ddd w dd10 1110    ADC.size #IMM,dest */
460
 
461
  prefix (0, 0, 0);
462
  dc = decode_dest23 (ddd, dd, w+1);
463
  imm = IMM (w+1);
464
  MATH_OP (dc, imm, carry, +);
465
 
466
  /** 0000 0001 1sss ddd w dd ss 0100   ADC.size src,dest */
467
 
468
  prefix (0, 0, 0);
469
  sc = decode_src23 (sss, ss, w+1);
470
  dc = decode_dest23 (ddd, dd, w+1);
471
  b = get_src (sc);
472
  MATH_OP (dc, b, carry, +);
473
 
474
  /** 1011 ddd w dd01 1110              ADCF.size dest */
475
 
476
  prefix (0, 1, 0);
477
  dc = decode_dest23 (ddd, dd, w+1);
478
  MATH_OP (dc, 0, carry, +);
479
 
480
  /** 1000 ddd w dd10 1110              ADD.size:G #IMM,dest */
481
 
482
  prefix (0, 1, 0);
483
  dc = decode_dest23(ddd, dd, w+1);
484
  imm = IMM(w+1);
485
  MATH_OP (dc, imm, 0, +);
486
 
487
  /** 1000 ddd0 dd11 0001               ADD.L:G #IMM,dest */
488
 
489
  prefix (0, 1, 0);
490
  dc = decode_dest23(ddd, dd, 4);
491
  imm = IMM(4);
492
  MATH_OP (dc, imm, 0, +);
493
 
494
  /** 111L ddd w dd11 immm              ADD.size:Q #IMM,dest */
495
 
496
  prefix (0, 1, 0);
497
  dc = decode_dest23(ddd, dd, L ? 4 : (w+1));
498
  imm = sign_ext (immm, 4);
499
  MATH_OP (dc, imm, 0, +);
500
 
501
  /** 00dd 011w                         ADD.size:S #IMM,dest */
502
 
503
  prefix (0, 1, 0);
504
  dc = decode_dest2(dd, w+1);
505
  imm = IMM (w+1);
506
  MATH_OP (dc, imm, 0, +);
507
 
508
  /** 10i0 110d                         ADD.L:S #IMM,A0/A1 */
509
 
510
  prefix (0, 0, 0);
511
  dc = reg_sd (d ? a1 : a0);
512
  imm = i ? 2 : 1;
513
  MATH_OP (dc, imm, 0, +);
514
 
515
  /** 1sss ddd w dd ss 1000             ADD.size:G src,dest */
516
 
517
  prefix (1, 1, 0);
518
  sc = decode_src23(sss, ss, w+1);
519
  dc = decode_dest23(ddd, dd, w+1);
520
  b = get_src (sc);
521
  MATH_OP (dc, b, 0, +);
522
 
523
  /** 1sss ddd1 dd ss 0010              ADD.L:G src,dest */
524
 
525
  prefix (1, 1, 0);
526
  sc = decode_src23(sss, ss, 4);
527
  dc = decode_dest23(ddd, dd, 4);
528
  b = get_src (sc);
529
  MATH_OP (dc, b, 0, +);
530
 
531
  /** 1011 0110 0001 0011               ADD.L:G #IMM16,SP */
532
 
533
  prefix (0, 0, 0);
534
  dc = reg_sd (sp);
535
  b = sign_ext (IMM(2), 16);
536
  MATH_OP (dc, b, 0, +);
537
 
538
  /** 01ii 001i                         ADD.L:Q #IMM3,SP */
539
 
540
  prefix (0, 0, 0);
541
  dc = reg_sd (sp);
542
  b = ii * 2 + i + 1;
543
  MATH_OP (dc, b, 0, +);
544
 
545
  /** 1011 0110 0000 0011               ADD.L:S #IMM8,SP */
546
 
547
  prefix (0, 0, 0);
548
  dc = reg_sd (sp);
549
  b = sign_ext (IMM(1), 8);
550
  MATH_OP (dc, b, 0, +);
551
 
552
  /** 1000 ddd0 dd01 0001               ADDX #IMM,dest */
553
 
554
  prefix (0, 1, 0);
555
  dc = decode_dest23(ddd, dd, 4);
556
  imm = sign_ext (IMM(1), 8);
557
  MATH_OP (dc, imm, 0, +);
558
 
559
  /** 1sss ddd0 dd ss 0010              ADDX src,dest */
560
 
561
  prefix (1, 1, 0);
562
  sc = decode_src23(sss, ss, 1);
563
  dc = decode_dest23(ddd, dd, 4);
564
  b = sign_ext (get_src (sc), 8);
565
  MATH_OP (dc, b, 0, +);
566
 
567
  /** 1111 ddd w dd01 immm              ADJNZ.size #IMM,dest,label */
568
 
569
  prefix (0, 0, 0);
570
  dc = decode_dest23 (ddd, dd, w+1);
571
  v = get_src (dc);
572
  imm = sign_ext(immm, 4);
573
  tprintf("%d + %d = %d\n", v, imm, v+imm);
574
  v += imm;
575
  put_dest (dc, v);
576
  a = sign_ext (IMM(1), 8);
577
  if ((v & (w ? 0xffff : 0xff)) != 0)
578
    {
579
      tprintf("jmp: %x + 2 + %d = ", get_reg (pc), a);
580
      put_reg (pc, m32c_opcode_pc + 2 + a);
581
      tprintf("%x\n", get_reg (pc));
582
    }
583
 
584
  /** 1000 ddd w dd11 1111              AND.size:G #IMM,dest */
585
 
586
  prefix (0, 1, 0);
587
  dc = decode_dest23(ddd, dd, w+1);
588
  imm = IMM(w+1);
589
  LOGIC_OP (dc, imm, &);
590
 
591
  /** 01dd 110w                         AND.size:S #IMM,dest */
592
 
593
  prefix (0, 1, 0);
594
  dc = decode_dest2(dd, w+1);
595
  imm = IMM (w+1);
596
  LOGIC_OP (dc, imm, &);
597
 
598
  /** 1sss ddd w dd ss 1101             AND.size:G src,dest */
599
 
600
  prefix (1, 1, 0);
601
  sc = decode_src23(sss, ss, w+1);
602
  dc = decode_dest23(ddd, dd, w+1);
603
  b = get_src (sc);
604
  LOGIC_OP (dc, b, &);
605
 
606
  /** 0000 0001 1101 sss0 ss00 1bit     BAND src */
607
 
608
  sc = decode_src23 (sss, ss, 1);
609
  BIT_OPC (sc, bit, b & carry);
610
 
611
  /** 1101 ddd0 dd11 0bit               BCLR dest */
612
 
613
  dc = decode_dest23 (ddd, dd, 1);
614
  BIT_OP (dc, bit, 0);
615
 
616
  /** 1100 ddd w dd10 1110              BITINDEX.size src */
617
 
618
  prefix (0, 0, 0);
619
  dc = decode_dest23 (ddd, dd, w+1);
620
  bitindex = get_src (dc);
621
  tprintf ("bitindex set to %d\n", bitindex);
622
  goto next_opcode;
623
 
624
  /** 1101 ddd0 dd01 0bit               BMcnd dest */
625
 
626
  prefix (0, 0, 0);
627
  dc = decode_dest23 (ddd, dd, 1);
628
  if (condition_true (IMM (1)))
629
    put_bit2 (dc, bit, 1);
630
  else
631
    put_bit2 (dc, bit, 0);
632
 
633
  /** 1101 1001 0c10 1cnd               BMcnd C */
634
 
635
  prefix (0, 0, 0);
636
  if (condition_true (c * 8 + cnd))
637
    set_c (1);
638
  else
639
    set_c (0);
640
 
641
  /** 0000 0001 1101 sss0 ss01 1bit     BNAND src */
642
 
643
  prefix (0, 0, 0);
644
  sc = decode_src23 (sss, ss, 1);
645
  BIT_OPC (sc, bit, (!b) & carry);
646
 
647
  /** 0000 0001 1101 sss0 ss11 0bit     BNOR src */
648
 
649
  prefix (0, 0, 0);
650
  sc = decode_src23 (sss, ss, 1);
651
  BIT_OPC (sc, bit, (!b) | carry);
652
 
653
  /** 1101 ddd0 dd01 1bit               BNOT dest */
654
 
655
  prefix (0, 0, 0);
656
  dc = decode_dest23 (ddd, dd, 1);
657
  BIT_OP (dc, bit, !b);
658
 
659
  /** 0000 0001 1101 sss0 ss00 0bit     BNTST src */
660
 
661
  prefix (0, 0, 0);
662
  sc = decode_dest23 (sss, ss, 1);
663
  b = get_bit2 (sc, bit);
664
  set_zc (!b, !b);
665
 
666
  /** 0000 0001 1101 sss0 ss11 1bit     BNXOR src */
667
 
668
  prefix (0, 0, 0);
669
  sc = decode_src23 (sss, ss, 1);
670
  BIT_OPC (sc, bit, !b ^ carry);
671
 
672
  /** 0000 0001 1101 sss0 ss10 0bit     BOR src */
673
 
674
  prefix (0, 0, 0);
675
  sc = decode_src23 (sss, ss, 1);
676
  BIT_OPC (sc, bit, b | carry);
677
 
678
  /** 0000 0000                         BRK */
679
 
680
  /* We report the break to our caller with the PC still pointing at the
681
     breakpoint instruction.  */
682
  put_reg (pc, m32c_opcode_pc);
683
  if (verbose)
684
    printf("[break]\n");
685
  if (in_gdb || (regs.r_intbl == 0 && regs.r_intbh == 0))
686
    return M32C_MAKE_HIT_BREAK ();
687
  if (mem_get_qi (0xFFFFE7) == 0xff)
688
    trigger_based_interrupt (0);
689
  else
690
    trigger_fixed_interrupt (0xFFFFE4);
691
 
692
  /** 1111 1110                         GBRK */
693
 
694
  /* This alternate break, which is not part of the chip's opcode set,
695
   is here in case you need to debug a program that itself uses the
696
   chip's BRK opcode.  You'll need to modify your copy of GDB to use
697
   this opcode instead of the real BRK.  */
698
 
699
  /* GDB Break. */
700
  /* We report the break to our caller with the PC still pointing at the
701
     breakpoint instruction.  */
702
  put_reg (pc, m32c_opcode_pc);
703
  if (verbose)
704
    printf("[gdb break]\n");
705
  return M32C_MAKE_HIT_BREAK ();
706
 
707
  /** 0000 1000                         BRK2 */
708
 
709
  if (verbose)
710
    printf("[break2]\n");
711
  if (in_gdb)
712
    return M32C_MAKE_HIT_BREAK ();
713
  if (mem_get_qi (0xFFFFE7) == 0xff)
714
    trigger_based_interrupt (0);
715
  else
716
    trigger_fixed_interrupt (0xFFFFE4);
717
 
718
  /** 1101 ddd0 dd11 1bit               BSET dest */
719
 
720
  dc = decode_dest23 (ddd, dd, 1);
721
  BIT_OP (dc, bit, 1);
722
 
723
  /** 1101 sss0 ss00 0bit               BTST:G src */
724
 
725
  prefix (0, 0, 0);
726
  sc = decode_src23 (sss, ss, 1);
727
  b = get_bit2 (sc, bit);
728
  set_zc (!b, b);
729
 
730
  /** 00bb 101b                         BTST:S src */
731
 
732
  sc = decode_src23 (3, 3, 1); /* bit,base:19 */
733
  b = get_bit2 (sc, bb*2 + b);
734
  set_zc (!b, b);
735
 
736
  /** 1101 ddd0 dd10 0bit               BTSTC dest */
737
 
738
  prefix (0, 0, 0);
739
  sc = decode_dest23 (ddd, dd, 1);
740
  b = get_bit2 (sc, bit);
741
  set_zc (!b, b);
742
  put_bit2 (sc, bit, 0);
743
 
744
  /** 1101 ddd0 dd10 1bit               BTSTS dest */
745
 
746
  prefix (0, 0, 0);
747
  sc = decode_dest23 (ddd, dd, 1);
748
  b = get_bit2 (sc, bit);
749
  set_zc (!b, b);
750
  put_bit2 (sc, bit, 1);
751
 
752
  /** 0000 0001 1101 sss0 ss10 1bit     BXOR src */
753
 
754
  prefix (0, 0, 0);
755
  sc = decode_src23 (sss, ss, 1);
756
  BIT_OPC (sc, bit, b ^ carry);
757
 
758
  /** 0000 0001 1000 ddd w dd11 1110    CLIP.size #IMM1,#IMM2,dest */
759
 
760
  prefix (0, 0, 0);
761
  dc = decode_dest23 (ddd, dd, w+1);
762
  a = sign_ext (IMM(w+1), w*8+8);
763
  b = sign_ext (IMM(w+1), w*8+8);
764
  v = sign_ext (get_src (dc), w*8+8);
765
  tprintf("clip %d <= %d <= %d : ", a, v, b);
766
  if (a > v)
767
    v = a;
768
  if (v > b)
769
    v = b;
770
  tprintf("%d\n", v);
771
  put_dest (dc, v);
772
 
773
  /** 1001 ddd w dd10 1110              CMP.size:G #IMM,dest */
774
 
775
  prefix (0, 1, 0);
776
  dc = decode_dest23 (ddd, dd, w+1);
777
  v = get_src (dc);
778
  imm = IMM(w+1);
779
  cmp (v, imm, w+1);
780
 
781
  /** 1010 ddd0 dd11 0001               CMP.L:G #IMM32,dest */
782
 
783
  prefix (0, 1, 0);
784
  dc = decode_dest23 (ddd, dd, 4);
785
  v = get_src (dc);
786
  imm = IMM(4);
787
  cmp (v, imm, 4);
788
 
789
  /** 1110 ddd w dd01 immm              CMP.size:Q #IMM,dest */
790
 
791
  prefix (0, 1, 0);
792
  dc = decode_dest23 (ddd, dd, w+1);
793
  v = get_src (dc);
794
  immm = sign_ext (immm, 4);
795
  cmp (v, immm, w+1);
796
 
797
  /** 01dd 011w                         CMP.size:S #IMM,dest */
798
 
799
  prefix (0, 1, 0);
800
  dc = decode_dest2 (dd, w+1);
801
  v = get_src (dc);
802
  imm = sign_ext (IMM(w+1),w*8+8);
803
  cmp (v, imm, w+1);
804
 
805
  /** 1sss ddd w dd ss 0110             CMP.size:G src,dest */
806
 
807
  prefix (1, 1, 0);
808
  sc = decode_src23 (sss, ss, w+1);
809
  dc = decode_dest23 (ddd, dd, w+1);
810
  a = get_src (dc);
811
  b = get_src (sc);
812
  cmp (a, b, w+1);
813
 
814
  /** 1sss ddd1 dd ss 0001              CMP.L:G src,dest */
815
 
816
  prefix (1, 1, 0);
817
  sc = decode_src23 (sss, ss, 4);
818
  dc = decode_dest23 (ddd, dd, 4);
819
  a = get_src (dc);
820
  b = get_src (sc);
821
  cmp (a, b, 4);
822
 
823
  /** 01dd 000w                         CMP.size:S src,R0/R0L */
824
 
825
  prefix (0, 1, 0);
826
  dc = decode_dest2 (dd, w+1);
827
  a = get_reg (w ? r0 : r0l);
828
  b = get_src (dc);
829
  cmp (a, b, w+1);
830
 
831
  /** 1010 ddd0 dd01 0001               CMPX #IMM,dest */
832
 
833
  prefix (0, 1, 0);
834
  dc = decode_dest23 (ddd, dd, 4);
835
  v = get_src (dc);
836
  imm = sign_ext (IMM(1), 8);
837
  cmp (v, imm, 4);
838
 
839
  /** 0000 0001 1000 ddd w dd00 1110    DADC.size #IMM,dest */
840
 
841
  DADDI(1,1);
842
 
843
  /** 0000 0001 1sss ddd w dd ss 1000   DADC.size src,dest */
844
 
845
  DADDV(1,1);
846
 
847
  /** 0000 0001 1000 ddd w dd01 1110    DADD.size #IMM,dest */
848
 
849
  DADDI(1,0);
850
 
851
  /** 0000 0001 1sss ddd w dd ss 0000   DADD.size src,dest */
852
 
853
  DADDV(1,0);
854
 
855
  /** 1011 ddd w dd00 1110              DEC.size dest */
856
 
857
  prefix (0, 1, 0);
858
  dc = decode_dest23 (ddd, dd, w+1);
859
  a = get_src (dc);
860
  v = a-1;
861
  tprintf ("%x -- = %x\n", a, v);
862
  set_sz (v, w+1);
863
  put_dest (dc, v);
864
 
865
  /** 1011 0000 010w 0011               DIV.size #IMM */
866
 
867
  prefix (0, 0, 0);
868
  div_op (-1, 0, 0, 0, w+1);
869
 
870
  /** 1000 sss w ss01 1110              DIV.size src */
871
 
872
  prefix (0, 1, 0);
873
  div_op (sss, ss, 0, 0, w+1);
874
 
875
  /** 0000 0001 1010 sss1 ss01 1111     DIV.L src */
876
 
877
  M32C_ONLY();
878
  prefix (0, 0, 0);
879
  div_op (sss, ss, 0, 0, 4);
880
 
881
  /** 1011 0000 000w 0011               DIVU.size #IMM */
882
 
883
  prefix (0, 0, 0);
884
  div_op (-1, 0, 1, 0, w+1);
885
 
886
  /** 1000 sss w ss00 1110              DIVU.size src */
887
 
888
  prefix (0, 1, 0);
889
  div_op (sss, ss, 1, 0, w+1);
890
 
891
  /** 0000 0001 1010 sss1 ss00 1111     DIVU.L src */
892
 
893
  M32C_ONLY();
894
  prefix (0, 0, 0);
895
  div_op (sss, ss, 1, 0, 4);
896
 
897
  /** 1011 0010 010w 0011               DIVX.size #IMM */
898
 
899
  prefix (0, 0, 0);
900
  div_op (-1, 0, 0, 1, w+1);
901
 
902
  /** 1001 sss w ss01 1110              DIVX.size src */
903
 
904
  prefix (0, 1, 0);
905
  div_op (sss, ss, 0, 1, w+1);
906
 
907
  /** 0000 0001 1010 sss1 ss10 1111     DIVX.L src */
908
 
909
  M32C_ONLY();
910
  prefix (0, 0, 0);
911
  div_op (sss, ss, 0, 1, 4);
912
 
913
  /** 0000 0001 1001 ddd w dd00 1110    DSBB.size #IMM,dest */
914
 
915
  DADDI(0,1);
916
 
917
  /** 0000 0001 1sss ddd w dd ss 1010   DSBB.size src,dest */
918
 
919
  DADDV(0,1);
920
 
921
  /** 0000 0001 1001 ddd w dd01 1110    DSUB.size #IMM,dest */
922
 
923
  DADDI(0,0);
924
 
925
  /** 0000 0001 1sss ddd w dd ss 0010   DSUB.size src,dest */
926
 
927
  DADDV(0,0);
928
 
929
  /** 1110 1100                         ENTER #IMM */
930
 
931
  imm = IMM(1);
932
  put_reg (sp, get_reg (sp) - 4);
933
  mem_put_si (get_reg (sp), get_reg (fb));
934
  put_reg (fb, get_reg (sp));
935
  put_reg (sp, get_reg (sp) - imm);
936
 
937
  /** 1111 1100                         EXITD */
938
 
939
  put_reg (sp, get_reg (fb));
940
  put_reg (fb, mem_get_si (get_reg (sp)));
941
  put_reg (sp, get_reg (sp) + 4);
942
  put_reg (pc, mem_get_si (get_reg (sp)));
943
  put_reg (sp, get_reg (sp) + 4);
944
 
945
  /** 1100 ddd w dd01 1110              EXTS.size dest */
946
 
947
  prefix (0, 0, 0);
948
  dc = decode_dest23 (ddd, dd, w+1);
949
  v = sign_ext (get_src (dc), (w+1)*8);
950
  dc = widen_sd (dc);
951
  put_dest (dc, v);
952
  set_sz (v, (w+1)*2);
953
 
954
  /** 0000 0001 1sss ddd0 dd ss 0111    EXTS.B src,dest */
955
 
956
  prefix (0, 0, 0);
957
  sc = decode_src23 (sss, ss, 1);
958
  dc = decode_dest23 (ddd, dd, 2);
959
  v = sign_ext (get_src (sc), 8);
960
  put_dest (dc, v);
961
  set_sz (v, 16);
962
 
963
  /** 0000 0001 1sss ddd0 dd ss 1011    EXTZ src,dest */
964
 
965
  prefix (0, 0, 0);
966
  sc = decode_src23 (sss, ss, 1);
967
  dc = decode_dest23 (ddd, dd, 2);
968
  v = get_src (sc);
969
  put_dest (dc, v);
970
  set_sz (v, 16);
971
 
972
  /** 1101 0011 1110 1dst               FCLR dest */
973
 
974
  set_flags (1 << dst, 0);
975
 
976
  /** 1001 1111                         FREIT */
977
 
978
  NOTYET();
979
 
980
  /** 1101 0001 1110 1dst               FSET dest */
981
 
982
  set_flags (1 << dst, 1 << dst);
983
 
984
  /** 1010 ddd w dd00 1110              INC.size dest */
985
 
986
  prefix (0, 1, 0);
987
  dc = decode_dest23 (ddd, dd, w+1);
988
  a = get_src (dc);
989
  v = a+1;
990
  tprintf ("%x ++ = %x\n", a, v);
991
  set_sz (v, w+1);
992
  put_dest (dc, v);
993
 
994
  /** 1000 sss0 ss0w 0011               INDEXB.size src */
995
  INDEXOP(1, 1, 1);
996
  /** 1010 sss0 ss0w 0011               INDEXBD.size src */
997
  INDEXOP(1, 0, 1);
998
  /** 1100 sss0 ss0w 0011               INDEXBS.size src */
999
  INDEXOP(1, 1, 0);
1000
  /** 1001 sss0 ss1w 0011               INDEXL.size src */
1001
  INDEXOP(4, 1, 1);
1002
  /** 1011 sss0 ss1w 0011               INDEXLD.size src */
1003
  INDEXOP(4, 0, 1);
1004
  /** 1001 sss0 ss0w 0011               INDEXLS.size src */
1005
  INDEXOP(4, 1, 0);
1006
  /** 1000 sss0 ss1w 0011               INDEXW.size src */
1007
  INDEXOP(2, 1, 1);
1008
  /** 1010 sss0 ss1w 0011               INDEXWD.size src */
1009
  INDEXOP(2, 0, 1);
1010
  /** 1100 sss0 ss1w 0011               INDEXWS.size src */
1011
  INDEXOP(2, 1, 0);
1012
 
1013
  /** 1011 1110 vector00                        INT #IMM */
1014
 
1015
  prefix (0, 0, 0);
1016
  trigger_based_interrupt (vector);
1017
 
1018
  /** 1011 1111                         INTO */
1019
 
1020
  prefix (0, 0, 0);
1021
  if (FLAG_O)
1022
    trigger_fixed_interrupt (0xffffe0);
1023
 
1024
  /** 1ccc 101c                         Jcnd label */
1025
 
1026
  prefix (0, 0, 0);
1027
  v = sign_ext (IMM(1), 8);
1028
  if (condition_true (ccc*2+c))
1029
    put_reg (pc, m32c_opcode_pc + 1 + v);
1030
 
1031
  /** 01dd 101d                         JMP.S label */
1032
 
1033
  prefix (0, 0, 0);
1034
  put_reg (pc, m32c_opcode_pc + (dd*2+d) + 2);
1035
 
1036
  /** 1011 1011                         JMP.B label */
1037
 
1038
  prefix (0, 0, 0);
1039
  imm = sign_ext (IMM(1), 8);
1040
  if (imm == -1)
1041
    {
1042
      if (verbose)
1043
        printf("[jmp-to-self detected as exit]\n");
1044
      return M32C_MAKE_HIT_BREAK ();
1045
    }
1046
  put_reg (pc, m32c_opcode_pc + 1 + imm);
1047
 
1048
  /** 1100 1110                         JMP.W label */
1049
 
1050
  prefix (0, 0, 0);
1051
  imm = sign_ext (IMM(2), 16);
1052
  put_reg (pc, m32c_opcode_pc + 1 + imm);
1053
 
1054
  /** 1100 1100                         JMP.A label */
1055
 
1056
  prefix (0, 0, 0);
1057
  imm = IMM(3);
1058
  put_reg (pc, imm);
1059
 
1060
  /** 1100 sss1 ss00 1111               JMPI.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 (pc, m32c_opcode_pc + a);
1067
 
1068
  /** 1000 sss0 ss00 0001               JMPI.A src */
1069
 
1070
  prefix (0, 0, 0);
1071
  sc = decode_src23 (sss, ss, 3);
1072
  a = get_src (sc);
1073
  put_reg (pc, a);
1074
 
1075
  /** 1101 1100                         JMPS #IMM8 */
1076
 
1077
  prefix (0, 0, 0);
1078
  imm = IMM(1);
1079
  a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
1080
  put_reg (pc, a);
1081
 
1082
  /** 1100 1111                         JSR.W label */
1083
 
1084
  prefix (0, 0, 0);
1085
  imm = sign_ext (IMM(2), 16);
1086
  put_reg (sp, get_reg (sp) - 4);
1087
  mem_put_si (get_reg (sp), get_reg (pc));
1088
  put_reg (pc, m32c_opcode_pc + imm + 1);
1089
 
1090
  /** 1100 1101                         JSR.A label */
1091
 
1092
  prefix (0, 0, 0);
1093
  imm = IMM(3);
1094
  put_reg (sp, get_reg (sp) - 4);
1095
  mem_put_si (get_reg (sp), get_reg (pc));
1096
  put_reg (pc, imm);
1097
 
1098
  /** 1100 sss1 ss01 1111               JSRI.W src */
1099
 
1100
  prefix (0, 0, 0);
1101
  sc = decode_src23 (sss, ss, 2);
1102
  a = get_src (sc);
1103
  a = sign_ext (a, 16);
1104
  put_reg (sp, get_reg (sp) - 4);
1105
  mem_put_si (get_reg (sp), get_reg (pc));
1106
  put_reg (pc, m32c_opcode_pc + a);
1107
 
1108
  /** 1001 sss0 ss00 0001               JSRI.A src */
1109
 
1110
  prefix (0, 0, 0);
1111
  sc = decode_src23 (sss, ss, 3);
1112
  a = get_src (sc);
1113
  put_reg (sp, get_reg (sp) - 4);
1114
  mem_put_si (get_reg (sp), get_reg (pc));
1115
  put_reg (pc, a);
1116
 
1117
  /** 1101 1101                         JSRS #IMM8 */
1118
 
1119
  prefix (0, 0, 0);
1120
  imm = IMM(1);
1121
  a = 0xff0000 + mem_get_hi (0xfffe00 - imm * 2);
1122
  put_reg (sp, get_reg (sp) - 4);
1123
  mem_put_si (get_reg (sp), get_reg (pc));
1124
  put_reg (pc, a);
1125
 
1126
  /** 1101 0101 1010 1dst               LDC #IMM16,dest */
1127
 
1128
  imm = IMM(2);
1129
  dc = decode_cr_b (dst, CR_B_DCT0);
1130
  put_dest (dc, imm);
1131
 
1132
  /** 1101 0101 0010 1dst               LDC #IMM24,dest */
1133
 
1134
  imm = IMM(3);
1135
  dc = decode_cr_b (dst, CR_B_INTB);
1136
  put_dest (dc, imm);
1137
 
1138
  /** 1101 0101 0110 1dst               LDC #IMM24,dest */
1139
 
1140
  imm = IMM(3);
1141
  dc = decode_cr_b (dst, CR_B_DMA0);
1142
  put_dest (dc, imm);
1143
 
1144
  /** 0000 0001 1101 sss1 ss00 1dst     LDC src,dest */
1145
 
1146
  prefix (0, 0, 0);
1147
  sc = decode_src23 (sss, ss, 2);
1148
  dc = decode_cr_b (dst, CR_B_DCT0);
1149
  a = get_src (sc);
1150
  put_dest (dc, a);
1151
 
1152
  /** 1101 sss1 ss00 0dst               LDC src,dest */
1153
 
1154
  prefix (0, 0, 0);
1155
  sc = decode_src23 (sss, ss, 3);
1156
  dc = decode_cr_b (dst, CR_B_INTB);
1157
  a = get_src (sc);
1158
  put_dest (dc, a);
1159
 
1160
  /** 0000 0001 1101 sss1 ss00 0dst     LDC src,dest */
1161
 
1162
  prefix (0, 0, 0);
1163
  sc = decode_src23 (sss, ss, 3);
1164
  dc = decode_cr_b (dst, CR_B_DMA0);
1165
  a = get_src (sc);
1166
  put_dest (dc, a);
1167
 
1168
  /** 1011 0110 1100 0011               LDCTX */
1169
 
1170
  NOTYET();
1171
 
1172
  /** 1101 0101 1110 1imm               LDIPL #IMM */
1173
 
1174
  set_flags (0x7000, imm*0x1000);
1175
 
1176
  /** 0000 0001 1000 ddd w dd11 1111    MAX.size #IMM,dest */
1177
 
1178
  prefix (0, 0, 0);
1179
  w++;
1180
  dc = decode_dest23 (ddd, dd, w);
1181
  imm = sign_ext (IMM(w), w*8);
1182
  a = sign_ext (get_src (dc), w*8);
1183
  tprintf ("max %d %d\n", imm, a);
1184
  if (imm > a)
1185
    put_dest (dc, imm);
1186
 
1187
  /** 0000 0001 1sss ddd w dd ss 1101   MAX.size src,dest */
1188
 
1189
  prefix (0, 0, 0);
1190
  w++;
1191
  sc = decode_src23 (sss, ss, w);
1192
  dc = decode_dest23 (ddd, dd, w);
1193
  b = sign_ext (get_src (sc), w*8);
1194
  a = sign_ext (get_src (dc), w*8);
1195
  tprintf ("max %d %d\n", b, a);
1196
  if (b > a)
1197
    put_dest (dc, b);
1198
 
1199
  /** 0000 0001 1000 ddd w dd10 1111    MIN.size #IMM,dest */
1200
 
1201
  prefix (0, 0, 0);
1202
  w++;
1203
  dc = decode_dest23 (ddd, dd, w);
1204
  imm = sign_ext (IMM(w), w*8);
1205
  a = sign_ext (get_src (dc), w*8);
1206
  tprintf ("min %d %d\n", imm, a);
1207
  if (imm < a)
1208
    put_dest (dc, imm);
1209
 
1210
  /** 0000 0001 1sss ddd w dd ss 1100   MIN.size src,dest */
1211
 
1212
  prefix (0, 0, 0);
1213
  w++;
1214
  sc = decode_src23 (sss, ss, w);
1215
  dc = decode_dest23 (ddd, dd, w);
1216
  b = sign_ext (get_src (sc), w*8);
1217
  a = sign_ext (get_src (dc), w*8);
1218
  tprintf ("min %d %d\n", b, a);
1219
  if (b < a)
1220
    put_dest (dc, b);
1221
 
1222
  /** 1001 ddd w dd10 1111              MOV.size:G #IMM,dest */
1223
 
1224
  dc = decode_dest23 (ddd, dd, w+1);
1225
  imm = IMM(w+1);
1226
  v = imm;
1227
  tprintf("%x = %x\n", v, v);
1228
  set_sz(v, w+1);
1229
  put_dest (dc, v);
1230
 
1231
  /** 1011 ddd0 dd11 0001               MOV.L:G #IMM,dest */
1232
 
1233
  dc = decode_dest23 (ddd, dd, 4);
1234
  imm = IMM(4);
1235
  v = imm;
1236
  tprintf("%x = %x\n", v, v);
1237
  set_sz(v, 4);
1238
  put_dest (dc, v);
1239
 
1240
  /** 1111 ddd w dd10 immm              MOV.size:Q #IMM4,dest */
1241
 
1242
  dc = decode_dest23 (ddd, dd, w+1);
1243
  imm = sign_ext (immm, 4);
1244
  v = imm;
1245
  tprintf("%x = %d\n", v, v);
1246
  set_sz(v, w+1);
1247
  put_dest (dc, v);
1248
 
1249
  /** 00dd 010w                         MOV.size:S #IMM,dest */
1250
 
1251
  prefix (0, 1, 0);
1252
  dc = decode_dest2 (dd, w+1);
1253
  imm = IMM(w+1);
1254
  put_dest (dc, imm);
1255
  set_sz (imm, w+1);
1256
 
1257
  /** 10w1 110d                         MOV.size:S #IMM,a0/a1 */
1258
 
1259
  imm = IMM(w ? 3 : 2);
1260
  put_reg (d ? a1 : a0, imm);
1261
  set_sz (imm & addr_mask, w+1);
1262
 
1263
  /** 00dd 001w                         MOV.size:Z #0,dest */
1264
 
1265
  prefix (0, 1, 0);
1266
  dc = decode_dest2 (dd, w+1);
1267
  put_dest (dc, 0);
1268
  set_sz (0, w+1);
1269
 
1270
  /** 1sss ddd w dd ss 1011             MOV.size:G src,dest */
1271
 
1272
  prefix (1, 1, 0);
1273
  sc = decode_src23 (sss, ss, w+1);
1274
  dc = decode_dest23 (ddd, dd, w+1);
1275
  v = get_src (sc);
1276
  put_dest (dc, v);
1277
  set_sz (v, w+1);
1278
 
1279
  /** 1sss ddd1 dd ss 0011              MOV.L:G src,dest */
1280
 
1281
  prefix (1, 1, 0);
1282
  sc = decode_src23 (sss, ss, 4);
1283
  dc = decode_dest23 (ddd, dd, 4);
1284
  v = get_src (sc);
1285
  put_dest (dc, v);
1286
  set_sz (v, 4);
1287
 
1288
  /** VARY SS 01 10 11 */
1289
  /** 00SS 100w                         MOV.size:S src,R0L/R0 */
1290
 
1291
  prefix (0, 1, 0);
1292
  sc = decode_dest2 (SS, w+1);
1293
  v = get_src (sc);
1294
  put_reg (w ? r0 : r0l, v);
1295
  set_sz (v, w+1);
1296
 
1297
  /** 01ss 111w                         MOV.size:S src,R1L/R1 */
1298
 
1299
  prefix (0, 1, 0);
1300
  sc = decode_dest2 (ss, w+1);
1301
  v = get_src (sc);
1302
  put_reg (w ? r1 : r1l, v);
1303
  set_sz (v, w+1);
1304
 
1305
  /** VARY DD 01 10 11 */
1306
  /** 00DD 000w                         MOV.size:S R0L/R0,dest */
1307
 
1308
  prefix (0, 1, 0);
1309
  dc = decode_dest2 (DD, w+1);
1310
  v = get_reg (w ? r0 : r0l);
1311
  put_dest (dc, v);
1312
  set_sz (v, w+1);
1313
 
1314
  /** 01ss 100d                         MOV.L:S src,A0/A1 */
1315
 
1316
  prefix (0, 1, 0);
1317
  sc = decode_dest2 (ss, 4);
1318
  v = get_src (sc);
1319
  put_reg (d ? a1 : a0, v);
1320
  set_sz (v, 4);
1321
 
1322
  /** 1011 ddd w dd00 1111              MOV.size:G dsp:8[SP], dest */
1323
 
1324
  prefix (0, 0, 0);
1325
  imm = IMM(1);
1326
  dc = decode_dest23 (ddd, dd, w+1);
1327
  a = get_reg (sp) + sign_ext (imm, 8);
1328
  a &= addr_mask;
1329
  if (w)
1330
    v = mem_get_hi (a);
1331
  else
1332
    v = mem_get_qi (a);
1333
  put_dest (dc, v);
1334
  set_sz (v, w+1);
1335
 
1336
  /** 1010 sss w ss00 1111              MOV.size:G src,dsp:8[SP] */
1337
 
1338
  prefix (0, 0, 0);
1339
  sc = decode_dest23 (sss, ss, w+1);
1340
  imm = IMM(1);
1341
  a = get_reg (sp) + sign_ext (imm, 8);
1342
  a &= addr_mask;
1343
  v = get_src (sc);
1344
  if (w)
1345
    mem_put_hi (a, v);
1346
  else
1347
    mem_put_qi (a, v);
1348
  set_sz (v, w+1);
1349
 
1350
  /** 1101 sss1 ss01 1dst               MOVA src,dest */
1351
 
1352
  static reg_id map[8] = { r2r0, r3r1, a0, a1 };
1353
  prefix (0, 0, 0);
1354
  sc = decode_src23 (sss, ss, 1);
1355
  if (!sc.mem || !map[dst])
1356
    UNSUPPORTED();
1357
  put_reg (map[dst], sc.u.addr);
1358
 
1359
  /** 0000 0001 1011 ddd0 dd hl 1110    MOVdir R0L,dest */
1360
 
1361
  prefix (0, 0, 0);
1362
  dc = decode_dest23 (ddd, dd, 1);
1363
  a = get_src (dc);
1364
  b = get_reg (r0l);
1365
  switch (hl)
1366
    {
1367
    case 0: a = (a & 0xf0) | (b & 0x0f); break;
1368
    case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1369
    case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1370
    case 3: a = (a & 0x0f) | (b & 0xf0); break;
1371
    }
1372
  put_dest (dc, a);
1373
 
1374
  /** 0000 0001 1010 sss0 ss hl 1110    MOVdir src,R0L */
1375
 
1376
  prefix (0, 0, 0);
1377
  sc = decode_dest23 (sss, ss, 1);
1378
  a = get_reg (r0l);
1379
  b = get_src (dc);
1380
  switch (hl)
1381
    {
1382
    case 0: a = (a & 0xf0) | (b & 0x0f); break;
1383
    case 1: a = (a & 0xf0) | ((b>>4) & 0x0f); break;
1384
    case 2: a = (a & 0x0f) | ((b & 0x0f)<<4); break;
1385
    case 3: a = (a & 0x0f) | (b & 0xf0); break;
1386
    }
1387
  put_reg (r0l, a);
1388
 
1389
  /** 1011 ddd0 dd01 0001               MOVX #IMM,dest */
1390
 
1391
  prefix (0, 1, 0);
1392
  dc = decode_dest23 (ddd, dd, 4);
1393
  imm = sign_ext (IMM(1), 8);
1394
  put_dest (dc, imm);
1395
  set_sz (imm, 1);
1396
 
1397
  /** 1000 ddd w dd01 1111              MUL.size #IMM,dest */
1398
 
1399
  prefix (0, 1, 0);
1400
  w ++;
1401
  dc = decode_dest23 (ddd, dd, w);
1402
  v = sign_ext (get_src (dc), w*8);
1403
  imm = sign_ext (IMM(w), w*8);
1404
  tprintf("%d * %d = %d\n", v, imm, v*imm);
1405
  v *= imm;
1406
  dc = widen_sd (dc);
1407
  put_dest (dc, v);
1408
 
1409
  /** 1sss ddd w dd ss 1100             MUL.size src,dest */
1410
 
1411
  prefix (1, 1, 0);
1412
  w ++;
1413
  sc = decode_src23 (sss, ss, w);
1414
  dc = decode_dest23 (ddd, dd, w);
1415
  a = sign_ext (get_src (sc), w*8);
1416
  b = sign_ext (get_src (dc), w*8);
1417
  tprintf("%d * %d = %d\n", a, b, a*b);
1418
  v = a * b;
1419
  dc = widen_sd (dc);
1420
  put_dest (dc, v);
1421
 
1422
  /** 0000 0001 1000 sss1 ss01 1111     MUL.L src,R2R0 */
1423
 
1424
  M32C_ONLY();
1425
  prefix (0, 0, 0);
1426
  sc = decode_src23 (sss, ss, 4);
1427
  a = sign_ext (get_src (sc), 32);
1428
  b = sign_ext (get_reg (r2r0), 32);
1429
  ll = (long long)a * (long long)b;
1430
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1431
  if (ll < b2minsigned[4] || ll > b2maxsigned[4])
1432
    set_flags (FLAGBIT_O, FLAGBIT_O);
1433
  else
1434
    set_flags (FLAGBIT_O, 0);
1435
  put_reg (r2r0, (int)ll);
1436
 
1437
  /** 1100 sss1 ss11 1110               MULEX src */
1438
 
1439
  prefix (0, 1, 0);
1440
  sc = decode_dest23 (sss, ss, 2);
1441
  a = sign_ext (get_src (sc), 16);
1442
  b = sign_ext (get_reg (r2r0), 32);
1443
  ll = (long long)a * (long long)b;
1444
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1445
  put_reg (r2r0, (int)ll);
1446
  put_reg (r1, (int)(ll >> 32));
1447
 
1448
  /** 1000 ddd w dd00 1111              MULU.size #IMM,dest */
1449
 
1450
  prefix (0, 1, 0);
1451
  w ++;
1452
  dc = decode_dest23 (ddd, dd, w);
1453
  v = get_src (dc);
1454
  imm = IMM(w);
1455
  tprintf("%d * %d = %d\n", v, imm, v*imm);
1456
  v *= imm;
1457
  dc = widen_sd (dc);
1458
  put_dest (dc, v);
1459
 
1460
  /** 1sss ddd w dd ss 0100             MULU.size src,dest */
1461
 
1462
  prefix (1, 1, 0);
1463
  w ++;
1464
  sc = decode_src23 (sss, ss, w);
1465
  dc = decode_dest23 (ddd, dd, w);
1466
  a = get_src (sc);
1467
  b = get_src (dc);
1468
  tprintf("%d * %d = %d\n", a, b, a*b);
1469
  v = a * b;
1470
  dc = widen_sd (dc);
1471
  put_dest (dc, v);
1472
 
1473
  /** 0000 0001 1000 sss1 ss00 1111     MULU.L src,R2R0 */
1474
 
1475
  M32C_ONLY();
1476
  prefix (0, 0, 0);
1477
  sc = decode_src23 (sss, ss, 4);
1478
  a = get_src (sc);
1479
  b = get_reg (r2r0);
1480
  ll = (long long)a * (long long)b;
1481
  tprintf("%d * %d = %lld (%llx)\n", a, b, ll, ll);
1482
  if (ll < b2minsigned[4] || ll > b2maxsigned[4])
1483
    set_flags (FLAGBIT_O, FLAGBIT_O);
1484
  else
1485
    set_flags (FLAGBIT_O, 0);
1486
  put_reg (r2r0, (int)ll);
1487
 
1488
  /** 1010 ddd w dd10 1111              NEG.size dest */
1489
 
1490
  prefix (0, 1, 0);
1491
  dc = decode_dest23 (ddd, dd, w+1);
1492
  a = sign_ext (get_src (dc), (w+1)*8);
1493
  v = -a;
1494
  tprintf("%d * -1 = %d\n", a, v);
1495
  set_oszc(v, w+1, v==0);
1496
  put_dest (dc, v);
1497
 
1498
  /** 1101 1110                         NOP */
1499
 
1500
  tprintf("nop\n");
1501
 
1502
  /** 1010 ddd w dd01 1110              NOT.size dest */
1503
 
1504
  prefix (0, 1, 0);
1505
  dc = decode_dest23 (ddd, dd, w+1);
1506
  a = get_src (dc);
1507
  v = ~a;
1508
  tprintf("~ %x = %x\n", a, v);
1509
  set_sz(v, w+1);
1510
  put_dest (dc, v);
1511
 
1512
  /** 1000 ddd w dd10 1111              OR.size:G #IMM,dest */
1513
 
1514
  prefix (0, 1, 0);
1515
  dc = decode_dest23(ddd, dd, w+1);
1516
  imm = IMM(w+1);
1517
  LOGIC_OP (dc, imm, |);
1518
 
1519
  /** 01dd 010w                         OR.size:S #IMM,dest */
1520
 
1521
  prefix (0, 1, 0);
1522
  dc = decode_dest2(dd, w+1);
1523
  imm = IMM (w+1);
1524
  LOGIC_OP (dc, imm, |);
1525
 
1526
  /** 1sss ddd w dd ss 0101             OR.size:G src,dest */
1527
 
1528
  prefix (1, 1, 0);
1529
  sc = decode_src23(sss, ss, w+1);
1530
  dc = decode_dest23(ddd, dd, w+1);
1531
  b = get_src (sc);
1532
  LOGIC_OP (dc, b, |);
1533
 
1534
  /** 1011 ddd w dd10 1111              POP.size dest */
1535
 
1536
  prefix (0, 1, 0);
1537
  dc = decode_dest23 (ddd, dd, w+1);
1538
  if (w)
1539
    a = mem_get_hi (get_reg (sp));
1540
  else
1541
    a = mem_get_qi (get_reg (sp));
1542
  put_reg (sp, get_reg (sp) + 2);
1543
  tprintf("pop%s: %x\n", w ? "hi" : "qi", a);
1544
  put_dest (dc, a);
1545
 
1546
  /** 1101 0011 1010 1dst               POPC dest */
1547
 
1548
  prefix (0, 0, 0);
1549
  dc = decode_cr_b (dst, CR_B_DCT0);
1550
  a = mem_get_hi (get_reg (sp));
1551
  put_reg (sp, get_reg (sp) + 2);
1552
  tprintf("pophi: %x\n", a);
1553
  put_dest (dc, a);
1554
 
1555
  /** 1101 0011 0010 1dst               POPC dest */
1556
 
1557
  prefix (0, 0, 0);
1558
  dc = decode_cr_b (dst, CR_B_INTB);
1559
  a = mem_get_si (get_reg (sp));
1560
  put_reg (sp, get_reg (sp) + 4);
1561
  tprintf("popsi: %x\n", a);
1562
  put_dest (dc, a);
1563
 
1564
  /** 1000 1110                         POPM dest */
1565
 
1566
  static int map[] = { r0, r1, r2, r3, a0, a1, sb, fb };
1567
  prefix (0, 0, 0);
1568
  imm = IMM(1);
1569
  tprintf("popm: %x\n", imm);
1570
  for (a=0; a<4; a++)
1571
    if (imm & (1<
1572
      {
1573
        v = mem_get_hi (get_reg (sp));
1574
        put_reg (map[a], v);
1575
        put_reg (sp, get_reg (sp) + 2);
1576
      }
1577
  for (; a<8; a++)
1578
    if (imm & (1<
1579
      {
1580
        v = mem_get_si (get_reg (sp));
1581
        put_reg (map[a], v);
1582
        put_reg (sp, get_reg (sp) + 4);
1583
      }
1584
 
1585
  /** 1010 111w                         PUSH.size #IMM */
1586
 
1587
  prefix (0, 0, 0);
1588
  imm = IMM(w+1);
1589
  tprintf("push%s: %x\n", w ? "hi" : "qi", imm);
1590
  int a = get_reg (sp) - 2;
1591
  if (w)
1592
    mem_put_hi (a, imm);
1593
  else
1594
    mem_put_qi (a, imm);
1595
  put_reg (sp, a);
1596
 
1597
  /** 1100 sss w ss00 1110              PUSH.size src */
1598
 
1599
  prefix (0, 1, 0);
1600
  sc = decode_dest23 (sss, ss, w+1);
1601
  a = get_src (sc);
1602
  put_reg (sp, get_reg (sp) - 2);
1603
  if (w)
1604
    mem_put_hi (get_reg (sp), a);
1605
  else
1606
    mem_put_qi (get_reg (sp), a);
1607
  tprintf("push%s: %x\n", w ? "hi" : "qi", a);
1608
 
1609
  /** 1011 0110 0101 0011               PUSH.L #IMM32 */
1610
 
1611
  imm = IMM(4);
1612
  put_reg (sp, get_reg (sp) - 4);
1613
  mem_put_si (get_reg (sp), imm);
1614
 
1615
  /** 1010 sss0 ss00 0001               PUSH.L src */
1616
 
1617
  prefix (0, 1, 0);
1618
  sc = decode_dest23 (sss, ss, 4);
1619
  a = get_src (sc);
1620
  put_reg (sp, get_reg (sp) - 4);
1621
  mem_put_si (get_reg (sp), a);
1622
 
1623
  /** 1011 0sa0 ss00 0001               PUSHA src */
1624
 
1625
  prefix (0, 0, 0);
1626
  sc = decode_dest23 (sa, ss, 1);
1627
  put_reg (sp, get_reg (sp) - 4);
1628
  mem_put_hi (get_reg (sp), sc.u.addr);
1629
  tprintf("pushsi: %x\n", sc.u.addr);
1630
 
1631
  /** 1101 0001 1010 1src               PUSHC src */
1632
 
1633
  prefix (0, 0, 0);
1634
  sc = decode_cr_b (src, CR_B_DCT0);
1635
  a = get_src (sc);
1636
  put_reg (sp, get_reg (sp) - 2);
1637
  mem_put_hi (get_reg (sp), a);
1638
  tprintf("pushhi: %x\n", a);
1639
 
1640
  /** 1101 0001 0010 1src               PUSHC src */
1641
 
1642
  prefix (0, 0, 0);
1643
  sc = decode_cr_b (src, CR_B_INTB);
1644
  a = get_src (sc);
1645
  put_reg (sp, get_reg (sp) - 4);
1646
  mem_put_si (get_reg (sp), a);
1647
  tprintf("pushsi: %x\n", a);
1648
 
1649
  /** 1000 1111                         PUSHM src */
1650
 
1651
  static int map[] = { fb, sb, a1, a0, r3, r2, r1, r0 };
1652
  imm = IMM(1);
1653
  tprintf("pushm: %x\n", imm);
1654
  for (a=0; a<4; a++)
1655
    if (imm & (1<
1656
      {
1657
        put_reg (sp, get_reg (sp) - 4);
1658
        v = get_reg (map[a]);
1659
        mem_put_si (get_reg (sp), v);
1660
      }
1661
  for (; a<8; a++)
1662
    if (imm & (1<
1663
      {
1664
        put_reg (sp, get_reg (sp) - 2);
1665
        v = get_reg (map[a]);
1666
        mem_put_hi (get_reg (sp), v);
1667
      }
1668
 
1669
  /** 1001 1110                         REIT */
1670
 
1671
  a = get_reg (sp);
1672
  put_reg (pc, mem_get_si (a));
1673
  a += 4;
1674
  put_reg (flags, mem_get_hi (a));
1675
  a += 2;
1676
  put_reg (sp, a);
1677
 
1678
  /** 1011 1000 010w 0011               RMPA.size */
1679
 
1680
  int count = get_reg (r3);
1681
  int list1 = get_reg (a0);
1682
  int list2 = get_reg (a1);
1683
  long long sum = get_reg_ll (r3r1r2r0) & 0xffffff;
1684
 
1685
  while (count)
1686
    {
1687
      if (w)
1688
        {
1689
          a = sign_ext (mem_get_hi (list1), 16);
1690
          b = sign_ext (mem_get_hi (list2), 16);
1691
        }
1692
      else
1693
        {
1694
          a = sign_ext (mem_get_qi (list1), 8);
1695
          b = sign_ext (mem_get_qi (list2), 8);
1696
        }
1697
      tprintf("%lld + %d * %d = ", sum, a, b);
1698
      sum += a * b;
1699
      tprintf("%lld\n", sum);
1700
      list1 += w ? 2 : 1;
1701
      list2 += w ? 2 : 1;
1702
      count --;
1703
    }
1704
  put_reg (r3, count);
1705
  put_reg (a0, list1);
1706
  put_reg (a1, list2);
1707
  put_reg (r2r0, (int)(sum & 0xffffffffU));
1708
  put_reg (r1, (int)(sum >> 32));
1709
 
1710
  /** 1011 ddd w dd10 1110              ROLC.size dest */
1711
 
1712
  prefix (0, 1, 0);
1713
  dc = decode_dest23 (ddd, dd, w+1);
1714
  rot_op (dc, 1, 1);
1715
 
1716
  /** 1010 ddd w dd10 1110              RORC.size dest */
1717
 
1718
  prefix (0, 1, 0);
1719
  dc = decode_dest23 (ddd, dd, w+1);
1720
  rot_op (dc, 1, -1);
1721
 
1722
  /** 1110 ddd w dd10 immm              ROT.size #IMM, dest */
1723
 
1724
  prefix (0, 1, 0);
1725
  dc = decode_dest23 (ddd, dd, w+1);
1726
  rot_op (dc, IMM4(), -1);
1727
 
1728
  /** 1010 ddd w dd11 1111              ROT.size R1H,dest */
1729
 
1730
  prefix (0, 1, 0);
1731
  dc = decode_dest23 (ddd, dd, w+1);
1732
  a = sign_ext (get_reg (r1h), 8);
1733
  rot_op (dc, a, -1);
1734
 
1735
  /** 1101 1111                         RTS */
1736
 
1737
  put_reg (pc, mem_get_si (get_reg (sp)));
1738
  put_reg (sp, get_reg (sp) + 4);
1739
 
1740
  /** 0000 0001 1001 ddd w dd10 1110    SBB.size #IMM, dest */
1741
 
1742
  prefix (0, 0, 0);
1743
  dc = decode_dest23 (ddd, dd, w+1);
1744
  imm = IMM (w+1);
1745
  MATH_OP (dc, imm, !carry, -);
1746
 
1747
  /** 0000 0001 1sss ddd w dd ss 0110   SBB.size src,dest */
1748
 
1749
  prefix (0, 0, 0);
1750
  sc = decode_src23 (sss, ss, w+1);
1751
  dc = decode_dest23 (ddd, dd, w+1);
1752
  MATH_OP (dc, get_src (sc), !carry, -);
1753
 
1754
  /** 1101 ddd1 dd11 cond               SCcond dest */
1755
 
1756
  prefix (0, 1, 0);
1757
  dc = decode_dest23 (ddd, dd, 2);
1758
  if (condition_true (cond))
1759
    put_dest (dc, 1);
1760
  else
1761
    put_dest (dc, 0);
1762
 
1763
  /** 1011 1000 110w 0011               SCMPU.size */
1764
 
1765
  ta0 = get_reg (a0);
1766
  ta1 = get_reg (a1);
1767
 
1768
  for (;;)
1769
    {
1770
      t0 = mem_get_qi (ta0);
1771
      t2 = mem_get_qi (ta1);
1772
      if (w)
1773
        {
1774
          t1 = mem_get_qi (ta0 + 1);
1775
          t3 = mem_get_qi (ta1 + 1);
1776
        }
1777
      dif = t0 - t2;
1778
      if (dif == 0 && t0 != 0 && w)
1779
        dif = t1 - t3;
1780
      set_oszc (dif, 1, dif > 0);
1781
 
1782
      ta0 += w ? 2 : 1;
1783
      ta1 += w ? 2 : 1;
1784
 
1785
      if (t0 == 0 || t0 != t2)
1786
        break;
1787
      if (w && (t1 == 0 || t1 != t3))
1788
        break;
1789
    }
1790
 
1791
  /** 1111 ddd w dd00 immm              SHA.size #IMM,dest */
1792
 
1793
  prefix (0, 1, 0);
1794
  dc = decode_dest23 (ddd, dd, w+1);
1795
  shift_op (dc, 1, IMM4(), 1);
1796
 
1797
  /** 1010 ddd0 dd10 0001               SHA.L #IMM,dest */
1798
 
1799
  prefix (0, 1, 0);
1800
  dc = decode_dest23 (ddd, dd, 4);
1801
  imm = sign_ext (IMM(1), 8);
1802
  shift_op (dc, 1, imm, 1);
1803
 
1804
  /** 1011 ddd w dd11 1110              SHA.size R1H,dest */
1805
 
1806
  prefix (0, 1, 0);
1807
  dc = decode_dest23 (ddd, dd, w+1);
1808
  a = sign_ext (get_reg (r1h), 8);
1809
  shift_op (dc, 1, a, 1);
1810
 
1811
  /** 1100 ddd0 dd01 0001               SHA.L   R1H,dest */
1812
 
1813
  prefix (0, 1, 0);
1814
  dc = decode_dest23 (ddd, dd, 4);
1815
  a = sign_ext (get_reg (r1h), 8);
1816
  shift_op (dc, 1, a, 1);
1817
 
1818
  /** 1100 ddd0 dd10 0001               SHANC.L #IMM,dest */
1819
 
1820
  M32C_ONLY();
1821
  prefix (0, 1, 0);
1822
  dc = decode_dest23 (ddd, dd, 4);
1823
  imm = sign_ext (IMM(1), 8);
1824
  shift_op (dc, 1, imm, 0);
1825
 
1826
  /** 1110 ddd w dd00 immm              SHL.size #IMM, dest */
1827
 
1828
  prefix (0, 1, 0);
1829
  dc = decode_dest23 (ddd, dd, w+1);
1830
  shift_op (dc, 0, IMM4(), 1);
1831
 
1832
  /** 1001 ddd0 dd10 0001               SHL.L #IMM, dest */
1833
 
1834
  prefix (0, 1, 0);
1835
  dc = decode_dest23 (ddd, dd, 4);
1836
  imm = sign_ext (IMM(1), 8);
1837
  shift_op (dc, 0, imm, 1);
1838
 
1839
  /** 1010 ddd w dd11 1110              SHL.size R1H,dest */
1840
 
1841
  prefix (0, 1, 0);
1842
  dc = decode_dest23 (ddd, dd, w+1);
1843
  a = sign_ext (get_reg (r1h), 8);
1844
  shift_op (dc, 0, a, 1);
1845
 
1846
  /** 1100 ddd0 dd00 0001               SHL.L R1H,dest */
1847
 
1848
  prefix (0, 1, 0);
1849
  dc = decode_dest23 (ddd, dd, 4);
1850
  a = sign_ext (get_reg (r1h), 8);
1851
  shift_op (dc, 0, a, 1);
1852
 
1853
  /** 1000 ddd0 dd10 0001               SHLNC.L #IMM,dest */
1854
 
1855
  M32C_ONLY();
1856
  prefix (0, 1, 0);
1857
  dc = decode_dest23 (ddd, dd, 4);
1858
  imm = sign_ext (IMM(1), 8);
1859
  shift_op (dc, 0, imm, 0);
1860
 
1861
  /** 1011 0010 100w 0011               SIN.size */
1862
 
1863
  v = get_reg (a0);
1864
  a = get_reg (a1);
1865
  b = get_reg (r3);
1866
  if (b) for (;b;)
1867
    {
1868
      if (w)
1869
        mem_put_hi(a, mem_get_hi (v));
1870
      else
1871
        mem_put_qi(a, mem_get_qi (v));
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 0110 100w 0011               SMOVB.size */
1880
 
1881
  v = get_reg (a0);
1882
  a = get_reg (a1);
1883
  b = get_reg (r3);
1884
  if (b) for (;b;)
1885
    {
1886
      if (w)
1887
        mem_put_hi(a, mem_get_hi (v));
1888
      else
1889
        mem_put_qi(a, mem_get_qi (v));
1890
      v -= w ? 2 : 1;
1891
      a -= w ? 2 : 1;
1892
      b --;
1893
    }
1894
  put_reg (a0, v);
1895
  put_reg (a1, a);
1896
  put_reg (r3, b);
1897
 
1898
  /** 1011 0000 100w 0011               SMOVF.size */
1899
 
1900
  v = get_reg (a0);
1901
  a = get_reg (a1);
1902
  b = get_reg (r3);
1903
  if (b) 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
      a += w ? 2 : 1;
1911
      b --;
1912
    }
1913
  put_reg (a0, v);
1914
  put_reg (a1, a);
1915
  put_reg (r3, b);
1916
 
1917
  /** 1011 1000 100w 0011               SMOVU.size */
1918
 
1919
  v = get_reg (a0);
1920
  a = get_reg (a1);
1921
  do
1922
    {
1923
      if (w)
1924
        mem_put_hi(a, (t0 = mem_get_hi (v)));
1925
      else
1926
        mem_put_qi(a, (t0 = mem_get_qi (v)));
1927
      v += w ? 2 : 1;
1928
      a += w ? 2 : 1;
1929
      if (t0 == 0
1930
          || (w && ((t0 & 0xff) == 0 || (t0 & 0xff00) == 0)))
1931
        break;
1932
    } while (1);
1933
  put_reg (a0, v);
1934
  put_reg (a1, a);
1935
 
1936
  /** 1011 0100 100w 0011               SOUT.size */
1937
 
1938
  v = get_reg (a0);
1939
  a = get_reg (a1);
1940
  b = get_reg (r3);
1941
  for (;b;)
1942
    {
1943
      if (w)
1944
        mem_put_hi(a, mem_get_hi (v));
1945
      else
1946
        mem_put_qi(a, mem_get_qi (v));
1947
      v += w ? 2 : 1;
1948
      b --;
1949
    }
1950
  put_reg (a0, v);
1951
  put_reg (a1, a);
1952
  put_reg (r3, b);
1953
 
1954
  /** 1011 1000 000w 0011               SSTR.size */
1955
 
1956
  a = get_reg (a1);
1957
  b = get_reg (r3);
1958
  v = get_reg (w ? r0 : r0l);
1959
  for (;b;)
1960
    {
1961
      if (w)
1962
        mem_put_hi(a, v);
1963
      else
1964
        mem_put_qi(a, v);
1965
      a += w ? 2 : 1;
1966
      b --;
1967
    }
1968
  put_reg (a1, a);
1969
  put_reg (r3, b);
1970
 
1971
  /** 0000 0001 1101 ddd1 dd01 0src     STC src,dest */
1972
 
1973
  prefix (0, 0, 0);
1974
  dc = decode_dest23 (ddd, dd, 4);
1975
  sc = decode_cr_b (src, CR_B_DMA0);
1976
  a = get_src (sc);
1977
  put_dest (dc, a);
1978
 
1979
  /** 0000 0001 1101 ddd1 dd01 1src     STC src,dest */
1980
 
1981
  prefix (0, 0, 0);
1982
  dc = decode_dest23 (ddd, dd, 2);
1983
  sc = decode_cr_b (src, CR_B_DCT0);
1984
  a = get_src (sc);
1985
  put_dest (dc, a);
1986
 
1987
  /** 1101 ddd1 dd01 0src               STC src,dest */
1988
 
1989
  prefix (0, 0, 0);
1990
  dc = decode_dest23 (ddd, dd, 4);
1991
  sc = decode_cr_b (src, CR_B_INTB);
1992
  a = get_src (sc);
1993
  put_dest (dc, a);
1994
 
1995
  /** 1011 0110 1101 0011               STCX abs16,abs24 */
1996
 
1997
  NOTYET();
1998
 
1999
  /** 1001 ddd w dd01 1111              STNZ.size #IMM,dest */
2000
 
2001
  prefix (0, 1, 0);
2002
  dc = decode_dest23 (ddd, dd, w+1);
2003
  imm = IMM(w+1);
2004
  if (! FLAG_Z)
2005
    put_dest (dc, imm);
2006
 
2007
  /** 1001 ddd w dd00 1111              STZ.size #IMM,dest */
2008
 
2009
  prefix (0, 1, 0);
2010
  dc = decode_dest23 (ddd, dd, w+1);
2011
  imm = IMM(w+1);
2012
  if (FLAG_Z)
2013
    put_dest (dc, imm);
2014
 
2015
  /** 1001 ddd w dd11 1111              STZX.size #IMM1,#IMM2,dest */
2016
 
2017
  prefix (0, 1, 0);
2018
  dc = decode_dest23 (ddd, dd, w+1);
2019
  a = IMM(w+1);
2020
  b = IMM(w+1);
2021
  if (FLAG_Z)
2022
    put_dest (dc, a);
2023
  else
2024
    put_dest (dc, b);
2025
 
2026
  /** 1000 ddd w dd11 1110              SUB.size:G #IMM,dest */
2027
 
2028
  prefix (0, 1, 0);
2029
  dc = decode_dest23(ddd, dd, w+1);
2030
  imm = IMM(w+1);
2031
  MATH_OP (dc, imm, 0, -);
2032
 
2033
  /** 1001 ddd0 dd11 0001               SUB.L:G #IMM,dest */
2034
 
2035
  prefix (0, 1, 0);
2036
  dc = decode_dest23(ddd, dd, 4);
2037
  imm = IMM(4);
2038
  MATH_OP (dc, imm, 0, -);
2039
 
2040
  /** 00dd 111w                         SUB.size:S #IMM,dest */
2041
 
2042
  prefix (0, 1, 0);
2043
  dc = decode_dest2(dd, w+1);
2044
  imm = IMM (w+1);
2045
  MATH_OP (dc, imm, 0, -);
2046
 
2047
  /** 1sss ddd w dd ss 1010             SUB.size:G src,dest */
2048
 
2049
  prefix (1, 1, 0);
2050
  sc = decode_src23(sss, ss, w+1);
2051
  dc = decode_dest23(ddd, dd, w+1);
2052
  b = get_src (sc);
2053
  MATH_OP (dc, b, 0, -);
2054
 
2055
  /** 1sss ddd1 dd ss 0000              SUB.L:G src,dest */
2056
 
2057
  prefix (1, 1, 0);
2058
  sc = decode_src23(sss, ss, 4);
2059
  dc = decode_dest23(ddd, dd, 4);
2060
  b = get_src (sc);
2061
  MATH_OP (dc, b, 0, -);
2062
 
2063
  /** 1001 ddd0 dd01 0001               SUBX #IMM,dest */
2064
 
2065
  prefix (0, 1, 0);
2066
  dc = decode_dest23(ddd, dd, 4);
2067
  imm = sign_ext (IMM(1), 8);
2068
  MATH_OP (dc, imm, 0, -);
2069
 
2070
  /** 1sss ddd0 dd ss 0000              SUBX src,dest */
2071
 
2072
  prefix (1, 1, 0);
2073
  sc = decode_src23(sss, ss, 1);
2074
  dc = decode_dest23(ddd, dd, 4);
2075
  b = sign_ext (get_src (sc), 8);
2076
  MATH_OP (dc, b, 0, -);
2077
 
2078
  /** 1001 ddd w dd11 1110              TST.size:G #IMM,dest */
2079
 
2080
  prefix (0, 0, 0);
2081
  dc = decode_dest23 (ddd, dd, w+1);
2082
  imm = IMM(w+1);
2083
  a = get_src (dc);
2084
  v = a & imm;
2085
  set_sz (v, w+1);
2086
 
2087
  /** 00dd 110w                         TST.size:S #IMM,dest */
2088
 
2089
  prefix (0, 0, 0);
2090
  dc = decode_dest2 (dd, w+1);
2091
  imm = IMM(w+1);
2092
  a = get_src (dc);
2093
  v = a & imm;
2094
  set_sz (v, w+1);
2095
 
2096
  /** 0000 0001 1sss ddd w dd ss 1001   TST.size:G src,dest */
2097
 
2098
  prefix (0, 0, 0);
2099
  sc = decode_src23 (sss, ss, w+1);
2100
  dc = decode_dest23 (ddd, dd, w+1);
2101
  b = get_src (sc);
2102
  a = get_src (dc);
2103
  v = a & b;
2104
  set_sz (v, w+1);
2105
 
2106
  /** 1111 1111                         UND */
2107
 
2108
  trigger_fixed_interrupt (0xffffdc);
2109
 
2110
  /** 1011 0010 0000 0011               WAIT */
2111
 
2112
  ;
2113
 
2114
  /** 1101 ddd w dd00 1src              XCHG.size src,dest */
2115
 
2116
  dc = decode_dest23 (ddd, dd, w+1);
2117
  sc = decode_src3 (src, w+1);
2118
  a = get_src (dc);
2119
  b = get_src (sc);
2120
  put_dest (dc, b);
2121
  put_dest (sc, a);
2122
 
2123
  /** 1001 ddd w dd00 1110              XOR.size #IMM,dest */
2124
 
2125
  prefix (0, 1, 0);
2126
  dc = decode_dest23(ddd, dd, w+1);
2127
  imm = IMM(w+1);
2128
  LOGIC_OP (dc, imm, ^);
2129
 
2130
  /** 1sss ddd w dd ss 1001             XOR.size src,dest */
2131
 
2132
  prefix (1, 1, 0);
2133
  sc = decode_src23(sss, ss, w+1);
2134
  dc = decode_dest23(ddd, dd, w+1);
2135
  b = get_src (sc);
2136
  LOGIC_OP (dc, b, ^);
2137
 
2138
/** */
2139
 
2140
  return step_result;
2141
}

powered by: WebSVN 2.1.0

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