Coverage Report

Created: 2024-05-21 06:29

/src/binutils-gdb/opcodes/tic54x-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassembly routines for TMS320C54X architecture
2
   Copyright (C) 1999-2024 Free Software Foundation, Inc.
3
   Contributed by Timothy Wall (twall@cygnus.com)
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this file; see the file COPYING.  If not, write to the
19
   Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include <errno.h>
24
#include <math.h>
25
#include <stdlib.h>
26
#include "disassemble.h"
27
#include "opcode/tic54x.h"
28
#include "coff/tic54x.h"
29
30
static int has_lkaddr (unsigned short, const insn_template *);
31
static int get_insn_size (unsigned short, const insn_template *);
32
static int print_instruction (disassemble_info *, bfd_vma,
33
                              unsigned short, const char *,
34
                              const enum optype [], int, int);
35
static int print_parallel_instruction (disassemble_info *, bfd_vma,
36
                                       unsigned short,
37
                                       const insn_template *, int);
38
static int sprint_dual_address (disassemble_info *,char [],
39
                                unsigned short);
40
static int sprint_indirect_address (disassemble_info *,char [],
41
                                    unsigned short);
42
static int sprint_direct_address (disassemble_info *,char [],
43
                                  unsigned short);
44
static int sprint_mmr (disassemble_info *,char [],int);
45
static int sprint_condition (disassemble_info *,char *,unsigned short);
46
static int sprint_cc2 (disassemble_info *,char *,unsigned short);
47
48
int
49
print_insn_tic54x (bfd_vma memaddr, disassemble_info *info)
50
1.69M
{
51
1.69M
  bfd_byte opbuf[2];
52
1.69M
  unsigned short opcode;
53
1.69M
  int status, size;
54
1.69M
  const insn_template* tm;
55
56
1.69M
  status = (*info->read_memory_func) (memaddr, opbuf, 2, info);
57
1.69M
  if (status != 0)
58
60
  {
59
60
    (*info->memory_error_func) (status, memaddr, info);
60
60
    return -1;
61
60
  }
62
63
1.69M
  opcode = bfd_getl16 (opbuf);
64
1.69M
  tm = tic54x_get_insn (info, memaddr, opcode, &size);
65
66
1.69M
  info->bytes_per_line = 2;
67
1.69M
  info->bytes_per_chunk = 2;
68
1.69M
  info->octets_per_byte = 2;
69
1.69M
  info->display_endian = BFD_ENDIAN_LITTLE;
70
71
1.69M
  if (tm->flags & FL_PAR)
72
54.9k
  {
73
54.9k
    if (!print_parallel_instruction (info, memaddr, opcode, tm, size))
74
0
      return -1;
75
54.9k
  }
76
1.64M
  else
77
1.64M
  {
78
1.64M
    if (!print_instruction (info, memaddr, opcode,
79
1.64M
                            (char *) tm->name,
80
1.64M
                            tm->operand_types,
81
1.64M
                            size, (tm->flags & FL_EXT)))
82
120
      return -1;
83
1.64M
  }
84
85
1.69M
  return size * 2;
86
1.69M
}
87
88
static int
89
has_lkaddr (unsigned short memdata, const insn_template *tm)
90
1.65M
{
91
1.65M
  return (IS_LKADDR (memdata)
92
1.65M
    && (OPTYPE (tm->operand_types[0]) == OP_Smem
93
157k
        || OPTYPE (tm->operand_types[1]) == OP_Smem
94
157k
        || OPTYPE (tm->operand_types[2]) == OP_Smem
95
157k
        || OPTYPE (tm->operand_types[1]) == OP_Sind
96
157k
              || OPTYPE (tm->operand_types[0]) == OP_Lmem
97
157k
              || OPTYPE (tm->operand_types[1]) == OP_Lmem));
98
1.65M
}
99
100
/* always returns 1 (whether an insn template was found) since we provide an
101
   "unknown instruction" template */
102
const insn_template*
103
tic54x_get_insn (disassemble_info *info, bfd_vma addr,
104
                 unsigned short memdata, int *size)
