1 /* Print instructions for the Motorola 88000, for GDB and GNU Binutils.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1993
3 Free Software Foundation, Inc.
4 Contributed by Data General Corporation, November 1989.
5 Partially derived from an earlier printcmd.c.
7 This file is part of GDB and the GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "opcode/m88k.h"
26 /* FIXME: Uses the internal bfd swapping routines. */
29 INSTAB
*hashtable
[HASHVAL
] = {0};
32 m88kdis
PARAMS ((bfd_vma
, unsigned long, struct disassemble_info
*));
35 printop
PARAMS ((struct disassemble_info
*, OPSPEC
*,
36 unsigned long, bfd_vma
, int));
39 init_disasm
PARAMS ((void));
42 install
PARAMS ((INSTAB
*instptr
));
45 * Disassemble an M88000 Instruction
48 * This module decodes the instruction at memaddr.
52 * Revision 1.0 11/08/85 Creation date by Motorola
53 * 05/11/89 R. Trawick adapted to GDB interface.
54 * 07/12/93 Ian Lance Taylor updated to
59 print_insn_m88k (memaddr
, info
)
61 struct disassemble_info
*info
;
66 /* Instruction addresses may have low two bits set. Clear them. */
67 memaddr
&=~ (bfd_vma
) 3;
69 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
72 (*info
->memory_error_func
) (status
, memaddr
, info
);
76 return m88kdis (memaddr
, _do_getb32 (buffer
), info
);
80 * disassemble the instruction in 'instruction'.
81 * 'pc' should be the address of this instruction, it will
82 * be used to print the target address if this is a relative jump or call
83 * the disassembled instruction is written to 'info'.
84 * The function returns the length of this instruction in bytes.
88 m88kdis (pc
, instruction
, info
)
90 unsigned long instruction
;
91 struct disassemble_info
*info
;
93 static int ihashtab_initialized
= 0;
99 if (! ihashtab_initialized
)
102 /* create a the appropriate mask to isolate the opcode */
104 class = instruction
& DEFMASK
;
105 if ((class >= SFU0
) && (class <= SFU7
))
107 if (instruction
< SFU1
)
112 else if (class == RRR
)
114 else if (class == RRI10
)
117 /* isolate the opcode */
118 opcode
= instruction
& opmask
;
120 /* search the hash table with the isolated opcode */
121 for (entry_ptr
= hashtable
[opcode
% HASHVAL
];
122 (entry_ptr
!= NULL
) && (entry_ptr
->opcode
!= opcode
);
123 entry_ptr
= entry_ptr
->next
)
126 if (entry_ptr
== NULL
)
127 (*info
->fprintf_func
) (info
->stream
, "word\t%08x", instruction
);
130 (*info
->fprintf_func
) (info
->stream
, "%s ", entry_ptr
->mnemonic
);
131 printop (info
, &(entry_ptr
->op1
), instruction
, pc
, 1);
132 printop (info
, &(entry_ptr
->op2
), instruction
, pc
, 0);
133 printop (info
, &(entry_ptr
->op3
), instruction
, pc
, 0);
140 * Decode an Operand of an Instruction
142 * Functional Description
144 * This module formats and writes an operand of an instruction to info
145 * based on the operand specification. When the first flag is set this
146 * is the first operand of an instruction. Undefined operand types
147 * cause a <dis error> message.
150 * disassemble_info where the operand may be printed
151 * OPSPEC *opptr Pointer to an operand specification
152 * UINT inst Instruction from which operand is extracted
153 * UINT pc PC of instruction; used for pc-relative disp.
154 * int first Flag which if nonzero indicates the first
155 * operand of an instruction
159 * The operand specified is extracted from the instruction and is
160 * written to buf in the format specified. The operand is preceded
161 * by a comma if it is not the first operand of an instruction and it
162 * is not a register indirect form. Registers are preceded by 'r' and
163 * hex values by '0x'.
167 * Revision 1.0 11/08/85 Creation date
171 printop (info
, opptr
, inst
, pc
, first
)
172 struct disassemble_info
*info
;
181 if (opptr
->width
== 0)
192 (*info
->fprintf_func
) (info
->stream
, ",");
200 (*info
->fprintf_func
) (info
->stream
, "cr%d",
201 UEXT (inst
, opptr
->offset
, opptr
->width
));
205 (*info
->fprintf_func
) (info
->stream
, "fcr%d",
206 UEXT (inst
, opptr
->offset
, opptr
->width
));
210 (*info
->fprintf_func
) (info
->stream
, "[r%d]",
211 UEXT (inst
, opptr
->offset
, opptr
->width
));
215 (*info
->fprintf_func
) (info
->stream
, "r%d",
216 UEXT (inst
, opptr
->offset
, opptr
->width
));
220 extracted_field
= UEXT (inst
, opptr
->offset
, opptr
->width
);
221 if (extracted_field
== 0)
222 (*info
->fprintf_func
) (info
->stream
, "0");
224 (*info
->fprintf_func
) (info
->stream
, "0x%02x", extracted_field
);
228 extracted_field
= UEXT (inst
, opptr
->offset
, opptr
->width
);
229 switch (extracted_field
& 0x0f)
231 case 0x1: cond_mask_sym
= "gt0"; break;
232 case 0x2: cond_mask_sym
= "eq0"; break;
233 case 0x3: cond_mask_sym
= "ge0"; break;
234 case 0xc: cond_mask_sym
= "lt0"; break;
235 case 0xd: cond_mask_sym
= "ne0"; break;
236 case 0xe: cond_mask_sym
= "le0"; break;
237 default: cond_mask_sym
= NULL
; break;
239 if (cond_mask_sym
!= NULL
)
240 (*info
->fprintf_func
) (info
->stream
, "%s", cond_mask_sym
);
242 (*info
->fprintf_func
) (info
->stream
, "%x", extracted_field
);
246 (*info
->print_address_func
)
247 (pc
+ (4 * (SEXT (inst
, opptr
->offset
, opptr
->width
))),
252 (*info
->fprintf_func
) (info
->stream
, "%d,r%d",
253 UEXT (inst
, opptr
->offset
, 5),
254 UEXT (inst
, (opptr
->offset
) + 5, 5));
258 (*info
->fprintf_func
) (info
->stream
, "%d<%d>",
259 UEXT (inst
, (opptr
->offset
) + 5, 5),
260 UEXT (inst
, opptr
->offset
, 5));
264 (*info
->fprintf_func
) (info
->stream
, "# <dis error: %08x>", inst
);
269 * Initialize the Disassembler Instruction Table
271 * Initialize the hash table and instruction table for the disassembler.
272 * This should be called once before the first call to disasm().
278 * If the debug option is selected, certain statistics about the hashing
279 * distribution are written to stdout.
283 * Revision 1.0 11/08/85 Creation date
291 for (i
= 0; i
< HASHVAL
; i
++)
294 size
= sizeof (instructions
) / sizeof (INSTAB
);
295 for (i
= 0; i
< size
; i
++)
296 install (&instructions
[i
]);
300 * Insert an instruction into the disassembler table by hashing the
301 * opcode and inserting it into the linked list for that hash value.
305 * INSTAB *instptr Pointer to the entry in the instruction table
308 * Revision 1.0 11/08/85 Creation date
309 * 05/11/89 R. TRAWICK ADAPTED FROM MOTOROLA
318 i
= (instptr
->opcode
) % HASHVAL
;
319 instptr
->next
= hashtable
[i
];
320 hashtable
[i
] = instptr
;
This page took 0.045694 seconds and 4 git commands to generate.