1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Disassemble SPU instructions
4 Copyright 2006 Free Software Foundation, Inc.
6 This file is part of GDB, GAS, and the GNU binutils.
10 #include <linux/string.h>
16 /* This file provides a disassembler function which uses
17 the disassembler interface defined in dis-asm.h. */
19 extern const struct spu_opcode spu_opcodes
[];
20 extern const int spu_num_opcodes
;
22 #define SPU_DISASM_TBL_SIZE (1 << 11)
23 static const struct spu_opcode
*spu_disassemble_table
[SPU_DISASM_TBL_SIZE
];
26 init_spu_disassemble (void)
30 /* If two instructions have the same opcode then we prefer the first
31 * one. In most cases it is just an alternate mnemonic. */
32 for (i
= 0; i
< spu_num_opcodes
; i
++)
34 int o
= spu_opcodes
[i
].opcode
;
35 if (o
>= SPU_DISASM_TBL_SIZE
)
36 continue; /* abort (); */
37 if (spu_disassemble_table
[o
] == 0)
38 spu_disassemble_table
[o
] = &spu_opcodes
[i
];
42 /* Determine the instruction from the 10 least significant bits. */
43 static const struct spu_opcode
*
44 get_index_for_opcode (unsigned int insn
)
46 const struct spu_opcode
*index
;
47 unsigned int opcode
= insn
>> (32-11);
49 /* Init the table. This assumes that element 0/opcode 0 (currently
50 * NOP) is always used */
51 if (spu_disassemble_table
[0] == 0)
52 init_spu_disassemble ();
54 if ((index
= spu_disassemble_table
[opcode
& 0x780]) != 0
55 && index
->insn_type
== RRR
)
58 if ((index
= spu_disassemble_table
[opcode
& 0x7f0]) != 0
59 && (index
->insn_type
== RI18
|| index
->insn_type
== LBT
))
62 if ((index
= spu_disassemble_table
[opcode
& 0x7f8]) != 0
63 && index
->insn_type
== RI10
)
66 if ((index
= spu_disassemble_table
[opcode
& 0x7fc]) != 0
67 && (index
->insn_type
== RI16
))
70 if ((index
= spu_disassemble_table
[opcode
& 0x7fe]) != 0
71 && (index
->insn_type
== RI8
))
74 if ((index
= spu_disassemble_table
[opcode
& 0x7ff]) != 0)
80 /* Print a Spu instruction. */
83 print_insn_spu (unsigned long insn
, unsigned long memaddr
)
87 const struct spu_opcode
*index
;
90 index
= get_index_for_opcode (insn
);
94 printf(".long 0x%lx", insn
);
100 tag
= (enum spu_insns
)(index
- spu_opcodes
);
101 printf("%s", index
->mnemonic
);
102 if (tag
== M_BI
|| tag
== M_BISL
|| tag
== M_IRET
|| tag
== M_BISLED
103 || tag
== M_BIHNZ
|| tag
== M_BIHZ
|| tag
== M_BINZ
|| tag
== M_BIZ
104 || tag
== M_SYNC
|| tag
== M_HBR
)
106 int fb
= (insn
>> (32-18)) & 0x7f;
108 printf(tag
== M_SYNC
? "c" : "p");
114 if (index
->arg
[0] != 0)
117 for (i
= 1; i
<= index
->arg
[0]; i
++)
119 int arg
= index
->arg
[i
];
120 if (arg
!= A_P
&& !paren
&& i
> 1)
127 DECODE_INSN_RT (insn
));
131 DECODE_INSN_RA (insn
));
135 DECODE_INSN_RB (insn
));
139 DECODE_INSN_RC (insn
));
143 DECODE_INSN_RA (insn
));
147 DECODE_INSN_RA (insn
));
155 173 - DECODE_INSN_U8 (insn
));
159 155 - DECODE_INSN_U8 (insn
));
169 hex_value
= DECODE_INSN_I7 (insn
);
170 printf("%d", hex_value
);
173 print_address(memaddr
+ DECODE_INSN_I9a (insn
) * 4);
176 print_address(memaddr
+ DECODE_INSN_I9b (insn
) * 4);
180 hex_value
= DECODE_INSN_I10 (insn
);
181 printf("%d", hex_value
);
184 hex_value
= DECODE_INSN_I10 (insn
) * 16;
185 printf("%d", hex_value
);
188 hex_value
= DECODE_INSN_I16 (insn
);
189 printf("%d", hex_value
);
192 hex_value
= DECODE_INSN_U16 (insn
);
193 printf("%u", hex_value
);
196 value
= DECODE_INSN_I16 (insn
) * 4;
201 hex_value
= memaddr
+ value
;
202 print_address(hex_value
& 0x3ffff);
206 value
= DECODE_INSN_U16 (insn
) * 4;
210 print_address(value
);
213 value
= DECODE_INSN_U18 (insn
);
220 print_address(value
);
223 hex_value
= DECODE_INSN_U14 (insn
);
224 printf("%u", hex_value
);
227 if (arg
!= A_P
&& paren
)
234 printf("\t# %x", hex_value
);