105
1.69M
{
106
1.69M
  const insn_template *tm = NULL;
107
108
124M
  for (tm = tic54x_optab; tm->name; tm++)
109
124M
  {
110
124M
    if (tm->opcode == (memdata & tm->mask))
111
1.65M
    {
112
      /* a few opcodes span two words */
113
1.65M
      if (tm->flags & FL_EXT)
114
29.6k
        {
115
          /* if lk addressing is used, the second half of the opcode gets
116
             pushed one word later */
117
29.6k
          bfd_byte opbuf[2];
118
29.6k
          bfd_vma addr2 = addr + 1 + has_lkaddr (memdata, tm);
119
29.6k
          int status = (*info->read_memory_func) (addr2, opbuf, 2, info);
120
          /* FIXME handle errors.  */
121
29.6k
          if (status == 0)
122
29.5k
            {
123
29.5k
              unsigned short data2 = bfd_getl16 (opbuf);
124
29.5k
              if (tm->opcode2 == (data2 & tm->mask2))
125
263
                {
126
263
                  if (size) *size = get_insn_size (memdata, tm);
127
263
                  return tm;
128
263
                }
129
29.5k
            }
130
29.6k
        }
131
1.62M
      else
132
1.62M
        {
133
1.62M
          if (size) *size = get_insn_size (memdata, tm);
134
1.62M
          return tm;
135
1.62M
        }
136
1.65M
    }
137
124M
  }
138
618k
  for (tm = (insn_template *) tic54x_paroptab; tm->name; tm++)
139
604k
  {
140
604k
    if (tm->opcode == (memdata & tm->mask))
141
54.9k
    {
142
54.9k
      if (size) *size = get_insn_size (memdata, tm);
143
54.9k
      return tm;
144
54.9k
    }
145
604k
  }
146
147
13.7k
  if (size) *size = 1;
148
13.7k
  return &tic54x_unknown_opcode;
149
68.6k
}
150
151
static int
152
get_insn_size (unsigned short memdata, const insn_template *insn)
153
1.68M
{
154
1.68M
  int size;
155
156
1.68M
  if (insn->flags & FL_PAR)
157
54.9k
    {
158
      /* only non-parallel instructions support lk addressing */
159
54.9k
      size = insn->words;
160
54.9k
    }
161
1.62M
  else
162
1.62M
    {
163
1.62M
      size = insn->words + has_lkaddr (memdata, insn);
164
1.62M
    }
165
166
1.68M
  return size;
167
1.68M
}
168
169
int
170
print_instruction (disassemble_info *info,
171
       bfd_vma memaddr,
172
       unsigned short opcode,
173
       const char *tm_name,
174
       const enum optype tm_operands[],
175
       int size,
176
       int ext)
