1*fae548d3Szrj /*
2*fae548d3Szrj * Copyright (c) 1983, 1993
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 /*
38*fae548d3Szrj * opcode of the `callf' instruction
39*fae548d3Szrj */
40*fae548d3Szrj #define CALL (0xc0000000)
41*fae548d3Szrj
42*fae548d3Szrj void sparc_find_call (Sym *, bfd_vma, bfd_vma);
43*fae548d3Szrj
44*fae548d3Szrj void
sparc_find_call(Sym * parent,bfd_vma p_lowpc,bfd_vma p_highpc)45*fae548d3Szrj sparc_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
46*fae548d3Szrj {
47*fae548d3Szrj bfd_vma pc, dest_pc;
48*fae548d3Szrj unsigned int insn;
49*fae548d3Szrj Sym *child;
50*fae548d3Szrj
51*fae548d3Szrj DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
52*fae548d3Szrj parent->name, (unsigned long) p_lowpc,
53*fae548d3Szrj (unsigned long) p_highpc));
54*fae548d3Szrj for (pc = (p_lowpc + 3) & ~(bfd_vma) 3; pc < p_highpc; pc += 4)
55*fae548d3Szrj {
56*fae548d3Szrj insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
57*fae548d3Szrj + pc - core_text_sect->vma));
58*fae548d3Szrj if (insn & CALL)
59*fae548d3Szrj {
60*fae548d3Szrj DBG (CALLDEBUG,
61*fae548d3Szrj printf ("[find_call] 0x%lx: callf", (unsigned long) pc));
62*fae548d3Szrj /*
63*fae548d3Szrj * Regular pc relative addressing check that this is the
64*fae548d3Szrj * address of a function.
65*fae548d3Szrj */
66*fae548d3Szrj dest_pc = pc + (((bfd_signed_vma) (insn & 0x3fffffff)
67*fae548d3Szrj ^ 0x20000000) - 0x20000000);
68*fae548d3Szrj if (hist_check_address (dest_pc))
69*fae548d3Szrj {
70*fae548d3Szrj child = sym_lookup (&symtab, dest_pc);
71*fae548d3Szrj if (child)
72*fae548d3Szrj {
73*fae548d3Szrj DBG (CALLDEBUG,
74*fae548d3Szrj printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
75*fae548d3Szrj (unsigned long) dest_pc, child->name,
76*fae548d3Szrj (unsigned long) child->addr));
77*fae548d3Szrj if (child->addr == dest_pc)
78*fae548d3Szrj {
79*fae548d3Szrj /* a hit: */
80*fae548d3Szrj arc_add (parent, child, (unsigned long) 0);
81*fae548d3Szrj continue;
82*fae548d3Szrj }
83*fae548d3Szrj }
84*fae548d3Szrj }
85*fae548d3Szrj /*
86*fae548d3Szrj * Something funny going on.
87*fae548d3Szrj */
88*fae548d3Szrj DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
89*fae548d3Szrj }
90*fae548d3Szrj }
91*fae548d3Szrj }
92