Coverage Report

Created: 2026-04-04 08:16

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
24.6k
#define NORMAL_INSN   1
29
13.3k
#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.51M
#define GET_TYPE(insn) (insn & 0x80000000 ? insn & 0xC0000000 : insn & 0xE0000000)
34
35
/* Instruction types.  */
36
34.6k
#define TWO_OPERAND_1 0x00000000
37
38.7k
#define TWO_OPERAND_2 0x40000000
38
25.4k
#define THREE_OPERAND 0x20000000
39
19.5k
#define PAR_STORE     0xC0000000
40
16.9k
#define MUL_ADDS      0x80000000
41
4.48k
#define BRANCHES      0x60000000
42
43
/* Specific instruction id bits.  */
44
297k
#define NORMAL_IDEN    0x1F800000
45
307k
#define PAR_STORE_IDEN 0x3E000000
46
20.9k
#define MUL_ADD_IDEN   0x2C000000
47
10.9k
#define BR_IMM_IDEN    0x1F000000
48
503k
#define BR_COND_IDEN   0x1C3F0000
49
50
/* Addressing modes.  */
51
14.3k
#define AM_REGISTER 0x00000000
52
2.42k
#define AM_DIRECT   0x00200000
53
2.75k
#define AM_INDIRECT 0x00400000
54
2.17k
#define AM_IMM      0x00600000
55
56
3.51k
#define P_FIELD 0x03000000
57
58
624
#define REG_AR0 0x08
59
2.07k
#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
37.9k
{
74
37.9k
  switch (GET_TYPE (insn_word))
75
37.9k
    {
76
17.3k
    case TWO_OPERAND_1:
77
19.3k
    case TWO_OPERAND_2:
78
22.3k
    case THREE_OPERAND:
79
22.3k
      insn->type = NORMAL_INSN;
80
22.3k
      {
81
22.3k
  insn_template *current_optab = (insn_template *) tic30_optab;
82
83
1.12M
  for (; current_optab < tic30_optab_end; current_optab++)
84
1.12M
    {
85
1.12M
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
86
152k
        {
87
152k
    if (current_optab->operands == 0)
88
3.99k
      {
89
3.99k
        if (current_optab->base_opcode == insn_word)
90
193
          {
91
193
      insn->tm = current_optab;
92
193
      break;
93
193
          }
94
3.99k
      }
95
148k
    else if ((current_optab->base_opcode & NORMAL_IDEN) == (insn_word & NORMAL_IDEN))
96
21.8k
      {
97
21.8k
        insn->tm = current_optab;
98
21.8k
        break;
99
21.8k
      }
100
152k
        }
101
1.12M
    }
102
22.3k
      }
103
22.3k
      break;
104
105
9.78k
    case PAR_STORE:
106
9.78k
      insn->type = PARALLEL_INSN;
107
9.78k
      {
108
9.78k
  partemplate *current_optab = (partemplate *) tic30_paroptab;
109
110
172k
  for (; current_optab < tic30_paroptab_end; current_optab++)
111
172k
    {
112
172k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
113
153k
        {
114
153k
    if ((current_optab->base_opcode & PAR_STORE_IDEN)
115
153k
        == (insn_word & PAR_STORE_IDEN))
116
9.70k
      {
117
9.70k
        insn->ptm = current_optab;
118
9.70k
        break;
119
9.70k
      }
120
153k
        }
121
172k
    }
122
9.78k
      }
123
9.78k
      break;
124
125
3.55k
    case MUL_ADDS:
126
3.55k
      insn->type = PARALLEL_INSN;
127
3.55k
      {
128
3.55k
  partemplate *current_optab = (partemplate *) tic30_paroptab;
129
130
61.1k
  for (; current_optab < tic30_paroptab_end; current_optab++)
131
61.1k
    {
132
61.1k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
133
10.4k
        {
134
10.4k
    if ((current_optab->base_opcode & MUL_ADD_IDEN)
135
10.4k
        == (insn_word & MUL_ADD_IDEN))
136
3.51k
      {
137
3.51k
        insn->ptm = current_optab;
138
3.51k
        break;
139
3.51k
      }
140
10.4k
        }
141
61.1k
    }
142
3.55k
      }
143
3.55k
      break;
144
145
2.24k
    case BRANCHES:
146
2.24k
      insn->type = NORMAL_INSN;
147
2.24k
      {
148
2.24k
  insn_template *current_optab = (insn_template *) tic30_optab;
149
150
365k
  for (; current_optab < tic30_optab_end; current_optab++)
151
364k
    {
152
364k
      if (GET_TYPE (current_optab->base_opcode) == GET_TYPE (insn_word))
153
257k
        {
154
257k
    if (current_optab->operand_types[0] & Imm24)
155
5.46k
      {
156
5.46k
        if ((current_optab->base_opcode & BR_IMM_IDEN)
157
5.46k
      == (insn_word & BR_IMM_IDEN))
158
515
          {
159
515
      insn->tm = current_optab;
160
515
      break;
161
515
          }
162
5.46k
      }
163
251k
    else if (current_optab->operands > 0)
164
216k
      {
165
216k
        if ((current_optab->base_opcode & BR_COND_IDEN)
166
216k
      == (insn_word & BR_COND_IDEN))
167
1.38k
          {
168
1.38k
      insn->tm = current_optab;
169
1.38k
      break;
170
1.38k
          }
171
216k
      }
172
34.7k
    else
173
34.7k
      {
174
34.7k
        if ((current_optab->base_opcode & (BR_COND_IDEN | 0x00800000))
175
34.7k
      == (insn_word & (BR_COND_IDEN | 0x00800000)))
176
157
          {
177
157
      insn->tm = current_optab;
178
157
      break;
179
157
          }
180
34.7k
      }
181
257k
        }
182
364k
    }
183
2.24k
      }
184
2.24k
      break;
185
0
    default:
186
0
      return 0;
187
37.9k
    }
188
37.9k
  return 1;
189
37.9k
}
190
191
395k
#define OPERAND_BUFFER_LEN 15
192
193
static int
194
get_register_operand (unsigned char fragment, char *buffer)
195
76.6k
{
196
76.6k
  const reg *current_reg = tic30_regtab;
197
198
76.6k
  if (buffer == NULL)
199
0
    return 0;
200
431k
  for (; current_reg < tic30_regtab_end; current_reg++)
201
429k
    {
202
429k
      if ((fragment & 0x1F) == current_reg->opcode)
203
75.2k
  {
204
75.2k
    strncpy (buffer, current_reg->name, OPERAND_BUFFER_LEN - 1);
205
75.2k
    buffer[OPERAND_BUFFER_LEN - 1] = 0;
206
75.2k
    return 1;
207
75.2k
  }
208
429k
    }
209
1.41k
  return 0;
210
76.6k
}
211
212
static int
213
get_indirect_operand (unsigned short fragment,
214
          int size,
215
          char *buffer)
