Coverage Report

Created: 2025-07-08 11:15

/src/binutils-gdb/opcodes/ft32-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble ft32 instructions.
2
   Copyright (C) 2013-2025 Free Software Foundation, Inc.
3
   Contributed by FTDI (support@ftdichip.com)
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 program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include <stdio.h>
24
#define STATIC_TABLE
25
#define DEFINE_TABLE
26
27
#include "opcode/ft32.h"
28
#include "disassemble.h"
29
30
extern const ft32_opc_info_t ft32_opc_info[];
31
32
static fprintf_ftype fpr;
33
static void *stream;
34
35
static int
36
sign_extend (int bit, int value)
37
14.2k
{
38
14.2k
  int onebit = (1 << bit);
39
14.2k
  return (value & (onebit - 1)) - (value & onebit);
40
14.2k
}
41
42
static void
43
ft32_opcode1 (unsigned int iword,
44
        struct disassemble_info *info)
45
45.1k
{
46
45.1k
  const ft32_opc_info_t *oo;
47
48
1.91M
  for (oo = ft32_opc_info; oo->name; oo++)
49
1.91M
    if ((iword & oo->mask) == oo->bits)
50
38.5k
      break;
51
52
45.1k
  if (oo->name)
53
38.5k
    {
54
38.5k
      int f = oo->fields;
55
38.5k
      int imm;
56
57
38.5k
      fpr (stream, "%s", oo->name);
58
38.5k
      if (oo->dw)
59
22.1k
  fpr (stream, ".%c ", "bsl"[(iword >> FT32_FLD_DW_BIT) & 3]);
60
16.3k
      else
61
16.3k
  fpr (stream, " ");
62
63
136k
      while (f)
64
98.2k
  {
65
98.2k
    int lobit = f & -f;
66
98.2k
    if (f & lobit)
67
98.2k
      {
68
98.2k
        switch (lobit)
69
98.2k
    {
70
6.82k
    case  FT32_FLD_CBCRCV:
71
      /* imm is {CB, CV}  */
72
6.82k
      imm = ((iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1)) << 4;
73
6.82k
      imm |= ((iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1));
74
6.82k
      switch (imm)
75
6.82k
        {
76
582
        case 0x00: fpr (stream, "nz");  break;
77
448
        case 0x01: fpr (stream, "z");   break;
78
412
        case 0x10: fpr (stream, "ae");  break;
79
746
        case 0x11: fpr (stream, "b");   break;
80
307
        case 0x20: fpr (stream, "no");  break;
81
240
        case 0x21: fpr (stream, "o");   break;
82
160
        case 0x30: fpr (stream, "ns");  break;
83
254
        case 0x31: fpr (stream, "s");   break;
84
798
        case 0x40: fpr (stream, "lt");  break;
85
796
        case 0x41: fpr (stream, "gte"); break;
86
306
        case 0x50: fpr (stream, "lte"); break;
87
274
        case 0x51: fpr (stream, "gt");  break;
88
851
        case 0x60: fpr (stream, "be");  break;
89
207
        case 0x61: fpr (stream, "a");   break;
90
439
        default:
91
439
          fpr (stream, "%d,$r30,%d", (imm >> 4), (imm & 1));
92
439
          break;
93
6.82k
        }
94
6.82k
      break;
95
6.82k
    case  FT32_FLD_CB:
96
6.56k
      imm = (iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1);
97
6.56k
      fpr (stream, "%d", imm);
98
6.56k
      break;
99
20.4k
    case  FT32_FLD_R_D:
100
20.4k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
101
20.4k
      break;
102
6.56k
    case  FT32_FLD_CR:
103
6.56k
      imm = (iword >> FT32_FLD_CR_BIT) & ((1 << FT32_FLD_CR_SIZ) - 1);
104
6.56k
      fpr (stream, "$r%d", 28 + imm);
105
6.56k
      break;
106
6.56k
    case  FT32_FLD_CV:
107
6.56k
      imm = (iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1);
108
6.56k
      fpr (stream, "%d", imm);
109
6.56k
      break;
110
14.4k
    case  FT32_FLD_R_1:
111
14.4k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
112
14.4k
      break;
113
9.65k
    case  FT32_FLD_RIMM:
114
9.65k
      imm = (iword >> FT32_FLD_RIMM_BIT) & ((1 << FT32_FLD_RIMM_SIZ) - 1);
115
9.65k
      if (imm & 0x400)
116
6.00k
        fpr (stream, "%d", sign_extend (9, imm));
117
3.64k
      else
118
3.64k
        fpr (stream, "$r%d", imm & 0x1f);
119
9.65k
      break;
120
576
    case  FT32_FLD_R_2:
121
576
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_2_BIT) & 0x1f);
122
576
      break;
123
2.92k
    case  FT32_FLD_K20:
124
2.92k
      imm = iword & ((1 << FT32_FLD_K20_SIZ) - 1);
125
2.92k
      fpr (stream, "%d", sign_extend (19, imm));
126
2.92k
      break;
127
13.9k
    case  FT32_FLD_PA:
128
13.9k
      imm = (iword & ((1 << FT32_FLD_PA_SIZ) - 1)) << 2;
129
13.9k
      info->print_address_func ((bfd_vma) imm, info);
130
13.9k
      break;
131
1.90k
    case  FT32_FLD_AA:
132
1.90k
      imm = iword & ((1 << FT32_FLD_AA_SIZ) - 1);
133
1.90k
      info->print_address_func ((1 << 23) | (bfd_vma) imm, info);
134
1.90k
      break;
135
369
    case  FT32_FLD_K16:
136
369
      imm = iword & ((1 << FT32_FLD_K16_SIZ) - 1);
137
369
      fpr (stream, "%d", imm);
138
369
      break;
139
5.28k
    case  FT32_FLD_K15:
140
5.28k
      imm = iword & ((1 << FT32_FLD_K15_SIZ) - 1);
141
5.28k
      fpr (stream, "%d", sign_extend (14, imm));
142
5.28k
      break;
143
578
    case  FT32_FLD_R_D_POST:
144
578
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
145
578
      break;
146
1.58k
    case  FT32_FLD_R_1_POST:
147
1.58k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
148
1.58k
      break;
149
0
    default:
150
0
      break;
151
98.2k
    }
152
98.2k
        f &= ~lobit;
153
98.2k
        if (f)
154
61.5k
    fpr (stream, ",");
155
98.2k
      }
156
98.2k
  }
