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. */
50 #define MASK_14 0x3fff
51 #define MASK_21 0x1fffff
53 /* This macro gets bit fields using HP's numbering (MSB = 0) */
55 #define GET_FIELD(X, FROM, TO) \
56 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
58 /* Some of these have been converted to 2-d arrays because they
59 consume less storage this way. If the maintenance becomes a
60 problem, convert them back to const 1-d pointer arrays. */
61 static const char control_reg
[][6] = {
62 "rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
63 "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4",
64 "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr",
65 "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3",
66 "tr4", "tr5", "tr6", "tr7"
69 static const char compare_cond_names
[][5] = {
70 "", ",=", ",<", ",<=", ",<<", ",<<=", ",sv", ",od",
71 ",tr", ",<>", ",>=", ",>", ",>>=", ",>>", ",nsv", ",ev"
73 static const char compare_cond_64_names
[][6] = {
74 "", ",*=", ",*<", ",*<=", ",*<<", ",*<<=", ",*sv", ",*od",
75 ",*tr", ",*<>", ",*>=", ",*>", ",*>>=", ",*>>", ",*nsv", ",*ev"
77 static const char cmpib_cond_64_names
[][6] = {
78 ",*<<", ",*=", ",*<", ",*<=", ",*>>=", ",*<>", ",*>=", ",*>"
80 static const char add_cond_names
[][5] = {
81 "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv", ",od",
82 ",tr", ",<>", ",>=", ",>", ",uv", ",vnz", ",nsv", ",ev"
84 static const char add_cond_64_names
[][6] = {
85 ",*", ",*=", ",*<", ",*<=", ",*nuv", ",*znv", ",*sv", ",*od",
86 ",*tr", ",*<>", ",*>=", ",*>", ",*uv", ",*vnz", ",*nsv", ",*ev"
88 static const char wide_add_cond_names
[][5] = {
89 "", ",=", ",<", ",<=", ",nuv", ",*=", ",*<", ",*<=",
90 ",tr", ",<>", ",>=", ",>", ",uv", ",*<>", ",*>=", ",*>"
92 static const char *const logical_cond_names
[] = {
93 "", ",=", ",<", ",<=", 0, 0, 0, ",od",
94 ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};
95 static const char *const logical_cond_64_names
[] = {
96 ",*", ",*=", ",*<", ",*<=", 0, 0, 0, ",*od",
97 ",*tr", ",*<>", ",*>=", ",*>", 0, 0, 0, ",*ev"};
98 static const char *const unit_cond_names
[] = {
99 "", 0, ",sbz", ",shz", ",sdc", 0, ",sbc", ",shc",
100 ",tr", 0, ",nbz", ",nhz", ",ndc", 0, ",nbc", ",nhc"
102 static const char *const unit_cond_64_names
[] = {
103 ",*", ",*swz", ",*sbz", ",*shz", ",*sdc", ",*swc", ",*sbc", ",*shc",
104 ",*tr", ",*nwz", ",*nbz", ",*nhz", ",*ndc", ",*nwc", ",*nbc", ",*nhc"
106 static const char shift_cond_names
[][4] = {
107 "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"
109 static const char shift_cond_64_names
[][5] = {
110 ",*", ",*=", ",*<", ",*od", ",*tr", ",*<>", ",*>=", ",*ev"
112 static const char bb_cond_64_names
[][5] = {
115 static const char index_compl_names
[][4] = {"", ",m", ",s", ",sm"};
116 static const char short_ldst_compl_names
[][4] = {"", ",ma", "", ",mb"};
117 static const char *const short_bytes_compl_names
[] = {
118 "", ",b,m", ",e", ",e,m"
120 static const char *const float_format_names
[] = {",sgl", ",dbl", "", ",quad"};
121 static const char float_comp_names
[][8] =
123 ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",
124 ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",
125 ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",
126 ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"
129 /* For a bunch of different instructions form an index into a
130 completer name table. */
131 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
132 GET_FIELD (insn, 18, 18) << 1)
134 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
135 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
137 /* Utility function to print registers. Put these first, so gcc's function
138 inlining can do its stuff. */
140 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
145 disassemble_info
*info
;
147 (*info
->fprintf_func
) (info
->stream
, reg
? reg_names
[reg
] : "r0");
151 fput_fp_reg (reg
, info
)
153 disassemble_info
*info
;
155 (*info
->fprintf_func
) (info
->stream
, reg
? fp_reg_names
[reg
] : "fr0");
159 fput_fp_reg_r (reg
, info
)
161 disassemble_info
*info
;
163 /* Special case floating point exception registers. */
165 (*info
->fprintf_func
) (info
->stream
, "fpe%d", reg
* 2 + 1);
167 (*info
->fprintf_func
) (info
->stream
, "%sR", reg
? fp_reg_names
[reg
]
172 fput_creg (reg
, info
)
174 disassemble_info
*info
;
176 (*info
->fprintf_func
) (info
->stream
, control_reg
[reg
]);
179 /* print constants with sign */
182 fput_const (num
, info
)
184 disassemble_info
*info
;
187 (*info
->fprintf_func
) (info
->stream
, "-%x", -(int)num
);
189 (*info
->fprintf_func
) (info
->stream
, "%x", num
);
192 /* Routines to extract various sized constants out of hppa
195 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
200 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
204 extract_5_load (word
)
207 return low_sign_extend (word
>> 16 & MASK_5
, 5);
210 /* extract the immediate field from a st{bhw}s instruction */
212 extract_5_store (word
)
215 return low_sign_extend (word
& MASK_5
, 5);
218 /* extract the immediate field from a break instruction */
220 extract_5r_store (word
)
223 return (word
& MASK_5
);
226 /* extract the immediate field from a {sr}sm instruction */
228 extract_5R_store (word
)
231 return (word
>> 16 & MASK_5
);
234 /* extract the immediate field from a bb instruction */
236 extract_5Q_store (word
)
239 return (word
>> 21 & MASK_5
);
242 /* extract an 11 bit immediate field */
247 return low_sign_extend (word
& MASK_11
, 11);
250 /* extract a 14 bit immediate field */
255 return low_sign_extend (word
& MASK_14
, 14);
258 /* extract a 21 bit constant */
268 val
= GET_FIELD (word
, 20, 20);
270 val
|= GET_FIELD (word
, 9, 19);
272 val
|= GET_FIELD (word
, 5, 6);
274 val
|= GET_FIELD (word
, 0, 4);
276 val
|= GET_FIELD (word
, 7, 8);
277 return sign_extend (val
, 21) << 11;
280 /* extract a 12 bit constant from branch instructions */
286 return sign_extend (GET_FIELD (word
, 19, 28) |
287 GET_FIELD (word
, 29, 29) << 10 |
288 (word
& 0x1) << 11, 12) << 2;
291 /* extract a 17 bit constant from branch instructions, returning the
292 19 bit signed value. */
298 return sign_extend (GET_FIELD (word
, 19, 28) |
299 GET_FIELD (word
, 29, 29) << 10 |
300 GET_FIELD (word
, 11, 15) << 11 |
301 (word
& 0x1) << 16, 17) << 2;
304 /* Print one instruction. */
306 print_insn_hppa (memaddr
, info
)
308 disassemble_info
*info
;
311 unsigned int insn
, i
;
315 (*info
->read_memory_func
) (memaddr
, buffer
, sizeof (buffer
), info
);
318 (*info
->memory_error_func
) (status
, memaddr
, info
);
323 insn
= bfd_getb32 (buffer
);
325 for (i
= 0; i
< NUMOPCODES
; ++i
)
327 const struct pa_opcode
*opcode
= &pa_opcodes
[i
];
328 if ((insn
& opcode
->mask
) == opcode
->match
)
330 register const char *s
;
332 (*info
->fprintf_func
) (info
->stream
, "%s", opcode
->name
);
334 if (!strchr ("cfCY?-+nHNZFIu", opcode
->args
[0]))
335 (*info
->fprintf_func
) (info
->stream
, " ");
336 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
341 fput_reg (GET_FIELD (insn
, 11, 15), info
);
344 if (GET_FIELD (insn
, 25, 25))
345 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
347 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
350 fput_reg (GET_FIELD (insn
, 6, 10), info
);
353 fput_creg (GET_FIELD (insn
, 6, 10), info
);
356 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
359 fput_reg (GET_FIELD (insn
, 27, 31), info
);
362 if (GET_FIELD (insn
, 25, 25))
363 fput_fp_reg_r (GET_FIELD (insn
, 27, 31), info
);
365 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
368 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
372 int reg
= GET_FIELD (insn
, 6, 10);
374 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
375 fput_fp_reg (reg
, info
);
380 int reg
= GET_FIELD (insn
, 11, 15);
382 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
383 fput_fp_reg (reg
, info
);
388 int reg
= GET_FIELD (insn
, 27, 31);
390 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
391 fput_fp_reg (reg
, info
);
396 int reg
= GET_FIELD (insn
, 16, 20);
398 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
399 fput_fp_reg (reg
, info
);
404 int reg
= GET_FIELD (insn
, 21, 25);
406 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
407 fput_fp_reg (reg
, info
);
411 fput_const (extract_5_load (insn
), info
);
414 (*info
->fprintf_func
) (info
->stream
,
415 "sr%d", GET_FIELD (insn
, 16, 17));
419 (*info
->fprintf_func
) (info
->stream
, "sr%d", extract_3 (insn
));
422 (*info
->fprintf_func
) (info
->stream
, "%s ",
423 index_compl_names
[GET_COMPL (insn
)]);
426 (*info
->fprintf_func
) (info
->stream
, "%s ",
427 short_ldst_compl_names
[GET_COMPL (insn
)]);
430 (*info
->fprintf_func
) (info
->stream
, "%s ",
431 short_bytes_compl_names
[GET_COMPL (insn
)]);
434 /* Handle conditions. */
441 (*info
->fprintf_func
) (info
->stream
, "%s ",
442 float_comp_names
[GET_FIELD
446 /* these four conditions are for the set of instructions
447 which distinguish true/false conditions by opcode
448 rather than by the 'f' bit (sigh): comb, comib,
451 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
456 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16, 18)
460 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)],
464 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)
468 fputs_filtered (cmpib_cond_64_names
[GET_FIELD (insn
, 16, 18)],
472 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
474 + GET_FIELD (insn
, 4, 4) * 8], info
);
477 fputs_filtered (add_cond_names
[GET_FIELD (insn
, 16, 18)
478 + GET_FIELD (insn
, 4, 4) * 8], info
);
481 (*info
->fprintf_func
) (info
->stream
, "%s ",
482 compare_cond_names
[GET_COND (insn
)]);
485 (*info
->fprintf_func
) (info
->stream
, "%s ",
486 compare_cond_64_names
[GET_COND (insn
)]);
489 (*info
->fprintf_func
) (info
->stream
, "%s ",
490 add_cond_names
[GET_COND (insn
)]);
493 (*info
->fprintf_func
) (info
->stream
, "%s ",
494 add_cond_64_names
[GET_COND (insn
)]);
497 (*info
->fprintf_func
) (info
->stream
, "%s",
498 add_cond_names
[GET_FIELD (insn
,
503 (*info
->fprintf_func
) (info
->stream
, "%s",
504 add_cond_names
[GET_FIELD (insn
,
509 (*info
->fprintf_func
)
511 wide_add_cond_names
[GET_FIELD (insn
, 16, 18)]);
515 (*info
->fprintf_func
)
517 wide_add_cond_names
[GET_FIELD (insn
, 16, 18) + 8]);
521 (*info
->fprintf_func
) (info
->stream
, "%s ",
522 logical_cond_names
[GET_COND (insn
)]);
525 (*info
->fprintf_func
) (info
->stream
, "%s ",
526 logical_cond_64_names
[GET_COND (insn
)]);
529 (*info
->fprintf_func
) (info
->stream
, "%s ",
530 unit_cond_names
[GET_COND (insn
)]);
533 (*info
->fprintf_func
) (info
->stream
, "%s ",
534 unit_cond_64_names
[GET_COND (insn
)]);
539 (*info
->fprintf_func
)
541 shift_cond_names
[GET_FIELD (insn
, 16, 18)]);
543 /* If the next character in args is 'n', it will handle
544 putting out the space. */
546 (*info
->fprintf_func
) (info
->stream
, " ");
549 (*info
->fprintf_func
) (info
->stream
, "%s",
550 shift_cond_64_names
[GET_FIELD (insn
, 16, 18)]);
553 (*info
->fprintf_func
)
555 bb_cond_64_names
[GET_FIELD (insn
, 16, 16)]);
557 /* If the next character in args is 'n', it will handle
558 putting out the space. */
560 (*info
->fprintf_func
) (info
->stream
, " ");
567 fput_const (extract_5_store (insn
), info
);
570 fput_const (extract_5r_store (insn
), info
);
573 fput_const (extract_5R_store (insn
), info
);
576 fput_const (extract_5Q_store (insn
), info
);
579 fput_const (extract_11 (insn
), info
);
582 fput_const (extract_14 (insn
), info
);
585 fput_const (extract_21 (insn
), info
);
589 (*info
->fprintf_func
) (info
->stream
, ",n ");
591 (*info
->fprintf_func
) (info
->stream
, " ");
594 if ((insn
& 0x20) && s
[1])
595 (*info
->fprintf_func
) (info
->stream
, ",n ");
596 else if (insn
& 0x20)
597 (*info
->fprintf_func
) (info
->stream
, ",n");
599 (*info
->fprintf_func
) (info
->stream
, " ");
602 (*info
->print_address_func
) (memaddr
+ 8 + extract_12 (insn
),
606 /* 17 bit PC-relative branch. */
607 (*info
->print_address_func
) ((memaddr
+ 8
608 + extract_17 (insn
)),
612 /* 17 bit displacement. This is an offset from a register
613 so it gets disasssembled as just a number, not any sort
615 fput_const (extract_17 (insn
), info
);
618 (*info
->fprintf_func
) (info
->stream
, "%d",
619 31 - GET_FIELD (insn
, 22, 26));
622 (*info
->fprintf_func
) (info
->stream
, "%d",
623 GET_FIELD (insn
, 22, 26));
626 (*info
->fprintf_func
) (info
->stream
, "%d",
627 32 - GET_FIELD (insn
, 27, 31));
630 fput_const (GET_FIELD (insn
, 6, 18), info
);
633 if (GET_FIELD (insn
, 26, 26))
634 (*info
->fprintf_func
) (info
->stream
, ",m ");
636 (*info
->fprintf_func
) (info
->stream
, " ");
639 fput_const (GET_FIELD (insn
, 6, 31), info
);
642 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
645 fput_const ((GET_FIELD (insn
, 6,20) << 5 |
646 GET_FIELD (insn
, 27, 31)), info
);
649 fput_const (GET_FIELD (insn
, 6, 20), info
);
653 int reg
= GET_FIELD (insn
, 21, 22);
654 reg
|= GET_FIELD (insn
, 16, 18) << 2;
655 if (GET_FIELD (insn
, 23, 23) != 0)
656 fput_fp_reg_r (reg
, info
);
658 fput_fp_reg (reg
, info
);
663 fput_const ((GET_FIELD (insn
, 6, 22) << 5 |
664 GET_FIELD (insn
, 27, 31)), info
);
667 fput_const ((GET_FIELD (insn
, 11, 20) << 5 |
668 GET_FIELD (insn
, 27, 31)), info
);
671 fput_const ((GET_FIELD (insn
, 16, 20) << 5 |
672 GET_FIELD (insn
, 27, 31)), info
);
675 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
678 /* if no destination completer and not before a completer
679 for fcmp, need a space here */
680 if (s
[1] == 'G' || s
[1] == '?')
681 fputs_filtered (float_format_names
[GET_FIELD (insn
, 19, 20)],
684 (*info
->fprintf_func
) (info
->stream
, "%s ",
685 float_format_names
[GET_FIELD
689 (*info
->fprintf_func
) (info
->stream
, "%s ",
690 float_format_names
[GET_FIELD (insn
,
694 if (GET_FIELD (insn
, 26, 26) == 1)
695 (*info
->fprintf_func
) (info
->stream
, "%s ",
696 float_format_names
[0]);
698 (*info
->fprintf_func
) (info
->stream
, "%s ",
699 float_format_names
[1]);
702 /* if no destination completer and not before a completer
703 for fcmp, need a space here */
705 fputs_filtered (float_format_names
[GET_FIELD (insn
, 20, 20)],
708 (*info
->fprintf_func
) (info
->stream
, "%s ",
709 float_format_names
[GET_FIELD
713 if (GET_FIELD (insn
, 24, 24))
714 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
716 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
720 if (GET_FIELD (insn
, 19, 19))
721 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
723 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
726 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
733 (*info
->fprintf_func
) (info
->stream
, "#%8x", insn
);