216
30.8k
{
217
30.8k
  unsigned char mod;
218
30.8k
  unsigned arnum;
219
30.8k
  unsigned char disp;
220
221
30.8k
  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
30.8k
  switch (size)
226
30.8k
    {
227
28.7k
    case 1:
228
28.7k
      mod = (fragment & 0x00F8) >> 3;
229
28.7k
      arnum = (fragment & 0x0007);
230
28.7k
      disp = 0;
231
28.7k
      break;
232
2.07k
    case 2:
233
2.07k
      mod = (fragment & 0xF800) >> 11;
234
2.07k
      arnum = (fragment & 0x0700) >> 8;
235
2.07k
      disp = (fragment & 0x00FF);
236
2.07k
      break;
237
0
    default:
238
0
      return 0;
239
30.8k
    }
240
30.8k
  {
241
30.8k
    const ind_addr_type *current_ind = tic30_indaddr_tab;
242
243
790k
    for (; current_ind < tic30_indaddrtab_end; current_ind++)
244
781k
      {
245
781k
  if (current_ind->modfield == mod)
246
21.6k
    {
247
21.6k
      if (current_ind->displacement == IMPLIED_DISP && size == 2)
248
231
        continue;
249
250
21.4k
      else
251
21.4k
        {
252
21.4k
    size_t i, len;
253
21.4k
    int bufcnt;
254
255
21.4k
    len = strlen (current_ind->syntax);
256
257
154k
    for (i = 0, bufcnt = 0; i < len; i++, bufcnt++)
258
132k
      {
259
132k
        buffer[bufcnt] = current_ind->syntax[i];
260
261
132k
        if (bufcnt > 0
262
111k
      && bufcnt < OPERAND_BUFFER_LEN - 1
263
111k
      && buffer[bufcnt - 1] == 'a'
264
21.4k
      && buffer[bufcnt] == 'r')
265
21.4k
          buffer[++bufcnt] = arnum + '0';
266
        
267
132k
        if (bufcnt < OPERAND_BUFFER_LEN - 1
268
132k
      && buffer[bufcnt] == '('
269
9.40k
      && current_ind->displacement == DISP_REQUIRED)
270
231
          {
271
231
      snprintf (buffer + (bufcnt + 1),
272
231
         OPERAND_BUFFER_LEN - (bufcnt + 1),
273
231
         "%u", disp);
274
231
      bufcnt += strlen (buffer + (bufcnt + 1));
275
231
          }
276
132k
      }
277
21.4k
    buffer[bufcnt + 1] = '\0';
278
21.4k
    break;
279
21.4k
        }
280
21.6k
    }
281
781k
      }
282
30.8k
  }
283
30.8k
  return 1;
284
30.8k
}
285
286
static int
287
cnvt_tmsfloat_ieee (unsigned long tmsfloat, int size, float *ieeefloat)
288
1.78k
{
289
1.78k
  unsigned long exponent, sign, mant;
290
1.78k
  union
291
1.78k
  {
292
1.78k
    unsigned long l;
293
1.78k
    float f;
294
1.78k
  } val;
295
296
1.78k
  if (size == 2)
297
1.78k
    {
298
1.78k
      if ((tmsfloat & 0x0000F000) == 0x00008000)
299
56
  tmsfloat = 0x80000000;
300
1.73k
      else
301
1.73k
  {
302
1.73k
    tmsfloat <<= 16;
303
1.73k
    tmsfloat = (long) tmsfloat >> 4;
304
1.73k
  }
305
1.78k
    }
306
1.78k
  exponent = tmsfloat & 0xFF000000;
307
1.78k
  if (exponent == 0x80000000)
308
56
    {
309
56
      *ieeefloat = 0.0;
310
56
      return 1;
311
56
    }
312
1.73k
  exponent += 0x7F000000;
313
1.73k
  sign = (tmsfloat & 0x00800000) << 8;
314
1.73k
  mant = tmsfloat & 0x007FFFFF;
315
1.73k
  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
1.73k
  exponent >>= 1;
333
1.73k
  if (sign)
334
117
    {
335
117
      mant = (~mant) & 0x007FFFFF;
336
117
      mant += 1;
337
117
      exponent += mant & 0x00800000;
338
117
      exponent &= 0x7F800000;
339
117
      mant &= 0x007FFFFF;
340
117
    }
341
1.73k
  if (tmsfloat == 0x80000000)
342
0
    sign = mant = exponent = 0;
343
1.73k
  tmsfloat = sign | exponent | mant;
344
1.73k
  val.l = tmsfloat;
345
1.73k
  *ieeefloat = val.f;
346
1.73k
  return 1;
347
1.73k
}
348
349
static int
350
print_two_operand (disassemble_info *info,
351
       unsigned long insn_word,
352
       struct instruction *insn)
