* xm-sun3os4.h, xm-sun4os4.h: Enable HAVE_MMAP.
[deliverable/binutils-gdb.git] / gdb / tahoe-pinsn.c
CommitLineData
7d9884b9
JG
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.
cb173f45 5
7d9884b9
JG
6This file is part of GDB.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
cb173f45 17
7d9884b9
JG
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22#include <stdio.h>
cb173f45 23#include "defs.h"
cb173f45 24#include "symtab.h"
aab77d5f 25#include "opcode/tahoe.h"
cb173f45
JK
26
27/* Tahoe instructions are never longer than this. */
28#define MAXLEN 62
29
30/* Number of elements in the opcode table. */
31#define NOPCODES (sizeof votstrs / sizeof votstrs[0])
32
33extern char *reg_names[];
34
35static unsigned char *print_insn_arg ();
36
37/* Print the Tahoe instruction at address MEMADDR in debugged memory,
38 on STREAM. Returns length of the instruction, in bytes. */
39
40int
41print_insn (memaddr, stream)
42 CORE_ADDR memaddr;
43 FILE *stream;
44{
45 unsigned char buffer[MAXLEN];
46 register int i;
47 register unsigned char *p;
48 register char *d;
49
50 read_memory (memaddr, buffer, MAXLEN);
51
52 for (i = 0; i < NOPCODES; i++)
53 if (votstrs[i].detail.code == buffer[0]
54 || votstrs[i].detail.code == *(unsigned short *)buffer)
55 break;
56
57 /* Handle undefined instructions. */
58 if (i == NOPCODES)
59 {
60 fprintf (stream, "0%o", buffer[0]);
61 return 1;
62 }
63
64 fprintf (stream, "%s", votstrs[i].name);
65
66 /* Point at first byte of argument data,
67 and at descriptor for first argument. */
68 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
69 d = votstrs[i].detail.args;
70
71 if (*d)
72 fputc ('\t', stream);
73
74 while (*d)
75 {
76 p = print_insn_arg (d, p, memaddr + (p - buffer), stream);
77 d += 2;
78 if (*d)
79 fprintf (stream, ",");
80 }
81 return p - buffer;
82}
83/*******************************************************************/
84static unsigned char *
85print_insn_arg (d, p, addr, stream)
86 char *d;
87 register char *p;
88 CORE_ADDR addr;
89 FILE *stream;
90{
91 int temp1 = 0;
92 register int regnum = *p & 0xf;
93 float floatlitbuf;
94
95 if (*d == 'b')
96 {
97 if (d[1] == 'b')
98 fprintf (stream, "0x%x", addr + *p++ + 1);
99 else
100 {
101
102 temp1 = *p;
103 temp1 <<= 8;
104 temp1 |= *(p + 1);
105 fprintf (stream, "0x%x", addr + temp1 + 2);
106 p += 2;
107 }
108 }
109 else
110 switch ((*p++ >> 4) & 0xf)
111 {
112 case 0:
113 case 1:
114 case 2:
7d9884b9 115 case 3: /* Literal (short immediate byte) mode */
cb173f45
JK
116 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
117 {
118 *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
119 fprintf (stream, "$%f", floatlitbuf);
120 }
121 else
122 fprintf (stream, "$%d", p[-1] & 0x3f);
123 break;
124
125 case 4: /* Indexed */
126 p = (char *) print_insn_arg (d, p, addr + 1, stream);
127 fprintf (stream, "[%s]", reg_names[regnum]);
128 break;
129
130 case 5: /* Register */
131 fprintf (stream, reg_names[regnum]);
132 break;
133
134 case 7: /* Autodecrement */
135 fputc ('-', stream);
136 case 6: /* Register deferred */
137 fprintf (stream, "(%s)", reg_names[regnum]);
138 break;
139
140 case 9: /* Absolute Address & Autoincrement deferred */
141 fputc ('*', stream);
142 if (regnum == PC_REGNUM)
143 {
144 temp1 = *p;
145 temp1 <<= 8;
146 temp1 |= *(p +1);
147
148 fputc ('$', stream);
149 print_address (temp1, stream);
150 p += 4;
151 break;
152 }
153 case 8: /*Immediate & Autoincrement SP */
154 if (regnum == 8) /*88 is Immediate Byte Mode*/
155 fprintf (stream, "$%d", *p++);
156
157 else if (regnum == 9) /*89 is Immediate Word Mode*/
158 {
159 temp1 = *p;
160 temp1 <<= 8;
161 temp1 |= *(p +1);
162 fprintf (stream, "$%d", temp1);
163 p += 2;
164 }
165
166 else if (regnum == PC_REGNUM) /*8F is Immediate Long Mode*/
167 {
168 temp1 = *p;
169 temp1 <<=8;
170 temp1 |= *(p +1);
171 temp1 <<=8;
172 temp1 |= *(p +2);
173 temp1 <<= 8;
174 temp1 |= *(p +3);
175 fprintf (stream, "$%d", temp1);
176 p += 4;
177 }
178
179 else /*8E is Autoincrement SP Mode*/
180 fprintf (stream, "(%s)+", reg_names[regnum]);
181 break;
182
183 case 11: /* Register + Byte Displacement Deferred Mode*/
184 fputc ('*', stream);
185 case 10: /* Register + Byte Displacement Mode*/
186 if (regnum == PC_REGNUM)
187 print_address (addr + *p + 2, stream);
188 else
189 fprintf (stream, "%d(%s)", *p, reg_names[regnum]);
190 p += 1;
191 break;
192
193 case 13: /* Register + Word Displacement Deferred Mode*/
194 fputc ('*', stream);
195 case 12: /* Register + Word Displacement Mode*/
196 temp1 = *p;
197 temp1 <<= 8;
198 temp1 |= *(p +1);
199 if (regnum == PC_REGNUM)
200 print_address (addr + temp1 + 3, stream);
201 else
202 fprintf (stream, "%d(%s)", temp1, reg_names[regnum]);
203 p += 2;
204 break;
205
206 case 15: /* Register + Long Displacement Deferred Mode*/
207 fputc ('*', stream);
208 case 14: /* Register + Long Displacement Mode*/
209 temp1 = *p;
210 temp1 <<= 8;
211 temp1 |= *(p +1);
212 temp1 <<= 8;
213 temp1 |= *(p +2);
214 temp1 <<= 8;
215 temp1 |= *(p +3);
216 if (regnum == PC_REGNUM)
217 print_address (addr + temp1 + 5, stream);
218 else
219 fprintf (stream, "%d(%s)", temp1, reg_names[regnum]);
220 p += 4;
221 }
222
223 return (unsigned char *) p;
224}
225
226
227
228
229
230
231
232
233
234
235
236
237
This page took 0.054415 seconds and 4 git commands to generate.