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