Coverage Report

Created: 2026-09-14 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/tilepro-dis.c
Line
Count
Source
1
/* tilepro-dis.c.  Disassembly routines for the TILEPro architecture.
2
   Copyright (C) 2011-2026 Free Software Foundation, Inc.
3
4
   This file is part of the GNU opcodes library.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include <stddef.h>
23
#include <assert.h>
24
#include "bfd.h"
25
#include "elf/tilepro.h"
26
#include "elf-bfd.h"
27
#include "disassemble.h"
28
#include "opcode/tilepro.h"
29
30
31
3.35k
#define TREG_ZERO 63
32
33
static int
34
contains_insn (tilepro_mnemonic expected_mnemonic,
35
         int expected_first_operand,
36
         int expected_second_operand,
37
         bfd_vma memaddr,
38
         int *last_operand_ret,
39
         disassemble_info *info)
40
8.28k
{
41
8.28k
  struct tilepro_decoded_instruction
42
8.28k
    decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
43
8.28k
  bfd_byte opbuf[TILEPRO_BUNDLE_SIZE_IN_BYTES];
44
8.28k
  int i, num_instructions;
45
46
8.28k
  if ((*info->read_memory_func) (memaddr, opbuf,
47
8.28k
         TILEPRO_BUNDLE_SIZE_IN_BYTES, info) != 0)
48
    /* If we cannot even read the memory, it obviously does not have the
49
       instruction for which we are looking. */
50
4.50k
    return 0;
51
52
  /* Parse the instructions in the bundle. */
53
3.77k
  num_instructions = parse_insn_tilepro (bfd_getl64 (opbuf), memaddr, decoded);
54
55
11.7k
  for (i = 0; i < num_instructions; i++)
56
8.02k
    {
57
8.02k
      const struct tilepro_opcode *opcode = decoded[i].opcode;
58
59
8.02k
      if (opcode->mnemonic != expected_mnemonic)
60
7.33k
  continue;
61
62
695
      if (expected_first_operand != -1
63
695
    && decoded[i].operand_values[0] != expected_first_operand)
64
381
  continue;
65
66
314
      if (expected_second_operand != -1
67
314
    && decoded[i].operand_values[1] != expected_second_operand)
68
314
  continue;
69
70
0
      *last_operand_ret = decoded[i].operand_values[opcode->num_operands - 1];
71
0
      return 1;
72
314
    }
73
74
  /* No match. */
75
3.77k
  return 0;
76
3.77k
}
77
78
79
int
80
print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
81
40.2k
{
82
40.2k
  struct tilepro_decoded_instruction
83
40.2k
    decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE];
84
40.2k
  bfd_byte opbuf[TILEPRO_BUNDLE_SIZE_IN_BYTES];
85
40.2k
  int status, i, num_instructions, num_printed;
86
40.2k
  tilepro_mnemonic padding_mnemonic;
87
88
40.2k
  status = (*info->read_memory_func) (memaddr, opbuf,
89
40.2k
                                      TILEPRO_BUNDLE_SIZE_IN_BYTES, info);
90
40.2k
  if (status != 0)
91
195
    {
92
195
      (*info->memory_error_func) (status, memaddr, info);
93
195
      return -1;
94
195
    }
95
96
40.0k
  info->bytes_per_line = TILEPRO_BUNDLE_SIZE_IN_BYTES;
97
40.0k
  info->bytes_per_chunk = TILEPRO_BUNDLE_SIZE_IN_BYTES;
98
40.0k
  info->octets_per_byte = 1;
99
40.0k
  info->display_endian = BFD_ENDIAN_LITTLE;
100
101
  /* Parse the instructions in the bundle.  */
102
40.0k
  num_instructions = parse_insn_tilepro (bfd_getl64 (opbuf), memaddr, decoded);
103
104
  /* Print the instructions in the bundle.  */
105
40.0k
  info->fprintf_func (info->stream, "{ ");
106
40.0k
  num_printed = 0;
107
108
  /* Determine which nop opcode is used for padding and should be skipped.  */
109
40.0k
  padding_mnemonic = TILEPRO_OPC_FNOP;
110
87.5k
  for (i = 0; i < num_instructions; i++)
111
72.3k
    {
112
72.3k
      if (!decoded[i].opcode->can_bundle)
113
24.8k
  {
114
    /* Instructions that cannot be bundled are padded out with nops,
115
       rather than fnops. Displaying them is always clutter.  */
116
24.8k
    padding_mnemonic = TILEPRO_OPC_NOP;
117
24.8k
    break;
118
24.8k
  }
119
72.3k
    }