353
19.3k
{
354
19.3k
  char name[12];
355
19.3k
  char operand[2][OPERAND_BUFFER_LEN] =
356
19.3k
  {
357
19.3k
    {0},
358
19.3k
    {0}
359
19.3k
  };
360
19.3k
  float f_number;
361
362
19.3k
  if (insn->tm == NULL)
363
102
    return 0;
364
19.2k
  strcpy (name, insn->tm->name);
365
19.2k
  if (insn->tm->opcode_modifier == AddressMode)
366
18.8k
    {
367
18.8k
      int src_op, dest_op;
368
      /* Determine whether instruction is a store or a normal instruction.  */
369
18.8k
      if ((insn->tm->operand_types[1] & (Direct | Indirect))
370
18.8k
    == (Direct | Indirect))
371
183
  {
372
183
    src_op = 1;
373
183
    dest_op = 0;
374
183
  }
375
18.6k
      else
376
18.6k
  {
377
18.6k
    src_op = 0;
378
18.6k
    dest_op = 1;
379
18.6k
  }
380
      /* Get the destination register.  */
381
18.8k
      if (insn->tm->operands == 2)
382
18.6k
  get_register_operand ((insn_word & 0x001F0000) >> 16, operand[dest_op]);
383
      /* Get the source operand based on addressing mode.  */
384
18.8k
      switch (insn_word & AddressMode)
385
18.8k
  {
386
13.7k
  case AM_REGISTER:
387
    /* Check for the NOP instruction before getting the operand.  */
388
13.7k
    if ((insn->tm->operand_types[0] & NotReq) == 0)
389
13.7k
      get_register_operand ((insn_word & 0x0000001F), operand[src_op]);
390
13.7k
    break;
391
987
  case AM_DIRECT:
392
987
    sprintf (operand[src_op], "@0x%lX", (insn_word & 0x0000FFFF));
393
987
    break;
394
2.07k
  case AM_INDIRECT:
395
2.07k
    get_indirect_operand ((insn_word & 0x0000FFFF), 2, operand[src_op]);
396
2.07k
    break;
397
2.08k
  case AM_IMM:
398
    /* Get the value of the immediate operand based on variable type.  */
399
2.08k
    switch (insn->tm->imm_arg_type)
400
2.08k
      {
401
1.78k
      case Imm_Float:
402
1.78k
        cnvt_tmsfloat_ieee ((insn_word & 0x0000FFFF), 2, &f_number);
403
1.78k
        sprintf (operand[src_op], "%2.2f", f_number);
404
1.78k
        break;
405
241
      case Imm_SInt:
406
241
        sprintf (operand[src_op], "%d", (short) (insn_word & 0x0000FFFF));
407
241
        break;
408
48
      case Imm_UInt:
409
48
        sprintf (operand[src_op], "%lu", (insn_word & 0x0000FFFF));
410
48
        break;
411
5
      default:
412
5
        return 0;
413
2.08k
      }
414
    /* Handle special case for LDP instruction.  */
415
2.07k
    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
18.8k
  }
422
18.8k
    }
423
  /* Handle case for stack and rotate instructions.  */
424
392
  else if (insn->tm->operands == 1)
425
199
    {
426
199
      if (insn->tm->opcode_modifier == StackOp)
427
199
  get_register_operand ((insn_word & 0x001F0000) >> 16, operand[0]);
428
199
    }
429
  /* Output instruction to stream.  */
430
19.2k
  info->fprintf_func (info->stream, "   %s %s%c%s", name,
431
19.2k
          operand[0][0] ? operand[0] : "",
432
19.2k
          operand[1][0] ? ',' : ' ',
433
19.2k
          operand[1][0] ? operand[1] : "");
434
19.2k
  return 1;
435
19.2k
}
436
437
static int
438
print_three_operand (disassemble_info *info,
439
         unsigned long insn_word,
440
         struct instruction *insn)
