/src/binutils-gdb/opcodes/h8300-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble h8300 instructions. |
2 | | Copyright (C) 1993-2024 Free Software Foundation, Inc. |
3 | | |
4 | | This file is part of the GNU opcodes library. |
5 | | |
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) |
9 | | any later version. |
10 | | |
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. |
15 | | |
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. */ |
20 | | |
21 | | #define DEFINE_TABLE |
22 | | |
23 | | #include "sysdep.h" |
24 | 4 | #define h8_opcodes h8ops |
25 | | #include "opcode/h8300.h" |
26 | | #include "disassemble.h" |
27 | | #include "opintl.h" |
28 | | #include "libiberty.h" |
29 | | |
30 | | struct h8_instruction |
31 | | { |
32 | | unsigned int length; |
33 | | const struct h8_opcode *opcode; |
34 | | }; |
35 | | |
36 | | struct h8_instruction *h8_instructions; |
37 | | |
38 | | /* Run through the opcodes and sort them into order to make them easy |
39 | | to disassemble. */ |
40 | | |
41 | | static void |
42 | | bfd_h8_disassemble_init (void) |
43 | 2 | { |
44 | 2 | unsigned int i; |
45 | 2 | unsigned int nopcodes; |
46 | 2 | const struct h8_opcode *p; |
47 | 2 | struct h8_instruction *pi; |
48 | | |
49 | 2 | nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode); |
50 | | |
51 | 2 | h8_instructions = xmalloc (nopcodes * sizeof (struct h8_instruction)); |
52 | | |
53 | 16.9k | for (p = h8_opcodes, pi = h8_instructions; p->name; p++, pi++) |
54 | 16.9k | { |
55 | | /* Just make sure there are an even number of nibbles in it, and |
56 | | that the count is the same as the length. */ |
57 | 299k | for (i = 0; p->data.nib[i] != (op_type) E; i++) |
58 | 282k | ; |
59 | 16.9k | OPCODES_ASSERT (!(i & 1)); |
60 | | |
61 | 16.9k | pi->length = i / 2; |
62 | 16.9k | pi->opcode = p; |
63 | 16.9k | } |
64 | | |
65 | | /* Add entry for the NULL vector terminator. */ |
66 | 2 | pi->length = 0; |
67 | 2 | pi->opcode = p; |
68 | 2 | } |
69 | | |
70 | | static void |
71 | | extract_immediate (FILE *stream, |
72 | | op_type looking_for, |
73 | | int thisnib, |
74 | | unsigned char *data, |
75 | | int *cst, |
76 | | int *len, |
77 | | const struct h8_opcode *q) |
78 | 222k | { |
79 | 222k | switch (looking_for & SIZE) |
80 | 222k | { |
81 | 54.9k | case L_2: |
82 | 54.9k | *len = 2; |
83 | 54.9k | *cst = thisnib & 3; |
84 | | |
85 | | /* DISP2 special treatment. */ |
86 | 54.9k | if ((looking_for & MODE) == DISP) |
87 | 54.9k | { |
88 | 54.9k | if (OP_KIND (q->how) == O_MOVAB |
89 | 54.9k | || OP_KIND (q->how) == O_MOVAW |
90 | 54.9k | || OP_KIND (q->how) == O_MOVAL) |
91 | 552 | { |
92 | | /* Handling for mova insn. */ |
93 | 552 | switch (q->args.nib[0] & MODE) |
94 | 552 | { |
95 | 486 | case INDEXB: |
96 | 486 | default: |
97 | 486 | break; |
98 | 486 | case INDEXW: |
99 | 66 | *cst *= 2; |
100 | 66 | break; |
101 | 0 | case INDEXL: |
102 | 0 | *cst *= 4; |
103 | 0 | break; |
104 | 552 | } |
105 | 552 | } |
106 | 54.3k | else |
107 | 54.3k | { |
108 | | /* Handling for non-mova insn. */ |
109 | 54.3k | switch (OP_SIZE (q->how)) |
110 | 54.3k | { |
111 | 15.3k | default: break; |
112 | 15.3k | case SW: |
113 | 11.5k | *cst *= 2; |
114 | 11.5k | break; |
115 | 27.4k | case SL: |
116 | 27.4k | *cst *= 4; |
117 | 27.4k | break; |
118 | 54.3k | } |
119 | 54.3k | } |
120 | 54.9k | } |
121 | 54.9k | break; |
122 | 150k | case L_8: |
123 | 150k | *len = 8; |
124 | 150k | *cst = data[0]; |
125 | 150k | break; |
126 | 3.26k | case L_16: |
127 | 16.7k | case L_16U: |
128 | 16.7k | *len = 16; |
129 | 16.7k | *cst = (data[0] << 8) + data [1]; |
130 | | #if 0 |
131 | | if ((looking_for & SIZE) == L_16) |
132 | | *cst = (short) *cst; /* Sign extend. */ |
133 | | #endif |
134 | 16.7k | break; |
135 | 640 | case L_32: |
136 | 640 | *len = 32; |
137 | 640 | *cst = (((unsigned) data[0] << 24) + (data[1] << 16) |
138 | 640 | + (data[2] << 8) + data[3]); |
139 | 640 | break; |
140 | 0 | default: |
141 | 0 | *len = 0; |
142 | 0 | *cst = 0; |
143 | 0 | fprintf (stream, "DISP bad size\n"); |
144 | 0 | break; |
145 | 222k | } |
146 | 222k | } |
147 | | |
148 | | static const char *regnames[] = |
149 | | { |
150 | | "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h", |
151 | | "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l" |
152 | | }; |
153 | | static const char *wregnames[] = |
154 | | { |
155 | | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
156 | | "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7" |
157 | | }; |
158 | | static const char *lregnames[] = |
159 | | { |
160 | | "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7", |
161 | | "er0", "er1", "er2", "er3", "er4", "er5", "er6", "er7" |
162 | | }; |
163 | | static const char *cregnames[] = |
164 | | { |
165 | | "ccr", "exr", "mach", "macl", "", "", "vbr", "sbr" |
166 | | }; |
167 | | |
168 | | static void |
169 | | print_one_arg (disassemble_info *info, |
170 | | bfd_vma addr, |
171 | | op_type x, |
172 | | int cst, |
173 | | int cstlen, |
174 | | int rdisp_n, |
175 | | int rn, |
176 | | const char **pregnames, |
177 | | int len) |
178 | 450k | { |
179 | 450k | void * stream = info->stream; |
180 | 450k | fprintf_ftype outfn = info->fprintf_func; |
181 | | |
182 | 450k | if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ) |
183 | 13.5k | outfn (stream, "#0x%x", (unsigned) cst); |
184 | 436k | else if ((x & MODE) == IMM) |
185 | 129k | outfn (stream, "#0x%x", (unsigned) cst); |
186 | 307k | else if ((x & MODE) == DBIT || (x & MODE) == KBIT) |
187 | 215 | outfn (stream, "#%d", (unsigned) cst); |
188 | 307k | else if ((x & MODE) == CONST_2) |
189 | 864 | outfn (stream, "#2"); |
190 | 306k | else if ((x & MODE) == CONST_4) |
191 | 314 | outfn (stream, "#4"); |
192 | 306k | else if ((x & MODE) == CONST_8) |
193 | 187 | outfn (stream, "#8"); |
194 | 306k | else if ((x & MODE) == CONST_16) |
195 | 342 | outfn (stream, "#16"); |
196 | 305k | else if ((x & MODE) == REG) |
197 | 239k | { |
198 | 239k | switch (x & SIZE) |
199 | 239k | { |
200 | 210k | case L_8: |
201 | 210k | outfn (stream, "%s", regnames[rn]); |
202 | 210k | break; |
203 | 23.2k | case L_16: |
204 | 23.2k | case L_16U: |
205 | 23.2k | outfn (stream, "%s", wregnames[rn]); |
206 | 23.2k | break; |
207 | 0 | case L_P: |
208 | 5.60k | case L_32: |
209 | 5.60k | outfn (stream, "%s", lregnames[rn]); |
210 | 5.60k | break; |
211 | 239k | } |
212 | 239k | } |
213 | 66.6k | else if ((x & MODE) == LOWREG) |
214 | 63 | { |
215 | 63 | switch (x & SIZE) |
216 | 63 | { |
217 | 28 | case L_8: |
218 | | /* Always take low half of reg. */ |
219 | 28 | outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]); |
220 | 28 | break; |
221 | 35 | case L_16: |
222 | 35 | case L_16U: |
223 | | /* Always take low half of reg. */ |
224 | 35 | outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]); |
225 | 35 | break; |
226 | 0 | case L_P: |
227 | 0 | case L_32: |
228 | 0 | outfn (stream, "%s.l", lregnames[rn]); |
229 | 0 | break; |
230 | 63 | } |
231 | 63 | } |
232 | 66.5k | else if ((x & MODE) == POSTINC) |
233 | 1.83k | outfn (stream, "@%s+", pregnames[rn]); |
234 | | |
235 | 64.7k | else if ((x & MODE) == POSTDEC) |
236 | 65 | outfn (stream, "@%s-", pregnames[rn]); |
237 | | |
238 | 64.6k | else if ((x & MODE) == PREINC) |
239 | 11 | outfn (stream, "@+%s", pregnames[rn]); |
240 | | |
241 | 64.6k | else if ((x & MODE) == PREDEC) |
242 | 373 | outfn (stream, "@-%s", pregnames[rn]); |
243 | | |
244 | 64.2k | else if ((x & MODE) == IND) |
245 | 2.80k | outfn (stream, "@%s", pregnames[rn]); |
246 | | |
247 | 61.4k | else if ((x & MODE) == ABS || (x & ABSJMP)) |
248 | 33.8k | outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen); |
249 | | |
250 | 27.6k | else if ((x & MODE) == MEMIND) |
251 | 2.35k | outfn (stream, "@@%d (0x%x)", cst, cst); |
252 | | |
253 | 25.2k | else if ((x & MODE) == VECIND) |
254 | 2.17k | { |
255 | | /* FIXME Multiplier should be 2 or 4, depending on processor mode, |
256 | | by which is meant "normal" vs. "middle", "advanced", "maximum". */ |
257 | | |
258 | 2.17k | int offset = (cst + 0x80) * 4; |
259 | 2.17k | outfn (stream, "@@%d (0x%x)", offset, offset); |
260 | 2.17k | } |
261 | 23.1k | else if ((x & MODE) == PCREL) |
262 | 8.94k | { |
263 | 8.94k | if ((x & SIZE) == L_16 || |
264 | 8.94k | (x & SIZE) == L_16U) |
265 | 61 | { |
266 | 61 | outfn (stream, ".%s%d (0x%lx)", |
267 | 61 | (short) cst > 0 ? "+" : "", |
268 | 61 | (short) cst, |
269 | 61 | (long)(addr + (short) cst + len)); |
270 | 61 | } |
271 | 8.88k | else |
272 | 8.88k | { |
273 | 8.88k | outfn (stream, ".%s%d (0x%lx)", |
274 | 8.88k | (char) cst > 0 ? "+" : "", |
275 | 8.88k | (char) cst, |
276 | 8.88k | (long)(addr + (char) cst + len)); |
277 | 8.88k | } |
278 | 8.94k | } |
279 | 14.1k | else if ((x & MODE) == DISP) |
280 | 3.12k | outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]); |
281 | | |
282 | 11.0k | else if ((x & MODE) == INDEXB) |
283 | | /* Always take low half of reg. */ |
284 | 137 | outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen, |
285 | 137 | regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]); |
286 | | |
287 | 10.9k | else if ((x & MODE) == INDEXW) |
288 | | /* Always take low half of reg. */ |
289 | 79 | outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen, |
290 | 79 | wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]); |
291 | | |
292 | 10.8k | else if ((x & MODE) == INDEXL) |
293 | 29 | outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]); |
294 | | |
295 | 10.8k | else if (x & CTRL) |
296 | 10.8k | outfn (stream, "%s", cregnames[rn]); |
297 | | |
298 | 0 | else if ((x & MODE) == CCR) |
299 | 0 | outfn (stream, "ccr"); |
300 | | |
301 | 0 | else if ((x & MODE) == EXR) |
302 | 0 | outfn (stream, "exr"); |
303 | | |
304 | 0 | else if ((x & MODE) == MACREG) |
305 | 0 | outfn (stream, "mac%c", cst ? 'l' : 'h'); |
306 | | |
307 | 0 | else |
308 | | /* xgettext:c-format */ |
309 | 0 | outfn (stream, _("Hmmmm 0x%x"), x); |
310 | 450k | } |
311 | | |
312 | | static unsigned int |
313 | | bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach) |
314 | 333k | { |
315 | | /* Find the first entry in the table for this opcode. */ |
316 | 333k | int regno[3] = { 0, 0, 0 }; |
317 | 333k | int dispregno[3] = { 0, 0, 0 }; |
318 | 333k | int cst[3] = { 0, 0, 0 }; |
319 | 333k | int cstlen[3] = { 0, 0, 0 }; |
320 | 333k | static bool init = 0; |
321 | 333k | const struct h8_instruction *qi; |
322 | 333k | char const **pregnames = mach != 0 ? lregnames : wregnames; |
323 | 333k | int status; |
324 | 333k | unsigned int maxlen; |
325 | 333k | unsigned char data[MAX_CODE_NIBBLES / 2]; |
326 | 333k | void *stream = info->stream; |
327 | 333k | fprintf_ftype outfn = info->fprintf_func; |
328 | | |
329 | 333k | if (!init) |
330 | 2 | { |
331 | 2 | bfd_h8_disassemble_init (); |
332 | 2 | init = 1; |
333 | 2 | } |
334 | | |
335 | 333k | status = info->read_memory_func (addr, data, 2, info); |
336 | 333k | if (status != 0) |
337 | 156 | { |
338 | 156 | info->memory_error_func (status, addr, info); |
339 | 156 | return -1; |
340 | 156 | } |
341 | | |
342 | 2.66M | for (maxlen = 2; maxlen < sizeof (data); maxlen += 2) |
343 | 2.32M | { |
344 | 2.32M | status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info); |
345 | 2.32M | if (status != 0) |
346 | 2.34k | break; |
347 | 2.32M | } |
348 | | |
349 | | /* Find the exact opcode/arg combo. */ |
350 | 1.46G | for (qi = h8_instructions; qi->opcode->name; qi++) |
351 | 1.46G | { |
352 | 1.46G | const struct h8_opcode *q; |
353 | 1.46G | const op_type *nib; |
354 | 1.46G | unsigned int len; |
355 | 1.46G | op_type looking_for; |
356 | | |
357 | 1.46G | if (qi->length > maxlen) |
358 | 4.88M | continue; |
359 | | |
360 | 1.45G | q = qi->opcode; |
361 | 1.45G | nib = q->data.nib; |
362 | 1.45G | len = 0; |
363 | 1.95G | while ((looking_for = *nib) != (op_type) E) |
364 | 1.95G | { |
365 | 1.95G | int thisnib; |
366 | 1.95G | int opnr; |
367 | | |
368 | 1.95G | OPCODES_ASSERT (len / 2 < maxlen); |
369 | 1.95G | thisnib = data[len / 2]; |
370 | 1.95G | thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf); |
371 | 1.95G | opnr = ((looking_for & OP3) == OP3 ? 2 |
372 | 1.95G | : (looking_for & DST) == DST ? 1 : 0); |
373 | | |
374 | 1.95G | if (looking_for < 16 && looking_for >= 0) |
375 | 1.95G | { |
376 | 1.95G | if (looking_for != thisnib) |
377 | 1.45G | goto fail; |
378 | 1.95G | } |
379 | 3.97M | else |
380 | 3.97M | { |
381 | 3.97M | if ((int) looking_for & (int) B31) |
382 | 600k | { |
383 | 600k | if (!((thisnib & 0x8) != 0)) |
384 | 440k | goto fail; |
385 | | |
386 | 159k | looking_for = (op_type) ((int) looking_for & ~(int) B31); |
387 | 159k | thisnib &= 0x7; |
388 | 159k | } |
389 | 3.37M | else if ((int) looking_for & (int) B30) |
390 | 2.39M | { |
391 | 2.39M | if (!((thisnib & 0x8) == 0)) |
392 | 312k | goto fail; |
393 | | |
394 | 2.08M | looking_for = (op_type) ((int) looking_for & ~(int) B30); |
395 | 2.08M | } |
396 | | |
397 | 3.21M | if ((int) looking_for & (int) B21) |
398 | 1.23M | { |
399 | 1.23M | if (!((thisnib & 0x4) != 0)) |
400 | 1.20M | goto fail; |
401 | | |
402 | 33.5k | looking_for = (op_type) ((int) looking_for & ~(int) B21); |
403 | 33.5k | thisnib &= 0xb; |
404 | 33.5k | } |
405 | 1.98M | else if ((int) looking_for & (int) B20) |
406 | 22.5k | { |
407 | 22.5k | if (!((thisnib & 0x4) == 0)) |
408 | 1.08k | goto fail; |
409 | | |
410 | 21.4k | looking_for = (op_type) ((int) looking_for & ~(int) B20); |
411 | 21.4k | } |
412 | 2.01M | if ((int) looking_for & (int) B11) |
413 | 0 | { |
414 | 0 | if (!((thisnib & 0x2) != 0)) |
415 | 0 | goto fail; |
416 | | |
417 | 0 | looking_for = (op_type) ((int) looking_for & ~(int) B11); |
418 | 0 | thisnib &= 0xd; |
419 | 0 | } |
420 | 2.01M | else if ((int) looking_for & (int) B10) |
421 | 0 | { |
422 | 0 | if (!((thisnib & 0x2) == 0)) |
423 | 0 | goto fail; |
424 | | |
425 | 0 | looking_for = (op_type) ((int) looking_for & ~(int) B10); |
426 | 0 | } |
427 | | |
428 | 2.01M | if ((int) looking_for & (int) B01) |
429 | 1.78k | { |
430 | 1.78k | if (!((thisnib & 0x1) != 0)) |
431 | 673 | goto fail; |
432 | | |
433 | 1.11k | looking_for = (op_type) ((int) looking_for & ~(int) B01); |
434 | 1.11k | thisnib &= 0xe; |
435 | 1.11k | } |
436 | 2.01M | else if ((int) looking_for & (int) B00) |
437 | 20.0k | { |
438 | 20.0k | if (!((thisnib & 0x1) == 0)) |
439 | 12.2k | goto fail; |
440 | | |
441 | 7.79k | looking_for = (op_type) ((int) looking_for & ~(int) B00); |
442 | 7.79k | } |
443 | | |
444 | 2.00M | if (looking_for & IGNORE) |
445 | 25.1k | { |
446 | | /* Hitachi has declared that IGNORE must be zero. */ |
447 | 25.1k | if (thisnib != 0) |
448 | 22.7k | goto fail; |
449 | 25.1k | } |
450 | 1.97M | else if ((looking_for & MODE) == DATA) |
451 | 369k | { |
452 | 369k | ; /* Skip embedded data. */ |
453 | 369k | } |
454 | 1.60M | else if ((looking_for & MODE) == DBIT) |
455 | 3.50k | { |
456 | | /* Exclude adds/subs by looking at bit 0 and 2, and |
457 | | make sure the operand size, either w or l, |
458 | | matches by looking at bit 1. */ |
459 | 3.50k | if ((looking_for & 7) != (thisnib & 7)) |
460 | 3.19k | goto fail; |
461 | | |
462 | 312 | cst[opnr] = (thisnib & 0x8) ? 2 : 1; |
463 | 312 | } |
464 | 1.60M | else if ((looking_for & MODE) == DISP |
465 | 1.60M | || (looking_for & MODE) == ABS |
466 | 1.60M | || (looking_for & MODE) == PCREL |
467 | 1.60M | || (looking_for & MODE) == INDEXB |
468 | 1.60M | || (looking_for & MODE) == INDEXW |
469 | 1.60M | || (looking_for & MODE) == INDEXL) |
470 | 222k | { |
471 | 222k | int extra; |
472 | 222k | switch (looking_for & SIZE) |
473 | 222k | { |
474 | 3.26k | case L_16: |
475 | 16.7k | case L_16U: |
476 | 16.7k | extra = 1; |
477 | 16.7k | break; |
478 | 640 | case L_32: |
479 | 640 | extra = 3; |
480 | 640 | break; |
481 | 205k | default: |
482 | 205k | extra = 0; |
483 | 205k | break; |
484 | 222k | } |
485 | 222k | OPCODES_ASSERT (len / 2 + extra < maxlen); |
486 | 222k | extract_immediate (stream, looking_for, thisnib, |
487 | 222k | data + len / 2, cst + opnr, |
488 | 222k | cstlen + opnr, q); |
489 | | /* Even address == bra, odd == bra/s. */ |
490 | 222k | if (q->how == O (O_BRAS, SB)) |
491 | 641 | cst[opnr] -= 1; |
492 | 222k | } |
493 | 1.38M | else if ((looking_for & MODE) == REG |
494 | 1.38M | || (looking_for & MODE) == LOWREG |
495 | 1.38M | || (looking_for & MODE) == IND |
496 | 1.38M | || (looking_for & MODE) == PREINC |
497 | 1.38M | || (looking_for & MODE) == POSTINC |
498 | 1.38M | || (looking_for & MODE) == PREDEC |
499 | 1.38M | || (looking_for & MODE) == POSTDEC) |
500 | 373k | { |
501 | 373k | regno[opnr] = thisnib; |
502 | 373k | } |
503 | 1.01M | else if (looking_for & CTRL) /* Control Register. */ |
504 | 18.7k | { |
505 | 18.7k | thisnib &= 7; |
506 | 18.7k | if (((looking_for & MODE) == CCR && (thisnib != C_CCR)) |
507 | 18.7k | || ((looking_for & MODE) == EXR && (thisnib != C_EXR)) |
508 | 18.7k | || ((looking_for & MODE) == MACH && (thisnib != C_MACH)) |
509 | 18.7k | || ((looking_for & MODE) == MACL && (thisnib != C_MACL)) |
510 | 18.7k | || ((looking_for & MODE) == VBR && (thisnib != C_VBR)) |
511 | 18.7k | || ((looking_for & MODE) == SBR && (thisnib != C_SBR))) |
512 | 3.45k | goto fail; |
513 | 15.3k | if (((looking_for & MODE) == CCR_EXR |
514 | 15.3k | && (thisnib != C_CCR && thisnib != C_EXR)) |
515 | 15.3k | || ((looking_for & MODE) == VBR_SBR |
516 | 14.8k | && (thisnib != C_VBR && thisnib != C_SBR)) |
517 | 15.3k | || ((looking_for & MODE) == MACREG |
518 | 14.2k | && (thisnib != C_MACH && thisnib != C_MACL))) |
519 | 2.89k | goto fail; |
520 | 12.4k | if (((looking_for & MODE) == CC_EX_VB_SB |
521 | 12.4k | && (thisnib != C_CCR && thisnib != C_EXR |
522 | 0 | && thisnib != C_VBR && thisnib != C_SBR))) |
523 | 0 | goto fail; |
524 | | |
525 | 12.4k | regno[opnr] = thisnib; |
526 | 12.4k | } |
527 | 991k | else if ((looking_for & SIZE) == L_5) |
528 | 8.40k | { |
529 | 8.40k | cst[opnr] = data[len / 2] & 31; |
530 | 8.40k | cstlen[opnr] = 5; |
531 | 8.40k | } |
532 | 983k | else if ((looking_for & SIZE) == L_4) |
533 | 142 | { |
534 | 142 | cst[opnr] = thisnib; |
535 | 142 | cstlen[opnr] = 4; |
536 | 142 | } |
537 | 983k | else if ((looking_for & SIZE) == L_16 |
538 | 983k | || (looking_for & SIZE) == L_16U) |
539 | 1.20k | { |
540 | 1.20k | OPCODES_ASSERT (len / 2 + 1 < maxlen); |
541 | 1.20k | cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2]; |
542 | 1.20k | cstlen[opnr] = 16; |
543 | 1.20k | } |
544 | 981k | else if ((looking_for & MODE) == MEMIND) |
545 | 2.35k | { |
546 | 2.35k | cst[opnr] = data[1]; |
547 | 2.35k | } |
548 | 979k | else if ((looking_for & MODE) == VECIND) |
549 | 2.17k | { |
550 | 2.17k | cst[opnr] = data[1] & 0x7f; |
551 | 2.17k | } |
552 | 977k | else if ((looking_for & SIZE) == L_32) |
553 | 271 | { |
554 | 271 | unsigned int i = len / 2; |
555 | | |
556 | 271 | OPCODES_ASSERT (i + 3 < maxlen); |
557 | 271 | cst[opnr] = (((unsigned) data[i] << 24) |
558 | 271 | | (data[i + 1] << 16) |
559 | 271 | | (data[i + 2] << 8) |
560 | 271 | | (data[i + 3])); |
561 | | |
562 | 271 | cstlen[opnr] = 32; |
563 | 271 | } |
564 | 977k | else if ((looking_for & SIZE) == L_24) |
565 | 929 | { |
566 | 929 | unsigned int i = len / 2; |
567 | | |
568 | 929 | OPCODES_ASSERT (i + 2 < maxlen); |
569 | 929 | cst[opnr] = |
570 | 929 | (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]); |
571 | 929 | cstlen[opnr] = 24; |
572 | 929 | } |
573 | 976k | else if (looking_for & DISPREG) |
574 | 830k | { |
575 | 830k | dispregno[opnr] = thisnib & 7; |
576 | 830k | } |
577 | 145k | else if ((looking_for & MODE) == KBIT) |
578 | 2.53k | { |
579 | 2.53k | switch (thisnib) |
580 | 2.53k | { |
581 | 249 | case 9: |
582 | 249 | cst[opnr] = 4; |
583 | 249 | break; |
584 | 66 | case 8: |
585 | 66 | cst[opnr] = 2; |
586 | 66 | break; |
587 | 849 | case 0: |
588 | 849 | cst[opnr] = 1; |
589 | 849 | break; |
590 | 1.36k | default: |
591 | 1.36k | goto fail; |
592 | 2.53k | } |
593 | 2.53k | } |
594 | 143k | else if ((looking_for & SIZE) == L_8) |
595 | 127k | { |
596 | 127k | cstlen[opnr] = 8; |
597 | 127k | cst[opnr] = data[len / 2]; |
598 | 127k | } |
599 | 15.7k | else if ((looking_for & SIZE) == L_3 |
600 | 15.7k | || (looking_for & SIZE) == L_3NZ) |
601 | 15.3k | { |
602 | 15.3k | cst[opnr] = thisnib & 0x7; |
603 | 15.3k | if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ) |
604 | 1.62k | goto fail; |
605 | 15.3k | } |
606 | 329 | else if ((looking_for & SIZE) == L_2) |
607 | 329 | { |
608 | 329 | cstlen[opnr] = 2; |
609 | 329 | cst[opnr] = thisnib & 0x3; |
610 | 329 | } |
611 | 0 | else if ((looking_for & MODE) == MACREG) |
612 | 0 | { |
613 | 0 | cst[opnr] = (thisnib == 3); |
614 | 0 | } |
615 | 0 | else |
616 | | /* xgettext:c-format */ |
617 | 0 | outfn (stream, _("Don't understand 0x%x \n"), looking_for); |
618 | 2.00M | } |
619 | | |
620 | 502M | len++; |
621 | 502M | nib++; |
622 | 502M | } |
623 | | |
624 | 275k | outfn (stream, "%s\t", q->name); |
625 | | |
626 | | /* Gross. Disgusting. */ |
627 | 275k | if (strcmp (q->name, "ldm.l") == 0) |
628 | 0 | { |
629 | 0 | int count, high; |
630 | |
|
631 | 0 | count = (data[1] / 16) & 0x3; |
632 | 0 | high = regno[1]; |
633 | |
|
634 | 0 | outfn (stream, "@sp+,er%d-er%d", high - count, high); |
635 | 0 | return qi->length; |
636 | 0 | } |
637 | | |
638 | 275k | if (strcmp (q->name, "stm.l") == 0) |
639 | 0 | { |
640 | 0 | int count, low; |
641 | |
|
642 | 0 | count = (data[1] / 16) & 0x3; |
643 | 0 | low = regno[0]; |
644 | |
|
645 | 0 | outfn (stream, "er%d-er%d,@-sp", low, low + count); |
646 | 0 | return qi->length; |
647 | 0 | } |
648 | 275k | if (strcmp (q->name, "rte/l") == 0 |
649 | 275k | || strcmp (q->name, "rts/l") == 0) |
650 | 1.01k | { |
651 | 1.01k | if (regno[0] == 0) |
652 | 350 | outfn (stream, "er%d", regno[1]); |
653 | 665 | else |
654 | 665 | outfn (stream, "er%d-er%d", regno[1] - regno[0], |
655 | 665 | regno[1]); |
656 | 1.01k | return qi->length; |
657 | 1.01k | } |
658 | 274k | if (startswith (q->name, "mova")) |
659 | 300 | { |
660 | 300 | const op_type *args = q->args.nib; |
661 | | |
662 | 300 | if (args[1] == (op_type) E) |
663 | 210 | { |
664 | | /* Short form. */ |
665 | 210 | print_one_arg (info, addr, args[0], cst[0], |
666 | 210 | cstlen[0], dispregno[0], regno[0], |
667 | 210 | pregnames, qi->length); |
668 | 210 | outfn (stream, ",er%d", dispregno[0]); |
669 | 210 | } |
670 | 90 | else |
671 | 90 | { |
672 | 90 | outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]); |
673 | 90 | print_one_arg (info, addr, args[1], cst[1], |
674 | 90 | cstlen[1], dispregno[1], regno[1], |
675 | 90 | pregnames, qi->length); |
676 | 90 | outfn (stream, ".%c),", |
677 | 90 | (args[0] & MODE) == INDEXB ? 'b' : 'w'); |
678 | 90 | print_one_arg (info, addr, args[2], cst[2], |
679 | 90 | cstlen[2], dispregno[2], regno[2], |
680 | 90 | pregnames, qi->length); |
681 | 90 | } |
682 | 300 | return qi->length; |
683 | 300 | } |
684 | | /* Fill in the args. */ |
685 | 274k | { |
686 | 274k | const op_type *args = q->args.nib; |
687 | 274k | int hadone = 0; |
688 | 274k | int nargs; |
689 | | |
690 | | /* Special case handling for the adds and subs instructions |
691 | | since in H8 mode thay can only take the r0-r7 registers |
692 | | but in other (higher) modes they can take the er0-er7 |
693 | | registers as well. */ |
694 | 274k | if (strcmp (qi->opcode->name, "adds") == 0 |
695 | 274k | || strcmp (qi->opcode->name, "subs") == 0) |
696 | 1.16k | { |
697 | 1.16k | outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]); |
698 | 1.16k | return qi->length; |
699 | 1.16k | } |
700 | | |
701 | 273k | for (nargs = 0; |
702 | 723k | nargs < 3 && args[nargs] != (op_type) E; |
703 | 449k | nargs++) |
704 | 449k | { |
705 | 449k | int x = args[nargs]; |
706 | | |
707 | 449k | if (hadone) |
708 | 214k | outfn (stream, ","); |
709 | | |
710 | 449k | print_one_arg (info, addr, x, |
711 | 449k | cst[nargs], cstlen[nargs], |
712 | 449k | dispregno[nargs], regno[nargs], |
713 | 449k | pregnames, qi->length); |
714 | | |
715 | 449k | hadone = 1; |
716 | 449k | } |
717 | 273k | } |
718 | 0 | return qi->length; |
719 | | |
720 | 1.45G | fail: |
721 | 1.45G | ; |
722 | 1.45G | } |
723 | | |
724 | | /* Fell off the end. */ |
725 | 58.1k | outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]); |
726 | 58.1k | return 2; |
727 | 333k | } |
728 | | |
729 | | int |
730 | | print_insn_h8300 (bfd_vma addr, disassemble_info *info) |
731 | 303k | { |
732 | 303k | return bfd_h8_disassemble (addr, info, 0); |
733 | 303k | } |
734 | | |
735 | | int |
736 | | print_insn_h8300h (bfd_vma addr, disassemble_info *info) |
737 | 20.3k | { |
738 | 20.3k | return bfd_h8_disassemble (addr, info, 1); |
739 | 20.3k | } |
740 | | |
741 | | int |
742 | | print_insn_h8300s (bfd_vma addr, disassemble_info *info) |
743 | 9.90k | { |
744 | 9.90k | return bfd_h8_disassemble (addr, info, 2); |
745 | 9.90k | } |