1 /* Disassemble h8500 instructions.
2 Copyright 1993, 1998, 2000, 2001, 2002, 2004, 2005, 2007
3 Free Software Foundation, Inc.
5 This file is part of the GNU opcodes library.
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)
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.
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. */
24 #define DISASSEMBLER_TABLE
28 #include "h8500-opc.h"
32 /* Maximum length of an instruction. */
39 /* Points to first byte not fetched. */
40 bfd_byte *max_fetched;
41 bfd_byte the_buffer[MAXLEN];
46 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
47 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
49 #define FETCH_DATA(info, addr) \
50 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
51 ? 1 : fetch_data ((info), (addr)))
54 fetch_data (struct disassemble_info *info, bfd_byte *addr)
57 struct private *priv = (struct private *) info->private_data;
58 bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
60 status = (*info->read_memory_func) (start,
62 addr - priv->max_fetched,
66 (*info->memory_error_func) (status, start, info);
67 longjmp (priv->bailout, 1);
70 priv->max_fetched = addr;
74 static char *crname[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
77 print_insn_h8500 (bfd_vma addr, disassemble_info *info)
79 const h8500_opcode_info *opcode;
80 void *stream = info->stream;
81 fprintf_ftype func = info->fprintf_func;
83 bfd_byte *buffer = priv.the_buffer;
85 info->private_data = (PTR) & priv;
86 priv.max_fetched = priv.the_buffer;
87 priv.insn_start = addr;
88 if (setjmp (priv.bailout) != 0)
92 /* Run down the table to find the one which matches. */
93 for (opcode = h8500_table; opcode->name; opcode++)
107 for (byte = 0; byte < opcode->length; byte++)
109 FETCH_DATA (info, buffer + byte + 1);
110 if ((buffer[byte] & opcode->bytes[byte].mask)
111 != (opcode->bytes[byte].contents))
116 /* Extract any info parts. */
117 switch (opcode->bytes[byte].insert)
123 /* xgettext:c-format */
124 func (stream, _("can't cope with insert %d\n"),
125 opcode->bytes[byte].insert);
128 rn = buffer[byte] & 0x7;
131 rs = buffer[byte] & 0x7;
134 cr = buffer[byte] & 0x7;
139 cr = buffer[byte] & 0x7;
144 FETCH_DATA (info, buffer + byte + 2);
145 disp = (buffer[byte] << 8) | (buffer[byte + 1]);
149 disp = ((char) (buffer[byte]));
153 rd = buffer[byte] & 0x7;
156 FETCH_DATA (info, buffer + byte + 3);
159 | (buffer[byte + 1] << 8)
160 | (buffer[byte + 2]);
163 FETCH_DATA (info, buffer + byte + 2);
164 abs = (buffer[byte] << 8) | (buffer[byte + 1]);
167 abs = (buffer[byte]);
170 FETCH_DATA (info, buffer + byte + 2);
171 imm = (buffer[byte] << 8) | (buffer[byte + 1]);
174 imm = (buffer[byte]) & 0xf;
178 imm = (buffer[byte]);
181 FETCH_DATA (info, buffer + byte + 2);
182 pcrel = (buffer[byte] << 8) | (buffer[byte + 1]);
185 pcrel = (buffer[byte]);
188 switch (buffer[byte] & 0x7)
208 /* We get here when all the masks have passed so we can output
210 FETCH_DATA (info, buffer + opcode->length);
211 (func) (stream, "%s\t", opcode->name);
212 for (i = 0; i < opcode->nargs; i++)
215 (func) (stream, ",");
216 switch (opcode->arg_type[i])
222 func (stream, "@(0x%x:16,r%d)", disp, rn);
225 func (stream, "@(0x%x:8 (%d),r%d)", disp & 0xff, disp, rn);
228 func (stream, "@(0x%x:16,r%d)", disp, rd);
231 func (stream, "@(0x%x:8 (%d), r%d)", disp & 0xff, disp, rd);
234 func (stream, "@(0x%x:8 (%d), fp)", disp & 0xff, disp);
238 func (stream, "%s", crname[cr]);
241 func (stream, "r%d", rn);
244 func (stream, "r%d", rd);
247 func (stream, "r%d", rs);
250 func (stream, "@-r%d", rn);
253 func (stream, "@r%d+", rn);
256 func (stream, "@r%d", rn);
259 func (stream, "@r%d", rd);
262 func (stream, "@sp+");
265 func (stream, "@-sp");
268 func (stream, "@0x%0x:24", abs);
271 func (stream, "@0x%0x:16", abs & 0xffff);
274 func (stream, "@0x%0x:8", abs & 0xff);
277 func (stream, "#0x%0x:16", imm & 0xffff);
285 for (i = 0; i < 8; i++)
289 func (stream, "r%d", i);
299 func (stream, "#0x%0x:8", imm & 0xff);
302 func (stream, "0x%0x:16",
303 (int)(pcrel + addr + opcode->length) & 0xffff);
306 func (stream, "#0x%0x:8",
307 (int)((char) pcrel + addr + opcode->length) & 0xffff);
310 func (stream, "#%d:q", qim);
313 func (stream, "#%d:4", imm);
317 return opcode->length;
322 /* Couldn't understand anything. */
323 /* xgettext:c-format */
324 func (stream, _("%02x\t\t*unknown*"), buffer[0]);