Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/tic54x-dis.c
Line
Count
Source
1
/* Disassembly routines for TMS320C54X architecture
2
   Copyright (C) 1999-2026 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.15M
{
51
1.15M
  bfd_byte opbuf[2];
52
1.15M
  unsigned short opcode;
53
1.15M
  int status, size;
54
1.15M
  const insn_template* tm;
55
56
1.15M
  status = (*info->read_memory_func) (memaddr, opbuf, 2, info);
57
1.15M
  if (status != 0)
58
132
  {
59
132
    (*info->memory_error_func) (status, memaddr, info);
60
132
    return -1;
61
132
  }
62
63
1.15M
  opcode = bfd_getl16 (opbuf);
64
1.15M
  tm = tic54x_get_insn (info, memaddr, opcode, &size);
65
66
1.15M
  info->bytes_per_line = 2;
67
1.15M
  info->bytes_per_chunk = 2;
68
1.15M
  info->octets_per_byte = 2;
69
1.15M
  info->display_endian = BFD_ENDIAN_LITTLE;
70
71
1.15M
  if (tm->flags & FL_PAR)
72
84.9k
  {
73
84.9k
    if (!print_parallel_instruction (info, memaddr, opcode, tm, size))
74
0
      return -1;
75
84.9k
  }
76
1.07M
  else
77
1.07M
  {
78
1.07M
    if (!print_instruction (info, memaddr, opcode,
79
1.07M
                            (char *) tm->name,
80
1.07M
                            tm->operand_types,
81
1.07M
                            size, (tm->flags & FL_EXT)))
82
139
      return -1;
83
1.07M
  }
84
85
1.15M
  return size * 2;
86
1.15M
}
87
88
static int
89
has_lkaddr (unsigned short memdata, const insn_template *tm)
90
1.08M
{
91
1.08M
  return (IS_LKADDR (memdata)
92
148k
    && (OPTYPE (tm->operand_types[0]) == OP_Smem
93
101k
        || OPTYPE (tm->operand_types[1]) == OP_Smem
94
97.3k
        || OPTYPE (tm->operand_types[2]) == OP_Smem
95
95.5k
        || OPTYPE (tm->operand_types[1]) == OP_Sind
96
94.7k
              || OPTYPE (tm->operand_types[0]) == OP_Lmem
97
91.6k
              || OPTYPE (tm->operand_types[1]) == OP_Lmem));
98
1.08M
}
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.15M
{
106
1.15M
  const insn_template *tm = NULL;
107
108
104M
  for (tm = tic54x_optab; tm->name; tm++)
109
103M
  {
110
103M
    if (tm->opcode == (memdata & tm->mask))
111
1.08M
    {
112
      /* a few opcodes span two words */
113
1.08M
      if (tm->flags & FL_EXT)
114
24.3k
        {
115
          /* if lk addressing is used, the second half of the opcode gets
116
             pushed one word later */
117
24.3k
          bfd_byte opbuf[2];
118
24.3k
          bfd_vma addr2 = addr + 1 + has_lkaddr (memdata, tm);
119
24.3k
          int status = (*info->read_memory_func) (addr2, opbuf, 2, info);
120
          /* FIXME handle errors.  */
121
24.3k
          if (status == 0)
122
24.3k
            {
123
24.3k
              unsigned short data2 = bfd_getl16 (opbuf);
124
24.3k
              if (tm->opcode2 == (data2 & tm->mask2))
125
830
                {
126
830
                  if (size) *size = get_insn_size (memdata, tm);
127
830
                  return tm;
128
830
                }
129
24.3k
            }
130
24.3k
        }
131
1.05M
      else
132
1.05M
        {
133
1.05M
          if (size) *size = get_insn_size (memdata, tm);
134
1.05M
          return tm;
135
1.05M
        }
136
1.08M
    }
137
103M
  }
138
889k
  for (tm = (insn_template *) tic54x_paroptab; tm->name; tm++)
139
874k
  {
140
874k
    if (tm->opcode == (memdata & tm->mask))
141
84.9k
    {
142
84.9k
      if (size) *size = get_insn_size (memdata, tm);
143
84.9k
      return tm;
144
84.9k
    }
145
874k
  }
146
147
15.5k
  if (size) *size = 1;
148
15.5k
  return &tic54x_unknown_opcode;
