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