441
3.03k
{
442
3.03k
  char operand[3][OPERAND_BUFFER_LEN] =
443
3.03k
  {
444
3.03k
    {0},
445
3.03k
    {0},
446
3.03k
    {0}
447
3.03k
  };
448
449
3.03k
  if (insn->tm == NULL)
450
229
    return 0;
451
2.81k
  switch (insn_word & AddressMode)
452
2.81k
    {
453
595
    case AM_REGISTER:
454
595
      get_register_operand ((insn_word & 0x000000FF), operand[0]);
455
595
      get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
456
595
      break;
457
1.43k
    case AM_DIRECT:
458
1.43k
      get_register_operand ((insn_word & 0x000000FF), operand[0]);
459
1.43k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
460
1.43k
      break;
461
681
    case AM_INDIRECT:
462
681
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
463
681
      get_register_operand ((insn_word & 0x0000FF00) >> 8, operand[1]);
464
681
      break;
465
97
    case AM_IMM:
466
97
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0]);
467
97
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1]);
468
97
      break;
469
0
    default:
470
0
      return 0;
471
2.81k
    }
472
2.81k
  if (insn->tm->operands == 3)
473
1.82k
    get_register_operand ((insn_word & 0x001F0000) >> 16, operand[2]);
474
2.81k
  info->fprintf_func (info->stream, "   %s %s,%s%c%s", insn->tm->name,
475
2.81k
          operand[0], operand[1],
476
2.81k
          operand[2][0] ? ',' : ' ',
477
2.81k
          operand[2][0] ? operand[2] : "");
478
2.81k
  return 1;
479
2.81k
}
480
481
static int
482
print_par_insn (disassemble_info *info,
483
    unsigned long insn_word,
484
    struct instruction *insn)
