Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/tic30-dis.c
Line
Count
Source
1
/* Disassembly routines for TMS320C30 architecture
2
   Copyright (C) 1998-2026 Free Software Foundation, Inc.
3
   Contributed by Steven Haworth (steve@pm.cse.rmit.edu.au)
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 "disassemble.h"
26
#include "opcode/tic30.h"
27
28
23.5k
#define NORMAL_INSN   1
29
14.4k
#define PARALLEL_INSN 2
30
31
/* Gets the type of instruction based on the top 2 or 3 bits of the
32
   instruction word.  */
33
3.36M
#define GET_TYPE(insn) (insn & 0x80000000 ? insn & 0xC0000000 : insn & 0xE0000000)
34
35
/* Instruction types.  */
36
32.6k
#define TWO_OPERAND_1 0x00000000
37
35.2k
#define TWO_OPERAND_2 0x40000000
38
24.4k
#define THREE_OPERAND 0x20000000
39
22.3k
#define PAR_STORE     0xC0000000
40
17.8k
#define MUL_ADDS      0x80000000
41
5.04k
#define BRANCHES      0x60000000
42
43
/* Specific instruction id bits.  */
44
254k
#define NORMAL_IDEN    0x1F800000
45
364k
#define PAR_STORE_IDEN 0x3E000000
46
19.8k
#define MUL_ADD_IDEN   0x2C000000
47
12.2k
#define BR_IMM_IDEN    0x1F000000
48
537k
#define BR_COND_IDEN   0x1C3F0000
49
50
/* Addressing modes.  */
51
13.0k
#define AM_REGISTER 0x00000000
52
2.56k
#define AM_DIRECT   0x00200000
53
2.05k
#define AM_INDIRECT 0x00400000
54
2.72k
#define AM_IMM      0x00600000
55
56
3.29k
#define P_FIELD 0x03000000
57
58
716
#define REG_AR0 0x08
59
2.63k
#define LDP_INSN 0x08700000
60
61
/* TMS320C30 program counter for current instruction.  */
62
static unsigned int _pc;
63
64
struct instruction
65
{
66
  int type;
67
  insn_template *tm;
68
  partemplate *ptm;
69
};
70
71
static int
72
get_tic30_instruction (unsigned long insn_word, struct instruction *insn)
73
38.0k
{
74
38.0k
  switch (GET_TYPE (insn_word))
75
38.0k
    {
76
16.3k
    case TWO_OPERAND_1:
77
17.6k
    case TWO_OPERAND_2:
78
21.0k
    case THREE_OPERAND:
79
21.0k
      insn->type = NORMAL_INSN;
80
21.0k
      {
81
21.0k
  insn_template *current_optab = (insn_template *) tic30_optab;
82
83
995k
  for (; current_optab < tic30_optab_end; current_optab++)
84
995k
    {
85
995k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
86
131k
        {
87
131k
    if (current_optab->operands == 0)
88
3.86k
      {
89
3.86k
        if (current_optab->base_opcode == insn_word)
90
138
          {
91
138
      insn->tm = current_optab;
92
138
      break;
93
138
          }
94
3.86k
      }
95
127k
    else if ((current_optab->base_opcode & NORMAL_IDEN) == (insn_word & NORMAL_IDEN))
96
20.5k
      {
97
20.5k
        insn->tm = current_optab;
98
20.5k
        break;
99
20.5k
      }
100
131k
        }
101
995k
    }
102
21.0k
      }
103
21.0k
      break;
104
105
11.1k
    case PAR_STORE:
106
11.1k
      insn->type = PARALLEL_INSN;
107
11.1k
      {
108
11.1k
  partemplate *current_optab = (partemplate *) tic30_paroptab;
109
110
205k
  for (; current_optab < tic30_paroptab_end; current_optab++)
111
205k
    {
112
205k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
113
182k
        {
114
182k
    if ((current_optab->base_opcode & PAR_STORE_IDEN)
115
182k
        == (insn_word & PAR_STORE_IDEN))
116
11.1k
      {
117
11.1k
        insn->ptm = current_optab;
118
11.1k
        break;
119
11.1k
      }
120
182k
        }
121
205k
    }
122
11.1k
      }
123
11.1k
      break;
124
125
3.32k
    case MUL_ADDS:
126
3.32k
      insn->type = PARALLEL_INSN;
127
3.32k
      {
128
3.32k
  partemplate *current_optab = (partemplate *) tic30_paroptab;
129
130
57.1k
  for (; current_optab < tic30_paroptab_end; current_optab++)
131
57.1k
    {
132
57.1k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
133
9.92k
        {
134
9.92k
    if ((current_optab->base_opcode & MUL_ADD_IDEN)
135
9.92k
        == (insn_word & MUL_ADD_IDEN))
136
3.29k
      {
137
3.29k
        insn->ptm = current_optab;
138
3.29k
        break;
139
3.29k
      }
140
9.92k
        }
141
57.1k
    }
142
3.32k
      }
143
3.32k
      break;
144
145
2.52k
    case BRANCHES:
146
2.52k
      insn->type = NORMAL_INSN;
147
2.52k
      {
148
2.52k
  insn_template *current_optab = (insn_template *) tic30_optab;
149
150
387k
  for (; current_optab < tic30_optab_end; current_optab++)
151
386k
    {
152
386k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
153
274k
        {
154
274k
    if (current_optab->operand_types[0] & Imm24)
155
6.11k
      {
156
6.11k
        if ((current_optab->base_opcode & BR_IMM_IDEN)
157
6.11k
      == (insn_word & BR_IMM_IDEN))
158
646
          {
159
646
      insn->tm = current_optab;
160
646
      break;
161
646
          }
162
6.11k
      }
163
268k
    else if (current_optab->operands > 0)
164
233k
      {
165
233k
        if ((current_optab->base_opcode & BR_COND_IDEN)
166
233k
      == (insn_word & BR_COND_IDEN))
167
1.56k
          {
168
1.56k
      insn->tm = current_optab;
169
1.56k
      break;
170
1.56k
          }
171
233k
      }
172
35.2k
    else
173
35.2k
      {
174
35.2k
        if ((current_optab->base_opcode & (BR_COND_IDEN | 0x00800000))
175
35.2k
      == (insn_word & (BR_COND_IDEN | 0x00800000)))
176
134
          {
177
134
      insn->tm = current_optab;
178
134
      break;
179
134
          }
180
35.2k
      }
181
274k
        }
182
386k
    }
183
2.52k
      }
184
2.52k
      break;
185
0
    default:
186
0
      return 0;
187
38.0k
    }
188
38.0k
  return 1;
189
38.0k
}
190
191
392k
#define OPERAND_BUFFER_LEN 15
192
193
static int
194
get_register_operand (unsigned char fragment, char *buffer)
195
77.3k
{
196
77.3k
  const reg *current_reg = tic30_regtab;
197
198
77.3k
  if (buffer == NULL)
199
0
    return 0;
200
451k
  for (; current_reg < tic30_regtab_end; current_reg++)
201
449k
    {
202
449k
      if ((fragment & 0x1F) == current_reg->opcode)
203
75.6k
  {
204
75.6k
    strncpy (buffer, current_reg->name, OPERAND_BUFFER_LEN - 1);
205
75.6k
    buffer[OPERAND_BUFFER_LEN - 1] = 0;
206
75.6k
    return 1;
207
75.6k
  }
208
449k
    }
209
1.70k
  return 0;
210
77.3k
}
211
212
static int
213
get_indirect_operand (unsigned short fragment,
214
          int size,
215
          char *buffer)
