Coverage Report

Created: 2023-08-28 06:30

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