177
1.75M
{
178
1.75M
  static int n;
179
  /* string storage for multiple operands */
180
1.75M
  char operand[4][64] = { {0},{0},{0},{0}, };
181
1.75M
  bfd_byte buf[2];
182
1.75M
  unsigned long opcode2 = 0;
183
1.75M
  unsigned long lkaddr = 0;
184
1.75M
  enum optype src = OP_None;
185
1.75M
  enum optype dst = OP_None;
186
1.75M
  int i, shift;
187
1.75M
  char *comma = "";
188
189
1.75M
  info->fprintf_func (info->stream, "%-7s", tm_name);
190
191
1.75M
  if (size > 1)
192
190k
    {
193
190k
      int status = (*info->read_memory_func) (memaddr + 1, buf, 2, info);
194
190k
      if (status != 0)
195
118
        return 0;
196
190k
      lkaddr = opcode2 = bfd_getl16 (buf);
197
190k
      if (size > 2)
198
4.00k
        {
199
4.00k
          status = (*info->read_memory_func) (memaddr + 2, buf, 2, info);
200
4.00k
          if (status != 0)
201
2
            return 0;
202
3.99k
          opcode2 = bfd_getl16 (buf);
203
3.99k
        }
204
190k
    }
205
206
5.48M
  for (i = 0; i < MAX_OPERANDS && OPTYPE (tm_operands[i]) != OP_None; i++)
207
3.73M
    {
208
3.73M
      char *next_comma = ",";
209
3.73M
      int optional = (tm_operands[i] & OPT) != 0;
210
211
3.73M
      switch (OPTYPE (tm_operands[i]))
212
3.73M
        {
213
140k
        case OP_Xmem:
214
140k
          sprint_dual_address (info, operand[i], XMEM (opcode));
215
140k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
216
140k
          break;
217
101k
        case OP_Ymem:
218
101k
          sprint_dual_address (info, operand[i], YMEM (opcode));
219
101k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
220
101k
          break;
221
1.30M
        case OP_Smem:
222
1.31M
        case OP_Sind:
223
1.35M
        case OP_Lmem:
224
1.35M
          info->fprintf_func (info->stream, "%s", comma);
225
1.35M
          if (INDIRECT (opcode))
226
121k
            {
227
121k
              if (MOD (opcode) >= 12)
228
38.8k
                {
229
38.8k
                  bfd_vma addr = lkaddr;
230
38.8k
                  int arf = ARF (opcode);
231
38.8k
                  int mod = MOD (opcode);
232
38.8k
                  if (mod == 15)
233
21.1k
                      info->fprintf_func (info->stream, "*(");
234
17.6k
                  else
235
17.6k
                      info->fprintf_func (info->stream, "*%sar%d(",
236
17.6k
                                          (mod == 13 || mod == 14 ? "+" : ""),
237
17.6k
                                          arf);
238
38.8k
                  (*(info->print_address_func)) ((bfd_vma) addr, info);
239
38.8k
                  info->fprintf_func (info->stream, ")%s",
240
38.8k
                                      mod == 14 ? "%" : "");
241
38.8k
                }
242
82.1k
              else
243
82.1k
                {
244
82.1k
                  sprint_indirect_address (info, operand[i], opcode);
245
82.1k
                  info->fprintf_func (info->stream, "%s", operand[i]);
246
82.1k
                }
247
121k
            }
248
1.23M
          else
249
1.23M
          {
250
            /* FIXME -- use labels (print_address_func) */
251
            /* in order to do this, we need to guess what DP is */
252
1.23M
            sprint_direct_address (info, operand[i], opcode);
253
1.23M
            info->fprintf_func (info->stream, "%s", operand[i]);
254
1.23M
          }
255
1.35M
          break;
256
23.1k
        case OP_dmad:
257
23.1k
          info->fprintf_func (info->stream, "%s", comma);
258
23.1k
          (*(info->print_address_func)) ((bfd_vma) opcode2, info);
259
23.1k
          break;
260
4.83k
        case OP_xpmad:
261
          /* upper 7 bits of address are in the opcode */
262
4.83k
          opcode2 += ((unsigned long) opcode & 0x7F) << 16;
263
          /* fall through */
264
29.1k
        case OP_pmad:
265
29.1k
          info->fprintf_func (info->stream, "%s", comma);
266
29.1k
          (*(info->print_address_func)) ((bfd_vma) opcode2, info);
267
29.1k
          break;
268
792
        case OP_MMRX:
269
792
          sprint_mmr (info, operand[i], MMRX (opcode));
270
792
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
271
792
          break;
272
792
        case OP_MMRY:
273
792
          sprint_mmr (info, operand[i], MMRY (opcode));
274
792
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
275
792
          break;
276
41.8k
        case OP_MMR:
277
41.8k
          sprint_mmr (info, operand[i], MMR (opcode));
278
41.8k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
279
41.8k
          break;
280
13.0k
        case OP_PA:
281
13.0k
          sprintf (operand[i], "pa%d", (unsigned) opcode2);
282
13.0k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
283
13.0k
          break;
284
151k
        case OP_SRC:
285
151k
          src = SRC (ext ? opcode2 : opcode) ? OP_B : OP_A;
286
151k
          sprintf (operand[i], (src == OP_B) ? "b" : "a");
287
151k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
288
151k
          break;
289
1.03M
        case OP_SRC1:
290
1.03M
          src = SRC1 (ext ? opcode2 : opcode) ? OP_B : OP_A;
291
1.03M
          sprintf (operand[i], (src == OP_B) ? "b" : "a");
292
1.03M
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
293
1.03M
          break;
294
9.37k
        case OP_RND:
295
9.37k
          dst = DST (opcode) ? OP_B : OP_A;
296
9.37k
          sprintf (operand[i], (dst == OP_B) ? "a" : "b");
297
9.37k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
298
9.37k
          break;
299
307k
        case OP_DST:
300
307k
          dst = DST (ext ? opcode2 : opcode) ? OP_B : OP_A;
301
307k
          if (!optional || dst != src)
302
245k
            {
303
245k
              sprintf (operand[i], (dst == OP_B) ? "b" : "a");
304
245k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
305
245k
            }
306
61.8k
          else
307
61.8k
            next_comma = comma;
308
307k
          break;
309
22.9k
        case OP_B:
310
22.9k
          sprintf (operand[i], "b");
311
22.9k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
312
22.9k
          break;
313
3
        case OP_A:
314
3
          sprintf (operand[i], "a");
315
3
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
316
3
          break;
317
165
        case OP_ARX:
318
165
          sprintf (operand[i], "ar%d", (int) ARX (opcode));
319
165
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
320
165
          break;
321
7.62k
        case OP_SHIFT:
322
7.62k
          shift = SHIFT (ext ? opcode2 : opcode);
323
7.62k
          if (!optional || shift != 0)
324
5.08k
            {
325
5.08k
              sprintf (operand[i], "%d", shift);
326
5.08k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
327
5.08k
            }
328
2.53k
          else
329
2.53k
            next_comma = comma;
330
7.62k
          break;
331
25.5k
        case OP_SHFT:
332
25.5k
          shift = SHFT (opcode);
333
25.5k
          if (!optional || shift != 0)
334
25.4k
            {
335
25.4k
              sprintf (operand[i], "%d", (unsigned) shift);
336
25.4k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
337
25.4k
            }
338
91
          else
339
91
            next_comma = comma;
340
25.5k
          break;
341
88.0k
        case OP_lk:
342
88.0k
          sprintf (operand[i], "#%d", (int) (short) opcode2);
343
88.0k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
344
88.0k
          break;
345
15.8k
        case OP_T:
346
15.8k
          sprintf (operand[i], "t");
347
15.8k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
348
15.8k
          break;
349
49.0k
        case OP_TS:
350
49.0k
          sprintf (operand[i], "ts");
351
49.0k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
352
49.0k
          break;
353
1.18k
        case OP_k8:
354
1.18k
          sprintf (operand[i], "%d", (int) ((signed char) (opcode & 0xFF)));
355
1.18k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
356
1.18k
          break;
357
34.4k
        case OP_16:
358
34.4k
          sprintf (operand[i], "16");
359
34.4k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
360
34.4k
          break;
361
9.46k
        case OP_ASM:
362
9.46k
          sprintf (operand[i], "asm");
363
9.46k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
364
9.46k
          break;
365
7.44k
        case OP_BITC:
366
7.44k
          sprintf (operand[i], "%d", (int) (opcode & 0xF));
367
7.44k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
368
7.44k
          break;
369
116k
        case OP_CC:
370
          /* put all CC operands in the same operand */
371
116k
          sprint_condition (info, operand[i], opcode);
372
116k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
373
116k
          i = MAX_OPERANDS;
374
116k
          break;
375
6.47k
        case OP_CC2:
376
6.47k
          sprint_cc2 (info, operand[i], opcode);
377
6.47k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
378
6.47k
          break;
379
165
        case OP_CC3:
380
165
        {
381
165
          const char *code[] = { "eq", "lt", "gt", "neq" };
382
383
    /* Do not use sprintf with only two parameters as a
384
       compiler warning could be generated in such conditions.  */
385
165
    sprintf (operand[i], "%s", code[CC3 (opcode)]);
386
165
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
387
165
          break;
388
4.83k
        }
389
22
        case OP_123:
390
22
          {
391
22
            int code = (opcode >> 8) & 0x3;
392
22
            sprintf (operand[i], "%d", (code == 0) ? 1 : (code == 2) ? 2 : 3);
393
22
            info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
394
22
            break;
395
4.83k
          }
396
205
        case OP_k5:
397
205
          sprintf (operand[i], "#%d", ((opcode & 0x1F) ^ 0x10) - 0x10);
398
205
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
399
205
          break;
400
5.96k
        case OP_k8u:
401
5.96k
          sprintf (operand[i], "#%d", (unsigned) (opcode & 0xFF));
402
5.96k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
403
5.96k
          break;
404
83
        case OP_k3:
405
83
          sprintf (operand[i], "#%d", (int) (opcode & 0x7));
406
83
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
407
83
          break;
408
2.17k
        case OP_lku:
409
2.17k
          sprintf (operand[i], "#%d", (unsigned) opcode2);
410
2.17k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
411
2.17k
          break;
412
109
        case OP_N:
413
109
          n = (opcode >> 9) & 0x1;
414
109
          sprintf (operand[i], "st%d", n);
415
109
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
416
109
          break;
417
109
        case OP_SBIT:
418
109
        {
419
109
          const char *status0[] = {
420
109
            "0", "1", "2", "3", "4", "5", "6", "7", "8",
421
109
            "ovb", "ova", "c", "tc", "13", "14", "15"
422
109
          };
423
109
          const char *status1[] = {
424
109
            "0", "1", "2", "3", "4",
425
109
            "cmpt", "frct", "c16", "sxm", "ovm", "10",
426
109
            "intm", "hm", "xf", "cpl", "braf"
427
109
          };
428
109
          sprintf (operand[i], "%s",
429
109
                   n ? status1[SBIT (opcode)] : status0[SBIT (opcode)]);
430
109
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
431
109
          break;
432
4.83k
        }
433
108k
        case OP_12:
434
108k
          sprintf (operand[i], "%d", (int) ((opcode >> 9) & 1) + 1);
435
108k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
436
108k
          break;
437
5.35k
        case OP_TRN:
438
5.35k
          sprintf (operand[i], "trn");
439
5.35k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
440
5.35k
          break;
441
7.98k
        case OP_DP:
442
7.98k
          sprintf (operand[i], "dp");
443
7.98k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
444
7.98k
          break;
445
5.53k
        case OP_k9:
446
          /* FIXME-- this is DP, print the original address? */
447
5.53k
          sprintf (operand[i], "#%d", (int) (opcode & 0x1FF));
448
5.53k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
449
5.53k
          break;
450
83
        case OP_ARP:
451
83
          sprintf (operand[i], "arp");
452
83
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
453
83
          break;
454
195
        case OP_031:
455
195
          sprintf (operand[i], "%d", (int) (opcode & 0x1F));
456
195
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
457
195
          break;
458
0
        default:
459
0
          sprintf (operand[i], "??? (0x%x)", tm_operands[i]);
460
0
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
461
0
          break;
462
3.73M
        }
463
3.73M
      comma = next_comma;
464
3.73M
    }
465
1.75M
  return 1;
466
1.75M
}
467
468
static int
469
print_parallel_instruction (disassemble_info *info,
470
          bfd_vma memaddr,
471
          unsigned short opcode,
472
          const insn_template *ptm,
473
          int size)
