* gdb.base/del.c: New file.
[deliverable/binutils-gdb.git] / gprof / vax.c
CommitLineData
252b5132 1/*
5ec4a8f3
NC
2 * Copyright (c) 1983, 1993, 2001
3 * The Regents of the University of California. All rights reserved.
252b5132 4 *
5ec4a8f3
NC
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
252b5132
RH
28 */
29#include "gprof.h"
6d9c411a
AM
30#include "search_list.h"
31#include "source.h"
32#include "symtab.h"
252b5132
RH
33#include "cg_arcs.h"
34#include "corefile.h"
35#include "hist.h"
252b5132
RH
36
37 /*
38 * opcode of the `calls' instruction
39 */
40#define CALLS 0xfb
41
42 /*
43 * register for pc relative addressing
44 */
45#define PC 0xf
46
47enum opermodes
48 {
49 literal, indexed, reg, regdef, autodec, autoinc, autoincdef,
50 bytedisp, bytedispdef, worddisp, worddispdef, longdisp, longdispdef,
51 immediate, absolute, byterel, bytereldef, wordrel, wordreldef,
52 longrel, longreldef
53 };
54typedef enum opermodes operandenum;
55
210c61aa 56/* *INDENT-OFF* */
6d9c411a 57/* Here to document only. We can't use this when cross compiling as
210c61aa
BE
58 the bitfield layout might not be the same as native.
59
60 struct modebyte
61 {
62 unsigned int regfield:4;
63 unsigned int modefield:4;
64 };
65*/
66/* *INDENT-ON* */
252b5132
RH
67
68/*
69 * A symbol to be the child of indirect calls:
70 */
3b04e729 71static Sym indirectchild;
252b5132 72
3e8f6abf
BE
73static operandenum vax_operandmode (unsigned char *);
74static char *vax_operandname (operandenum);
75static long vax_operandlength (unsigned char *);
76static bfd_signed_vma vax_offset (unsigned char *);
77void vax_find_call (Sym *, bfd_vma, bfd_vma);
5789ecea 78
252b5132 79static operandenum
3e8f6abf 80vax_operandmode (unsigned char *modep)
252b5132 81{
6d9c411a 82 int usesreg = *modep & 0xf;
252b5132 83
6d9c411a 84 switch ((*modep >> 4) & 0xf)
252b5132
RH
85 {
86 case 0:
87 case 1:
88 case 2:
89 case 3:
90 return literal;
91 case 4:
92 return indexed;
93 case 5:
94 return reg;
95 case 6:
96 return regdef;
97 case 7:
98 return autodec;
99 case 8:
100 return usesreg != PC ? autoinc : immediate;
101 case 9:
102 return usesreg != PC ? autoincdef : absolute;
103 case 10:
104 return usesreg != PC ? bytedisp : byterel;
105 case 11:
106 return usesreg != PC ? bytedispdef : bytereldef;
107 case 12:
108 return usesreg != PC ? worddisp : wordrel;
109 case 13:
110 return usesreg != PC ? worddispdef : wordreldef;
111 case 14:
112 return usesreg != PC ? longdisp : longrel;
113 case 15:
114 return usesreg != PC ? longdispdef : longreldef;
115 }
116 /* NOTREACHED */
117 abort ();
118}
119
120static char *
3e8f6abf 121vax_operandname (operandenum mode)
252b5132
RH
122{
123
124 switch (mode)
125 {
126 case literal:
127 return "literal";
128 case indexed:
129 return "indexed";
130 case reg:
131 return "register";
132 case regdef:
133 return "register deferred";
134 case autodec:
135 return "autodecrement";
136 case autoinc:
137 return "autoincrement";
138 case autoincdef:
139 return "autoincrement deferred";
140 case bytedisp:
141 return "byte displacement";
142 case bytedispdef:
143 return "byte displacement deferred";
144 case byterel:
145 return "byte relative";
146 case bytereldef:
147 return "byte relative deferred";
148 case worddisp:
149 return "word displacement";
150 case worddispdef:
151 return "word displacement deferred";
152 case wordrel:
153 return "word relative";
154 case wordreldef:
155 return "word relative deferred";
156 case immediate:
157 return "immediate";
158 case absolute:
159 return "absolute";
160 case longdisp:
161 return "long displacement";
162 case longdispdef:
163 return "long displacement deferred";
164 case longrel:
165 return "long relative";
166 case longreldef:
167 return "long relative deferred";
168 }
169 /* NOTREACHED */
170 abort ();
171}
172
173static long
3e8f6abf 174vax_operandlength (unsigned char *modep)
252b5132
RH
175{
176
177 switch (vax_operandmode (modep))
178 {
179 case literal:
180 case reg:
181 case regdef:
182 case autodec:
183 case autoinc:
184 case autoincdef:
185 return 1;
186 case bytedisp:
187 case bytedispdef:
188 case byterel:
189 case bytereldef:
190 return 2;
191 case worddisp:
192 case worddispdef:
193 case wordrel:
194 case wordreldef:
195 return 3;
196 case immediate:
197 case absolute:
198 case longdisp:
199 case longdispdef:
200 case longrel:
201 case longreldef:
202 return 5;
203 case indexed:
6d9c411a 204 return 1 + vax_operandlength (modep + 1);
252b5132
RH
205 }
206 /* NOTREACHED */
207 abort ();
208}
209
6d9c411a 210static bfd_signed_vma
3e8f6abf 211vax_offset (unsigned char *modep)
252b5132
RH
212{
213 operandenum mode = vax_operandmode (modep);
252b5132 214
6d9c411a 215 ++modep; /* skip over the mode */
252b5132
RH
216 switch (mode)
217 {
218 default:
219 fprintf (stderr, "[reladdr] not relative address\n");
6d9c411a 220 return 0;
252b5132 221 case byterel:
6d9c411a 222 return 1 + bfd_get_signed_8 (core_bfd, modep);
252b5132 223 case wordrel:
6d9c411a 224 return 2 + bfd_get_signed_16 (core_bfd, modep);
252b5132 225 case longrel:
6d9c411a 226 return 4 + bfd_get_signed_32 (core_bfd, modep);
252b5132
RH
227 }
228}
229
230
231void
3e8f6abf 232vax_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
252b5132
RH
233{
234 unsigned char *instructp;
235 long length;
236 Sym *child;
237 operandenum mode;
238 operandenum firstmode;
6d9c411a 239 bfd_vma pc, destpc;
b34976b6 240 static bfd_boolean inited = FALSE;
252b5132
RH
241
242 if (!inited)
243 {
b34976b6 244 inited = TRUE;
252b5132
RH
245 sym_init (&indirectchild);
246 indirectchild.cg.prop.fract = 1.0;
247 indirectchild.cg.cyc.head = &indirectchild;
248 }
249
250 if (core_text_space == 0)
251 {
252 return;
253 }
254 if (p_lowpc < s_lowpc)
255 {
256 p_lowpc = s_lowpc;
257 }
258 if (p_highpc > s_highpc)
259 {
260 p_highpc = s_highpc;
261 }
262 DBG (CALLDEBUG, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
fdcf7d43
ILT
263 parent->name, (unsigned long) p_lowpc,
264 (unsigned long) p_highpc));
6d9c411a 265 for (pc = p_lowpc; pc < p_highpc; pc += length)
252b5132
RH
266 {
267 length = 1;
6d9c411a
AM
268 instructp = ((unsigned char *) core_text_space
269 + pc - core_text_sect->vma);
270 if ((*instructp & 0xff) == CALLS)
252b5132
RH
271 {
272 /*
273 * maybe a calls, better check it out.
274 * skip the count of the number of arguments.
275 */
276 DBG (CALLDEBUG,
6d9c411a
AM
277 printf ("[findcall]\t0x%lx:calls", (unsigned long) pc));
278 firstmode = vax_operandmode (instructp + length);
252b5132
RH
279 switch (firstmode)
280 {
281 case literal:
282 case immediate:
283 break;
284 default:
285 goto botched;
286 }
6d9c411a
AM
287 length += vax_operandlength (instructp + length);
288 mode = vax_operandmode (instructp + length);
252b5132
RH
289 DBG (CALLDEBUG,
290 printf ("\tfirst operand is %s", vax_operandname (firstmode));
291 printf ("\tsecond operand is %s\n", vax_operandname (mode)));
292 switch (mode)
293 {
294 case regdef:
295 case bytedispdef:
296 case worddispdef:
297 case longdispdef:
298 case bytereldef:
299 case wordreldef:
300 case longreldef:
301 /*
302 * indirect call: call through pointer
303 * either *d(r) as a parameter or local
304 * (r) as a return value
305 * *f as a global pointer
306 * [are there others that we miss?,
307 * e.g. arrays of pointers to functions???]
308 */
309 arc_add (parent, &indirectchild, (unsigned long) 0);
6d9c411a 310 length += vax_operandlength (instructp + length);
252b5132
RH
311 continue;
312 case byterel:
313 case wordrel:
314 case longrel:
315 /*
316 * regular pc relative addressing
0eee5820 317 * check that this is the address of
252b5132
RH
318 * a function.
319 */
6d9c411a 320 destpc = pc + vax_offset (instructp + length);
252b5132
RH
321 if (destpc >= s_lowpc && destpc <= s_highpc)
322 {
323 child = sym_lookup (&symtab, destpc);
324 DBG (CALLDEBUG,
fdcf7d43
ILT
325 printf ("[findcall]\tdestpc 0x%lx",
326 (unsigned long) destpc);
252b5132 327 printf (" child->name %s", child->name);
fdcf7d43
ILT
328 printf (" child->addr 0x%lx\n",
329 (unsigned long) child->addr);
252b5132
RH
330 );
331 if (child->addr == destpc)
332 {
333 /*
334 * a hit
335 */
336 arc_add (parent, child, (unsigned long) 0);
6d9c411a 337 length += vax_operandlength (instructp + length);
252b5132
RH
338 continue;
339 }
340 goto botched;
341 }
342 /*
343 * else:
344 * it looked like a calls,
345 * but it wasn't to anywhere.
346 */
347 goto botched;
348 default:
349 botched:
350 /*
351 * something funny going on.
352 */
353 DBG (CALLDEBUG, printf ("[findcall]\tbut it's a botch\n"));
354 length = 1;
355 continue;
356 }
357 }
358 }
359}
This page took 0.291061 seconds and 4 git commands to generate.