1 /* Instruction printing code for the AMD 29000
2 Copyright 1990, 1993, 1994, 1995, 1998, 2000
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 /* Print a symbolic representation of a general-purpose
27 register number NUM on STREAM.
28 NUM is a number as found in the instruction, not as found in
29 debugging symbols; it must be in the range 0-255. */
31 print_general (num
, info
)
33 struct disassemble_info
*info
;
36 (*info
->fprintf_func
) (info
->stream
, "gr%d", num
);
38 (*info
->fprintf_func
) (info
->stream
, "lr%d", num
- 128);
41 /* Like print_general but a special-purpose register.
43 The mnemonics used by the AMD assembler are not quite the same
44 as the ones in the User's Manual. We use the ones that the
47 print_special (num
, info
)
49 struct disassemble_info
*info
;
51 /* Register names of registers 0-SPEC0_NUM-1. */
52 static char *spec0_names
[] = {
53 "vab", "ops", "cps", "cfg", "cha", "chd", "chc", "rbp", "tmc", "tmr",
54 "pc0", "pc1", "pc2", "mmu", "lru", "rsn", "rma0", "rmc0", "rma1", "rmc1",
55 "spc0", "spc1", "spc2", "iba0", "ibc0", "iba1", "ibc1", "dba", "dbc",
58 #define SPEC0_NUM ((sizeof spec0_names) / (sizeof spec0_names[0]))
60 /* Register names of registers 128-128+SPEC128_NUM-1. */
61 static char *spec128_names
[] = {
62 "ipc", "ipa", "ipb", "q", "alu", "bp", "fc", "cr"
64 #define SPEC128_NUM ((sizeof spec128_names) / (sizeof spec128_names[0]))
66 /* Register names of registers 160-160+SPEC160_NUM-1. */
67 static char *spec160_names
[] = {
68 "fpe", "inte", "fps", "sr163", "exop"
70 #define SPEC160_NUM ((sizeof spec160_names) / (sizeof spec160_names[0]))
73 (*info
->fprintf_func
) (info
->stream
, spec0_names
[num
]);
74 else if (num
>= 128 && num
< 128 + SPEC128_NUM
)
75 (*info
->fprintf_func
) (info
->stream
, spec128_names
[num
-128]);
76 else if (num
>= 160 && num
< 160 + SPEC160_NUM
)
77 (*info
->fprintf_func
) (info
->stream
, spec160_names
[num
-160]);
79 (*info
->fprintf_func
) (info
->stream
, "sr%d", num
);
82 /* Is an instruction with OPCODE a delayed branch? */
84 is_delayed_branch (opcode
)
87 return (opcode
== 0xa8 || opcode
== 0xa9 || opcode
== 0xa0 || opcode
== 0xa1
88 || opcode
== 0xa4 || opcode
== 0xa5
89 || opcode
== 0xb4 || opcode
== 0xb5
90 || opcode
== 0xc4 || opcode
== 0xc0
91 || opcode
== 0xac || opcode
== 0xad
95 /* Now find the four bytes of INSN and put them in *INSN{0,8,16,24}. */
97 find_bytes_big (insn
, insn0
, insn8
, insn16
, insn24
)
100 unsigned char *insn8
;
101 unsigned char *insn16
;
102 unsigned char *insn24
;
111 find_bytes_little (insn
, insn0
, insn8
, insn16
, insn24
)
113 unsigned char *insn0
;
114 unsigned char *insn8
;
115 unsigned char *insn16
;
116 unsigned char *insn24
;
124 typedef void (*find_byte_func_type
)
125 PARAMS ((char *, unsigned char *, unsigned char *,
126 unsigned char *, unsigned char *));
128 /* Print one instruction from MEMADDR on INFO->STREAM.
129 Return the size of the instruction (always 4 on a29k). */
132 print_insn (memaddr
, info
)
134 struct disassemble_info
*info
;
136 /* The raw instruction. */
139 /* The four bytes of the instruction. */
140 unsigned char insn24
, insn16
, insn8
, insn0
;
142 find_byte_func_type find_byte_func
= (find_byte_func_type
)info
->private_data
;
144 struct a29k_opcode CONST
* opcode
;
148 (*info
->read_memory_func
) (memaddr
, (bfd_byte
*) &insn
[0], 4, info
);
151 (*info
->memory_error_func
) (status
, memaddr
, info
);
156 (*find_byte_func
) (insn
, &insn0
, &insn8
, &insn16
, &insn24
);
158 printf ("%02x%02x%02x%02x ", insn24
, insn16
, insn8
, insn0
);
160 /* Handle the nop (aseq 0x40,gr1,gr1) specially */
161 if ((insn24
==0x70) && (insn16
==0x40) && (insn8
==0x01) && (insn0
==0x01)) {
162 (*info
->fprintf_func
) (info
->stream
,"nop");
166 /* The opcode is always in insn24. */
167 for (opcode
= &a29k_opcodes
[0];
168 opcode
< &a29k_opcodes
[num_opcodes
];
171 if (((unsigned long) insn24
<< 24) == opcode
->opcode
)
175 (*info
->fprintf_func
) (info
->stream
, "%s ", opcode
->name
);
176 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
181 print_general (insn8
, info
);
185 print_general (insn0
, info
);
189 print_general (insn16
, info
);
193 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
);
197 (*info
->fprintf_func
) (info
->stream
, "0x%x", (insn16
<< 8) + insn0
);
201 /* This used to be %x for binutils. */
202 (*info
->fprintf_func
) (info
->stream
, "0x%x",
203 (insn16
<< 24) + (insn0
<< 16));
207 (*info
->fprintf_func
) (info
->stream
, "%d",
208 ((insn16
<< 8) + insn0
) | 0xffff0000);
212 /* This output looks just like absolute addressing, but
213 maybe that's OK (it's what the GDB m68k and EBMON
214 a29k disassemblers do). */
215 /* All the shifting is to sign-extend it. p*/
216 (*info
->print_address_func
)
218 (((int)((insn16
<< 10) + (insn0
<< 2)) << 14) >> 14),
223 (*info
->print_address_func
)
224 ((insn16
<< 10) + (insn0
<< 2), info
);
228 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
>> 7);
232 (*info
->fprintf_func
) (info
->stream
, "0x%x", insn16
& 0x7f);
236 (*info
->fprintf_func
) (info
->stream
, "0x%x", insn16
);
240 print_special (insn8
, info
);
244 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
>> 7);
248 (*info
->fprintf_func
) (info
->stream
, "%d", (insn0
>> 4) & 7);
252 if ((insn16
& 3) != 0)
253 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
& 3);
257 (*info
->fprintf_func
) (info
->stream
, "%d", (insn0
>> 2) & 3);
261 (*info
->fprintf_func
) (info
->stream
, "%d", insn0
& 3);
265 (*info
->fprintf_func
) (info
->stream
, "%d", (insn16
>> 2) & 15);
269 (*info
->fprintf_func
) (info
->stream
, "%d", insn16
& 3);
273 (*info
->fprintf_func
) (info
->stream
, "%c", *s
);
277 /* Now we look for a const,consth pair of instructions,
278 in which case we try to print the symbolic address. */
279 if (insn24
== 2) /* consth */
283 unsigned char prev_insn0
, prev_insn8
, prev_insn16
, prev_insn24
;
285 errcode
= (*info
->read_memory_func
) (memaddr
- 4,
286 (bfd_byte
*) &prev_insn
[0],
291 /* If it is a delayed branch, we need to look at the
292 instruction before the delayed brach to handle
299 (*find_byte_func
) (prev_insn
, &prev_insn0
, &prev_insn8
,
300 &prev_insn16
, &prev_insn24
);
301 if (is_delayed_branch (prev_insn24
))
303 errcode
= (*info
->read_memory_func
)
304 (memaddr
- 8, (bfd_byte
*) &prev_insn
[0], 4, info
);
305 (*find_byte_func
) (prev_insn
, &prev_insn0
, &prev_insn8
,
306 &prev_insn16
, &prev_insn24
);
310 /* If there was a problem reading memory, then assume
311 the previous instruction was not const. */
314 /* Is it const to the same register? */
316 && prev_insn8
== insn8
)
318 (*info
->fprintf_func
) (info
->stream
, "\t; ");
319 (*info
->print_address_func
)
320 (((insn16
<< 24) + (insn0
<< 16)
321 + (prev_insn16
<< 8) + (prev_insn0
)),
330 /* This used to be %8x for binutils. */
331 (*info
->fprintf_func
)
332 (info
->stream
, ".word 0x%08x",
333 (insn24
<< 24) + (insn16
<< 16) + (insn8
<< 8) + insn0
);
337 /* Disassemble an big-endian a29k instruction. */
339 print_insn_big_a29k (memaddr
, info
)
341 struct disassemble_info
*info
;
343 info
->private_data
= (PTR
) find_bytes_big
;
344 return print_insn (memaddr
, info
);
347 /* Disassemble a little-endian a29k instruction. */
349 print_insn_little_a29k (memaddr
, info
)
351 struct disassemble_info
*info
;
353 info
->private_data
= (PTR
) find_bytes_little
;
354 return print_insn (memaddr
, info
);