1 /* $OpenBSD: mips64.c,v 1.2 2006/03/25 19:06:36 espie Exp $ */ 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. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * From: sparc.c 5.1 (Berkeley) 7/7/92 37 */ 38 39 #ifndef lint 40 #if 0 41 static char sccsid[] = "@(#)mips.c 8.1 (Berkeley) 6/6/93"; 42 #else 43 static char rcsid[] = "$OpenBSD: mips64.c,v 1.2 2006/03/25 19:06:36 espie Exp $"; 44 #endif 45 #endif /* not lint */ 46 47 #include "gprof.h" 48 49 /* 50 * a namelist entry to be the child of indirect calls 51 */ 52 nltype indirectchild = { 53 "(*)" , /* the name */ 54 (unsigned long) 0 , /* the pc entry point */ 55 (unsigned long) 0 , /* entry point aligned to histogram */ 56 (double) 0.0 , /* ticks in this routine */ 57 (double) 0.0 , /* cumulative ticks in children */ 58 (long) 0 , /* how many times called */ 59 (long) 0 , /* times called by live arcs */ 60 (long) 0 , /* how many calls to self */ 61 (double) 1.0 , /* propagation fraction */ 62 (double) 0.0 , /* self propagation time */ 63 (double) 0.0 , /* child propagation time */ 64 (short) 0 , /* print flag */ 65 (short) 0 , /* flags */ 66 (int) 0 , /* index in the graph list */ 67 (int) 0 , /* graph call chain top-sort order */ 68 (int) 0 , /* internal number of cycle on */ 69 (int) 0 , /* number of live parent arcs */ 70 (struct nl *) &indirectchild , /* pointer to head of cycle */ 71 (struct nl *) 0 , /* pointer to next member of cycle */ 72 (arctype *) 0 , /* list of caller arcs */ 73 (arctype *) 0 /* list of callee arcs */ 74 }; 75 76 void 77 findcall(nltype *parentp, unsigned long p_lowpc, unsigned long p_highpc) 78 { 79 unsigned long pc; 80 nltype *childp; 81 unsigned long destpc; 82 long op; 83 int off; 84 85 if (textspace == 0) 86 return; 87 if (p_lowpc < s_lowpc) 88 p_lowpc = s_lowpc; 89 if (p_highpc > s_highpc) 90 p_highpc = s_highpc; 91 92 for (pc = p_lowpc; pc < p_highpc; pc += 4) { 93 off = pc - s_lowpc; 94 op = *(unsigned long *)&textspace[off]; 95 if ((op & 0xfc000000) == 0x0c000000) { 96 /* 97 * a jal insn -- check that this 98 * is the address of a function. 99 */ 100 off = (op & 0x03ffffff) << 2; 101 destpc = (pc & 0xf0000000) | off; 102 if (destpc >= s_lowpc && destpc <= s_highpc) { 103 childp = nllookup(destpc); 104 if (childp != 0 && childp->value == destpc) 105 addarc(parentp, childp, 0L); 106 } 107 } else if ((op & 0xfc00f83f) == 0x0000f809) 108 /* 109 * A jalr -- an indirect call. 110 */ 111 addarc(parentp, &indirectchild, 0L); 112 } 113 } 114