Coverage Report

Created: 2023-06-29 07:13

/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[128];
31
32
static fprintf_ftype fpr;
33
static void *stream;
34
35
static int
36
sign_extend (int bit, int value)
37
25.6k
{
38
25.6k
  int onebit = (1 << bit);
39
25.6k
  return (value & (onebit - 1)) - (value & onebit);
40
25.6k
}
41
42
static void
43
ft32_opcode1 (unsigned int iword,
44
        struct disassemble_info *info)
45
87.1k
{
46
87.1k
  const ft32_opc_info_t *oo;
47
48
3.74M
  for (oo = ft32_opc_info; oo->name; oo++)
49
3.73M
    if ((iword & oo->mask) == oo->bits)
50
70.6k
      break;
51
52
87.1k
  if (oo->name)
53
70.6k
    {
54
70.6k
      int f = oo->fields;
55
70.6k
      int imm;
56
57
70.6k
      fpr (stream, "%s", oo->name);
58
70.6k
      if (oo->dw)
59
42.6k
  fpr (stream, ".%c ", "bsl"[(iword >> FT32_FLD_DW_BIT) & 3]);
60
28.0k
      else
61
28.0k
  fpr (stream, " ");
62
63
255k
      while (f)
64
184k
  {
65
184k
    int lobit = f & -f;
66
184k
    if (f & lobit)
67
184k
      {
68
184k
        switch (lobit)
69
184k
    {
70
10.3k
    case  FT32_FLD_CBCRCV:
71
      /* imm is {CB, CV}  */
72
10.3k
      imm = ((iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1)) << 4;
73
10.3k
      imm |= ((iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1));
74
10.3k
      switch (imm)
75
10.3k
        {
76
1.36k
        case 0x00: fpr (stream, "nz");  break;
77
1.09k
        case 0x01: fpr (stream, "z");   break;
78
650
        case 0x10: fpr (stream, "ae");  break;
79
596
        case 0x11: fpr (stream, "b");   break;
80
376
        case 0x20: fpr (stream, "no");  break;
81
402
        case 0x21: fpr (stream, "o");   break;
82
270
        case 0x30: fpr (stream, "ns");  break;
83
400
        case 0x31: fpr (stream, "s");   break;
84
1.09k
        case 0x40: fpr (stream, "lt");  break;
85
1.03k
        case 0x41: fpr (stream, "gte"); break;
86
385
        case 0x50: fpr (stream, "lte"); break;
87
897
        case 0x51: fpr (stream, "gt");  break;
88
552
        case 0x60: fpr (stream, "be");  break;
89
305
        case 0x61: fpr (stream, "a");   break;
90
920
        default:
91
920
          fpr (stream, "%d,$r30,%d", (imm >> 4), (imm & 1));
92
920
          break;
93
10.3k
        }
94
10.3k
      break;
95
13.2k
    case  FT32_FLD_CB:
96
13.2k
      imm = (iword >> FT32_FLD_CB_BIT) & ((1 << FT32_FLD_CB_SIZ) - 1);
97
13.2k
      fpr (stream, "%d", imm);
98
13.2k
      break;
99
39.1k
    case  FT32_FLD_R_D:
100
39.1k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
101
39.1k
      break;
102
13.2k
    case  FT32_FLD_CR:
103
13.2k
      imm = (iword >> FT32_FLD_CR_BIT) & ((1 << FT32_FLD_CR_SIZ) - 1);
104
13.2k
      fpr (stream, "$r%d", 28 + imm);
105
13.2k
      break;
106
13.2k
    case  FT32_FLD_CV:
107
13.2k
      imm = (iword >> FT32_FLD_CV_BIT) & ((1 << FT32_FLD_CV_SIZ) - 1);
108
13.2k
      fpr (stream, "%d", imm);
109
13.2k
      break;
110
26.1k
    case  FT32_FLD_R_1:
111
26.1k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
112
26.1k
      break;
113
17.2k
    case  FT32_FLD_RIMM:
114
17.2k
      imm = (iword >> FT32_FLD_RIMM_BIT) & ((1 << FT32_FLD_RIMM_SIZ) - 1);
115
17.2k
      if (imm & 0x400)
116
9.80k
        fpr (stream, "%d", sign_extend (9, imm));
117
7.41k
      else
118
7.41k
        fpr (stream, "$r%d", imm & 0x1f);
119
17.2k
      break;
120
1.52k
    case  FT32_FLD_R_2:
121
1.52k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_2_BIT) & 0x1f);
122
1.52k
      break;
123
5.44k
    case  FT32_FLD_K20:
124
5.44k
      imm = iword & ((1 << FT32_FLD_K20_SIZ) - 1);
125
5.44k
      fpr (stream, "%d", sign_extend (19, imm));
126
5.44k
      break;
127
25.2k
    case  FT32_FLD_PA:
128
25.2k
      imm = (iword & ((1 << FT32_FLD_PA_SIZ) - 1)) << 2;
129
25.2k
      info->print_address_func ((bfd_vma) imm, info);
130
25.2k
      break;
131
4.21k
    case  FT32_FLD_AA:
132
4.21k
      imm = iword & ((1 << FT32_FLD_AA_SIZ) - 1);
133
4.21k
      info->print_address_func ((1 << 23) | (bfd_vma) imm, info);
134
4.21k
      break;
135
357
    case  FT32_FLD_K16:
136
357
      imm = iword & ((1 << FT32_FLD_K16_SIZ) - 1);
137
357
      fpr (stream, "%d", imm);
138
357
      break;
139
10.4k
    case  FT32_FLD_K15:
140
10.4k
      imm = iword & ((1 << FT32_FLD_K15_SIZ) - 1);
141
10.4k
      fpr (stream, "%d", sign_extend (14, imm));
142
10.4k
      break;
143
1.43k
    case  FT32_FLD_R_D_POST:
144
1.43k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);
145
1.43k
      break;
146
3.14k
    case  FT32_FLD_R_1_POST:
147
3.14k
      fpr (stream, "$r%d", (iword >> FT32_FLD_R_1_BIT) & 0x1f);
148
3.14k
      break;
149
0
    default:
150
0
      break;
151
184k
    }
152
184k
        f &= ~lobit;
153
184k
        if (f)
154
116k
    fpr (stream, ",");
155
184k
      }
