1 /* Print instructions for Tahoe target machines, for GDB.
2 Copyright 1986, 1989, 1991 Free Software Foundation, Inc.
3 Contributed by the State University of New York at Buffalo, by the
4 Distributed Computer Systems Lab, Department of Computer Science, 1991.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "opcode/tahoe.h"
26 /* Tahoe instructions are never longer than this. */
29 /* Number of elements in the opcode table. */
30 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
32 extern char *reg_names[];
34 static unsigned char *print_insn_arg ();
36 /* Print the Tahoe instruction at address MEMADDR in debugged memory,
37 on STREAM. Returns length of the instruction, in bytes. */
40 print_insn (memaddr, stream)
44 unsigned char buffer[MAXLEN];
46 register unsigned char *p;
49 read_memory (memaddr, buffer, MAXLEN);
51 for (i = 0; i < NOPCODES; i++)
52 if (votstrs[i].detail.code == buffer[0]
53 || votstrs[i].detail.code == *(unsigned short *)buffer)
56 /* Handle undefined instructions. */
59 fprintf (stream, "0%o", buffer[0]);
63 fprintf (stream, "%s", votstrs[i].name);
65 /* Point at first byte of argument data,
66 and at descriptor for first argument. */
67 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
68 d = votstrs[i].detail.args;
75 p = print_insn_arg (d, p, memaddr + (p - buffer), stream);
78 fprintf (stream, ",");
82 /*******************************************************************/
83 static unsigned char *
84 print_insn_arg (d, p, addr, stream)
91 register int regnum = *p & 0xf;
97 fprintf (stream, "0x%x", addr + *p++ + 1);
104 fprintf (stream, "0x%x", addr + temp1 + 2);
109 switch ((*p++ >> 4) & 0xf)
114 case 3: /* Literal (short immediate byte) mode */
115 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
117 *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
118 fprintf (stream, "$%f", floatlitbuf);
121 fprintf (stream, "$%d", p[-1] & 0x3f);
124 case 4: /* Indexed */
125 p = (char *) print_insn_arg (d, p, addr + 1, stream);
126 fprintf (stream, "[%s]", reg_names[regnum]);
129 case 5: /* Register */
130 fprintf (stream, reg_names[regnum]);
133 case 7: /* Autodecrement */
135 case 6: /* Register deferred */
136 fprintf (stream, "(%s)", reg_names[regnum]);
139 case 9: /* Absolute Address & Autoincrement deferred */
141 if (regnum == PC_REGNUM)
148 print_address (temp1, stream);
152 case 8: /*Immediate & Autoincrement SP */
153 if (regnum == 8) /*88 is Immediate Byte Mode*/
154 fprintf (stream, "$%d", *p++);
156 else if (regnum == 9) /*89 is Immediate Word Mode*/
161 fprintf (stream, "$%d", temp1);
165 else if (regnum == PC_REGNUM) /*8F is Immediate Long Mode*/
174 fprintf (stream, "$%d", temp1);
178 else /*8E is Autoincrement SP Mode*/
179 fprintf (stream, "(%s)+", reg_names[regnum]);
182 case 11: /* Register + Byte Displacement Deferred Mode*/
184 case 10: /* Register + Byte Displacement Mode*/
185 if (regnum == PC_REGNUM)
186 print_address (addr + *p + 2, stream);
188 fprintf (stream, "%d(%s)", *p, reg_names[regnum]);
192 case 13: /* Register + Word Displacement Deferred Mode*/
194 case 12: /* Register + Word Displacement Mode*/
198 if (regnum == PC_REGNUM)
199 print_address (addr + temp1 + 3, stream);
201 fprintf (stream, "%d(%s)", temp1, reg_names[regnum]);
205 case 15: /* Register + Long Displacement Deferred Mode*/
207 case 14: /* Register + Long Displacement Mode*/
215 if (regnum == PC_REGNUM)
216 print_address (addr + temp1 + 5, stream);
218 fprintf (stream, "%d(%s)", temp1, reg_names[regnum]);
222 return (unsigned char *) p;