485
13.3k
{
486
13.3k
  size_t i, len;
487
13.3k
  char *name1, *name2;
488
13.3k
  char operand[2][3][OPERAND_BUFFER_LEN] =
489
13.3k
  {
490
13.3k
    {
491
13.3k
      {0},
492
13.3k
      {0},
493
13.3k
      {0}
494
13.3k
    },
495
13.3k
    {
496
13.3k
      {0},
497
13.3k
      {0},
498
13.3k
      {0}
499
13.3k
    }
500
13.3k
  };
501
502
13.3k
  if (insn->ptm == NULL)
503
123
    return 0;
504
  /* Parse out the names of each of the parallel instructions from the
505
     q_insn1_insn2 format.  */
506
13.2k
  name1 = (char *) strdup (insn->ptm->name + 2);
507
13.2k
  name2 = "";
508
13.2k
  len = strlen (name1);
509
63.1k
  for (i = 0; i < len; i++)
510
63.1k
    {
511
63.1k
      if (name1[i] == '_')
512
13.2k
  {
513
13.2k
    name2 = &name1[i + 1];
514
13.2k
    name1[i] = '\0';
515
13.2k
    break;
516
13.2k
  }
517
63.1k
    }
518
  /* Get the operands of the instruction based on the operand order.  */
519
13.2k
  switch (insn->ptm->oporder)
520
13.2k
    {
521
1.91k
    case OO_4op1:
522
1.91k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
523
1.91k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
524
1.91k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
525
1.91k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
526
1.91k
      break;
527
423
    case OO_4op2:
528
423
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
529
423
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
530
423
      get_register_operand ((insn_word >> 19) & 0x07, operand[1][1]);
531
423
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][1]);
532
423
      break;
533
3.20k
    case OO_4op3:
534
3.20k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
535
3.20k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
536
3.20k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
537
3.20k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][0]);
538
3.20k
      break;
539
1.32k
    case OO_5op1:
540
1.32k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][0]);
541
1.32k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
542
1.32k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
543
1.32k
      get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
544
1.32k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
545
1.32k
      break;
546
2.83k
    case OO_5op2:
547
2.83k
      get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
548
2.83k
      get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][1]);
549
2.83k
      get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
550
2.83k
      get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
551
2.83k
      get_register_operand ((insn_word >> 22) & 0x07, operand[0][2]);
552
2.83k
      break;
553
3.51k
    case OO_PField:
554
3.51k
      if (insn_word & 0x00800000)
555
3.19k
  get_register_operand (0x01, operand[0][2]);
556
317
      else
557
317
  get_register_operand (0x00, operand[0][2]);
558
3.51k
      if (insn_word & 0x00400000)
559
241
  get_register_operand (0x03, operand[1][2]);
560
3.27k
      else
561
3.27k
  get_register_operand (0x02, operand[1][2]);
562
3.51k
      switch (insn_word & P_FIELD)
563
3.51k
  {
564
864
  case 0x00000000:
565
864
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[0][1]);
566
864
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
567
864
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
568
864
    get_register_operand ((insn_word >> 19) & 0x07, operand[1][0]);
569
864
    break;
570
2.07k
  case 0x01000000:
571
2.07k
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][0]);
572
2.07k
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
573
2.07k
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][1]);
574
2.07k
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
575
2.07k
    break;
576
436
  case 0x02000000:
577
436
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
578
436
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[1][0]);
579
436
    get_register_operand ((insn_word >> 16) & 0x07, operand[0][1]);
580
436
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][0]);
581
436
    break;
582
143
  case 0x03000000:
583
143
    get_indirect_operand ((insn_word & 0x000000FF), 1, operand[1][1]);
584
143
    get_indirect_operand ((insn_word & 0x0000FF00) >> 8, 1, operand[0][0]);
585
143
    get_register_operand ((insn_word >> 16) & 0x07, operand[1][0]);
586
143
    get_register_operand ((insn_word >> 19) & 0x07, operand[0][1]);
587
143
    break;
588
3.51k
  }
589
3.51k
      break;
590
3.51k
    default:
591
0
      return 0;
592
13.2k
    }
593
13.2k
  info->fprintf_func (info->stream, "   %s %s,%s%c%s", name1,
594
13.2k
          operand[0][0], operand[0][1],
595
13.2k
          operand[0][2][0] ? ',' : ' ',
596
13.2k
          operand[0][2][0] ? operand[0][2] : "");
597
13.2k
  info->fprintf_func (info->stream, "\n\t\t\t|| %s %s,%s%c%s", name2,
598
13.2k
          operand[1][0], operand[1][1],
599
13.2k
          operand[1][2][0] ? ',' : ' ',
600
13.2k
          operand[1][2][0] ? operand[1][2] : "");
601
13.2k
  free (name1);
602
13.2k
  return 1;
603
13.2k
}
604
605
static int
606
print_branch (disassemble_info *info,
607
        unsigned long insn_word,
608
        struct instruction *insn)
