CARP: Delete ABOUT_TO_RETURN across all targets.
[deliverable/binutils-gdb.git] / gdb / gould-tdep.c
CommitLineData
18b46e7c 1/* GOULD RISC target-dependent code for GDB, the GNU debugger.
7d9884b9 2 Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
dd3b648e
RP
3
4This file is part of GDB.
5
99a7de40 6This program is free software; you can redistribute it and/or modify
dd3b648e 7it under the terms of the GNU General Public License as published by
99a7de40
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
dd3b648e 10
99a7de40 11This program is distributed in the hope that it will be useful,
dd3b648e
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
99a7de40 17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
dd3b648e 19
dd3b648e 20#include "defs.h"
dd3b648e
RP
21#include "symtab.h"
22#include "frame.h"
7d9884b9 23#include "gdbcore.h"
dd3b648e 24#if defined GOULD_PN
aab77d5f 25#include "opcode/pn.h"
dd3b648e 26#else
aab77d5f 27#include "opcode/np1.h"
dd3b648e
RP
28#endif
29
30/* GOULD RISC instructions are never longer than this many bytes. */
31#define MAXLEN 4
32
33/* Number of elements in the opcode table. */
34#define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
35
98760eab
AC
36/* Both gcc and cc return small structs in registers (i.e. in GDB
37 terminology, small structs don't use the struct return convention). */
38int
39gould_use_struct_convention (gcc_p, type)
40 int gcc_p;
41 struct type *type;
42{
43 return (TYPE_LENGTH(type) > 8);
44}
45
46
dd3b648e
RP
47\f
48/* Print the GOULD instruction at address MEMADDR in debugged memory,
49 on STREAM. Returns length of the instruction, in bytes. */
50
51int
18b46e7c
SS
52gould_print_insn (memaddr, stream)
53 CORE_ADDR memaddr;
54 FILE *stream;
dd3b648e
RP
55{
56 unsigned char buffer[MAXLEN];
57 register int i;
58 register char *d;
59 register int bestmask;
60 unsigned best;
61 int temp, index, bestlen;
62
63 read_memory (memaddr, buffer, MAXLEN);
64
65 bestmask = 0;
66 index = -1;
67 best = 0xffffffff;
68 for (i = 0; i < NOPCODES; i++)
69 {
70 register unsigned int opcode = gld_opcodes[i].opcode;
71 register unsigned int mask = gld_opcodes[i].mask;
72 register unsigned int len = gld_opcodes[i].length;
73 register unsigned int test;
74
75 /* Get possible opcode bytes into integer */
76 test = buffer[0] << 24;
77 test |= buffer[1] << 16;
78 test |= buffer[2] << 8;
79 test |= buffer[3];
80
81 /* Mask with opcode and see if match */
82 if ((opcode & mask) == (test & mask))
83 {
84 /* See if second or third match */
85 if (index >= 0)
86 {
87 /* Take new one if it looks good */
88 if (bestlen == MAXLEN && len == MAXLEN)
89 {
90 /* See if lower bits matched */
91 if (((bestmask & 3) == 0) &&
92 ((mask & 3) != 0))
93 {
94 bestmask = mask;
95 bestlen = len;
96 best = test;
97 index = i;
98 }
99 }
100 }
101 else
102 {
103 /* First match, save it */
104 bestmask = mask;
105 bestlen = len;
106 best = test;
107 index = i;
108 }
109 }
110 }
111
112 /* Handle undefined instructions. */
113 if (index < 0)
114 {
115 fprintf (stream, "undefined 0%o",(buffer[0]<<8)+buffer[1]);
116 return 2;
117 }
118
119 /* Print instruction name */
120 fprintf (stream, "%-12s", gld_opcodes[index].name);
121
122 /* Adjust if short instruction */
123 if (gld_opcodes[index].length < 4)
124 {
125 best >>= 16;
126 i = 0;
127 }
128 else
129 {
130 i = 16;
131 }
132
133 /* Dump out instruction arguments */
134 for (d = gld_opcodes[index].args; *d; ++d)
135 {
136 switch (*d)
137 {
138 case 'f':
139 fprintf (stream, "%d", (best >> (7 + i)) & 7);
140 break;
141 case 'r':
142 fprintf (stream, "r%d", (best >> (7 + i)) & 7);
143 break;
144 case 'R':
145 fprintf (stream, "r%d", (best >> (4 + i)) & 7);
146 break;
147 case 'b':
148 fprintf (stream, "b%d", (best >> (7 + i)) & 7);
149 break;
150 case 'B':
151 fprintf (stream, "b%d", (best >> (4 + i)) & 7);
152 break;
153 case 'v':
154 fprintf (stream, "b%d", (best >> (7 + i)) & 7);
155 break;
156 case 'V':
157 fprintf (stream, "b%d", (best >> (4 + i)) & 7);
158 break;
159 case 'X':
160 temp = (best >> 20) & 7;
161 if (temp)
162 fprintf (stream, "r%d", temp);
163 else
164 putc ('0', stream);
165 break;
166 case 'A':
167 temp = (best >> 16) & 7;
168 if (temp)
169 fprintf (stream, "(b%d)", temp);
170 break;
171 case 'S':
172 fprintf (stream, "#%d", best & 0x1f);
173 break;
174 case 'I':
175 fprintf (stream, "#%x", best & 0xffff);
176 break;
177 case 'O':
178 fprintf (stream, "%x", best & 0xffff);
179 break;
180 case 'h':
181 fprintf (stream, "%d", best & 0xfffe);
182 break;
183 case 'd':
184 fprintf (stream, "%d", best & 0xfffc);
185 break;
186 case 'T':
187 fprintf (stream, "%d", (best >> 8) & 0xff);
188 break;
189 case 'N':
190 fprintf (stream, "%d", best & 0xff);
191 break;
192 default:
193 putc (*d, stream);
194 break;
195 }
196 }
197
198 /* Return length of instruction */
199 return (gld_opcodes[index].length);
200}
201
202/*
203 * Find the number of arguments to a function.
204 */
205findarg(frame)
206 struct frame_info *frame;
207{
208 register struct symbol *func;
209 register unsigned pc;
210
211#ifdef notdef
212 /* find starting address of frame function */
213 pc = get_pc_function_start (frame->pc);
214
215 /* find function symbol info */
216 func = find_pc_function (pc);
217
218 /* call blockframe code to look for match */
219 if (func != NULL)
220 return (func->value.block->nsyms / sizeof(int));
221#endif
222
223 return (-1);
224}
225
226/*
227 * In the case of the NPL, the frame's norminal address is Br2 and the
228 * previous routines frame is up the stack X bytes. Finding out what
229 * 'X' is can be tricky.
230 *
231 * 1.) stored in the code function header xA(Br1).
232 * 2.) must be careful of recurssion.
233 */
1dfc8dfb 234CORE_ADDR
dd3b648e 235findframe(thisframe)
1dfc8dfb 236 struct frame_info *thisframe;
dd3b648e 237{
1dfc8dfb
SS
238 register CORE_ADDR pointer;
239 CORE_ADDR framechain();
dd3b648e
RP
240#if 0
241 struct frame_info *frame;
242
243 /* Setup toplevel frame structure */
244 frame->pc = read_pc();
245 frame->next_frame = 0;
246 frame->frame = read_register (SP_REGNUM); /* Br2 */
247
248 /* Search for this frame (start at current Br2) */
249 do
250 {
251 pointer = framechain(frame);
252 frame->next_frame = frame->frame;
253 frame->frame = pointer;
254 frame->pc = FRAME_SAVED_PC(frame);
255 }
256 while (frame->next_frame != thisframe);
257#endif
258
259 pointer = framechain (thisframe);
260
261 /* stop gap for now, end at __base3 */
262 if (thisframe->pc == 0)
263 return 0;
264
265 return pointer;
266}
267
268/*
269 * Gdb front-end and internal framechain routine.
270 * Go back up stack one level. Tricky...
271 */
1dfc8dfb 272CORE_ADDR
dd3b648e
RP
273framechain(frame)
274 register struct frame_info *frame;
275{
276 register CORE_ADDR func, prevsp;
277 register unsigned value;
278
279 /* Get real function start address from internal frame address */
280 func = get_pc_function_start(frame->pc);
281
282 /* If no stack given, read register Br1 "(sp)" */
283 if (!frame->frame)
284 prevsp = read_register (SP_REGNUM);
285 else
286 prevsp = frame->frame;
287
288 /* Check function header, case #2 */
289 value = read_memory_integer (func, 4);
290 if (value)
291 {
292 /* 32bit call push value stored in function header */
293 prevsp += value;
294 }
295 else
296 {
297 /* read half-word from suabr at start of function */
298 prevsp += read_memory_integer (func + 10, 2);
299 }
300
301 return (prevsp);
302}
This page took 0.338901 seconds and 4 git commands to generate.