Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/tic6x-dis.c
Line
Count
Source
1
/* TI C6X disassembler.
2
   Copyright (C) 2010-2026 Free Software Foundation, Inc.
3
   Contributed by Joseph Myers <joseph@codesourcery.com>
4
        Bernd Schmidt  <bernds@codesourcery.com>
5
6
   This file is part of libopcodes.
7
8
   This library is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
13
   It is distributed in the hope that it will be useful, but WITHOUT
14
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
16
   License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
23
#include "sysdep.h"
24
#include "disassemble.h"
25
#include "opcode/tic6x.h"
26
#include "libiberty.h"
27
28
/* Define the instruction format table.  */
29
const tic6x_insn_format tic6x_insn_format_table[tic6x_insn_format_max] =
30
  {
31
#define FMT(name, num_bits, cst_bits, mask, fields) \
32
    { num_bits, cst_bits, mask, fields },
33
#include "opcode/tic6x-insn-formats.h"
34
#undef FMT
35
  };
36
37
/* Define the control register table.  */
38
const tic6x_ctrl tic6x_ctrl_table[tic6x_ctrl_max] =
39
  {
40
#define CTRL(name, isa, rw, crlo, crhi_mask)  \
41
    {           \
42
      STRINGX(name),        \
43
      CONCAT2(TIC6X_INSN_,isa),     \
44
      CONCAT2(tic6x_rw_,rw),      \
45
      crlo,         \
46
      crhi_mask         \
47
    },
48
#include "opcode/tic6x-control-registers.h"
49
#undef CTRL
50
  };
51
52
/* Define the opcode table.  */
53
const tic6x_opcode tic6x_opcode_table[tic6x_opcode_max] =
54
  {
55
#define INSNU(name, func_unit, format, type, isa, flags, fixed, ops, var) \
56
    {                 \
57
      STRINGX(name),              \
58
      CONCAT2(tic6x_func_unit_,func_unit),        \
59
      CONCAT3(tic6x_insn_format,_,format),              \
60
      CONCAT2(tic6x_pipeline_,type),          \
61
      CONCAT2(TIC6X_INSN_,isa),           \
62
      flags,                \
63
      fixed,                \
64
      ops,                \
65
      var               \
66
    },
67
#define INSNUE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
68
    {                 \
69
      STRINGX(name),              \
70
      CONCAT2(tic6x_func_unit_,func_unit),        \
71
      CONCAT3(tic6x_insn_format,_,format),              \
72
      CONCAT2(tic6x_pipeline_,type),          \
73
      CONCAT2(TIC6X_INSN_,isa),           \
74
      flags,                \
75
      fixed,                \
76
      ops,                \
77
      var               \
78
    },
79
#define INSN(name, func_unit, format, type, isa, flags, fixed, ops, var) \
80
    {                 \
81
      STRINGX(name),              \
82
      CONCAT2(tic6x_func_unit_,func_unit),        \
83
      CONCAT4(tic6x_insn_format_,func_unit,_,format),     \
84
      CONCAT2(tic6x_pipeline_,type),          \
85
      CONCAT2(TIC6X_INSN_,isa),           \
86
      flags,                \
87
      fixed,                \
88
      ops,                \
89
      var               \
90
    },
91
#define INSNE(name, e, func_unit, format, type, isa, flags, fixed, ops, var) \
92
    {                 \
93
      STRINGX(name),              \
94
      CONCAT2(tic6x_func_unit_,func_unit),        \
95
      CONCAT4(tic6x_insn_format_,func_unit,_,format),     \
96
      CONCAT2(tic6x_pipeline_,type),          \
97
      CONCAT2(TIC6X_INSN_,isa),           \
98
      flags,                \
99
      fixed,                \
100
      ops,                \
101
      var               \
102
    },
103
#include "opcode/tic6x-opcode-table.h"
104
#undef INSN
105
#undef INSNE
106
#undef INSNU
107
#undef INSNUE
108
  };
109
110
/* If instruction format FMT has a field FIELD, return a pointer to
111
   the description of that field; otherwise return NULL.  */
112
113
const tic6x_insn_field *
114
tic6x_field_from_fmt (const tic6x_insn_format *fmt, tic6x_insn_field_id field)
115
10.6M
{
116
10.6M
  unsigned int f;
117
118
38.3M
  for (f = 0; f < fmt->num_fields; f++)
119
38.2M
    if (fmt->fields[f].field_id == field)
120
10.5M
      return &fmt->fields[f];
121
122
62.6k
  return NULL;
123
10.6M
}
124
125
/* Extract the field width.  */
126
127
static unsigned int
128
tic6x_field_width (const tic6x_insn_field *field)
129
34.7k
{
130
34.7k
  unsigned int i;
131
34.7k
  unsigned int width = 0;
132
133
34.7k
  if (!field->num_bitfields)
134
0
    return field->bitfields[0].width;
135
136
70.7k
  for (i = 0 ; i < field->num_bitfields ; i++)
137
35.9k
    width += field->bitfields[i].width;
138
139
34.7k
  return width;
140
34.7k
}
141
142
/* Extract the bits corresponding to FIELD from OPCODE.  */
143
144
static unsigned int
145
tic6x_field_bits (unsigned int opcode, const tic6x_insn_field *field)
146
10.5M
{
147
10.5M
  unsigned int i;
148
10.5M
  unsigned int val = 0;
149
150
10.5M
  if (!field->num_bitfields)
151
0
    return (opcode >> field->bitfields[0].low_pos) & ((1u << field->bitfields[0].width) - 1);
152
153
21.1M
  for (i = 0 ; i < field->num_bitfields ; i++)
154
10.5M
    val |= ((opcode >> field->bitfields[i].low_pos) & ((1u << field->bitfields[i].width) - 1))
155
10.5M
      << field->bitfields[i].pos;
156
157
10.5M
  return val;
158
10.5M
}
159
160
/* Extract a 32-bit value read from the instruction stream.  */
161
162
static unsigned int
163
tic6x_extract_32 (unsigned char *p, struct disassemble_info *info)
164
552k
{
165
552k
  if (info->endian == BFD_ENDIAN_LITTLE)
166
114
    return p[0] | (p[1] << 8) | (p[2] << 16) | ((unsigned) p[3] << 24);
167
552k
  else
168
552k
    return p[3] | (p[2] << 8) | (p[1] << 16) | ((unsigned) p[0] << 24);
169
552k
}
170
171
/* Extract a 16-bit value read from the instruction stream.  */
172
173
static unsigned int
174
tic6x_extract_16 (unsigned char *p, tic6x_fetch_packet_header *header,
175
                  struct disassemble_info *info)
176
12.8k
{
177
12.8k
  unsigned int op16;
178
179
12.8k
  if (info->endian == BFD_ENDIAN_LITTLE)
180
36
    op16 = (p[0]) | (p[1] << 8);
181
12.7k
  else
182
12.7k
    op16 = (p[1]) | (p[0] << 8);
183
12.8k
  op16 |= (header->sat << TIC6X_COMPACT_SAT_POS);
184
12.8k
  op16 |= (header->br << TIC6X_COMPACT_BR_POS);
185
12.8k
  op16 |= (header->dsz << TIC6X_COMPACT_DSZ_POS);
186
12.8k
  return op16;
187
12.8k
}
188
189
/* FP points to a fetch packet.  Return whether it is header-based; if
190
   it is, fill in HEADER.  */
191
192
static bool
193
tic6x_check_fetch_packet_header (unsigned char *fp,
194
         tic6x_fetch_packet_header *header,
195
         struct disassemble_info *info)
