1 /* This file has been modified by Data General Corporation, November 1989. */
4 #include "m88k-opcode.h"
8 void sprint_address ();
10 /* Changed hashtab to hashtable to avoid naming conflict
11 with libdc.o (used for tdesc) for m88k.
14 INSTAB *hashtable[HASHVAL] = {0};
17 * Disassemble an M88000 Instruction
20 * This module decodes the first instruction in inbuf. It uses the pc
21 * to display pc-relative displacements. It writes the disassembled
22 * instruction in outbuf.
26 * Revision 1.0 11/08/85 Creation date by Motorola
27 * 05/11/89 R. Trawick adapted to GDB interface.
31 print_insn (memaddr, stream)
35 unsigned char buffer[MAXLEN];
36 /* should be expanded if disassembler prints symbol names */
40 /* Instruction addresses may have low two bits set. Clear them. */
42 read_memory (memaddr, buffer, MAXLEN);
44 n = m88kdis ((int)memaddr, buffer, outbuf);
46 fputs (outbuf, stream);
52 * disassemble the first instruction in 'inbuf'.
53 * 'pc' should be the address of this instruction, it will
54 * be used to print the target address if this is a relative jump or call
55 * 'outbuf' gets filled in with the disassembled instruction. It should
56 * be long enough to hold the longest disassembled instruction.
57 * 100 bytes is certainly enough, unless symbol printing is added later
58 * The function returns the length of this instruction in bytes.
61 int m88kdis( pc, inbuf, outbuf )
67 { static ihashtab_initialized = 0;
76 if (!ihashtab_initialized) {
80 /* create a the appropriate mask to isolate the opcode */
82 class= instruction & DEFMASK;
83 if ((class >= SFU0) && (class <= SFU7)) {
84 if (instruction < SFU1) {
89 } else if (class == RRR) {
91 } else if (class == RRI10) {
95 /* isolate the opcode */
96 opcode= instruction & opmask;
98 /* search the hash table with the isolated opcode */
99 for (entry_ptr= hashtable[ opcode % HASHVAL ];
100 (entry_ptr != NULL) && (entry_ptr->opcode != opcode);
101 entry_ptr= entry_ptr->next) {
104 if (entry_ptr == NULL) {
105 sprintf( outbuf, "word\t%08x", instruction );
107 sprintf( outbuf, "%s\t", entry_ptr->mnemonic );
108 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op1), instruction, pc, 1 );
109 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op2), instruction, pc, 0 );
110 sprintop( &outbuf[strlen(outbuf)], &(entry_ptr->op3), instruction, pc, 0 );
119 * Decode an Operand of an Instruction
121 * Functional Description
123 * This module formats and writes an operand of an instruction to buf
124 * based on the operand specification. When the first flag is set this
125 * is the first operand of an instruction. Undefined operand types
126 * cause a <dis error> message.
129 * char *buf buffer where the operand may be printed
130 * OPSPEC *opptr Pointer to an operand specification
131 * UINT inst Instruction from which operand is extracted
132 * UINT pc PC of instruction; used for pc-relative disp.
133 * int first Flag which if nonzero indicates the first
134 * operand of an instruction
138 * The operand specified is extracted from the instruction and is
139 * written to buf in the format specified. The operand is preceded
140 * by a comma if it is not the first operand of an instruction and it
141 * is not a register indirect form. Registers are preceded by 'r' and
142 * hex values by '0x'.
146 * Revision 1.0 11/08/85 Creation date
149 sprintop( buf, opptr, inst, pc, first )
157 { int extracted_field;
159 char cond_mask_sym_buf[6];
161 if (opptr->width == 0)
164 switch(opptr->type) {
168 sprintf( buf, "cr%d", UEXT(inst,opptr->offset,opptr->width));
174 sprintf( buf, "fcr%d", UEXT(inst,opptr->offset,opptr->width));
178 sprintf( buf, "[r%d]", UEXT(inst,opptr->offset,opptr->width));
184 sprintf( buf, "r%d", UEXT(inst,opptr->offset,opptr->width));
190 extracted_field= UEXT(inst, opptr->offset, opptr->width);
191 if (extracted_field == 0) {
194 sprintf( buf, "0x%02x", extracted_field );
201 extracted_field= UEXT(inst, opptr->offset, opptr->width);
202 switch (extracted_field & 0x0f) {
203 case 0x1: cond_mask_sym= "gt0";
205 case 0x2: cond_mask_sym= "eq0";
207 case 0x3: cond_mask_sym= "ge0";
209 case 0xc: cond_mask_sym= "lt0";
211 case 0xd: cond_mask_sym= "ne0";
213 case 0xe: cond_mask_sym= "le0";
215 default: cond_mask_sym= cond_mask_sym_buf;
216 sprintf( cond_mask_sym_buf,
221 strcpy( buf, cond_mask_sym );
227 sprint_address( pc + 4*(SEXT(inst,opptr->offset,opptr->width)),
234 UEXT(inst,opptr->offset,5),
235 UEXT(inst,(opptr->offset)+5,5) );
243 UEXT(inst,(opptr->offset)+5,5),
244 UEXT(inst,opptr->offset,5));
248 sprintf( buf, "<dis error: %08x>", inst );
254 * Initialize the Disassembler Instruction Table
256 * Initialize the hash table and instruction table for the disassembler.
257 * This should be called once before the first call to disasm().
263 * If the debug option is selected, certain statistics about the hashing
264 * distribution are written to stdout.
268 * Revision 1.0 11/08/85 Creation date
275 for (i=0 ; i < HASHVAL ; i++)
278 for (i=0, size = sizeof(instructions) / sizeof(INSTAB) ; i < size ;
279 install(&instructions[i++]));
284 * Insert an instruction into the disassembler table by hashing the
285 * opcode and inserting it into the linked list for that hash value.
289 * INSTAB *instptr Pointer to the entry in the instruction table
292 * Revision 1.0 11/08/85 Creation date
293 * 05/11/89 R. TRAWICK ADAPTED FROM MOTOROLA
301 i = (instptr->opcode) % HASHVAL;
302 instptr->next = hashtable[i];
303 hashtable[i] = instptr;
307 /* adapted from print_address in printcmd by R. Trawick 5/15/89. The two should
311 void sprint_address (addr, buffer)
322 sprintf ( buffer, "0x%x", addr);
324 fs = find_pc_function (addr);
327 i = find_pc_misc_function (addr);
329 if (i < 0) return; /* If nothing comes through, don't
330 print anything symbolic */
332 name = misc_function_vector[i].name;
333 name_location = misc_function_vector[i].address;
336 name_location = BLOCK_START (SYMBOL_BLOCK_VALUE (fs));
339 if (addr - name_location)
340 sprintf (buffer, " <%s+%d>", name, addr - name_location);
342 sprintf (buffer, " <%s>", name);