12a6b7db3Sskrll /*
22a6b7db3Sskrll * Copyright (c) 1983, 1993, 1998
32a6b7db3Sskrll * The Regents of the University of California. All rights reserved.
42a6b7db3Sskrll *
52a6b7db3Sskrll * Redistribution and use in source and binary forms, with or without
62a6b7db3Sskrll * modification, are permitted provided that the following conditions
72a6b7db3Sskrll * are met:
82a6b7db3Sskrll * 1. Redistributions of source code must retain the above copyright
92a6b7db3Sskrll * notice, this list of conditions and the following disclaimer.
102a6b7db3Sskrll * 2. Redistributions in binary form must reproduce the above copyright
112a6b7db3Sskrll * notice, this list of conditions and the following disclaimer in the
122a6b7db3Sskrll * documentation and/or other materials provided with the distribution.
132a6b7db3Sskrll * 3. Neither the name of the University nor the names of its contributors
142a6b7db3Sskrll * may be used to endorse or promote products derived from this software
152a6b7db3Sskrll * without specific prior written permission.
162a6b7db3Sskrll *
172a6b7db3Sskrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182a6b7db3Sskrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
192a6b7db3Sskrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202a6b7db3Sskrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212a6b7db3Sskrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222a6b7db3Sskrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232a6b7db3Sskrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242a6b7db3Sskrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252a6b7db3Sskrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262a6b7db3Sskrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272a6b7db3Sskrll * SUCH DAMAGE.
282a6b7db3Sskrll */
292a6b7db3Sskrll #include "gprof.h"
302a6b7db3Sskrll #include "search_list.h"
312a6b7db3Sskrll #include "source.h"
322a6b7db3Sskrll #include "symtab.h"
332a6b7db3Sskrll #include "cg_arcs.h"
342a6b7db3Sskrll #include "corefile.h"
352a6b7db3Sskrll #include "hist.h"
362a6b7db3Sskrll
372a6b7db3Sskrll static Sym indirect_child;
382a6b7db3Sskrll
392a6b7db3Sskrll void mips_find_call (Sym *, bfd_vma, bfd_vma);
402a6b7db3Sskrll
412a6b7db3Sskrll void
mips_find_call(Sym * parent,bfd_vma p_lowpc,bfd_vma p_highpc)422a6b7db3Sskrll mips_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
432a6b7db3Sskrll {
442a6b7db3Sskrll bfd_vma pc, dest_pc;
452a6b7db3Sskrll unsigned int op;
462a6b7db3Sskrll int offset;
472a6b7db3Sskrll Sym *child;
484f645668Schristos static bool inited = false;
492a6b7db3Sskrll
502a6b7db3Sskrll if (!inited)
512a6b7db3Sskrll {
524f645668Schristos inited = true;
532a6b7db3Sskrll sym_init (&indirect_child);
542a6b7db3Sskrll indirect_child.name = _("<indirect child>");
552a6b7db3Sskrll indirect_child.cg.prop.fract = 1.0;
562a6b7db3Sskrll indirect_child.cg.cyc.head = &indirect_child;
572a6b7db3Sskrll }
582a6b7db3Sskrll
592a6b7db3Sskrll DBG (CALLDEBUG, printf (_("[find_call] %s: 0x%lx to 0x%lx\n"),
602a6b7db3Sskrll parent->name, (unsigned long) p_lowpc,
612a6b7db3Sskrll (unsigned long) p_highpc));
62*cb63e24eSchristos p_lowpc = (p_lowpc + 3) & ~3;
63*cb63e24eSchristos p_highpc &= ~3;
642a6b7db3Sskrll for (pc = p_lowpc; pc < p_highpc; pc += 4)
652a6b7db3Sskrll {
662a6b7db3Sskrll op = bfd_get_32 (core_bfd, ((unsigned char *)core_text_space
672a6b7db3Sskrll + pc - core_text_sect->vma));
682a6b7db3Sskrll if ((op & 0xfc000000) == 0x0c000000)
692a6b7db3Sskrll {
702a6b7db3Sskrll /* This is a "jal" instruction. Check that the destination
712a6b7db3Sskrll is the address of a function. */
722a6b7db3Sskrll DBG (CALLDEBUG,
732a6b7db3Sskrll printf (_("[find_call] 0x%lx: jal"), (unsigned long) pc));
742a6b7db3Sskrll offset = (op & 0x03ffffff) << 2;
752a6b7db3Sskrll dest_pc = (pc & ~(bfd_vma) 0xfffffff) | offset;
762a6b7db3Sskrll if (hist_check_address (dest_pc))
772a6b7db3Sskrll {
782a6b7db3Sskrll child = sym_lookup (&symtab, dest_pc);
79be12b8bcSchristos if (child)
80be12b8bcSchristos {
812a6b7db3Sskrll DBG (CALLDEBUG,
822a6b7db3Sskrll printf (" 0x%lx\t; name=%s, addr=0x%lx",
832a6b7db3Sskrll (unsigned long) dest_pc, child->name,
842a6b7db3Sskrll (unsigned long) child->addr));
852a6b7db3Sskrll if (child->addr == dest_pc)
862a6b7db3Sskrll {
872a6b7db3Sskrll DBG (CALLDEBUG, printf ("\n"));
882a6b7db3Sskrll /* a hit: */
892a6b7db3Sskrll arc_add (parent, child, (unsigned long) 0);
902a6b7db3Sskrll continue;
912a6b7db3Sskrll }
922a6b7db3Sskrll }
93be12b8bcSchristos }
942a6b7db3Sskrll /* Something funny going on. */
952a6b7db3Sskrll DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
962a6b7db3Sskrll }
972a6b7db3Sskrll else if ((op & 0xfc00f83f) == 0x0000f809)
982a6b7db3Sskrll {
992a6b7db3Sskrll /* This is a "jalr" instruction (indirect call). */
1002a6b7db3Sskrll DBG (CALLDEBUG,
1012a6b7db3Sskrll printf (_("[find_call] 0x%lx: jalr\n"), (unsigned long) pc));
1022a6b7db3Sskrll arc_add (parent, &indirect_child, (unsigned long) 0);
1032a6b7db3Sskrll }
1042a6b7db3Sskrll }
1052a6b7db3Sskrll }
106