196
209k
{
197
209k
  int i;
198
199
209k
  header->header = tic6x_extract_32 (fp + 28, info);
200
201
209k
  if ((header->header & 0xf0000000) != 0xe0000000)
202
191k
    {
203
191k
      header->prot = 0;
204
191k
      header->rs = 0;
205
191k
      header->dsz = 0;
206
191k
      header->br = 0;
207
191k
      header->sat = 0;
208
1.53M
      for (i = 0; i < 7; i++)
209
1.34M
  header->word_compact[i] = false;
210
2.87M
      for (i = 0; i < 14; i++)
211
2.68M
  header->p_bits[i] = false;
212
191k
      return false;
213
191k
    }
214
215
143k
  for (i = 0; i < 7; i++)
216
125k
    header->word_compact[i]
217
125k
      = (header->header & (1u << (21 + i))) != 0;
218
219
17.8k
  header->prot = (header->header & (1u << 20)) != 0;
220
17.8k
  header->rs = (header->header & (1u << 19)) != 0;
221
17.8k
  header->dsz = (header->header >> 16) & 0x7;
222
17.8k
  header->br = (header->header & (1u << 15)) != 0;
223
17.8k
  header->sat = (header->header & (1u << 14)) != 0;
224
225
268k
  for (i = 0; i < 14; i++)
226
250k
    header->p_bits[i] = (header->header & (1u << i)) != 0;
227
228
17.8k
  return true;
229
209k
}
230
231
/* Disassemble the instruction at ADDR and print it using
232
   INFO->FPRINTF_FUNC and INFO->STREAM, returning the number of bytes
233
   consumed.  */
