1 /* Disassemble h8500 instructions.
2 Copyright (C) 1993-2017 Free Software Foundation, Inc.
4 This file is part of the GNU opcodes library.
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
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.
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
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
24 #define DISASSEMBLER_TABLE
27 #include "h8500-opc.h"
31 /* Maximum length of an instruction. */
38 /* Points to first byte not fetched. */
39 bfd_byte *max_fetched;
40 bfd_byte the_buffer[MAXLEN];
42 OPCODES_SIGJMP_BUF bailout;
45 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
46 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
48 #define FETCH_DATA(info, addr) \
49 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
50 ? 1 : fetch_data ((info), (addr)))
53 fetch_data (struct disassemble_info *info, bfd_byte *addr)
56 struct private *priv = (struct private *) info->private_data;
57 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
59 status = (*info->read_memory_func) (start,
61 addr - priv->max_fetched,
65 (*info->memory_error_func) (status, start, info);
66 OPCODES_SIGLONGJMP (priv->bailout, 1);
69 priv->max_fetched = addr;
73 static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
76 print_insn_h8500 (bfd_vma addr, disassemble_info *info)
78 const h8500_opcode_info *opcode;
79 void *stream = info->stream;
80 fprintf_ftype func = info->fprintf_func;
82 bfd_byte *buffer = priv.the_buffer;
84 info->private_data = (PTR) & priv;
85 priv.max_fetched = priv.the_buffer;
86 priv.insn_start = addr;
87 if (OPCODES_SIGSETJMP (priv.bailout) != 0)
91 /* Run down the table to find the one which matches. */
92 for (opcode = h8500_table; opcode->name; opcode++)
106 for (byte = 0; byte < opcode->length; byte++)
108 FETCH_DATA (info, buffer + byte + 1);
109 if ((buffer[byte] & opcode->bytes[byte].mask)
110 != (opcode->bytes[byte].contents))
115 /* Extract any info parts. */
116 switch (opcode->bytes[byte].insert)
122 /* xgettext:c-format */
123 func (stream, _("can't cope with insert %d\n"),
124 opcode->bytes[byte].insert);
127 rn = buffer[byte] & 0x7;
130 rs = buffer[byte] & 0x7;
133 cr = buffer[byte] & 0x7;
138 cr = buffer[byte] & 0x7;
143 FETCH_DATA (info, buffer + byte + 2);
144 disp = (buffer[byte] << 8) | (buffer[byte + 1]);
148 disp = ((char) (buffer[byte]));
152 rd = buffer[byte] & 0x7;
155 FETCH_DATA (info, buffer + byte + 3);
158 | (buffer[byte + 1] << 8)
159 | (buffer[byte + 2]);
162 FETCH_DATA (info, buffer + byte + 2);
163 abs_val = (buffer[byte] << 8) | (buffer[byte + 1]);
166 abs_val = (buffer[byte]);
169 FETCH_DATA (info, buffer + byte + 2);
170 imm = (buffer[byte] << 8) | (buffer[byte + 1]);
173 imm = (buffer[byte]) & 0xf;
177 imm = (buffer[byte]);
180 FETCH_DATA (info, buffer + byte + 2);
181 pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
184 pcrel = (buffer[byte]);
187 switch (buffer[byte] & 0x7)
207 /* We get here when all the masks have passed so we can output
209 FETCH_DATA (info, buffer + opcode->length);
210 (func) (stream, "%s\t", opcode->name);
211 for (i = 0; i < opcode->nargs; i++)
214 (func) (stream, ",");
215 switch (opcode->arg_type[i])
221 func (stream, "@(0x%x:16,r%d)", disp, rn);
224 func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
227 func (stream, "@(0x%x:16,r%d)", disp, rd);
230 func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
233 func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
237 func (stream, "%s", crname[cr]);
240 func (stream, "r%d", rn);
243 func (stream, "r%d", rd);
246 func (stream, "r%d", rs);
249 func (stream, "@-r%d", rn);
252 func (stream, "@r%d+", rn);
255 func (stream, "@r%d", rn);
258 func (stream, "@r%d", rd);
261 func (stream, "@sp+");
264 func (stream, "@-sp");
267 func (stream, "@0x%0x:24", abs_val);
270 func (stream, "@0x%0x:16", abs_val & 0xffff);
273 func (stream, "@0x%0x:8", abs_val & 0xff);
276 func (stream, "#0x%0x:16", imm & 0xffff);
284 for (j = 0; j < 8; j++)
288 func (stream, "r%d", j);
298 func (stream, "#0x%0x:8", imm & 0xff);
301 func (stream, "0x%0x:16",
302 (int)(pcrel + addr + opcode->length) & 0xffff);
305 func (stream, "#0x%0x:8",
306 (int)((char) pcrel + addr + opcode->length) & 0xffff);
309 func (stream, "#%d:q", qim);
312 func (stream, "#%d:4", imm);
316 return opcode->length;
321 /* Couldn't understand anything. */
322 /* xgettext:c-format */
323 func (stream, _("%02x\t\t*unknown*"), buffer[0]);