xref: /netbsd-src/external/gpl3/binutils/dist/gprof/sparc.c (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
12a6b7db3Sskrll /*
22a6b7db3Sskrll  * Copyright (c) 1983, 1993
32a6b7db3Sskrll  *      The Regents of the University of California.  All rights reserved.
42a6b7db3Sskrll  *
52a6b7db3Sskrll  * Redistribution and use in source and binary forms, with or without
62a6b7db3Sskrll  * modification, are permitted provided that the following conditions
72a6b7db3Sskrll  * are met:
82a6b7db3Sskrll  * 1. Redistributions of source code must retain the above copyright
92a6b7db3Sskrll  *    notice, this list of conditions and the following disclaimer.
102a6b7db3Sskrll  * 2. Redistributions in binary form must reproduce the above copyright
112a6b7db3Sskrll  *    notice, this list of conditions and the following disclaimer in the
122a6b7db3Sskrll  *    documentation and/or other materials provided with the distribution.
132a6b7db3Sskrll  * 3. Neither the name of the University nor the names of its contributors
142a6b7db3Sskrll  *    may be used to endorse or promote products derived from this software
152a6b7db3Sskrll  *    without specific prior written permission.
162a6b7db3Sskrll  *
172a6b7db3Sskrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182a6b7db3Sskrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
192a6b7db3Sskrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202a6b7db3Sskrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212a6b7db3Sskrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222a6b7db3Sskrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232a6b7db3Sskrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242a6b7db3Sskrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252a6b7db3Sskrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262a6b7db3Sskrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272a6b7db3Sskrll  * SUCH DAMAGE.
282a6b7db3Sskrll  */
292a6b7db3Sskrll #include "gprof.h"
302a6b7db3Sskrll #include "search_list.h"
312a6b7db3Sskrll #include "source.h"
322a6b7db3Sskrll #include "symtab.h"
332a6b7db3Sskrll #include "cg_arcs.h"
342a6b7db3Sskrll #include "corefile.h"
352a6b7db3Sskrll #include "hist.h"
362a6b7db3Sskrll 
372a6b7db3Sskrll     /*
382a6b7db3Sskrll      *        opcode of the `callf' instruction
392a6b7db3Sskrll      */
402a6b7db3Sskrll #define	CALL	(0xc0000000)
412a6b7db3Sskrll 
422a6b7db3Sskrll void sparc_find_call (Sym *, bfd_vma, bfd_vma);
432a6b7db3Sskrll 
442a6b7db3Sskrll void
sparc_find_call(Sym * parent,bfd_vma p_lowpc,bfd_vma p_highpc)452a6b7db3Sskrll sparc_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
462a6b7db3Sskrll {
472a6b7db3Sskrll   bfd_vma pc, dest_pc;
482a6b7db3Sskrll   unsigned int insn;
492a6b7db3Sskrll   Sym *child;
502a6b7db3Sskrll 
512a6b7db3Sskrll   DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
522a6b7db3Sskrll 			  parent->name, (unsigned long) p_lowpc,
532a6b7db3Sskrll 			  (unsigned long) p_highpc));
54*cb63e24eSchristos   p_lowpc = (p_lowpc + 3) & ~3;
55*cb63e24eSchristos   p_highpc &= ~3;
56*cb63e24eSchristos   for (pc = p_lowpc; pc < p_highpc; pc += 4)
572a6b7db3Sskrll     {
582a6b7db3Sskrll       insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
592a6b7db3Sskrll 				    + pc - core_text_sect->vma));
602a6b7db3Sskrll       if (insn & CALL)
612a6b7db3Sskrll 	{
622a6b7db3Sskrll 	  DBG (CALLDEBUG,
632a6b7db3Sskrll 	       printf ("[find_call] 0x%lx: callf", (unsigned long) pc));
642a6b7db3Sskrll 	  /*
652a6b7db3Sskrll 	   * Regular pc relative addressing check that this is the
662a6b7db3Sskrll 	   * address of a function.
672a6b7db3Sskrll 	   */
682a6b7db3Sskrll 	  dest_pc = pc + (((bfd_signed_vma) (insn & 0x3fffffff)
692a6b7db3Sskrll 			   ^ 0x20000000) - 0x20000000);
702a6b7db3Sskrll 	  if (hist_check_address (dest_pc))
712a6b7db3Sskrll 	    {
722a6b7db3Sskrll 	      child = sym_lookup (&symtab, dest_pc);
73be12b8bcSchristos 	      if (child)
74be12b8bcSchristos 		{
752a6b7db3Sskrll 	          DBG (CALLDEBUG,
762a6b7db3Sskrll 		      printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
772a6b7db3Sskrll 			     (unsigned long) dest_pc, child->name,
782a6b7db3Sskrll 			     (unsigned long) child->addr));
792a6b7db3Sskrll 	          if (child->addr == dest_pc)
802a6b7db3Sskrll 		    {
812a6b7db3Sskrll 		      /* a hit:  */
822a6b7db3Sskrll 		      arc_add (parent, child, (unsigned long) 0);
832a6b7db3Sskrll 		      continue;
842a6b7db3Sskrll 		    }
852a6b7db3Sskrll 		}
86be12b8bcSchristos 	    }
872a6b7db3Sskrll 	  /*
882a6b7db3Sskrll 	   * Something funny going on.
892a6b7db3Sskrll 	   */
902a6b7db3Sskrll 	  DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
912a6b7db3Sskrll 	}
922a6b7db3Sskrll     }
932a6b7db3Sskrll }
94