ld/
[binutils.git] / opcodes / hppa-dis.c
blob65294625509256053099f5a292953462339bd91c
1 /* Disassembler for the PA-RISC. Somewhat derived from sparc-pinsn.c.
2 Copyright 1989, 1990, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2003,
3 2005 Free Software Foundation, Inc.
5 Contributed by the Center for Software Science at the
6 University of Utah (pa-gdb-bugs@cs.utah.edu).
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
23 #include "sysdep.h"
24 #include "dis-asm.h"
25 #include "libhppa.h"
26 #include "opcode/hppa.h"
28 /* Integer register names, indexed by the numbers which appear in the
29 opcodes. */
30 static const char *const reg_names[] =
32 "flags", "r1", "rp", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
33 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
34 "r20", "r21", "r22", "r23", "r24", "r25", "r26", "dp", "ret0", "ret1",
35 "sp", "r31"
38 /* Floating point register names, indexed by the numbers which appear in the
39 opcodes. */
40 static const char *const fp_reg_names[] =
42 "fpsr", "fpe2", "fpe4", "fpe6",
43 "fr4", "fr5", "fr6", "fr7", "fr8",
44 "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
45 "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",
46 "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31"
49 typedef unsigned int CORE_ADDR;
51 /* Get at various relevent fields of an instruction word. */
53 #define MASK_5 0x1f
54 #define MASK_10 0x3ff
55 #define MASK_11 0x7ff
56 #define MASK_14 0x3fff
57 #define MASK_16 0xffff
58 #define MASK_21 0x1fffff
60 /* These macros get bit fields using HP's numbering (MSB = 0). */
62 #define GET_FIELD(X, FROM, TO) \
63 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
65 #define GET_BIT(X, WHICH) \
66 GET_FIELD (X, WHICH, WHICH)
68 /* Some of these have been converted to 2-d arrays because they
69 consume less storage this way. If the maintenance becomes a
70 problem, convert them back to const 1-d pointer arrays. */
71 static const char *const control_reg[] =
73 "rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
74 "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4",
75 "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr",
76 "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3",
77 "tr4", "tr5", "tr6", "tr7"
80 static const char *const compare_cond_names[] =
82 "", ",=", ",<", ",<=", ",<<", ",<<=", ",sv", ",od",
83 ",tr", ",<>", ",>=", ",>", ",>>=", ",>>", ",nsv", ",ev"
85 static const char *const compare_cond_64_names[] =
87 "", ",*=", ",*<", ",*<=", ",*<<", ",*<<=", ",*sv", ",*od",
88 ",*tr", ",*<>", ",*>=", ",*>", ",*>>=", ",*>>", ",*nsv", ",*ev"
90 static const char *const cmpib_cond_64_names[] =
92 ",*<<", ",*=", ",*<", ",*<=", ",*>>=", ",*<>", ",*>=", ",*>"
94 static const char *const add_cond_names[] =
96 "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv", ",od",
97 ",tr", ",<>", ",>=", ",>", ",uv", ",vnz", ",nsv", ",ev"
99 static const char *const add_cond_64_names[] =
101 "", ",*=", ",*<", ",*<=", ",*nuv", ",*znv", ",*sv", ",*od",
102 ",*tr", ",*<>", ",*>=", ",*>", ",*uv", ",*vnz", ",*nsv", ",*ev"
104 static const char *const wide_add_cond_names[] =
106 "", ",=", ",<", ",<=", ",nuv", ",*=", ",*<", ",*<=",
107 ",tr", ",<>", ",>=", ",>", ",uv", ",*<>", ",*>=", ",*>"
109 static const char *const logical_cond_names[] =
111 "", ",=", ",<", ",<=", 0, 0, 0, ",od",
112 ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};
113 static const char *const logical_cond_64_names[] =
115 "", ",*=", ",*<", ",*<=", 0, 0, 0, ",*od",
116 ",*tr", ",*<>", ",*>=", ",*>", 0, 0, 0, ",*ev"};
117 static const char *const unit_cond_names[] =
119 "", ",swz", ",sbz", ",shz", ",sdc", ",swc", ",sbc", ",shc",
120 ",tr", ",nwz", ",nbz", ",nhz", ",ndc", ",nwc", ",nbc", ",nhc"
122 static const char *const unit_cond_64_names[] =
124 "", ",*swz", ",*sbz", ",*shz", ",*sdc", ",*swc", ",*sbc", ",*shc",
125 ",*tr", ",*nwz", ",*nbz", ",*nhz", ",*ndc", ",*nwc", ",*nbc", ",*nhc"
127 static const char *const shift_cond_names[] =
129 "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"
131 static const char *const shift_cond_64_names[] =
133 "", ",*=", ",*<", ",*od", ",*tr", ",*<>", ",*>=", ",*ev"
135 static const char *const bb_cond_64_names[] =
137 ",*<", ",*>="
139 static const char *const index_compl_names[] = {"", ",m", ",s", ",sm"};
140 static const char *const short_ldst_compl_names[] = {"", ",ma", "", ",mb"};
141 static const char *const short_bytes_compl_names[] =
143 "", ",b,m", ",e", ",e,m"
145 static const char *const float_format_names[] = {",sgl", ",dbl", "", ",quad"};
146 static const char *const fcnv_fixed_names[] = {",w", ",dw", "", ",qw"};
147 static const char *const fcnv_ufixed_names[] = {",uw", ",udw", "", ",uqw"};
148 static const char *const float_comp_names[] =
150 ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",
151 ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",
152 ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",
153 ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"
155 static const char *const signed_unsigned_names[] = {",u", ",s"};
156 static const char *const mix_half_names[] = {",l", ",r"};
157 static const char *const saturation_names[] = {",us", ",ss", 0, ""};
158 static const char *const read_write_names[] = {",r", ",w"};
159 static const char *const add_compl_names[] = { 0, "", ",l", ",tsv" };
161 /* For a bunch of different instructions form an index into a
162 completer name table. */
163 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
164 GET_FIELD (insn, 18, 18) << 1)
166 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
167 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
169 /* Utility function to print registers. Put these first, so gcc's function
170 inlining can do its stuff. */
172 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
174 static void
175 fput_reg (unsigned reg, disassemble_info *info)
177 (*info->fprintf_func) (info->stream, reg ? reg_names[reg] : "r0");
180 static void
181 fput_fp_reg (unsigned reg, disassemble_info *info)
183 (*info->fprintf_func) (info->stream, reg ? fp_reg_names[reg] : "fr0");
186 static void
187 fput_fp_reg_r (unsigned reg, disassemble_info *info)
189 /* Special case floating point exception registers. */
190 if (reg < 4)
191 (*info->fprintf_func) (info->stream, "fpe%d", reg * 2 + 1);
192 else
193 (*info->fprintf_func) (info->stream, "%sR",
194 reg ? fp_reg_names[reg] : "fr0");
197 static void
198 fput_creg (unsigned reg, disassemble_info *info)
200 (*info->fprintf_func) (info->stream, control_reg[reg]);
203 /* Print constants with sign. */
205 static void
206 fput_const (unsigned num, disassemble_info *info)
208 if ((int) num < 0)
209 (*info->fprintf_func) (info->stream, "-%x", - (int) num);
210 else
211 (*info->fprintf_func) (info->stream, "%x", num);
214 /* Routines to extract various sized constants out of hppa
215 instructions. */
217 /* Extract a 3-bit space register number from a be, ble, mtsp or mfsp. */
218 static int
219 extract_3 (unsigned word)
221 return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);
224 static int
225 extract_5_load (unsigned word)
227 return low_sign_extend (word >> 16 & MASK_5, 5);
230 /* Extract the immediate field from a st{bhw}s instruction. */
232 static int
233 extract_5_store (unsigned word)
235 return low_sign_extend (word & MASK_5, 5);
238 /* Extract the immediate field from a break instruction. */
240 static unsigned
241 extract_5r_store (unsigned word)
243 return (word & MASK_5);
246 /* Extract the immediate field from a {sr}sm instruction. */
248 static unsigned
249 extract_5R_store (unsigned word)
251 return (word >> 16 & MASK_5);
254 /* Extract the 10 bit immediate field from a {sr}sm instruction. */
256 static unsigned
257 extract_10U_store (unsigned word)
259 return (word >> 16 & MASK_10);
262 /* Extract the immediate field from a bb instruction. */
264 static unsigned
265 extract_5Q_store (unsigned word)
267 return (word >> 21 & MASK_5);
270 /* Extract an 11 bit immediate field. */
272 static int
273 extract_11 (unsigned word)
275 return low_sign_extend (word & MASK_11, 11);
278 /* Extract a 14 bit immediate field. */
280 static int
281 extract_14 (unsigned word)
283 return low_sign_extend (word & MASK_14, 14);
286 /* Extract a 16 bit immediate field (PA2.0 wide only). */
288 static int
289 extract_16 (unsigned word)
291 int m15, m0, m1;
293 m0 = GET_BIT (word, 16);
294 m1 = GET_BIT (word, 17);
295 m15 = GET_BIT (word, 31);
296 word = (word >> 1) & 0x1fff;
297 word = word | (m15 << 15) | ((m15 ^ m0) << 14) | ((m15 ^ m1) << 13);
298 return sign_extend (word, 16);
301 /* Extract a 21 bit constant. */
303 static int
304 extract_21 (unsigned word)
306 int val;
308 word &= MASK_21;
309 word <<= 11;
310 val = GET_FIELD (word, 20, 20);
311 val <<= 11;
312 val |= GET_FIELD (word, 9, 19);
313 val <<= 2;
314 val |= GET_FIELD (word, 5, 6);
315 val <<= 5;
316 val |= GET_FIELD (word, 0, 4);
317 val <<= 2;
318 val |= GET_FIELD (word, 7, 8);
319 return sign_extend (val, 21) << 11;
322 /* Extract a 12 bit constant from branch instructions. */
324 static int
325 extract_12 (unsigned word)
327 return sign_extend (GET_FIELD (word, 19, 28)
328 | GET_FIELD (word, 29, 29) << 10
329 | (word & 0x1) << 11, 12) << 2;
332 /* Extract a 17 bit constant from branch instructions, returning the
333 19 bit signed value. */
335 static int
336 extract_17 (unsigned word)
338 return sign_extend (GET_FIELD (word, 19, 28)
339 | GET_FIELD (word, 29, 29) << 10
340 | GET_FIELD (word, 11, 15) << 11
341 | (word & 0x1) << 16, 17) << 2;
344 static int
345 extract_22 (unsigned word)
347 return sign_extend (GET_FIELD (word, 19, 28)
348 | GET_FIELD (word, 29, 29) << 10
349 | GET_FIELD (word, 11, 15) << 11
350 | GET_FIELD (word, 6, 10) << 16
351 | (word & 0x1) << 21, 22) << 2;
354 /* Print one instruction. */
357 print_insn_hppa (bfd_vma memaddr, disassemble_info *info)
359 bfd_byte buffer[4];
360 unsigned int insn, i;
363 int status =
364 (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
365 if (status != 0)
367 (*info->memory_error_func) (status, memaddr, info);
368 return -1;
372 insn = bfd_getb32 (buffer);
374 for (i = 0; i < NUMOPCODES; ++i)
376 const struct pa_opcode *opcode = &pa_opcodes[i];
378 if ((insn & opcode->mask) == opcode->match)
380 const char *s;
381 #ifndef BFD64
382 if (opcode->arch == pa20w)
383 continue;
384 #endif
385 (*info->fprintf_func) (info->stream, "%s", opcode->name);
387 if (!strchr ("cfCY?-+nHNZFIuv{", opcode->args[0]))
388 (*info->fprintf_func) (info->stream, " ");
389 for (s = opcode->args; *s != '\0'; ++s)
391 switch (*s)
393 case 'x':
394 fput_reg (GET_FIELD (insn, 11, 15), info);
395 break;
396 case 'a':
397 case 'b':
398 fput_reg (GET_FIELD (insn, 6, 10), info);
399 break;
400 case '^':
401 fput_creg (GET_FIELD (insn, 6, 10), info);
402 break;
403 case 't':
404 fput_reg (GET_FIELD (insn, 27, 31), info);
405 break;
407 /* Handle floating point registers. */
408 case 'f':
409 switch (*++s)
411 case 't':
412 fput_fp_reg (GET_FIELD (insn, 27, 31), info);
413 break;
414 case 'T':
415 if (GET_FIELD (insn, 25, 25))
416 fput_fp_reg_r (GET_FIELD (insn, 27, 31), info);
417 else
418 fput_fp_reg (GET_FIELD (insn, 27, 31), info);
419 break;
420 case 'a':
421 if (GET_FIELD (insn, 25, 25))
422 fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
423 else
424 fput_fp_reg (GET_FIELD (insn, 6, 10), info);
425 break;
427 /* 'fA' will not generate a space before the regsiter
428 name. Normally that is fine. Except that it
429 causes problems with xmpyu which has no FP format
430 completer. */
431 case 'X':
432 fputs_filtered (" ", info);
433 /* FALLTHRU */
435 case 'A':
436 if (GET_FIELD (insn, 24, 24))
437 fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
438 else
439 fput_fp_reg (GET_FIELD (insn, 6, 10), info);
440 break;
441 case 'b':
442 if (GET_FIELD (insn, 25, 25))
443 fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
444 else
445 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
446 break;
447 case 'B':
448 if (GET_FIELD (insn, 19, 19))
449 fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
450 else
451 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
452 break;
453 case 'C':
455 int reg = GET_FIELD (insn, 21, 22);
456 reg |= GET_FIELD (insn, 16, 18) << 2;
457 if (GET_FIELD (insn, 23, 23) != 0)
458 fput_fp_reg_r (reg, info);
459 else
460 fput_fp_reg (reg, info);
461 break;
463 case 'i':
465 int reg = GET_FIELD (insn, 6, 10);
467 reg |= (GET_FIELD (insn, 26, 26) << 4);
468 fput_fp_reg (reg, info);
469 break;
471 case 'j':
473 int reg = GET_FIELD (insn, 11, 15);
475 reg |= (GET_FIELD (insn, 26, 26) << 4);
476 fput_fp_reg (reg, info);
477 break;
479 case 'k':
481 int reg = GET_FIELD (insn, 27, 31);
483 reg |= (GET_FIELD (insn, 26, 26) << 4);
484 fput_fp_reg (reg, info);
485 break;
487 case 'l':
489 int reg = GET_FIELD (insn, 21, 25);
491 reg |= (GET_FIELD (insn, 26, 26) << 4);
492 fput_fp_reg (reg, info);
493 break;
495 case 'm':
497 int reg = GET_FIELD (insn, 16, 20);
499 reg |= (GET_FIELD (insn, 26, 26) << 4);
500 fput_fp_reg (reg, info);
501 break;
504 /* 'fe' will not generate a space before the register
505 name. Normally that is fine. Except that it
506 causes problems with fstw fe,y(b) which has no FP
507 format completer. */
508 case 'E':
509 fputs_filtered (" ", info);
510 /* FALLTHRU */
512 case 'e':
513 if (GET_FIELD (insn, 30, 30))
514 fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
515 else
516 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
517 break;
518 case 'x':
519 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
520 break;
522 break;
524 case '5':
525 fput_const (extract_5_load (insn), info);
526 break;
527 case 's':
529 int space = GET_FIELD (insn, 16, 17);
530 /* Zero means implicit addressing, not use of sr0. */
531 if (space != 0)
532 (*info->fprintf_func) (info->stream, "sr%d", space);
534 break;
536 case 'S':
537 (*info->fprintf_func) (info->stream, "sr%d",
538 extract_3 (insn));
539 break;
541 /* Handle completers. */
542 case 'c':
543 switch (*++s)
545 case 'x':
546 (*info->fprintf_func)
547 (info->stream, "%s",
548 index_compl_names[GET_COMPL (insn)]);
549 break;
550 case 'X':
551 (*info->fprintf_func)
552 (info->stream, "%s ",
553 index_compl_names[GET_COMPL (insn)]);
554 break;
555 case 'm':
556 (*info->fprintf_func)
557 (info->stream, "%s",
558 short_ldst_compl_names[GET_COMPL (insn)]);
559 break;
560 case 'M':
561 (*info->fprintf_func)
562 (info->stream, "%s ",
563 short_ldst_compl_names[GET_COMPL (insn)]);
564 break;
565 case 'A':
566 (*info->fprintf_func)
567 (info->stream, "%s ",
568 short_bytes_compl_names[GET_COMPL (insn)]);
569 break;
570 case 's':
571 (*info->fprintf_func)
572 (info->stream, "%s",
573 short_bytes_compl_names[GET_COMPL (insn)]);
574 break;
575 case 'c':
576 case 'C':
577 switch (GET_FIELD (insn, 20, 21))
579 case 1:
580 (*info->fprintf_func) (info->stream, ",bc ");
581 break;
582 case 2:
583 (*info->fprintf_func) (info->stream, ",sl ");
584 break;
585 default:
586 (*info->fprintf_func) (info->stream, " ");
588 break;
589 case 'd':
590 switch (GET_FIELD (insn, 20, 21))
592 case 1:
593 (*info->fprintf_func) (info->stream, ",co ");
594 break;
595 default:
596 (*info->fprintf_func) (info->stream, " ");
598 break;
599 case 'o':
600 (*info->fprintf_func) (info->stream, ",o");
601 break;
602 case 'g':
603 (*info->fprintf_func) (info->stream, ",gate");
604 break;
605 case 'p':
606 (*info->fprintf_func) (info->stream, ",l,push");
607 break;
608 case 'P':
609 (*info->fprintf_func) (info->stream, ",pop");
610 break;
611 case 'l':
612 case 'L':
613 (*info->fprintf_func) (info->stream, ",l");
614 break;
615 case 'w':
616 (*info->fprintf_func)
617 (info->stream, "%s ",
618 read_write_names[GET_FIELD (insn, 25, 25)]);
619 break;
620 case 'W':
621 (*info->fprintf_func) (info->stream, ",w ");
622 break;
623 case 'r':
624 if (GET_FIELD (insn, 23, 26) == 5)
625 (*info->fprintf_func) (info->stream, ",r");
626 break;
627 case 'Z':
628 if (GET_FIELD (insn, 26, 26))
629 (*info->fprintf_func) (info->stream, ",m ");
630 else
631 (*info->fprintf_func) (info->stream, " ");
632 break;
633 case 'i':
634 if (GET_FIELD (insn, 25, 25))
635 (*info->fprintf_func) (info->stream, ",i");
636 break;
637 case 'z':
638 if (!GET_FIELD (insn, 21, 21))
639 (*info->fprintf_func) (info->stream, ",z");
640 break;
641 case 'a':
642 (*info->fprintf_func)
643 (info->stream, "%s",
644 add_compl_names[GET_FIELD (insn, 20, 21)]);
645 break;
646 case 'Y':
647 (*info->fprintf_func)
648 (info->stream, ",dc%s",
649 add_compl_names[GET_FIELD (insn, 20, 21)]);
650 break;
651 case 'y':
652 (*info->fprintf_func)
653 (info->stream, ",c%s",
654 add_compl_names[GET_FIELD (insn, 20, 21)]);
655 break;
656 case 'v':
657 if (GET_FIELD (insn, 20, 20))
658 (*info->fprintf_func) (info->stream, ",tsv");
659 break;
660 case 't':
661 (*info->fprintf_func) (info->stream, ",tc");
662 if (GET_FIELD (insn, 20, 20))
663 (*info->fprintf_func) (info->stream, ",tsv");
664 break;
665 case 'B':
666 (*info->fprintf_func) (info->stream, ",db");
667 if (GET_FIELD (insn, 20, 20))
668 (*info->fprintf_func) (info->stream, ",tsv");
669 break;
670 case 'b':
671 (*info->fprintf_func) (info->stream, ",b");
672 if (GET_FIELD (insn, 20, 20))
673 (*info->fprintf_func) (info->stream, ",tsv");
674 break;
675 case 'T':
676 if (GET_FIELD (insn, 25, 25))
677 (*info->fprintf_func) (info->stream, ",tc");
678 break;
679 case 'S':
680 /* EXTRD/W has a following condition. */
681 if (*(s + 1) == '?')
682 (*info->fprintf_func)
683 (info->stream, "%s",
684 signed_unsigned_names[GET_FIELD (insn, 21, 21)]);
685 else
686 (*info->fprintf_func)
687 (info->stream, "%s ",
688 signed_unsigned_names[GET_FIELD (insn, 21, 21)]);
689 break;
690 case 'h':
691 (*info->fprintf_func)
692 (info->stream, "%s",
693 mix_half_names[GET_FIELD (insn, 17, 17)]);
694 break;
695 case 'H':
696 (*info->fprintf_func)
697 (info->stream, "%s ",
698 saturation_names[GET_FIELD (insn, 24, 25)]);
699 break;
700 case '*':
701 (*info->fprintf_func)
702 (info->stream, ",%d%d%d%d ",
703 GET_FIELD (insn, 17, 18), GET_FIELD (insn, 20, 21),
704 GET_FIELD (insn, 22, 23), GET_FIELD (insn, 24, 25));
705 break;
707 case 'q':
709 int m, a;
711 m = GET_FIELD (insn, 28, 28);
712 a = GET_FIELD (insn, 29, 29);
714 if (m && !a)
715 fputs_filtered (",ma ", info);
716 else if (m && a)
717 fputs_filtered (",mb ", info);
718 else
719 fputs_filtered (" ", info);
720 break;
723 case 'J':
725 int opc = GET_FIELD (insn, 0, 5);
727 if (opc == 0x16 || opc == 0x1e)
729 if (GET_FIELD (insn, 29, 29) == 0)
730 fputs_filtered (",ma ", info);
731 else
732 fputs_filtered (",mb ", info);
734 else
735 fputs_filtered (" ", info);
736 break;
739 case 'e':
741 int opc = GET_FIELD (insn, 0, 5);
743 if (opc == 0x13 || opc == 0x1b)
745 if (GET_FIELD (insn, 18, 18) == 1)
746 fputs_filtered (",mb ", info);
747 else
748 fputs_filtered (",ma ", info);
750 else if (opc == 0x17 || opc == 0x1f)
752 if (GET_FIELD (insn, 31, 31) == 1)
753 fputs_filtered (",ma ", info);
754 else
755 fputs_filtered (",mb ", info);
757 else
758 fputs_filtered (" ", info);
760 break;
763 break;
765 /* Handle conditions. */
766 case '?':
768 s++;
769 switch (*s)
771 case 'f':
772 (*info->fprintf_func)
773 (info->stream, "%s ",
774 float_comp_names[GET_FIELD (insn, 27, 31)]);
775 break;
777 /* These four conditions are for the set of instructions
778 which distinguish true/false conditions by opcode
779 rather than by the 'f' bit (sigh): comb, comib,
780 addb, addib. */
781 case 't':
782 fputs_filtered
783 (compare_cond_names[GET_FIELD (insn, 16, 18)], info);
784 break;
785 case 'n':
786 fputs_filtered
787 (compare_cond_names[GET_FIELD (insn, 16, 18)
788 + GET_FIELD (insn, 4, 4) * 8],
789 info);
790 break;
791 case 'N':
792 fputs_filtered
793 (compare_cond_64_names[GET_FIELD (insn, 16, 18)
794 + GET_FIELD (insn, 2, 2) * 8],
795 info);
796 break;
797 case 'Q':
798 fputs_filtered
799 (cmpib_cond_64_names[GET_FIELD (insn, 16, 18)],
800 info);
801 break;
802 case '@':
803 fputs_filtered
804 (add_cond_names[GET_FIELD (insn, 16, 18)
805 + GET_FIELD (insn, 4, 4) * 8],
806 info);
807 break;
808 case 's':
809 (*info->fprintf_func)
810 (info->stream, "%s ",
811 compare_cond_names[GET_COND (insn)]);
812 break;
813 case 'S':
814 (*info->fprintf_func)
815 (info->stream, "%s ",
816 compare_cond_64_names[GET_COND (insn)]);
817 break;
818 case 'a':
819 (*info->fprintf_func)
820 (info->stream, "%s ",
821 add_cond_names[GET_COND (insn)]);
822 break;
823 case 'A':
824 (*info->fprintf_func)
825 (info->stream, "%s ",
826 add_cond_64_names[GET_COND (insn)]);
827 break;
828 case 'd':
829 (*info->fprintf_func)
830 (info->stream, "%s",
831 add_cond_names[GET_FIELD (insn, 16, 18)]);
832 break;
834 case 'W':
835 (*info->fprintf_func)
836 (info->stream, "%s",
837 wide_add_cond_names[GET_FIELD (insn, 16, 18) +
838 GET_FIELD (insn, 4, 4) * 8]);
839 break;
841 case 'l':
842 (*info->fprintf_func)
843 (info->stream, "%s ",
844 logical_cond_names[GET_COND (insn)]);
845 break;
846 case 'L':
847 (*info->fprintf_func)
848 (info->stream, "%s ",
849 logical_cond_64_names[GET_COND (insn)]);
850 break;
851 case 'u':
852 (*info->fprintf_func)
853 (info->stream, "%s ",
854 unit_cond_names[GET_COND (insn)]);
855 break;
856 case 'U':
857 (*info->fprintf_func)
858 (info->stream, "%s ",
859 unit_cond_64_names[GET_COND (insn)]);
860 break;
861 case 'y':
862 case 'x':
863 case 'b':
864 (*info->fprintf_func)
865 (info->stream, "%s",
866 shift_cond_names[GET_FIELD (insn, 16, 18)]);
868 /* If the next character in args is 'n', it will handle
869 putting out the space. */
870 if (s[1] != 'n')
871 (*info->fprintf_func) (info->stream, " ");
872 break;
873 case 'X':
874 (*info->fprintf_func)
875 (info->stream, "%s ",
876 shift_cond_64_names[GET_FIELD (insn, 16, 18)]);
877 break;
878 case 'B':
879 (*info->fprintf_func)
880 (info->stream, "%s",
881 bb_cond_64_names[GET_FIELD (insn, 16, 16)]);
883 /* If the next character in args is 'n', it will handle
884 putting out the space. */
885 if (s[1] != 'n')
886 (*info->fprintf_func) (info->stream, " ");
887 break;
889 break;
892 case 'V':
893 fput_const (extract_5_store (insn), info);
894 break;
895 case 'r':
896 fput_const (extract_5r_store (insn), info);
897 break;
898 case 'R':
899 fput_const (extract_5R_store (insn), info);
900 break;
901 case 'U':
902 fput_const (extract_10U_store (insn), info);
903 break;
904 case 'B':
905 case 'Q':
906 fput_const (extract_5Q_store (insn), info);
907 break;
908 case 'i':
909 fput_const (extract_11 (insn), info);
910 break;
911 case 'j':
912 fput_const (extract_14 (insn), info);
913 break;
914 case 'k':
915 fputs_filtered ("L%", info);
916 fput_const (extract_21 (insn), info);
917 break;
918 case '<':
919 case 'l':
920 /* 16-bit long disp., PA2.0 wide only. */
921 fput_const (extract_16 (insn), info);
922 break;
923 case 'n':
924 if (insn & 0x2)
925 (*info->fprintf_func) (info->stream, ",n ");
926 else
927 (*info->fprintf_func) (info->stream, " ");
928 break;
929 case 'N':
930 if ((insn & 0x20) && s[1])
931 (*info->fprintf_func) (info->stream, ",n ");
932 else if (insn & 0x20)
933 (*info->fprintf_func) (info->stream, ",n");
934 else if (s[1])
935 (*info->fprintf_func) (info->stream, " ");
936 break;
937 case 'w':
938 (*info->print_address_func)
939 (memaddr + 8 + extract_12 (insn), info);
940 break;
941 case 'W':
942 /* 17 bit PC-relative branch. */
943 (*info->print_address_func)
944 ((memaddr + 8 + extract_17 (insn)), info);
945 break;
946 case 'z':
947 /* 17 bit displacement. This is an offset from a register
948 so it gets disasssembled as just a number, not any sort
949 of address. */
950 fput_const (extract_17 (insn), info);
951 break;
953 case 'Z':
954 /* addil %r1 implicit output. */
955 fputs_filtered ("r1", info);
956 break;
958 case 'Y':
959 /* be,l %sr0,%r31 implicit output. */
960 fputs_filtered ("sr0,r31", info);
961 break;
963 case '@':
964 (*info->fprintf_func) (info->stream, "0");
965 break;
967 case '.':
968 (*info->fprintf_func) (info->stream, "%d",
969 GET_FIELD (insn, 24, 25));
970 break;
971 case '*':
972 (*info->fprintf_func) (info->stream, "%d",
973 GET_FIELD (insn, 22, 25));
974 break;
975 case '!':
976 fputs_filtered ("sar", info);
977 break;
978 case 'p':
979 (*info->fprintf_func) (info->stream, "%d",
980 31 - GET_FIELD (insn, 22, 26));
981 break;
982 case '~':
984 int num;
985 num = GET_FIELD (insn, 20, 20) << 5;
986 num |= GET_FIELD (insn, 22, 26);
987 (*info->fprintf_func) (info->stream, "%d", 63 - num);
988 break;
990 case 'P':
991 (*info->fprintf_func) (info->stream, "%d",
992 GET_FIELD (insn, 22, 26));
993 break;
994 case 'q':
996 int num;
997 num = GET_FIELD (insn, 20, 20) << 5;
998 num |= GET_FIELD (insn, 22, 26);
999 (*info->fprintf_func) (info->stream, "%d", num);
1000 break;
1002 case 'T':
1003 (*info->fprintf_func) (info->stream, "%d",
1004 32 - GET_FIELD (insn, 27, 31));
1005 break;
1006 case '%':
1008 int num;
1009 num = (GET_FIELD (insn, 23, 23) + 1) * 32;
1010 num -= GET_FIELD (insn, 27, 31);
1011 (*info->fprintf_func) (info->stream, "%d", num);
1012 break;
1014 case '|':
1016 int num;
1017 num = (GET_FIELD (insn, 19, 19) + 1) * 32;
1018 num -= GET_FIELD (insn, 27, 31);
1019 (*info->fprintf_func) (info->stream, "%d", num);
1020 break;
1022 case '$':
1023 fput_const (GET_FIELD (insn, 20, 28), info);
1024 break;
1025 case 'A':
1026 fput_const (GET_FIELD (insn, 6, 18), info);
1027 break;
1028 case 'D':
1029 fput_const (GET_FIELD (insn, 6, 31), info);
1030 break;
1031 case 'v':
1032 (*info->fprintf_func) (info->stream, ",%d",
1033 GET_FIELD (insn, 23, 25));
1034 break;
1035 case 'O':
1036 fput_const ((GET_FIELD (insn, 6,20) << 5 |
1037 GET_FIELD (insn, 27, 31)), info);
1038 break;
1039 case 'o':
1040 fput_const (GET_FIELD (insn, 6, 20), info);
1041 break;
1042 case '2':
1043 fput_const ((GET_FIELD (insn, 6, 22) << 5 |
1044 GET_FIELD (insn, 27, 31)), info);
1045 break;
1046 case '1':
1047 fput_const ((GET_FIELD (insn, 11, 20) << 5 |
1048 GET_FIELD (insn, 27, 31)), info);
1049 break;
1050 case '0':
1051 fput_const ((GET_FIELD (insn, 16, 20) << 5 |
1052 GET_FIELD (insn, 27, 31)), info);
1053 break;
1054 case 'u':
1055 (*info->fprintf_func) (info->stream, ",%d",
1056 GET_FIELD (insn, 23, 25));
1057 break;
1058 case 'F':
1059 /* If no destination completer and not before a completer
1060 for fcmp, need a space here. */
1061 if (s[1] == 'G' || s[1] == '?')
1062 fputs_filtered
1063 (float_format_names[GET_FIELD (insn, 19, 20)], info);
1064 else
1065 (*info->fprintf_func)
1066 (info->stream, "%s ",
1067 float_format_names[GET_FIELD (insn, 19, 20)]);
1068 break;
1069 case 'G':
1070 (*info->fprintf_func)
1071 (info->stream, "%s ",
1072 float_format_names[GET_FIELD (insn, 17, 18)]);
1073 break;
1074 case 'H':
1075 if (GET_FIELD (insn, 26, 26) == 1)
1076 (*info->fprintf_func) (info->stream, "%s ",
1077 float_format_names[0]);
1078 else
1079 (*info->fprintf_func) (info->stream, "%s ",
1080 float_format_names[1]);
1081 break;
1082 case 'I':
1083 /* If no destination completer and not before a completer
1084 for fcmp, need a space here. */
1085 if (s[1] == '?')
1086 fputs_filtered
1087 (float_format_names[GET_FIELD (insn, 20, 20)], info);
1088 else
1089 (*info->fprintf_func)
1090 (info->stream, "%s ",
1091 float_format_names[GET_FIELD (insn, 20, 20)]);
1092 break;
1094 case 'J':
1095 fput_const (extract_14 (insn), info);
1096 break;
1098 case '#':
1100 int sign = GET_FIELD (insn, 31, 31);
1101 int imm10 = GET_FIELD (insn, 18, 27);
1102 int disp;
1104 if (sign)
1105 disp = (-1 << 10) | imm10;
1106 else
1107 disp = imm10;
1109 disp <<= 3;
1110 fput_const (disp, info);
1111 break;
1113 case 'K':
1114 case 'd':
1116 int sign = GET_FIELD (insn, 31, 31);
1117 int imm11 = GET_FIELD (insn, 18, 28);
1118 int disp;
1120 if (sign)
1121 disp = (-1 << 11) | imm11;
1122 else
1123 disp = imm11;
1125 disp <<= 2;
1126 fput_const (disp, info);
1127 break;
1130 case '>':
1131 case 'y':
1133 /* 16-bit long disp., PA2.0 wide only. */
1134 int disp = extract_16 (insn);
1135 disp &= ~3;
1136 fput_const (disp, info);
1137 break;
1140 case '&':
1142 /* 16-bit long disp., PA2.0 wide only. */
1143 int disp = extract_16 (insn);
1144 disp &= ~7;
1145 fput_const (disp, info);
1146 break;
1149 case '_':
1150 break; /* Dealt with by '{' */
1152 case '{':
1154 int sub = GET_FIELD (insn, 14, 16);
1155 int df = GET_FIELD (insn, 17, 18);
1156 int sf = GET_FIELD (insn, 19, 20);
1157 const char * const * source = float_format_names;
1158 const char * const * dest = float_format_names;
1159 char *t = "";
1161 if (sub == 4)
1163 fputs_filtered (",UND ", info);
1164 break;
1166 if ((sub & 3) == 3)
1167 t = ",t";
1168 if ((sub & 3) == 1)
1169 source = sub & 4 ? fcnv_ufixed_names : fcnv_fixed_names;
1170 if (sub & 2)
1171 dest = sub & 4 ? fcnv_ufixed_names : fcnv_fixed_names;
1173 (*info->fprintf_func) (info->stream, "%s%s%s ",
1174 t, source[sf], dest[df]);
1175 break;
1178 case 'm':
1180 int y = GET_FIELD (insn, 16, 18);
1182 if (y != 1)
1183 fput_const ((y ^ 1) - 1, info);
1185 break;
1187 case 'h':
1189 int cbit;
1191 cbit = GET_FIELD (insn, 16, 18);
1193 if (cbit > 0)
1194 (*info->fprintf_func) (info->stream, ",%d", cbit - 1);
1195 break;
1198 case '=':
1200 int cond = GET_FIELD (insn, 27, 31);
1202 switch (cond)
1204 case 0: fputs_filtered (" ", info); break;
1205 case 1: fputs_filtered ("acc ", info); break;
1206 case 2: fputs_filtered ("rej ", info); break;
1207 case 5: fputs_filtered ("acc8 ", info); break;
1208 case 6: fputs_filtered ("rej8 ", info); break;
1209 case 9: fputs_filtered ("acc6 ", info); break;
1210 case 13: fputs_filtered ("acc4 ", info); break;
1211 case 17: fputs_filtered ("acc2 ", info); break;
1212 default: break;
1214 break;
1217 case 'X':
1218 (*info->print_address_func)
1219 (memaddr + 8 + extract_22 (insn), info);
1220 break;
1221 case 'L':
1222 fputs_filtered (",rp", info);
1223 break;
1224 default:
1225 (*info->fprintf_func) (info->stream, "%c", *s);
1226 break;
1229 return sizeof (insn);
1232 (*info->fprintf_func) (info->stream, "#%8x", insn);
1233 return sizeof (insn);