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