474
54.9k
{
475
54.9k
  print_instruction (info, memaddr, opcode,
476
54.9k
                     ptm->name, ptm->operand_types, size, 0);
477
54.9k
  info->fprintf_func (info->stream, " || ");
478
54.9k
  return print_instruction (info, memaddr, opcode,
479
54.9k
                            ptm->parname, ptm->paroperand_types, size, 0);
480
54.9k
}
481
482
static int
483
sprint_dual_address (disassemble_info *info ATTRIBUTE_UNUSED,
484
         char buf[],
485
         unsigned short code)
486
241k
{
487
241k
  const char *formats[] = {
488
241k
    "*ar%d",
489
241k
    "*ar%d-",
490
241k
    "*ar%d+",
491
241k
    "*ar%d+0%%",
492
241k
  };
493
241k
  return sprintf (buf, formats[XMOD (code)], XARX (code));
494
241k
}
495
496
static int
497
sprint_indirect_address (disassemble_info *info ATTRIBUTE_UNUSED,
498
       char buf[],
499
       unsigned short opcode)
500
82.1k
{
501
82.1k
  const char *formats[] = {
502
82.1k
    "*ar%d",
503
82.1k
    "*ar%d-",
504
82.1k
    "*ar%d+",
505
82.1k
    "*+ar%d",
506
82.1k
    "*ar%d-0B",
507
82.1k
    "*ar%d-0",
508
82.1k
    "*ar%d+0",
509
82.1k
    "*ar%d+0B",
510
82.1k
    "*ar%d-%%",
511
82.1k
    "*ar%d-0%%",
512
82.1k
    "*ar%d+%%",
513
82.1k
    "*ar%d+0%%",
514
82.1k
  };
515
82.1k
  return sprintf (buf, formats[MOD (opcode)], ARF (opcode));
516
82.1k
}
517
518
static int
519
sprint_direct_address (disassemble_info *info ATTRIBUTE_UNUSED,
520
           char buf[],
521
           unsigned short opcode)
