1*3d8817e4Smiod /*
2*3d8817e4Smiod * Copyright (c) 1983, 1993, 1998
3*3d8817e4Smiod * The Regents of the University of California. All rights reserved.
4*3d8817e4Smiod *
5*3d8817e4Smiod * Redistribution and use in source and binary forms, with or without
6*3d8817e4Smiod * modification, are permitted provided that the following conditions
7*3d8817e4Smiod * are met:
8*3d8817e4Smiod * 1. Redistributions of source code must retain the above copyright
9*3d8817e4Smiod * notice, this list of conditions and the following disclaimer.
10*3d8817e4Smiod * 2. Redistributions in binary form must reproduce the above copyright
11*3d8817e4Smiod * notice, this list of conditions and the following disclaimer in the
12*3d8817e4Smiod * documentation and/or other materials provided with the distribution.
13*3d8817e4Smiod * 3. Neither the name of the University nor the names of its contributors
14*3d8817e4Smiod * may be used to endorse or promote products derived from this software
15*3d8817e4Smiod * without specific prior written permission.
16*3d8817e4Smiod *
17*3d8817e4Smiod * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*3d8817e4Smiod * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*3d8817e4Smiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*3d8817e4Smiod * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*3d8817e4Smiod * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*3d8817e4Smiod * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*3d8817e4Smiod * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*3d8817e4Smiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*3d8817e4Smiod * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*3d8817e4Smiod * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*3d8817e4Smiod * SUCH DAMAGE.
28*3d8817e4Smiod */
29*3d8817e4Smiod #include "gprof.h"
30*3d8817e4Smiod #include "search_list.h"
31*3d8817e4Smiod #include "source.h"
32*3d8817e4Smiod #include "symtab.h"
33*3d8817e4Smiod #include "cg_arcs.h"
34*3d8817e4Smiod #include "corefile.h"
35*3d8817e4Smiod #include "hist.h"
36*3d8817e4Smiod
37*3d8817e4Smiod static Sym indirect_child;
38*3d8817e4Smiod
39*3d8817e4Smiod void mips_find_call (Sym *, bfd_vma, bfd_vma);
40*3d8817e4Smiod
41*3d8817e4Smiod void
mips_find_call(Sym * parent,bfd_vma p_lowpc,bfd_vma p_highpc)42*3d8817e4Smiod mips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
43*3d8817e4Smiod {
44*3d8817e4Smiod bfd_vma pc, dest_pc;
45*3d8817e4Smiod unsigned int op;
46*3d8817e4Smiod int offset;
47*3d8817e4Smiod Sym *child;
48*3d8817e4Smiod static bfd_boolean inited = FALSE;
49*3d8817e4Smiod
50*3d8817e4Smiod if (!inited)
51*3d8817e4Smiod {
52*3d8817e4Smiod inited = TRUE;
53*3d8817e4Smiod sym_init (&indirect_child);
54*3d8817e4Smiod indirect_child.name = _("<indirect child>");
55*3d8817e4Smiod indirect_child.cg.prop.fract = 1.0;
56*3d8817e4Smiod indirect_child.cg.cyc.head = &indirect_child;
57*3d8817e4Smiod }
58*3d8817e4Smiod
59*3d8817e4Smiod if (!core_text_space)
60*3d8817e4Smiod {
61*3d8817e4Smiod return;
62*3d8817e4Smiod }
63*3d8817e4Smiod if (p_lowpc < s_lowpc)
64*3d8817e4Smiod {
65*3d8817e4Smiod p_lowpc = s_lowpc;
66*3d8817e4Smiod }
67*3d8817e4Smiod if (p_highpc > s_highpc)
68*3d8817e4Smiod {
69*3d8817e4Smiod p_highpc = s_highpc;
70*3d8817e4Smiod }
71*3d8817e4Smiod DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
72*3d8817e4Smiod parent->name, (unsigned long) p_lowpc,
73*3d8817e4Smiod (unsigned long) p_highpc));
74*3d8817e4Smiod for (pc = p_lowpc; pc < p_highpc; pc += 4)
75*3d8817e4Smiod {
76*3d8817e4Smiod op = bfd_get_32 (core_bfd, &((char *)core_text_space)[pc - s_lowpc]);
77*3d8817e4Smiod if ((op & 0xfc000000) == 0x0c000000)
78*3d8817e4Smiod {
79*3d8817e4Smiod /* This is a "jal" instruction. Check that the destination
80*3d8817e4Smiod is the address of a function. */
81*3d8817e4Smiod DBG (CALLDEBUG,
82*3d8817e4Smiod printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc));
83*3d8817e4Smiod offset = (op & 0x03ffffff) << 2;
84*3d8817e4Smiod dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset;
85*3d8817e4Smiod if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
86*3d8817e4Smiod {
87*3d8817e4Smiod child = sym_lookup (&symtab, dest_pc);
88*3d8817e4Smiod DBG (CALLDEBUG,
89*3d8817e4Smiod printf (" 0x%lx\t; name=%s, addr=0x%lx",
90*3d8817e4Smiod (unsigned long) dest_pc, child->name,
91*3d8817e4Smiod (unsigned long) child->addr));
92*3d8817e4Smiod if (child->addr == dest_pc)
93*3d8817e4Smiod {
94*3d8817e4Smiod DBG (CALLDEBUG, printf ("\n"));
95*3d8817e4Smiod /* a hit: */
96*3d8817e4Smiod arc_add (parent, child, (unsigned long) 0);
97*3d8817e4Smiod continue;
98*3d8817e4Smiod }
99*3d8817e4Smiod }
100*3d8817e4Smiod /* Something funny going on. */
101*3d8817e4Smiod DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
102*3d8817e4Smiod }
103*3d8817e4Smiod else if ((op & 0xfc00f83f) == 0x0000f809)
104*3d8817e4Smiod {
105*3d8817e4Smiod /* This is a "jalr" instruction (indirect call). */
106*3d8817e4Smiod DBG (CALLDEBUG,
107*3d8817e4Smiod printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc));
108*3d8817e4Smiod arc_add (parent, &indirect_child, (unsigned long) 0);
109*3d8817e4Smiod }
110*3d8817e4Smiod }
111*3d8817e4Smiod }
112