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"
27 void sprint_address ();
29 INSTAB *hashtable[HASHVAL] = {0};
32 * Disassemble an M88000 Instruction
35 * This module decodes the first instruction in inbuf. It uses the pc
36 * to display pc-relative displacements. It writes the disassembled
37 * instruction in outbuf.
41 * Revision 1.0 11/08/85 Creation date by Motorola
42 * 05/11/89 R. Trawick adapted to GDB interface.
46 print_insn (memaddr, stream)
50 unsigned char buffer[MAXLEN];
51 /* should be expanded if disassembler prints symbol names */
55 /* Instruction addresses may have low two bits set. Clear them. */
57 read_memory (memaddr, buffer, MAXLEN);
59 n = m88kdis ((int)memaddr, buffer, outbuf);
61 fputs (outbuf, stream);
67 * disassemble the first instruction in 'inbuf'.
68 * 'pc' should be the address of this instruction, it will
69 * be used to print the target address if this is a relative jump or call
70 * 'outbuf' gets filled in with the disassembled instruction. It should
71 * be long enough to hold the longest disassembled instruction.
72 * 100 bytes is certainly enough, unless symbol printing is added later
73 * The function returns the length of this instruction in bytes.
76 int m88kdis( pc, inbuf, outbuf )
82 { static ihashtab_initialized = 0;
91 if (!ihashtab_initialized) {
95 /* create a the appropriate mask to isolate the opcode */
97 class= instruction & DEFMASK;
98 if ((class >= SFU0) && (class <= SFU7)) {
99 if (instruction < SFU1) {
104 } else if (class == RRR) {
106 } else if (class == RRI10) {
110 /* isolate the opcode */
111 opcode= instruction & opmask;
113 /* search the hash table with the isolated opcode */
114 for (entry_ptr= hashtable[ opcode % HASHVAL ];
115 (entry_ptr != NULL) && (entry_ptr->opcode != opcode);
116 entry_ptr= entry_ptr->next) {
119 if (entry_ptr == NULL) {
120 sprintf( outbuf, "word\t%08x", instruction );
122 sprintf( outbuf, "%s\t", entry_ptr->mnemonic );
123 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op1), instruction, pc, 1 );
124 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op2), instruction, pc, 0 );
125 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op3), instruction, pc, 0 );
134 * Decode an Operand of an Instruction
136 * Functional Description
138 * This module formats and writes an operand of an instruction to buf
139 * based on the operand specification. When the first flag is set this
140 * is the first operand of an instruction. Undefined operand types
141 * cause a <dis error> message.
144 * char *buf buffer where the operand may be printed
145 * OPSPEC *opptr Pointer to an operand specification
146 * UINT inst Instruction from which operand is extracted
147 * UINT pc PC of instruction; used for pc-relative disp.
148 * int first Flag which if nonzero indicates the first
149 * operand of an instruction
153 * The operand specified is extracted from the instruction and is
154 * written to buf in the format specified. The operand is preceded
155 * by a comma if it is not the first operand of an instruction and it
156 * is not a register indirect form. Registers are preceded by 'r' and
157 * hex values by '0x'.
161 * Revision 1.0 11/08/85 Creation date
164 sprintop( buf, opptr, inst, pc, first )
172 { int extracted_field;
174 char cond_mask_sym_buf[6];
176 if (opptr->width == 0)
179 switch(opptr->type) {
183 sprintf( buf, "cr%d", UEXT(inst,opptr->offset,opptr->width));
189 sprintf( buf, "fcr%d", UEXT(inst,opptr->offset,opptr->width));
193 sprintf( buf, "[r%d]", UEXT(inst,opptr->offset,opptr->width));
199 sprintf( buf, "r%d", UEXT(inst,opptr->offset,opptr->width));
205 extracted_field= UEXT(inst, opptr->offset, opptr->width);
206 if (extracted_field == 0) {
209 sprintf( buf, "0x%02x", extracted_field );
216 extracted_field= UEXT(inst, opptr->offset, opptr->width);
217 switch (extracted_field & 0x0f) {
218 case 0x1: cond_mask_sym= "gt0";
220 case 0x2: cond_mask_sym= "eq0";
222 case 0x3: cond_mask_sym= "ge0";
224 case 0xc: cond_mask_sym= "lt0";
226 case 0xd: cond_mask_sym= "ne0";
228 case 0xe: cond_mask_sym= "le0";
230 default: cond_mask_sym= cond_mask_sym_buf;
231 sprintf( cond_mask_sym_buf,
236 strcpy( buf, cond_mask_sym );
242 sprint_address( pc + 4*(SEXT(inst,opptr->offset,opptr->width)),
249 UEXT(inst,opptr->offset,5),
250 UEXT(inst,(opptr->offset)+5,5) );
258 UEXT(inst,(opptr->offset)+5,5),
259 UEXT(inst,opptr->offset,5));
263 sprintf( buf, "<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
290 for (i=0 ; i < HASHVAL ; i++)
293 for (i=0, size = sizeof(instructions) / sizeof(INSTAB) ; i < size ;
294 install(&instructions[i++]));
299 * Insert an instruction into the disassembler table by hashing the
300 * opcode and inserting it into the linked list for that hash value.
304 * INSTAB *instptr Pointer to the entry in the instruction table
307 * Revision 1.0 11/08/85 Creation date
308 * 05/11/89 R. TRAWICK ADAPTED FROM MOTOROLA
316 i = (instptr->opcode) % HASHVAL;
317 instptr->next = hashtable[i];
318 hashtable[i] = instptr;
322 /* adapted from print_address in printcmd by R. Trawick 5/15/89. The two should
326 void sprint_address (addr, buffer)
337 sprintf ( buffer, "0x%x", addr);
339 fs = find_pc_function (addr);
342 i = find_pc_misc_function (addr);
344 if (i < 0) return; /* If nothing comes through, don't
345 print anything symbolic */
347 name = misc_function_vector[i].name;
348 name_location = misc_function_vector[i].address;
351 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (fs));
354 if (addr - name_location)
355 sprintf (buffer, " <%s+%d>", name, addr - name_location);
357 sprintf (buffer, " <%s>", name);