1 /* Print NS 32000 instructions for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1991, 1992, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 _initialize_ns32k_tdep ()
26 tm_print_insn
= print_insn_ns32k
;
29 /* Advance PC across any function entry prologue instructions
30 to reach some "real" code. */
33 merlin_skip_prologue (pc
)
36 register int op
= read_memory_integer (pc
, 1);
39 op
= read_memory_integer (pc
+2,1);
42 else if ((op
& 0xc0) == 0x80)
50 umax_skip_prologue (pc
)
53 register unsigned char op
= read_memory_integer (pc
, 1);
56 op
= read_memory_integer (pc
+2,1);
59 else if ((op
& 0xc0) == 0x80)
67 /* Return number of args passed to a frame.
68 Can return -1, meaning no way to tell. */
71 merlin_frame_num_args (fi
)
72 struct frame_info
*fi
;
80 pc
= FRAME_SAVED_PC (fi
);
81 insn
= read_memory_integer (pc
,2);
82 addr_mode
= (insn
>> 11) & 0x1f;
84 if ((insn
& 0x7fc) == 0x57c
85 && addr_mode
== 0x14) /* immediate */
87 if (insn
== 0x57c) /* adjspb */
89 else if (insn
== 0x57d) /* adjspw */
91 else if (insn
== 0x57f) /* adjspd */
93 numargs
= read_memory_integer (pc
+2,width
);
95 flip_bytes (&numargs
, width
);
96 numargs
= - sign_extend (numargs
, width
*8) / 4;
104 /* Return number of args passed to a frame.
105 Can return -1, meaning no way to tell.
106 Encore's C compiler often reuses same area on stack for args,
107 so this will often not work properly. If the arg names
108 are known, it's likely most of them will be printed. */
110 umax_frame_num_args (fi
)
111 struct frame_info
*fi
;
115 CORE_ADDR enter_addr
;
117 unsigned int addr_mode
;
121 enter_addr
= ns32k_get_enter_addr ((fi
)->pc
);
124 pc
= ((enter_addr
== 1)
125 ? SAVED_PC_AFTER_CALL (fi
)
126 : FRAME_SAVED_PC (fi
));
127 insn
= read_memory_integer (pc
,2);
128 addr_mode
= (insn
>> 11) & 0x1f;
130 if ((insn
& 0x7fc) == 0x57c
131 && addr_mode
== 0x14) /* immediate */
133 if (insn
== 0x57c) /* adjspb */
135 else if (insn
== 0x57d) /* adjspw */
137 else if (insn
== 0x57f) /* adjspd */
139 numargs
= read_memory_integer (pc
+2,width
);
141 flip_bytes (&numargs
, width
);
142 numargs
= - sign_extend (numargs
, width
*8) / 4;
149 sign_extend (value
, bits
)
151 value
= value
& ((1 << bits
) - 1);
152 return (value
& (1 << (bits
-1))
153 ? value
| (~((1 << bits
) - 1))
158 flip_bytes (ptr
, count
)
167 ptr
[0] = ptr
[count
-1];
174 /* Return the number of locals in the current frame given a pc
175 pointing to the enter instruction. This is used in the macro
176 FRAME_FIND_SAVED_REGS. */
179 ns32k_localcount (enter_pc
)
182 unsigned char localtype
;
185 localtype
= read_memory_integer (enter_pc
+2, 1);
186 if ((localtype
& 0x80) == 0)
187 localcount
= localtype
;
188 else if ((localtype
& 0xc0) == 0x80)
189 localcount
= (((localtype
& 0x3f) << 8)
190 | (read_memory_integer (enter_pc
+3, 1) & 0xff));
192 localcount
= (((localtype
& 0x3f) << 24)
193 | ((read_memory_integer (enter_pc
+3, 1) & 0xff) << 16)
194 | ((read_memory_integer (enter_pc
+4, 1) & 0xff) << 8 )
195 | (read_memory_integer (enter_pc
+5, 1) & 0xff));
200 /* Nonzero if instruction at PC is a return instruction. */
203 ns32k_about_to_return (pc
)
206 return (read_memory_integer (pc
, 1) == 0x12);
211 * Get the address of the enter opcode for the function
212 * containing PC, if there is an enter for the function,
213 * and if the pc is between the enter and exit.
214 * Returns positive address if pc is between enter/exit,
215 * 1 if pc before enter or after exit, 0 otherwise.
219 ns32k_get_enter_addr (pc
)
222 CORE_ADDR enter_addr
;
228 if (ns32k_about_to_return (pc
))
229 return 1; /* after exit */
231 enter_addr
= get_pc_function_start (pc
);
233 if (pc
== enter_addr
)
234 return 1; /* before enter */
236 op
= read_memory_integer (enter_addr
, 1);
239 return 0; /* function has no enter/exit */
241 return enter_addr
; /* pc is between enter and exit */