1*043fbe51Sderaadt /* $OpenBSD: mips64.c,v 1.3 2009/10/27 23:59:38 deraadt Exp $ */
2d9e22319Spefo /* $NetBSD: mips.c,v 1.4 1995/04/19 07:16:11 cgd Exp $ */
3d9e22319Spefo
4d9e22319Spefo /*
5d9e22319Spefo * Copyright (c) 1992, 1993
6d9e22319Spefo * The Regents of the University of California. All rights reserved.
7d9e22319Spefo *
8d9e22319Spefo * This software was developed by the Computer Systems Engineering group
9d9e22319Spefo * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10d9e22319Spefo * contributed to Berkeley. Modified by Ralph Campbell for mips.
11d9e22319Spefo *
12d9e22319Spefo * Redistribution and use in source and binary forms, with or without
13d9e22319Spefo * modification, are permitted provided that the following conditions
14d9e22319Spefo * are met:
15d9e22319Spefo * 1. Redistributions of source code must retain the above copyright
16d9e22319Spefo * notice, this list of conditions and the following disclaimer.
17d9e22319Spefo * 2. Redistributions in binary form must reproduce the above copyright
18d9e22319Spefo * notice, this list of conditions and the following disclaimer in the
19d9e22319Spefo * documentation and/or other materials provided with the distribution.
20d9e22319Spefo * 3. Neither the name of the University nor the names of its contributors
21d9e22319Spefo * may be used to endorse or promote products derived from this software
22d9e22319Spefo * without specific prior written permission.
23d9e22319Spefo *
24d9e22319Spefo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25d9e22319Spefo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26d9e22319Spefo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27d9e22319Spefo * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28d9e22319Spefo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29d9e22319Spefo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30d9e22319Spefo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31d9e22319Spefo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32d9e22319Spefo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33d9e22319Spefo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34d9e22319Spefo * SUCH DAMAGE.
35d9e22319Spefo *
36d9e22319Spefo * From: sparc.c 5.1 (Berkeley) 7/7/92
37d9e22319Spefo */
38d9e22319Spefo
39d9e22319Spefo #include "gprof.h"
40d9e22319Spefo
41d9e22319Spefo /*
42d9e22319Spefo * a namelist entry to be the child of indirect calls
43d9e22319Spefo */
44d9e22319Spefo nltype indirectchild = {
45d9e22319Spefo "(*)" , /* the name */
46d9e22319Spefo (unsigned long) 0 , /* the pc entry point */
47d9e22319Spefo (unsigned long) 0 , /* entry point aligned to histogram */
48d9e22319Spefo (double) 0.0 , /* ticks in this routine */
49d9e22319Spefo (double) 0.0 , /* cumulative ticks in children */
50d9e22319Spefo (long) 0 , /* how many times called */
51d9e22319Spefo (long) 0 , /* times called by live arcs */
52d9e22319Spefo (long) 0 , /* how many calls to self */
53d9e22319Spefo (double) 1.0 , /* propagation fraction */
54d9e22319Spefo (double) 0.0 , /* self propagation time */
55d9e22319Spefo (double) 0.0 , /* child propagation time */
56d9e22319Spefo (short) 0 , /* print flag */
57d9e22319Spefo (short) 0 , /* flags */
58d9e22319Spefo (int) 0 , /* index in the graph list */
59d9e22319Spefo (int) 0 , /* graph call chain top-sort order */
60d9e22319Spefo (int) 0 , /* internal number of cycle on */
61d9e22319Spefo (int) 0 , /* number of live parent arcs */
62d9e22319Spefo (struct nl *) &indirectchild , /* pointer to head of cycle */
63d9e22319Spefo (struct nl *) 0 , /* pointer to next member of cycle */
64d9e22319Spefo (arctype *) 0 , /* list of caller arcs */
65d9e22319Spefo (arctype *) 0 /* list of callee arcs */
66d9e22319Spefo };
67d9e22319Spefo
68d9e22319Spefo void
findcall(nltype * parentp,unsigned long p_lowpc,unsigned long p_highpc)699bd74cdeSespie findcall(nltype *parentp, unsigned long p_lowpc, unsigned long p_highpc)
70d9e22319Spefo {
719bd74cdeSespie unsigned long pc;
72d9e22319Spefo nltype *childp;
73d9e22319Spefo unsigned long destpc;
74d9e22319Spefo long op;
75d9e22319Spefo int off;
76d9e22319Spefo
77d9e22319Spefo if (textspace == 0)
78d9e22319Spefo return;
79d9e22319Spefo if (p_lowpc < s_lowpc)
80d9e22319Spefo p_lowpc = s_lowpc;
81d9e22319Spefo if (p_highpc > s_highpc)
82d9e22319Spefo p_highpc = s_highpc;
83d9e22319Spefo
84d9e22319Spefo for (pc = p_lowpc; pc < p_highpc; pc += 4) {
85d9e22319Spefo off = pc - s_lowpc;
869bd74cdeSespie op = *(unsigned long *)&textspace[off];
87d9e22319Spefo if ((op & 0xfc000000) == 0x0c000000) {
88d9e22319Spefo /*
89d9e22319Spefo * a jal insn -- check that this
90d9e22319Spefo * is the address of a function.
91d9e22319Spefo */
92d9e22319Spefo off = (op & 0x03ffffff) << 2;
93d9e22319Spefo destpc = (pc & 0xf0000000) | off;
94d9e22319Spefo if (destpc >= s_lowpc && destpc <= s_highpc) {
95d9e22319Spefo childp = nllookup(destpc);
96d9e22319Spefo if (childp != 0 && childp->value == destpc)
97d9e22319Spefo addarc(parentp, childp, 0L);
98d9e22319Spefo }
99d9e22319Spefo } else if ((op & 0xfc00f83f) == 0x0000f809)
100d9e22319Spefo /*
101d9e22319Spefo * A jalr -- an indirect call.
102d9e22319Spefo */
103d9e22319Spefo addarc(parentp, &indirectchild, 0L);
104d9e22319Spefo }
105d9e22319Spefo }
106