1 /* ppc-dis.c -- Disassemble PowerPC instructions
2 Copyright 1994, 1995, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support
6 This file is part of GDB, GAS, and the GNU binutils.
8 GDB, GAS, and the GNU binutils are free software; you can redistribute
9 them and/or modify them under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either version
11 2, or (at your option) any later version.
13 GDB, GAS, and the GNU binutils are distributed in the hope that they
14 will be useful, but WITHOUT ANY WARRANTY; without even the implied
15 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this file; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include <asm/cputable.h>
23 #include <asm/cpu_has_feature.h>
29 /* Print a PowerPC or POWER instruction. */
32 print_insn_powerpc (unsigned long insn
, unsigned long memaddr
)
34 const struct powerpc_opcode
*opcode
;
35 const struct powerpc_opcode
*opcode_end
;
39 dialect
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_COMMON
40 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
| PPC_OPCODE_ALTIVEC
;
42 if (cpu_has_feature(CPU_FTRS_POWER5
))
43 dialect
|= PPC_OPCODE_POWER5
;
45 if (cpu_has_feature(CPU_FTRS_CELL
))
46 dialect
|= PPC_OPCODE_CELL
| PPC_OPCODE_ALTIVEC
;
48 if (cpu_has_feature(CPU_FTRS_POWER6
))
49 dialect
|= PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
| PPC_OPCODE_ALTIVEC
;
51 /* Get the major opcode of the instruction. */
54 /* Find the first match in the opcode table. We could speed this up
55 a bit by doing a binary search on the major opcode. */
56 opcode_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
58 for (opcode
= powerpc_opcodes
; opcode
< opcode_end
; opcode
++)
60 unsigned long table_op
;
61 const unsigned char *opindex
;
62 const struct powerpc_operand
*operand
;
67 table_op
= PPC_OP (opcode
->opcode
);
73 if ((insn
& opcode
->mask
) != opcode
->opcode
74 || (opcode
->flags
& dialect
) == 0)
77 /* Make two passes over the operands. First see if any of them
78 have extraction functions, and, if they do, make sure the
79 instruction is valid. */
81 for (opindex
= opcode
->operands
; *opindex
!= 0; opindex
++)
83 operand
= powerpc_operands
+ *opindex
;
85 (*operand
->extract
) (insn
, dialect
, &invalid
);
90 /* The instruction is valid. */
91 printf("%s", opcode
->name
);
92 if (opcode
->operands
[0] != 0)
95 /* Now extract and print the operands. */
98 for (opindex
= opcode
->operands
; *opindex
!= 0; opindex
++)
102 operand
= powerpc_operands
+ *opindex
;
104 /* Operands that are marked FAKE are simply ignored. We
105 already made sure that the extract function considered
106 the instruction to be valid. */
107 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
110 /* Extract the value from the instruction. */
111 if (operand
->extract
)
112 value
= (*operand
->extract
) (insn
, dialect
, &invalid
);
115 value
= (insn
>> operand
->shift
) & ((1 << operand
->bits
) - 1);
116 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0
117 && (value
& (1 << (operand
->bits
- 1))) != 0)
118 value
-= 1 << operand
->bits
;
121 /* If the operand is optional, and the value is zero, don't
123 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
124 && (operand
->flags
& PPC_OPERAND_NEXT
) == 0
134 /* Print the operand as directed by the flags. */
135 if ((operand
->flags
& PPC_OPERAND_GPR
) != 0
136 || ((operand
->flags
& PPC_OPERAND_GPR_0
) != 0 && value
!= 0))
137 printf("r%ld", value
);
138 else if ((operand
->flags
& PPC_OPERAND_FPR
) != 0)
139 printf("f%ld", value
);
140 else if ((operand
->flags
& PPC_OPERAND_VR
) != 0)
141 printf("v%ld", value
);
142 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0)
143 print_address (memaddr
+ value
);
144 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
145 print_address (value
& 0xffffffff);
146 else if ((operand
->flags
& PPC_OPERAND_CR
) == 0
147 || (dialect
& PPC_OPCODE_PPC
) == 0)
148 printf("%ld", value
);
151 if (operand
->bits
== 3)
152 printf("cr%ld", value
);
155 static const char *cbnames
[4] = { "lt", "gt", "eq", "so" };
161 printf("4*cr%d+", cr
);
163 printf("%s", cbnames
[cc
]);
173 if ((operand
->flags
& PPC_OPERAND_PARENS
) == 0)
182 /* We have found and printed an instruction; return. */
186 if ((dialect
& PPC_OPCODE_ANY
) != 0)
188 dialect
= ~PPC_OPCODE_ANY
;
192 /* We could not find a match. */
193 printf(".long 0x%lx", insn
);