2001-11-14 Dave Brolley <brolley@redhat.com>
[binutils.git] / gprof / alpha.c
blob4fa917ea551cf7bedcf63f228691539b7fc3f642
1 /*
2 * Copyright (c) 1983, 1998 Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #include "gprof.h"
20 #include "cg_arcs.h"
21 #include "corefile.h"
22 #include "hist.h"
23 #include "symtab.h"
26 * Opcodes of the call instructions:
28 #define OP_Jxx 0x1a
29 #define OP_BSR 0x34
31 #define Jxx_FUNC_JMP 0
32 #define Jxx_FUNC_JSR 1
33 #define Jxx_FUNC_RET 2
34 #define Jxx_FUNC_JSR_COROUTINE 3
36 typedef union
38 struct
40 unsigned other:26;
41 unsigned op_code:6;
43 a; /* any format */
44 struct
46 int disp:21;
47 unsigned ra:5;
48 unsigned op_code:6;
50 b; /* branch format */
51 struct
53 int hint:14;
54 unsigned func:2;
55 unsigned rb:5;
56 unsigned ra:5;
57 unsigned op_code:6;
59 j; /* jump format */
61 alpha_Instruction;
63 static Sym indirect_child;
65 void alpha_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
68 * On the Alpha we can only detect PC relative calls, which are
69 * usually generated for calls to functions within the same
70 * object file only. This is still better than nothing, however.
71 * (In particular it should be possible to find functions that
72 * potentially call integer division routines, for example.)
74 void
75 alpha_find_call (parent, p_lowpc, p_highpc)
76 Sym *parent;
77 bfd_vma p_lowpc;
78 bfd_vma p_highpc;
80 static bfd_vma delta = 0;
81 bfd_vma dest_pc;
82 alpha_Instruction *pc;
83 Sym *child;
85 if (!delta)
87 delta = (bfd_vma) core_text_space - core_text_sect->vma;
89 sym_init (&indirect_child);
90 indirect_child.name = _("<indirect child>");
91 indirect_child.cg.prop.fract = 1.0;
92 indirect_child.cg.cyc.head = &indirect_child;
95 if (!core_text_space)
97 return;
99 if (p_lowpc < s_lowpc)
101 p_lowpc = s_lowpc;
103 if (p_highpc > s_highpc)
105 p_highpc = s_highpc;
107 DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
108 parent->name, (unsigned long) p_lowpc,
109 (unsigned long) p_highpc));
110 for (pc = (alpha_Instruction *) (p_lowpc + delta);
111 pc < (alpha_Instruction *) (p_highpc + delta);
112 ++pc)
114 switch (pc->a.op_code)
116 case OP_Jxx:
118 * There is no simple and reliable way to determine the
119 * target of a jsr (the hint bits help, but there aren't
120 * enough bits to get a satisfactory hit rate). Instead,
121 * for any indirect jump we simply add an arc from PARENT
122 * to INDIRECT_CHILD---that way the user it at least able
123 * to see that there are other calls as well.
125 if (pc->j.func == Jxx_FUNC_JSR
126 || pc->j.func == Jxx_FUNC_JSR_COROUTINE)
128 DBG (CALLDEBUG,
129 printf (_("[find_call] 0x%lx: jsr%s <indirect_child>\n"),
130 (unsigned long) pc - (unsigned long) delta,
131 pc->j.func == Jxx_FUNC_JSR ? "" : "_coroutine"));
132 arc_add (parent, &indirect_child, (unsigned long) 0);
134 break;
136 case OP_BSR:
137 DBG (CALLDEBUG,
138 printf (_("[find_call] 0x%lx: bsr"),
139 (unsigned long) pc - (unsigned long) delta));
141 * Regular PC relative addressing. Check that this is the
142 * address of a function. The linker sometimes redirects
143 * the entry point by 8 bytes to skip loading the global
144 * pointer, so we all for either address:
146 dest_pc = ((bfd_vma) (pc + 1 + pc->b.disp)) - delta;
147 if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
149 child = sym_lookup (&symtab, dest_pc);
150 DBG (CALLDEBUG,
151 printf (" 0x%lx\t; name=%s, addr=0x%lx",
152 (unsigned long) dest_pc, child->name,
153 (unsigned long) child->addr));
154 if (child->addr == dest_pc || child->addr == dest_pc - 8)
156 DBG (CALLDEBUG, printf ("\n"));
157 /* a hit: */
158 arc_add (parent, child, (unsigned long) 0);
159 continue;
163 * Something funny going on.
165 DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
166 break;
168 default:
169 break;