Annotation of src/usr.bin/gprof/vax.c, Revision 1.8
1.8 ! deraadt 1: /* $OpenBSD: vax.c,v 1.7 2006/03/25 19:06:36 espie Exp $ */
1.2 deraadt 2: /* $NetBSD: vax.c,v 1.6 1996/04/20 14:56:37 ragge Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1983, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
1.6 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: */
32:
33: #include "gprof.h"
34:
35: /*
36: * a namelist entry to be the child of indirect calls
37: */
38: nltype indirectchild = {
39: "(*)" , /* the name */
40: (unsigned long) 0 , /* the pc entry point */
41: (unsigned long) 0 , /* entry point aligned to histogram */
42: (double) 0.0 , /* ticks in this routine */
43: (double) 0.0 , /* cumulative ticks in children */
44: (long) 0 , /* how many times called */
1.2 deraadt 45: (long) 0 , /* times called by live arcs */
1.1 deraadt 46: (long) 0 , /* how many calls to self */
47: (double) 1.0 , /* propagation fraction */
48: (double) 0.0 , /* self propagation time */
49: (double) 0.0 , /* child propagation time */
1.2 deraadt 50: (short) 0 , /* print flag */
51: (short) 0 , /* see below */
1.1 deraadt 52: (int) 0 , /* index in the graph list */
53: (int) 0 , /* graph call chain top-sort order */
54: (int) 0 , /* internal number of cycle on */
1.2 deraadt 55: (int) 0 , /* number of live parent arcs */
1.1 deraadt 56: (struct nl *) &indirectchild , /* pointer to head of cycle */
57: (struct nl *) 0 , /* pointer to next member of cycle */
58: (arctype *) 0 , /* list of caller arcs */
59: (arctype *) 0 /* list of callee arcs */
60: };
61:
62: operandenum
1.7 espie 63: operandmode(struct modebyte *modep)
1.1 deraadt 64: {
65: long usesreg = modep -> regfield;
66:
67: switch ( modep -> modefield ) {
68: case 0:
69: case 1:
70: case 2:
71: case 3:
72: return literal;
73: case 4:
74: return indexed;
75: case 5:
76: return reg;
77: case 6:
78: return regdef;
79: case 7:
80: return autodec;
81: case 8:
82: return ( usesreg != PC ? autoinc : immediate );
83: case 9:
84: return ( usesreg != PC ? autoincdef : absolute );
85: case 10:
86: return ( usesreg != PC ? bytedisp : byterel );
87: case 11:
88: return ( usesreg != PC ? bytedispdef : bytereldef );
89: case 12:
90: return ( usesreg != PC ? worddisp : wordrel );
91: case 13:
92: return ( usesreg != PC ? worddispdef : wordreldef );
93: case 14:
94: return ( usesreg != PC ? longdisp : longrel );
95: case 15:
96: return ( usesreg != PC ? longdispdef : longreldef );
97: }
98: /* NOTREACHED */
99: }
100:
101: char *
1.7 espie 102: operandname(operandenum mode)
1.1 deraadt 103: {
104:
105: switch ( mode ) {
106: case literal:
107: return "literal";
108: case indexed:
109: return "indexed";
110: case reg:
111: return "register";
112: case regdef:
113: return "register deferred";
114: case autodec:
115: return "autodecrement";
116: case autoinc:
117: return "autoincrement";
118: case autoincdef:
119: return "autoincrement deferred";
120: case bytedisp:
121: return "byte displacement";
122: case bytedispdef:
123: return "byte displacement deferred";
124: case byterel:
125: return "byte relative";
126: case bytereldef:
127: return "byte relative deferred";
128: case worddisp:
129: return "word displacement";
130: case worddispdef:
131: return "word displacement deferred";
132: case wordrel:
133: return "word relative";
134: case wordreldef:
135: return "word relative deferred";
136: case immediate:
137: return "immediate";
138: case absolute:
139: return "absolute";
140: case longdisp:
141: return "long displacement";
142: case longdispdef:
143: return "long displacement deferred";
144: case longrel:
145: return "long relative";
146: case longreldef:
147: return "long relative deferred";
148: }
149: /* NOTREACHED */
150: }
151:
152: long
1.7 espie 153: operandlength(struct modebyte *modep)
1.1 deraadt 154: {
155:
156: switch ( operandmode( modep ) ) {
157: case literal:
158: case reg:
159: case regdef:
160: case autodec:
161: case autoinc:
162: case autoincdef:
163: return 1;
164: case bytedisp:
165: case bytedispdef:
166: case byterel:
167: case bytereldef:
168: return 2;
169: case worddisp:
170: case worddispdef:
171: case wordrel:
172: case wordreldef:
173: return 3;
174: case immediate:
175: case absolute:
176: case longdisp:
177: case longdispdef:
178: case longrel:
179: case longreldef:
180: return 5;
181: case indexed:
182: return 1+operandlength( (struct modebyte *) ((char *) modep) + 1 );
183: }
184: /* NOTREACHED */
185: }
186:
187: unsigned long
1.7 espie 188: reladdr(struct modebyte *modep)
1.1 deraadt 189: {
190: operandenum mode = operandmode( modep );
191: char *cp;
192: short *sp;
193: long *lp;
194:
195: cp = (char *) modep;
196: cp += 1; /* skip over the mode */
197: switch ( mode ) {
198: default:
1.4 mickey 199: warnx("[reladdr] not relative address");
1.1 deraadt 200: return (unsigned long) modep;
201: case byterel:
202: return (unsigned long) ( cp + sizeof *cp + *cp );
203: case wordrel:
204: sp = (short *) cp;
205: return (unsigned long) ( cp + sizeof *sp + *sp );
206: case longrel:
207: lp = (long *) cp;
208: return (unsigned long) ( cp + sizeof *lp + *lp );
209: }
210: }
211:
1.4 mickey 212: void
1.7 espie 213: findcall(nltype *parentp, unsigned long p_lowpc, unsigned long p_highpc)
1.1 deraadt 214: {
215: unsigned char *instructp;
216: long length;
217: nltype *childp;
218: operandenum mode;
219: operandenum firstmode;
220: unsigned long destpc;
221:
222: if ( textspace == 0 ) {
223: return;
224: }
225: if ( p_lowpc < s_lowpc ) {
226: p_lowpc = s_lowpc;
227: }
228: if ( p_highpc > s_highpc ) {
229: p_highpc = s_highpc;
230: }
231: # ifdef DEBUG
232: if ( debug & CALLDEBUG ) {
233: printf( "[findcall] %s: 0x%x to 0x%x\n" ,
234: parentp -> name , p_lowpc , p_highpc );
235: }
1.5 danh 236: # endif /* DEBUG */
1.1 deraadt 237: for ( instructp = textspace + p_lowpc ;
238: instructp < textspace + p_highpc ;
239: instructp += length ) {
240: length = 1;
241: if ( *instructp == CALLS ) {
242: /*
243: * maybe a calls, better check it out.
244: * skip the count of the number of arguments.
245: */
246: # ifdef DEBUG
247: if ( debug & CALLDEBUG ) {
248: printf( "[findcall]\t0x%x:calls" , instructp - textspace );
249: }
1.5 danh 250: # endif /* DEBUG */
1.1 deraadt 251: firstmode = operandmode( (struct modebyte *) (instructp+length) );
252: switch ( firstmode ) {
253: case literal:
254: case immediate:
255: break;
256: default:
257: goto botched;
258: }
259: length += operandlength( (struct modebyte *) (instructp+length) );
260: mode = operandmode( (struct modebyte *) ( instructp + length ) );
261: # ifdef DEBUG
262: if ( debug & CALLDEBUG ) {
263: printf( "\tfirst operand is %s", operandname( firstmode ) );
264: printf( "\tsecond operand is %s\n" , operandname( mode ) );
265: }
1.5 danh 266: # endif /* DEBUG */
1.1 deraadt 267: switch ( mode ) {
268: case regdef:
269: case bytedispdef:
270: case worddispdef:
271: case longdispdef:
272: case bytereldef:
273: case wordreldef:
274: case longreldef:
275: /*
276: * indirect call: call through pointer
277: * either *d(r) as a parameter or local
278: * (r) as a return value
279: * *f as a global pointer
280: * [are there others that we miss?,
281: * e.g. arrays of pointers to functions???]
282: */
283: addarc( parentp , &indirectchild , (long) 0 );
284: length += operandlength(
285: (struct modebyte *) ( instructp + length ) );
286: continue;
287: case byterel:
288: case wordrel:
289: case longrel:
290: /*
291: * regular pc relative addressing
292: * check that this is the address of
293: * a function.
294: */
295: destpc = reladdr( (struct modebyte *) (instructp+length) )
296: - (unsigned long) textspace;
297: if ( destpc >= s_lowpc && destpc <= s_highpc ) {
298: childp = nllookup( destpc );
299: # ifdef DEBUG
300: if ( debug & CALLDEBUG ) {
301: printf( "[findcall]\tdestpc 0x%x" , destpc );
302: printf( " childp->name %s" , childp -> name );
303: printf( " childp->value 0x%x\n" ,
304: childp -> value );
305: }
1.5 danh 306: # endif /* DEBUG */
1.1 deraadt 307: if ( childp -> value == destpc ) {
308: /*
309: * a hit
310: */
311: addarc( parentp , childp , (long) 0 );
312: length += operandlength( (struct modebyte *)
313: ( instructp + length ) );
314: continue;
315: }
316: goto botched;
317: }
318: /*
319: * else:
320: * it looked like a calls,
321: * but it wasn't to anywhere.
322: */
323: goto botched;
324: default:
325: botched:
326: /*
327: * something funny going on.
328: */
329: # ifdef DEBUG
330: if ( debug & CALLDEBUG ) {
331: printf( "[findcall]\tbut it's a botch\n" );
332: }
1.5 danh 333: # endif /* DEBUG */
1.1 deraadt 334: length = 1;
335: continue;
336: }
337: }
338: }
339: }