216
32.7k
{
217
32.7k
  unsigned char mod;
218
32.7k
  unsigned arnum;
219
32.7k
  unsigned char disp;
220
221
32.7k
  if (buffer == NULL)
222
0
    return 0;
223
  /* Determine which bits identify the sections of the indirect
224
     operand based on the size in bytes.  */
225
32.7k
  switch (size)
226
32.7k
    {
227
31.3k
    case 1:
228
31.3k
      mod = (fragment & 0x00F8) >> 3;
229
31.3k
      arnum = (fragment & 0x0007);
230
31.3k
      disp = 0;
231
31.3k
      break;
232
1.40k
    case 2:
233
1.40k
      mod = (fragment & 0xF800) >> 11;
234
1.40k
      arnum = (fragment & 0x0700) >> 8;
235
1.40k
      disp = (fragment & 0x00FF);
236
1.40k
      break;
237
0
    default:
238
0
      return 0;
239
32.7k
    }
240
32.7k
  {
241
32.7k
    const ind_addr_type *current_ind = tic30_indaddr_tab;
242
243
870k
    for (; current_ind < tic30_indaddrtab_end; current_ind++)
244
859k
      {
245
859k
  if (current_ind->modfield == mod)
246
22.6k
    {
247
22.6k
      if (current_ind->displacement == IMPLIED_DISP && size == 2)
248
202
        continue;
249
250
22.4k
      else
251
22.4k
        {
252
22.4k
    size_t i, len;
253
22.4k
    int bufcnt;
254
255
22.4k
    len = strlen (current_ind->syntax);
256
257
154k
    for (i = 0, bufcnt = 0; i < len; i++, bufcnt++)
258
131k
      {
259
131k
        buffer[bufcnt] = current_ind->syntax[i];
260
261
131k
        if (bufcnt > 0
262
109k
      && bufcnt < OPERAND_BUFFER_LEN - 1
263
109k
      && buffer[bufcnt - 1] == 'a'
264
22.4k
      && buffer[bufcnt] == 'r')
265
22.4k
          buffer[++bufcnt] = arnum + '0';
266
        
267
131k
        if (bufcnt < OPERAND_BUFFER_LEN - 1
268
131k
      && buffer[bufcnt] == '('
269
8.42k
      && current_ind->displacement == DISP_REQUIRED)
270
202
          {
271
202
      snprintf (buffer + (bufcnt + 1),
272
202
         OPERAND_BUFFER_LEN - (bufcnt + 1),
273
202
         "%u", disp);
274
202
      bufcnt += strlen (buffer + (bufcnt + 1));
275
202
          }
276
131k
      }
277
22.4k
    buffer[bufcnt + 1] = '\0';
278
22.4k
    break;
279
22.4k
        }
280
22.6k
    }
281
859k
      }
282
32.7k
  }
283
32.7k
  return 1;
284
32.7k
}
285
286
static int
287
cnvt_tmsfloat_ieee (unsigned long tmsfloat, int size, float *ieeefloat)
288
2.42k
{
289
2.42k
  unsigned long exponent, sign, mant;
290
2.42k
  union
291
2.42k
  {
292
2.42k
    unsigned long l;
293
2.42k
    float f;
294
2.42k
  } val;
295
296
2.42k
  if (size == 2)
297
2.42k
    {
298
2.42k
      if ((tmsfloat & 0x0000F000) == 0x00008000)
299
59
  tmsfloat = 0x80000000;
300
2.36k
      else
301
2.36k
  {
302
2.36k
    tmsfloat <<= 16;
303
2.36k
    tmsfloat = (long) tmsfloat >> 4;
304
2.36k
  }
305
2.42k
    }
306
2.42k
  exponent = tmsfloat & 0xFF000000;
307
2.42k
  if (exponent == 0x80000000)
308
59
    {
309
59
      *ieeefloat = 0.0;
310
59
      return 1;
311
59
    }
312
2.36k
  exponent += 0x7F000000;
313
2.36k
  sign = (tmsfloat & 0x00800000) << 8;
314
2.36k
  mant = tmsfloat & 0x007FFFFF;
315
2.36k
  if (exponent == 0xFF000000)
316
0
    {
317
0
      if (mant == 0)
318
0
  *ieeefloat = ERANGE;
319
0
#ifdef HUGE_VALF
320
0
      if (sign == 0)
321
0
  *ieeefloat = HUGE_VALF;
322
0
      else
323
0
  *ieeefloat = -HUGE_VALF;
324
#else
325
      if (sign == 0)
326
  *ieeefloat = 1.0 / 0.0;
327
      else
328
  *ieeefloat = -1.0 / 0.0;
329
#endif
330
0
      return 1;
331
0
    }
332
2.36k
  exponent >>= 1;
333
2.36k
  if (sign)
334
127
    {
335
127
      mant = (~mant) & 0x007FFFFF;
336
127
      mant += 1;
337
127
      exponent += mant & 0x00800000;
338
127
      exponent &= 0x7F800000;
339
127
      mant &= 0x007FFFFF;
340
127
    }
341
2.36k
  if (tmsfloat == 0x80000000)
342
0
    sign = mant = exponent = 0;
343
2.36k
  tmsfloat = sign | exponent | mant;
344
2.36k
  val.l = tmsfloat;
345
2.36k
  *ieeefloat = val.f;
346
2.36k
  return 1;
347
2.36k
}
348
349
static int
350
print_two_operand (disassemble_info *info,
351
       unsigned long insn_word,
352
       struct instruction *insn)
