Back to index

cell-binutils  2.17cvs20070401
mips.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1983, 1993, 1998
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 static Sym indirect_child;
00038 
00039 void mips_find_call (Sym *, bfd_vma, bfd_vma);
00040 
00041 void
00042 mips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
00043 {
00044   bfd_vma pc, dest_pc;
00045   unsigned int op;
00046   int offset;
00047   Sym *child;
00048   static bfd_boolean inited = FALSE;
00049 
00050   if (!inited)
00051     {
00052       inited = TRUE;
00053       sym_init (&indirect_child);
00054       indirect_child.name = _("<indirect child>");
00055       indirect_child.cg.prop.fract = 1.0;
00056       indirect_child.cg.cyc.head = &indirect_child;
00057     }
00058 
00059   if (!core_text_space)
00060     {
00061       return;
00062     }
00063   if (p_lowpc < s_lowpc)
00064     {
00065       p_lowpc = s_lowpc;
00066     }
00067   if (p_highpc > s_highpc)
00068     {
00069       p_highpc = s_highpc;
00070     }
00071   DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
00072                        parent->name, (unsigned long) p_lowpc,
00073                        (unsigned long) p_highpc));
00074   for (pc = p_lowpc; pc < p_highpc; pc += 4)
00075     {
00076       op = bfd_get_32 (core_bfd, &((char *)core_text_space)[pc - s_lowpc]);
00077       if ((op & 0xfc000000) == 0x0c000000)
00078        {
00079          /* This is a "jal" instruction.  Check that the destination
00080             is the address of a function.  */
00081          DBG (CALLDEBUG,
00082               printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc));
00083           offset = (op & 0x03ffffff) << 2;
00084          dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset;
00085          if (dest_pc >= s_lowpc && dest_pc <= s_highpc)
00086            {
00087              child = sym_lookup (&symtab, dest_pc);
00088              DBG (CALLDEBUG,
00089                  printf (" 0x%lx\t; name=%s, addr=0x%lx",
00090                         (unsigned long) dest_pc, child->name,
00091                         (unsigned long) child->addr));
00092              if (child->addr == dest_pc)
00093               {
00094                 DBG (CALLDEBUG, printf ("\n"));
00095                 /* a hit:  */
00096                 arc_add (parent, child, (unsigned long) 0);
00097                 continue;
00098               }
00099            }
00100          /* Something funny going on.  */
00101          DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
00102        }
00103       else if ((op & 0xfc00f83f) == 0x0000f809)
00104        {
00105          /* This is a "jalr" instruction (indirect call).  */
00106          DBG (CALLDEBUG,
00107               printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc));
00108          arc_add (parent, &indirect_child, (unsigned long) 0);
00109        }
00110     }
00111 }