175fd0b74Schristos /*
275fd0b74Schristos * Copyright (c) 1983, 1993, 1998
375fd0b74Schristos * The Regents of the University of California. All rights reserved.
475fd0b74Schristos *
575fd0b74Schristos * Redistribution and use in source and binary forms, with or without
675fd0b74Schristos * modification, are permitted provided that the following conditions
775fd0b74Schristos * are met:
875fd0b74Schristos * 1. Redistributions of source code must retain the above copyright
975fd0b74Schristos * notice, this list of conditions and the following disclaimer.
1075fd0b74Schristos * 2. Redistributions in binary form must reproduce the above copyright
1175fd0b74Schristos * notice, this list of conditions and the following disclaimer in the
1275fd0b74Schristos * documentation and/or other materials provided with the distribution.
1375fd0b74Schristos * 3. Neither the name of the University nor the names of its contributors
1475fd0b74Schristos * may be used to endorse or promote products derived from this software
1575fd0b74Schristos * without specific prior written permission.
1675fd0b74Schristos *
1775fd0b74Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1875fd0b74Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1975fd0b74Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2075fd0b74Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2175fd0b74Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2275fd0b74Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2375fd0b74Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2475fd0b74Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2575fd0b74Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2675fd0b74Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2775fd0b74Schristos * SUCH DAMAGE.
2875fd0b74Schristos */
2975fd0b74Schristos #include "gprof.h"
3075fd0b74Schristos #include "search_list.h"
3175fd0b74Schristos #include "source.h"
3275fd0b74Schristos #include "symtab.h"
3375fd0b74Schristos #include "cg_arcs.h"
3475fd0b74Schristos #include "corefile.h"
3575fd0b74Schristos #include "hist.h"
3675fd0b74Schristos
3775fd0b74Schristos static Sym indirect_child;
3875fd0b74Schristos
3975fd0b74Schristos void mips_find_call (Sym *, bfd_vma, bfd_vma);
4075fd0b74Schristos
4175fd0b74Schristos void
mips_find_call(Sym * parent,bfd_vma p_lowpc,bfd_vma p_highpc)4275fd0b74Schristos mips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
4375fd0b74Schristos {
4475fd0b74Schristos bfd_vma pc, dest_pc;
4575fd0b74Schristos unsigned int op;
4675fd0b74Schristos int offset;
4775fd0b74Schristos Sym *child;
48*e992f068Schristos static bool inited = false;
4975fd0b74Schristos
5075fd0b74Schristos if (!inited)
5175fd0b74Schristos {
52*e992f068Schristos inited = true;
5375fd0b74Schristos sym_init (&indirect_child);
5475fd0b74Schristos indirect_child.name = _("<indirect child>");
5575fd0b74Schristos indirect_child.cg.prop.fract = 1.0;
5675fd0b74Schristos indirect_child.cg.cyc.head = &indirect_child;
5775fd0b74Schristos }
5875fd0b74Schristos
5975fd0b74Schristos DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
6075fd0b74Schristos parent->name, (unsigned long) p_lowpc,
6175fd0b74Schristos (unsigned long) p_highpc));
6275fd0b74Schristos for (pc = p_lowpc; pc < p_highpc; pc += 4)
6375fd0b74Schristos {
6475fd0b74Schristos op = bfd_get_32 (core_bfd, ((unsigned char *)core_text_space
6575fd0b74Schristos + pc - core_text_sect->vma));
6675fd0b74Schristos if ((op & 0xfc000000) == 0x0c000000)
6775fd0b74Schristos {
6875fd0b74Schristos /* This is a "jal" instruction. Check that the destination
6975fd0b74Schristos is the address of a function. */
7075fd0b74Schristos DBG (CALLDEBUG,
7175fd0b74Schristos printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc));
7275fd0b74Schristos offset = (op & 0x03ffffff) << 2;
7375fd0b74Schristos dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset;
7475fd0b74Schristos if (hist_check_address (dest_pc))
7575fd0b74Schristos {
7675fd0b74Schristos child = sym_lookup (&symtab, dest_pc);
7775fd0b74Schristos if (child)
7875fd0b74Schristos {
7975fd0b74Schristos DBG (CALLDEBUG,
8075fd0b74Schristos printf (" 0x%lx\t; name=%s, addr=0x%lx",
8175fd0b74Schristos (unsigned long) dest_pc, child->name,
8275fd0b74Schristos (unsigned long) child->addr));
8375fd0b74Schristos if (child->addr == dest_pc)
8475fd0b74Schristos {
8575fd0b74Schristos DBG (CALLDEBUG, printf ("\n"));
8675fd0b74Schristos /* a hit: */
8775fd0b74Schristos arc_add (parent, child, (unsigned long) 0);
8875fd0b74Schristos continue;
8975fd0b74Schristos }
9075fd0b74Schristos }
9175fd0b74Schristos }
9275fd0b74Schristos /* Something funny going on. */
9375fd0b74Schristos DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
9475fd0b74Schristos }
9575fd0b74Schristos else if ((op & 0xfc00f83f) == 0x0000f809)
9675fd0b74Schristos {
9775fd0b74Schristos /* This is a "jalr" instruction (indirect call). */
9875fd0b74Schristos DBG (CALLDEBUG,
9975fd0b74Schristos printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc));
10075fd0b74Schristos arc_add (parent, &indirect_child, (unsigned long) 0);
10175fd0b74Schristos }
10275fd0b74Schristos }
10375fd0b74Schristos }
104