157
38.5k
    }
158
6.60k
  else
159
6.60k
    fpr (stream, "!");
160
45.1k
}
161
162
static void
163
ft32_opcode (bfd_vma addr ATTRIBUTE_UNUSED,
164
       unsigned int iword,
165
       struct disassemble_info *info)
166
35.0k
{
167
35.0k
  unsigned int sc[2];
168
35.0k
  if (ft32_decode_shortcode ((unsigned int) addr, iword, sc))
169
10.0k
    {
170
10.0k
      ft32_opcode1 (sc[0], info);
171
10.0k
      fpr (stream, " ; ");
172
10.0k
      ft32_opcode1 (sc[1], info);
173
10.0k
    }
174
24.9k
  else
175
24.9k
    ft32_opcode1 (iword, info);
176
35.0k
}
177
178
int
179
print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
180
35.1k
{
181
35.1k
  int status;
182
35.1k
  stream = info->stream;
183
35.1k
  bfd_byte buffer[4];
184
35.1k
  unsigned int iword;
185
186
35.1k
  fpr = info->fprintf_func;
187
188
35.1k
  if ((status = info->read_memory_func (addr, buffer, 4, info)))
189
134
    goto fail;
190
191
35.0k
  iword = bfd_getl32 (buffer);
192
193
35.0k
  fpr (stream, "%08x ", iword);
194
195
35.0k
  ft32_opcode (addr, iword, info);
196
197
35.0k
  return 4;
198
199
134
 fail:
200
134
  info->memory_error_func (status, addr, info);
201
134
  return -1;
202
35.1k
}