1 /* ppc-dis.c -- Disassemble PowerPC instructions
2 Copyright 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support
5 This file is part of GDB, GAS, and the GNU binutils.
7 GDB, GAS, and the GNU binutils are free software; you can redistribute
8 them and/or modify them under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either version
10 2, or (at your option) any later version.
12 GDB, GAS, and the GNU binutils are distributed in the hope that they
13 will be useful, but WITHOUT ANY WARRANTY; without even the implied
14 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this file; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* Print a PowerPC or POWER instruction. */
29 print_insn_powerpc (unsigned long insn, unsigned long memaddr)
31 const struct powerpc_opcode *opcode;
32 const struct powerpc_opcode *opcode_end;
36 dialect = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_COMMON
37 | PPC_OPCODE_64 | PPC_OPCODE_POWER4 | PPC_OPCODE_ALTIVEC;
39 /* Get the major opcode of the instruction. */
42 /* Find the first match in the opcode table. We could speed this up
43 a bit by doing a binary search on the major opcode. */
44 opcode_end = powerpc_opcodes + powerpc_num_opcodes;
46 for (opcode = powerpc_opcodes; opcode < opcode_end; opcode++)
48 unsigned long table_op;
49 const unsigned char *opindex;
50 const struct powerpc_operand *operand;
55 table_op = PPC_OP (opcode->opcode);
61 if ((insn & opcode->mask) != opcode->opcode
62 || (opcode->flags & dialect) == 0)
65 /* Make two passes over the operands. First see if any of them
66 have extraction functions, and, if they do, make sure the
67 instruction is valid. */
69 for (opindex = opcode->operands; *opindex != 0; opindex++)
71 operand = powerpc_operands + *opindex;
73 (*operand->extract) (insn, dialect, &invalid);
78 /* The instruction is valid. */
79 printf("%s", opcode->name);
80 if (opcode->operands[0] != 0)
83 /* Now extract and print the operands. */
86 for (opindex = opcode->operands; *opindex != 0; opindex++)
90 operand = powerpc_operands + *opindex;
92 /* Operands that are marked FAKE are simply ignored. We
93 already made sure that the extract function considered
94 the instruction to be valid. */
95 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
98 /* Extract the value from the instruction. */
100 value = (*operand->extract) (insn, dialect, &invalid);
103 value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
104 if ((operand->flags & PPC_OPERAND_SIGNED) != 0
105 && (value & (1 << (operand->bits - 1))) != 0)
106 value -= 1 << operand->bits;
109 /* If the operand is optional, and the value is zero, don't
111 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
112 && (operand->flags & PPC_OPERAND_NEXT) == 0
122 /* Print the operand as directed by the flags. */
123 if ((operand->flags & PPC_OPERAND_GPR) != 0)
124 printf("r%ld", value);
125 else if ((operand->flags & PPC_OPERAND_FPR) != 0)
126 printf("f%ld", value);
127 else if ((operand->flags & PPC_OPERAND_VR) != 0)
128 printf("v%ld", value);
129 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0)
130 print_address (memaddr + value);
131 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
132 print_address (value & 0xffffffff);
133 else if ((operand->flags & PPC_OPERAND_CR) == 0
134 || (dialect & PPC_OPCODE_PPC) == 0)
135 printf("%ld", value);
138 if (operand->bits == 3)
139 printf("cr%d", value);
142 static const char *cbnames[4] = { "lt", "gt", "eq", "so" };
148 printf("4*cr%d+", cr);
150 printf("%s", cbnames[cc]);
160 if ((operand->flags & PPC_OPERAND_PARENS) == 0)
169 /* We have found and printed an instruction; return. */
173 if ((dialect & PPC_OPCODE_ANY) != 0)
175 dialect = ~PPC_OPCODE_ANY;
179 /* We could not find a match. */
180 printf(".long 0x%lx", insn);