1 /* Disassemble h8300 instructions.
2 Copyright (C) 1993 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #define h8_opcodes h8ops
21 #include "opcode/h8300.h"
25 /* Run through the opcodes and sort them into order to make them easy
29 bfd_h8_disassemble_init ()
36 for (p = h8_opcodes; p->name; p++)
41 if ((int) p->data.nib[0] < 16)
43 n1 = (int) p->data.nib[0];
47 if ((int) p->data.nib[1] < 16)
49 n2 = (int) p->data.nib[1];
54 /* Just make sure there are an even number of nibbles in it, and
55 that the count is the same s the length */
56 for (i = 0; p->data.nib[i] != E; i++)
67 bfd_h8_disassemble (addr, info, mode)
69 disassemble_info *info;
72 /* Find the first entry in the table for this opcode */
73 static CONST char *regnames[] =
75 "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
76 "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l"};
78 static CONST char *wregnames[] =
80 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
81 "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7"
84 static CONST char *lregnames[] =
86 "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7",
87 "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7"
97 static boolean init = 0;
98 struct h8_opcode *q = h8_opcodes;
99 char CONST **pregnames = mode != 0 ? lregnames : wregnames;
103 unsigned char data[20];
104 void *stream = info->stream;
105 fprintf_ftype fprintf = info->fprintf_func;
109 bfd_h8_disassemble_init ();
113 status = info->read_memory_func(addr, data, 2, info);
116 info->memory_error_func(status, addr, info);
119 for (l = 2; status == 0 && l < 10; l+=2)
121 status = info->read_memory_func(addr+l, data+l, 2, info);
126 /* Find the exact opcode/arg combo */
130 unsigned int len = 0;
136 op_type looking_for = *nib;
137 int thisnib = data[len >> 1];
139 thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
141 if (looking_for < 16 && looking_for >=0)
144 if (looking_for != thisnib)
151 if ((int) looking_for & (int) B31)
153 if (! (((int) thisnib & 0x8) != 0))
155 looking_for = (op_type) ((int) looking_for & ~(int) B31);
157 if ((int) looking_for & (int) B30)
159 if (!(((int) thisnib & 0x8) == 0))
161 looking_for = (op_type) ((int) looking_for & ~(int) B30);
164 if (looking_for & DBIT)
166 if ((looking_for & 5) != (thisnib &5)) goto fail;
167 abs = (thisnib & 0x8) ? 2 : 1;
170 else if (looking_for & (REG | IND|INC|DEC))
172 if (looking_for & SRC)
181 else if (looking_for & L_16)
183 abs = (data[len >> 1]) * 256 + data[(len + 2) >> 1];
187 else if(looking_for & ABSJMP)
194 else if(looking_for & MEMIND)
198 else if (looking_for & L_32)
201 abs = (data[i] << 24)
202 | (data[i + 1] << 16)
209 else if (looking_for & L_24)
212 abs = (data[i] << 16) | (data[i + 1] << 8)| (data[i+
216 else if (looking_for & IGNORE)
220 else if (looking_for & DISPREG)
224 else if (looking_for & KBIT)
239 else if (looking_for & L_8)
242 abs = data[len >> 1];
244 else if (looking_for & L_3)
248 else if (looking_for & L_2)
253 else if (looking_for == E)
259 for (i = 0; i < q->length; i++)
261 fprintf (stream, "%02x ", data[i]);
265 fprintf (stream, " ");
268 fprintf (stream, "%s\t", q->name);
269 /* Fill in the args */
271 op_type *args = q->args.nib;
279 fprintf (stream, ",");
284 fprintf (stream, "#0x%x", (unsigned) bit);
286 else if (x & (IMM|KBIT|DBIT))
288 fprintf (stream, "#0x%x", (unsigned) abs);
292 int rn = (x & DST) ? rd : rs;
296 fprintf (stream, "%s", regnames[rn]);
299 fprintf (stream, "%s", wregnames[rn]);
303 fprintf (stream, "%s", lregnames[rn]);
311 fprintf (stream, "@%s+", pregnames[rs]);
315 fprintf (stream, "@-%s", pregnames[rd]);
320 int rn = (x & DST) ? rd : rs;
321 fprintf (stream, "@%s", pregnames[rn]);
324 else if (x & ABS8MEM)
326 fprintf (stream, "@0x%x:8", (unsigned) abs);
329 else if (x & (ABS|ABSJMP))
331 fprintf (stream, "@0x%x:%d", (unsigned) abs, plen);
336 fprintf (stream, "@@%d (%x)", abs, abs);
344 fprintf (stream, ".%s%d (%x)", (short) abs > 0 ? "+" : "", (short) abs,
345 addr + (short) abs + 2);
348 fprintf (stream, ".%s%d (%x)", (char) abs > 0 ? "+" : "", (char) abs,
349 addr + (char) abs + 2);
354 fprintf (stream, "@(0x%x:%d,%s)", abs,plen, pregnames[rdisp]);
360 fprintf (stream, "ccr");
364 fprintf (stream, "Hmmmm %x", x);
375 fprintf (stream, "Dont understand %x \n", looking_for);
387 /* Fell of the end */
388 fprintf (stream, "%02x %02x .word\tH'%x,H'%x",
395 print_insn_h8300 (addr, info)
397 disassemble_info *info;
399 return bfd_h8_disassemble (addr, info , 0);
403 print_insn_h8300h (addr, info)
405 disassemble_info *info;
407 return bfd_h8_disassemble (addr, info , 1);
411 print_insn_h8300s (addr, info)
413 disassemble_info *info;
415 return bfd_h8_disassemble (addr, info , 2);