Coverage Report

Created: 2026-07-25 10:20

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