156
184k
  }
157
70.6k
    }
158
16.5k
  else
159
16.5k
    fpr (stream, "!");
160
87.1k
}
161
162
static void
163
ft32_opcode (bfd_vma addr ATTRIBUTE_UNUSED,
164
       unsigned int iword,
165
       struct disassemble_info *info)
166
70.7k
{
167
70.7k
  unsigned int sc[2];
168
70.7k
  if (ft32_decode_shortcode ((unsigned int) addr, iword, sc))
169
16.3k
    {
170
16.3k
      ft32_opcode1 (sc[0], info);
171
16.3k
      fpr (stream, " ; ");
172
16.3k
      ft32_opcode1 (sc[1], info);
173
16.3k
    }
174
54.4k
  else
175
54.4k
    ft32_opcode1 (iword, info);
176
70.7k
}
177
178
int
179
print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
180
70.8k
{
181
70.8k
  int status;
182
70.8k
  stream = info->stream;
183
70.8k
  bfd_byte buffer[4];
184
70.8k
  unsigned int iword;
185
186
70.8k
  fpr = info->fprintf_func;
187
188
70.8k
  if ((status = info->read_memory_func (addr, buffer, 4, info)))
189
84
    goto fail;
190
191
70.7k
  iword = bfd_getl32 (buffer);
192
193
70.7k
  fpr (stream, "%08x ", iword);
194
195
70.7k
  ft32_opcode (addr, iword, info);
196
197
70.7k
  return 4;
198
199
84
 fail:
200
84
  info->memory_error_func (status, addr, info);
201
84
  return -1;
202
70.8k
}