353
17.6k
{
354
17.6k
  char name[12];
355
17.6k
  char operand[2][OPERAND_BUFFER_LEN] =
356
17.6k
  {
357
17.6k
    {0},
358
17.6k
    {0}
359
17.6k
  };
360
17.6k
  float f_number;
361
362
17.6k
  if (insn->tm == NULL)
363
81
    return 0;
364
17.5k
  strcpy (name, insn->tm->name);
365
17.5k
  if (insn->tm->opcode_modifier == AddressMode)
366
17.2k
    {
367
17.2k
      int src_op, dest_op;
368
      /* Determine whether instruction is a store or a normal instruction.  */
369
17.2k
      if ((insn->tm->operand_types[1] & (Direct | Indirect))
370
17.2k
    == (Direct | Indirect))
371
191
  {
372
191
    src_op = 1;
373
191
    dest_op = 0;
374
191
  }
375
17.1k
      else
376
17.1k
  {
377
17.1k
    src_op = 0;
378
17.1k
    dest_op = 1;
379
17.1k
  }
380
      /* Get the destination register.  */
381
17.2k
      if (insn->tm->operands == 2)
382
17.1k
  get_register_operand ((insn_word & 0x001F0000) >> 16, operand[dest_op]);
383
      /* Get the source operand based on addressing mode.  */
384
17.2k
      switch (insn_word & AddressMode)
385
17.2k
  {
386
12.4k
  case AM_REGISTER:
387
    /* Check for the NOP instruction before getting the operand.  */
388
12.4k
    if ((insn->tm->operand_types[0] & NotReq) == 0)
389
12.4k
      get_register_operand ((insn_word & 0x0000001F), operand[src_op]);
390
12.4k
    break;
391
824
  case AM_DIRECT:
392
824
    sprintf (operand[src_op], "@0x%lX", (insn_word & 0x0000FFFF));
393
824
    break;
394
1.40k
  case AM_INDIRECT:
395
1.40k
    get_indirect_operand ((insn_word & 0x0000FFFF), 2, operand[src_op]);
396
1.40k
    break;
397
2.63k
  case AM_IMM:
398
    /* Get the value of the immediate operand based on variable type.  */
399
2.63k
    switch (insn->tm->imm_arg_type)
400
2.63k
      {
401
2.42k
      case Imm_Float:
402
2.42k
        cnvt_tmsfloat_ieee ((insn_word & 0x0000FFFF), 2, &f_number);
403
2.42k
        sprintf (operand[src_op], "%2.2f", f_number);
404
2.42k
        break;
405
179
      case Imm_SInt:
406
179
        sprintf (operand[src_op], "%d", (short) (insn_word & 0x0000FFFF));
407
179
        break;
408
33
      case Imm_UInt:
409
33
        sprintf (operand[src_op], "%lu", (insn_word & 0x0000FFFF));
410
33
        break;
411
2
      default:
412
2
        return 0;
413
2.63k
      }
414
    /* Handle special case for LDP instruction.  */
415
2.63k
    if ((insn_word & 0xFFFFFF00) == LDP_INSN)
416
0
      {
417
0
        strcpy (name, "ldp");
418
0
        sprintf (operand[0], "0x%06lX", (insn_word & 0x000000FF) << 16);
419
0
        operand[1][0] = '\0';
420
0
      }
421
17.2k
  }
422
17.2k
    }
423
  /* Handle case for stack and rotate instructions.  */
424
271
  else if (insn->tm->operands == 1)
425
133
    {
426
133
      if (insn->tm->opcode_modifier == StackOp)
427
133
  get_register_operand ((insn_word & 0x001F0000) >> 16, operand[0]);
428
133
    }
429
  /* Output instruction to stream.  */
430
17.5k
  info->fprintf_func (info->stream, "   %s %s%c%s", name,
431
17.5k
          operand[0][0] ? operand[0] : "",
432
17.5k
          operand[1][0] ? ',' : ' ',
433
17.5k
          operand[1][0] ? operand[1] : "");
434
17.5k
  return 1;
435
17.5k
}
436
437
static int
438
print_three_operand (disassemble_info *info,
439
         unsigned long insn_word,
440
         struct instruction *insn)
