1 /* Print GOULD RISC instructions for GDB, the GNU debugger.
2 Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB 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 1, or (at your option)
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "pn-opcode.h"
30 #include "np1-opcode.h"
33 /* GOULD RISC instructions are never longer than this many bytes. */
36 /* Number of elements in the opcode table. */
37 #define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
40 /* Print the GOULD instruction at address MEMADDR in debugged memory,
41 on STREAM. Returns length of the instruction, in bytes. */
44 print_insn (memaddr
, stream
)
48 unsigned char buffer
[MAXLEN
];
51 register int bestmask
;
53 int temp
, index
, bestlen
;
55 read_memory (memaddr
, buffer
, MAXLEN
);
60 for (i
= 0; i
< NOPCODES
; i
++)
62 register unsigned int opcode
= gld_opcodes
[i
].opcode
;
63 register unsigned int mask
= gld_opcodes
[i
].mask
;
64 register unsigned int len
= gld_opcodes
[i
].length
;
65 register unsigned int test
;
67 /* Get possible opcode bytes into integer */
68 test
= buffer
[0] << 24;
69 test
|= buffer
[1] << 16;
70 test
|= buffer
[2] << 8;
73 /* Mask with opcode and see if match */
74 if ((opcode
& mask
) == (test
& mask
))
76 /* See if second or third match */
79 /* Take new one if it looks good */
80 if (bestlen
== MAXLEN
&& len
== MAXLEN
)
82 /* See if lower bits matched */
83 if (((bestmask
& 3) == 0) &&
95 /* First match, save it */
104 /* Handle undefined instructions. */
107 fprintf (stream
, "undefined 0%o",(buffer
[0]<<8)+buffer
[1]);
111 /* Print instruction name */
112 fprintf (stream
, "%-12s", gld_opcodes
[index
].name
);
114 /* Adjust if short instruction */
115 if (gld_opcodes
[index
].length
< 4)
125 /* Dump out instruction arguments */
126 for (d
= gld_opcodes
[index
].args
; *d
; ++d
)
131 fprintf (stream
, "%d", (best
>> (7 + i
)) & 7);
134 fprintf (stream
, "r%d", (best
>> (7 + i
)) & 7);
137 fprintf (stream
, "r%d", (best
>> (4 + i
)) & 7);
140 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
143 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
146 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
149 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
152 temp
= (best
>> 20) & 7;
154 fprintf (stream
, "r%d", temp
);
159 temp
= (best
>> 16) & 7;
161 fprintf (stream
, "(b%d)", temp
);
164 fprintf (stream
, "#%d", best
& 0x1f);
167 fprintf (stream
, "#%x", best
& 0xffff);
170 fprintf (stream
, "%x", best
& 0xffff);
173 fprintf (stream
, "%d", best
& 0xfffe);
176 fprintf (stream
, "%d", best
& 0xfffc);
179 fprintf (stream
, "%d", (best
>> 8) & 0xff);
182 fprintf (stream
, "%d", best
& 0xff);
190 /* Return length of instruction */
191 return (gld_opcodes
[index
].length
);
195 * Find the number of arguments to a function.
198 struct frame_info
*frame
;
200 register struct symbol
*func
;
201 register unsigned pc
;
204 /* find starting address of frame function */
205 pc
= get_pc_function_start (frame
->pc
);
207 /* find function symbol info */
208 func
= find_pc_function (pc
);
210 /* call blockframe code to look for match */
212 return (func
->value
.block
->nsyms
/ sizeof(int));
219 * In the case of the NPL, the frame's norminal address is Br2 and the
220 * previous routines frame is up the stack X bytes. Finding out what
221 * 'X' is can be tricky.
223 * 1.) stored in the code function header xA(Br1).
224 * 2.) must be careful of recurssion.
230 register FRAME_ADDR pointer
;
231 FRAME_ADDR
framechain();
233 struct frame_info
*frame
;
235 /* Setup toplevel frame structure */
236 frame
->pc
= read_pc();
237 frame
->next_frame
= 0;
238 frame
->frame
= read_register (SP_REGNUM
); /* Br2 */
240 /* Search for this frame (start at current Br2) */
243 pointer
= framechain(frame
);
244 frame
->next_frame
= frame
->frame
;
245 frame
->frame
= pointer
;
246 frame
->pc
= FRAME_SAVED_PC(frame
);
248 while (frame
->next_frame
!= thisframe
);
251 pointer
= framechain (thisframe
);
253 /* stop gap for now, end at __base3 */
254 if (thisframe
->pc
== 0)
261 * Gdb front-end and internal framechain routine.
262 * Go back up stack one level. Tricky...
266 register struct frame_info
*frame
;
268 register CORE_ADDR func
, prevsp
;
269 register unsigned value
;
271 /* Get real function start address from internal frame address */
272 func
= get_pc_function_start(frame
->pc
);
274 /* If no stack given, read register Br1 "(sp)" */
276 prevsp
= read_register (SP_REGNUM
);
278 prevsp
= frame
->frame
;
280 /* Check function header, case #2 */
281 value
= read_memory_integer (func
, 4);
284 /* 32bit call push value stored in function header */
289 /* read half-word from suabr at start of function */
290 prevsp
+= read_memory_integer (func
+ 10, 2);
This page took 0.034654 seconds and 4 git commands to generate.