import gdb-1999-07-07 post reformat
[deliverable/binutils-gdb.git] / gdb / ns32k-tdep.c
CommitLineData
c906108c
SS
1/* Print NS 32000 instructions for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1991, 1992, 1994, 1995
3 Free Software Foundation, Inc.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22
23void
24_initialize_ns32k_tdep ()
25{
26 tm_print_insn = print_insn_ns32k;
27}
b83266a0
SS
28
29/* Advance PC across any function entry prologue instructions
30 to reach some "real" code. */
31
32CORE_ADDR
33merlin_skip_prologue (pc)
34 CORE_ADDR pc;
35{
36 register int op = read_memory_integer (pc, 1);
37 if (op == 0x82)
38 {
39 op = read_memory_integer (pc+2,1);
40 if ((op & 0x80) == 0)
41 pc += 3;
42 else if ((op & 0xc0) == 0x80)
43 pc += 4;
44 else pc += 6;
45 }
46 return pc;
47}
48
49CORE_ADDR
50umax_skip_prologue (pc)
51 CORE_ADDR pc;
52{
53 register unsigned char op = read_memory_integer (pc, 1);
54 if (op == 0x82)
55 {
56 op = read_memory_integer (pc+2,1);
57 if ((op & 0x80) == 0)
58 pc += 3;
59 else if ((op & 0xc0) == 0x80)
60 pc += 4;
61 else
62 pc += 6;
63 }
64 return pc;
65}
66
392a587b
JM
67/* Return number of args passed to a frame.
68 Can return -1, meaning no way to tell. */
69
70int
71merlin_frame_num_args (fi)
72 struct frame_info *fi;
73{
74 int numargs;
75 CORE_ADDR pc;
76 int insn;
77 int addr_mode;
78 int width;
79
80 pc = FRAME_SAVED_PC (fi);
81 insn = read_memory_integer (pc,2);
82 addr_mode = (insn >> 11) & 0x1f;
83 insn = insn & 0x7ff;
84 if ((insn & 0x7fc) == 0x57c
85 && addr_mode == 0x14) /* immediate */
86 {
87 if (insn == 0x57c) /* adjspb */
88 width = 1;
89 else if (insn == 0x57d) /* adjspw */
90 width = 2;
91 else if (insn == 0x57f) /* adjspd */
92 width = 4;
93 numargs = read_memory_integer (pc+2,width);
94 if (width > 1)
95 flip_bytes (&numargs, width);
96 numargs = - sign_extend (numargs, width*8) / 4;
97 }
98 else
99 numargs = -1;
100 return numargs;
101}
102
cce74817
JM
103
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. */
392a587b
JM
109int
110umax_frame_num_args (fi)
111 struct frame_info *fi;
112{
113 int numargs;
114 CORE_ADDR pc;
115 CORE_ADDR enter_addr;
116 unsigned int insn;
117 unsigned int addr_mode;
118 int width;
119
120 numargs = -1;
121 enter_addr = ns32k_get_enter_addr ((fi)->pc);
122 if (enter_addr > 0)
123 {
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;
129 insn = insn & 0x7ff;
130 if ((insn & 0x7fc) == 0x57c
131 && addr_mode == 0x14) /* immediate */
132 {
133 if (insn == 0x57c) /* adjspb */
134 width = 1;
135 else if (insn == 0x57d) /* adjspw */
136 width = 2;
137 else if (insn == 0x57f) /* adjspd */
138 width = 4;
139 numargs = read_memory_integer (pc+2,width);
140 if (width > 1)
141 flip_bytes (&numargs, width);
142 numargs = - sign_extend (numargs, width*8) / 4;
143 }
144 }
145 return numargs;
146}
b83266a0 147
c906108c
SS
148
149sign_extend (value, bits)
150{
151 value = value & ((1 << bits) - 1);
152 return (value & (1 << (bits-1))
153 ? value | (~((1 << bits) - 1))
154 : value);
155}
156
157void
158flip_bytes (ptr, count)
159 char *ptr;
160 int count;
161{
162 char tmp;
163
164 while (count > 0)
165 {
166 tmp = *ptr;
167 ptr[0] = ptr[count-1];
168 ptr[count-1] = tmp;
169 ptr++;
170 count -= 2;
171 }
172}
173
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. */
177
178int
179ns32k_localcount (enter_pc)
180 CORE_ADDR enter_pc;
181{
182 unsigned char localtype;
183 int localcount;
184
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));
191 else
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));
196 return localcount;
197}
198
199
200/* Nonzero if instruction at PC is a return instruction. */
201
202static int
203ns32k_about_to_return (pc)
204 CORE_ADDR pc;
205{
206 return (read_memory_integer (pc, 1) == 0x12);
207}
208
209
210/*
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.
216 */
217
218CORE_ADDR
219ns32k_get_enter_addr (pc)
220 CORE_ADDR pc;
221{
222 CORE_ADDR enter_addr;
223 unsigned char op;
224
225 if (pc == 0)
226 return 0;
227
228 if (ns32k_about_to_return (pc))
229 return 1; /* after exit */
230
231 enter_addr = get_pc_function_start (pc);
232
233 if (pc == enter_addr)
234 return 1; /* before enter */
235
236 op = read_memory_integer (enter_addr, 1);
237
238 if (op != 0x82)
239 return 0; /* function has no enter/exit */
240
241 return enter_addr; /* pc is between enter and exit */
242}
This page took 0.035586 seconds and 4 git commands to generate.