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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "opcode/hppa.h"
26 /* Integer register names, indexed by the numbers which appear in the
28 static const char *const reg_names
[] =
29 {"flags", "r1", "rp", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
30 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
31 "r20", "r21", "r22", "arg3", "arg2", "arg1", "arg0", "dp", "ret0", "ret1",
34 /* Floating point register names, indexed by the numbers which appear in the
36 static const char *const fp_reg_names
[] =
37 {"fpsr", "fpe2", "fpe4", "fpe6",
38 "fr4", "fr5", "fr6", "fr7", "fr8",
39 "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
40 "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23",
41 "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31"};
43 typedef unsigned int CORE_ADDR
;
45 /* Get at various relevent fields of an instruction word. */
49 #define MASK_14 0x3fff
50 #define MASK_21 0x1fffff
52 /* This macro gets bit fields using HP's numbering (MSB = 0) */
54 #define GET_FIELD(X, FROM, TO) \
55 ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
57 /* Some of these have been converted to 2-d arrays because they
58 consume less storage this way. If the maintenance becomes a
59 problem, convert them back to const 1-d pointer arrays. */
60 static const char control_reg
[][6] = {
61 "rctr", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
62 "pidr1", "pidr2", "ccr", "sar", "pidr3", "pidr4",
63 "iva", "eiem", "itmr", "pcsq", "pcoq", "iir", "isr",
64 "ior", "ipsw", "eirr", "tr0", "tr1", "tr2", "tr3",
65 "tr4", "tr5", "tr6", "tr7"
68 static const char compare_cond_names
[][5] = {
69 "", ",=", ",<", ",<=", ",<<", ",<<=", ",sv",
70 ",od", ",tr", ",<>", ",>=", ",>", ",>>=",
73 static const char add_cond_names
[][5] = {
74 "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv",
75 ",od", ",tr", ",<>", ",>=", ",>", ",uv",
78 static const char *const logical_cond_names
[] = {
79 "", ",=", ",<", ",<=", 0, 0, 0, ",od",
80 ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};
81 static const char *const unit_cond_names
[] = {
82 "", 0, ",sbz", ",shz", ",sdc", 0, ",sbc", ",shc",
83 ",tr", 0, ",nbz", ",nhz", ",ndc", 0, ",nbc", ",nhc"
85 static const char shift_cond_names
[][4] = {
86 "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"
88 static const char index_compl_names
[][4] = {"", ",m", ",s", ",sm"};
89 static const char short_ldst_compl_names
[][4] = {"", ",ma", "", ",mb"};
90 static const char *const short_bytes_compl_names
[] = {
91 "", ",b,m", ",e", ",e,m"
93 static const char *const float_format_names
[] = {",sgl", ",dbl", "", ",quad"};
94 static const char float_comp_names
[][8] =
96 ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",
97 ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",
98 ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",
99 ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"
102 /* For a bunch of different instructions form an index into a
103 completer name table. */
104 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
105 GET_FIELD (insn, 18, 18) << 1)
107 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
108 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
110 /* Utility function to print registers. Put these first, so gcc's function
111 inlining can do its stuff. */
113 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
118 disassemble_info
*info
;
120 (*info
->fprintf_func
) (info
->stream
, reg
? reg_names
[reg
] : "r0");
124 fput_fp_reg (reg
, info
)
126 disassemble_info
*info
;
128 (*info
->fprintf_func
) (info
->stream
, reg
? fp_reg_names
[reg
] : "fr0");
132 fput_fp_reg_r (reg
, info
)
134 disassemble_info
*info
;
136 /* Special case floating point exception registers. */
138 (*info
->fprintf_func
) (info
->stream
, "fpe%d", reg
* 2 + 1);
140 (*info
->fprintf_func
) (info
->stream
, "%sR", reg
? fp_reg_names
[reg
]
145 fput_creg (reg
, info
)
147 disassemble_info
*info
;
149 (*info
->fprintf_func
) (info
->stream
, control_reg
[reg
]);
152 /* print constants with sign */
155 fput_const (num
, info
)
157 disassemble_info
*info
;
160 (*info
->fprintf_func
) (info
->stream
, "-%x", -(int)num
);
162 (*info
->fprintf_func
) (info
->stream
, "%x", num
);
165 /* Routines to extract various sized constants out of hppa
168 /* This assumes that no garbage lies outside of the lower bits of
172 sign_extend (val
, bits
)
175 return (int)(val
>> (bits
- 1) ? (-1 << bits
) | val
: val
);
178 /* For many immediate values the sign bit is the low bit! */
181 low_sign_extend (val
, bits
)
184 return (int)((val
& 0x1 ? (-1 << (bits
- 1)) : 0) | val
>> 1);
186 /* extract the immediate field from a ld{bhw}s instruction */
190 get_field (val
, from
, to
)
191 unsigned val
, from
, to
;
193 val
= val
>> (31 - to
);
194 return val
& ((1 << (32 - from
)) - 1);
198 set_field (val
, from
, to
, new_val
)
199 unsigned *val
, from
, to
, new_val
;
201 unsigned mask
= ~((1 << (to
- from
+ 1)) << (31 - from
));
202 return *val
= (*val
& mask
) | (new_val
<< (31 - from
));
206 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
211 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
215 extract_5_load (word
)
218 return low_sign_extend (word
>> 16 & MASK_5
, 5);
221 /* extract the immediate field from a st{bhw}s instruction */
223 extract_5_store (word
)
226 return low_sign_extend (word
& MASK_5
, 5);
229 /* extract the immediate field from a break instruction */
231 extract_5r_store (word
)
234 return (word
& MASK_5
);
237 /* extract the immediate field from a {sr}sm instruction */
239 extract_5R_store (word
)
242 return (word
>> 16 & MASK_5
);
245 /* extract the immediate field from a bb instruction */
247 extract_5Q_store (word
)
250 return (word
>> 21 & MASK_5
);
253 /* extract an 11 bit immediate field */
258 return low_sign_extend (word
& MASK_11
, 11);
261 /* extract a 14 bit immediate field */
266 return low_sign_extend (word
& MASK_14
, 14);
270 /* deposit a 14 bit constant in a word */
272 deposit_14 (opnd
, word
)
276 unsigned sign
= (opnd
< 0 ? 1 : 0);
278 return word
| ((unsigned)opnd
<< 1 & MASK_14
) | sign
;
282 /* extract a 21 bit constant */
292 val
= GET_FIELD (word
, 20, 20);
294 val
|= GET_FIELD (word
, 9, 19);
296 val
|= GET_FIELD (word
, 5, 6);
298 val
|= GET_FIELD (word
, 0, 4);
300 val
|= GET_FIELD (word
, 7, 8);
301 return sign_extend (val
, 21) << 11;
305 /* deposit a 21 bit constant in a word. Although 21 bit constants are
306 usually the top 21 bits of a 32 bit constant, we assume that only
307 the low 21 bits of opnd are relevant */
310 deposit_21 (opnd
, word
)
315 val
|= GET_FIELD (opnd
, 11 + 14, 11 + 18);
317 val
|= GET_FIELD (opnd
, 11 + 12, 11 + 13);
319 val
|= GET_FIELD (opnd
, 11 + 19, 11 + 20);
321 val
|= GET_FIELD (opnd
, 11 + 1, 11 + 11);
323 val
|= GET_FIELD (opnd
, 11 + 0, 11 + 0);
328 /* extract a 12 bit constant from branch instructions */
334 return sign_extend (GET_FIELD (word
, 19, 28) |
335 GET_FIELD (word
, 29, 29) << 10 |
336 (word
& 0x1) << 11, 12) << 2;
339 /* extract a 17 bit constant from branch instructions, returning the
340 19 bit signed value. */
346 return sign_extend (GET_FIELD (word
, 19, 28) |
347 GET_FIELD (word
, 29, 29) << 10 |
348 GET_FIELD (word
, 11, 15) << 11 |
349 (word
& 0x1) << 16, 17) << 2;
352 /* Print one instruction. */
354 print_insn_hppa (memaddr
, info
)
356 disassemble_info
*info
;
358 unsigned int insn
, i
, op
;
362 (*info
->read_memory_func
) (memaddr
, (bfd_byte
*) &insn
, sizeof (insn
),
366 (*info
->memory_error_func
) (status
, memaddr
, info
);
371 for (i
= 0; i
< NUMOPCODES
; ++i
)
373 const struct pa_opcode
*opcode
= &pa_opcodes
[i
];
374 if ((insn
& opcode
->mask
) == opcode
->match
)
376 register const char *s
;
378 (*info
->fprintf_func
) (info
->stream
, "%s", opcode
->name
);
380 if (!strchr ("cfCY<?!@-+&U>~nHNZFIMadu|", opcode
->args
[0]))
381 (*info
->fprintf_func
) (info
->stream
, " ");
382 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
387 fput_reg (GET_FIELD (insn
, 11, 15), info
);
390 if (GET_FIELD (insn
, 25, 25))
391 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
393 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
396 fput_reg (GET_FIELD (insn
, 6, 10), info
);
399 fput_creg (GET_FIELD (insn
, 6, 10), info
);
402 if (GET_FIELD (insn
, 25, 25))
403 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
405 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
408 fput_reg (GET_FIELD (insn
, 27, 31), info
);
411 if (GET_FIELD (insn
, 25, 25))
412 fput_fp_reg_r (GET_FIELD (insn
, 27, 31), info
);
414 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
417 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
421 int reg
= GET_FIELD (insn
, 6, 10);
423 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
424 fput_fp_reg (reg
, info
);
429 int reg
= GET_FIELD (insn
, 11, 15);
431 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
432 fput_fp_reg (reg
, info
);
437 int reg
= GET_FIELD (insn
, 27, 31);
439 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
440 fput_fp_reg (reg
, info
);
445 int reg
= GET_FIELD (insn
, 16, 20);
447 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
448 fput_fp_reg (reg
, info
);
453 int reg
= GET_FIELD (insn
, 21, 25);
455 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
456 fput_fp_reg (reg
, info
);
460 fput_const (extract_5_load (insn
), info
);
463 (*info
->fprintf_func
) (info
->stream
,
464 "sr%d", GET_FIELD (insn
, 16, 17));
467 (*info
->fprintf_func
) (info
->stream
, "sr%d", extract_3 (insn
));
470 (*info
->fprintf_func
) (info
->stream
, "%s ",
471 index_compl_names
[GET_COMPL (insn
)]);
474 (*info
->fprintf_func
) (info
->stream
, "%s ",
475 short_ldst_compl_names
[GET_COMPL (insn
)]);
478 (*info
->fprintf_func
) (info
->stream
, "%s ",
479 short_bytes_compl_names
[GET_COMPL (insn
)]);
481 /* these four conditions are for the set of instructions
482 which distinguish true/false conditions by opcode rather
483 than by the 'f' bit (sigh): comb, comib, addb, addib */
485 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16, 18)],
489 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16, 18) + 8],
493 fputs_filtered (add_cond_names
[GET_FIELD (insn
, 16, 18) + 8],
497 (*info
->fprintf_func
) (info
->stream
, "%s ",
498 compare_cond_names
[GET_COND (insn
)]);
501 (*info
->fprintf_func
) (info
->stream
, "%s ",
502 add_cond_names
[GET_COND (insn
)]);
505 (*info
->fprintf_func
) (info
->stream
, "%s",
506 add_cond_names
[GET_FIELD (insn
, 16, 18)]);
510 (*info
->fprintf_func
) (info
->stream
, "%s ",
511 logical_cond_names
[GET_COND (insn
)]);
514 (*info
->fprintf_func
) (info
->stream
, "%s ",
515 unit_cond_names
[GET_COND (insn
)]);
520 (*info
->fprintf_func
)
522 shift_cond_names
[GET_FIELD (insn
, 16, 18)]);
524 /* If the next character in args is 'n', it will handle
525 putting out the space. */
527 (*info
->fprintf_func
) (info
->stream
, " ");
530 fput_const (extract_5_store (insn
), info
);
533 fput_const (extract_5r_store (insn
), info
);
536 fput_const (extract_5R_store (insn
), info
);
539 fput_const (extract_5Q_store (insn
), info
);
542 fput_const (extract_11 (insn
), info
);
545 fput_const (extract_14 (insn
), info
);
548 fput_const (extract_21 (insn
), info
);
552 (*info
->fprintf_func
) (info
->stream
, ",n ");
554 (*info
->fprintf_func
) (info
->stream
, " ");
557 if ((insn
& 0x20) && s
[1])
558 (*info
->fprintf_func
) (info
->stream
, ",n ");
559 else if (insn
& 0x20)
560 (*info
->fprintf_func
) (info
->stream
, ",n");
562 (*info
->fprintf_func
) (info
->stream
, " ");
565 (*info
->print_address_func
) (memaddr
+ 8 + extract_12 (insn
),
569 /* 17 bit PC-relative branch. */
570 (*info
->print_address_func
) ((memaddr
+ 8
571 + extract_17 (insn
)),
575 /* 17 bit displacement. This is an offset from a register
576 so it gets disasssembled as just a number, not any sort
578 fput_const (extract_17 (insn
), info
);
581 (*info
->fprintf_func
) (info
->stream
, "%d",
582 31 - GET_FIELD (insn
, 22, 26));
585 (*info
->fprintf_func
) (info
->stream
, "%d",
586 GET_FIELD (insn
, 22, 26));
589 (*info
->fprintf_func
) (info
->stream
, "%d",
590 32 - GET_FIELD (insn
, 27, 31));
593 fput_const (GET_FIELD (insn
, 6, 18), info
);
596 if (GET_FIELD (insn
, 26, 26))
597 (*info
->fprintf_func
) (info
->stream
, ",m ");
599 (*info
->fprintf_func
) (info
->stream
, " ");
602 fput_const (GET_FIELD (insn
, 6, 31), info
);
605 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
608 fput_const ((GET_FIELD (insn
, 6,20) << 5 |
609 GET_FIELD (insn
, 27, 31)), info
);
612 fput_const (GET_FIELD (insn
, 6, 20), info
);
615 fput_const ((GET_FIELD (insn
, 6, 22) << 5 |
616 GET_FIELD (insn
, 27, 31)), info
);
619 fput_const ((GET_FIELD (insn
, 11, 20) << 5 |
620 GET_FIELD (insn
, 27, 31)), info
);
623 fput_const ((GET_FIELD (insn
, 16, 20) << 5 |
624 GET_FIELD (insn
, 27, 31)), info
);
627 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
630 /* if no destination completer and not before a completer
631 for fcmp, need a space here */
632 if (GET_FIELD (insn
, 21, 22) == 1 || s
[1] == 'M')
633 fputs_filtered (float_format_names
[GET_FIELD (insn
, 19, 20)],
636 (*info
->fprintf_func
) (info
->stream
, "%s ",
637 float_format_names
[GET_FIELD
641 (*info
->fprintf_func
) (info
->stream
, "%s ",
642 float_format_names
[GET_FIELD (insn
,
646 if (GET_FIELD (insn
, 26, 26) == 1)
647 (*info
->fprintf_func
) (info
->stream
, "%s ",
648 float_format_names
[0]);
650 (*info
->fprintf_func
) (info
->stream
, "%s ",
651 float_format_names
[1]);
654 /* if no destination completer and not before a completer
655 for fcmp, need a space here */
656 if (GET_FIELD (insn
, 21, 22) == 1 || s
[1] == 'M')
657 fputs_filtered (float_format_names
[GET_FIELD (insn
, 20, 20)],
660 (*info
->fprintf_func
) (info
->stream
, "%s ",
661 float_format_names
[GET_FIELD
665 if (GET_FIELD (insn
, 24, 24))
666 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
668 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
672 if (GET_FIELD (insn
, 19, 19))
673 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
675 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
678 (*info
->fprintf_func
) (info
->stream
, "%s ",
679 float_comp_names
[GET_FIELD
683 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
690 (*info
->fprintf_func
) (info
->stream
, "#%8x", insn
);
This page took 0.043994 seconds and 4 git commands to generate.