Coverage Report

Created: 2023-08-28 06:31

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