1 /* GOULD RISC target-dependent code for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
25 #include "opcode/pn.h"
27 #include "opcode/np1.h"
30 /* GOULD RISC instructions are never longer than this many bytes. */
33 /* Number of elements in the opcode table. */
34 #define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
37 gould_frame_chain_valid (chain
, fi
)
39 struct frame_info
*fi
; /* not used here */
41 return (chain
!= 0 && chain
!= (thisframe
)->frame
);
44 /* Both gcc and cc return small structs in registers (i.e. in GDB
45 terminology, small structs don't use the struct return convention). */
47 gould_use_struct_convention (gcc_p
, type
)
51 return (TYPE_LENGTH(type
) > 8);
56 /* Print the GOULD instruction at address MEMADDR in debugged memory,
57 on STREAM. Returns length of the instruction, in bytes. */
60 gould_print_insn (memaddr
, stream
)
64 unsigned char buffer
[MAXLEN
];
67 register int bestmask
;
69 int temp
, index
, bestlen
;
71 read_memory (memaddr
, buffer
, MAXLEN
);
76 for (i
= 0; i
< NOPCODES
; i
++)
78 register unsigned int opcode
= gld_opcodes
[i
].opcode
;
79 register unsigned int mask
= gld_opcodes
[i
].mask
;
80 register unsigned int len
= gld_opcodes
[i
].length
;
81 register unsigned int test
;
83 /* Get possible opcode bytes into integer */
84 test
= buffer
[0] << 24;
85 test
|= buffer
[1] << 16;
86 test
|= buffer
[2] << 8;
89 /* Mask with opcode and see if match */
90 if ((opcode
& mask
) == (test
& mask
))
92 /* See if second or third match */
95 /* Take new one if it looks good */
96 if (bestlen
== MAXLEN
&& len
== MAXLEN
)
98 /* See if lower bits matched */
99 if (((bestmask
& 3) == 0) &&
111 /* First match, save it */
120 /* Handle undefined instructions. */
123 fprintf (stream
, "undefined 0%o",(buffer
[0]<<8)+buffer
[1]);
127 /* Print instruction name */
128 fprintf (stream
, "%-12s", gld_opcodes
[index
].name
);
130 /* Adjust if short instruction */
131 if (gld_opcodes
[index
].length
< 4)
141 /* Dump out instruction arguments */
142 for (d
= gld_opcodes
[index
].args
; *d
; ++d
)
147 fprintf (stream
, "%d", (best
>> (7 + i
)) & 7);
150 fprintf (stream
, "r%d", (best
>> (7 + i
)) & 7);
153 fprintf (stream
, "r%d", (best
>> (4 + i
)) & 7);
156 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
159 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
162 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
165 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
168 temp
= (best
>> 20) & 7;
170 fprintf (stream
, "r%d", temp
);
175 temp
= (best
>> 16) & 7;
177 fprintf (stream
, "(b%d)", temp
);
180 fprintf (stream
, "#%d", best
& 0x1f);
183 fprintf (stream
, "#%x", best
& 0xffff);
186 fprintf (stream
, "%x", best
& 0xffff);
189 fprintf (stream
, "%d", best
& 0xfffe);
192 fprintf (stream
, "%d", best
& 0xfffc);
195 fprintf (stream
, "%d", (best
>> 8) & 0xff);
198 fprintf (stream
, "%d", best
& 0xff);
206 /* Return length of instruction */
207 return (gld_opcodes
[index
].length
);
211 * Find the number of arguments to a function.
214 struct frame_info
*frame
;
216 register struct symbol
*func
;
217 register unsigned pc
;
220 /* find starting address of frame function */
221 pc
= get_pc_function_start (frame
->pc
);
223 /* find function symbol info */
224 func
= find_pc_function (pc
);
226 /* call blockframe code to look for match */
228 return (func
->value
.block
->nsyms
/ sizeof(int));
235 * In the case of the NPL, the frame's norminal address is Br2 and the
236 * previous routines frame is up the stack X bytes. Finding out what
237 * 'X' is can be tricky.
239 * 1.) stored in the code function header xA(Br1).
240 * 2.) must be careful of recurssion.
244 struct frame_info
*thisframe
;
246 register CORE_ADDR pointer
;
247 CORE_ADDR
framechain();
249 struct frame_info
*frame
;
251 /* Setup toplevel frame structure */
252 frame
->pc
= read_pc();
253 frame
->next_frame
= 0;
254 frame
->frame
= read_register (SP_REGNUM
); /* Br2 */
256 /* Search for this frame (start at current Br2) */
259 pointer
= framechain(frame
);
260 frame
->next_frame
= frame
->frame
;
261 frame
->frame
= pointer
;
262 frame
->pc
= FRAME_SAVED_PC(frame
);
264 while (frame
->next_frame
!= thisframe
);
267 pointer
= framechain (thisframe
);
269 /* stop gap for now, end at __base3 */
270 if (thisframe
->pc
== 0)
277 * Gdb front-end and internal framechain routine.
278 * Go back up stack one level. Tricky...
282 register struct frame_info
*frame
;
284 register CORE_ADDR func
, prevsp
;
285 register unsigned value
;
287 /* Get real function start address from internal frame address */
288 func
= get_pc_function_start(frame
->pc
);
290 /* If no stack given, read register Br1 "(sp)" */
292 prevsp
= read_register (SP_REGNUM
);
294 prevsp
= frame
->frame
;
296 /* Check function header, case #2 */
297 value
= read_memory_integer (func
, 4);
300 /* 32bit call push value stored in function header */
305 /* read half-word from suabr at start of function */
306 prevsp
+= read_memory_integer (func
+ 10, 2);