441
3.41k
{
442
3.41k
  char operand[3][OPERAND_BUFFER_LEN] =
443
3.41k
  {
444
3.41k
    {0},
445
3.41k
    {0},
446
3.41k
    {0}
447
3.41k
  };
448
449
3.41k
  if (insn->tm == NULL)
450
310
    return 0;
451
3.10k
  switch (insn_word & AddressMode)
452
3.10k
    {
453
632
    case AM_REGISTER:
454
632
      get_register_operand ((insn_word & 0x000000FF), operand[0]);
455
632
      get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
456
632
      break;
457
1.74k
    case AM_DIRECT:
458
1.74k
      get_register_operand ((insn_word & 0x000000FF), operand[0]);
459
1.74k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
460
1.74k
      break;
461
643
    case AM_INDIRECT:
462
643
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
463
643
      get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
464
643
      break;
465
85
    case AM_IMM:
466
85
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
467
85
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
468
85
      break;
469
0
    default:
470
0
      return 0;
471
3.10k
    }
472
3.10k
  if (insn->tm->operands == 3)
473
1.79k
    get_register_operand ((insn_word & 0x001F0000) >> 16, operand[2]);
474
3.10k
  info->fprintf_func (info->stream, "   %s %s,%s%c%s", insn->tm->name,
475
3.10k
          operand[0], operand[1],
476
3.10k
          operand[2][0] ? ',' : ' ',
477
3.10k
          operand[2][0] ? operand[2] : "");
478
3.10k
  return 1;
479
3.10k
}
480
481
static int
482
print_par_insn (disassemble_info *info,
483
    unsigned long insn_word,
484
    struct instruction *insn)
