Coverage Report

Created: 2023-08-28 06:23

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