* alpha.c (alpha_Instruction): Don't use.
[deliverable/binutils-gdb.git] / gprof / alpha.c
CommitLineData
252b5132
RH
1/*
2 * Copyright (c) 1983, 1998 Regents of the University of California.
3 * All rights reserved.
4 *
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.
18 */
19#include "gprof.h"
6d9c411a
AM
20#include "search_list.h"
21#include "source.h"
22#include "symtab.h"
252b5132
RH
23#include "cg_arcs.h"
24#include "corefile.h"
25#include "hist.h"
252b5132
RH
26
27/*
28 * Opcodes of the call instructions:
29 */
30#define OP_Jxx 0x1a
31#define OP_BSR 0x34
32
33#define Jxx_FUNC_JMP 0
34#define Jxx_FUNC_JSR 1
35#define Jxx_FUNC_RET 2
36#define Jxx_FUNC_JSR_COROUTINE 3
37
6d9c411a
AM
38#if 0
39/* Here to document only. We can't use this when cross compiling as
40 the bitfield layout might not be the same as native. */
252b5132
RH
41typedef union
42 {
43 struct
44 {
45 unsigned other:26;
46 unsigned op_code:6;
47 }
48 a; /* any format */
49 struct
50 {
51 int disp:21;
52 unsigned ra:5;
53 unsigned op_code:6;
54 }
55 b; /* branch format */
56 struct
57 {
58 int hint:14;
59 unsigned func:2;
60 unsigned rb:5;
61 unsigned ra:5;
62 unsigned op_code:6;
63 }
64 j; /* jump format */
65 }
66alpha_Instruction;
6d9c411a 67#endif
252b5132
RH
68
69static Sym indirect_child;
70
5789ecea 71void alpha_find_call PARAMS ((Sym *, bfd_vma, bfd_vma));
252b5132
RH
72
73/*
74 * On the Alpha we can only detect PC relative calls, which are
75 * usually generated for calls to functions within the same
76 * object file only. This is still better than nothing, however.
77 * (In particular it should be possible to find functions that
78 * potentially call integer division routines, for example.)
79 */
80void
81alpha_find_call (parent, p_lowpc, p_highpc)
82 Sym *parent;
83 bfd_vma p_lowpc;
84 bfd_vma p_highpc;
85{
6d9c411a
AM
86 bfd_vma pc, dest_pc;
87 unsigned long insn;
252b5132
RH
88 Sym *child;
89
6d9c411a 90 if (indirect_child.name == NULL)
252b5132 91 {
252b5132
RH
92 sym_init (&indirect_child);
93 indirect_child.name = _("<indirect child>");
94 indirect_child.cg.prop.fract = 1.0;
95 indirect_child.cg.cyc.head = &indirect_child;
96 }
97
98 if (!core_text_space)
99 {
100 return;
101 }
102 if (p_lowpc < s_lowpc)
103 {
104 p_lowpc = s_lowpc;
105 }
106 if (p_highpc > s_highpc)
107 {
108 p_highpc = s_highpc;
109 }
110 DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
fdcf7d43
ILT
111 parent->name, (unsigned long) p_lowpc,
112 (unsigned long) p_highpc));
6d9c411a 113 for (pc = (p_lowpc + 3) & ~3; pc < p_highpc; pc += 4)
252b5132 114 {
6d9c411a
AM
115 insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
116 + pc - core_text_sect->vma));
117 switch (insn & (0x3f << 26))
252b5132 118 {
6d9c411a 119 case OP_Jxx << 26:
252b5132
RH
120 /*
121 * There is no simple and reliable way to determine the
122 * target of a jsr (the hint bits help, but there aren't
123 * enough bits to get a satisfactory hit rate). Instead,
124 * for any indirect jump we simply add an arc from PARENT
125 * to INDIRECT_CHILD---that way the user it at least able
126 * to see that there are other calls as well.
127 */
6d9c411a
AM
128 if ((insn & (3 << 14)) == Jxx_FUNC_JSR << 14
129 || (insn & (3 << 14)) == Jxx_FUNC_JSR_COROUTINE << 14)
252b5132
RH
130 {
131 DBG (CALLDEBUG,
132 printf (_("[find_call] 0x%lx: jsr%s <indirect_child>\n"),
6d9c411a
AM
133 (unsigned long) pc,
134 ((insn & (3 << 14)) == Jxx_FUNC_JSR << 14
135 ? "" : "_coroutine")));
252b5132
RH
136 arc_add (parent, &indirect_child, (unsigned long) 0);
137 }
138 break;
139
6d9c411a 140 case OP_BSR << 26:
252b5132 141 DBG (CALLDEBUG,
6d9c411a 142 printf (_("[find_call] 0x%lx: bsr"), (unsigned long) pc));
252b5132
RH
143 /*
144 * Regular PC relative addressing. Check that this is the
145 * address of a function. The linker sometimes redirects
146 * the entry point by 8 bytes to skip loading the global
6d9c411a 147 * pointer, so we allow for either address:
252b5132 148 */
6d9c411a
AM
149 dest_pc = pc + 4 + (((bfd_signed_vma) (insn & 0x1fffff)
150 ^ 0x100000) - 0x100000);
252b5132
RH
151 if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
152 {
153 child = sym_lookup (&symtab, dest_pc);
154 DBG (CALLDEBUG,
155 printf (" 0x%lx\t; name=%s, addr=0x%lx",
fdcf7d43
ILT
156 (unsigned long) dest_pc, child->name,
157 (unsigned long) child->addr));
252b5132
RH
158 if (child->addr == dest_pc || child->addr == dest_pc - 8)
159 {
160 DBG (CALLDEBUG, printf ("\n"));
161 /* a hit: */
162 arc_add (parent, child, (unsigned long) 0);
163 continue;
164 }
165 }
166 /*
167 * Something funny going on.
168 */
169 DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
170 break;
171
172 default:
173 break;
174 }
175 }
176}
This page took 0.102465 seconds and 4 git commands to generate.