4a7fd06efb7f2349d610755aba6df6a90fd0c3d3
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"
128 static const char *const signed_unsigned_names
[][3] = {",u", ",s"};
129 static const char *const mix_half_names
[][3] = {",l", ",r"};
130 static const char *const saturation_names
[][3] = {",us", ",ss", 0, ""};
133 /* For a bunch of different instructions form an index into a
134 completer name table. */
135 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
136 GET_FIELD (insn, 18, 18) << 1)
138 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
139 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
141 /* Utility function to print registers. Put these first, so gcc's function
142 inlining can do its stuff. */
144 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
149 disassemble_info
*info
;
151 (*info
->fprintf_func
) (info
->stream
, reg
? reg_names
[reg
] : "r0");
155 fput_fp_reg (reg
, info
)
157 disassemble_info
*info
;
159 (*info
->fprintf_func
) (info
->stream
, reg
? fp_reg_names
[reg
] : "fr0");
163 fput_fp_reg_r (reg
, info
)
165 disassemble_info
*info
;
167 /* Special case floating point exception registers. */
169 (*info
->fprintf_func
) (info
->stream
, "fpe%d", reg
* 2 + 1);
171 (*info
->fprintf_func
) (info
->stream
, "%sR", reg
? fp_reg_names
[reg
]
176 fput_creg (reg
, info
)
178 disassemble_info
*info
;
180 (*info
->fprintf_func
) (info
->stream
, control_reg
[reg
]);
183 /* print constants with sign */
186 fput_const (num
, info
)
188 disassemble_info
*info
;
191 (*info
->fprintf_func
) (info
->stream
, "-%x", -(int)num
);
193 (*info
->fprintf_func
) (info
->stream
, "%x", num
);
196 /* Routines to extract various sized constants out of hppa
199 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
204 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
208 extract_5_load (word
)
211 return low_sign_extend (word
>> 16 & MASK_5
, 5);
214 /* extract the immediate field from a st{bhw}s instruction */
216 extract_5_store (word
)
219 return low_sign_extend (word
& MASK_5
, 5);
222 /* extract the immediate field from a break instruction */
224 extract_5r_store (word
)
227 return (word
& MASK_5
);
230 /* extract the immediate field from a {sr}sm instruction */
232 extract_5R_store (word
)
235 return (word
>> 16 & MASK_5
);
238 /* extract the immediate field from a bb instruction */
240 extract_5Q_store (word
)
243 return (word
>> 21 & MASK_5
);
246 /* extract an 11 bit immediate field */
251 return low_sign_extend (word
& MASK_11
, 11);
254 /* extract a 14 bit immediate field */
259 return low_sign_extend (word
& MASK_14
, 14);
262 /* extract a 21 bit constant */
272 val
= GET_FIELD (word
, 20, 20);
274 val
|= GET_FIELD (word
, 9, 19);
276 val
|= GET_FIELD (word
, 5, 6);
278 val
|= GET_FIELD (word
, 0, 4);
280 val
|= GET_FIELD (word
, 7, 8);
281 return sign_extend (val
, 21) << 11;
284 /* extract a 12 bit constant from branch instructions */
290 return sign_extend (GET_FIELD (word
, 19, 28) |
291 GET_FIELD (word
, 29, 29) << 10 |
292 (word
& 0x1) << 11, 12) << 2;
295 /* extract a 17 bit constant from branch instructions, returning the
296 19 bit signed value. */
302 return sign_extend (GET_FIELD (word
, 19, 28) |
303 GET_FIELD (word
, 29, 29) << 10 |
304 GET_FIELD (word
, 11, 15) << 11 |
305 (word
& 0x1) << 16, 17) << 2;
308 /* Print one instruction. */
310 print_insn_hppa (memaddr
, info
)
312 disassemble_info
*info
;
315 unsigned int insn
, i
;
319 (*info
->read_memory_func
) (memaddr
, buffer
, sizeof (buffer
), info
);
322 (*info
->memory_error_func
) (status
, memaddr
, info
);
327 insn
= bfd_getb32 (buffer
);
329 for (i
= 0; i
< NUMOPCODES
; ++i
)
331 const struct pa_opcode
*opcode
= &pa_opcodes
[i
];
332 if ((insn
& opcode
->mask
) == opcode
->match
)
334 register const char *s
;
336 (*info
->fprintf_func
) (info
->stream
, "%s", opcode
->name
);
338 if (!strchr ("cfCY?-+nHNZFIu", opcode
->args
[0]))
339 (*info
->fprintf_func
) (info
->stream
, " ");
340 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
345 fput_reg (GET_FIELD (insn
, 11, 15), info
);
348 if (GET_FIELD (insn
, 25, 25))
349 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
351 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
355 fput_reg (GET_FIELD (insn
, 6, 10), info
);
358 fput_creg (GET_FIELD (insn
, 6, 10), info
);
361 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
364 fput_reg (GET_FIELD (insn
, 27, 31), info
);
367 if (GET_FIELD (insn
, 25, 25))
368 fput_fp_reg_r (GET_FIELD (insn
, 27, 31), info
);
370 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
373 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
377 int reg
= GET_FIELD (insn
, 6, 10);
379 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
380 fput_fp_reg (reg
, info
);
385 int reg
= GET_FIELD (insn
, 11, 15);
387 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
388 fput_fp_reg (reg
, info
);
393 int reg
= GET_FIELD (insn
, 27, 31);
395 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
396 fput_fp_reg (reg
, info
);
401 int reg
= GET_FIELD (insn
, 16, 20);
403 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
404 fput_fp_reg (reg
, info
);
409 int reg
= GET_FIELD (insn
, 21, 25);
411 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
412 fput_fp_reg (reg
, info
);
416 fput_const (extract_5_load (insn
), info
);
419 (*info
->fprintf_func
) (info
->stream
,
420 "sr%d", GET_FIELD (insn
, 16, 17));
424 (*info
->fprintf_func
) (info
->stream
, "sr%d", extract_3 (insn
));
427 /* Handle completers. */
432 (*info
->fprintf_func
) (info
->stream
, "%s ",
433 index_compl_names
[GET_COMPL (insn
)]);
436 (*info
->fprintf_func
) (info
->stream
, "%s ",
437 short_ldst_compl_names
[GET_COMPL (insn
)]);
440 (*info
->fprintf_func
) (info
->stream
, "%s ",
441 short_bytes_compl_names
[GET_COMPL (insn
)]);
444 if (GET_FIELD (insn
, 26, 26))
445 (*info
->fprintf_func
) (info
->stream
, ",m ");
447 (*info
->fprintf_func
) (info
->stream
, " ");
450 /* EXTRD/W has a following condition. */
452 (*info
->fprintf_func
)
453 (info
->stream
, "%s", signed_unsigned_names
[GET_FIELD
456 (*info
->fprintf_func
)
457 (info
->stream
, "%s ", signed_unsigned_names
[GET_FIELD
461 (*info
->fprintf_func
)
462 (info
->stream
, "%s", mix_half_names
[GET_FIELD
466 (*info
->fprintf_func
)
467 (info
->stream
, "%s", saturation_names
[GET_FIELD
471 (*info
->fprintf_func
)
472 (info
->stream
, ",%d%d%d%d ",
473 GET_FIELD (insn
, 17, 18), GET_FIELD (insn
, 20, 21),
474 GET_FIELD (insn
, 22, 23), GET_FIELD (insn
, 24, 25));
479 /* Handle conditions. */
486 (*info
->fprintf_func
) (info
->stream
, "%s ",
487 float_comp_names
[GET_FIELD
491 /* these four conditions are for the set of instructions
492 which distinguish true/false conditions by opcode
493 rather than by the 'f' bit (sigh): comb, comib,
496 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
501 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16, 18)
505 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)],
509 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)
513 fputs_filtered (cmpib_cond_64_names
[GET_FIELD (insn
, 16, 18)],
517 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
519 + GET_FIELD (insn
, 4, 4) * 8], info
);
522 fputs_filtered (add_cond_names
[GET_FIELD (insn
, 16, 18)
523 + GET_FIELD (insn
, 4, 4) * 8], info
);
526 (*info
->fprintf_func
) (info
->stream
, "%s ",
527 compare_cond_names
[GET_COND (insn
)]);
530 (*info
->fprintf_func
) (info
->stream
, "%s ",
531 compare_cond_64_names
[GET_COND (insn
)]);
534 (*info
->fprintf_func
) (info
->stream
, "%s ",
535 add_cond_names
[GET_COND (insn
)]);
538 (*info
->fprintf_func
) (info
->stream
, "%s ",
539 add_cond_64_names
[GET_COND (insn
)]);
542 (*info
->fprintf_func
) (info
->stream
, "%s",
543 add_cond_names
[GET_FIELD (insn
,
548 (*info
->fprintf_func
) (info
->stream
, "%s",
549 add_cond_names
[GET_FIELD (insn
,
554 (*info
->fprintf_func
)
556 wide_add_cond_names
[GET_FIELD (insn
, 16, 18)]);
560 (*info
->fprintf_func
)
562 wide_add_cond_names
[GET_FIELD (insn
, 16, 18) + 8]);
566 (*info
->fprintf_func
) (info
->stream
, "%s ",
567 logical_cond_names
[GET_COND (insn
)]);
570 (*info
->fprintf_func
) (info
->stream
, "%s ",
571 logical_cond_64_names
[GET_COND (insn
)]);
574 (*info
->fprintf_func
) (info
->stream
, "%s ",
575 unit_cond_names
[GET_COND (insn
)]);
578 (*info
->fprintf_func
) (info
->stream
, "%s ",
579 unit_cond_64_names
[GET_COND (insn
)]);
584 (*info
->fprintf_func
)
586 shift_cond_names
[GET_FIELD (insn
, 16, 18)]);
588 /* If the next character in args is 'n', it will handle
589 putting out the space. */
591 (*info
->fprintf_func
) (info
->stream
, " ");
594 (*info
->fprintf_func
) (info
->stream
, "%s",
595 shift_cond_64_names
[GET_FIELD (insn
, 16, 18)]);
598 (*info
->fprintf_func
)
600 bb_cond_64_names
[GET_FIELD (insn
, 16, 16)]);
602 /* If the next character in args is 'n', it will handle
603 putting out the space. */
605 (*info
->fprintf_func
) (info
->stream
, " ");
612 fput_const (extract_5_store (insn
), info
);
615 fput_const (extract_5r_store (insn
), info
);
618 fput_const (extract_5R_store (insn
), info
);
621 fput_const (extract_5Q_store (insn
), info
);
624 fput_const (extract_11 (insn
), info
);
627 fput_const (extract_14 (insn
), info
);
630 fput_const (extract_21 (insn
), info
);
634 (*info
->fprintf_func
) (info
->stream
, ",n ");
636 (*info
->fprintf_func
) (info
->stream
, " ");
639 if ((insn
& 0x20) && s
[1])
640 (*info
->fprintf_func
) (info
->stream
, ",n ");
641 else if (insn
& 0x20)
642 (*info
->fprintf_func
) (info
->stream
, ",n");
644 (*info
->fprintf_func
) (info
->stream
, " ");
647 (*info
->print_address_func
) (memaddr
+ 8 + extract_12 (insn
),
651 /* 17 bit PC-relative branch. */
652 (*info
->print_address_func
) ((memaddr
+ 8
653 + extract_17 (insn
)),
657 /* 17 bit displacement. This is an offset from a register
658 so it gets disasssembled as just a number, not any sort
660 fput_const (extract_17 (insn
), info
);
663 (*info
->fprintf_func
) (info
->stream
, "%d",
664 GET_FIELD (insn
, 24, 25));
667 (*info
->fprintf_func
) (info
->stream
, "%sar");
670 (*info
->fprintf_func
) (info
->stream
, "%d",
671 31 - GET_FIELD (insn
, 22, 26));
676 num
= GET_FIELD (insn
, 20, 20) << 5;
677 num
|= GET_FIELD (insn
, 22, 26);
678 (*info
->fprintf_func
) (info
->stream
, "%d", 63 - num
);
682 (*info
->fprintf_func
) (info
->stream
, "%d",
683 GET_FIELD (insn
, 22, 26));
686 (*info
->fprintf_func
) (info
->stream
, "%d",
687 32 - GET_FIELD (insn
, 27, 31));
690 fput_const (GET_FIELD (insn
, 20, 28), info
);
693 fput_const (GET_FIELD (insn
, 6, 18), info
);
696 fput_const (GET_FIELD (insn
, 6, 31), info
);
699 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
702 fput_const ((GET_FIELD (insn
, 6,20) << 5 |
703 GET_FIELD (insn
, 27, 31)), info
);
706 fput_const (GET_FIELD (insn
, 6, 20), info
);
710 int reg
= GET_FIELD (insn
, 21, 22);
711 reg
|= GET_FIELD (insn
, 16, 18) << 2;
712 if (GET_FIELD (insn
, 23, 23) != 0)
713 fput_fp_reg_r (reg
, info
);
715 fput_fp_reg (reg
, info
);
720 fput_const ((GET_FIELD (insn
, 6, 22) << 5 |
721 GET_FIELD (insn
, 27, 31)), info
);
724 fput_const ((GET_FIELD (insn
, 11, 20) << 5 |
725 GET_FIELD (insn
, 27, 31)), info
);
728 fput_const ((GET_FIELD (insn
, 16, 20) << 5 |
729 GET_FIELD (insn
, 27, 31)), info
);
732 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
735 /* if no destination completer and not before a completer
736 for fcmp, need a space here */
737 if (s
[1] == 'G' || s
[1] == '?')
738 fputs_filtered (float_format_names
[GET_FIELD (insn
, 19, 20)],
741 (*info
->fprintf_func
) (info
->stream
, "%s ",
742 float_format_names
[GET_FIELD
746 (*info
->fprintf_func
) (info
->stream
, "%s ",
747 float_format_names
[GET_FIELD (insn
,
751 if (GET_FIELD (insn
, 26, 26) == 1)
752 (*info
->fprintf_func
) (info
->stream
, "%s ",
753 float_format_names
[0]);
755 (*info
->fprintf_func
) (info
->stream
, "%s ",
756 float_format_names
[1]);
759 /* if no destination completer and not before a completer
760 for fcmp, need a space here */
762 fputs_filtered (float_format_names
[GET_FIELD (insn
, 20, 20)],
765 (*info
->fprintf_func
) (info
->stream
, "%s ",
766 float_format_names
[GET_FIELD
770 if (GET_FIELD (insn
, 24, 24))
771 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
773 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
777 if (GET_FIELD (insn
, 19, 19))
778 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
780 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
783 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
790 (*info
->fprintf_func
) (info
->stream
, "#%8x", insn
);