Back to index

cell-binutils  2.17cvs20070401
sparc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1983, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 #include "gprof.h"
00030 #include "search_list.h"
00031 #include "source.h"
00032 #include "symtab.h"
00033 #include "cg_arcs.h"
00034 #include "corefile.h"
00035 #include "hist.h"
00036 
00037     /*
00038      *        opcode of the `callf' instruction
00039      */
00040 #define       CALL   (0xc0000000)
00041 
00042 void sparc_find_call (Sym *, bfd_vma, bfd_vma);
00043 
00044 void
00045 sparc_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
00046 {
00047   bfd_vma pc, dest_pc;
00048   unsigned int insn;
00049   Sym *child;
00050 
00051   if (core_text_space == 0)
00052     {
00053       return;
00054     }
00055   if (p_lowpc < s_lowpc)
00056     {
00057       p_lowpc = s_lowpc;
00058     }
00059   if (p_highpc > s_highpc)
00060     {
00061       p_highpc = s_highpc;
00062     }
00063   DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
00064                        parent->name, (unsigned long) p_lowpc,
00065                        (unsigned long) p_highpc));
00066   for (pc = (p_lowpc + 3) & ~(bfd_vma) 3; pc < p_highpc; pc += 4)
00067     {
00068       insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
00069                                 + pc - core_text_sect->vma));
00070       if (insn & CALL)
00071        {
00072          DBG (CALLDEBUG,
00073               printf ("[find_call] 0x%lx: callf", (unsigned long) pc));
00074          /*
00075           * Regular pc relative addressing check that this is the
00076           * address of a function.
00077           */
00078          dest_pc = pc + (((bfd_signed_vma) (insn & 0x3fffffff)
00079                         ^ 0x20000000) - 0x20000000);
00080          if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
00081            {
00082              child = sym_lookup (&symtab, dest_pc);
00083              DBG (CALLDEBUG,
00084                  printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
00085                         (unsigned long) dest_pc, child->name,
00086                         (unsigned long) child->addr));
00087              if (child->addr == dest_pc)
00088               {
00089                 /* a hit:  */
00090                 arc_add (parent, child, (unsigned long) 0);
00091                 continue;
00092               }
00093            }
00094          /*
00095           * Something funny going on.
00096           */
00097          DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
00098        }
00099     }
00100 }