149
100k
}
150
151
static int
152
get_insn_size (unsigned short memdata, const insn_template *insn)
153
1.14M
{
154
1.14M
  int size;
155
156
1.14M
  if (insn->flags & FL_PAR)
157
84.9k
    {
158
      /* only non-parallel instructions support lk addressing */
159
84.9k
      size = insn->words;
160
84.9k
    }
161
1.05M
  else
162
1.05M
    {
163
1.05M
      size = insn->words + has_lkaddr (memdata, insn);
164
1.05M
    }
165
166
1.14M
  return size;
167
1.14M
}
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.24M
{
178
1.24M
  static int n;
179
  /* string storage for multiple operands */
180
1.24M
  char operand[4][64] = { {0},{0},{0},{0}, };
181
1.24M
  bfd_byte buf[2];
182
1.24M
  unsigned long opcode2 = 0;
183
1.24M
  unsigned long lkaddr = 0;
184
1.24M
  enum optype src = OP_None;
185
1.24M
  enum optype dst = OP_None;
186
1.24M
  int i, shift;
187
1.24M
  char *comma = "";
188
189
1.24M
  info->fprintf_func (info->stream, "%-7s", tm_name);
190
191
1.24M
  if (size > 1)
192
165k
    {
193
165k
      int status = (*info->read_memory_func) (memaddr + 1, buf, 2, info);
194
165k
      if (status != 0)
195
129
        return 0;
196
165k
      lkaddr = opcode2 = bfd_getl16 (buf);
197
165k
      if (size > 2)
198
6.47k
        {
199
6.47k
          status = (*info->read_memory_func) (memaddr + 2, buf, 2, info);
200
6.47k
          if (status != 0)
201
10
            return 0;
202
6.46k
          opcode2 = bfd_getl16 (buf);
203
6.46k
        }
204
165k
    }
205
206
3.94M
  for (i = 0; i < MAX_OPERANDS && OPTYPE (tm_operands[i]) != OP_None; i++)
207
2.70M
    {
208
2.70M
      char *next_comma = ",";
209
2.70M
      int optional = (tm_operands[i] & OPT) != 0;
210
211
2.70M
      switch (OPTYPE (tm_operands[i]))
212
2.70M
        {
213
189k
        case OP_Xmem:
214
189k
          sprint_dual_address (info, operand[i], XMEM (opcode));
215
189k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
216
189k
          break;
217
155k
        case OP_Ymem:
218
155k
          sprint_dual_address (info, operand[i], YMEM (opcode));
219
155k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
220
155k
          break;
221
739k
        case OP_Smem:
222
749k
        case OP_Sind:
223
797k
        case OP_Lmem:
224
797k
          info->fprintf_func (info->stream, "%s", comma);
225
797k
          if (INDIRECT (opcode))
226
152k
            {
227
152k
              if (MOD (opcode) >= 12)
228
54.6k
                {
229
54.6k
                  bfd_vma addr = lkaddr;
230
54.6k
                  int arf = ARF (opcode);
231
54.6k
                  int mod = MOD (opcode);
232
54.6k
                  if (mod == 15)
233
19.2k
                      info->fprintf_func (info->stream, "*(");
234
35.3k
                  else
235
35.3k
                      info->fprintf_func (info->stream, "*%sar%d(",
236
35.3k
                                          (mod == 13 || mod == 14 ? "+" : ""),
237
35.3k
                                          arf);
238
54.6k
                  (*(info->print_address_func)) ((bfd_vma) addr, info);
239
54.6k
                  info->fprintf_func (info->stream, ")%s",
240
54.6k
                                      mod == 14 ? "%" : "");
241
54.6k
                }
242
97.6k
              else
243
97.6k
                {
244
97.6k
                  sprint_indirect_address (info, operand[i], opcode);
245
97.6k
                  info->fprintf_func (info->stream, "%s", operand[i]);
246
97.6k
                }
247
152k
            }
248
644k
          else
249
644k
          {
250
            /* FIXME -- use labels (print_address_func) */
251
            /* in order to do this, we need to guess what DP is */
252
644k
            sprint_direct_address (info, operand[i], opcode);
253
644k
            info->fprintf_func (info->stream, "%s", operand[i]);
254
644k
          }
255
797k
          break;
256
18.0k
        case OP_dmad:
257
18.0k
          info->fprintf_func (info->stream, "%s", comma);
258
18.0k
          (*(info->print_address_func)) ((bfd_vma) opcode2, info);
259
18.0k
          break;
260
5.24k
        case OP_xpmad:
261
          /* upper 7 bits of address are in the opcode */
262
5.24k
          opcode2 += ((unsigned long) opcode & 0x7F) << 16;
263
          /* fall through */
264
32.9k
        case OP_pmad:
265
32.9k
          info->fprintf_func (info->stream, "%s", comma);
266
32.9k
          (*(info->print_address_func)) ((bfd_vma) opcode2, info);
267
32.9k
          break;
268
1.84k
        case OP_MMRX:
269
1.84k
          sprint_mmr (info, operand[i], MMRX (opcode));
270
1.84k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
271
1.84k
          break;
272
1.84k
        case OP_MMRY:
273
1.84k
          sprint_mmr (info, operand[i], MMRY (opcode));
274
1.84k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
275
1.84k
          break;
276
31.6k
        case OP_MMR:
277
31.6k
          sprint_mmr (info, operand[i], MMR (opcode));
278
31.6k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
279
31.6k
          break;
280
9.35k
        case OP_PA:
281
9.35k
          sprintf (operand[i], "pa%d", (unsigned) opcode2);
282
9.35k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
283
9.35k
          break;
284
186k
        case OP_SRC:
285
186k
          src = SRC (ext ? opcode2 : opcode) ? OP_B : OP_A;
286
186k
          sprintf (operand[i], (src == OP_B) ? "b" : "a");
287
186k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
288
186k
          break;
289
568k
        case OP_SRC1:
290
568k
          src = SRC1 (ext ? opcode2 : opcode) ? OP_B : OP_A;
291
568k
          sprintf (operand[i], (src == OP_B) ? "b" : "a");
292
568k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
293
568k
          break;
294
11.8k
        case OP_RND:
295
11.8k
          dst = DST (opcode) ? OP_B : OP_A;
296
11.8k
          sprintf (operand[i], (dst == OP_B) ? "a" : "b");
297
11.8k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
298
11.8k
          break;
299
315k
        case OP_DST:
300
315k
          dst = DST (ext ? opcode2 : opcode) ? OP_B : OP_A;
301
315k
          if (!optional || dst != src)
302
252k
            {
303
252k
              sprintf (operand[i], (dst == OP_B) ? "b" : "a");
304
252k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
305
252k
            }
306
63.4k
          else
307
63.4k
            next_comma = comma;
308
315k
          break;
309
8.94k
        case OP_B:
310
8.94k
          sprintf (operand[i], "b");
311
8.94k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
312
8.94k
          break;
313
247
        case OP_A:
314
247
          sprintf (operand[i], "a");
315
247
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
316
247
          break;
317
354
        case OP_ARX:
318
354
          sprintf (operand[i], "ar%d", (int) ARX (opcode));
319
354
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
320
354
          break;
321
15.0k
        case OP_SHIFT:
322
15.0k
          shift = SHIFT (ext ? opcode2 : opcode);
323
15.0k
          if (!optional || shift != 0)
324
12.1k
            {
325
12.1k
              sprintf (operand[i], "%d", shift);
326
12.1k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
327
12.1k
            }
328
2.90k
          else
329
2.90k
            next_comma = comma;
330
15.0k
          break;
331
22.1k
        case OP_SHFT:
332
22.1k
          shift = SHFT (opcode);
333
22.1k
          if (!optional || shift != 0)
334
21.5k
            {
335
21.5k
              sprintf (operand[i], "%d", (unsigned) shift);
336
21.5k
              info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
337
21.5k
            }
338
567
          else
339
567
            next_comma = comma;
340
22.1k
          break;
341
53.2k
        case OP_lk:
342
53.2k
          sprintf (operand[i], "#%d", (int) (short) opcode2);
343
53.2k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
344
53.2k
          break;
345
9.43k
        case OP_T:
346
9.43k
          sprintf (operand[i], "t");
347
9.43k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
348
9.43k
          break;
349
36.4k
        case OP_TS:
350
36.4k
          sprintf (operand[i], "ts");
351
36.4k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
352
36.4k
          break;
353
2.03k
        case OP_k8:
354
2.03k
          sprintf (operand[i], "%d", (int) ((signed char) (opcode & 0xFF)));
355
2.03k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
356
2.03k
          break;
357
27.2k
        case OP_16:
358
27.2k
          sprintf (operand[i], "16");
359
27.2k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
360
27.2k
          break;
361
14.6k
        case OP_ASM:
362
14.6k
          sprintf (operand[i], "asm");
363
14.6k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
364
14.6k
          break;
365
2.63k
        case OP_BITC:
366
2.63k
          sprintf (operand[i], "%d", (int) (opcode & 0xF));
367
2.63k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
368
2.63k
          break;
369
78.0k
        case OP_CC:
370
          /* put all CC operands in the same operand */
371
78.0k
          sprint_condition (info, operand[i], opcode);
372
78.0k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
373
78.0k
          i = MAX_OPERANDS;
374
78.0k
          break;
375
11.1k
        case OP_CC2:
376
11.1k
          sprint_cc2 (info, operand[i], opcode);
377
11.1k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
378
11.1k
          break;
379
354
        case OP_CC3:
380
354
        {
381
354
          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
354
    sprintf (operand[i], "%s", code[CC3 (opcode)]);
386
354
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
387
354
          break;
388
5.24k
        }
389
397
        case OP_123:
390
397
          {
391
397
            int code = (opcode >> 8) & 0x3;
392
397
            sprintf (operand[i], "%d", (code == 0) ? 1 : (code == 2) ? 2 : 3);
393
397
            info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
394
397
            break;
395
5.24k
          }
396
416
        case OP_k5:
397
416
          sprintf (operand[i], "#%d", ((opcode & 0x1F) ^ 0x10) - 0x10);
398
416
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
399
416
          break;
400
8.09k
        case OP_k8u:
401
8.09k
          sprintf (operand[i], "#%d", (unsigned) (opcode & 0xFF));
402
8.09k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
403
8.09k
          break;
404
135
        case OP_k3:
405
135
          sprintf (operand[i], "#%d", (int) (opcode & 0x7));
406
135
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
407
135
          break;
408
2.41k
        case OP_lku:
409
2.41k
          sprintf (operand[i], "#%d", (unsigned) opcode2);
410
2.41k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
411
2.41k
          break;
412
424
        case OP_N:
413
424
          n = (opcode >> 9) & 0x1;
414
424
          sprintf (operand[i], "st%d", n);
415
424
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
416
424
          break;
417
424
        case OP_SBIT:
418
424
        {
419
424
          const char *status0[] = {
420
424
            "0", "1", "2", "3", "4", "5", "6", "7", "8",
421
424
            "ovb", "ova", "c", "tc", "13", "14", "15"
422
424
          };
423
424
          const char *status1[] = {
424
424
            "0", "1", "2", "3", "4",
425
424
            "cmpt", "frct", "c16", "sxm", "ovm", "10",
426
424
            "intm", "hm", "xf", "cpl", "braf"
427
424
          };
428
424
          sprintf (operand[i], "%s",
429
424
                   n ? status1[SBIT (opcode)] : status0[SBIT (opcode)]);
430
424
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
431
424
          break;
432
5.24k
        }
433
68.7k
        case OP_12:
434
68.7k
          sprintf (operand[i], "%d", (int) ((opcode >> 9) & 1) + 1);
435
68.7k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
436
68.7k
          break;
437
2.87k
        case OP_TRN:
438
2.87k
          sprintf (operand[i], "trn");
439
2.87k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
440
2.87k
          break;
441
11.5k
        case OP_DP:
442
11.5k
          sprintf (operand[i], "dp");
443
11.5k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
444
11.5k
          break;
445
8.48k
        case OP_k9:
446
          /* FIXME-- this is DP, print the original address? */
447
8.48k
          sprintf (operand[i], "#%d", (int) (opcode & 0x1FF));
448
8.48k
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
449
8.48k
          break;
450
135
        case OP_ARP:
451
135
          sprintf (operand[i], "arp");
452
135
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
453
135
          break;
454
291
        case OP_031:
455
291
          sprintf (operand[i], "%d", (int) (opcode & 0x1F));
456
291
          info->fprintf_func (info->stream, "%s%s", comma, operand[i]);
457
291
          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
2.70M
        }
463
2.70M
      comma = next_comma;
464
2.70M
    }
465
1.24M
  return 1;
466
1.24M
}
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
84.9k
{
475
84.9k
  print_instruction (info, memaddr, opcode,
476
84.9k
                     ptm->name, ptm->operand_types, size, 0);
477
84.9k
  info->fprintf_func (info->stream, " || ");
478
84.9k
  return print_instruction (info, memaddr, opcode,
479
84.9k
                            ptm->parname, ptm->paroperand_types, size, 0);
480
84.9k
}
481
482
static int
483
sprint_dual_address (disassemble_info *info ATTRIBUTE_UNUSED,
484
         char buf[],
485
         unsigned short code)
