]>
Commit | Line | Data |
---|---|---|
5c84d377 | 1 | /* Disassembly routines for TMS320C54X architecture |
d83c6548 | 2 | Copyright 1999, 2000, 2001 Free Software Foundation, Inc. |
5c84d377 TW |
3 | Contributed by Timothy Wall (twall@cygnus.com) |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
18 | 02111-1307, USA. */ | |
19 | ||
20 | #include <errno.h> | |
21 | #include <math.h> | |
22 | #include <stdlib.h> | |
c1485d85 | 23 | #include "sysdep.h" |
5c84d377 TW |
24 | #include "dis-asm.h" |
25 | #include "opcode/tic54x.h" | |
26 | #include "coff/tic54x.h" | |
27 | ||
28 | typedef struct _instruction { | |
29 | int parallel; | |
30 | template *tm; | |
31 | partemplate *ptm; | |
32 | } instruction; | |
33 | ||
d83c6548 | 34 | static int has_lkaddr PARAMS ((unsigned short, template *)); |
5c84d377 | 35 | static int get_insn_size PARAMS ((unsigned short, instruction *)); |
d83c6548 | 36 | static int get_instruction PARAMS ((disassemble_info *, bfd_vma, |
5c84d377 | 37 | unsigned short, instruction *)); |
d83c6548 AJ |
38 | static int print_instruction PARAMS ((disassemble_info *, bfd_vma, |
39 | unsigned short, char *, | |
5c84d377 TW |
40 | enum optype [], int, int)); |
41 | static int print_parallel_instruction PARAMS ((disassemble_info *, bfd_vma, | |
42 | unsigned short, partemplate *, | |
d83c6548 AJ |
43 | int)); |
44 | static int sprint_dual_address (disassemble_info *,char [], | |
5c84d377 | 45 | unsigned short); |
d83c6548 | 46 | static int sprint_indirect_address (disassemble_info *,char [], |
5c84d377 | 47 | unsigned short); |
d83c6548 | 48 | static int sprint_direct_address (disassemble_info *,char [], |
5c84d377 TW |
49 | unsigned short); |
50 | static int sprint_mmr (disassemble_info *,char [],int); | |
51 | static int sprint_condition (disassemble_info *,char *,unsigned short); | |
52 | static int sprint_cc2 (disassemble_info *,char *,unsigned short); | |
53 | ||
54 | int | |
33822a8e | 55 | print_insn_tic54x (memaddr, info) |
5c84d377 TW |
56 | bfd_vma memaddr; |
57 | disassemble_info *info; | |
58 | { | |
d83c6548 | 59 | bfd_byte opbuf[2]; |
5c84d377 TW |
60 | unsigned short opcode; |
61 | int status, size; | |
62 | instruction insn; | |
63 | ||
64 | status = (*info->read_memory_func) (memaddr, opbuf, 2, info); | |
65 | if (status != 0) | |
66 | { | |
33822a8e | 67 | (*info->memory_error_func) (status, memaddr, info); |
5c84d377 TW |
68 | return -1; |
69 | } | |
70 | ||
33822a8e | 71 | opcode = bfd_getl16 (opbuf); |
5c84d377 TW |
72 | if (!get_instruction (info, memaddr, opcode, &insn)) |
73 | return -1; | |
74 | ||
75 | size = get_insn_size (opcode, &insn); | |
76 | info->bytes_per_line = 2; | |
77 | info->bytes_per_chunk = 2; | |
78 | info->octets_per_byte = 2; | |
79 | info->display_endian = BFD_ENDIAN_LITTLE; | |
80 | ||
81 | if (insn.parallel) | |
82 | { | |
83 | if (!print_parallel_instruction (info, memaddr, opcode, insn.ptm, size)) | |
84 | return -1; | |
85 | } | |
86 | else | |
87 | { | |
d83c6548 AJ |
88 | if (!print_instruction (info, memaddr, opcode, |
89 | (char *) insn.tm->name, | |
5c84d377 TW |
90 | insn.tm->operand_types, |
91 | size, (insn.tm->flags & FL_EXT))) | |
92 | return -1; | |
93 | } | |
94 | ||
33822a8e | 95 | return size * 2; |
5c84d377 TW |
96 | } |
97 | ||
98 | static int | |
33822a8e | 99 | has_lkaddr (opcode, tm) |
5c84d377 TW |
100 | unsigned short opcode; |
101 | template *tm; | |
102 | { | |
33822a8e KH |
103 | return (IS_LKADDR (opcode) |
104 | && (OPTYPE (tm->operand_types[0]) == OP_Smem | |
105 | || OPTYPE (tm->operand_types[1]) == OP_Smem | |
106 | || OPTYPE (tm->operand_types[2]) == OP_Smem | |
107 | || OPTYPE (tm->operand_types[1]) == OP_Sind)); | |
5c84d377 TW |
108 | } |
109 | ||
110 | /* always returns 1 (whether an insn template was found) since we provide an | |
111 | "unknown instruction" template */ | |
d83c6548 | 112 | static int |
5c84d377 TW |
113 | get_instruction (info, addr, opcode, insn) |
114 | disassemble_info *info; | |
115 | bfd_vma addr; | |
116 | unsigned short opcode; | |
117 | instruction *insn; | |
118 | { | |
119 | template * tm; | |
120 | partemplate * ptm; | |
121 | ||
122 | insn->parallel = 0; | |
33822a8e | 123 | for (tm = (template *) tic54x_optab; tm->name; tm++) |
5c84d377 TW |
124 | { |
125 | if (tm->opcode == (opcode & tm->mask)) | |
126 | { | |
127 | /* a few opcodes span two words */ | |
128 | if (tm->flags & FL_EXT) | |
129 | { | |
130 | /* if lk addressing is used, the second half of the opcode gets | |
131 | pushed one word later */ | |
132 | bfd_byte opbuf[2]; | |
33822a8e KH |
133 | bfd_vma addr2 = addr + 1 + has_lkaddr (opcode, tm); |
134 | int status = (*info->read_memory_func) (addr2, opbuf, 2, info); | |
5c84d377 TW |
135 | if (status == 0) |
136 | { | |
33822a8e | 137 | unsigned short opcode2 = bfd_getl16 (opbuf); |
5c84d377 TW |
138 | if (tm->opcode2 == (opcode2 & tm->mask2)) |
139 | { | |
140 | insn->tm = tm; | |
141 | return 1; | |
142 | } | |
143 | } | |
144 | } | |
145 | else | |
146 | { | |
147 | insn->tm = tm; | |
148 | return 1; | |
149 | } | |
150 | } | |
151 | } | |
33822a8e | 152 | for (ptm = (partemplate *) tic54x_paroptab; ptm->name; ptm++) |
5c84d377 TW |
153 | { |
154 | if (ptm->opcode == (opcode & ptm->mask)) | |
155 | { | |
156 | insn->parallel = 1; | |
157 | insn->ptm = ptm; | |
158 | return 1; | |
159 | } | |
160 | } | |
161 | ||
33822a8e | 162 | insn->tm = (template *) &tic54x_unknown_opcode; |
5c84d377 TW |
163 | return 1; |
164 | } | |
165 | ||
d83c6548 | 166 | static int |
5c84d377 TW |
167 | get_insn_size (opcode, insn) |
168 | unsigned short opcode; | |
169 | instruction *insn; | |
170 | { | |
171 | int size; | |
172 | ||
173 | if (insn->parallel) | |
174 | { | |
175 | /* only non-parallel instructions support lk addressing */ | |
176 | size = insn->ptm->words; | |
177 | } | |
178 | else | |
179 | { | |
33822a8e | 180 | size = insn->tm->words + has_lkaddr (opcode, insn->tm); |
5c84d377 TW |
181 | } |
182 | ||
183 | return size; | |
184 | } | |
185 | ||
186 | int | |
187 | print_instruction (info, memaddr, opcode, tm_name, tm_operands, size, ext) | |
188 | disassemble_info *info; | |
189 | bfd_vma memaddr; | |
190 | unsigned short opcode; | |
191 | char *tm_name; | |
192 | enum optype tm_operands[]; | |
193 | int size; | |
194 | int ext; | |
195 | { | |
196 | static int n; | |
197 | /* string storage for multiple operands */ | |
198 | char operand[4][64] = { {0},{0},{0},{0}, }; | |
199 | bfd_byte buf[2]; | |
200 | unsigned long opcode2, lkaddr; | |
201 | enum optype src = OP_None; | |
202 | enum optype dst = OP_None; | |
203 | int i, shift; | |
204 | char *comma = ""; | |
205 | ||
206 | info->fprintf_func (info->stream, "%-7s", tm_name); | |
207 | ||
208 | if (size > 1) | |
209 | { | |
33822a8e | 210 | int status = (*info->read_memory_func) (memaddr + 1, buf, 2, info); |
5c84d377 TW |
211 | if (status != 0) |
212 | return 0; | |
33822a8e | 213 | lkaddr = opcode2 = bfd_getl16 (buf); |
5c84d377 TW |
214 | if (size > 2) |
215 | { | |
33822a8e | 216 | status = (*info->read_memory_func) (memaddr + 2, buf, 2, info); |
5c84d377 TW |
217 | if (status != 0) |
218 | return 0; | |
33822a8e | 219 | opcode2 = bfd_getl16 (buf); |
5c84d377 TW |
220 | } |
221 | } | |
222 | ||
33822a8e | 223 | for (i = 0; i < MAX_OPERANDS && OPTYPE (tm_operands[i]) != OP_None; i++) |
5c84d377 TW |
224 | { |
225 | char *next_comma = ","; | |
226 | int optional = (tm_operands[i] & OPT) != 0; | |
227 | ||
33822a8e | 228 | switch (OPTYPE (tm_operands[i])) |
5c84d377 TW |
229 | { |
230 | case OP_Xmem: | |
33822a8e | 231 | sprint_dual_address (info, operand[i], XMEM (opcode)); |
5c84d377 TW |
232 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
233 | break; | |
234 | case OP_Ymem: | |
33822a8e | 235 | sprint_dual_address (info, operand[i], YMEM (opcode)); |
5c84d377 TW |
236 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
237 | break; | |
238 | case OP_Smem: | |
239 | case OP_Sind: | |
240 | case OP_Lmem: | |
241 | info->fprintf_func (info->stream, "%s", comma); | |
33822a8e | 242 | if (INDIRECT (opcode)) |
5c84d377 | 243 | { |
33822a8e | 244 | if (MOD (opcode) >= 12) |
5c84d377 TW |
245 | { |
246 | bfd_vma addr = lkaddr; | |
33822a8e KH |
247 | int arf = ARF (opcode); |
248 | int mod = MOD (opcode); | |
5c84d377 TW |
249 | if (mod == 15) |
250 | info->fprintf_func (info->stream, "*("); | |
251 | else | |
d83c6548 | 252 | info->fprintf_func (info->stream, "*%sar%d(", |
5c84d377 TW |
253 | (mod == 13 || mod == 14 ? "+" : ""), |
254 | arf); | |
33822a8e | 255 | (*(info->print_address_func)) ((bfd_vma) addr, info); |
d83c6548 | 256 | info->fprintf_func (info->stream, ")%s", |
5c84d377 TW |
257 | mod == 14 ? "%" : ""); |
258 | } | |
259 | else | |
260 | { | |
261 | sprint_indirect_address (info, operand[i], opcode); | |
262 | info->fprintf_func (info->stream, "%s", operand[i]); | |
263 | } | |
264 | } | |
265 | else | |
266 | { | |
267 | /* FIXME -- use labels (print_address_func) */ | |
268 | /* in order to do this, we need to guess what DP is */ | |
269 | sprint_direct_address (info, operand[i], opcode); | |
270 | info->fprintf_func (info->stream, "%s", operand[i]); | |
271 | } | |
272 | break; | |
273 | case OP_dmad: | |
274 | info->fprintf_func (info->stream, "%s", comma); | |
33822a8e | 275 | (*(info->print_address_func)) ((bfd_vma) opcode2, info); |
5c84d377 TW |
276 | break; |
277 | case OP_xpmad: | |
278 | /* upper 7 bits of address are in the opcode */ | |
33822a8e | 279 | opcode2 += ((unsigned long) opcode & 0x7F) << 16; |
5c84d377 TW |
280 | /* fall through */ |
281 | case OP_pmad: | |
282 | info->fprintf_func (info->stream, "%s", comma); | |
33822a8e | 283 | (*(info->print_address_func)) ((bfd_vma) opcode2, info); |
5c84d377 TW |
284 | break; |
285 | case OP_MMRX: | |
33822a8e | 286 | sprint_mmr (info, operand[i], MMRX (opcode)); |
5c84d377 TW |
287 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
288 | break; | |
289 | case OP_MMRY: | |
33822a8e | 290 | sprint_mmr (info, operand[i], MMRY (opcode)); |
5c84d377 TW |
291 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
292 | break; | |
293 | case OP_MMR: | |
33822a8e | 294 | sprint_mmr (info, operand[i], MMR (opcode)); |
5c84d377 TW |
295 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
296 | break; | |
297 | case OP_PA: | |
33822a8e | 298 | sprintf (operand[i], "pa%d", (unsigned) opcode2); |
5c84d377 TW |
299 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
300 | break; | |
301 | case OP_SRC: | |
33822a8e | 302 | src = SRC (ext ? opcode2 : opcode) ? OP_B : OP_A; |
5c84d377 TW |
303 | sprintf (operand[i], (src == OP_B) ? "b" : "a"); |
304 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
305 | break; | |
306 | case OP_SRC1: | |
33822a8e | 307 | src = SRC1 (ext ? opcode2 : opcode) ? OP_B : OP_A; |
5c84d377 TW |
308 | sprintf (operand[i], (src == OP_B) ? "b" : "a"); |
309 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
310 | break; | |
311 | case OP_RND: | |
33822a8e | 312 | dst = DST (opcode) ? OP_B : OP_A; |
5c84d377 TW |
313 | sprintf (operand[i], (dst == OP_B) ? "a" : "b"); |
314 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
315 | break; | |
316 | case OP_DST: | |
33822a8e | 317 | dst = DST (ext ? opcode2 : opcode) ? OP_B : OP_A; |
5c84d377 TW |
318 | if (!optional || dst != src) |
319 | { | |
320 | sprintf (operand[i], (dst == OP_B) ? "b" : "a"); | |
321 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
322 | } | |
323 | else | |
324 | next_comma = comma; | |
325 | break; | |
326 | case OP_B: | |
327 | sprintf (operand[i], "b"); | |
328 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
329 | break; | |
330 | case OP_A: | |
331 | sprintf (operand[i], "a"); | |
332 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
333 | break; | |
334 | case OP_ARX: | |
33822a8e | 335 | sprintf (operand[i], "ar%d", (int) ARX (opcode)); |
5c84d377 TW |
336 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
337 | break; | |
338 | case OP_SHIFT: | |
33822a8e | 339 | shift = SHIFT (ext ? opcode2 : opcode); |
5c84d377 TW |
340 | if (!optional || shift != 0) |
341 | { | |
33822a8e | 342 | sprintf (operand[i], "%d", shift); |
5c84d377 TW |
343 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
344 | } | |
345 | else | |
346 | next_comma = comma; | |
347 | break; | |
348 | case OP_SHFT: | |
33822a8e | 349 | shift = SHFT (opcode); |
5c84d377 TW |
350 | if (!optional || shift != 0) |
351 | { | |
33822a8e | 352 | sprintf (operand[i], "%d", (unsigned) shift); |
5c84d377 TW |
353 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
354 | } | |
355 | else | |
356 | next_comma = comma; | |
357 | break; | |
358 | case OP_lk: | |
33822a8e | 359 | sprintf (operand[i], "#%d", (int) (short) opcode2); |
5c84d377 TW |
360 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
361 | break; | |
362 | case OP_T: | |
363 | sprintf (operand[i], "t"); | |
364 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
365 | break; | |
366 | case OP_TS: | |
367 | sprintf (operand[i], "ts"); | |
368 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
369 | break; | |
370 | case OP_k8: | |
33822a8e | 371 | sprintf (operand[i], "%d", (int) ((signed char) (opcode & 0xFF))); |
5c84d377 TW |
372 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
373 | break; | |
374 | case OP_16: | |
375 | sprintf (operand[i], "16"); | |
376 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
377 | break; | |
378 | case OP_ASM: | |
379 | sprintf (operand[i], "asm"); | |
380 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
381 | break; | |
382 | case OP_BITC: | |
33822a8e | 383 | sprintf (operand[i], "%d", (int) (opcode & 0xF)); |
5c84d377 TW |
384 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
385 | break; | |
386 | case OP_CC: | |
387 | /* put all CC operands in the same operand */ | |
388 | sprint_condition (info, operand[i], opcode); | |
389 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
390 | i = MAX_OPERANDS; | |
391 | break; | |
392 | case OP_CC2: | |
393 | sprint_cc2 (info, operand[i], opcode); | |
394 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
395 | break; | |
396 | case OP_CC3: | |
397 | { | |
398 | const char *code[] = { "eq", "lt", "gt", "neq" }; | |
33822a8e | 399 | sprintf (operand[i], code[CC3 (opcode)]); |
5c84d377 TW |
400 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
401 | break; | |
402 | } | |
403 | case OP_123: | |
404 | { | |
33822a8e | 405 | int code = (opcode >> 8) & 0x3; |
5c84d377 TW |
406 | sprintf (operand[i], "%d", (code == 0) ? 1 : (code == 2) ? 2 : 3); |
407 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
408 | break; | |
409 | } | |
410 | case OP_k5: | |
d83c6548 | 411 | sprintf (operand[i], "#%d", |
33822a8e | 412 | (int) (((signed char) opcode & 0x1F) << 3) >> 3); |
5c84d377 TW |
413 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
414 | break; | |
415 | case OP_k8u: | |
33822a8e | 416 | sprintf (operand[i], "#%d", (unsigned) (opcode & 0xFF)); |
5c84d377 TW |
417 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
418 | break; | |
419 | case OP_k3: | |
33822a8e | 420 | sprintf (operand[i], "#%d", (int) (opcode & 0x7)); |
5c84d377 TW |
421 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
422 | break; | |
423 | case OP_lku: | |
33822a8e | 424 | sprintf (operand[i], "#%d", (unsigned) opcode2); |
5c84d377 TW |
425 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
426 | break; | |
427 | case OP_N: | |
428 | n = (opcode >> 9) & 0x1; | |
429 | sprintf (operand[i], "st%d", n); | |
430 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
431 | break; | |
432 | case OP_SBIT: | |
433 | { | |
434 | const char *status0[] = { | |
d83c6548 | 435 | "0", "1", "2", "3", "4", "5", "6", "7", "8", |
5c84d377 TW |
436 | "ovb", "ova", "c", "tc", "13", "14", "15" |
437 | }; | |
438 | const char *status1[] = { | |
d83c6548 | 439 | "0", "1", "2", "3", "4", |
5c84d377 TW |
440 | "cmpt", "frct", "c16", "sxm", "ovm", "10", |
441 | "intm", "hm", "xf", "cpl", "braf" | |
442 | }; | |
d83c6548 | 443 | sprintf (operand[i], "%s", |
33822a8e | 444 | n ? status1[SBIT (opcode)] : status0[SBIT (opcode)]); |
5c84d377 TW |
445 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
446 | break; | |
447 | } | |
448 | case OP_12: | |
33822a8e | 449 | sprintf (operand[i], "%d", (int) ((opcode >> 9) & 1) + 1); |
5c84d377 TW |
450 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
451 | break; | |
452 | case OP_TRN: | |
453 | sprintf (operand[i], "trn"); | |
454 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
455 | break; | |
456 | case OP_DP: | |
457 | sprintf (operand[i], "dp"); | |
458 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
459 | break; | |
460 | case OP_k9: | |
461 | /* FIXME-- this is DP, print the original address? */ | |
33822a8e | 462 | sprintf (operand[i], "#%d", (int) (opcode & 0x1FF)); |
5c84d377 TW |
463 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
464 | break; | |
465 | case OP_ARP: | |
466 | sprintf (operand[i], "arp"); | |
467 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
468 | break; | |
469 | case OP_031: | |
33822a8e | 470 | sprintf (operand[i], "%d", (int) (opcode & 0x1F)); |
5c84d377 TW |
471 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); |
472 | break; | |
473 | default: | |
474 | sprintf (operand[i], "??? (0x%x)", tm_operands[i]); | |
475 | info->fprintf_func (info->stream, "%s%s", comma, operand[i]); | |
476 | break; | |
477 | } | |
478 | comma = next_comma; | |
479 | } | |
480 | return 1; | |
481 | } | |
482 | ||
483 | static int | |
484 | print_parallel_instruction (info, memaddr, opcode, ptm, size) | |
485 | disassemble_info *info; | |
486 | bfd_vma memaddr; | |
487 | unsigned short opcode; | |
488 | partemplate *ptm; | |
489 | int size; | |
490 | { | |
d83c6548 | 491 | print_instruction (info, memaddr, opcode, |
5c84d377 TW |
492 | ptm->name, ptm->operand_types, size, 0); |
493 | info->fprintf_func (info->stream, " || "); | |
d83c6548 | 494 | return print_instruction (info, memaddr, opcode, |
5c84d377 TW |
495 | ptm->parname, ptm->paroperand_types, size, 0); |
496 | } | |
497 | ||
498 | static int | |
499 | sprint_dual_address (info, buf, code) | |
d83c6548 | 500 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
501 | char buf[]; |
502 | unsigned short code; | |
503 | { | |
504 | const char *formats[] = { | |
505 | "*ar%d", | |
506 | "*ar%d-", | |
507 | "*ar%d+", | |
508 | "*ar%d+0%%", | |
509 | }; | |
33822a8e | 510 | return sprintf (buf, formats[XMOD (code)], XARX (code)); |
5c84d377 TW |
511 | } |
512 | ||
513 | static int | |
514 | sprint_indirect_address (info, buf, opcode) | |
d83c6548 | 515 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
516 | char buf[]; |
517 | unsigned short opcode; | |
518 | { | |
519 | const char *formats[] = { | |
520 | "*ar%d", | |
521 | "*ar%d-", | |
522 | "*ar%d+", | |
523 | "*+ar%d", | |
524 | "*ar%d-0B", | |
525 | "*ar%d-0", | |
526 | "*ar%d+0", | |
527 | "*ar%d+0B", | |
528 | "*ar%d-%%", | |
529 | "*ar%d-0%%", | |
530 | "*ar%d+%%", | |
531 | "*ar%d+0%%", | |
532 | }; | |
33822a8e | 533 | return sprintf (buf, formats[MOD (opcode)], ARF (opcode)); |
5c84d377 TW |
534 | } |
535 | ||
536 | static int | |
537 | sprint_direct_address (info, buf, opcode) | |
d83c6548 | 538 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
539 | char buf[]; |
540 | unsigned short opcode; | |
541 | { | |
542 | /* FIXME -- look up relocation if available */ | |
33822a8e | 543 | return sprintf (buf, "0x??%02x", (int) (opcode & 0x7F)); |
5c84d377 TW |
544 | } |
545 | ||
546 | static int | |
547 | sprint_mmr (info, buf, mmr) | |
d83c6548 | 548 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
549 | char buf[]; |
550 | int mmr; | |
551 | { | |
33822a8e | 552 | symbol *reg = (symbol *) mmregs; |
5c84d377 TW |
553 | while (reg->name != NULL) |
554 | { | |
555 | if (mmr == reg->value) | |
556 | { | |
33822a8e | 557 | sprintf (buf, "%s", (reg + 1)->name); |
5c84d377 TW |
558 | return 1; |
559 | } | |
560 | ++reg; | |
561 | } | |
d1e28e24 | 562 | sprintf (buf, "MMR(%d)", mmr); /* FIXME -- different targets. */ |
5c84d377 TW |
563 | return 0; |
564 | } | |
565 | ||
566 | static int | |
567 | sprint_cc2 (info, buf, opcode) | |
d83c6548 | 568 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
569 | char *buf; |
570 | unsigned short opcode; | |
571 | { | |
572 | const char *cc2[] = { | |
573 | "??", "??", "ageq", "alt", "aneq", "aeq", "agt", "aleq", | |
574 | "??", "??", "bgeq", "blt", "bneq", "beq", "bgt", "bleq", | |
575 | }; | |
576 | return sprintf (buf, "%s", cc2[opcode & 0xF]); | |
577 | } | |
578 | ||
579 | static int | |
580 | sprint_condition (info, buf, opcode) | |
d83c6548 | 581 | disassemble_info *info ATTRIBUTE_UNUSED; |
5c84d377 TW |
582 | char *buf; |
583 | unsigned short opcode; | |
584 | { | |
585 | char *start = buf; | |
586 | const char *cmp[] = { | |
587 | "??", "??", "geq", "lt", "neq", "eq", "gt", "leq" | |
588 | }; | |
589 | if (opcode & 0x40) | |
590 | { | |
591 | char acc = (opcode & 0x8) ? 'b' : 'a'; | |
592 | if (opcode & 0x7) | |
33822a8e KH |
593 | buf += sprintf (buf, "%c%s%s", acc, cmp[(opcode & 0x7)], |
594 | (opcode & 0x20) ? ", " : ""); | |
5c84d377 | 595 | if (opcode & 0x20) |
33822a8e | 596 | buf += sprintf (buf, "%c%s", acc, (opcode & 0x10) ? "ov" : "nov"); |
5c84d377 TW |
597 | } |
598 | else if (opcode & 0x3F) | |
599 | { | |
600 | if (opcode & 0x30) | |
d83c6548 | 601 | buf += sprintf (buf, "%s%s", |
5c84d377 TW |
602 | ((opcode & 0x30) == 0x30) ? "tc" : "ntc", |
603 | (opcode & 0x0F) ? ", " : ""); | |
604 | if (opcode & 0x0C) | |
d83c6548 | 605 | buf += sprintf (buf, "%s%s", |
5c84d377 TW |
606 | ((opcode & 0x0C) == 0x0C) ? "c" : "nc", |
607 | (opcode & 0x03) ? ", " : ""); | |
608 | if (opcode & 0x03) | |
d83c6548 | 609 | buf += sprintf (buf, "%s", |
5c84d377 TW |
610 | ((opcode & 0x03) == 0x03) ? "bio" : "nbio"); |
611 | } | |
612 | else | |
613 | buf += sprintf (buf, "unc"); | |
614 | ||
615 | return buf - start; | |
616 | } |