]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - opcodes/h8500-dis.c
Update the simplified Chinese translation of the messages in the opcodes library.
[thirdparty/binutils-gdb.git] / opcodes / h8500-dis.c
CommitLineData
252b5132 1/* Disassemble h8500 instructions.
2571583a 2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
252b5132 3
9b201bb5
NC
4 This file is part of the GNU opcodes library.
5
6 This library is free software; you can redistribute it and/or modify
ed049af3 7 it under the terms of the GNU General Public License as published by
9b201bb5
NC
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
252b5132 10
9b201bb5
NC
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
252b5132 15
ed049af3
NC
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
47b0e7ad
NC
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
252b5132 20
df7b86aa 21#include "sysdep.h"
252b5132
RH
22#include <stdio.h>
23
24#define DISASSEMBLER_TABLE
25#define DEFINE_TABLE
26
27#include "h8500-opc.h"
88c1242d 28#include "disassemble.h"
252b5132
RH
29#include "opintl.h"
30
31/* Maximum length of an instruction. */
32#define MAXLEN 8
33
34#include <setjmp.h>
35
36struct private
37{
38 /* Points to first byte not fetched. */
39 bfd_byte *max_fetched;
40 bfd_byte the_buffer[MAXLEN];
41 bfd_vma insn_start;
8df14d78 42 OPCODES_SIGJMP_BUF bailout;
252b5132
RH
43};
44
45/* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
46 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
47 on error. */
48#define FETCH_DATA(info, addr) \
49 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
50 ? 1 : fetch_data ((info), (addr)))
51
52static int
47b0e7ad 53fetch_data (struct disassemble_info *info, bfd_byte *addr)
252b5132
RH
54{
55 int status;
56 struct private *priv = (struct private *) info->private_data;
57 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
58
59 status = (*info->read_memory_func) (start,
60 priv->max_fetched,
61 addr - priv->max_fetched,
62 info);
63 if (status != 0)
64 {
65 (*info->memory_error_func) (status, start, info);
8df14d78 66 OPCODES_SIGLONGJMP (priv->bailout, 1);
252b5132
RH
67 }
68 else
69 priv->max_fetched = addr;
70 return 1;
71}
72
c07ab2ec 73static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
252b5132
RH
74
75int
47b0e7ad 76print_insn_h8500 (bfd_vma addr, disassemble_info *info)
252b5132 77{
6a51a8a8 78 const h8500_opcode_info *opcode;
252b5132
RH
79 void *stream = info->stream;
80 fprintf_ftype func = info->fprintf_func;
252b5132
RH
81 struct private priv;
82 bfd_byte *buffer = priv.the_buffer;
83
84 info->private_data = (PTR) & priv;
85 priv.max_fetched = priv.the_buffer;
86 priv.insn_start = addr;
8df14d78 87 if (OPCODES_SIGSETJMP (priv.bailout) != 0)
252b5132
RH
88 /* Error return. */
89 return -1;
90
c07ab2ec 91 /* Run down the table to find the one which matches. */
252b5132
RH
92 for (opcode = h8500_table; opcode->name; opcode++)
93 {
94 int byte;
95 int rn = 0;
96 int rd = 0;
97 int rs = 0;
98 int disp = 0;
91d6fa6a 99 int abs_val = 0;
252b5132
RH
100 int imm = 0;
101 int pcrel = 0;
102 int qim = 0;
103 int i;
104 int cr = 0;
c07ab2ec 105
252b5132
RH
106 for (byte = 0; byte < opcode->length; byte++)
107 {
108 FETCH_DATA (info, buffer + byte + 1);
109 if ((buffer[byte] & opcode->bytes[byte].mask)
110 != (opcode->bytes[byte].contents))
47b0e7ad
NC
111 goto next;
112
252b5132
RH
113 else
114 {
c07ab2ec 115 /* Extract any info parts. */
252b5132
RH
116 switch (opcode->bytes[byte].insert)
117 {
118 case 0:
119 case FP:
120 break;
121 default:
122 /* xgettext:c-format */
123 func (stream, _("can't cope with insert %d\n"),
124 opcode->bytes[byte].insert);
125 break;
126 case RN:
127 rn = buffer[byte] & 0x7;
128 break;
129 case RS:
130 rs = buffer[byte] & 0x7;
131 break;
132 case CRB:
133 cr = buffer[byte] & 0x7;
134 if (cr == 0)
135 goto next;
136 break;
137 case CRW:
138 cr = buffer[byte] & 0x7;
139 if (cr != 0)
140 goto next;
141 break;
142 case DISP16:
143 FETCH_DATA (info, buffer + byte + 2);
144 disp = (buffer[byte] << 8) | (buffer[byte + 1]);
145 break;
146 case FPIND_D8:
147 case DISP8:
148 disp = ((char) (buffer[byte]));
149 break;
150 case RD:
151 case RDIND:
152 rd = buffer[byte] & 0x7;
153 break;
154 case ABS24:
155 FETCH_DATA (info, buffer + byte + 3);
91d6fa6a 156 abs_val =
252b5132
RH
157 (buffer[byte] << 16)
158 | (buffer[byte + 1] << 8)
159 | (buffer[byte + 2]);
160 break;
161 case ABS16:
162 FETCH_DATA (info, buffer + byte + 2);
91d6fa6a 163 abs_val = (buffer[byte] << 8) | (buffer[byte + 1]);
252b5132
RH
164 break;
165 case ABS8:
91d6fa6a 166 abs_val = (buffer[byte]);
252b5132
RH
167 break;
168 case IMM16:
169 FETCH_DATA (info, buffer + byte + 2);
170 imm = (buffer[byte] << 8) | (buffer[byte + 1]);
171 break;
172 case IMM4:
173 imm = (buffer[byte]) & 0xf;
174 break;
175 case IMM8:
176 case RLIST:
177 imm = (buffer[byte]);
178 break;
179 case PCREL16:
180 FETCH_DATA (info, buffer + byte + 2);
181 pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
182 break;
183 case PCREL8:
184 pcrel = (buffer[byte]);
185 break;
186 case QIM:
187 switch (buffer[byte] & 0x7)
188 {
189 case 0:
190 qim = 1;
191 break;
192 case 1:
193 qim = 2;
194 break;
195 case 4:
196 qim = -1;
197 break;
198 case 5:
199 qim = -2;
200 break;
201 }
202 break;
203
204 }
205 }
206 }
c07ab2ec
NC
207 /* We get here when all the masks have passed so we can output
208 the operands. */
252b5132 209 FETCH_DATA (info, buffer + opcode->length);
252b5132
RH
210 (func) (stream, "%s\t", opcode->name);
211 for (i = 0; i < opcode->nargs; i++)
212 {
213 if (i)
214 (func) (stream, ",");
215 switch (opcode->arg_type[i])
216 {
217 case FP:
218 func (stream, "fp");
219 break;
220 case RNIND_D16:
221 func (stream, "@(0x%x:16,r%d)", disp, rn);
222 break;
223 case RNIND_D8:
224 func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
225 break;
226 case RDIND_D16:
227 func (stream, "@(0x%x:16,r%d)", disp, rd);
228 break;
229 case RDIND_D8:
230 func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
231 break;
232 case FPIND_D8:
0fd3a477 233 func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
252b5132
RH
234 break;
235 case CRB:
236 case CRW:
237 func (stream, "%s", crname[cr]);
238 break;
239 case RN:
240 func (stream, "r%d", rn);
241 break;
242 case RD:
243 func (stream, "r%d", rd);
244 break;
245 case RS:
246 func (stream, "r%d", rs);
247 break;
248 case RNDEC:
249 func (stream, "@-r%d", rn);
250 break;
251 case RNINC:
252 func (stream, "@r%d+", rn);
253 break;
254 case RNIND:
255 func (stream, "@r%d", rn);
256 break;
257 case RDIND:
258 func (stream, "@r%d", rd);
259 break;
260 case SPINC:
261 func (stream, "@sp+");
262 break;
263 case SPDEC:
264 func (stream, "@-sp");
265 break;
266 case ABS24:
91d6fa6a 267 func (stream, "@0x%0x:24", abs_val);
252b5132
RH
268 break;
269 case ABS16:
91d6fa6a 270 func (stream, "@0x%0x:16", abs_val & 0xffff);
252b5132
RH
271 break;
272 case ABS8:
91d6fa6a 273 func (stream, "@0x%0x:8", abs_val & 0xff);
252b5132
RH
274 break;
275 case IMM16:
276 func (stream, "#0x%0x:16", imm & 0xffff);
277 break;
278 case RLIST:
279 {
91d6fa6a 280 int j;
252b5132 281 int nc = 0;
47b0e7ad 282
252b5132 283 func (stream, "(");
91d6fa6a 284 for (j = 0; j < 8; j++)
252b5132 285 {
91d6fa6a 286 if (imm & (1 << j))
252b5132 287 {
91d6fa6a 288 func (stream, "r%d", j);
252b5132
RH
289 if (nc)
290 func (stream, ",");
291 nc = 1;
292 }
293 }
294 func (stream, ")");
295 }
296 break;
297 case IMM8:
298 func (stream, "#0x%0x:8", imm & 0xff);
299 break;
300 case PCREL16:
c07ab2ec 301 func (stream, "0x%0x:16",
0fd3a477 302 (int)(pcrel + addr + opcode->length) & 0xffff);
252b5132
RH
303 break;
304 case PCREL8:
305 func (stream, "#0x%0x:8",
0fd3a477 306 (int)((char) pcrel + addr + opcode->length) & 0xffff);
252b5132
RH
307 break;
308 case QIM:
309 func (stream, "#%d:q", qim);
310 break;
311 case IMM4:
312 func (stream, "#%d:4", imm);
313 break;
314 }
315 }
316 return opcode->length;
c07ab2ec
NC
317 next:
318 ;
252b5132
RH
319 }
320
c07ab2ec 321 /* Couldn't understand anything. */
252b5132
RH
322 /* xgettext:c-format */
323 func (stream, _("%02x\t\t*unknown*"), buffer[0]);
324 return 1;
252b5132 325}