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"
97 struct h8_opcode
*q
= h8_opcodes
;
98 char CONST
**pregnames
= hmode
? lregnames
: wregnames
;
100 unsigned char data
[20];
101 void *stream
= info
->stream
;
102 fprintf_ftype fprintf
= info
->fprintf_func
;
106 bfd_h8_disassemble_init ();
110 status
= info
->read_memory_func(addr
, data
, 2, info
);
113 info
->memory_error_func(status
, addr
, info
);
116 status
= info
->read_memory_func(addr
, data
+2, 8, info
);
120 /* Find the exact opcode/arg combo */
124 unsigned int len
= 0;
130 op_type looking_for
= *nib
;
131 int thisnib
= data
[len
>> 1];
133 thisnib
= (len
& 1) ? (thisnib
& 0xf) : ((thisnib
>> 4) & 0xf);
135 if (looking_for
< 16)
138 if (looking_for
!= thisnib
)
145 if ((int) looking_for
& (int) B31
)
147 if (! (((int) thisnib
& 0x8) != 0))
149 looking_for
= (op_type
) ((int) looking_for
& ~(int) B31
);
151 if ((int) looking_for
& (int) B30
)
153 if (!(((int) thisnib
& 0x8) == 0))
155 looking_for
= (op_type
) ((int) looking_for
& ~(int) B30
);
158 if (looking_for
& DBIT
)
160 if ((looking_for
& 5) != (thisnib
&5)) goto fail
;
161 abs
= (thisnib
& 0x8) ? 2 : 1;
164 else if (looking_for
& (REG
| IND
|INC
|DEC
))
166 if (looking_for
& SRC
)
175 else if (looking_for
& L_16
)
177 abs
= (data
[len
>> 1]) * 256 + data
[(len
+ 2) >> 1];
181 else if(looking_for
& ABSJMP
)
189 else if (looking_for
& L_32
)
192 abs
= (data
[i
] << 24)
193 | (data
[i
+ 1] << 16)
200 else if (looking_for
& L_24
)
203 abs
= (data
[i
] << 16) | (data
[i
+ 1] << 8)| (data
[i
+
207 else if (looking_for
& IGNORE
)
211 else if (looking_for
& DISPREG
)
215 else if (looking_for
& KBIT
)
230 else if (looking_for
& L_8
)
233 abs
= data
[len
>> 1];
235 else if (looking_for
& L_3
)
241 else if (looking_for
== E
)
247 for (i
= 0; i
< q
->length
; i
++)
249 fprintf (stream
, "%02x ", data
[i
]);
253 fprintf (stream
, " ");
256 fprintf (stream
, "%s\t", q
->name
);
257 /* Fill in the args */
259 op_type
*args
= q
->args
.nib
;
267 fprintf (stream
, ",");
270 if (x
& (IMM
|KBIT
|DBIT
))
273 fprintf (stream
, "#0x%x", (unsigned) abs
);
277 int rn
= (x
& DST
) ? rd
: rs
;
281 fprintf (stream
, "%s", regnames
[rn
]);
284 fprintf (stream
, "%s", wregnames
[rn
]);
288 fprintf (stream
, "%s", lregnames
[rn
]);
296 fprintf (stream
, "@%s+", pregnames
[rs
]);
300 fprintf (stream
, "@-%s", pregnames
[rd
]);
305 int rn
= (x
& DST
) ? rd
: rs
;
306 fprintf (stream
, "@%s", pregnames
[rn
]);
309 else if (x
& (ABS
|ABSJMP
|ABSMOV
))
311 fprintf (stream
, "@0x%x:%d", (unsigned) abs
, plen
);
316 fprintf (stream
, "@@%d (%x)", abs
, abs
);
321 fprintf (stream
, ".%s%d (%x)", (char) abs
> 0 ? "+" : "", (char) abs
,
322 addr
+ (char) abs
+ 2);
326 fprintf (stream
, "@(0x%x:%d,%s)", abs
,plen
, pregnames
[rdisp
]);
332 fprintf (stream
, "ccr");
336 fprintf (stream
, "Hmmmm %x", x
);
347 fprintf (stream
, "Dont understand %x \n", looking_for
);
359 /* Fell of the end */
360 fprintf (stream
, "%02x %02x .word\tH'%x,H'%x",
367 print_insn_h8300 (addr
, info
)
369 disassemble_info
*info
;
371 return bfd_h8_disassemble (addr
, info
, 0);
375 print_insn_h8300h (addr
, info
)
377 disassemble_info
*info
;
379 return bfd_h8_disassemble (addr
, info
, 1);
This page took 0.037477 seconds and 4 git commands to generate.