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