1179404Sobrien/* 2179404Sobrien * Copyright (c) 1983, 1993, 1998 3179404Sobrien * The Regents of the University of California. All rights reserved. 4179404Sobrien * 5179404Sobrien * Redistribution and use in source and binary forms, with or without 6179404Sobrien * modification, are permitted provided that the following conditions 7179404Sobrien * are met: 8179404Sobrien * 1. Redistributions of source code must retain the above copyright 9179404Sobrien * notice, this list of conditions and the following disclaimer. 10179404Sobrien * 2. Redistributions in binary form must reproduce the above copyright 11179404Sobrien * notice, this list of conditions and the following disclaimer in the 12179404Sobrien * documentation and/or other materials provided with the distribution. 13179404Sobrien * 3. Neither the name of the University nor the names of its contributors 14179404Sobrien * may be used to endorse or promote products derived from this software 15179404Sobrien * without specific prior written permission. 16179404Sobrien * 17179404Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18179404Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19179404Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20179404Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21179404Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22179404Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23179404Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24179404Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25179404Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26179404Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27179404Sobrien * SUCH DAMAGE. 28179404Sobrien */ 29179404Sobrien#include "gprof.h" 30179404Sobrien#include "search_list.h" 31179404Sobrien#include "source.h" 32179404Sobrien#include "symtab.h" 33179404Sobrien#include "cg_arcs.h" 34179404Sobrien#include "corefile.h" 35179404Sobrien#include "hist.h" 36179404Sobrien 37179404Sobrienstatic Sym indirect_child; 38179404Sobrien 39218822Sdimvoid mips_find_call (Sym *, bfd_vma, bfd_vma); 40179404Sobrien 41179404Sobrienvoid 42218822Sdimmips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc) 43179404Sobrien{ 44179404Sobrien bfd_vma pc, dest_pc; 45179404Sobrien unsigned int op; 46179404Sobrien int offset; 47179404Sobrien Sym *child; 48179404Sobrien static bfd_boolean inited = FALSE; 49179404Sobrien 50179404Sobrien if (!inited) 51179404Sobrien { 52179404Sobrien inited = TRUE; 53179404Sobrien sym_init (&indirect_child); 54179404Sobrien indirect_child.name = _("<indirect child>"); 55179404Sobrien indirect_child.cg.prop.fract = 1.0; 56179404Sobrien indirect_child.cg.cyc.head = &indirect_child; 57179404Sobrien } 58179404Sobrien 59179404Sobrien DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"), 60179404Sobrien parent->name, (unsigned long) p_lowpc, 61179404Sobrien (unsigned long) p_highpc)); 62179404Sobrien for (pc = p_lowpc; pc < p_highpc; pc += 4) 63179404Sobrien { 64218822Sdim op = bfd_get_32 (core_bfd, ((unsigned char *)core_text_space 65218822Sdim + pc - core_text_sect->vma)); 66179404Sobrien if ((op & 0xfc000000) == 0x0c000000) 67179404Sobrien { 68179404Sobrien /* This is a "jal" instruction. Check that the destination 69179404Sobrien is the address of a function. */ 70179404Sobrien DBG (CALLDEBUG, 71179404Sobrien printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc)); 72179404Sobrien offset = (op & 0x03ffffff) << 2; 73179404Sobrien dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset; 74218822Sdim if (hist_check_address (dest_pc)) 75179404Sobrien { 76179404Sobrien child = sym_lookup (&symtab, dest_pc); 77179404Sobrien DBG (CALLDEBUG, 78179404Sobrien printf (" 0x%lx\t; name=%s, addr=0x%lx", 79179404Sobrien (unsigned long) dest_pc, child->name, 80179404Sobrien (unsigned long) child->addr)); 81179404Sobrien if (child->addr == dest_pc) 82179404Sobrien { 83179404Sobrien DBG (CALLDEBUG, printf ("\n")); 84179404Sobrien /* a hit: */ 85179404Sobrien arc_add (parent, child, (unsigned long) 0); 86179404Sobrien continue; 87179404Sobrien } 88179404Sobrien } 89179404Sobrien /* Something funny going on. */ 90179404Sobrien DBG (CALLDEBUG, printf ("\tbut it's a botch\n")); 91179404Sobrien } 92179404Sobrien else if ((op & 0xfc00f83f) == 0x0000f809) 93179404Sobrien { 94179404Sobrien /* This is a "jalr" instruction (indirect call). */ 95179404Sobrien DBG (CALLDEBUG, 96179404Sobrien printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc)); 97179404Sobrien arc_add (parent, &indirect_child, (unsigned long) 0); 98179404Sobrien } 99179404Sobrien } 100179404Sobrien} 101