Name change (It's hitacho micro systems, not hitachi data systems)
[deliverable/binutils-gdb.git] / gdb / gould-pinsn.c
1 /* Print GOULD RISC instructions for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include <stdio.h>
21 #include "defs.h"
22 #include "symtab.h"
23 #include "frame.h"
24 #include "gdbcore.h"
25 #if defined GOULD_PN
26 #include "opcode/pn.h"
27 #else
28 #include "opcode/np1.h"
29 #endif
30
31 /* GOULD RISC instructions are never longer than this many bytes. */
32 #define MAXLEN 4
33
34 /* Number of elements in the opcode table. */
35 #define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
36
37 \f
38 /* Print the GOULD instruction at address MEMADDR in debugged memory,
39 on STREAM. Returns length of the instruction, in bytes. */
40
41 int
42 print_insn (memaddr, stream)
43 CORE_ADDR memaddr;
44 FILE *stream;
45 {
46 unsigned char buffer[MAXLEN];
47 register int i;
48 register char *d;
49 register int bestmask;
50 unsigned best;
51 int temp, index, bestlen;
52
53 read_memory (memaddr, buffer, MAXLEN);
54
55 bestmask = 0;
56 index = -1;
57 best = 0xffffffff;
58 for (i = 0; i < NOPCODES; i++)
59 {
60 register unsigned int opcode = gld_opcodes[i].opcode;
61 register unsigned int mask = gld_opcodes[i].mask;
62 register unsigned int len = gld_opcodes[i].length;
63 register unsigned int test;
64
65 /* Get possible opcode bytes into integer */
66 test = buffer[0] << 24;
67 test |= buffer[1] << 16;
68 test |= buffer[2] << 8;
69 test |= buffer[3];
70
71 /* Mask with opcode and see if match */
72 if ((opcode & mask) == (test & mask))
73 {
74 /* See if second or third match */
75 if (index >= 0)
76 {
77 /* Take new one if it looks good */
78 if (bestlen == MAXLEN && len == MAXLEN)
79 {
80 /* See if lower bits matched */
81 if (((bestmask & 3) == 0) &&
82 ((mask & 3) != 0))
83 {
84 bestmask = mask;
85 bestlen = len;
86 best = test;
87 index = i;
88 }
89 }
90 }
91 else
92 {
93 /* First match, save it */
94 bestmask = mask;
95 bestlen = len;
96 best = test;
97 index = i;
98 }
99 }
100 }
101
102 /* Handle undefined instructions. */
103 if (index < 0)
104 {
105 fprintf (stream, "undefined 0%o",(buffer[0]<<8)+buffer[1]);
106 return 2;
107 }
108
109 /* Print instruction name */
110 fprintf (stream, "%-12s", gld_opcodes[index].name);
111
112 /* Adjust if short instruction */
113 if (gld_opcodes[index].length < 4)
114 {
115 best >>= 16;
116 i = 0;
117 }
118 else
119 {
120 i = 16;
121 }
122
123 /* Dump out instruction arguments */
124 for (d = gld_opcodes[index].args; *d; ++d)
125 {
126 switch (*d)
127 {
128 case 'f':
129 fprintf (stream, "%d", (best >> (7 + i)) & 7);
130 break;
131 case 'r':
132 fprintf (stream, "r%d", (best >> (7 + i)) & 7);
133 break;
134 case 'R':
135 fprintf (stream, "r%d", (best >> (4 + i)) & 7);
136 break;
137 case 'b':
138 fprintf (stream, "b%d", (best >> (7 + i)) & 7);
139 break;
140 case 'B':
141 fprintf (stream, "b%d", (best >> (4 + i)) & 7);
142 break;
143 case 'v':
144 fprintf (stream, "b%d", (best >> (7 + i)) & 7);
145 break;
146 case 'V':
147 fprintf (stream, "b%d", (best >> (4 + i)) & 7);
148 break;
149 case 'X':
150 temp = (best >> 20) & 7;
151 if (temp)
152 fprintf (stream, "r%d", temp);
153 else
154 putc ('0', stream);
155 break;
156 case 'A':
157 temp = (best >> 16) & 7;
158 if (temp)
159 fprintf (stream, "(b%d)", temp);
160 break;
161 case 'S':
162 fprintf (stream, "#%d", best & 0x1f);
163 break;
164 case 'I':
165 fprintf (stream, "#%x", best & 0xffff);
166 break;
167 case 'O':
168 fprintf (stream, "%x", best & 0xffff);
169 break;
170 case 'h':
171 fprintf (stream, "%d", best & 0xfffe);
172 break;
173 case 'd':
174 fprintf (stream, "%d", best & 0xfffc);
175 break;
176 case 'T':
177 fprintf (stream, "%d", (best >> 8) & 0xff);
178 break;
179 case 'N':
180 fprintf (stream, "%d", best & 0xff);
181 break;
182 default:
183 putc (*d, stream);
184 break;
185 }
186 }
187
188 /* Return length of instruction */
189 return (gld_opcodes[index].length);
190 }
191
192 /*
193 * Find the number of arguments to a function.
194 */
195 findarg(frame)
196 struct frame_info *frame;
197 {
198 register struct symbol *func;
199 register unsigned pc;
200
201 #ifdef notdef
202 /* find starting address of frame function */
203 pc = get_pc_function_start (frame->pc);
204
205 /* find function symbol info */
206 func = find_pc_function (pc);
207
208 /* call blockframe code to look for match */
209 if (func != NULL)
210 return (func->value.block->nsyms / sizeof(int));
211 #endif
212
213 return (-1);
214 }
215
216 /*
217 * In the case of the NPL, the frame's norminal address is Br2 and the
218 * previous routines frame is up the stack X bytes. Finding out what
219 * 'X' is can be tricky.
220 *
221 * 1.) stored in the code function header xA(Br1).
222 * 2.) must be careful of recurssion.
223 */
224 FRAME_ADDR
225 findframe(thisframe)
226 FRAME thisframe;
227 {
228 register FRAME_ADDR pointer;
229 FRAME_ADDR framechain();
230 #if 0
231 struct frame_info *frame;
232
233 /* Setup toplevel frame structure */
234 frame->pc = read_pc();
235 frame->next_frame = 0;
236 frame->frame = read_register (SP_REGNUM); /* Br2 */
237
238 /* Search for this frame (start at current Br2) */
239 do
240 {
241 pointer = framechain(frame);
242 frame->next_frame = frame->frame;
243 frame->frame = pointer;
244 frame->pc = FRAME_SAVED_PC(frame);
245 }
246 while (frame->next_frame != thisframe);
247 #endif
248
249 pointer = framechain (thisframe);
250
251 /* stop gap for now, end at __base3 */
252 if (thisframe->pc == 0)
253 return 0;
254
255 return pointer;
256 }
257
258 /*
259 * Gdb front-end and internal framechain routine.
260 * Go back up stack one level. Tricky...
261 */
262 FRAME_ADDR
263 framechain(frame)
264 register struct frame_info *frame;
265 {
266 register CORE_ADDR func, prevsp;
267 register unsigned value;
268
269 /* Get real function start address from internal frame address */
270 func = get_pc_function_start(frame->pc);
271
272 /* If no stack given, read register Br1 "(sp)" */
273 if (!frame->frame)
274 prevsp = read_register (SP_REGNUM);
275 else
276 prevsp = frame->frame;
277
278 /* Check function header, case #2 */
279 value = read_memory_integer (func, 4);
280 if (value)
281 {
282 /* 32bit call push value stored in function header */
283 prevsp += value;
284 }
285 else
286 {
287 /* read half-word from suabr at start of function */
288 prevsp += read_memory_integer (func + 10, 2);
289 }
290
291 return (prevsp);
292 }
This page took 0.037611 seconds and 4 git commands to generate.