486
344k
{
487
344k
  const char *formats[] = {
488
344k
    "*ar%d",
489
344k
    "*ar%d-",
490
344k
    "*ar%d+",
491
344k
    "*ar%d+0%%",
492
344k
  };
493
344k
  return sprintf (buf, formats[XMOD (code)], XARX (code));
494
344k
}
495
496
static int
497
sprint_indirect_address (disassemble_info *info ATTRIBUTE_UNUSED,
498
       char buf[],
499
       unsigned short opcode)
500
97.6k
{
501
97.6k
  const char *formats[] = {
502
97.6k
    "*ar%d",
503
97.6k
    "*ar%d-",
504
97.6k
    "*ar%d+",
505
97.6k
    "*+ar%d",
506
97.6k
    "*ar%d-0B",
507
97.6k
    "*ar%d-0",
508
97.6k
    "*ar%d+0",
509
97.6k
    "*ar%d+0B",
510
97.6k
    "*ar%d-%%",
511
97.6k
    "*ar%d-0%%",
512
97.6k
    "*ar%d+%%",
513
97.6k
    "*ar%d+0%%",
514
97.6k
  };
515
97.6k
  return sprintf (buf, formats[MOD (opcode)], ARF (opcode));
516
97.6k
}
517
518
static int
519
sprint_direct_address (disassemble_info *info ATTRIBUTE_UNUSED,
520
           char buf[],
521
           unsigned short opcode)
