1 /* Print GOULD RISC instructions 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., 675 Mass Ave, Cambridge, MA 02139, 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 /* Print the GOULD instruction at address MEMADDR in debugged memory,
38 on STREAM. Returns length of the instruction, in bytes. */
41 print_insn (memaddr
, stream
)
45 unsigned char buffer
[MAXLEN
];
48 register int bestmask
;
50 int temp
, index
, bestlen
;
52 read_memory (memaddr
, buffer
, MAXLEN
);
57 for (i
= 0; i
< NOPCODES
; i
++)
59 register unsigned int opcode
= gld_opcodes
[i
].opcode
;
60 register unsigned int mask
= gld_opcodes
[i
].mask
;
61 register unsigned int len
= gld_opcodes
[i
].length
;
62 register unsigned int test
;
64 /* Get possible opcode bytes into integer */
65 test
= buffer
[0] << 24;
66 test
|= buffer
[1] << 16;
67 test
|= buffer
[2] << 8;
70 /* Mask with opcode and see if match */
71 if ((opcode
& mask
) == (test
& mask
))
73 /* See if second or third match */
76 /* Take new one if it looks good */
77 if (bestlen
== MAXLEN
&& len
== MAXLEN
)
79 /* See if lower bits matched */
80 if (((bestmask
& 3) == 0) &&
92 /* First match, save it */
101 /* Handle undefined instructions. */
104 fprintf (stream
, "undefined 0%o",(buffer
[0]<<8)+buffer
[1]);
108 /* Print instruction name */
109 fprintf (stream
, "%-12s", gld_opcodes
[index
].name
);
111 /* Adjust if short instruction */
112 if (gld_opcodes
[index
].length
< 4)
122 /* Dump out instruction arguments */
123 for (d
= gld_opcodes
[index
].args
; *d
; ++d
)
128 fprintf (stream
, "%d", (best
>> (7 + i
)) & 7);
131 fprintf (stream
, "r%d", (best
>> (7 + i
)) & 7);
134 fprintf (stream
, "r%d", (best
>> (4 + i
)) & 7);
137 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
140 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
143 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
146 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
149 temp
= (best
>> 20) & 7;
151 fprintf (stream
, "r%d", temp
);
156 temp
= (best
>> 16) & 7;
158 fprintf (stream
, "(b%d)", temp
);
161 fprintf (stream
, "#%d", best
& 0x1f);
164 fprintf (stream
, "#%x", best
& 0xffff);
167 fprintf (stream
, "%x", best
& 0xffff);
170 fprintf (stream
, "%d", best
& 0xfffe);
173 fprintf (stream
, "%d", best
& 0xfffc);
176 fprintf (stream
, "%d", (best
>> 8) & 0xff);
179 fprintf (stream
, "%d", best
& 0xff);
187 /* Return length of instruction */
188 return (gld_opcodes
[index
].length
);
192 * Find the number of arguments to a function.
195 struct frame_info
*frame
;
197 register struct symbol
*func
;
198 register unsigned pc
;
201 /* find starting address of frame function */
202 pc
= get_pc_function_start (frame
->pc
);
204 /* find function symbol info */
205 func
= find_pc_function (pc
);
207 /* call blockframe code to look for match */
209 return (func
->value
.block
->nsyms
/ sizeof(int));
216 * In the case of the NPL, the frame's norminal address is Br2 and the
217 * previous routines frame is up the stack X bytes. Finding out what
218 * 'X' is can be tricky.
220 * 1.) stored in the code function header xA(Br1).
221 * 2.) must be careful of recurssion.
227 register FRAME_ADDR pointer
;
228 FRAME_ADDR
framechain();
230 struct frame_info
*frame
;
232 /* Setup toplevel frame structure */
233 frame
->pc
= read_pc();
234 frame
->next_frame
= 0;
235 frame
->frame
= read_register (SP_REGNUM
); /* Br2 */
237 /* Search for this frame (start at current Br2) */
240 pointer
= framechain(frame
);
241 frame
->next_frame
= frame
->frame
;
242 frame
->frame
= pointer
;
243 frame
->pc
= FRAME_SAVED_PC(frame
);
245 while (frame
->next_frame
!= thisframe
);
248 pointer
= framechain (thisframe
);
250 /* stop gap for now, end at __base3 */
251 if (thisframe
->pc
== 0)
258 * Gdb front-end and internal framechain routine.
259 * Go back up stack one level. Tricky...
263 register struct frame_info
*frame
;
265 register CORE_ADDR func
, prevsp
;
266 register unsigned value
;
268 /* Get real function start address from internal frame address */
269 func
= get_pc_function_start(frame
->pc
);
271 /* If no stack given, read register Br1 "(sp)" */
273 prevsp
= read_register (SP_REGNUM
);
275 prevsp
= frame
->frame
;
277 /* Check function header, case #2 */
278 value
= read_memory_integer (func
, 4);
281 /* 32bit call push value stored in function header */
286 /* read half-word from suabr at start of function */
287 prevsp
+= read_memory_integer (func
+ 10, 2);
This page took 0.034346 seconds and 4 git commands to generate.