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