Coverage Report

Created: 2026-09-14 08:07

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