120
121
133k
  for (i = 0; i < num_instructions; i++)
122
93.6k
    {
123
93.6k
      const struct tilepro_opcode *opcode = decoded[i].opcode;
124
93.6k
      const char *name;
125
93.6k
      int j;
126
127
      /* Do not print out fnops, unless everything is an fnop, in
128
   which case we will print out just the last one.  */
129
93.6k
      if (opcode->mnemonic == padding_mnemonic
130
108
    && (num_printed > 0 || i + 1 < num_instructions))
131
108
  continue;
132
133
93.5k
      if (num_printed > 0)
134
53.4k
  info->fprintf_func (info->stream, " ; ");
135
93.5k
      ++num_printed;
136
137
93.5k
      name = opcode->name;
138
93.5k
      if (name == NULL)
139
34.1k
  name = "<invalid>";
140
93.5k
      info->fprintf_func (info->stream, "%s", name);
141
142
257k
      for (j = 0; j < opcode->num_operands; j++)
143
164k
  {
144
164k
    int num;
145
164k
    const struct tilepro_operand *op;
146
164k
    const char *spr_name;
147
148
164k
    if (j > 0)
149
104k
      info->fprintf_func (info->stream, ",");
150
164k
    info->fprintf_func (info->stream, " ");
151
152
164k
    num = decoded[i].operand_values[j];
153
154
164k
    op = decoded[i].operands[j];
155
164k
    switch (op->type)
156
164k
      {
157
124k
      case TILEPRO_OP_TYPE_REGISTER:
158
124k
        info->fprintf_func (info->stream, "%s",
159
124k
          tilepro_register_names[num]);
160
124k
        break;
161
162
226
      case TILEPRO_OP_TYPE_SPR:
163
226
        spr_name = get_tilepro_spr_name(num);
164
226
        if (spr_name != NULL)
165
88
    info->fprintf_func (info->stream, "%s", spr_name);
166
138
        else
167
138
    info->fprintf_func (info->stream, "%d", num);
168
226
        break;
169
170
34.3k
      case TILEPRO_OP_TYPE_IMMEDIATE:
171
34.3k
        {
172
34.3k
    bfd_vma addr = 0;
173
34.3k
    int found_addr = 0;
174
34.3k
    int addr_piece;
175
176
34.3k
    switch (opcode->mnemonic)
177
34.3k
      {
178
3.35k
      case TILEPRO_OPC_ADDLI:
179
3.35k
        if (contains_insn (TILEPRO_OPC_AULI,
180
3.35k
               decoded[i].operand_values[1],
181
3.35k
               TREG_ZERO,
182
3.35k
               memaddr - TILEPRO_BUNDLE_SIZE_IN_BYTES,
183
3.35k
               &addr_piece,
184
3.35k
               info))
185
0
          {
186
0
      addr = num + (addr_piece << 16);
187
0
      found_addr = 1;
188
0
          }
189
3.35k
        break;
190
191
4.92k
      case TILEPRO_OPC_AULI:
192
4.92k
        if (contains_insn (TILEPRO_OPC_MOVELI,
193
4.92k
               decoded[i].operand_values[1],
194
4.92k
               -1,
195
4.92k
               memaddr - TILEPRO_BUNDLE_SIZE_IN_BYTES,
196
4.92k
               &addr_piece,
197
4.92k
               info))
198
0
          {
199
0
      addr = (num << 16) + addr_piece;
200
0
      found_addr = 1;
201
0
          }
202
4.92k
        break;
203
204
26.0k
      default:
205
        /* Operand does not look like a constructed address.  */
206
26.0k
        break;
207
34.3k
      }
208
209
34.3k
    info->fprintf_func (info->stream, "%d", num);
210
211
34.3k
    if (found_addr)
212
0
      {
213
0
        info->fprintf_func (info->stream, " /* ");
214
0
        info->print_address_func (addr, info);
215
0
        info->fprintf_func (info->stream, " */");
216
0
      }
217
34.3k
        }
218
0
        break;
219
220
5.31k
      case TILEPRO_OP_TYPE_ADDRESS:
221
5.31k
        info->print_address_func ((bfd_vma)(unsigned int) num, info);
222
5.31k
        break;
223
224
0
      default:
225
0
        abort ();
226
164k
      }
227
164k
  }
228
93.5k
    }
229
40.0k
  info->fprintf_func (info->stream, " }");
230
231
40.0k
  return TILEPRO_BUNDLE_SIZE_IN_BYTES;
232
40.0k
}