7e0426035f181c8a7ba4b63ab3ff4a185f72c8c3
[deliverable/binutils-gdb.git] / gdb / vax-tdep.c
1 /* Print VAX instructions for GDB, the GNU debugger.
2 Copyright 1986, 1989, 1991, 1992, 1996 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "defs.h"
21 #include "symtab.h"
22 #include "opcode/vax.h"
23
24 /* Vax instructions are never longer than this. */
25 #define MAXLEN 62
26
27 /* Number of elements in the opcode table. */
28 #define NOPCODES (sizeof votstrs / sizeof votstrs[0])
29
30 static unsigned char *print_insn_arg ();
31 \f
32 /* Advance PC across any function entry prologue instructions
33 to reach some "real" code. */
34
35 CORE_ADDR
36 vax_skip_prologue (pc)
37 CORE_ADDR pc;
38 {
39 register int op = (unsigned char) read_memory_integer (pc, 1);
40 if (op == 0x11)
41 pc += 2; /* skip brb */
42 if (op == 0x31)
43 pc += 3; /* skip brw */
44 if (op == 0xC2
45 && ((unsigned char) read_memory_integer (pc+2, 1)) == 0x5E)
46 pc += 3; /* skip subl2 */
47 if (op == 0x9E
48 && ((unsigned char) read_memory_integer (pc+1, 1)) == 0xAE
49 && ((unsigned char) read_memory_integer(pc+3, 1)) == 0x5E)
50 pc += 4; /* skip movab */
51 if (op == 0x9E
52 && ((unsigned char) read_memory_integer (pc+1, 1)) == 0xCE
53 && ((unsigned char) read_memory_integer(pc+4, 1)) == 0x5E)
54 pc += 5; /* skip movab */
55 if (op == 0x9E
56 && ((unsigned char) read_memory_integer (pc+1, 1)) == 0xEE
57 && ((unsigned char) read_memory_integer(pc+6, 1)) == 0x5E)
58 pc += 7; /* skip movab */
59 return pc;
60 }
61
62 /* Print the vax instruction at address MEMADDR in debugged memory,
63 from disassembler info INFO.
64 Returns length of the instruction, in bytes. */
65
66 static int
67 vax_print_insn (memaddr, info)
68 CORE_ADDR memaddr;
69 disassemble_info *info;
70 {
71 unsigned char buffer[MAXLEN];
72 register int i;
73 register unsigned char *p;
74 register char *d;
75
76 int status = (*info->read_memory_func) (memaddr, buffer, MAXLEN, info);
77 if (status != 0)
78 {
79 (*info->memory_error_func) (status, memaddr, info);
80 return -1;
81 }
82
83 for (i = 0; i < NOPCODES; i++)
84 if (votstrs[i].detail.code == buffer[0]
85 || votstrs[i].detail.code == *(unsigned short *)buffer)
86 break;
87
88 /* Handle undefined instructions. */
89 if (i == NOPCODES)
90 {
91 (*info->fprintf_func) (info->stream, "0%o", buffer[0]);
92 return 1;
93 }
94
95 (*info->fprintf_func) (info->stream, "%s", votstrs[i].name);
96
97 /* Point at first byte of argument data,
98 and at descriptor for first argument. */
99 p = buffer + 1 + (votstrs[i].detail.code >= 0x100);
100 d = votstrs[i].detail.args;
101
102 if (*d)
103 (*info->fprintf_func) (info->stream, " ");
104
105 while (*d)
106 {
107 p = print_insn_arg (d, p, memaddr + (p - buffer), info);
108 d += 2;
109 if (*d)
110 (*info->fprintf_func) (info->stream, ",");
111 }
112 return p - buffer;
113 }
114
115 static unsigned char *
116 print_insn_arg (d, p, addr, info)
117 char *d;
118 register char *p;
119 CORE_ADDR addr;
120 disassemble_info *info;
121 {
122 register int regnum = *p & 0xf;
123 float floatlitbuf;
124
125 if (*d == 'b')
126 {
127 if (d[1] == 'b')
128 (*info->fprintf_func) (info->stream, "0x%x", addr + *p++ + 1);
129 else
130 {
131 (*info->fprintf_func) (info->stream, "0x%x", addr + *(short *)p + 2);
132 p += 2;
133 }
134 }
135 else
136 switch ((*p++ >> 4) & 0xf)
137 {
138 case 0:
139 case 1:
140 case 2:
141 case 3: /* Literal mode */
142 if (d[1] == 'd' || d[1] == 'f' || d[1] == 'g' || d[1] == 'h')
143 {
144 *(int *)&floatlitbuf = 0x4000 + ((p[-1] & 0x3f) << 4);
145 (*info->fprintf_func) (info->stream, "$%f", floatlitbuf);
146 }
147 else
148 (*info->fprintf_func) (info->stream, "$%d", p[-1] & 0x3f);
149 break;
150
151 case 4: /* Indexed */
152 p = (char *) print_insn_arg (d, p, addr + 1, info);
153 (*info->fprintf_func) (info->stream, "[%s]", REGISTER_NAME (regnum));
154 break;
155
156 case 5: /* Register */
157 (*info->fprintf_func) (info->stream, REGISTER_NAME (regnum));
158 break;
159
160 case 7: /* Autodecrement */
161 (*info->fprintf_func) (info->stream, "-");
162 case 6: /* Register deferred */
163 (*info->fprintf_func) (info->stream, "(%s)", REGISTER_NAME (regnum));
164 break;
165
166 case 9: /* Autoincrement deferred */
167 (*info->fprintf_func) (info->stream, "@");
168 if (regnum == PC_REGNUM)
169 {
170 (*info->fprintf_func) (info->stream, "#");
171 info->target = *(long *)p;
172 (*info->print_address_func) (info->target, info);
173 p += 4;
174 break;
175 }
176 case 8: /* Autoincrement */
177 if (regnum == PC_REGNUM)
178 {
179 (*info->fprintf_func) (info->stream, "#");
180 switch (d[1])
181 {
182 case 'b':
183 (*info->fprintf_func) (info->stream, "%d", *p++);
184 break;
185
186 case 'w':
187 (*info->fprintf_func) (info->stream, "%d", *(short *)p);
188 p += 2;
189 break;
190
191 case 'l':
192 (*info->fprintf_func) (info->stream, "%d", *(long *)p);
193 p += 4;
194 break;
195
196 case 'q':
197 (*info->fprintf_func) (info->stream, "0x%x%08x",
198 ((long *)p)[1], ((long *)p)[0]);
199 p += 8;
200 break;
201
202 case 'o':
203 (*info->fprintf_func) (info->stream, "0x%x%08x%08x%08x",
204 ((long *)p)[3], ((long *)p)[2],
205 ((long *)p)[1], ((long *)p)[0]);
206 p += 16;
207 break;
208
209 case 'f':
210 if (INVALID_FLOAT (p, 4))
211 (*info->fprintf_func) (info->stream,
212 "<<invalid float 0x%x>>",
213 *(int *) p);
214 else
215 (*info->fprintf_func) (info->stream, "%f", *(float *) p);
216 p += 4;
217 break;
218
219 case 'd':
220 if (INVALID_FLOAT (p, 8))
221 (*info->fprintf_func) (info->stream,
222 "<<invalid float 0x%x%08x>>",
223 ((long *)p)[1], ((long *)p)[0]);
224 else
225 (*info->fprintf_func) (info->stream, "%f", *(double *) p);
226 p += 8;
227 break;
228
229 case 'g':
230 (*info->fprintf_func) (info->stream, "g-float");
231 p += 8;
232 break;
233
234 case 'h':
235 (*info->fprintf_func) (info->stream, "h-float");
236 p += 16;
237 break;
238
239 }
240 }
241 else
242 (*info->fprintf_func) (info->stream, "(%s)+", REGISTER_NAME (regnum));
243 break;
244
245 case 11: /* Byte displacement deferred */
246 (*info->fprintf_func) (info->stream, "@");
247 case 10: /* Byte displacement */
248 if (regnum == PC_REGNUM)
249 {
250 info->target = addr + *p + 2;
251 (*info->print_address_func) (info->target, info);
252 }
253 else
254 (*info->fprintf_func) (info->stream, "%d(%s)", *p, REGISTER_NAME (regnum));
255 p += 1;
256 break;
257
258 case 13: /* Word displacement deferred */
259 (*info->fprintf_func) (info->stream, "@");
260 case 12: /* Word displacement */
261 if (regnum == PC_REGNUM)
262 {
263 info->target = addr + *(short *)p + 3;
264 (*info->print_address_func) (info->target, info);
265 }
266 else
267 (*info->fprintf_func) (info->stream, "%d(%s)",
268 *(short *)p, REGISTER_NAME (regnum));
269 p += 2;
270 break;
271
272 case 15: /* Long displacement deferred */
273 (*info->fprintf_func) (info->stream, "@");
274 case 14: /* Long displacement */
275 if (regnum == PC_REGNUM)
276 {
277 info->target = addr + *(short *)p + 5;
278 (*info->print_address_func) (info->target, info);
279 }
280 else
281 (*info->fprintf_func) (info->stream, "%d(%s)",
282 *(long *)p, REGISTER_NAME (regnum));
283 p += 4;
284 }
285
286 return (unsigned char *) p;
287 }
288
289 void
290 _initialize_vax_tdep ()
291 {
292 tm_print_insn = vax_print_insn;
293 }
This page took 0.034748 seconds and 4 git commands to generate.