522
644k
{
523
  /* FIXME -- look up relocation if available */
524
644k
  return sprintf (buf, "DP+0x%02x", (int) (opcode & 0x7F));
525
644k
}
526
527
static int
528
sprint_mmr (disassemble_info *info ATTRIBUTE_UNUSED,
529
      char buf[],
530
      int mmr)
531
35.3k
{
532
35.3k
  const tic54x_symbol *reg = tic54x_mmregs;
533
2.94M
  while (reg->name != NULL)
534
2.93M
    {
535
2.93M
      if (mmr == reg->value)
536
17.3k
        {
537
17.3k
          sprintf (buf, "%s", (reg + 1)->name);
538
17.3k
          return 1;
539
17.3k
        }
540
2.91M
      ++reg;
541
2.91M
    }
542
18.0k
  sprintf (buf, "MMR(%d)", mmr); /* FIXME -- different targets.  */
543
18.0k
  return 0;
544
35.3k
}
545
546
static int
547
sprint_cc2 (disassemble_info *info ATTRIBUTE_UNUSED,
548
      char *buf,
549
      unsigned short opcode)
550
11.1k
{
551
11.1k
  const char *cc2[] = {
552
11.1k
    "??", "??", "ageq", "alt", "aneq", "aeq", "agt", "aleq",
553
11.1k
    "??", "??", "bgeq", "blt", "bneq", "beq", "bgt", "bleq",
554
11.1k
  };
555
11.1k
  return sprintf (buf, "%s", cc2[opcode & 0xF]);
556
11.1k
}
557
558
static int
559
sprint_condition (disassemble_info *info ATTRIBUTE_UNUSED,
560
      char *buf,
561
      unsigned short opcode)