485
14.4k
{
486
14.4k
  size_t i, len;
487
14.4k
  char *name1, *name2;
488
14.4k
  char operand[2][3][OPERAND_BUFFER_LEN] =
489
14.4k
  {
490
14.4k
    {
491
14.4k
      {0},
492
14.4k
      {0},
493
14.4k
      {0}
494
14.4k
    },
495
14.4k
    {
496
14.4k
      {0},
497
14.4k
      {0},
498
14.4k
      {0}
499
14.4k
    }
500
14.4k
  };
501
502
14.4k
  if (insn->ptm == NULL)
503
91
    return 0;
504
  /* Parse out the names of each of the parallel instructions from the
505
     q_insn1_insn2 format.  */
506
14.3k
  name1 = (char *) strdup (insn->ptm->name + 2);
507
14.3k
  name2 = "";
508
14.3k
  len = strlen (name1);
509
68.5k
  for (i = 0; i < len; i++)
510
68.5k
    {
511
68.5k
      if (name1[i] == '_')
512
14.3k
  {
513
14.3k
    name2 = &name1[i + 1];
514
14.3k
    name1[i] = '\0';
515
14.3k
    break;
516
14.3k
  }
517
68.5k
    }
518
  /* Get the operands of the instruction based on the operand order.  */
519
14.3k
  switch (insn->ptm->oporder)
520
14.3k
    {
521
1.03k
    case OO_4op1:
522
1.03k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
523
1.03k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
524
1.03k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
525
1.03k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
526
1.03k
      break;
527
474
    case OO_4op2:
528
474
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
529
474
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
530
474
      get_register_operand ((insn_word >> 19) & 0x07, operand[1][1]);
531
474
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
532
474
      break;
533
4.28k
    case OO_4op3:
534
4.28k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
535
4.28k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
536
4.28k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
537
4.28k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][0]);
538
4.28k
      break;
