Coverage Report

Created: 2023-08-28 06:31

/src/binutils-gdb/opcodes/ft32-dis.c
Line
Count
Source (jump to first uncovered line)
1
/* Disassemble ft32 instructions.
2
   Copyright (C) 2013-2023 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
17.8k
{
38
17.8k
  int onebit = (1 << bit);
39
17.8k
  return (value & (onebit - 1)) - (value & onebit);
40
17.8k
}
41
42
static void
43
ft32_opcode1 (unsigned int iword,
44
        struct disassemble_info *info)
45
61.9k
{
46
61.9k
  const ft32_opc_info_t *oo;
47
48
2.64M
  for (oo = ft32_opc_info; oo->name; oo++)
49
2.63M
    if ((iword & oo->mask) == oo->bits)
50
49.7k
      break;
51
52
61.9k
  if (oo->name)
53
49.7k
    {
54
49.7k
      int f = oo->fields;
55
49.7k
      int imm;
56
57
49.7k
      fpr (stream, "%s", oo->name);
58
49.7k
      if (oo->dw)
59
29.5k
  fpr (stream, ".%c ", "bsl"[(iword >> FT32_FLD_DW_BIT) & 3]);
60
20.1k
      else
61
20.1k
  fpr (stream, " ");
62
63
179k
      while (f)
64
129k
  {
65
129k
    int lobit = f & -f;
66
129k
    if (f & lobit)
67
129k
      {
68
129k
        switch (lobit)
69
129k
    {
70
6.78k
    case  FT32_FLD_CBCRCV:
71
      /* imm is {CB, CV}  */
72
6.78k
      imm = ((iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1)) << 4;
73
6.78k
      imm |= ((iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1));
74
6.78k
      switch (imm)
75
6.78k
        {
76
1.07k
        case 0x00: fpr (stream, "nz");  break;
77
805
        case 0x01: fpr (stream, "z");   break;
78
345
        case 0x10: fpr (stream, "ae");  break;
79
361
        case 0x11: fpr (stream, "b");   break;
80
275
        case 0x20: fpr (stream, "no");  break;
81
268
        case 0x21: fpr (stream, "o");   break;
82
166
        case 0x30: fpr (stream, "ns");  break;
83
291
        case 0x31: fpr (stream, "s");   break;
84
857
        case 0x40: fpr (stream, "lt");  break;
85
535
        case 0x41: fpr (stream, "gte"); break;
86
280
        case 0x50: fpr (stream, "lte"); break;
87
272
        case 0x51: fpr (stream, "gt");  break;
88
458
        case 0x60: fpr (stream, "be");  break;
89
250
        case 0x61: fpr (stream, "a");   break;
90
554
        default:
91
554
          fpr (stream, "%d,$r30,%d", (imm >> 4), (imm & 1));
92
554
          break;
93
6.78k
        }
94
6.78k
      break;
95
9.74k
    case  FT32_FLD_CB:
96
9.74k
      imm = (iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1);
97
9.74k
      fpr (stream, "%d", imm);
98
9.74k
      break;
99
27.6k
    case  FT32_FLD_R_D:
100
27.6k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
101
27.6k
      break;
102
9.74k
    case  FT32_FLD_CR:
103
9.74k
      imm = (iword >> FT32_FLD_CR_BIT) & ((1 << FT32_FLD_CR_SIZ) - 1);
104
9.74k
      fpr (stream, "$r%d", 28 + imm);
105
9.74k
      break;
106
9.74k
    case  FT32_FLD_CV:
107
9.74k
      imm = (iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1);
108
9.74k
      fpr (stream, "%d", imm);
109
9.74k
      break;
110
18.5k
    case  FT32_FLD_R_1:
111
18.5k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
112
18.5k
      break;
113
11.0k
    case  FT32_FLD_RIMM:
114
11.0k
      imm = (iword >> FT32_FLD_RIMM_BIT) & ((1 << FT32_FLD_RIMM_SIZ) - 1);
115
11.0k
      if (imm & 0x400)
116
5.77k
        fpr (stream, "%d", sign_extend (9, imm));
117
5.24k
      else
118
5.24k
        fpr (stream, "$r%d", imm & 0x1f);
119
11.0k
      break;
120
940
    case  FT32_FLD_R_2:
121
940
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_2_BIT) & 0x1f);
122
940
      break;
123
4.01k
    case  FT32_FLD_K20:
124
4.01k
      imm = iword & ((1 << FT32_FLD_K20_SIZ) - 1);
125
4.01k
      fpr (stream, "%d", sign_extend (19, imm));
126
4.01k
      break;
127
17.2k
    case  FT32_FLD_PA:
128
17.2k
      imm = (iword & ((1 << FT32_FLD_PA_SIZ) - 1)) << 2;
129
17.2k
      info->print_address_func ((bfd_vma) imm, info);
130
17.2k
      break;
131
3.03k
    case  FT32_FLD_AA:
132
3.03k
      imm = iword & ((1 << FT32_FLD_AA_SIZ) - 1);
133
3.03k
      info->print_address_func ((1 << 23) | (bfd_vma) imm, info);
134
3.03k
      break;
135
173
    case  FT32_FLD_K16:
136
173
      imm = iword & ((1 << FT32_FLD_K16_SIZ) - 1);
137
173
      fpr (stream, "%d", imm);
138
173
      break;
139
8.02k
    case  FT32_FLD_K15:
140
8.02k
      imm = iword & ((1 << FT32_FLD_K15_SIZ) - 1);
141
8.02k
      fpr (stream, "%d", sign_extend (14, imm));
142
8.02k
      break;
143
555
    case  FT32_FLD_R_D_POST:
144
555
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
145
555
      break;
146
2.27k
    case  FT32_FLD_R_1_POST:
147
2.27k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
148
2.27k
      break;
149
0
    default:
150
0
      break;
151
129k
    }
152
129k
        f &= ~lobit;
153
129k
        if (f)
154
81.8k
    fpr (stream, ",");
155
129k
      }
156
129k
  }
157
49.7k
    }
158
12.1k
  else
159
12.1k
    fpr (stream, "!");
160
61.9k
}
161
162
static void
163
ft32_opcode (bfd_vma addr ATTRIBUTE_UNUSED,
164
       unsigned int iword,
165
       struct disassemble_info *info)
166
50.9k
{
167
50.9k
  unsigned int sc[2];
168
50.9k
  if (ft32_decode_shortcode ((unsigned int) addr, iword, sc))
169
10.9k
    {
170
10.9k
      ft32_opcode1 (sc[0], info);
171
10.9k
      fpr (stream, " ; ");
172
10.9k
      ft32_opcode1 (sc[1], info);
173
10.9k
    }
174
40.0k
  else
175
40.0k
    ft32_opcode1 (iword, info);
176
50.9k
}
177
178
int
179
print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
180
51.0k
{
181
51.0k
  int status;
182
51.0k
  stream = info->stream;
183
51.0k
  bfd_byte buffer[4];
184
51.0k
  unsigned int iword;
185
186
51.0k
  fpr = info->fprintf_func;
187
188
51.0k
  if ((status = info->read_memory_func (addr, buffer, 4, info)))
189
77
    goto fail;
190
191
50.9k
  iword = bfd_getl32 (buffer);
192
193
50.9k
  fpr (stream, "%08x ", iword);
194
195
50.9k
  ft32_opcode (addr, iword, info);
196
197
50.9k
  return 4;
198
199
77
 fail:
200
77
  info->memory_error_func (status, addr, info);
201
77
  return -1;
202
51.0k
}