234
235
int
236
print_insn_tic6x (bfd_vma addr, struct disassemble_info *info)
237
187k
{
238
187k
  int status;
239
187k
  bfd_vma fp_addr;
240
187k
  bfd_vma fp_offset;
241
187k
  unsigned char fp[32];
242
187k
  unsigned int opcode;
243
187k
  tic6x_opcode_id opcode_id;
244
187k
  bool fetch_packet_header_based;
245
187k
  tic6x_fetch_packet_header header;
246
187k
  unsigned int num_bits;
247
187k
  bool bad_offset = false;
248
249
187k
  fp_offset = addr & 0x1f;
250
187k
  fp_addr = addr - fp_offset;
251
  /* Read in a block of instructions.  Since there might be a
252
     symbol in the middle of this block, disable stop_vma.  */
253
187k
  info->stop_vma = 0;
254
187k
  status = info->read_memory_func (fp_addr, fp, 32, info);
255
187k
  if (status)
256
238
    {
257
238
      info->memory_error_func (status, addr, info);
258
238
      return -1;
259
238
    }
260
261
186k
  fetch_packet_header_based
262
186k
    = tic6x_check_fetch_packet_header (fp, &header, info);
263
186k
  if (fetch_packet_header_based)
264
17.0k
    {
265
17.0k
      if (fp_offset & 0x1)
266
11
  bad_offset = true;
267
17.0k
      else if ((fp_offset & 0x3) && (fp_offset >= 28
268
6.00k
             || !header.word_compact[fp_offset >> 2]))
269
11
  bad_offset = true;
270
16.9k
      else if (fp_offset == 28)
271
1.39k
  {
272
1.39k
    info->bytes_per_chunk = 4;
273
1.39k
    info->fprintf_func (info->stream, "<fetch packet header 0x%.8x>",
274
1.39k
            header.header);
275
1.39k
    return 4;
276
1.39k
  }
277
17.0k
    }
278
169k
  else
279
169k
    {
280
169k
      if (fp_offset & 0x3)
281
0
  bad_offset = true;
282
169k
    }
283
284
185k
  if (bad_offset)
285
22
    {
286
22
      info->bytes_per_chunk = 1;
287
22
      info->fprintf_func (info->stream, ".byte 0x%.2x", fp[fp_offset]);
288
22
      return 1;
289
22
    }
290
291
185k
  num_bits = 32;
292
185k
  if (fetch_packet_header_based && header.word_compact[fp_offset >> 2])
293
12.0k
    num_bits = 16;
294
295
185k
  if (num_bits == 16)
296
12.0k
    {
297
      /* The least-significant part of a 32-bit word comes logically
298
   before the most-significant part.  For big-endian, follow the
299
   TI assembler in showing instructions in logical order by
300
   pretending that the two halves of the word are in opposite
301
   locations to where they actually are.  */
302
12.0k
      if (info->endian == BFD_ENDIAN_LITTLE)
303
36
  opcode = tic6x_extract_16 (fp + fp_offset, &header, info);
304
11.9k
      else
305
11.9k
  opcode = tic6x_extract_16 (fp + (fp_offset ^ 2), &header, info);
306
12.0k
    }
307
173k
  else
308
173k
    opcode = tic6x_extract_32 (fp + fp_offset, info);
309
310
72.6M
  for (opcode_id = 0; opcode_id < tic6x_opcode_max; opcode_id++)
311
72.6M
    {
312
72.6M
      const tic6x_opcode *const opc = &tic6x_opcode_table[opcode_id];
313
72.6M
      const tic6x_insn_format *const fmt
314
72.6M
  = &tic6x_insn_format_table[opc->format];
315
72.6M
      const tic6x_insn_field *creg_field;
316
72.6M
      bool p_bit;
317
72.6M
      const char *parallel;
318
72.6M
      const char *cond = "";
319
72.6M
      const char *func_unit;
320
72.6M
      char func_unit_buf[8];
321
72.6M
      unsigned int func_unit_side = 0;
322
72.6M
      unsigned int func_unit_data_side = 0;
323
72.6M
      unsigned int func_unit_cross = 0;
324
72.6M
      unsigned int t_val = 0;
325
      /* The maximum length of the text of a non-PC-relative operand
326
   is 24 bytes (SPMASK masking all eight functional units, with
327
   separating commas and trailing NUL).  */
328
72.6M
      char operands[TIC6X_MAX_OPERANDS][24] = { { 0 } };
329
72.6M
      bfd_vma operands_addresses[TIC6X_MAX_OPERANDS] = { 0 };
330
72.6M
      bool operands_text[TIC6X_MAX_OPERANDS] = { false };
331
72.6M
      bool operands_pcrel[TIC6X_MAX_OPERANDS] = { false };
332
72.6M
      unsigned int fix;
333
72.6M
      unsigned int num_operands;
334
72.6M
      unsigned int op_num;
335
72.6M
      bool fixed_ok;
336
72.6M
      bool operands_ok;
337
72.6M
      bool have_t = false;
338
339
72.6M
      if (opc->flags & TIC6X_FLAG_MACRO)
340
7.73M
  continue;
341
64.8M
      if (fmt->num_bits != num_bits)
342
21.6M
  continue;
343
43.1M
      if ((opcode & fmt->mask) != fmt->cst_bits)
344
39.8M
  continue;
345
346
      /* If the format has a creg field, it is only a candidate for a
347
   match if the creg and z fields have values indicating a valid
348
   condition; reserved values indicate either an instruction
349
   format without a creg field, or an invalid instruction.  */
350
3.35M
      creg_field = tic6x_field_from_fmt (fmt, tic6x_field_creg);
351
3.35M
      if (creg_field)
352
3.29M
  {
353
3.29M
    const tic6x_insn_field *z_field;
354
3.29M
    unsigned int creg_value, z_value;
355
3.29M
    static const char *const conds[8][2] =
356
3.29M
      {
357
3.29M
        { "", NULL },
358
3.29M
        { "[b0] ", "[!b0] " },
359
3.29M
        { "[b1] ", "[!b1] " },
360
3.29M
        { "[b2] ", "[!b2] " },
361
3.29M
        { "[a1] ", "[!a1] " },
362
3.29M
        { "[a2] ", "[!a2] " },
363
3.29M
        { "[a0] ", "[!a0] " },
364
3.29M
        { NULL, NULL }
365
3.29M
      };
366
367
    /* A creg field is not meaningful without a z field, so if
368
       the z field is not present this is an error in the format
369
       table.  */
370
3.29M
    z_field = tic6x_field_from_fmt (fmt, tic6x_field_z);
371
3.29M
    if (!z_field)
372
0
      {
373
0
        printf ("*** opcode %x: missing z field", opcode);
374
0
        abort ();
375
0
      }
376
377
3.29M
    creg_value = tic6x_field_bits (opcode, creg_field);
378
3.29M
    z_value = tic6x_field_bits (opcode, z_field);
379
3.29M
    cond = conds[creg_value][z_value];
380
3.29M
    if (cond == NULL)
381
584k
      continue;
382
3.29M
  }
383
384
2.77M
      if (opc->flags & TIC6X_FLAG_INSN16_SPRED)
385
1.06k
  {
386
1.06k
    const tic6x_insn_field *cc_field;
387
1.06k
          unsigned int s_value = 0;
388
1.06k
          unsigned int z_value = 0;
389
1.06k
          bool cond_known = false;
390
1.06k
          static const char *const conds[2][2] =
391
1.06k
            {
392
1.06k
              { "[a0] ", "[!a0] " },
393
1.06k
              { "[b0] ", "[!b0] " }
394
1.06k
            };
395
396
1.06k
          cc_field = tic6x_field_from_fmt (fmt, tic6x_field_cc);
397
398
1.06k
          if (cc_field)
399
76
      {
400
76
        unsigned int cc_value;
401
402
76
        cc_value = tic6x_field_bits (opcode, cc_field);
403
76
        s_value = (cc_value & 0x2) >> 1;
404
76
        z_value = (cc_value & 0x1);
405
76
        cond_known = true;
406
76
      }
407
990
    else
408
990
      {
409
990
        const tic6x_insn_field *z_field;
410
990
        const tic6x_insn_field *s_field;
411
412
990
        s_field = tic6x_field_from_fmt (fmt, tic6x_field_s);
413
414
990
        if (!s_field)
415
0
    {
416
0
      printf ("opcode %x: missing compact insn predicate register field (s field)\n",
417
0
        opcode);
418
0
      abort ();
419
0
    }
420
990
        s_value = tic6x_field_bits (opcode, s_field);
421
990
        z_field = tic6x_field_from_fmt (fmt, tic6x_field_z);
422
990
        if (!z_field)
423
0
    {
424
0
      printf ("opcode %x: missing compact insn predicate z_value (z field)\n", opcode);
425
0
      abort ();
426
0
    }
427
428
990
        z_value = tic6x_field_bits (opcode, z_field);
429
990
        cond_known = true;
430
990
      }
431
432
1.06k
          if (!cond_known)
433
0
      {
434
0
        printf ("opcode %x: unspecified ompact insn predicate\n", opcode);
435
0
        abort ();
436
0
      }
437
1.06k
          cond = conds[s_value][z_value];
438
1.06k
  }
439
440
      /* All fixed fields must have matching values; all fields with
441
   restricted ranges must have values within those ranges.  */
442
2.77M
      fixed_ok = true;
443
2.98M
      for (fix = 0; fix < opc->num_fixed_fields; fix++)
444
2.85M
  {
445
2.85M
    unsigned int field_bits;
446
2.85M
    const tic6x_insn_field *const field
447
2.85M
      = tic6x_field_from_fmt (fmt, opc->fixed_fields[fix].field_id);
448
449
2.85M
    if (!field)
450
0
      {
451
0
        printf ("opcode %x: missing field #%d for FIX #%d\n",
452
0
          opcode, opc->fixed_fields[fix].field_id, fix);
453
0
        abort ();
454
0
      }
455
456
2.85M
    field_bits = tic6x_field_bits (opcode, field);
457
2.85M
    if (field_bits < opc->fixed_fields[fix].min_val
458
999k
        || field_bits > opc->fixed_fields[fix].max_val)
459
2.64M
      {
460
2.64M
        fixed_ok = false;
461
2.64M
        break;
462
2.64M
      }
463
2.85M
  }
464
2.77M
      if (!fixed_ok)
465
2.64M
  continue;
466
467
      /* The instruction matches.  */
468
469
      /* The p-bit indicates whether this instruction is in parallel
470
   with the *next* instruction, whereas the parallel bars
471
   indicate the instruction is in parallel with the *previous*
472
   instruction.  Thus, we must find the p-bit for the previous
473
   instruction.  */
474
132k
      if (num_bits == 16 && (fp_offset & 0x2) == 2)
475
5.43k
  {
476
    /* This is the logically second (most significant; second in
477
       fp_offset terms because fp_offset relates to logical not
478
       physical addresses) instruction of a compact pair; find
479
       the p-bit for the first (least significant).  */
480
5.43k
    p_bit = header.p_bits[(fp_offset >> 2) << 1];
481
5.43k
  }
482
127k
      else if (fp_offset >= 4)
483
109k
  {
484
    /* Find the last instruction of the previous word in this
485
       fetch packet.  For compact instructions, this is the most
486
       significant 16 bits.  */
487
109k
    if (fetch_packet_header_based
488
6.27k
        && header.word_compact[(fp_offset >> 2) - 1])
489
4.19k
      p_bit = header.p_bits[(fp_offset >> 1) - 1];
490
105k
    else
491
105k
      {
492
105k
        unsigned int prev_opcode
493
105k
    = tic6x_extract_32 (fp + (fp_offset & 0x1c) - 4, info);
494
105k
        p_bit = (prev_opcode & 0x1) != 0;
495
105k
      }
496
109k
  }
497
17.5k
      else
498
17.5k
  {
499
    /* Find the last instruction of the previous fetch
500
       packet.  */
501
17.5k
    unsigned char fp_prev[32];
502
503
17.5k
    status = info->read_memory_func (fp_addr - 32, fp_prev, 32, info);
504
17.5k
    if (status)
505
      /* No previous instruction to be parallel with.  */
506
600
      p_bit = false;
507
16.9k
    else
508
16.9k
      {
509
16.9k
        bool prev_header_based;
510
16.9k
        tic6x_fetch_packet_header prev_header;
511
512
16.9k
        prev_header_based
513
16.9k
    = tic6x_check_fetch_packet_header (fp_prev, &prev_header, info);
514
16.9k
        if (prev_header_based)
515
787
    {
516
787
      if (prev_header.word_compact[6])
517
421
        p_bit = prev_header.p_bits[13];
518
366
      else
519
366
        {
520
366
          unsigned int prev_opcode = tic6x_extract_32 (fp_prev + 24,
521
366
                   info);
522
366
          p_bit = (prev_opcode & 0x1) != 0;
523
366
        }
524
787
    }
525
16.1k
        else
526
16.1k
    {
527
16.1k
      unsigned int prev_opcode = tic6x_extract_32 (fp_prev + 28,
528
16.1k
                     info);
529
16.1k
      p_bit = (prev_opcode & 0x1) != 0;
530
16.1k
    }
531
16.9k
      }
532
17.5k
  }
533
132k
      parallel = p_bit ? "|| " : "";
534
535
132k
      if (opc->func_unit == tic6x_func_unit_nfu)
536
14.2k
  func_unit = "";
537
118k
      else
538
118k
  {
539
118k
    unsigned int fld_num;
540
118k
    char func_unit_char;
541
118k
    const char *data_str;
542
118k
    bool have_areg = false;
543
118k
    bool have_cross = false;
544
545
118k
    func_unit_side = (opc->flags & TIC6X_FLAG_SIDE_B_ONLY) ? 2 : 0;
546
118k
    func_unit_cross = 0;
547
118k
    func_unit_data_side = (opc->flags & TIC6X_FLAG_SIDE_T2_ONLY) ? 2 : 0;
548
549
675k
    for (fld_num = 0; fld_num < opc->num_variable_fields; fld_num++)
550
556k
      {
551
556k
        const tic6x_coding_field *const enc = &opc->variable_fields[fld_num];
552
556k
        const tic6x_insn_field *field;
553
556k
        unsigned int fld_val;
554
555
556k
        field = tic6x_field_from_fmt (fmt, enc->field_id);
556
557
556k
        if (!field)
558
0
    {
559
0
      printf ("opcode %x: could not retrieve field (field_id:%d)\n",
560
0
        opcode, fld_num);
561
0
      abort ();
562
0
    }
563
564
556k
        fld_val = tic6x_field_bits (opcode, field);
565
566
556k
        switch (enc->coding_method)
567
556k
    {
568
97.2k
    case tic6x_coding_fu:
569
      /* The side must be specified exactly once.  */
570
97.2k
      if (func_unit_side)
571
0
        {
572
0
          printf ("opcode %x: field #%d use tic6x_coding_fu, but func_unit_side is already set!\n",
573
0
            opcode, fld_num);
574
0
          abort ();
575
0
        }
576
97.2k
      func_unit_side = (fld_val ? 2 : 1);
577
97.2k
      break;
578
579
43.2k
    case tic6x_coding_data_fu:
580
      /* The data side must be specified exactly once.  */
581
43.2k
      if (func_unit_data_side)
582
0
        {
583
0
          printf ("opcode %x: field #%d use tic6x_coding_fu, but func_unit_side is already set!\n",
584
0
            opcode, fld_num);
585
0
          abort ();
586
0
        }
587
43.2k
      func_unit_data_side = (fld_val ? 2 : 1);
588
43.2k
      break;
589
590
47.9k
    case tic6x_coding_xpath:
591
      /* Cross path use must be specified exactly
592
         once.  */
593
47.9k
      if (have_cross)
594
0
        {
595
0
          printf ("opcode %x: field #%d use tic6x_coding_xpath, have_cross is already set!\n",
596
0
            opcode, fld_num);
597
0
          abort ();
598
0
        }
599
47.9k
      have_cross = true;
600
47.9k
      func_unit_cross = fld_val;
601
47.9k
      break;
602
603
2.82k
                case tic6x_coding_rside:
604
                  /* If the format has a t field, use it for src/dst register side.  */
605
2.82k
                  have_t = true;
606
2.82k
                  t_val = fld_val;
607
2.82k
                  func_unit_data_side = (t_val ? 2 : 1);
608
2.82k
                  break;
609
610
20.2k
    case tic6x_coding_areg:
611
20.2k
      have_areg = true;
612
20.2k
      break;
613
614
345k
    default:
615
      /* Don't relate to functional units.  */
616
345k
      break;
617
556k
    }
618
556k
      }
619
620
    /* The side of the functional unit used must now have been
621
       determined either from the flags or from an instruction
622
       field.  */
623
118k
    if (func_unit_side != 1 && func_unit_side != 2)
624
0
      {
625
0
        printf ("opcode %x: func_unit_side is not encoded!\n", opcode);
626
0
        abort ();
627
0
      }
628
629
    /* Cross paths are not applicable when sides are specified
630
       for both address and data paths.  */
631
118k
    if (func_unit_data_side && have_cross)
632
0
      {
633
0
        printf ("opcode %x: xpath not applicable when side are specified both for address and data!\n",
634
0
          opcode);
635
0
        abort ();
636
0
      }
637
638
    /* Separate address and data paths are only applicable for
639
       the D unit.  */
640
118k
    if (func_unit_data_side && opc->func_unit != tic6x_func_unit_d)
641
0
      {
642
0
        printf ("opcode %x: separate address and data paths only applicable for D unit!\n",
643
0
          opcode);
644
0
        abort ();
645
0
          }
646
647
    /* If an address register is being used but in ADDA rather
648
       than a load or store, it uses a cross path for side-A
649
       instructions, and the cross path use is not specified by
650
       an instruction field.  */
651
118k
    if (have_areg && !func_unit_data_side)
652
437
      {
653
437
        if (have_cross)
654
0
    {
655
0
      printf ("opcode %x: illegal cross path specifier in adda opcode!\n", opcode);
656
0
      abort ();
657
0
    }
658
437
        func_unit_cross = func_unit_side == 1;
659
437
      }
660
661
118k
    switch (opc->func_unit)
662
118k
      {
663
48.5k
      case tic6x_func_unit_d:
664
48.5k
        func_unit_char = 'D';
665
48.5k
        break;
666
667
10.3k
      case tic6x_func_unit_l:
668
10.3k
        func_unit_char = 'L';
669
10.3k
        break;
670
671
30.6k
      case tic6x_func_unit_m:
672
30.6k
        func_unit_char = 'M';
673
30.6k
        break;
674
675
28.7k
      case tic6x_func_unit_s:
676
28.7k
        func_unit_char = 'S';
677
28.7k
        break;
678
679
0
      default:
680
0
              printf ("opcode %x: illegal func_unit specifier %d\n", opcode, opc->func_unit);
681
0
        abort ();
682
118k
      }
683
684
118k
    switch (func_unit_data_side)
685
118k
      {
686
72.2k
      case 0:
687
72.2k
        data_str = "";
688
72.2k
        break;
689
690
22.9k
      case 1:
691
22.9k
        data_str = "T1";
692
22.9k
        break;
693
694
23.1k
      case 2:
695
23.1k
        data_str = "T2";
696
23.1k
        break;
697
698
0
      default:
699
0
              printf ("opcode %x: illegal data func_unit specifier %d\n",
700
0
          opcode, func_unit_data_side);
701
0
        abort ();
702
118k
      }
703
704
118k
    if (opc->flags & TIC6X_FLAG_INSN16_BSIDE && func_unit_side == 1)
705
75
        func_unit_cross = 1;
706
707
118k
    snprintf (func_unit_buf, sizeof func_unit_buf, " .%c%u%s%s",
708
118k
        func_unit_char, func_unit_side,
709
118k
        (func_unit_cross ? "X" : ""), data_str);
710
118k
    func_unit = func_unit_buf;
711
118k
  }
712
713
      /* For each operand there must be one or more fields set based
714
   on that operand, that can together be used to derive the
715
   operand value.  */
716
132k
      operands_ok = true;
717
132k
      num_operands = opc->num_operands;
718
444k
      for (op_num = 0; op_num < num_operands; op_num++)
719
312k
  {
720
312k
    unsigned int fld_num;
721
312k
    unsigned int mem_base_reg = 0;
722
312k
    bool mem_base_reg_known = false;
723
312k
    bool mem_base_reg_known_long = false;
724
312k
    unsigned int mem_offset = 0;
725
312k
    bool mem_offset_known = false;
726
312k
    bool mem_offset_known_long = false;
727
312k
    unsigned int mem_mode = 0;
728
312k
    bool mem_mode_known = false;
729
312k
    unsigned int mem_scaled = 0;
730
312k
    bool mem_scaled_known = false;
731
312k
    unsigned int crlo = 0;
732
312k
    bool crlo_known = false;
733
312k
    unsigned int crhi = 0;
734
312k
    bool crhi_known = false;
735
312k
    bool spmask_skip_operand = false;
736
312k
    unsigned int fcyc_bits = 0;
737
312k
    bool prev_sploop_found = false;
738
739
312k
    switch (opc->operand_info[op_num].form)
740
312k
      {
741
98
      case tic6x_operand_b15reg:
742
        /* Fully determined by the functional unit.  */
743
98
        operands_text[op_num] = true;
744
98
        snprintf (operands[op_num], 24, "b15");
745
98
        continue;
746
747
45
      case tic6x_operand_zreg:
748
        /* Fully determined by the functional unit.  */
749
45
        operands_text[op_num] = true;
750
45
        snprintf (operands[op_num], 24, "%c0",
751
45
      (func_unit_side == 2 ? 'b' : 'a'));
752
45
        continue;
753
754
1.37k
      case tic6x_operand_retreg:
755
        /* Fully determined by the functional unit.  */
756
1.37k
        operands_text[op_num] = true;
757
1.37k
        snprintf (operands[op_num], 24, "%c3",
758
1.37k
      (func_unit_side == 2 ? 'b' : 'a'));
759
1.37k
        continue;
760
761
0
      case tic6x_operand_irp:
762
0
        operands_text[op_num] = true;
763
0
        snprintf (operands[op_num], 24, "irp");
764
0
        continue;
765
766
0
      case tic6x_operand_nrp:
767
0
        operands_text[op_num] = true;
768
0
        snprintf (operands[op_num], 24, "nrp");
769
0
        continue;
770
771
8
      case tic6x_operand_ilc:
772
8
        operands_text[op_num] = true;
773
8
        snprintf (operands[op_num], 24, "ilc");
774
8
        continue;
775
776
4
      case tic6x_operand_hw_const_minus_1:
777
4
        operands_text[op_num] = true;
778
4
        snprintf (operands[op_num], 24, "-1");
779
4
        continue;
780
781
7
      case tic6x_operand_hw_const_0:
782
7
        operands_text[op_num] = true;
783
7
        snprintf (operands[op_num], 24, "0");
784
7
        continue;
785
786
9
      case tic6x_operand_hw_const_1:
787
9
        operands_text[op_num] = true;
788
9
        snprintf (operands[op_num], 24, "1");
789
9
        continue;
790
791
791
      case tic6x_operand_hw_const_5:
792
791
        operands_text[op_num] = true;
793
791
        snprintf (operands[op_num], 24, "5");
794
791
        continue;
795
796
3.47k
      case tic6x_operand_hw_const_16:
797
3.47k
        operands_text[op_num] = true;
798
3.47k
        snprintf (operands[op_num], 24, "16");
799
3.47k
        continue;
800
801
18
      case tic6x_operand_hw_const_24:
802
18
        operands_text[op_num] = true;
803
18
        snprintf (operands[op_num], 24, "24");
804
18
        continue;
805
806
45
      case tic6x_operand_hw_const_31:
807
45
        operands_text[op_num] = true;
808
45
        snprintf (operands[op_num], 24, "31");
809
45
        continue;
810
811
306k
      default:
812
306k
        break;
813
312k
      }
814
815
1.17M
    for (fld_num = 0; fld_num < opc->num_variable_fields; fld_num++)
816
1.17M
      {
817
1.17M
        const tic6x_coding_field *const enc
818
1.17M
    = &opc->variable_fields[fld_num];
819
1.17M
        const tic6x_insn_field *field;
820
1.17M
        unsigned int fld_val;
821
1.17M
        unsigned int reg_base = 0;
822
1.17M
        signed int signed_fld_val;
823
1.17M
              char reg_side = '?';
824
825
1.17M
        if (enc->operand_num != op_num)
826
604k
    continue;
827
570k
        field = tic6x_field_from_fmt (fmt, enc->field_id);
828
570k
        if (!field)
829
0
    {
830
0
      printf ("opcode %x: missing field (field_id:%d) in format\n", opcode, enc->field_id);
831
0
      abort ();
832
0
    }
833
570k
              fld_val = tic6x_field_bits (opcode, field);
834
570k
        switch (enc->coding_method)
835
570k
    {
836
199
                case tic6x_coding_cst_s3i:
837
199
                  (fld_val == 0x00) && (fld_val = 0x10);
838
199
                  (fld_val == 0x07) && (fld_val = 0x08);
839
                  /* Fall through.  */
840
14.2k
    case tic6x_coding_ucst:
841
19.5k
    case tic6x_coding_ulcst_dpr_byte:
842
25.8k
    case tic6x_coding_ulcst_dpr_half:
843
34.5k
    case tic6x_coding_ulcst_dpr_word:
844
34.5k
    case tic6x_coding_lcst_low16:
845
34.5k
      switch (opc->operand_info[op_num].form)
846
34.5k
        {
847
13.9k
        case tic6x_operand_asm_const:
848
14.7k
        case tic6x_operand_link_const:
849
14.7k
          operands_text[op_num] = true;
850
14.7k
          snprintf (operands[op_num], 24, "%u", fld_val);
851
14.7k
          break;
852
853
19.8k
        case tic6x_operand_mem_long:
854
19.8k
          mem_offset = fld_val;
855
19.8k
          mem_offset_known_long = true;
856
19.8k
          break;
857
858
0
        default:
859
0
                      printf ("opcode %x: illegal operand form for operand#%d\n", opcode, op_num);
860
0
          abort ();
861
34.5k
        }
862
34.5k
      break;
863
864
34.5k
    case tic6x_coding_lcst_high16:
865
2.34k
      operands_text[op_num] = true;
866
2.34k
      snprintf (operands[op_num], 24, "%u", fld_val << 16);
867
2.34k
      break;
868
869
673
                case tic6x_coding_scst_l3i:
870
673
      operands_text[op_num] = true;
871
673
                  if (fld_val == 0)
872
94
        {
873
94
          signed_fld_val = 8;
874
94
        }
875
579
      else
876
579
        {
877
579
          signed_fld_val = (signed int) fld_val;
878
579
          signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
879
579
          signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
880
579
        }
881
673
      snprintf (operands[op_num], 24, "%d", signed_fld_val);
882
673
      break;
883
884
10.9k
    case tic6x_coding_scst:
885
10.9k
      operands_text[op_num] = true;
886
10.9k
      signed_fld_val = (signed int) fld_val;
887
10.9k
      signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
888
10.9k
      signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
889
10.9k
      snprintf (operands[op_num], 24, "%d", signed_fld_val);
890
10.9k
      break;
891
892
13.1k
    case tic6x_coding_ucst_minus_one:
893
13.1k
      operands_text[op_num] = true;
894
13.1k
      snprintf (operands[op_num], 24, "%u", fld_val + 1);
895
13.1k
      break;
896
897
5.58k
    case tic6x_coding_pcrel:
898
5.86k
    case tic6x_coding_pcrel_half:
899
5.86k
      signed_fld_val = (signed int) fld_val;
900
5.86k
      signed_fld_val ^= (1 << (tic6x_field_width (field) - 1));
901
5.86k
      signed_fld_val -= (1 << (tic6x_field_width (field) - 1));
902
5.86k
      if (fetch_packet_header_based
903
456
          && enc->coding_method == tic6x_coding_pcrel_half)
904
251
        signed_fld_val *= 2;
905
5.61k
      else
906
5.61k
        signed_fld_val *= 4;
907
5.86k
      operands_pcrel[op_num] = true;
908
5.86k
      operands_addresses[op_num] = fp_addr + signed_fld_val;
909
5.86k
      break;
910
911
209
    case tic6x_coding_regpair_msb:
912
209
      if (opc->operand_info[op_num].form != tic6x_operand_regpair)
913
0
        abort ();
914
209
      operands_text[op_num] = true;
915
209
      snprintf (operands[op_num], 24, "%c%u:%c%u",
916
209
          (func_unit_side == 2 ? 'b' : 'a'), (fld_val | 0x1),
917
209
          (func_unit_side == 2 ? 'b' : 'a'), (fld_val | 0x1) - 1);
918
209
      break;
919
920
791
    case tic6x_coding_pcrel_half_unsigned:
921
791
      operands_pcrel[op_num] = true;
922
791
      operands_addresses[op_num] = fp_addr + 2 * fld_val;
923
791
      break;
924
925
4.66k
    case tic6x_coding_reg_shift:
926
4.66k
      fld_val <<= 1;
927
      /* Fall through.  */
928
232k
    case tic6x_coding_reg:
929
232k
                  if (num_bits == 16 && header.rs && !(opc->flags & TIC6X_FLAG_INSN16_NORS))
930
6.89k
                    {
931
6.89k
          reg_base = 16;
932
6.89k
                    }
933
232k
      switch (opc->operand_info[op_num].form)
934
232k
        {
935
1.92k
        case tic6x_operand_treg:
936
1.92k
                      if (!have_t)
937
0
      {
938
0
        printf ("opcode %x: operand treg but missing t field\n", opcode);
939
0
        abort ();
940
0
      }
941
1.92k
          operands_text[op_num] = true;
942
1.92k
                      reg_side = t_val ? 'b' : 'a';
943
1.92k
          snprintf (operands[op_num], 24, "%c%u", reg_side, reg_base + fld_val);
944
1.92k
          break;
945
946
92.8k
        case tic6x_operand_reg:
947
92.8k
          operands_text[op_num] = true;
948
92.8k
                      reg_side = (func_unit_side == 2) ? 'b' : 'a';
949
92.8k
          snprintf (operands[op_num], 24, "%c%u", reg_side,  reg_base + fld_val);
950
92.8k
          break;
951
952
230
        case tic6x_operand_reg_nors:
953
230
          operands_text[op_num] = true;
954
230
                      reg_side = (func_unit_side == 2) ? 'b' : 'a';
955
230
          snprintf (operands[op_num], 24, "%c%u", reg_side, fld_val);
956
230
          break;
957
958
8
        case tic6x_operand_reg_bside:
959
8
          operands_text[op_num] = true;
960
8
          snprintf (operands[op_num], 24, "b%u", reg_base + fld_val);
961
8
          break;
962
963
270
        case tic6x_operand_reg_bside_nors:
964
270
          operands_text[op_num] = true;
965
270
          snprintf (operands[op_num], 24, "b%u", fld_val);
966
270
          break;
967
968
46.1k
        case tic6x_operand_xreg:
969
46.1k
          operands_text[op_num] = true;
970
46.1k
                      reg_side = ((func_unit_side == 2) ^ func_unit_cross) ? 'b' : 'a';
971
46.1k
          snprintf (operands[op_num], 24, "%c%u", reg_side,  reg_base + fld_val);
972
46.1k
          break;
973
974
37.1k
        case tic6x_operand_dreg:
975
37.1k
          operands_text[op_num] = true;
976
37.1k
                      reg_side = (func_unit_data_side == 2) ? 'b' : 'a';
977
37.1k
          snprintf (operands[op_num], 24, "%c%u", reg_side,  reg_base + fld_val);
978
37.1k
          break;
979
980
21.7k
        case tic6x_operand_regpair:
981
21.7k
          operands_text[op_num] = true;
982
21.7k
          if (fld_val & 1)
983
3.82k
      operands_ok = false;
984
21.7k
                      reg_side = (func_unit_side == 2) ? 'b' : 'a';
985
21.7k
          snprintf (operands[op_num], 24, "%c%u:%c%u",
986
21.7k
                                reg_side, reg_base + fld_val + 1,
987
21.7k
        reg_side, reg_base + fld_val);
988
21.7k
          break;
989
990
1.68k
        case tic6x_operand_xregpair:
991
1.68k
          operands_text[op_num] = true;
992
1.68k
          if (fld_val & 1)
993
771
      operands_ok = false;
994
1.68k
                      reg_side = ((func_unit_side == 2) ^ func_unit_cross) ? 'b' : 'a';
995
1.68k
          snprintf (operands[op_num], 24, "%c%u:%c%u",
996
1.68k
        reg_side, reg_base + fld_val + 1,
997
1.68k
        reg_side, reg_base + fld_val);
998
1.68k
          break;
999
1000
900
        case tic6x_operand_tregpair:
1001
900
                      if (!have_t)
1002
0
      {
1003
0
        printf ("opcode %x: operand tregpair but missing t field\n", opcode);
1004
0
        abort ();
1005
0
      }
1006
900
          operands_text[op_num] = true;
1007
900
          if (fld_val & 1)
1008
6
      operands_ok = false;
1009
900
                      reg_side = t_val ? 'b' : 'a';
1010
900
          snprintf (operands[op_num], 24, "%c%u:%c%u",
1011
900
        reg_side, reg_base + fld_val + 1,
1012
900
        reg_side, reg_base + fld_val);
1013
900
          break;
1014
1015
6.04k
        case tic6x_operand_dregpair:
1016
6.04k
          operands_text[op_num] = true;
1017
6.04k
          if (fld_val & 1)
1018
690
      operands_ok = false;
1019
6.04k
                      reg_side = (func_unit_data_side) == 2 ? 'b' : 'a';
1020
6.04k
          snprintf (operands[op_num], 24, "%c%u:%c%u",
1021
6.04k
        reg_side, reg_base + fld_val + 1,
1022
6.04k
        reg_side, reg_base + fld_val);
1023
6.04k
          break;
1024
1025
10
        case tic6x_operand_mem_deref:
1026
10
          operands_text[op_num] = true;
1027
10
                      reg_side = func_unit_side == 2 ? 'b' : 'a';
1028
10
          snprintf (operands[op_num], 24, "*%c%u", reg_side, reg_base + fld_val);
1029
10
          break;
1030
1031
20.1k
        case tic6x_operand_mem_short:
1032
23.3k
        case tic6x_operand_mem_ndw:
1033
23.3k
          mem_base_reg = fld_val;
1034
23.3k
          mem_base_reg_known = true;
1035
23.3k
          break;
1036
1037
0
        default:
1038
0
                      printf ("opcode %x: unexpected operand form %d for operand #%d",
1039
0
            opcode, opc->operand_info[op_num].form, op_num);
1040
0
          abort ();
1041
232k
        }
1042
232k
      break;
1043
1044
232k
                case tic6x_coding_reg_ptr:
1045
2.27k
      switch (opc->operand_info[op_num].form)
1046
2.27k
        {
1047
2.04k
        case tic6x_operand_mem_short:
1048
2.27k
        case tic6x_operand_mem_ndw:
1049
2.27k
                      if (fld_val > 0x3u)
1050
0
      {
1051
0
        printf("opcode %x: illegal field value for ptr register of operand #%d (%d)",
1052
0
         opcode, op_num, fld_val);
1053
0
        abort ();
1054
0
      }
1055
2.27k
          mem_base_reg = 0x4 | fld_val;
1056
2.27k
          mem_base_reg_known = true;
1057
2.27k
          break;
1058
1059
0
        default:
1060
0
                      printf ("opcode %x: unexpected operand form %d for operand #%d",
1061
0
            opcode, opc->operand_info[op_num].form, op_num);
1062
0
          abort ();
1063
2.27k
        }
1064
2.27k
      break;
1065
1066
20.2k
    case tic6x_coding_areg:
1067
20.2k
      switch (opc->operand_info[op_num].form)
1068
20.2k
        {
1069
437
        case tic6x_operand_areg:
1070
437
          operands_text[op_num] = true;
1071
437
          snprintf (operands[op_num], 24, "b%u",
1072
437
        fld_val ? 15u : 14u);
1073
437
          break;
1074
1075
19.8k
        case tic6x_operand_mem_long:
1076
19.8k
          mem_base_reg = fld_val ? 15u : 14u;
1077
19.8k
          mem_base_reg_known_long = true;
1078
19.8k
          break;
1079
1080
0
        default:
1081
0
                      printf ("opcode %x: bad operand form\n", opcode);
1082
0
          abort ();
1083
20.2k
        }
1084
20.2k
      break;
1085
1086
20.2k
    case tic6x_coding_mem_offset_minus_one_noscale:
1087
507
    case tic6x_coding_mem_offset_minus_one:
1088
507
      fld_val += 1;
1089
      /* Fall through.  */
1090
3.92k
    case tic6x_coding_mem_offset_noscale:
1091
26.2k
    case tic6x_coding_mem_offset:
1092
26.2k
      mem_offset = fld_val;
1093
26.2k
      mem_offset_known = true;
1094
26.2k
      if (num_bits == 16)
1095
2.82k
        {
1096
2.82k
          mem_mode_known = true;
1097
2.82k
          mem_mode = TIC6X_INSN16_MEM_MODE_VAL (opc->flags);
1098
2.82k
          mem_scaled_known = true;
1099
2.82k
          mem_scaled = true;
1100
2.82k
          if (opc->flags & TIC6X_FLAG_INSN16_B15PTR)
1101
545
      {
1102
545
        mem_base_reg_known = true;
1103
545
        mem_base_reg = 15;
1104
545
      }
1105
2.82k
          if ( enc->coding_method == tic6x_coding_mem_offset_noscale
1106
2.64k
         || enc->coding_method == tic6x_coding_mem_offset_noscale )
1107
175
      mem_scaled = false;
1108
2.82k
        }
1109
26.2k
      break;
1110
1111
23.3k
    case tic6x_coding_mem_mode:
1112
23.3k
      mem_mode = fld_val;
1113
23.3k
      mem_mode_known = true;
1114
23.3k
      break;
1115
1116
3.23k
    case tic6x_coding_scaled:
1117
3.23k
      mem_scaled = fld_val;
1118
3.23k
      mem_scaled_known = true;
1119
3.23k
      break;
1120
1121
1.11k
    case tic6x_coding_crlo:
1122
1.11k
      crlo = fld_val;
1123
1.11k
      crlo_known = true;
1124
1.11k
      break;
1125
1126
1.11k
    case tic6x_coding_crhi:
1127
1.11k
      crhi = fld_val;
1128
1.11k
      crhi_known = true;
1129
1.11k
      break;
1130
1131
96
    case tic6x_coding_fstg:
1132
192
    case tic6x_coding_fcyc:
1133
192
      if (!prev_sploop_found)
1134
192
        {
1135
192
          bfd_vma search_fp_addr = fp_addr;
1136
192
          bfd_vma search_fp_offset = fp_offset;
1137
192
          bool search_fp_header_based
1138
192
      = fetch_packet_header_based;
1139
192
          tic6x_fetch_packet_header search_fp_header = header;
1140
192
          unsigned char search_fp[32];
1141
192
          unsigned int search_num_bits;
1142
192
          unsigned int search_opcode;
1143
192
          unsigned int sploop_ii = 0;
1144
192
          int i;
1145
1146
192
          memcpy (search_fp, fp, 32);
1147
1148
          /* To interpret these bits in an SPKERNEL
1149
       instruction, we must find the previous
1150
       SPLOOP-family instruction.  It may come up to
1151
       48 execute packets earlier.  */
1152
48.2k
          for (i = 0; i < 48 * 8; i++)
1153
48.2k
      {
1154
        /* Find the previous instruction.  */
1155
48.2k
        if (search_fp_offset & 2)
1156
440
          search_fp_offset -= 2;
1157
47.7k
        else if (search_fp_offset >= 4)
1158
41.6k
          {
1159
41.6k
            if (search_fp_header_based
1160
734
          && (search_fp_header.word_compact
1161
734
              [(search_fp_offset >> 2) - 1]))
1162
336
        search_fp_offset -= 2;
1163
41.3k
            else
1164
41.3k
        search_fp_offset -= 4;
1165
41.6k
          }
1166
6.09k
        else
1167
6.09k
          {
1168
6.09k
            search_fp_addr -= 32;
1169
6.09k
            status = info->read_memory_func (search_fp_addr,
1170
6.09k
                     search_fp,
1171
6.09k
                     32, info);
1172
6.09k
            if (status)
1173
        /* No previous SPLOOP instruction.  */
1174
156
        break;
1175
5.94k
            search_fp_header_based
1176
5.94k
        = (tic6x_check_fetch_packet_header
1177
5.94k
           (search_fp, &search_fp_header, info));
1178
5.94k
            if (search_fp_header_based)
1179
80
        search_fp_offset
1180
80
          = search_fp_header.word_compact[6] ? 26 : 24;
1181
5.86k
            else
1182
5.86k
        search_fp_offset = 28;
1183
5.94k
          }
1184
1185
        /* Extract the previous instruction.  */
1186
48.0k
        if (search_fp_header_based)
1187
1.25k
          search_num_bits
1188
1.25k
            = (search_fp_header.word_compact[search_fp_offset
1189
1.25k
                     >> 2]
1190
1.25k
         ? 16
1191
1.25k
         : 32);
1192
46.8k
        else
1193
46.8k
          search_num_bits = 32;
1194
48.0k
        if (search_num_bits == 16)
1195
796
          {
1196
796
            if (info->endian == BFD_ENDIAN_LITTLE)
1197
0
        search_opcode
1198
0
          = (tic6x_extract_16
1199
0
             (search_fp + search_fp_offset, &header, info));
1200
796
            else
1201
796
        search_opcode
1202
796
          = (tic6x_extract_16
1203
796
             (search_fp + (search_fp_offset ^ 2), &header,
1204
796
              info));
1205
796
          }
1206
47.2k
        else
1207
47.2k
          search_opcode
1208
47.2k
            = tic6x_extract_32 (search_fp + search_fp_offset,
1209
47.2k
              info);
1210
1211
        /* Check whether it is an SPLOOP-family
1212
           instruction.  */
1213
48.0k
        if (search_num_bits == 32
1214
47.2k
            && ((search_opcode & 0x003ffffe) == 0x00038000
1215
47.2k
          || (search_opcode & 0x003ffffe) == 0x0003a000
1216
47.2k
          || ((search_opcode & 0x003ffffe)
1217
47.2k
              == 0x0003e000)))
1218
0
          {
1219
0
            prev_sploop_found = true;
1220
0
            sploop_ii = ((search_opcode >> 23) & 0x1f) + 1;
1221
0
          }
1222
48.0k
        else if (search_num_bits == 16
1223
796
           && (search_opcode & 0x3c7e) == 0x0c66)
1224
0
          {
1225
0
            prev_sploop_found = true;
1226
0
            sploop_ii
1227
0
        = (((search_opcode >> 7) & 0x7)
1228
0
           | ((search_opcode >> 11) & 0x8)) + 1;
1229
0
          }
1230
48.0k
        if (prev_sploop_found)
1231
0
          {
1232
0
            if (sploop_ii <= 0)
1233
0
        {
1234
0
          printf ("opcode %x:  sloop index not found (%d)\n", opcode, sploop_ii);
1235
0
          abort ();
1236
0
        }
1237
0
            else if (sploop_ii <= 1)
1238
0
        fcyc_bits = 0;
1239
0
            else if (sploop_ii <= 2)
1240
0
        fcyc_bits = 1;
1241
0
            else if (sploop_ii <= 4)
1242
0
        fcyc_bits = 2;
1243
0
            else if (sploop_ii <= 8)
1244
0
        fcyc_bits = 3;
1245
0
            else if (sploop_ii <= 14)
1246
0
        fcyc_bits = 4;
1247
0
            else
1248
0
        prev_sploop_found = false;
1249
0
          }
1250
48.0k
        if (prev_sploop_found)
1251
0
          break;
1252
48.0k
      }
1253
192
        }
1254
192
      if (!prev_sploop_found)
1255
192
        {
1256
192
          operands_ok = false;
1257
192
          operands_text[op_num] = true;
1258
192
          break;
1259
192
        }
1260
0
      if (fcyc_bits > tic6x_field_width(field))
1261
0
        {
1262
0
          printf ("opcode %x: illegal fcyc value (%d)\n", opcode, fcyc_bits);
1263
0
          abort ();
1264
0
        }
1265
0
      if (enc->coding_method == tic6x_coding_fstg)
1266
0
        {
1267
0
          int i, t;
1268
0
          for (t = 0, i = fcyc_bits; i < 6; i++)
1269
0
      t = (t << 1) | ((fld_val >> i) & 1);
1270
0
          operands_text[op_num] = true;
1271
0
          snprintf (operands[op_num], 24, "%u", t);
1272
0
        }
1273
0
      else
1274
0
        {
1275
0
          operands_text[op_num] = true;
1276
0
          snprintf (operands[op_num], 24, "%u",
1277
0
        fld_val & ((1 << fcyc_bits) - 1));
1278
0
        }
1279
0
      break;
1280
1281
832
    case tic6x_coding_spmask:
1282
832
      if (fld_val == 0)
1283
58
        spmask_skip_operand = true;
1284
774
      else
1285
774
        {
1286
774
          char *p;
1287
774
          unsigned int i;
1288
1289
774
          operands_text[op_num] = true;
1290
774
          p = operands[op_num];
1291
6.96k
          for (i = 0; i < 8; i++)
1292
6.19k
      if (fld_val & (1 << i))
1293
2.60k
        {
1294
2.60k
          *p++ = "LSDM"[i/2];
1295
2.60k
          *p++ = '1' + (i & 1);
1296
2.60k
          *p++ = ',';
1297
2.60k
        }
1298
774
          p[-1] = 0;
1299
774
        }
1300
832
      break;
1301
1302
97.1k
    case tic6x_coding_fu:
1303
140k
    case tic6x_coding_data_fu:
1304
187k
    case tic6x_coding_xpath:
1305
190k
    case tic6x_coding_rside:
1306
      /* Don't relate to operands, so operand number is
1307
         meaningless.  */
1308
190k
      break;
1309
1310
0
    default:
1311
0
                  printf ("opcode %x: illegal field encoding (%d)\n", opcode, enc->coding_method);
1312
0
      abort ();
1313
570k
    }
1314
1315
570k
        if (mem_base_reg_known_long && mem_offset_known_long)
1316
19.8k
    {
1317
19.8k
      if (operands_text[op_num] || operands_pcrel[op_num])
1318
0
        {
1319
0
          printf ("opcode %x: long access but operands already known ?\n", opcode);
1320
0
          abort ();
1321
0
        }
1322
19.8k
      operands_text[op_num] = true;
1323
19.8k
      snprintf (operands[op_num], 24, "*+b%u(%u)", mem_base_reg,
1324
19.8k
          mem_offset * opc->operand_info[op_num].size);
1325
19.8k
    }
1326
1327
570k
        if (mem_base_reg_known && mem_offset_known && mem_mode_known
1328
29.4k
      && (mem_scaled_known
1329
23.3k
          || (opc->operand_info[op_num].form
1330
23.3k
        != tic6x_operand_mem_ndw)))
1331
26.2k
    {
1332
26.2k
      char side;
1333
26.2k
      char base[4];
1334
26.2k
      bool offset_is_reg;
1335
26.2k
      bool offset_scaled;
1336
26.2k
      char offset[4];
1337
26.2k
      char offsetp[6];
1338
1339
26.2k
      if (operands_text[op_num] || operands_pcrel[op_num])
1340
0
        {
1341
0
          printf ("opcode %x: mem access operands already known ?\n", opcode);
1342
0
          abort ();
1343
0
        }
1344
1345
26.2k
      side = func_unit_side == 2 ? 'b' : 'a';
1346
26.2k
      snprintf (base, 4, "%c%u", side, mem_base_reg);
1347
1348
26.2k
      offset_is_reg = (mem_mode & 4) != 0;
1349
26.2k
      if (offset_is_reg)
1350
8.11k
        {
1351
1352
8.11k
          if (num_bits == 16 && header.rs && !(opc->flags & TIC6X_FLAG_INSN16_NORS))
1353
348
      {
1354
348
        reg_base = 16;
1355
348
      }
1356
8.11k
          snprintf (offset, 4, "%c%u", side, reg_base + mem_offset);
1357
8.11k
          if (opc->operand_info[op_num].form
1358
8.11k
        == tic6x_operand_mem_ndw)
1359
1.11k
      offset_scaled = mem_scaled != 0;
1360
7.00k
          else
1361
7.00k
      offset_scaled = true;
1362
8.11k
        }
1363
18.0k
      else
1364
18.0k
        {
1365
18.0k
          if (opc->operand_info[op_num].form
1366
18.0k
        == tic6x_operand_mem_ndw)
1367
2.35k
      {
1368
2.35k
        offset_scaled = mem_scaled != 0;
1369
2.35k
        snprintf (offset, 4, "%u", mem_offset);
1370
2.35k
      }
1371
15.7k
          else
1372
15.7k
      {
1373
15.7k
        offset_scaled = false;
1374
15.7k
        snprintf (offset, 4, "%u",
1375
15.7k
            (mem_offset
1376
15.7k
             * opc->operand_info[op_num].size));
1377
15.7k
      }
1378
18.0k
        }
1379
1380
26.2k
      if (offset_scaled)
1381
7.80k
        snprintf (offsetp, 6, "[%s]", offset);
1382
18.4k
      else
1383
18.4k
        snprintf (offsetp, 6, "(%s)", offset);
1384
1385
26.2k
      operands_text[op_num] = true;
1386
26.2k
      switch (mem_mode & ~4u)
1387
26.2k
        {
1388
5.52k
        case 0:
1389
5.52k
          snprintf (operands[op_num], 24, "*-%s%s", base, offsetp);
1390
5.52k
          break;
1391
1392
4.67k
        case 1:
1393
4.67k
          snprintf (operands[op_num], 24, "*+%s%s", base, offsetp);
1394
4.67k
          break;
1395
1396
2.80k
        case 2:
1397
5.55k
        case 3:
1398
5.55k
          operands_ok = false;
1399
5.55k
          break;
1400
1401
2.95k
        case 8:
1402
2.95k
          snprintf (operands[op_num], 24, "*--%s%s", base,
1403
2.95k
        offsetp);
1404
2.95k
          break;
1405
1406
1.52k
        case 9:
1407
1.52k
          snprintf (operands[op_num], 24, "*++%s%s", base,
1408
1.52k
        offsetp);
1409
1.52k
          break;
1410
1411
2.47k
        case 10:
1412
2.47k
          snprintf (operands[op_num], 24, "*%s--%s", base,
1413
2.47k
        offsetp);
1414
2.47k
          break;
1415
1416
3.49k
        case 11:
1417
3.49k
          snprintf (operands[op_num], 24, "*%s++%s", base,
1418
3.49k
        offsetp);
1419
3.49k
          break;
1420
1421
0
        default:
1422
0
                      printf ("*** unknown mem_mode : %d \n", mem_mode);
1423
0
          abort ();
1424
26.2k
        }
1425
26.2k
    }
1426
1427
570k
        if (crlo_known && crhi_known)
1428
1.11k
    {
1429
1.11k
      tic6x_rw rw;
1430
1.11k
      tic6x_ctrl_id crid;
1431
1432
1.11k
      if (operands_text[op_num] || operands_pcrel[op_num])
1433
0
        {
1434
0
          printf ("*** abort crlo crli\n");
1435
0
          abort ();
1436
0
        }
1437
1438
1.11k
      rw = opc->operand_info[op_num].rw;
1439
1.11k
      if (rw != tic6x_rw_read
1440
930
          && rw != tic6x_rw_write)
1441
0
        {
1442
0
          printf ("*** abort rw : %d\n", rw);
1443
0
          abort ();
1444
0
        }
1445
1446
31.5k
      for (crid = 0; crid < tic6x_ctrl_max; crid++)
1447
30.5k
        {
1448
30.5k
          if (crlo == tic6x_ctrl_table[crid].crlo
1449
1.09k
        && (crhi & tic6x_ctrl_table[crid].crhi_mask) == 0
1450
102
        && (rw == tic6x_rw_read
1451
102
            ? (tic6x_ctrl_table[crid].rw == tic6x_rw_read
1452
81
         || (tic6x_ctrl_table[crid].rw
1453
81
             == tic6x_rw_read_write))
1454
102
            : (tic6x_ctrl_table[crid].rw == tic6x_rw_write
1455
14
         || (tic6x_ctrl_table[crid].rw
1456
14
             == tic6x_rw_read_write))))
1457
90
      break;
1458
30.5k
        }
1459
1.11k
      if (crid == tic6x_ctrl_max)
1460
1.02k
        {
1461
1.02k
          operands_text[op_num] = true;
1462
1.02k
          operands_ok = false;
1463
1.02k
        }
1464
90
      else
1465
90
        {
1466
90
          operands_text[op_num] = true;
1467
90
          snprintf (operands[op_num], 24, "%s",
1468
90
        tic6x_ctrl_table[crid].name);
1469
90
        }
1470
1.11k
    }
1471
1472
570k
        if (operands_text[op_num] || operands_pcrel[op_num]
1473
263k
      || spmask_skip_operand)
1474
306k
    break;
1475
570k
      }
1476
          /* end for fld_num */
1477
1478
306k
    if (spmask_skip_operand)
1479
58
      {
1480
        /* SPMASK operands are only valid as the single operand
1481
     in the opcode table.  */
1482
58
        if (num_operands != 1)
1483
0
    {
1484
0
      printf ("opcode: %x, num_operands != 1 : %d\n", opcode, num_operands);
1485
0
      abort ();
1486
0
    }
1487
58
        num_operands = 0;
1488
58
        break;
1489
58
      }
1490
1491
    /* The operand must by now have been decoded.  */
1492
306k
    if (!operands_text[op_num] && !operands_pcrel[op_num])
1493
0
            {
1494
0
              printf ("opcode: %x, operand #%d not decoded\n", opcode, op_num);
1495
0
              abort ();
1496
0
            }
1497
306k
        }
1498
      /* end for op_num */
1499
1500
132k
      if (!operands_ok)
1501
10.8k
  continue;
1502
1503
121k
      info->bytes_per_chunk = num_bits / 8;
1504
121k
      info->fprintf_func (info->stream, "%s", parallel);
1505
121k
      info->fprintf_func (info->stream, "%s%s%s", cond, opc->name,
1506
121k
                          func_unit);
1507
408k
      for (op_num = 0; op_num < num_operands; op_num++)
1508
286k
  {
1509
286k
    info->fprintf_func (info->stream, "%c", (op_num == 0 ? ' ' : ','));
1510
286k
    if (operands_pcrel[op_num])
1511
6.65k
      info->print_address_func (operands_addresses[op_num], info);
1512
280k
    else
1513
280k
      info->fprintf_func (info->stream, "%s", operands[op_num]);
1514
286k
  }
1515
121k
      if (fetch_packet_header_based && header.prot)
1516
2.46k
  info->fprintf_func (info->stream, " || nop 5");
1517
1518
121k
      return num_bits / 8;
1519
132k
    }
1520
1521
63.7k
  info->bytes_per_chunk = num_bits / 8;
1522
63.7k
  info->fprintf_func (info->stream, "<undefined instruction 0x%.*x>",
1523
63.7k
          (int) num_bits / 4, opcode);
1524
63.7k
  return num_bits / 8;
1525
185k
}