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