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