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",
71 ",od", ",tr", ",<>", ",>=", ",>", ",>>=",
74 static const char add_cond_names
[][5] = {
75 "", ",=", ",<", ",<=", ",nuv", ",znv", ",sv",
76 ",od", ",tr", ",<>", ",>=", ",>", ",uv",
79 static const char *const logical_cond_names
[] = {
80 "", ",=", ",<", ",<=", 0, 0, 0, ",od",
81 ",tr", ",<>", ",>=", ",>", 0, 0, 0, ",ev"};
82 static const char *const unit_cond_names
[] = {
83 "", 0, ",sbz", ",shz", ",sdc", 0, ",sbc", ",shc",
84 ",tr", 0, ",nbz", ",nhz", ",ndc", 0, ",nbc", ",nhc"
86 static const char shift_cond_names
[][4] = {
87 "", ",=", ",<", ",od", ",tr", ",<>", ",>=", ",ev"
89 static const char index_compl_names
[][4] = {"", ",m", ",s", ",sm"};
90 static const char short_ldst_compl_names
[][4] = {"", ",ma", "", ",mb"};
91 static const char *const short_bytes_compl_names
[] = {
92 "", ",b,m", ",e", ",e,m"
94 static const char *const float_format_names
[] = {",sgl", ",dbl", "", ",quad"};
95 static const char float_comp_names
[][8] =
97 ",false?", ",false", ",?", ",!<=>", ",=", ",=t", ",?=", ",!<>",
98 ",!?>=", ",<", ",?<", ",!>=", ",!?>", ",<=", ",?<=", ",!>",
99 ",!?<=", ",>", ",?>", ",!<=", ",!?<", ",>=", ",?>=", ",!<",
100 ",!?=", ",<>", ",!=", ",!=t", ",!?", ",<=>", ",true?", ",true"
103 /* For a bunch of different instructions form an index into a
104 completer name table. */
105 #define GET_COMPL(insn) (GET_FIELD (insn, 26, 26) | \
106 GET_FIELD (insn, 18, 18) << 1)
108 #define GET_COND(insn) (GET_FIELD ((insn), 16, 18) + \
109 (GET_FIELD ((insn), 19, 19) ? 8 : 0))
111 /* Utility function to print registers. Put these first, so gcc's function
112 inlining can do its stuff. */
114 #define fputs_filtered(STR,F) (*info->fprintf_func) (info->stream, "%s", STR)
119 disassemble_info
*info
;
121 (*info
->fprintf_func
) (info
->stream
, reg
? reg_names
[reg
] : "r0");
125 fput_fp_reg (reg
, info
)
127 disassemble_info
*info
;
129 (*info
->fprintf_func
) (info
->stream
, reg
? fp_reg_names
[reg
] : "fr0");
133 fput_fp_reg_r (reg
, info
)
135 disassemble_info
*info
;
137 /* Special case floating point exception registers. */
139 (*info
->fprintf_func
) (info
->stream
, "fpe%d", reg
* 2 + 1);
141 (*info
->fprintf_func
) (info
->stream
, "%sR", reg
? fp_reg_names
[reg
]
146 fput_creg (reg
, info
)
148 disassemble_info
*info
;
150 (*info
->fprintf_func
) (info
->stream
, control_reg
[reg
]);
153 /* print constants with sign */
156 fput_const (num
, info
)
158 disassemble_info
*info
;
161 (*info
->fprintf_func
) (info
->stream
, "-%x", -(int)num
);
163 (*info
->fprintf_func
) (info
->stream
, "%x", num
);
166 /* Routines to extract various sized constants out of hppa
169 /* extract a 3-bit space register number from a be, ble, mtsp or mfsp */
174 return GET_FIELD (word
, 18, 18) << 2 | GET_FIELD (word
, 16, 17);
178 extract_5_load (word
)
181 return low_sign_extend (word
>> 16 & MASK_5
, 5);
184 /* extract the immediate field from a st{bhw}s instruction */
186 extract_5_store (word
)
189 return low_sign_extend (word
& MASK_5
, 5);
192 /* extract the immediate field from a break instruction */
194 extract_5r_store (word
)
197 return (word
& MASK_5
);
200 /* extract the immediate field from a {sr}sm instruction */
202 extract_5R_store (word
)
205 return (word
>> 16 & MASK_5
);
208 /* extract the immediate field from a bb instruction */
210 extract_5Q_store (word
)
213 return (word
>> 21 & MASK_5
);
216 /* extract an 11 bit immediate field */
221 return low_sign_extend (word
& MASK_11
, 11);
224 /* extract a 14 bit immediate field */
229 return low_sign_extend (word
& MASK_14
, 14);
232 /* extract a 21 bit constant */
242 val
= GET_FIELD (word
, 20, 20);
244 val
|= GET_FIELD (word
, 9, 19);
246 val
|= GET_FIELD (word
, 5, 6);
248 val
|= GET_FIELD (word
, 0, 4);
250 val
|= GET_FIELD (word
, 7, 8);
251 return sign_extend (val
, 21) << 11;
254 /* extract a 12 bit constant from branch instructions */
260 return sign_extend (GET_FIELD (word
, 19, 28) |
261 GET_FIELD (word
, 29, 29) << 10 |
262 (word
& 0x1) << 11, 12) << 2;
265 /* extract a 17 bit constant from branch instructions, returning the
266 19 bit signed value. */
272 return sign_extend (GET_FIELD (word
, 19, 28) |
273 GET_FIELD (word
, 29, 29) << 10 |
274 GET_FIELD (word
, 11, 15) << 11 |
275 (word
& 0x1) << 16, 17) << 2;
278 /* Print one instruction. */
280 print_insn_hppa (memaddr
, info
)
282 disassemble_info
*info
;
285 unsigned int insn
, i
;
289 (*info
->read_memory_func
) (memaddr
, buffer
, sizeof (buffer
), info
);
292 (*info
->memory_error_func
) (status
, memaddr
, info
);
297 insn
= bfd_getb32 (buffer
);
299 for (i
= 0; i
< NUMOPCODES
; ++i
)
301 const struct pa_opcode
*opcode
= &pa_opcodes
[i
];
302 if ((insn
& opcode
->mask
) == opcode
->match
)
304 register const char *s
;
306 (*info
->fprintf_func
) (info
->stream
, "%s", opcode
->name
);
308 if (!strchr ("cfCY?-+nHNZFIu", opcode
->args
[0]))
309 (*info
->fprintf_func
) (info
->stream
, " ");
310 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
315 fput_reg (GET_FIELD (insn
, 11, 15), info
);
318 if (GET_FIELD (insn
, 25, 25))
319 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
321 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
324 fput_reg (GET_FIELD (insn
, 6, 10), info
);
327 fput_creg (GET_FIELD (insn
, 6, 10), info
);
330 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
333 fput_reg (GET_FIELD (insn
, 27, 31), info
);
336 if (GET_FIELD (insn
, 25, 25))
337 fput_fp_reg_r (GET_FIELD (insn
, 27, 31), info
);
339 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
342 fput_fp_reg (GET_FIELD (insn
, 27, 31), info
);
346 int reg
= GET_FIELD (insn
, 6, 10);
348 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
349 fput_fp_reg (reg
, info
);
354 int reg
= GET_FIELD (insn
, 11, 15);
356 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
357 fput_fp_reg (reg
, info
);
362 int reg
= GET_FIELD (insn
, 27, 31);
364 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
365 fput_fp_reg (reg
, info
);
370 int reg
= GET_FIELD (insn
, 16, 20);
372 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
373 fput_fp_reg (reg
, info
);
378 int reg
= GET_FIELD (insn
, 21, 25);
380 reg
|= (GET_FIELD (insn
, 26, 26) << 4);
381 fput_fp_reg (reg
, info
);
385 fput_const (extract_5_load (insn
), info
);
388 (*info
->fprintf_func
) (info
->stream
,
389 "sr%d", GET_FIELD (insn
, 16, 17));
392 (*info
->fprintf_func
) (info
->stream
, "sr%d", extract_3 (insn
));
395 (*info
->fprintf_func
) (info
->stream
, "%s ",
396 index_compl_names
[GET_COMPL (insn
)]);
399 (*info
->fprintf_func
) (info
->stream
, "%s ",
400 short_ldst_compl_names
[GET_COMPL (insn
)]);
403 (*info
->fprintf_func
) (info
->stream
, "%s ",
404 short_bytes_compl_names
[GET_COMPL (insn
)]);
407 /* Handle conditions. */
414 (*info
->fprintf_func
) (info
->stream
, "%s ",
415 float_comp_names
[GET_FIELD
419 /* these four conditions are for the set of instructions
420 which distinguish true/false conditions by opcode
421 rather than by the 'f' bit (sigh): comb, comib,
424 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
429 fputs_filtered (compare_cond_names
[GET_FIELD (insn
, 16,
431 + GET_FIELD (insn
, 4, 4) * 8], info
);
434 fputs_filtered (add_cond_names
[GET_FIELD (insn
, 16, 18)
435 + GET_FIELD (insn
, 4, 4) * 8], info
);
438 (*info
->fprintf_func
) (info
->stream
, "%s ",
439 compare_cond_names
[GET_COND (insn
)]);
442 (*info
->fprintf_func
) (info
->stream
, "%s ",
443 add_cond_names
[GET_COND (insn
)]);
446 (*info
->fprintf_func
) (info
->stream
, "%s",
447 add_cond_names
[GET_FIELD (insn
,
453 (*info
->fprintf_func
) (info
->stream
, "%s ",
454 logical_cond_names
[GET_COND (insn
)]);
457 (*info
->fprintf_func
) (info
->stream
, "%s ",
458 unit_cond_names
[GET_COND (insn
)]);
463 (*info
->fprintf_func
)
465 shift_cond_names
[GET_FIELD (insn
, 16, 18)]);
467 /* If the next character in args is 'n', it will handle
468 putting out the space. */
470 (*info
->fprintf_func
) (info
->stream
, " ");
478 fput_const (extract_5_store (insn
), info
);
481 fput_const (extract_5r_store (insn
), info
);
484 fput_const (extract_5R_store (insn
), info
);
487 fput_const (extract_5Q_store (insn
), info
);
490 fput_const (extract_11 (insn
), info
);
493 fput_const (extract_14 (insn
), info
);
496 fput_const (extract_21 (insn
), info
);
500 (*info
->fprintf_func
) (info
->stream
, ",n ");
502 (*info
->fprintf_func
) (info
->stream
, " ");
505 if ((insn
& 0x20) && s
[1])
506 (*info
->fprintf_func
) (info
->stream
, ",n ");
507 else if (insn
& 0x20)
508 (*info
->fprintf_func
) (info
->stream
, ",n");
510 (*info
->fprintf_func
) (info
->stream
, " ");
513 (*info
->print_address_func
) (memaddr
+ 8 + extract_12 (insn
),
517 /* 17 bit PC-relative branch. */
518 (*info
->print_address_func
) ((memaddr
+ 8
519 + extract_17 (insn
)),
523 /* 17 bit displacement. This is an offset from a register
524 so it gets disasssembled as just a number, not any sort
526 fput_const (extract_17 (insn
), info
);
529 (*info
->fprintf_func
) (info
->stream
, "%d",
530 31 - GET_FIELD (insn
, 22, 26));
533 (*info
->fprintf_func
) (info
->stream
, "%d",
534 GET_FIELD (insn
, 22, 26));
537 (*info
->fprintf_func
) (info
->stream
, "%d",
538 32 - GET_FIELD (insn
, 27, 31));
541 fput_const (GET_FIELD (insn
, 6, 18), info
);
544 if (GET_FIELD (insn
, 26, 26))
545 (*info
->fprintf_func
) (info
->stream
, ",m ");
547 (*info
->fprintf_func
) (info
->stream
, " ");
550 fput_const (GET_FIELD (insn
, 6, 31), info
);
553 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
556 fput_const ((GET_FIELD (insn
, 6,20) << 5 |
557 GET_FIELD (insn
, 27, 31)), info
);
560 fput_const (GET_FIELD (insn
, 6, 20), info
);
564 int reg
= GET_FIELD (insn
, 21, 22);
565 reg
|= GET_FIELD (insn
, 16, 18) << 2;
566 if (GET_FIELD (insn
, 23, 23) != 0)
567 fput_fp_reg_r (reg
, info
);
569 fput_fp_reg (reg
, info
);
574 fput_const ((GET_FIELD (insn
, 6, 22) << 5 |
575 GET_FIELD (insn
, 27, 31)), info
);
578 fput_const ((GET_FIELD (insn
, 11, 20) << 5 |
579 GET_FIELD (insn
, 27, 31)), info
);
582 fput_const ((GET_FIELD (insn
, 16, 20) << 5 |
583 GET_FIELD (insn
, 27, 31)), info
);
586 (*info
->fprintf_func
) (info
->stream
, ",%d", GET_FIELD (insn
, 23, 25));
589 /* if no destination completer and not before a completer
590 for fcmp, need a space here */
591 if (GET_FIELD (insn
, 21, 22) == 1 || s
[1] == '?')
592 fputs_filtered (float_format_names
[GET_FIELD (insn
, 19, 20)],
595 (*info
->fprintf_func
) (info
->stream
, "%s ",
596 float_format_names
[GET_FIELD
600 (*info
->fprintf_func
) (info
->stream
, "%s ",
601 float_format_names
[GET_FIELD (insn
,
605 if (GET_FIELD (insn
, 26, 26) == 1)
606 (*info
->fprintf_func
) (info
->stream
, "%s ",
607 float_format_names
[0]);
609 (*info
->fprintf_func
) (info
->stream
, "%s ",
610 float_format_names
[1]);
613 /* if no destination completer and not before a completer
614 for fcmp, need a space here */
615 if (GET_FIELD (insn
, 21, 22) == 1 || s
[1] == '?')
616 fputs_filtered (float_format_names
[GET_FIELD (insn
, 20, 20)],
619 (*info
->fprintf_func
) (info
->stream
, "%s ",
620 float_format_names
[GET_FIELD
624 if (GET_FIELD (insn
, 24, 24))
625 fput_fp_reg_r (GET_FIELD (insn
, 6, 10), info
);
627 fput_fp_reg (GET_FIELD (insn
, 6, 10), info
);
631 if (GET_FIELD (insn
, 19, 19))
632 fput_fp_reg_r (GET_FIELD (insn
, 11, 15), info
);
634 fput_fp_reg (GET_FIELD (insn
, 11, 15), info
);
637 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
644 (*info
->fprintf_func
) (info
->stream
, "#%8x", insn
);
This page took 0.084533 seconds and 5 git commands to generate.