OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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