1 /* Print instructions for the Motorola 88000, for GDB and GNU Binutils.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Data General Corporation, November 1989.
4 Partially derived from an earlier printcmd.c.
6 This file is part of GDB and the GNU Binutils.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "opcode/m88k.h"
26 void sprint_address ();
28 INSTAB *hashtable[HASHVAL] = {0};
31 * Disassemble an M88000 Instruction
34 * This module decodes the first instruction in inbuf. It uses the pc
35 * to display pc-relative displacements. It writes the disassembled
36 * instruction in outbuf.
40 * Revision 1.0 11/08/85 Creation date by Motorola
41 * 05/11/89 R. Trawick adapted to GDB interface.
45 print_insn (memaddr, stream)
49 unsigned char buffer[MAXLEN];
50 /* should be expanded if disassembler prints symbol names */
54 /* Instruction addresses may have low two bits set. Clear them. */
56 read_memory (memaddr, buffer, MAXLEN);
58 n = m88kdis ((int)memaddr, buffer, outbuf);
60 fputs (outbuf, stream);
66 * disassemble the first instruction in 'inbuf'.
67 * 'pc' should be the address of this instruction, it will
68 * be used to print the target address if this is a relative jump or call
69 * 'outbuf' gets filled in with the disassembled instruction. It should
70 * be long enough to hold the longest disassembled instruction.
71 * 100 bytes is certainly enough, unless symbol printing is added later
72 * The function returns the length of this instruction in bytes.
75 int m88kdis( pc, inbuf, outbuf )
81 { static ihashtab_initialized = 0;
90 if (!ihashtab_initialized) {
94 /* create a the appropriate mask to isolate the opcode */
96 class= instruction & DEFMASK;
97 if ((class >= SFU0) && (class <= SFU7)) {
98 if (instruction < SFU1) {
103 } else if (class == RRR) {
105 } else if (class == RRI10) {
109 /* isolate the opcode */
110 opcode= instruction & opmask;
112 /* search the hash table with the isolated opcode */
113 for (entry_ptr= hashtable[ opcode % HASHVAL ];
114 (entry_ptr != NULL) && (entry_ptr->opcode != opcode);
115 entry_ptr= entry_ptr->next) {
118 if (entry_ptr == NULL) {
119 sprintf( outbuf, "word\t%08x", instruction );
121 sprintf( outbuf, "%s\t", entry_ptr->mnemonic );
122 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op1), instruction, pc, 1 );
123 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op2), instruction, pc, 0 );
124 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op3), instruction, pc, 0 );
133 * Decode an Operand of an Instruction
135 * Functional Description
137 * This module formats and writes an operand of an instruction to buf
138 * based on the operand specification. When the first flag is set this
139 * is the first operand of an instruction. Undefined operand types
140 * cause a <dis error> message.
143 * char *buf buffer where the operand may be printed
144 * OPSPEC *opptr Pointer to an operand specification
145 * UINT inst Instruction from which operand is extracted
146 * UINT pc PC of instruction; used for pc-relative disp.
147 * int first Flag which if nonzero indicates the first
148 * operand of an instruction
152 * The operand specified is extracted from the instruction and is
153 * written to buf in the format specified. The operand is preceded
154 * by a comma if it is not the first operand of an instruction and it
155 * is not a register indirect form. Registers are preceded by 'r' and
156 * hex values by '0x'.
160 * Revision 1.0 11/08/85 Creation date
163 sprintop( buf, opptr, inst, pc, first )
171 { int extracted_field;
173 char cond_mask_sym_buf[6];
175 if (opptr->width == 0)
178 switch(opptr->type) {
182 sprintf( buf, "cr%d", UEXT(inst,opptr->offset,opptr->width));
188 sprintf( buf, "fcr%d", UEXT(inst,opptr->offset,opptr->width));
192 sprintf( buf, "[r%d]", UEXT(inst,opptr->offset,opptr->width));
198 sprintf( buf, "r%d", UEXT(inst,opptr->offset,opptr->width));
204 extracted_field= UEXT(inst, opptr->offset, opptr->width);
205 if (extracted_field == 0) {
208 sprintf( buf, "0x%02x", extracted_field );
215 extracted_field= UEXT(inst, opptr->offset, opptr->width);
216 switch (extracted_field & 0x0f) {
217 case 0x1: cond_mask_sym= "gt0";
219 case 0x2: cond_mask_sym= "eq0";
221 case 0x3: cond_mask_sym= "ge0";
223 case 0xc: cond_mask_sym= "lt0";
225 case 0xd: cond_mask_sym= "ne0";
227 case 0xe: cond_mask_sym= "le0";
229 default: cond_mask_sym= cond_mask_sym_buf;
230 sprintf( cond_mask_sym_buf,
235 strcpy( buf, cond_mask_sym );
241 sprint_address( pc + 4*(SEXT(inst,opptr->offset,opptr->width)),
248 UEXT(inst,opptr->offset,5),
249 UEXT(inst,(opptr->offset)+5,5) );
257 UEXT(inst,(opptr->offset)+5,5),
258 UEXT(inst,opptr->offset,5));
262 sprintf( buf, "<dis error: %08x>", inst );
268 * Initialize the Disassembler Instruction Table
270 * Initialize the hash table and instruction table for the disassembler.
271 * This should be called once before the first call to disasm().
277 * If the debug option is selected, certain statistics about the hashing
278 * distribution are written to stdout.
282 * Revision 1.0 11/08/85 Creation date
289 for (i=0 ; i < HASHVAL ; i++)
292 for (i=0, size = sizeof(instructions) / sizeof(INSTAB) ; i < size ;
293 install(&instructions[i++]));
298 * Insert an instruction into the disassembler table by hashing the
299 * opcode and inserting it into the linked list for that hash value.
303 * INSTAB *instptr Pointer to the entry in the instruction table
306 * Revision 1.0 11/08/85 Creation date
307 * 05/11/89 R. TRAWICK ADAPTED FROM MOTOROLA
315 i = (instptr->opcode) % HASHVAL;
316 instptr->next = hashtable[i];
317 hashtable[i] = instptr;
321 /* adapted from print_address in printcmd by R. Trawick 5/15/89. The two should
325 void sprint_address (addr, buffer)
331 struct minimal_symbol *msymbol;
336 sprintf ( buffer, "0x%x", addr);
338 fs = find_pc_function (addr);
341 msymbol = lookup_minimal_symbol_by_pc (addr);
343 if (msymbol == NULL) return; /* If nothing comes through, don't
344 print anything symbolic */
346 name = SYMBOL_NAME (msymbol);
347 name_location = SYMBOL_VALUE_ADDRESS (msymbol);
349 name = SYMBOL_NAME (fs);
350 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (fs));
353 if (addr - name_location)
354 sprintf (buffer, " <%s+%d>", name, addr - name_location);
356 sprintf (buffer, " <%s>", name);