Coverage Report

Created: 2025-06-24 06:45

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