539
1.31k
    case OO_5op1:
540
1.31k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
541
1.31k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
542
1.31k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
543
1.31k
      get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
544
1.31k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
545
1.31k
      break;
546
4.00k
    case OO_5op2:
547
4.00k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
548
4.00k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
549
4.00k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
550
4.00k
      get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
551
4.00k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
552
4.00k
      break;
553
3.29k
    case OO_PField:
554
3.29k
      if (insn_word & 0x00800000)
555
2.99k
  get_register_operand (0x01, operand[0][2]);
556
297
      else
557
297
  get_register_operand (0x00, operand[0][2]);
558
3.29k
      if (insn_word & 0x00400000)
559
208
  get_register_operand (0x03, operand[1][2]);
560
3.08k
      else
561
3.08k
  get_register_operand (0x02, operand[1][2]);
562
3.29k
      switch (insn_word & P_FIELD)
563
3.29k
  {
564
810
  case 0x00000000:
565
810
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
566
810
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
567
810
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
568
810
    get_register_operand ((insn_word >> 19) & 0x07, operand[1][0]);
569
810
    break;
570
2.10k
  case 0x01000000:
571
2.10k
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][0]);
572
2.10k
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
573
2.10k
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
574
2.10k
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
575
2.10k
    break;
576
166
  case 0x02000000:
577
166
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
578
166
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
579
166
    get_register_operand ((insn_word >> 16) & 0x07, operand[0][1]);
580
166
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
581
166
    break;
582
213
  case 0x03000000:
583
213
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
584
213
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
585
213
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
586
213
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
587
213
    break;
588
3.29k
  }
589
3.29k
      break;
590
3.29k
    default:
591
0
      return 0;
592
14.3k
    }
593
14.3k
  info->fprintf_func (info->stream, "   %s %s,%s%c%s", name1,
594
14.3k
          operand[0][0], operand[0][1],
595
14.3k
          operand[0][2][0] ? ',' : ' ',
596
14.3k
          operand[0][2][0] ? operand[0][2] : "");
597
14.3k
  info->fprintf_func (info->stream, "\n\t\t\t|| %s %s,%s%c%s", name2,
598
14.3k
          operand[1][0], operand[1][1],
599
14.3k
          operand[1][2][0] ? ',' : ' ',
600
14.3k
          operand[1][2][0] ? operand[1][2] : "");
601
14.3k
  free (name1);
602
14.3k
  return 1;
603
14.3k
}
604
605
static int
606
print_branch (disassemble_info *info,
607
        unsigned long insn_word,
608
        struct instruction *insn)
