Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/tilegx-dis.c
Line
Count
Source
1
/* tilegx-dis.c.  Disassembly routines for the TILE-Gx 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/tilegx.h"
26
#include "elf-bfd.h"
27
#include "disassemble.h"
28
#include "opcode/tilegx.h"
29
30
31
int
32
print_insn_tilegx (bfd_vma memaddr, disassemble_info *info)
33
33.3k
{
34
33.3k
  struct tilegx_decoded_instruction
35
33.3k
    decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE];
36
33.3k
  bfd_byte opbuf[TILEGX_BUNDLE_SIZE_IN_BYTES];
37
33.3k
  int status, i, num_instructions, num_printed;
38
33.3k
  tilegx_mnemonic padding_mnemonic;
39
40
33.3k
  status = (*info->read_memory_func) (memaddr, opbuf,
41
33.3k
                                      TILEGX_BUNDLE_SIZE_IN_BYTES, info);
42
33.3k
  if (status != 0)
43
121
    {
44
121
      (*info->memory_error_func) (status, memaddr, info);
45
121
      return -1;
46
121
    }
47
48
33.2k
  info->bytes_per_line = TILEGX_BUNDLE_SIZE_IN_BYTES;
49
33.2k
  info->bytes_per_chunk = TILEGX_BUNDLE_SIZE_IN_BYTES;
50
33.2k
  info->octets_per_byte = 1;
51
33.2k
  info->display_endian = BFD_ENDIAN_LITTLE;
52
53
  /* Parse the instructions in the bundle.  */
54
33.2k
  num_instructions =
55
33.2k
    parse_insn_tilegx (bfd_getl64 (opbuf), memaddr, decoded);
56
57
  /* Print the instructions in the bundle.  */
58
33.2k
  info->fprintf_func (info->stream, "{ ");
59
33.2k
  num_printed = 0;
60
61
  /* Determine which nop opcode is used for padding and should be skipped.  */
62
33.2k
  padding_mnemonic = TILEGX_OPC_FNOP;
63
78.8k
  for (i = 0; i < num_instructions; i++)
64
65.6k
    {
65
65.6k
      if (!decoded[i].opcode->can_bundle)
66
20.0k
  {
67
    /* Instructions that cannot be bundled are padded out with nops,
68
       rather than fnops. Displaying them is always clutter. */
69
20.0k
    padding_mnemonic = TILEGX_OPC_NOP;
70
20.0k
    break;
71
20.0k
  }
72
65.6k
    }
73
74
116k
  for (i = 0; i < num_instructions; i++)
75
83.7k
    {
76
83.7k
      const struct tilegx_opcode *opcode = decoded[i].opcode;
77
83.7k
      const char *name;
78
83.7k
      int j;
79
80
      /* Do not print out fnops, unless everything is an fnop, in
81
   which case we will print out just the last one. */
82
83.7k
      if (opcode->mnemonic == padding_mnemonic
83
14
    && (num_printed > 0 || i + 1 < num_instructions))
84
14
  continue;
85
86
83.6k
      if (num_printed > 0)
87
50.4k
  info->fprintf_func (info->stream, " ; ");
88
83.6k
      ++num_printed;
89
90
83.6k
      name = opcode->name;
91
83.6k
      if (name == NULL)
92
22.5k
  name = "<invalid>";
93
83.6k
      info->fprintf_func (info->stream, "%s", name);
94
95
248k
      for (j = 0; j < opcode->num_operands; j++)
96
164k
  {
97
164k
    bfd_vma num;
98
164k
    const struct tilegx_operand *op;
99
164k
    const char *spr_name;
100
101
164k
    if (j > 0)
102
103k
      info->fprintf_func (info->stream, ",");
103
164k
    info->fprintf_func (info->stream, " ");
104
105
164k
    num = decoded[i].operand_values[j];
106
107
164k
    op = decoded[i].operands[j];
108
164k
    switch (op->type)
109
164k
      {
110
130k
      case TILEGX_OP_TYPE_REGISTER:
111
130k
        info->fprintf_func (info->stream, "%s",
112
130k
          tilegx_register_names[(int) num]);
113
130k
        break;
114
30
      case TILEGX_OP_TYPE_SPR:
115
30
        spr_name = get_tilegx_spr_name (num);
116
30
        if (spr_name != NULL)
117
12
    info->fprintf_func (info->stream, "%s", spr_name);
118
18
        else
119
18
    info->fprintf_func (info->stream, "%d", (int)num);
120
30
        break;
121
32.4k
      case TILEGX_OP_TYPE_IMMEDIATE:
122
32.4k
        info->fprintf_func (info->stream, "%d", (int)num);
123
32.4k
        break;
124
1.32k
      case TILEGX_OP_TYPE_ADDRESS:
125
1.32k
        info->print_address_func (num, info);
126
1.32k
        break;
127
0
      default:
128
0
        abort ();
129
164k
      }
130
164k
  }
131
83.6k
    }
132
33.2k
  info->fprintf_func (info->stream, " }");
133
134
33.2k
  return TILEGX_BUNDLE_SIZE_IN_BYTES;
135
33.2k
}