522
1.23M
{
523
  /* FIXME -- look up relocation if available */
524
1.23M
  return sprintf (buf, "DP+0x%02x", (int) (opcode & 0x7F));
525
1.23M
}
526
527
static int
528
sprint_mmr (disassemble_info *info ATTRIBUTE_UNUSED,
529
      char buf[],
530
      int mmr)
531
43.4k
{
532
43.4k
  const tic54x_symbol *reg = tic54x_mmregs;
533
3.72M
  while (reg->name != NULL)
534
3.69M
    {
535
3.69M
      if (mmr == reg->value)
536
17.6k
        {
537
17.6k
          sprintf (buf, "%s", (reg + 1)->name);
538
17.6k
          return 1;
539
17.6k
        }
540
3.67M
      ++reg;
541
3.67M
    }
542
25.7k
  sprintf (buf, "MMR(%d)", mmr); /* FIXME -- different targets.  */
543
25.7k
  return 0;
544
43.4k
}
545
546
static int
547
sprint_cc2 (disassemble_info *info ATTRIBUTE_UNUSED,
548
      char *buf,
549
      unsigned short opcode)
550
6.47k
{
551
6.47k
  const char *cc2[] = {
552
6.47k
    "??", "??", "ageq", "alt", "aneq", "aeq", "agt", "aleq",
553
6.47k
    "??", "??", "bgeq", "blt", "bneq", "beq", "bgt", "bleq",
554
6.47k
  };
555
6.47k
  return sprintf (buf, "%s", cc2[opcode & 0xF]);
556
6.47k
}
557
558
static int
559
sprint_condition (disassemble_info *info ATTRIBUTE_UNUSED,
560
      char *buf,
561
      unsigned short opcode)
