/src/binutils-gdb/opcodes/h8300-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Disassemble h8300 instructions. |
2 | | Copyright (C) 1993-2025 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 | 311k | { |
79 | 311k | switch (looking_for & SIZE) |
80 | 311k | { |
81 | 75.7k | case L_2: |
82 | 75.7k | *len = 2; |
83 | 75.7k | *cst = thisnib & 3; |
84 | | |
85 | | /* DISP2 special treatment. */ |
86 | 75.7k | if ((looking_for & MODE) == DISP) |
87 | 75.7k | { |
88 | 75.7k | if (OP_KIND (q->how) == O_MOVAB |
89 | 75.7k | || OP_KIND (q->how) == O_MOVAW |
90 | 75.7k | || OP_KIND (q->how) == O_MOVAL) |
91 | 680 | { |
92 | | /* Handling for mova insn. */ |
93 | 680 | switch (q->args.nib[0] & MODE) |
94 | 680 | { |
95 | 132 | case INDEXB: |
96 | 132 | default: |
97 | 132 | break; |
98 | 548 | case INDEXW: |
99 | 548 | *cst *= 2; |
100 | 548 | break; |
101 | 0 | case INDEXL: |
102 | 0 | *cst *= 4; |
103 | 0 | break; |
104 | 680 | } |
105 | 680 | } |
106 | 75.0k | else |
107 | 75.0k | { |
108 | | /* Handling for non-mova insn. */ |
109 | 75.0k | switch (OP_SIZE (q->how)) |
110 | 75.0k | { |
111 | 18.4k | default: break; |
112 | 21.9k | case SW: |
113 | 21.9k | *cst *= 2; |
114 | 21.9k | break; |
115 | 34.6k | case SL: |
116 | 34.6k | *cst *= 4; |
117 | 34.6k | break; |
118 | 75.0k | } |
119 | 75.0k | } |
120 | 75.7k | } |
121 | 75.7k | break; |
122 | 228k | case L_8: |
123 | 228k | *len = 8; |
124 | 228k | *cst = data[0]; |
125 | 228k | break; |
126 | 4.81k | case L_16: |
127 | 6.60k | case L_16U: |
128 | 6.60k | *len = 16; |
129 | 6.60k | *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 | 6.60k | break; |
135 | 1.20k | case L_32: |
136 | 1.20k | *len = 32; |
137 | 1.20k | *cst = (((unsigned) data[0] << 24) + (data[1] << 16) |
138 | 1.20k | + (data[2] << 8) + data[3]); |
139 | 1.20k | break; |
140 | 0 | default: |
141 | 0 | *len = 0; |
142 | 0 | *cst = 0; |
143 | 0 | fprintf (stream, "DISP bad size\n"); |
144 | 0 | break; |
145 | 311k | } |
146 | 311k | } |
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 | 610k | { |
179 | 610k | void * stream = info->stream; |
180 | 610k | fprintf_ftype outfn = info->fprintf_func; |
181 | | |
182 | 610k | if ((x & SIZE) == L_3 || (x & SIZE) == L_3NZ) |
183 | 19.3k | outfn (stream, "#0x%x", (unsigned) cst); |
184 | 591k | else if ((x & MODE) == IMM) |
185 | 164k | outfn (stream, "#0x%x", (unsigned) cst); |
186 | 427k | else if ((x & MODE) == DBIT || (x & MODE) == KBIT) |
187 | 300 | outfn (stream, "#%d", (unsigned) cst); |
188 | 426k | else if ((x & MODE) == CONST_2) |
189 | 1.05k | outfn (stream, "#2"); |
190 | 425k | else if ((x & MODE) == CONST_4) |
191 | 442 | outfn (stream, "#4"); |
192 | 425k | else if ((x & MODE) == CONST_8) |
193 | 446 | outfn (stream, "#8"); |
194 | 424k | else if ((x & MODE) == CONST_16) |
195 | 448 | outfn (stream, "#16"); |
196 | 424k | else if ((x & MODE) == REG) |
197 | 324k | { |
198 | 324k | switch (x & SIZE) |
199 | 324k | { |
200 | 279k | case L_8: |
201 | 279k | outfn (stream, "%s", regnames[rn]); |
202 | 279k | break; |
203 | 37.2k | case L_16: |
204 | 37.2k | case L_16U: |
205 | 37.2k | outfn (stream, "%s", wregnames[rn]); |
206 | 37.2k | break; |
207 | 0 | case L_P: |
208 | 7.40k | case L_32: |
209 | 7.40k | outfn (stream, "%s", lregnames[rn]); |
210 | 7.40k | break; |
211 | 324k | } |
212 | 324k | } |
213 | 100k | else if ((x & MODE) == LOWREG) |
214 | 337 | { |
215 | 337 | switch (x & SIZE) |
216 | 337 | { |
217 | 181 | case L_8: |
218 | | /* Always take low half of reg. */ |
219 | 181 | outfn (stream, "%s.b", regnames[rn < 8 ? rn + 8 : rn]); |
220 | 181 | break; |
221 | 156 | case L_16: |
222 | 156 | case L_16U: |
223 | | /* Always take low half of reg. */ |
224 | 156 | outfn (stream, "%s.w", wregnames[rn < 8 ? rn : rn - 8]); |
225 | 156 | break; |
226 | 0 | case L_P: |
227 | 0 | case L_32: |
228 | 0 | outfn (stream, "%s.l", lregnames[rn]); |
229 | 0 | break; |
230 | 337 | } |
231 | 337 | } |
232 | 99.8k | else if ((x & MODE) == POSTINC) |
233 | 3.97k | outfn (stream, "@%s+", pregnames[rn]); |
234 | | |
235 | 95.9k | else if ((x & MODE) == POSTDEC) |
236 | 251 | outfn (stream, "@%s-", pregnames[rn]); |
237 | | |
238 | 95.6k | else if ((x & MODE) == PREINC) |
239 | 48 | outfn (stream, "@+%s", pregnames[rn]); |
240 | | |
241 | 95.6k | else if ((x & MODE) == PREDEC) |
242 | 614 | outfn (stream, "@-%s", pregnames[rn]); |
243 | | |
244 | 94.9k | else if ((x & MODE) == IND) |
245 | 4.53k | outfn (stream, "@%s", pregnames[rn]); |
246 | | |
247 | 90.4k | else if ((x & MODE) == ABS || (x & ABSJMP)) |
248 | 47.3k | outfn (stream, "@0x%x:%d", (unsigned) cst, cstlen); |
249 | | |
250 | 43.1k | else if ((x & MODE) == MEMIND) |
251 | 3.16k | outfn (stream, "@@%d (0x%x)", cst, cst); |
252 | | |
253 | 39.9k | else if ((x & MODE) == VECIND) |
254 | 1.37k | { |
255 | | /* FIXME Multiplier should be 2 or 4, depending on processor mode, |
256 | | by which is meant "normal" vs. "middle", "advanced", "maximum". */ |
257 | | |
258 | 1.37k | int offset = (cst + 0x80) * 4; |
259 | 1.37k | outfn (stream, "@@%d (0x%x)", offset, offset); |
260 | 1.37k | } |
261 | 38.5k | else if ((x & MODE) == PCREL) |
262 | 15.6k | { |
263 | 15.6k | if ((x & SIZE) == L_16 || |
264 | 15.6k | (x & SIZE) == L_16U) |
265 | 152 | { |
266 | 152 | outfn (stream, ".%s%d (0x%lx)", |
267 | 152 | (short) cst > 0 ? "+" : "", |
268 | 152 | (short) cst, |
269 | 152 | (long)(addr + (short) cst + len)); |
270 | 152 | } |
271 | 15.4k | else |
272 | 15.4k | { |
273 | 15.4k | outfn (stream, ".%s%d (0x%lx)", |
274 | 15.4k | (char) cst > 0 ? "+" : "", |
275 | 15.4k | (char) cst, |
276 | 15.4k | (long)(addr + (char) cst + len)); |
277 | 15.4k | } |
278 | 15.6k | } |
279 | 22.9k | else if ((x & MODE) == DISP) |
280 | 4.27k | outfn (stream, "@(0x%x:%d,%s)", cst, cstlen, pregnames[rdisp_n]); |
281 | | |
282 | 18.6k | else if ((x & MODE) == INDEXB) |
283 | | /* Always take low half of reg. */ |
284 | 240 | outfn (stream, "@(0x%x:%d,%s.b)", cst, cstlen, |
285 | 240 | regnames[rdisp_n < 8 ? rdisp_n + 8 : rdisp_n]); |
286 | | |
287 | 18.4k | else if ((x & MODE) == INDEXW) |
288 | | /* Always take low half of reg. */ |
289 | 124 | outfn (stream, "@(0x%x:%d,%s.w)", cst, cstlen, |
290 | 124 | wregnames[rdisp_n < 8 ? rdisp_n : rdisp_n - 8]); |
291 | | |
292 | 18.2k | else if ((x & MODE) == INDEXL) |
293 | 208 | outfn (stream, "@(0x%x:%d,%s.l)", cst, cstlen, lregnames[rdisp_n]); |
294 | | |
295 | 18.0k | else if (x & CTRL) |
296 | 18.0k | 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 | 610k | } |
311 | | |
312 | | static unsigned int |
313 | | bfd_h8_disassemble (bfd_vma addr, disassemble_info *info, int mach) |
314 | 500k | { |
315 | | /* Find the first entry in the table for this opcode. */ |
316 | 500k | int regno[3] = { 0, 0, 0 }; |
317 | 500k | int dispregno[3] = { 0, 0, 0 }; |
318 | 500k | int cst[3] = { 0, 0, 0 }; |
319 | 500k | int cstlen[3] = { 0, 0, 0 }; |
320 | 500k | static bool init = 0; |
321 | 500k | const struct h8_instruction *qi; |
322 | 500k | char const **pregnames = mach != 0 ? lregnames : wregnames; |
323 | 500k | int status; |
324 | 500k | unsigned int maxlen; |
325 | 500k | unsigned char data[MAX_CODE_NIBBLES / 2]; |
326 | 500k | void *stream = info->stream; |
327 | 500k | fprintf_ftype outfn = info->fprintf_func; |
328 | | |
329 | 500k | if (!init) |
330 | 2 | { |
331 | 2 | bfd_h8_disassemble_init (); |
332 | 2 | init = 1; |
333 | 2 | } |
334 | | |
335 | 500k | status = info->read_memory_func (addr, data, 2, info); |
336 | 500k | if (status != 0) |
337 | 249 | { |
338 | 249 | info->memory_error_func (status, addr, info); |
339 | 249 | return -1; |
340 | 249 | } |
341 | | |
342 | 3.98M | for (maxlen = 2; maxlen < sizeof (data); maxlen += 2) |
343 | 3.48M | { |
344 | 3.48M | status = info->read_memory_func (addr + maxlen, data + maxlen, 2, info); |
345 | 3.48M | if (status != 0) |
346 | 4.38k | break; |
347 | 3.48M | } |
348 | | |
349 | | /* Find the exact opcode/arg combo. */ |
350 | 2.23G | for (qi = h8_instructions; qi->opcode->name; qi++) |
351 | 2.23G | { |
352 | 2.23G | const struct h8_opcode *q; |
353 | 2.23G | const op_type *nib; |
354 | 2.23G | unsigned int len; |
355 | 2.23G | op_type looking_for; |
356 | | |
357 | 2.23G | if (qi->length > maxlen) |
358 | 9.23M | continue; |
359 | | |
360 | 2.22G | q = qi->opcode; |
361 | 2.22G | nib = q->data.nib; |
362 | 2.22G | len = 0; |
363 | 3.01G | while ((looking_for = *nib) != (op_type) E) |
364 | 3.01G | { |
365 | 3.01G | int thisnib; |
366 | 3.01G | int opnr; |
367 | | |
368 | 3.01G | OPCODES_ASSERT (len / 2 < maxlen); |
369 | 3.01G | thisnib = data[len / 2]; |
370 | 3.01G | thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib / 16) & 0xf); |
371 | 3.01G | opnr = ((looking_for & OP3) == OP3 ? 2 |
372 | 3.01G | : (looking_for & DST) == DST ? 1 : 0); |
373 | | |
374 | 3.01G | if (looking_for < 16 && looking_for >= 0) |
375 | 3.01G | { |
376 | 3.01G | if (looking_for != thisnib) |
377 | 2.21G | goto fail; |
378 | 3.01G | } |
379 | 4.49M | else |
380 | 4.49M | { |
381 | 4.49M | if ((int) looking_for & (int) B31) |
382 | 828k | { |
383 | 828k | if (!((thisnib & 0x8) != 0)) |
384 | 567k | goto fail; |
385 | | |
386 | 260k | looking_for = (op_type) ((int) looking_for & ~(int) B31); |
387 | 260k | thisnib &= 0x7; |
388 | 260k | } |
389 | 3.66M | else if ((int) looking_for & (int) B30) |
390 | 2.29M | { |
391 | 2.29M | if (!((thisnib & 0x8) == 0)) |
392 | 542k | goto fail; |
393 | | |
394 | 1.75M | looking_for = (op_type) ((int) looking_for & ~(int) B30); |
395 | 1.75M | } |
396 | | |
397 | 3.38M | if ((int) looking_for & (int) B21) |
398 | 754k | { |
399 | 754k | if (!((thisnib & 0x4) != 0)) |
400 | 691k | goto fail; |
401 | | |
402 | 62.5k | looking_for = (op_type) ((int) looking_for & ~(int) B21); |
403 | 62.5k | thisnib &= 0xb; |
404 | 62.5k | } |
405 | 2.63M | else if ((int) looking_for & (int) B20) |
406 | 16.8k | { |
407 | 16.8k | if (!((thisnib & 0x4) == 0)) |
408 | 1.87k | goto fail; |
409 | | |
410 | 15.0k | looking_for = (op_type) ((int) looking_for & ~(int) B20); |
411 | 15.0k | } |
412 | 2.69M | if ((int) looking_for & (int) B11) |
413 | 864 | { |
414 | 864 | if (!((thisnib & 0x2) != 0)) |
415 | 576 | goto fail; |
416 | | |
417 | 288 | looking_for = (op_type) ((int) looking_for & ~(int) B11); |
418 | 288 | thisnib &= 0xd; |
419 | 288 | } |
420 | 2.69M | else if ((int) looking_for & (int) B10) |
421 | 864 | { |
422 | 864 | if (!((thisnib & 0x2) == 0)) |
423 | 288 | goto fail; |
424 | | |
425 | 576 | looking_for = (op_type) ((int) looking_for & ~(int) B10); |
426 | 576 | } |
427 | | |
428 | 2.69M | if ((int) looking_for & (int) B01) |
429 | 3.19k | { |
430 | 3.19k | if (!((thisnib & 0x1) != 0)) |
431 | 1.29k | goto fail; |
432 | | |
433 | 1.89k | looking_for = (op_type) ((int) looking_for & ~(int) B01); |
434 | 1.89k | thisnib &= 0xe; |
435 | 1.89k | } |
436 | 2.68M | else if ((int) looking_for & (int) B00) |
437 | 25.2k | { |
438 | 25.2k | if (!((thisnib & 0x1) == 0)) |
439 | 11.8k | goto fail; |
440 | | |
441 | 13.3k | looking_for = (op_type) ((int) looking_for & ~(int) B00); |
442 | 13.3k | } |
443 | | |
444 | 2.67M | if (looking_for & IGNORE) |
445 | 139k | { |
446 | | /* Hitachi has declared that IGNORE must be zero. */ |
447 | 139k | if (thisnib != 0) |
448 | 135k | goto fail; |
449 | 139k | } |
450 | 2.54M | else if ((looking_for & MODE) == DATA) |
451 | 456k | { |
452 | 456k | ; /* Skip embedded data. */ |
453 | 456k | } |
454 | 2.08M | else if ((looking_for & MODE) == DBIT) |
455 | 5.02k | { |
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 | 5.02k | if ((looking_for & 7) != (thisnib & 7)) |
460 | 4.59k | goto fail; |
461 | | |
462 | 426 | cst[opnr] = (thisnib & 0x8) ? 2 : 1; |
463 | 426 | } |
464 | 2.07M | else if ((looking_for & MODE) == DISP |
465 | 2.07M | || (looking_for & MODE) == ABS |
466 | 2.07M | || (looking_for & MODE) == PCREL |
467 | 2.07M | || (looking_for & MODE) == INDEXB |
468 | 2.07M | || (looking_for & MODE) == INDEXW |
469 | 2.07M | || (looking_for & MODE) == INDEXL) |
470 | 311k | { |
471 | 311k | int extra; |
472 | 311k | switch (looking_for & SIZE) |
473 | 311k | { |
474 | 4.81k | case L_16: |
475 | 6.60k | case L_16U: |
476 | 6.60k | extra = 1; |
477 | 6.60k | break; |
478 | 1.20k | case L_32: |
479 | 1.20k | extra = 3; |
480 | 1.20k | break; |
481 | 303k | default: |
482 | 303k | extra = 0; |
483 | 303k | break; |
484 | 311k | } |
485 | 311k | OPCODES_ASSERT (len / 2 + extra < maxlen); |
486 | 311k | extract_immediate (stream, looking_for, thisnib, |
487 | 311k | data + len / 2, cst + opnr, |
488 | 311k | cstlen + opnr, q); |
489 | | /* Even address == bra, odd == bra/s. */ |
490 | 311k | if (q->how == O (O_BRAS, SB)) |
491 | 664 | cst[opnr] -= 1; |
492 | 311k | } |
493 | 1.76M | else if ((looking_for & MODE) == REG |
494 | 1.76M | || (looking_for & MODE) == LOWREG |
495 | 1.76M | || (looking_for & MODE) == IND |
496 | 1.76M | || (looking_for & MODE) == PREINC |
497 | 1.76M | || (looking_for & MODE) == POSTINC |
498 | 1.76M | || (looking_for & MODE) == PREDEC |
499 | 1.76M | || (looking_for & MODE) == POSTDEC) |
500 | 733k | { |
501 | 733k | regno[opnr] = thisnib; |
502 | 733k | } |
503 | 1.03M | else if (looking_for & CTRL) /* Control Register. */ |
504 | 24.1k | { |
505 | 24.1k | thisnib &= 7; |
506 | 24.1k | if (((looking_for & MODE) == CCR && (thisnib != C_CCR)) |
507 | 24.1k | || ((looking_for & MODE) == EXR && (thisnib != C_EXR)) |
508 | 24.1k | || ((looking_for & MODE) == MACH && (thisnib != C_MACH)) |
509 | 24.1k | || ((looking_for & MODE) == MACL && (thisnib != C_MACL)) |
510 | 24.1k | || ((looking_for & MODE) == VBR && (thisnib != C_VBR)) |
511 | 24.1k | || ((looking_for & MODE) == SBR && (thisnib != C_SBR))) |
512 | 6.45k | goto fail; |
513 | 17.6k | if (((looking_for & MODE) == CCR_EXR |
514 | 17.6k | && (thisnib != C_CCR && thisnib != C_EXR)) |
515 | 17.6k | || ((looking_for & MODE) == VBR_SBR |
516 | 16.1k | && (thisnib != C_VBR && thisnib != C_SBR)) |
517 | 17.6k | || ((looking_for & MODE) == MACREG |
518 | 14.8k | && (thisnib != C_MACH && thisnib != C_MACL))) |
519 | 5.22k | 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 | 1.00M | else if ((looking_for & SIZE) == L_5) |
528 | 6.86k | { |
529 | 6.86k | cst[opnr] = data[len / 2] & 31; |
530 | 6.86k | cstlen[opnr] = 5; |
531 | 6.86k | } |
532 | 1.00M | else if ((looking_for & SIZE) == L_4) |
533 | 123 | { |
534 | 123 | cst[opnr] = thisnib; |
535 | 123 | cstlen[opnr] = 4; |
536 | 123 | } |
537 | 1.00M | else if ((looking_for & SIZE) == L_16 |
538 | 1.00M | || (looking_for & SIZE) == L_16U) |
539 | 1.60k | { |
540 | 1.60k | OPCODES_ASSERT (len / 2 + 1 < maxlen); |
541 | 1.60k | cst[opnr] = (data[len / 2]) * 256 + data[(len + 2) / 2]; |
542 | 1.60k | cstlen[opnr] = 16; |
543 | 1.60k | } |
544 | 1.00M | else if ((looking_for & MODE) == MEMIND) |
545 | 3.16k | { |
546 | 3.16k | cst[opnr] = data[1]; |
547 | 3.16k | } |
548 | 997k | else if ((looking_for & MODE) == VECIND) |
549 | 1.37k | { |
550 | 1.37k | cst[opnr] = data[1] & 0x7f; |
551 | 1.37k | } |
552 | 996k | else if ((looking_for & SIZE) == L_32) |
553 | 513 | { |
554 | 513 | unsigned int i = len / 2; |
555 | | |
556 | 513 | OPCODES_ASSERT (i + 3 < maxlen); |
557 | 513 | cst[opnr] = (((unsigned) data[i] << 24) |
558 | 513 | | (data[i + 1] << 16) |
559 | 513 | | (data[i + 2] << 8) |
560 | 513 | | (data[i + 3])); |
561 | | |
562 | 513 | cstlen[opnr] = 32; |
563 | 513 | } |
564 | 995k | else if ((looking_for & SIZE) == L_24) |
565 | 2.00k | { |
566 | 2.00k | unsigned int i = len / 2; |
567 | | |
568 | 2.00k | OPCODES_ASSERT (i + 2 < maxlen); |
569 | 2.00k | cst[opnr] = |
570 | 2.00k | (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]); |
571 | 2.00k | cstlen[opnr] = 24; |
572 | 2.00k | } |
573 | 993k | else if (looking_for & DISPREG) |
574 | 804k | { |
575 | 804k | dispregno[opnr] = thisnib & 7; |
576 | 804k | } |
577 | 189k | else if ((looking_for & MODE) == KBIT) |
578 | 4.23k | { |
579 | 4.23k | switch (thisnib) |
580 | 4.23k | { |
581 | 136 | case 9: |
582 | 136 | cst[opnr] = 4; |
583 | 136 | break; |
584 | 325 | case 8: |
585 | 325 | cst[opnr] = 2; |
586 | 325 | break; |
587 | 1.91k | case 0: |
588 | 1.91k | cst[opnr] = 1; |
589 | 1.91k | break; |
590 | 1.85k | default: |
591 | 1.85k | goto fail; |
592 | 4.23k | } |
593 | 4.23k | } |
594 | 185k | else if ((looking_for & SIZE) == L_8) |
595 | 162k | { |
596 | 162k | cstlen[opnr] = 8; |
597 | 162k | cst[opnr] = data[len / 2]; |
598 | 162k | } |
599 | 22.1k | else if ((looking_for & SIZE) == L_3 |
600 | 22.1k | || (looking_for & SIZE) == L_3NZ) |
601 | 21.1k | { |
602 | 21.1k | cst[opnr] = thisnib & 0x7; |
603 | 21.1k | if (cst[opnr] == 0 && (looking_for & SIZE) == L_3NZ) |
604 | 1.42k | goto fail; |
605 | 21.1k | } |
606 | 986 | else if ((looking_for & SIZE) == L_2) |
607 | 986 | { |
608 | 986 | cstlen[opnr] = 2; |
609 | 986 | cst[opnr] = thisnib & 0x3; |
610 | 986 | } |
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.67M | } |
619 | | |
620 | 797M | len++; |
621 | 797M | nib++; |
622 | 797M | } |
623 | | |
624 | 410k | outfn (stream, "%s\t", q->name); |
625 | | |
626 | | /* Gross. Disgusting. */ |
627 | 410k | if (strcmp (q->name, "ldm.l") == 0) |
628 | 38 | { |
629 | 38 | int count, high; |
630 | | |
631 | 38 | count = (data[1] / 16) & 0x3; |
632 | 38 | high = regno[1]; |
633 | | |
634 | 38 | outfn (stream, "@sp+,er%d-er%d", high - count, high); |
635 | 38 | return qi->length; |
636 | 38 | } |
637 | | |
638 | 410k | if (strcmp (q->name, "stm.l") == 0) |
639 | 10 | { |
640 | 10 | int count, low; |
641 | | |
642 | 10 | count = (data[1] / 16) & 0x3; |
643 | 10 | low = regno[0]; |
644 | | |
645 | 10 | outfn (stream, "er%d-er%d,@-sp", low, low + count); |
646 | 10 | return qi->length; |
647 | 10 | } |
648 | 410k | if (strcmp (q->name, "rte/l") == 0 |
649 | 410k | || strcmp (q->name, "rts/l") == 0) |
650 | 6.30k | { |
651 | 6.30k | if (regno[0] == 0) |
652 | 600 | outfn (stream, "er%d", regno[1]); |
653 | 5.70k | else |
654 | 5.70k | outfn (stream, "er%d-er%d", regno[1] - regno[0], |
655 | 5.70k | regno[1]); |
656 | 6.30k | return qi->length; |
657 | 6.30k | } |
658 | 404k | if (startswith (q->name, "mova")) |
659 | 400 | { |
660 | 400 | const op_type *args = q->args.nib; |
661 | | |
662 | 400 | if (args[1] == (op_type) E) |
663 | 336 | { |
664 | | /* Short form. */ |
665 | 336 | print_one_arg (info, addr, args[0], cst[0], |
666 | 336 | cstlen[0], dispregno[0], regno[0], |
667 | 336 | pregnames, qi->length); |
668 | 336 | outfn (stream, ",er%d", dispregno[0]); |
669 | 336 | } |
670 | 64 | else |
671 | 64 | { |
672 | 64 | outfn (stream, "@(0x%x:%d,", cst[0], cstlen[0]); |
673 | 64 | print_one_arg (info, addr, args[1], cst[1], |
674 | 64 | cstlen[1], dispregno[1], regno[1], |
675 | 64 | pregnames, qi->length); |
676 | 64 | outfn (stream, ".%c),", |
677 | 64 | (args[0] & MODE) == INDEXB ? 'b' : 'w'); |
678 | 64 | print_one_arg (info, addr, args[2], cst[2], |
679 | 64 | cstlen[2], dispregno[2], regno[2], |
680 | 64 | pregnames, qi->length); |
681 | 64 | } |
682 | 400 | return qi->length; |
683 | 400 | } |
684 | | /* Fill in the args. */ |
685 | 404k | { |
686 | 404k | const op_type *args = q->args.nib; |
687 | 404k | int hadone = 0; |
688 | 404k | 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 | 404k | if (strcmp (qi->opcode->name, "adds") == 0 |
695 | 404k | || strcmp (qi->opcode->name, "subs") == 0) |
696 | 2.37k | { |
697 | 2.37k | outfn (stream, "#%d,%s", cst[0], pregnames[regno[1] & 0x7]); |
698 | 2.37k | return qi->length; |
699 | 2.37k | } |
700 | | |
701 | 401k | for (nargs = 0; |
702 | 1.01M | nargs < 3 && args[nargs] != (op_type) E; |
703 | 610k | nargs++) |
704 | 610k | { |
705 | 610k | int x = args[nargs]; |
706 | | |
707 | 610k | if (hadone) |
708 | 289k | outfn (stream, ","); |
709 | | |
710 | 610k | print_one_arg (info, addr, x, |
711 | 610k | cst[nargs], cstlen[nargs], |
712 | 610k | dispregno[nargs], regno[nargs], |
713 | 610k | pregnames, qi->length); |
714 | | |
715 | 610k | hadone = 1; |
716 | 610k | } |
717 | 401k | } |
718 | 0 | return qi->length; |
719 | | |
720 | 2.22G | fail: |
721 | 2.22G | ; |
722 | 2.22G | } |
723 | | |
724 | | /* Fell off the end. */ |
725 | 89.5k | outfn (stream, ".word\tH'%x,H'%x", data[0], data[1]); |
726 | 89.5k | return 2; |
727 | 500k | } |
728 | | |
729 | | int |
730 | | print_insn_h8300 (bfd_vma addr, disassemble_info *info) |
731 | 467k | { |
732 | 467k | return bfd_h8_disassemble (addr, info, 0); |
733 | 467k | } |
734 | | |
735 | | int |
736 | | print_insn_h8300h (bfd_vma addr, disassemble_info *info) |
737 | 9.56k | { |
738 | 9.56k | return bfd_h8_disassemble (addr, info, 1); |
739 | 9.56k | } |
740 | | |
741 | | int |
742 | | print_insn_h8300s (bfd_vma addr, disassemble_info *info) |
743 | 24.1k | { |
744 | 24.1k | return bfd_h8_disassemble (addr, info, 2); |
745 | 24.1k | } |