609
2.24k
{
610
2.24k
  char operand[2][OPERAND_BUFFER_LEN] =
611
2.24k
  {
612
2.24k
    {0},
613
2.24k
    {0}
614
2.24k
  };
615
2.24k
  unsigned long address;
616
2.24k
  int print_label = 0;
617
618
2.24k
  if (insn->tm == NULL)
619
186
    return 0;
620
  /* Get the operands for 24-bit immediate jumps.  */
621
2.05k
  if (insn->tm->operand_types[0] & Imm24)
622
515
    {
623
515
      address = insn_word & 0x00FFFFFF;
624
515
      sprintf (operand[0], "0x%lX", address);
625
515
      print_label = 1;
626
515
    }
627
  /* Get the operand for the trap instruction.  */
628
1.53k
  else if (insn->tm->operand_types[0] & IVector)
629
179
    {
630
179
      address = insn_word & 0x0000001F;
631
179
      sprintf (operand[0], "0x%lX", address);
632
179
    }
633
1.36k
  else
634
1.36k
    {
635
1.36k
      address = insn_word & 0x0000FFFF;
636
      /* Get the operands for the DB instructions.  */
637
1.36k
      if (insn->tm->operands == 2)
638
624
  {
639
624
    get_register_operand (((insn_word & 0x01C00000) >> 22) + REG_AR0, operand[0]);
640
624
    if (insn_word & PCRel)
641
248
      {
642
248
        sprintf (operand[1], "%d", (short) address);
643
248
        print_label = 1;
644
248
      }
645
376
    else
646
376
      get_register_operand (insn_word & 0x0000001F, operand[1]);
647
624
  }
648
      /* Get the operands for the standard branches.  */
649
736
      else if (insn->tm->operands == 1)
650
579
  {
651
579
    if (insn_word & PCRel)
652
271
      {
653
271
        address = (short) address;
654
271
        sprintf (operand[0], "%ld", address);
655
271
        print_label = 1;
656
271
      }
657
308
    else
658
308
      get_register_operand (insn_word & 0x0000001F, operand[0]);
659
579
  }
660
1.36k
    }
661
2.05k
  info->fprintf_func (info->stream, "   %s %s%c%s", insn->tm->name,
662
2.05k
          operand[0][0] ? operand[0] : "",
663
2.05k
          operand[1][0] ? ',' : ' ',
664
2.05k
          operand[1][0] ? operand[1] : "");
665
  /* Print destination of branch in relation to current symbol.  */
666
2.05k
  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.05k
  return 1;
689
2.24k
}
690
691
int
692
print_insn_tic30 (bfd_vma pc, disassemble_info *info)
693
38.1k
{
694
38.1k
  unsigned long insn_word;
695
38.1k
  struct instruction insn = { 0, NULL, NULL };
696
38.1k
  bfd_vma bufaddr = pc - info->buffer_vma;
697
698
38.1k
  if (bufaddr + 3 >= info->buffer_length)
699
143
    return -1;
700
701
  /* Obtain the current instruction word from the buffer.  */
702
37.9k
  insn_word = (((unsigned) *(info->buffer + bufaddr) << 24)
703
37.9k
         | (*(info->buffer + bufaddr + 1) << 16)
704
37.9k
         | (*(info->buffer + bufaddr + 2) << 8)
705
37.9k
         | *(info->buffer + bufaddr + 3));
706
37.9k
  _pc = pc / 4;
707
  /* Get the instruction referred to by the current instruction word
708
     and print it out based on its type.  */
709
37.9k
  if (!get_tic30_instruction (insn_word, &insn))
710
0
    return -1;
711
37.9k
  switch (GET_TYPE (insn_word))
712
37.9k
    {
713
17.3k
    case TWO_OPERAND_1:
714
19.3k
    case TWO_OPERAND_2:
715
19.3k
      if (!print_two_operand (info, insn_word, &insn))
716
107
  return -1;
717
19.2k
      break;
718
19.2k
    case THREE_OPERAND:
719
3.03k
      if (!print_three_operand (info, insn_word, &insn))
720
229
  return -1;
721
2.81k
      break;
722
9.78k
    case PAR_STORE:
723
13.3k
    case MUL_ADDS:
724
13.3k
      if (!print_par_insn (info, insn_word, &insn))
725
123
  return -1;
726
13.2k
      break;
727
13.2k
    case BRANCHES:
728
2.24k
      if (!print_branch (info, insn_word, &insn))
729
186
  return -1;
730
2.05k
      break;
731
37.9k
    }
732
37.3k
  return 4;
733
37.9k
}