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., 675 Mass Ave, Cambridge, MA 02139, 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, hmode)
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"
96 static boolean init = 0;
97 struct h8_opcode *q = h8_opcodes;
98 char CONST **pregnames = hmode ? lregnames : wregnames;
102 unsigned char data[20];
103 void *stream = info->stream;
104 fprintf_ftype fprintf = info->fprintf_func;
108 bfd_h8_disassemble_init ();
112 status = info->read_memory_func(addr, data, 2, info);
115 info->memory_error_func(status, addr, info);
118 for (l = 2; status == 0 && l < 10; l+=2)
120 status = info->read_memory_func(addr+l, data+l, 2, info);
125 /* Find the exact opcode/arg combo */
129 unsigned int len = 0;
135 op_type looking_for = *nib;
136 int thisnib = data[len >> 1];
138 thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
140 if (looking_for < 16 && looking_for >=0)
143 if (looking_for != thisnib)
150 if ((int) looking_for & (int) B31)
152 if (! (((int) thisnib & 0x8) != 0))
154 looking_for = (op_type) ((int) looking_for & ~(int) B31);
156 if ((int) looking_for & (int) B30)
158 if (!(((int) thisnib & 0x8) == 0))
160 looking_for = (op_type) ((int) looking_for & ~(int) B30);
163 if (looking_for & DBIT)
165 if ((looking_for & 5) != (thisnib &5)) goto fail;
166 abs = (thisnib & 0x8) ? 2 : 1;
169 else if (looking_for & (REG | IND|INC|DEC))
171 if (looking_for & SRC)
180 else if (looking_for & L_16)
182 abs = (data[len >> 1]) * 256 + data[(len + 2) >> 1];
186 else if(looking_for & ABSJMP)
193 else if(looking_for & MEMIND)
197 else if (looking_for & L_32)
200 abs = (data[i] << 24)
201 | (data[i + 1] << 16)
208 else if (looking_for & L_24)
211 abs = (data[i] << 16) | (data[i + 1] << 8)| (data[i+
215 else if (looking_for & IGNORE)
219 else if (looking_for & DISPREG)
223 else if (looking_for & KBIT)
238 else if (looking_for & L_8)
241 abs = data[len >> 1];
243 else if (looking_for & L_3)
249 else if (looking_for == E)
255 for (i = 0; i < q->length; i++)
257 fprintf (stream, "%02x ", data[i]);
261 fprintf (stream, " ");
264 fprintf (stream, "%s\t", q->name);
265 /* Fill in the args */
267 op_type *args = q->args.nib;
275 fprintf (stream, ",");
278 if (x & (IMM|KBIT|DBIT))
281 fprintf (stream, "#0x%x", (unsigned) abs);
285 int rn = (x & DST) ? rd : rs;
289 fprintf (stream, "%s", regnames[rn]);
292 fprintf (stream, "%s", wregnames[rn]);
296 fprintf (stream, "%s", lregnames[rn]);
304 fprintf (stream, "@%s+", pregnames[rs]);
308 fprintf (stream, "@-%s", pregnames[rd]);
313 int rn = (x & DST) ? rd : rs;
314 fprintf (stream, "@%s", pregnames[rn]);
317 else if (x & (ABS|ABSJMP|ABSMOV))
319 fprintf (stream, "@0x%x:%d", (unsigned) abs, plen);
324 fprintf (stream, "@@%d (%x)", abs, abs);
331 fprintf (stream, ".%s%d (%x)", (char) abs > 0 ? "+" : "", (char) abs,
332 addr + (char) abs + 2);
336 fprintf (stream, "@(0x%x:%d,%s)", abs,plen, pregnames[rdisp]);
342 fprintf (stream, "ccr");
346 fprintf (stream, "Hmmmm %x", x);
357 fprintf (stream, "Dont understand %x \n", looking_for);
369 /* Fell of the end */
370 fprintf (stream, "%02x %02x .word\tH'%x,H'%x",
377 print_insn_h8300 (addr, info)
379 disassemble_info *info;
381 return bfd_h8_disassemble (addr, info , 0);
385 print_insn_h8300h (addr, info)
387 disassemble_info *info;
389 return bfd_h8_disassemble (addr, info , 1);