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. */
29 /* GOULD RISC instructions are never longer than this many bytes. */
32 /* Number of elements in the opcode table. */
33 #define NOPCODES (sizeof gld_opcodes / sizeof gld_opcodes[0])
36 /* Print the GOULD instruction at address MEMADDR in debugged memory,
37 on STREAM. Returns length of the instruction, in bytes. */
40 print_insn (memaddr
, stream
)
44 unsigned char buffer
[MAXLEN
];
47 register int bestmask
;
49 int temp
, index
, bestlen
;
51 read_memory (memaddr
, buffer
, MAXLEN
);
56 for (i
= 0; i
< NOPCODES
; i
++)
58 register unsigned int opcode
= gld_opcodes
[i
].opcode
;
59 register unsigned int mask
= gld_opcodes
[i
].mask
;
60 register unsigned int len
= gld_opcodes
[i
].length
;
61 register unsigned int test
;
63 /* Get possible opcode bytes into integer */
64 test
= buffer
[0] << 24;
65 test
|= buffer
[1] << 16;
66 test
|= buffer
[2] << 8;
69 /* Mask with opcode and see if match */
70 if ((opcode
& mask
) == (test
& mask
))
72 /* See if second or third match */
75 /* Take new one if it looks good */
76 if (bestlen
== MAXLEN
&& len
== MAXLEN
)
78 /* See if lower bits matched */
79 if (((bestmask
& 3) == 0) &&
91 /* First match, save it */
100 /* Handle undefined instructions. */
103 fprintf (stream
, "undefined 0%o",(buffer
[0]<<8)+buffer
[1]);
107 /* Print instruction name */
108 fprintf (stream
, "%-12s", gld_opcodes
[index
].name
);
110 /* Adjust if short instruction */
111 if (gld_opcodes
[index
].length
< 4)
121 /* Dump out instruction arguments */
122 for (d
= gld_opcodes
[index
].args
; *d
; ++d
)
127 fprintf (stream
, "%d", (best
>> (7 + i
)) & 7);
130 fprintf (stream
, "r%d", (best
>> (7 + i
)) & 7);
133 fprintf (stream
, "r%d", (best
>> (4 + i
)) & 7);
136 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
139 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
142 fprintf (stream
, "b%d", (best
>> (7 + i
)) & 7);
145 fprintf (stream
, "b%d", (best
>> (4 + i
)) & 7);
148 temp
= (best
>> 20) & 7;
150 fprintf (stream
, "r%d", temp
);
155 temp
= (best
>> 16) & 7;
157 fprintf (stream
, "(b%d)", temp
);
160 fprintf (stream
, "#%d", best
& 0x1f);
163 fprintf (stream
, "#%x", best
& 0xffff);
166 fprintf (stream
, "%x", best
& 0xffff);
169 fprintf (stream
, "%d", best
& 0xfffe);
172 fprintf (stream
, "%d", best
& 0xfffc);
175 fprintf (stream
, "%d", (best
>> 8) & 0xff);
178 fprintf (stream
, "%d", best
& 0xff);
186 /* Return length of instruction */
187 return (gld_opcodes
[index
].length
);
191 * Find the number of arguments to a function.
194 struct frame_info
*frame
;
196 register struct symbol
*func
;
197 register unsigned pc
;
200 /* find starting address of frame function */
201 pc
= get_pc_function_start (frame
->pc
);
203 /* find function symbol info */
204 func
= find_pc_function (pc
);
206 /* call blockframe code to look for match */
208 return (func
->value
.block
->nsyms
/ sizeof(int));
215 * In the case of the NPL, the frame's norminal address is Br2 and the
216 * previous routines frame is up the stack X bytes. Finding out what
217 * 'X' is can be tricky.
219 * 1.) stored in the code function header xA(Br1).
220 * 2.) must be careful of recurssion.
226 register FRAME_ADDR pointer
;
228 struct frame_info
*frame
;
229 FRAME_ADDR
framechain();
231 /* Setup toplevel frame structure */
232 frame
->pc
= read_pc();
233 frame
->next_frame
= 0;
234 frame
->frame
= read_register (SP_REGNUM
); /* Br2 */
236 /* Search for this frame (start at current Br2) */
239 pointer
= framechain(frame
);
240 frame
->next_frame
= frame
->frame
;
241 frame
->frame
= pointer
;
242 frame
->pc
= FRAME_SAVED_PC(frame
);
244 while (frame
->next_frame
!= thisframe
);
247 pointer
= framechain (thisframe
);
249 /* stop gap for now, end at __base3 */
250 if (thisframe
->pc
== 0)
257 * Gdb front-end and internal framechain routine.
258 * Go back up stack one level. Tricky...
262 register struct frame_info
*frame
;
264 register CORE_ADDR func
, prevsp
;
265 register unsigned value
;
267 /* Get real function start address from internal frame address */
268 func
= get_pc_function_start(frame
->pc
);
270 /* If no stack given, read register Br1 "(sp)" */
272 prevsp
= read_register (SP_REGNUM
);
274 prevsp
= frame
->frame
;
276 /* Check function header, case #2 */
277 value
= read_memory_integer (func
, 4);
280 /* 32bit call push value stored in function header */
285 /* read half-word from suabr at start of function */
286 prevsp
+= read_memory_integer (func
+ 10, 2);
This page took 0.036107 seconds and 4 git commands to generate.