1 /* Disassembler for the PA-RISC. Somewhat derived from sparc-pinsn.c.
2 Copyright 1989, 1990, 1992, 1993 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "opcode/hppa.h"
27 /* Integer register names, indexed by the numbers which appear in the
29 static const char *const reg_names[] =
30 {"flags", "r1", "rp", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
31 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
32 "r20", "r21", "r22", "r23", "r24", "r25", "r26", "dp", "ret0", "ret1",
35 /* Floating point register names, indexed by the numbers which appear in the
37 static const char *const fp_reg_names[] =
38 {"fpsr", "fpe2", "fpe4", "fpe6",
39 "fr4", "fr5", "fr6", "fr7", "fr8",
40 "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
41 "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",
42 "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31"};
44 typedef unsigned int CORE_ADDR;
46 /* Get at various relevent fields of an instruction word. */
51 #define MASK_14 0x3fff
52 #define MASK_21 0x1fffff
54 /* This macro gets bit fields using HP's numbering (MSB = 0) */
56 #define GET_FIELD(X, FROM, TO) \
57 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
59 /* Some of these have been converted to 2-d arrays because they
60 consume less storage this way. If the maintenance becomes a
61 problem, convert them back to const 1-d pointer arrays. */
62 static const char control_reg[][6] = {
63 "rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
64 "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4",
65 "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr",
66 "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3",
67 "tr4", "tr5", "tr6", "tr7"
70 static const char compare_cond_names[][5] = {
71 "", ",=", ",<", ",<=", ",<<", ",<<=", ",sv", ",od",
72 ",tr", ",<>", ",>=", ",>", ",>>=", ",>>", ",nsv", ",ev"
74 static const char compare_cond_64_names[][6] = {
75 "", ",*=", ",*<", ",*<=", ",*<<", ",*<<=", ",*sv", ",*od",
76 ",*tr", ",*<>", ",*>=", ",*>", ",*>>=", ",*>>", ",*nsv", ",*ev"
78 static const char cmpib_cond_64_names[][6] = {
79 ",*<<", ",*=", ",*<", ",*<=", ",*>>=", ",*<>", ",*>=", ",*>"
81 static const char add_cond_names[][5] = {
82 "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv", ",od",
83 ",tr", ",<>", ",>=", ",>", ",uv", ",vnz", ",nsv", ",ev"
85 static const char add_cond_64_names[][6] = {
86 ",*", ",*=", ",*<", ",*<=", ",*nuv", ",*znv", ",*sv", ",*od",
87 ",*tr", ",*<>", ",*>=", ",*>", ",*uv", ",*vnz", ",*nsv", ",*ev"
89 static const char wide_add_cond_names[][5] = {
90 "", ",=", ",<", ",<=", ",nuv", ",*=", ",*<", ",*<=",
91 ",tr", ",<>", ",>=", ",>", ",uv", ",*<>", ",*>=", ",*>"
93 static const char *const logical_cond_names[] = {
94 "", ",=", ",<", ",<=", 0, 0, 0, ",od",
95 ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};
96 static const char *const logical_cond_64_names[] = {
97 ",*", ",*=", ",*<", ",*<=", 0, 0, 0, ",*od",
98 ",*tr", ",*<>", ",*>=", ",*>", 0, 0, 0, ",*ev"};
99 static const char *const unit_cond_names[] = {
100 "", 0, ",sbz", ",shz", ",sdc", 0, ",sbc", ",shc",
101 ",tr", 0, ",nbz", ",nhz", ",ndc", 0, ",nbc", ",nhc"
103 static const char *const unit_cond_64_names[] = {
104 ",*", ",*swz", ",*sbz", ",*shz", ",*sdc", ",*swc", ",*sbc", ",*shc",
105 ",*tr", ",*nwz", ",*nbz", ",*nhz", ",*ndc", ",*nwc", ",*nbc", ",*nhc"
107 static const char shift_cond_names[][4] = {
108 "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"
110 static const char shift_cond_64_names[][5] = {
111 ",*", ",*=", ",*<", ",*od", ",*tr", ",*<>", ",*>=", ",*ev"
113 static const char bb_cond_64_names[][5] = {
116 static const char index_compl_names[][4] = {"", ",m", ",s", ",sm"};
117 static const char short_ldst_compl_names[][4] = {"", ",ma", "", ",mb"};
118 static const char *const short_bytes_compl_names[] = {
119 "", ",b,m", ",e", ",e,m"
121 static const char *const float_format_names[] = {",sgl", ",dbl", "", ",quad"};
122 static const char float_comp_names[][8] =
124 ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",
125 ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",
126 ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",
127 ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"
129 static const char *const signed_unsigned_names[][3] = {",u", ",s"};
130 static const char *const mix_half_names[][3] = {",l", ",r"};
131 static const char *const saturation_names[][4] = {",us", ",ss", 0, ""};
132 static const char *const read_write_names[][3] = {",r", ",w"};
133 static const char *const add_compl_names[] = {
137 /* For a bunch of different instructions form an index into a
138 completer name table. */
139 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
140 GET_FIELD (insn, 18, 18) << 1)
142 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
143 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
145 /* Utility function to print registers. Put these first, so gcc's function
146 inlining can do its stuff. */
148 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
153 disassemble_info *info;
155 (*info->fprintf_func) (info->stream, reg ? reg_names[reg] : "r0");
159 fput_fp_reg (reg, info)
161 disassemble_info *info;
163 (*info->fprintf_func) (info->stream, reg ? fp_reg_names[reg] : "fr0");
167 fput_fp_reg_r (reg, info)
169 disassemble_info *info;
171 /* Special case floating point exception registers. */
173 (*info->fprintf_func) (info->stream, "fpe%d", reg * 2 + 1);
175 (*info->fprintf_func) (info->stream, "%sR", reg ? fp_reg_names[reg]
180 fput_creg (reg, info)
182 disassemble_info *info;
184 (*info->fprintf_func) (info->stream, control_reg[reg]);
187 /* print constants with sign */
190 fput_const (num, info)
192 disassemble_info *info;
195 (*info->fprintf_func) (info->stream, "-%x", -(int)num);
197 (*info->fprintf_func) (info->stream, "%x", num);
200 /* Routines to extract various sized constants out of hppa
203 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
208 return GET_FIELD (word, 18, 18) << 2 | GET_FIELD (word, 16, 17);
212 extract_5_load (word)
215 return low_sign_extend (word >> 16 & MASK_5, 5);
218 /* extract the immediate field from a st{bhw}s instruction */
220 extract_5_store (word)
223 return low_sign_extend (word & MASK_5, 5);
226 /* extract the immediate field from a break instruction */
228 extract_5r_store (word)
231 return (word & MASK_5);
234 /* extract the immediate field from a {sr}sm instruction */
236 extract_5R_store (word)
239 return (word >> 16 & MASK_5);
242 /* extract the 10 bit immediate field from a {sr}sm instruction */
244 extract_10U_store (word)
247 return (word >> 16 & MASK_10);
250 /* extract the immediate field from a bb instruction */
252 extract_5Q_store (word)
255 return (word >> 21 & MASK_5);
258 /* extract an 11 bit immediate field */
263 return low_sign_extend (word & MASK_11, 11);
266 /* extract a 14 bit immediate field */
271 return low_sign_extend (word & MASK_14, 14);
274 /* extract a 21 bit constant */
284 val = GET_FIELD (word, 20, 20);
286 val |= GET_FIELD (word, 9, 19);
288 val |= GET_FIELD (word, 5, 6);
290 val |= GET_FIELD (word, 0, 4);
292 val |= GET_FIELD (word, 7, 8);
293 return sign_extend (val, 21) << 11;
296 /* extract a 12 bit constant from branch instructions */
302 return sign_extend (GET_FIELD (word, 19, 28) |
303 GET_FIELD (word, 29, 29) << 10 |
304 (word & 0x1) << 11, 12) << 2;
307 /* extract a 17 bit constant from branch instructions, returning the
308 19 bit signed value. */
314 return sign_extend (GET_FIELD (word, 19, 28) |
315 GET_FIELD (word, 29, 29) << 10 |
316 GET_FIELD (word, 11, 15) << 11 |
317 (word & 0x1) << 16, 17) << 2;
320 /* Print one instruction. */
322 print_insn_hppa (memaddr, info)
324 disassemble_info *info;
327 unsigned int insn, i;
331 (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
334 (*info->memory_error_func) (status, memaddr, info);
339 insn = bfd_getb32 (buffer);
341 for (i = 0; i < NUMOPCODES; ++i)
343 const struct pa_opcode *opcode = &pa_opcodes[i];
344 if ((insn & opcode->mask) == opcode->match)
346 register const char *s;
348 (*info->fprintf_func) (info->stream, "%s", opcode->name);
350 if (!strchr ("cfCY?-+nHNZFIu", opcode->args[0]))
351 (*info->fprintf_func) (info->stream, " ");
352 for (s = opcode->args; *s != '\0'; ++s)
357 fput_reg (GET_FIELD (insn, 11, 15), info);
360 if (GET_FIELD (insn, 25, 25))
361 fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
363 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
367 fput_reg (GET_FIELD (insn, 6, 10), info);
370 fput_creg (GET_FIELD (insn, 6, 10), info);
373 fput_fp_reg (GET_FIELD (insn, 6, 10), info);
376 fput_reg (GET_FIELD (insn, 27, 31), info);
379 if (GET_FIELD (insn, 25, 25))
380 fput_fp_reg_r (GET_FIELD (insn, 27, 31), info);
382 fput_fp_reg (GET_FIELD (insn, 27, 31), info);
385 fput_fp_reg (GET_FIELD (insn, 27, 31), info);
389 int reg = GET_FIELD (insn, 6, 10);
391 reg |= (GET_FIELD (insn, 26, 26) << 4);
392 fput_fp_reg (reg, info);
397 int reg = GET_FIELD (insn, 11, 15);
399 reg |= (GET_FIELD (insn, 26, 26) << 4);
400 fput_fp_reg (reg, info);
405 int reg = GET_FIELD (insn, 27, 31);
407 reg |= (GET_FIELD (insn, 26, 26) << 4);
408 fput_fp_reg (reg, info);
413 int reg = GET_FIELD (insn, 16, 20);
415 reg |= (GET_FIELD (insn, 26, 26) << 4);
416 fput_fp_reg (reg, info);
421 int reg = GET_FIELD (insn, 21, 25);
423 reg |= (GET_FIELD (insn, 26, 26) << 4);
424 fput_fp_reg (reg, info);
428 fput_const (extract_5_load (insn), info);
431 (*info->fprintf_func) (info->stream,
432 "sr%d", GET_FIELD (insn, 16, 17));
436 (*info->fprintf_func) (info->stream, "sr%d", extract_3 (insn));
439 /* Handle completers. */
444 (*info->fprintf_func) (info->stream, "%s ",
445 index_compl_names[GET_COMPL (insn)]);
448 (*info->fprintf_func) (info->stream, "%s ",
449 short_ldst_compl_names[GET_COMPL (insn)]);
452 (*info->fprintf_func) (info->stream, "%s ",
453 short_bytes_compl_names[GET_COMPL (insn)]);
456 (*info->fprintf_func) (info->stream, ",l");
459 (*info->fprintf_func) (info->stream, "%s ",
460 read_write_names[GET_FIELD (insn, 25, 25)]);
463 (*info->fprintf_func) (info->stream, ",w");
466 if (GET_FIELD (insn, 23, 26) == 5)
467 (*info->fprintf_func) (info->stream, ",r");
470 if (GET_FIELD (insn, 26, 26))
471 (*info->fprintf_func) (info->stream, ",m ");
473 (*info->fprintf_func) (info->stream, " ");
476 if (GET_FIELD (insn, 25, 25))
477 (*info->fprintf_func) (info->stream, ",i");
480 (*info->fprintf_func)
481 (info->stream, "%s", add_compl_names[GET_FIELD
485 (*info->fprintf_func)
486 (info->stream, ",dc%s", add_compl_names[GET_FIELD
490 (*info->fprintf_func)
491 (info->stream, ",c%s", add_compl_names[GET_FIELD
495 if (GET_FIELD (insn, 20, 20))
496 (*info->fprintf_func) (info->stream, ",tsv");
499 (*info->fprintf_func) (info->stream, ",tc");
500 if (GET_FIELD (insn, 20, 20))
501 (*info->fprintf_func) (info->stream, ",tsv");
504 (*info->fprintf_func) (info->stream, ",db");
505 if (GET_FIELD (insn, 20, 20))
506 (*info->fprintf_func) (info->stream, ",tsv");
509 (*info->fprintf_func) (info->stream, ",b");
510 if (GET_FIELD (insn, 20, 20))
511 (*info->fprintf_func) (info->stream, ",tsv");
514 if (GET_FIELD (insn, 25, 25))
515 (*info->fprintf_func) (info->stream, ",tc");
518 /* EXTRD/W has a following condition. */
520 (*info->fprintf_func)
521 (info->stream, "%s", signed_unsigned_names[GET_FIELD
524 (*info->fprintf_func)
525 (info->stream, "%s ", signed_unsigned_names[GET_FIELD
529 (*info->fprintf_func)
530 (info->stream, "%s", mix_half_names[GET_FIELD
534 (*info->fprintf_func)
535 (info->stream, "%s", saturation_names[GET_FIELD
539 (*info->fprintf_func)
540 (info->stream, ",%d%d%d%d ",
541 GET_FIELD (insn, 17, 18), GET_FIELD (insn, 20, 21),
542 GET_FIELD (insn, 22, 23), GET_FIELD (insn, 24, 25));
547 /* Handle conditions. */
554 (*info->fprintf_func) (info->stream, "%s ",
555 float_comp_names[GET_FIELD
559 /* these four conditions are for the set of instructions
560 which distinguish true/false conditions by opcode
561 rather than by the 'f' bit (sigh): comb, comib,
564 fputs_filtered (compare_cond_names[GET_FIELD (insn, 16,
569 fputs_filtered (compare_cond_names[GET_FIELD (insn, 16, 18)
573 fputs_filtered (compare_cond_64_names[GET_FIELD (insn, 16, 18)],
577 fputs_filtered (compare_cond_64_names[GET_FIELD (insn, 16, 18)
581 fputs_filtered (cmpib_cond_64_names[GET_FIELD (insn, 16, 18)],
585 fputs_filtered (compare_cond_names[GET_FIELD (insn, 16,
587 + GET_FIELD (insn, 4, 4) * 8], info);
590 fputs_filtered (add_cond_names[GET_FIELD (insn, 16, 18)
591 + GET_FIELD (insn, 4, 4) * 8], info);
594 (*info->fprintf_func) (info->stream, "%s ",
595 compare_cond_names[GET_COND (insn)]);
598 (*info->fprintf_func) (info->stream, "%s ",
599 compare_cond_64_names[GET_COND (insn)]);
602 (*info->fprintf_func) (info->stream, "%s ",
603 add_cond_names[GET_COND (insn)]);
606 (*info->fprintf_func) (info->stream, "%s ",
607 add_cond_64_names[GET_COND (insn)]);
610 (*info->fprintf_func) (info->stream, "%s",
611 add_cond_names[GET_FIELD (insn,
616 (*info->fprintf_func) (info->stream, "%s",
617 add_cond_names[GET_FIELD (insn,
622 (*info->fprintf_func)
624 wide_add_cond_names[GET_FIELD (insn, 16, 18)]);
628 (*info->fprintf_func)
630 wide_add_cond_names[GET_FIELD (insn, 16, 18) + 8]);
634 (*info->fprintf_func) (info->stream, "%s ",
635 logical_cond_names[GET_COND (insn)]);
638 (*info->fprintf_func) (info->stream, "%s ",
639 logical_cond_64_names[GET_COND (insn)]);
642 (*info->fprintf_func) (info->stream, "%s ",
643 unit_cond_names[GET_COND (insn)]);
646 (*info->fprintf_func) (info->stream, "%s ",
647 unit_cond_64_names[GET_COND (insn)]);
652 (*info->fprintf_func)
654 shift_cond_names[GET_FIELD (insn, 16, 18)]);
656 /* If the next character in args is 'n', it will handle
657 putting out the space. */
659 (*info->fprintf_func) (info->stream, " ");
662 (*info->fprintf_func) (info->stream, "%s",
663 shift_cond_64_names[GET_FIELD (insn, 16, 18)]);
666 (*info->fprintf_func)
668 bb_cond_64_names[GET_FIELD (insn, 16, 16)]);
670 /* If the next character in args is 'n', it will handle
671 putting out the space. */
673 (*info->fprintf_func) (info->stream, " ");
680 fput_const (extract_5_store (insn), info);
683 fput_const (extract_5r_store (insn), info);
686 fput_const (extract_5R_store (insn), info);
689 fput_const (extract_10U_store (insn), info);
692 fput_const (extract_5Q_store (insn), info);
695 fput_const (extract_11 (insn), info);
698 fput_const (extract_14 (insn), info);
701 fput_const (extract_21 (insn), info);
705 (*info->fprintf_func) (info->stream, ",n ");
707 (*info->fprintf_func) (info->stream, " ");
710 if ((insn & 0x20) && s[1])
711 (*info->fprintf_func) (info->stream, ",n ");
712 else if (insn & 0x20)
713 (*info->fprintf_func) (info->stream, ",n");
715 (*info->fprintf_func) (info->stream, " ");
718 (*info->print_address_func) (memaddr + 8 + extract_12 (insn),
722 /* 17 bit PC-relative branch. */
723 (*info->print_address_func) ((memaddr + 8
724 + extract_17 (insn)),
728 /* 17 bit displacement. This is an offset from a register
729 so it gets disasssembled as just a number, not any sort
731 fput_const (extract_17 (insn), info);
734 (*info->fprintf_func) (info->stream, "%d",
735 GET_FIELD (insn, 24, 25));
738 (*info->fprintf_func) (info->stream, "%d",
739 GET_FIELD (insn, 22, 25));
742 (*info->fprintf_func) (info->stream, "%sar");
745 (*info->fprintf_func) (info->stream, "%d",
746 31 - GET_FIELD (insn, 22, 26));
751 num = GET_FIELD (insn, 20, 20) << 5;
752 num |= GET_FIELD (insn, 22, 26);
753 (*info->fprintf_func) (info->stream, "%d", 63 - num);
757 (*info->fprintf_func) (info->stream, "%d",
758 GET_FIELD (insn, 22, 26));
761 (*info->fprintf_func) (info->stream, "%d",
762 32 - GET_FIELD (insn, 27, 31));
765 fput_const (GET_FIELD (insn, 20, 28), info);
768 fput_const (GET_FIELD (insn, 6, 18), info);
771 fput_const (GET_FIELD (insn, 6, 31), info);
774 (*info->fprintf_func) (info->stream, ",%d", GET_FIELD (insn, 23, 25));
777 fput_const ((GET_FIELD (insn, 6,20) << 5 |
778 GET_FIELD (insn, 27, 31)), info);
781 fput_const (GET_FIELD (insn, 6, 20), info);
785 int reg = GET_FIELD (insn, 21, 22);
786 reg |= GET_FIELD (insn, 16, 18) << 2;
787 if (GET_FIELD (insn, 23, 23) != 0)
788 fput_fp_reg_r (reg, info);
790 fput_fp_reg (reg, info);
795 fput_const ((GET_FIELD (insn, 6, 22) << 5 |
796 GET_FIELD (insn, 27, 31)), info);
799 fput_const ((GET_FIELD (insn, 11, 20) << 5 |
800 GET_FIELD (insn, 27, 31)), info);
803 fput_const ((GET_FIELD (insn, 16, 20) << 5 |
804 GET_FIELD (insn, 27, 31)), info);
807 (*info->fprintf_func) (info->stream, ",%d", GET_FIELD (insn, 23, 25));
810 /* if no destination completer and not before a completer
811 for fcmp, need a space here */
812 if (s[1] == 'G' || s[1] == '?')
813 fputs_filtered (float_format_names[GET_FIELD (insn, 19, 20)],
816 (*info->fprintf_func) (info->stream, "%s ",
817 float_format_names[GET_FIELD
821 (*info->fprintf_func) (info->stream, "%s ",
822 float_format_names[GET_FIELD (insn,
826 if (GET_FIELD (insn, 26, 26) == 1)
827 (*info->fprintf_func) (info->stream, "%s ",
828 float_format_names[0]);
830 (*info->fprintf_func) (info->stream, "%s ",
831 float_format_names[1]);
834 /* if no destination completer and not before a completer
835 for fcmp, need a space here */
837 fputs_filtered (float_format_names[GET_FIELD (insn, 20, 20)],
840 (*info->fprintf_func) (info->stream, "%s ",
841 float_format_names[GET_FIELD
845 if (GET_FIELD (insn, 24, 24))
846 fput_fp_reg_r (GET_FIELD (insn, 6, 10), info);
848 fput_fp_reg (GET_FIELD (insn, 6, 10), info);
852 if (GET_FIELD (insn, 19, 19))
853 fput_fp_reg_r (GET_FIELD (insn, 11, 15), info);
855 fput_fp_reg (GET_FIELD (insn, 11, 15), info);
858 (*info->fprintf_func) (info->stream, "%c", *s);
865 (*info->fprintf_func) (info->stream, "#%8x", insn);