562
116k
{
563
116k
  char *start = buf;
564
116k
  const char *cmp[] = {
565
116k
      "??", "??", "geq", "lt", "neq", "eq", "gt", "leq"
566
116k
  };
567
116k
  if (opcode & 0x40)
568
99.6k
    {
569
99.6k
      char acc = (opcode & 0x8) ? 'b' : 'a';
570
99.6k
      if (opcode & 0x7)
571
98.8k
          buf += sprintf (buf, "%c%s%s", acc, cmp[(opcode & 0x7)],
572
98.8k
                          (opcode & 0x20) ? ", " : "");
573
99.6k
      if (opcode & 0x20)
574
96.9k
          buf += sprintf (buf, "%c%s", acc, (opcode & 0x10) ? "ov" : "nov");
575
99.6k
    }
576
17.1k
  else if (opcode & 0x3F)
577
8.77k
    {
578
8.77k
      if (opcode & 0x30)
579
6.02k
        buf += sprintf (buf, "%s%s",
580
6.02k
                        ((opcode & 0x30) == 0x30) ? "tc" : "ntc",
581
6.02k
                        (opcode & 0x0F) ? ", " : "");
582
8.77k
      if (opcode & 0x0C)
583
5.80k
        buf += sprintf (buf, "%s%s",
584
5.80k
                        ((opcode & 0x0C) == 0x0C) ? "c" : "nc",
585
5.80k
                        (opcode & 0x03) ? ", " : "");
586
8.77k
      if (opcode & 0x03)
587
5.98k
        buf += sprintf (buf, "%s",
588
5.98k
                        ((opcode & 0x03) == 0x03) ? "bio" : "nbio");
589
8.77k
    }
590
8.33k
  else
591
8.33k
    buf += sprintf (buf, "unc");
592
593
116k
  return buf - start;
594
116k
}