1 /* Instruction printing code for the AMD 29000
2 Copyright 1990, 1993, 1994, 1995, 1998, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support. Written by Jim Kingdon.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "opcode/a29k.h"
26 static void print_general
PARAMS ((int, struct disassemble_info
*));
27 static void print_special
PARAMS ((unsigned int, struct disassemble_info
*));
28 static int is_delayed_branch
PARAMS ((int));
29 static void find_bytes_little
30 PARAMS ((char *, unsigned char *, unsigned char *, unsigned char *,
32 static void find_bytes_big
33 PARAMS ((char *, unsigned char *, unsigned char *, unsigned char *,
35 static int print_insn
PARAMS ((bfd_vma
, struct disassemble_info
*));
38 /* Print a symbolic representation of a general-purpose
39 register number NUM on STREAM.
40 NUM is a number as found in the instruction, not as found in
41 debugging symbols; it must be in the range 0-255. */
43 print_general (num
, info
)
45 struct disassemble_info
*info
;
48 (*info
->fprintf_func
) (info
->stream
, "gr%d", num
);
50 (*info
->fprintf_func
) (info
->stream
, "lr%d", num
- 128);
53 /* Like print_general but a special-purpose register.
55 The mnemonics used by the AMD assembler are not quite the same
56 as the ones in the User's Manual. We use the ones that the
59 print_special (num
, info
)
61 struct disassemble_info
*info
;
63 /* Register names of registers 0-SPEC0_NUM-1. */
64 static char *spec0_names
[] = {
65 "vab", "ops", "cps", "cfg", "cha", "chd", "chc", "rbp", "tmc", "tmr",
66 "pc0", "pc1", "pc2", "mmu", "lru", "rsn", "rma0", "rmc0", "rma1", "rmc1",
67 "spc0", "spc1", "spc2", "iba0", "ibc0", "iba1", "ibc1", "dba", "dbc",
70 #define SPEC0_NUM ((sizeof spec0_names) / (sizeof spec0_names[0]))
72 /* Register names of registers 128-128+SPEC128_NUM-1. */
73 static char *spec128_names
[] = {
74 "ipc", "ipa", "ipb", "q", "alu", "bp", "fc", "cr"
76 #define SPEC128_NUM ((sizeof spec128_names) / (sizeof spec128_names[0]))
78 /* Register names of registers 160-160+SPEC160_NUM-1. */
79 static char *spec160_names
[] = {
80 "fpe", "inte", "fps", "sr163", "exop"
82 #define SPEC160_NUM ((sizeof spec160_names) / (sizeof spec160_names[0]))
85 (*info
->fprintf_func
) (info
->stream
, spec0_names
[num
]);
86 else if (num
>= 128 && num
< 128 + SPEC128_NUM
)
87 (*info
->fprintf_func
) (info
->stream
, spec128_names
[num
-128]);
88 else if (num
>= 160 && num
< 160 + SPEC160_NUM
)
89 (*info
->fprintf_func
) (info
->stream
, spec160_names
[num
-160]);
91 (*info
->fprintf_func
) (info
->stream
, "sr%d", num
);
94 /* Is an instruction with OPCODE a delayed branch? */
96 is_delayed_branch (opcode
)
99 return (opcode
== 0xa8 || opcode
== 0xa9 || opcode
== 0xa0 || opcode
== 0xa1
100 || opcode
== 0xa4 || opcode
== 0xa5
101 || opcode
== 0xb4 || opcode
== 0xb5
102 || opcode
== 0xc4 || opcode
== 0xc0
103 || opcode
== 0xac || opcode
== 0xad
107 /* Now find the four bytes of INSN and put them in *INSN{0,8,16,24}. */
109 find_bytes_big (insn
, insn0
, insn8
, insn16
, insn24
)
111 unsigned char *insn0
;
112 unsigned char *insn8
;
113 unsigned char *insn16
;
114 unsigned char *insn24
;
123 find_bytes_little (insn
, insn0
, insn8
, insn16
, insn24
)
125 unsigned char *insn0
;
126 unsigned char *insn8
;
127 unsigned char *insn16
;
128 unsigned char *insn24
;
136 typedef void (*find_byte_func_type
)
137 PARAMS ((char *, unsigned char *, unsigned char *,
138 unsigned char *, unsigned char *));
140 /* Print one instruction from MEMADDR on INFO->STREAM.
141 Return the size of the instruction (always 4 on a29k). */
144 print_insn (memaddr
, info
)
146 struct disassemble_info
*info
;
148 /* The raw instruction. */
151 /* The four bytes of the instruction. */
152 unsigned char insn24
, insn16
, insn8
, insn0
;
154 find_byte_func_type find_byte_func
= (find_byte_func_type
)info
->private_data
;
156 struct a29k_opcode
const * opcode
;
160 (*info
->read_memory_func
) (memaddr
, (bfd_byte
*) &insn
[0], 4, info
);
163 (*info
->memory_error_func
) (status
, memaddr
, info
);
168 (*find_byte_func
) (insn
, &insn0
, &insn8
, &insn16
, &insn24
);
170 printf ("%02x%02x%02x%02x ", insn24
, insn16
, insn8
, insn0
);
172 /* Handle the nop (aseq 0x40,gr1,gr1) specially */
173 if ((insn24
==0x70) && (insn16
==0x40) && (insn8
==0x01) && (insn0
==0x01)) {
174 (*info
->fprintf_func
) (info
->stream
,"nop");
178 /* The opcode is always in insn24. */
179 for (opcode
= &a29k_opcodes
[0];
180 opcode
< &a29k_opcodes
[num_opcodes
];
183 if (((unsigned long) insn24
<< 24) == opcode
->opcode
)
187 (*info
->fprintf_func
) (info
->stream
, "%s ", opcode
->name
);
188 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
193 print_general (insn8
, info
);
197 print_general (insn0
, info
);
201 print_general (insn16
, info
);
205 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
);
209 (*info
->fprintf_func
) (info
->stream
, "0x%x", (insn16
<< 8) + insn0
);
213 /* This used to be %x for binutils. */
214 (*info
->fprintf_func
) (info
->stream
, "0x%x",
215 (insn16
<< 24) + (insn0
<< 16));
219 (*info
->fprintf_func
) (info
->stream
, "%d",
220 ((insn16
<< 8) + insn0
) | 0xffff0000);
224 /* This output looks just like absolute addressing, but
225 maybe that's OK (it's what the GDB m68k and EBMON
226 a29k disassemblers do). */
227 /* All the shifting is to sign-extend it. p*/
228 (*info
->print_address_func
)
230 (((int)((insn16
<< 10) + (insn0
<< 2)) << 14) >> 14),
235 (*info
->print_address_func
)
236 ((insn16
<< 10) + (insn0
<< 2), info
);
240 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
>> 7);
244 (*info
->fprintf_func
) (info
->stream
, "0x%x", insn16
& 0x7f);
248 (*info
->fprintf_func
) (info
->stream
, "0x%x", insn16
);
252 print_special (insn8
, info
);
256 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
>> 7);
260 (*info
->fprintf_func
) (info
->stream
, "%d", (insn0
>> 4) & 7);
264 if ((insn16
& 3) != 0)
265 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
& 3);
269 (*info
->fprintf_func
) (info
->stream
, "%d", (insn0
>> 2) & 3);
273 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
& 3);
277 (*info
->fprintf_func
) (info
->stream
, "%d", (insn16
>> 2) & 15);
281 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
& 3);
285 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
289 /* Now we look for a const,consth pair of instructions,
290 in which case we try to print the symbolic address. */
291 if (insn24
== 2) /* consth */
295 unsigned char prev_insn0
, prev_insn8
, prev_insn16
, prev_insn24
;
297 errcode
= (*info
->read_memory_func
) (memaddr
- 4,
298 (bfd_byte
*) &prev_insn
[0],
303 /* If it is a delayed branch, we need to look at the
304 instruction before the delayed brach to handle
311 (*find_byte_func
) (prev_insn
, &prev_insn0
, &prev_insn8
,
312 &prev_insn16
, &prev_insn24
);
313 if (is_delayed_branch (prev_insn24
))
315 errcode
= (*info
->read_memory_func
)
316 (memaddr
- 8, (bfd_byte
*) &prev_insn
[0], 4, info
);
317 (*find_byte_func
) (prev_insn
, &prev_insn0
, &prev_insn8
,
318 &prev_insn16
, &prev_insn24
);
322 /* If there was a problem reading memory, then assume
323 the previous instruction was not const. */
326 /* Is it const to the same register? */
328 && prev_insn8
== insn8
)
330 (*info
->fprintf_func
) (info
->stream
, "\t; ");
331 (*info
->print_address_func
)
332 (((insn16
<< 24) + (insn0
<< 16)
333 + (prev_insn16
<< 8) + (prev_insn0
)),
342 /* This used to be %8x for binutils. */
343 (*info
->fprintf_func
)
344 (info
->stream
, ".word 0x%08x",
345 (insn24
<< 24) + (insn16
<< 16) + (insn8
<< 8) + insn0
);
349 /* Disassemble an big-endian a29k instruction. */
351 print_insn_big_a29k (memaddr
, info
)
353 struct disassemble_info
*info
;
355 info
->private_data
= (PTR
) find_bytes_big
;
356 return print_insn (memaddr
, info
);
359 /* Disassemble a little-endian a29k instruction. */
361 print_insn_little_a29k (memaddr
, info
)
363 struct disassemble_info
*info
;
365 info
->private_data
= (PTR
) find_bytes_little
;
366 return print_insn (memaddr
, info
);