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. */
26 #include "pn-opcode.h"
28 #include "np1-opcode.h"
31 /* GOULD RISC instructions are never longer than this many bytes. */
34 /* Number of elements in the opcode table. */
35 #define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
38 /* Print the GOULD instruction at address MEMADDR in debugged memory,
39 on STREAM. Returns length of the instruction, in bytes. */
42 print_insn (memaddr
, stream
)
46 unsigned char buffer
[MAXLEN
];
49 register int bestmask
;
51 int temp
, index
, bestlen
;
53 read_memory (memaddr
, buffer
, MAXLEN
);
58 for (i
= 0; i
< NOPCODES
; i
++)
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
;
65 /* Get possible opcode bytes into integer */
66 test
= buffer
[0] << 24;
67 test
|= buffer
[1] << 16;
68 test
|= buffer
[2] << 8;
71 /* Mask with opcode and see if match */
72 if ((opcode
& mask
) == (test
& mask
))
74 /* See if second or third match */
77 /* Take new one if it looks good */
78 if (bestlen
== MAXLEN
&& len
== MAXLEN
)
80 /* See if lower bits matched */
81 if (((bestmask
& 3) == 0) &&
93 /* First match, save it */
102 /* Handle undefined instructions. */
105 fprintf (stream
, "undefined 0%o",(buffer
[0]<<8)+buffer
[1]);
109 /* Print instruction name */
110 fprintf (stream
, "%-12s", gld_opcodes
[index
].name
);
112 /* Adjust if short instruction */
113 if (gld_opcodes
[index
].length
< 4)
123 /* Dump out instruction arguments */
124 for (d
= gld_opcodes
[index
].args
; *d
; ++d
)
129 fprintf (stream
, "%d", (best
>> (7 + i
)) & 7);
132 fprintf (stream
, "r%d", (best
>> (7 + i
)) & 7);
135 fprintf (stream
, "r%d", (best
>> (4 + i
)) & 7);
138 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
141 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
144 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
147 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
150 temp
= (best
>> 20) & 7;
152 fprintf (stream
, "r%d", temp
);
157 temp
= (best
>> 16) & 7;
159 fprintf (stream
, "(b%d)", temp
);
162 fprintf (stream
, "#%d", best
& 0x1f);
165 fprintf (stream
, "#%x", best
& 0xffff);
168 fprintf (stream
, "%x", best
& 0xffff);
171 fprintf (stream
, "%d", best
& 0xfffe);
174 fprintf (stream
, "%d", best
& 0xfffc);
177 fprintf (stream
, "%d", (best
>> 8) & 0xff);
180 fprintf (stream
, "%d", best
& 0xff);
188 /* Return length of instruction */
189 return (gld_opcodes
[index
].length
);
193 * Find the number of arguments to a function.
196 struct frame_info
*frame
;
198 register struct symbol
*func
;
199 register unsigned pc
;
202 /* find starting address of frame function */
203 pc
= get_pc_function_start (frame
->pc
);
205 /* find function symbol info */
206 func
= find_pc_function (pc
);
208 /* call blockframe code to look for match */
210 return (func
->value
.block
->nsyms
/ sizeof(int));
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.
221 * 1.) stored in the code function header xA(Br1).
222 * 2.) must be careful of recurssion.
228 register FRAME_ADDR pointer
;
229 FRAME_ADDR
framechain();
231 struct frame_info
*frame
;
233 /* Setup toplevel frame structure */
234 frame
->pc
= read_pc();
235 frame
->next_frame
= 0;
236 frame
->frame
= read_register (SP_REGNUM
); /* Br2 */
238 /* Search for this frame (start at current Br2) */
241 pointer
= framechain(frame
);
242 frame
->next_frame
= frame
->frame
;
243 frame
->frame
= pointer
;
244 frame
->pc
= FRAME_SAVED_PC(frame
);
246 while (frame
->next_frame
!= thisframe
);
249 pointer
= framechain (thisframe
);
251 /* stop gap for now, end at __base3 */
252 if (thisframe
->pc
== 0)
259 * Gdb front-end and internal framechain routine.
260 * Go back up stack one level. Tricky...
264 register struct frame_info
*frame
;
266 register CORE_ADDR func
, prevsp
;
267 register unsigned value
;
269 /* Get real function start address from internal frame address */
270 func
= get_pc_function_start(frame
->pc
);
272 /* If no stack given, read register Br1 "(sp)" */
274 prevsp
= read_register (SP_REGNUM
);
276 prevsp
= frame
->frame
;
278 /* Check function header, case #2 */
279 value
= read_memory_integer (func
, 4);
282 /* 32bit call push value stored in function header */
287 /* read half-word from suabr at start of function */
288 prevsp
+= read_memory_integer (func
+ 10, 2);
This page took 0.036002 seconds and 4 git commands to generate.