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 /* Handle completers. */
427 (*info
->fprintf_func
) (info
->stream
, "%s ",
428 index_compl_names
[GET_COMPL (insn
)]);
431 (*info
->fprintf_func
) (info
->stream
, "%s ",
432 short_ldst_compl_names
[GET_COMPL (insn
)]);
435 (*info
->fprintf_func
) (info
->stream
, "%s ",
436 short_bytes_compl_names
[GET_COMPL (insn
)]);
439 if (GET_FIELD (insn
, 26, 26))
440 (*info
->fprintf_func
) (info
->stream
, ",m ");
442 (*info
->fprintf_func
) (info
->stream
, " ");
447 /* Handle conditions. */
454 (*info
->fprintf_func
) (info
->stream
, "%s ",
455 float_comp_names
[GET_FIELD
459 /* these four conditions are for the set of instructions
460 which distinguish true/false conditions by opcode
461 rather than by the 'f' bit (sigh): comb, comib,
464 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
469 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16, 18)
473 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)],
477 fputs_filtered (compare_cond_64_names
[GET_FIELD (insn
, 16, 18)
481 fputs_filtered (cmpib_cond_64_names
[GET_FIELD (insn
, 16, 18)],
485 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
487 + GET_FIELD (insn
, 4, 4) * 8], info
);
490 fputs_filtered (add_cond_names
[GET_FIELD (insn
, 16, 18)
491 + GET_FIELD (insn
, 4, 4) * 8], info
);
494 (*info
->fprintf_func
) (info
->stream
, "%s ",
495 compare_cond_names
[GET_COND (insn
)]);
498 (*info
->fprintf_func
) (info
->stream
, "%s ",
499 compare_cond_64_names
[GET_COND (insn
)]);
502 (*info
->fprintf_func
) (info
->stream
, "%s ",
503 add_cond_names
[GET_COND (insn
)]);
506 (*info
->fprintf_func
) (info
->stream
, "%s ",
507 add_cond_64_names
[GET_COND (insn
)]);
510 (*info
->fprintf_func
) (info
->stream
, "%s",
511 add_cond_names
[GET_FIELD (insn
,
516 (*info
->fprintf_func
) (info
->stream
, "%s",
517 add_cond_names
[GET_FIELD (insn
,
522 (*info
->fprintf_func
)
524 wide_add_cond_names
[GET_FIELD (insn
, 16, 18)]);
528 (*info
->fprintf_func
)
530 wide_add_cond_names
[GET_FIELD (insn
, 16, 18) + 8]);
534 (*info
->fprintf_func
) (info
->stream
, "%s ",
535 logical_cond_names
[GET_COND (insn
)]);
538 (*info
->fprintf_func
) (info
->stream
, "%s ",
539 logical_cond_64_names
[GET_COND (insn
)]);
542 (*info
->fprintf_func
) (info
->stream
, "%s ",
543 unit_cond_names
[GET_COND (insn
)]);
546 (*info
->fprintf_func
) (info
->stream
, "%s ",
547 unit_cond_64_names
[GET_COND (insn
)]);
552 (*info
->fprintf_func
)
554 shift_cond_names
[GET_FIELD (insn
, 16, 18)]);
556 /* If the next character in args is 'n', it will handle
557 putting out the space. */
559 (*info
->fprintf_func
) (info
->stream
, " ");
562 (*info
->fprintf_func
) (info
->stream
, "%s",
563 shift_cond_64_names
[GET_FIELD (insn
, 16, 18)]);
566 (*info
->fprintf_func
)
568 bb_cond_64_names
[GET_FIELD (insn
, 16, 16)]);
570 /* If the next character in args is 'n', it will handle
571 putting out the space. */
573 (*info
->fprintf_func
) (info
->stream
, " ");
580 fput_const (extract_5_store (insn
), info
);
583 fput_const (extract_5r_store (insn
), info
);
586 fput_const (extract_5R_store (insn
), info
);
589 fput_const (extract_5Q_store (insn
), info
);
592 fput_const (extract_11 (insn
), info
);
595 fput_const (extract_14 (insn
), info
);
598 fput_const (extract_21 (insn
), info
);
602 (*info
->fprintf_func
) (info
->stream
, ",n ");
604 (*info
->fprintf_func
) (info
->stream
, " ");
607 if ((insn
& 0x20) && s
[1])
608 (*info
->fprintf_func
) (info
->stream
, ",n ");
609 else if (insn
& 0x20)
610 (*info
->fprintf_func
) (info
->stream
, ",n");
612 (*info
->fprintf_func
) (info
->stream
, " ");
615 (*info
->print_address_func
) (memaddr
+ 8 + extract_12 (insn
),
619 /* 17 bit PC-relative branch. */
620 (*info
->print_address_func
) ((memaddr
+ 8
621 + extract_17 (insn
)),
625 /* 17 bit displacement. This is an offset from a register
626 so it gets disasssembled as just a number, not any sort
628 fput_const (extract_17 (insn
), info
);
631 (*info
->fprintf_func
) (info
->stream
, "%d",
632 GET_FIELD (insn
, 24, 25));
635 (*info
->fprintf_func
) (info
->stream
, "%sar");
638 (*info
->fprintf_func
) (info
->stream
, "%d",
639 31 - GET_FIELD (insn
, 22, 26));
644 num
= GET_FIELD (insn
, 20, 20) << 5;
645 num
|= GET_FIELD (insn
, 22, 26);
646 (*info
->fprintf_func
) (info
->stream
, "%d", 63 - num
);
650 (*info
->fprintf_func
) (info
->stream
, "%d",
651 GET_FIELD (insn
, 22, 26));
654 (*info
->fprintf_func
) (info
->stream
, "%d",
655 32 - GET_FIELD (insn
, 27, 31));
658 fput_const (GET_FIELD (insn
, 20, 28), info
);
661 fput_const (GET_FIELD (insn
, 6, 18), info
);
664 fput_const (GET_FIELD (insn
, 6, 31), info
);
667 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
670 fput_const ((GET_FIELD (insn
, 6,20) << 5 |
671 GET_FIELD (insn
, 27, 31)), info
);
674 fput_const (GET_FIELD (insn
, 6, 20), info
);
678 int reg
= GET_FIELD (insn
, 21, 22);
679 reg
|= GET_FIELD (insn
, 16, 18) << 2;
680 if (GET_FIELD (insn
, 23, 23) != 0)
681 fput_fp_reg_r (reg
, info
);
683 fput_fp_reg (reg
, info
);
688 fput_const ((GET_FIELD (insn
, 6, 22) << 5 |
689 GET_FIELD (insn
, 27, 31)), info
);
692 fput_const ((GET_FIELD (insn
, 11, 20) << 5 |
693 GET_FIELD (insn
, 27, 31)), info
);
696 fput_const ((GET_FIELD (insn
, 16, 20) << 5 |
697 GET_FIELD (insn
, 27, 31)), info
);
700 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
703 /* if no destination completer and not before a completer
704 for fcmp, need a space here */
705 if (s
[1] == 'G' || s
[1] == '?')
706 fputs_filtered (float_format_names
[GET_FIELD (insn
, 19, 20)],
709 (*info
->fprintf_func
) (info
->stream
, "%s ",
710 float_format_names
[GET_FIELD
714 (*info
->fprintf_func
) (info
->stream
, "%s ",
715 float_format_names
[GET_FIELD (insn
,
719 if (GET_FIELD (insn
, 26, 26) == 1)
720 (*info
->fprintf_func
) (info
->stream
, "%s ",
721 float_format_names
[0]);
723 (*info
->fprintf_func
) (info
->stream
, "%s ",
724 float_format_names
[1]);
727 /* if no destination completer and not before a completer
728 for fcmp, need a space here */
730 fputs_filtered (float_format_names
[GET_FIELD (insn
, 20, 20)],
733 (*info
->fprintf_func
) (info
->stream
, "%s ",
734 float_format_names
[GET_FIELD
738 if (GET_FIELD (insn
, 24, 24))
739 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
741 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
745 if (GET_FIELD (insn
, 19, 19))
746 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
748 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
751 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
758 (*info
->fprintf_func
) (info
->stream
, "#%8x", insn
);
This page took 0.101475 seconds and 5 git commands to generate.