609
2.52k
{
610
2.52k
  char operand[2][OPERAND_BUFFER_LEN] =
611
2.52k
  {
612
2.52k
    {0},
613
2.52k
    {0}
614
2.52k
  };
615
2.52k
  unsigned long address;
616
2.52k
  int print_label = 0;
617
618
2.52k
  if (insn->tm == NULL)
619
175
    return 0;
620
  /* Get the operands for 24-bit immediate jumps.  */
621
2.34k
  if (insn->tm->operand_types[0] & Imm24)
622
646
    {
623
646
      address = insn_word & 0x00FFFFFF;
624
646
      sprintf (operand[0], "0x%lX", address);
625
646
      print_label = 1;
626
646
    }
627
  /* Get the operand for the trap instruction.  */
628
1.70k
  else if (insn->tm->operand_types[0] & IVector)
629
186
    {
630
186
      address = insn_word & 0x0000001F;
631
186
      sprintf (operand[0], "0x%lX", address);
632
186
    }
633
1.51k
  else
634
1.51k
    {
635
1.51k
      address = insn_word & 0x0000FFFF;
636
      /* Get the operands for the DB instructions.  */
637
1.51k
      if (insn->tm->operands == 2)
638
716
  {
639
716
    get_register_operand (((insn_word & 0x01C00000) >> 22) + REG_AR0, operand[0]);
640
716
    if (insn_word & PCRel)
641
267
      {
642
267
        sprintf (operand[1], "%d", (short) address);
643
267
        print_label = 1;
644
267
      }
645
449
    else
646
449
      get_register_operand (insn_word & 0x0000001F, operand[1]);
647
716
  }
648
      /* Get the operands for the standard branches.  */
649
798
      else if (insn->tm->operands == 1)
650
664
  {
651
664
    if (insn_word & PCRel)
652
301
      {
653
301
        address = (short) address;
654
301
        sprintf (operand[0], "%ld", address);
655
301
        print_label = 1;
656
301
      }
657
363
    else
658
363
      get_register_operand (insn_word & 0x0000001F, operand[0]);
659
664
  }
660
1.51k
    }
661
2.34k
  info->fprintf_func (info->stream, "   %s %s%c%s", insn->tm->name,
662
2.34k
          operand[0][0] ? operand[0] : "",
663
2.34k
          operand[1][0] ? ',' : ' ',
664
2.34k
          operand[1][0] ? operand[1] : "");
665
  /* Print destination of branch in relation to current symbol.  */
666
2.34k
  if (print_label && info->symbols)
667
0
    {
668
0
      asymbol *sym = *info->symbols;
669
670
0
      if ((insn->tm->opcode_modifier == PCRel) && (insn_word & PCRel))
671
0
  {
672
0
    address = (_pc + 1 + (short) address) - ((sym->section->vma + sym->value) / 4);
673
    /* Check for delayed instruction, if so adjust destination.  */
674
0
    if (insn_word & 0x00200000)
675
0
      address += 2;
676
0
  }
677
0
      else
678
0
  {
679
0
    address -= ((sym->section->vma + sym->value) / 4);
680
0
  }
681
0
      if (address == 0)
682
0
  info->fprintf_func (info->stream, " <%s>", sym->name);
683
0
      else
684
0
  info->fprintf_func (info->stream, " <%s %c %lu>", sym->name,
685
0
          ((short) address < 0) ? '-' : '+',
686
0
          address);
687
0
    }
688
2.34k
  return 1;
689
2.52k
}
690
691
int
692
print_insn_tic30 (bfd_vma pc, disassemble_info *info)
693
38.2k
{
694
38.2k
  unsigned long insn_word;
695
38.2k
  struct instruction insn = { 0, NULL, NULL };
696
38.2k
  bfd_vma bufaddr = pc - info->buffer_vma;
697
698
38.2k
  if (bufaddr + 3 >= info->buffer_length)
699
145
    return -1;
700
701
  /* Obtain the current instruction word from the buffer.  */
702
38.0k
  insn_word = (((unsigned) *(info->buffer + bufaddr) << 24)
703
38.0k
         | (*(info->buffer + bufaddr + 1) << 16)
704
38.0k
         | (*(info->buffer + bufaddr + 2) << 8)
705
38.0k
         | *(info->buffer + bufaddr + 3));
706
38.0k
  _pc = pc / 4;
707
  /* Get the instruction referred to by the current instruction word
708
     and print it out based on its type.  */
709
38.0k
  if (!get_tic30_instruction (insn_word, &insn))
710
0
    return -1;
711
38.0k
  switch (GET_TYPE (insn_word))
712
38.0k
    {
713
16.3k
    case TWO_OPERAND_1:
714
17.6k
    case TWO_OPERAND_2:
715
17.6k
      if (!print_two_operand (info, insn_word, &insn))
716
83
  return -1;
717
17.5k
      break;
718
17.5k
    case THREE_OPERAND:
719
3.41k
      if (!print_three_operand (info, insn_word, &insn))
720
310
  return -1;
721
3.10k
      break;
722
11.1k
    case PAR_STORE:
723
14.4k
    case MUL_ADDS:
724
14.4k
      if (!print_par_insn (info, insn_word, &insn))
725
91
  return -1;
726
14.3k
      break;
727
14.3k
    case BRANCHES:
728
2.52k
      if (!print_branch (info, insn_word, &insn))
729
175
  return -1;
730
2.34k
      break;
731
38.0k
    }
732
37.4k
  return 4;
733
38.0k
}