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