Commit | Line | Data |
---|---|---|
ae06e374 ME |
1 | /* Disassemble SPU instructions |
2 | ||
3 | Copyright 2006 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GDB, GAS, and the GNU binutils. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. */ | |
20 | ||
21 | #include <linux/string.h> | |
22 | #include "nonstdio.h" | |
23 | #include "ansidecl.h" | |
24 | #include "spu.h" | |
25 | ||
26 | extern void print_address (unsigned long memaddr); | |
27 | ||
28 | /* This file provides a disassembler function which uses | |
29 | the disassembler interface defined in dis-asm.h. */ | |
30 | ||
31 | extern const struct spu_opcode spu_opcodes[]; | |
32 | extern const int spu_num_opcodes; | |
33 | ||
34 | #define SPU_DISASM_TBL_SIZE (1 << 11) | |
35 | static const struct spu_opcode *spu_disassemble_table[SPU_DISASM_TBL_SIZE]; | |
36 | ||
37 | static void | |
38 | init_spu_disassemble (void) | |
39 | { | |
40 | int i; | |
41 | ||
42 | /* If two instructions have the same opcode then we prefer the first | |
43 | * one. In most cases it is just an alternate mnemonic. */ | |
44 | for (i = 0; i < spu_num_opcodes; i++) | |
45 | { | |
46 | int o = spu_opcodes[i].opcode; | |
47 | if (o >= SPU_DISASM_TBL_SIZE) | |
48 | continue; /* abort (); */ | |
49 | if (spu_disassemble_table[o] == 0) | |
50 | spu_disassemble_table[o] = &spu_opcodes[i]; | |
51 | } | |
52 | } | |
53 | ||
54 | /* Determine the instruction from the 10 least significant bits. */ | |
55 | static const struct spu_opcode * | |
56 | get_index_for_opcode (unsigned int insn) | |
57 | { | |
58 | const struct spu_opcode *index; | |
59 | unsigned int opcode = insn >> (32-11); | |
60 | ||
61 | /* Init the table. This assumes that element 0/opcode 0 (currently | |
62 | * NOP) is always used */ | |
63 | if (spu_disassemble_table[0] == 0) | |
64 | init_spu_disassemble (); | |
65 | ||
66 | if ((index = spu_disassemble_table[opcode & 0x780]) != 0 | |
67 | && index->insn_type == RRR) | |
68 | return index; | |
69 | ||
70 | if ((index = spu_disassemble_table[opcode & 0x7f0]) != 0 | |
71 | && (index->insn_type == RI18 || index->insn_type == LBT)) | |
72 | return index; | |
73 | ||
74 | if ((index = spu_disassemble_table[opcode & 0x7f8]) != 0 | |
75 | && index->insn_type == RI10) | |
76 | return index; | |
77 | ||
78 | if ((index = spu_disassemble_table[opcode & 0x7fc]) != 0 | |
79 | && (index->insn_type == RI16)) | |
80 | return index; | |
81 | ||
82 | if ((index = spu_disassemble_table[opcode & 0x7fe]) != 0 | |
83 | && (index->insn_type == RI8)) | |
84 | return index; | |
85 | ||
86 | if ((index = spu_disassemble_table[opcode & 0x7ff]) != 0) | |
87 | return index; | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
92 | /* Print a Spu instruction. */ | |
93 | ||
94 | int | |
95 | print_insn_spu (unsigned long insn, unsigned long memaddr) | |
96 | { | |
97 | int value; | |
98 | int hex_value; | |
99 | const struct spu_opcode *index; | |
100 | enum spu_insns tag; | |
101 | ||
102 | index = get_index_for_opcode (insn); | |
103 | ||
104 | if (index == 0) | |
105 | { | |
106 | printf(".long 0x%x", insn); | |
107 | } | |
108 | else | |
109 | { | |
110 | int i; | |
111 | int paren = 0; | |
112 | tag = (enum spu_insns)(index - spu_opcodes); | |
113 | printf("%s", index->mnemonic); | |
114 | if (tag == M_BI || tag == M_BISL || tag == M_IRET || tag == M_BISLED | |
115 | || tag == M_BIHNZ || tag == M_BIHZ || tag == M_BINZ || tag == M_BIZ | |
116 | || tag == M_SYNC || tag == M_HBR) | |
117 | { | |
118 | int fb = (insn >> (32-18)) & 0x7f; | |
119 | if (fb & 0x40) | |
120 | printf(tag == M_SYNC ? "c" : "p"); | |
121 | if (fb & 0x20) | |
122 | printf("d"); | |
123 | if (fb & 0x10) | |
124 | printf("e"); | |
125 | } | |
126 | if (index->arg[0] != 0) | |
127 | printf("\t"); | |
128 | hex_value = 0; | |
129 | for (i = 1; i <= index->arg[0]; i++) | |
130 | { | |
131 | int arg = index->arg[i]; | |
132 | if (arg != A_P && !paren && i > 1) | |
133 | printf(","); | |
134 | ||
135 | switch (arg) | |
136 | { | |
137 | case A_T: | |
138 | printf("$%d", | |
139 | DECODE_INSN_RT (insn)); | |
140 | break; | |
141 | case A_A: | |
142 | printf("$%d", | |
143 | DECODE_INSN_RA (insn)); | |
144 | break; | |
145 | case A_B: | |
146 | printf("$%d", | |
147 | DECODE_INSN_RB (insn)); | |
148 | break; | |
149 | case A_C: | |
150 | printf("$%d", | |
151 | DECODE_INSN_RC (insn)); | |
152 | break; | |
153 | case A_S: | |
154 | printf("$sp%d", | |
155 | DECODE_INSN_RA (insn)); | |
156 | break; | |
157 | case A_H: | |
158 | printf("$ch%d", | |
159 | DECODE_INSN_RA (insn)); | |
160 | break; | |
161 | case A_P: | |
162 | paren++; | |
163 | printf("("); | |
164 | break; | |
165 | case A_U7A: | |
166 | printf("%d", | |
167 | 173 - DECODE_INSN_U8 (insn)); | |
168 | break; | |
169 | case A_U7B: | |
170 | printf("%d", | |
171 | 155 - DECODE_INSN_U8 (insn)); | |
172 | break; | |
173 | case A_S3: | |
174 | case A_S6: | |
175 | case A_S7: | |
176 | case A_S7N: | |
177 | case A_U3: | |
178 | case A_U5: | |
179 | case A_U6: | |
180 | case A_U7: | |
181 | hex_value = DECODE_INSN_I7 (insn); | |
182 | printf("%d", hex_value); | |
183 | break; | |
184 | case A_S11: | |
185 | print_address(memaddr + DECODE_INSN_I9a (insn) * 4); | |
186 | break; | |
187 | case A_S11I: | |
188 | print_address(memaddr + DECODE_INSN_I9b (insn) * 4); | |
189 | break; | |
190 | case A_S10: | |
191 | case A_S10B: | |
192 | hex_value = DECODE_INSN_I10 (insn); | |
193 | printf("%d", hex_value); | |
194 | break; | |
195 | case A_S14: | |
196 | hex_value = DECODE_INSN_I10 (insn) * 16; | |
197 | printf("%d", hex_value); | |
198 | break; | |
199 | case A_S16: | |
200 | hex_value = DECODE_INSN_I16 (insn); | |
201 | printf("%d", hex_value); | |
202 | break; | |
203 | case A_X16: | |
204 | hex_value = DECODE_INSN_U16 (insn); | |
205 | printf("%u", hex_value); | |
206 | break; | |
207 | case A_R18: | |
208 | value = DECODE_INSN_I16 (insn) * 4; | |
209 | if (value == 0) | |
210 | printf("%d", value); | |
211 | else | |
212 | { | |
213 | hex_value = memaddr + value; | |
214 | print_address(hex_value & 0x3ffff); | |
215 | } | |
216 | break; | |
217 | case A_S18: | |
218 | value = DECODE_INSN_U16 (insn) * 4; | |
219 | if (value == 0) | |
220 | printf("%d", value); | |
221 | else | |
222 | print_address(value); | |
223 | break; | |
224 | case A_U18: | |
225 | value = DECODE_INSN_U18 (insn); | |
226 | if (value == 0 || 1) | |
227 | { | |
228 | hex_value = value; | |
229 | printf("%u", value); | |
230 | } | |
231 | else | |
232 | print_address(value); | |
233 | break; | |
234 | case A_U14: | |
235 | hex_value = DECODE_INSN_U14 (insn); | |
236 | printf("%u", hex_value); | |
237 | break; | |
238 | } | |
239 | if (arg != A_P && paren) | |
240 | { | |
241 | printf(")"); | |
242 | paren--; | |
243 | } | |
244 | } | |
245 | if (hex_value > 16) | |
246 | printf("\t# %x", hex_value); | |
247 | } | |
248 | return 4; | |
249 | } |