1 /* Disassemble SPU instructions
3 Copyright 2006 Free Software Foundation, Inc.
5 This file is part of GDB, GAS, and the GNU binutils.
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 along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include <linux/string.h>
27 /* This file provides a disassembler function which uses
28 the disassembler interface defined in dis-asm.h. */
30 extern const struct spu_opcode spu_opcodes
[];
31 extern const int spu_num_opcodes
;
33 #define SPU_DISASM_TBL_SIZE (1 << 11)
34 static const struct spu_opcode
*spu_disassemble_table
[SPU_DISASM_TBL_SIZE
];
37 init_spu_disassemble (void)
41 /* If two instructions have the same opcode then we prefer the first
42 * one. In most cases it is just an alternate mnemonic. */
43 for (i
= 0; i
< spu_num_opcodes
; i
++)
45 int o
= spu_opcodes
[i
].opcode
;
46 if (o
>= SPU_DISASM_TBL_SIZE
)
47 continue; /* abort (); */
48 if (spu_disassemble_table
[o
] == 0)
49 spu_disassemble_table
[o
] = &spu_opcodes
[i
];
53 /* Determine the instruction from the 10 least significant bits. */
54 static const struct spu_opcode
*
55 get_index_for_opcode (unsigned int insn
)
57 const struct spu_opcode
*index
;
58 unsigned int opcode
= insn
>> (32-11);
60 /* Init the table. This assumes that element 0/opcode 0 (currently
61 * NOP) is always used */
62 if (spu_disassemble_table
[0] == 0)
63 init_spu_disassemble ();
65 if ((index
= spu_disassemble_table
[opcode
& 0x780]) != 0
66 && index
->insn_type
== RRR
)
69 if ((index
= spu_disassemble_table
[opcode
& 0x7f0]) != 0
70 && (index
->insn_type
== RI18
|| index
->insn_type
== LBT
))
73 if ((index
= spu_disassemble_table
[opcode
& 0x7f8]) != 0
74 && index
->insn_type
== RI10
)
77 if ((index
= spu_disassemble_table
[opcode
& 0x7fc]) != 0
78 && (index
->insn_type
== RI16
))
81 if ((index
= spu_disassemble_table
[opcode
& 0x7fe]) != 0
82 && (index
->insn_type
== RI8
))
85 if ((index
= spu_disassemble_table
[opcode
& 0x7ff]) != 0)
91 /* Print a Spu instruction. */
94 print_insn_spu (unsigned long insn
, unsigned long memaddr
)
98 const struct spu_opcode
*index
;
101 index
= get_index_for_opcode (insn
);
105 printf(".long 0x%lx", insn
);
111 tag
= (enum spu_insns
)(index
- spu_opcodes
);
112 printf("%s", index
->mnemonic
);
113 if (tag
== M_BI
|| tag
== M_BISL
|| tag
== M_IRET
|| tag
== M_BISLED
114 || tag
== M_BIHNZ
|| tag
== M_BIHZ
|| tag
== M_BINZ
|| tag
== M_BIZ
115 || tag
== M_SYNC
|| tag
== M_HBR
)
117 int fb
= (insn
>> (32-18)) & 0x7f;
119 printf(tag
== M_SYNC
? "c" : "p");
125 if (index
->arg
[0] != 0)
128 for (i
= 1; i
<= index
->arg
[0]; i
++)
130 int arg
= index
->arg
[i
];
131 if (arg
!= A_P
&& !paren
&& i
> 1)
138 DECODE_INSN_RT (insn
));
142 DECODE_INSN_RA (insn
));
146 DECODE_INSN_RB (insn
));
150 DECODE_INSN_RC (insn
));
154 DECODE_INSN_RA (insn
));
158 DECODE_INSN_RA (insn
));
166 173 - DECODE_INSN_U8 (insn
));
170 155 - DECODE_INSN_U8 (insn
));
180 hex_value
= DECODE_INSN_I7 (insn
);
181 printf("%d", hex_value
);
184 print_address(memaddr
+ DECODE_INSN_I9a (insn
) * 4);
187 print_address(memaddr
+ DECODE_INSN_I9b (insn
) * 4);
191 hex_value
= DECODE_INSN_I10 (insn
);
192 printf("%d", hex_value
);
195 hex_value
= DECODE_INSN_I10 (insn
) * 16;
196 printf("%d", hex_value
);
199 hex_value
= DECODE_INSN_I16 (insn
);
200 printf("%d", hex_value
);
203 hex_value
= DECODE_INSN_U16 (insn
);
204 printf("%u", hex_value
);
207 value
= DECODE_INSN_I16 (insn
) * 4;
212 hex_value
= memaddr
+ value
;
213 print_address(hex_value
& 0x3ffff);
217 value
= DECODE_INSN_U16 (insn
) * 4;
221 print_address(value
);
224 value
= DECODE_INSN_U18 (insn
);
231 print_address(value
);
234 hex_value
= DECODE_INSN_U14 (insn
);
235 printf("%u", hex_value
);
238 if (arg
!= A_P
&& paren
)
245 printf("\t# %x", hex_value
);