562
78.0k
{
563
78.0k
  char *start = buf;
564
78.0k
  const char *cmp[] = {
565
78.0k
      "??", "??", "geq", "lt", "neq", "eq", "gt", "leq"
566
78.0k
  };
567
78.0k
  if (opcode & 0x40)
568
63.0k
    {
569
63.0k
      char acc = (opcode & 0x8) ? 'b' : 'a';
570
63.0k
      if (opcode & 0x7)
571
61.6k
          buf += sprintf (buf, "%c%s%s", acc, cmp[(opcode & 0x7)],
572
61.6k
                          (opcode & 0x20) ? ", " : "");
573
63.0k
      if (opcode & 0x20)
574
59.1k
          buf += sprintf (buf, "%c%s", acc, (opcode & 0x10) ? "ov" : "nov");
575
63.0k
    }
576
14.9k
  else if (opcode & 0x3F)
577
9.03k
    {
578
9.03k
      if (opcode & 0x30)
579
5.96k
        buf += sprintf (buf, "%s%s",
580
5.96k
                        ((opcode & 0x30) == 0x30) ? "tc" : "ntc",
581
5.96k
                        (opcode & 0x0F) ? ", " : "");
582
9.03k
      if (opcode & 0x0C)
583
5.49k
        buf += sprintf (buf, "%s%s",
584
5.49k
                        ((opcode & 0x0C) == 0x0C) ? "c" : "nc",
585
5.49k
                        (opcode & 0x03) ? ", " : "");
586
9.03k
      if (opcode & 0x03)
587
6.96k
        buf += sprintf (buf, "%s",
588
6.96k
                        ((opcode & 0x03) == 0x03) ? "bio" : "nbio");
589
9.03k
    }
590
5.89k
  else
591
5.89k
    buf += sprintf (buf, "unc");
592
593
78.0k
  return buf - start;
594
78.0k
}