2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)vax.c 8.1 (Berkeley) 6/6/93
39 * a namelist entry to be the child of indirect calls
41 nltype indirectchild = {
42 "(*)" , /* the name */
43 (unsigned long) 0 , /* the pc entry point */
44 (unsigned long) 0 , /* entry point aligned to histogram */
45 (double) 0.0 , /* ticks in this routine */
46 (double) 0.0 , /* cumulative ticks in children */
47 (long) 0 , /* how many times called */
48 (long) 0 , /* how many calls to self */
49 (double) 1.0 , /* propagation fraction */
50 (double) 0.0 , /* self propagation time */
51 (double) 0.0 , /* child propagation time */
52 (bool) 0 , /* print flag */
53 (int) 0 , /* index in the graph list */
54 (int) 0 , /* graph call chain top-sort order */
55 (int) 0 , /* internal number of cycle on */
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 */
64 struct modebyte *modep;
66 long usesreg = modep -> regfield;
68 switch ( modep -> modefield ) {
83 return ( usesreg != PC ? autoinc : immediate );
85 return ( usesreg != PC ? autoincdef : absolute );
87 return ( usesreg != PC ? bytedisp : byterel );
89 return ( usesreg != PC ? bytedispdef : bytereldef );
91 return ( usesreg != PC ? worddisp : wordrel );
93 return ( usesreg != PC ? worddispdef : wordreldef );
95 return ( usesreg != PC ? longdisp : longrel );
97 return ( usesreg != PC ? longdispdef : longreldef );
115 return "register deferred";
117 return "autodecrement";
119 return "autoincrement";
121 return "autoincrement deferred";
123 return "byte displacement";
125 return "byte displacement deferred";
127 return "byte relative";
129 return "byte relative deferred";
131 return "word displacement";
133 return "word displacement deferred";
135 return "word relative";
137 return "word relative deferred";
143 return "long displacement";
145 return "long displacement deferred";
147 return "long relative";
149 return "long relative deferred";
155 operandlength( modep )
156 struct modebyte *modep;
159 switch ( operandmode( modep ) ) {
185 return 1+operandlength( (struct modebyte *) ((char *) modep) + 1 );
192 struct modebyte *modep;
194 operandenum mode = operandmode( modep );
200 cp += 1; /* skip over the mode */
203 fprintf( stderr , "[reladdr] not relative address\n" );
204 return (unsigned long) modep;
206 return (unsigned long) ( cp + sizeof *cp + *cp );
209 return (unsigned long) ( cp + sizeof *sp + *sp );
212 return (unsigned long) ( cp + sizeof *lp + *lp );
216 findcall( parentp , p_lowpc , p_highpc )
218 unsigned long p_lowpc;
219 unsigned long p_highpc;
221 unsigned char *instructp;
225 operandenum firstmode;
226 unsigned long destpc;
228 if ( textspace == 0 ) {
231 if ( p_lowpc < s_lowpc ) {
234 if ( p_highpc > s_highpc ) {
238 if ( debug & CALLDEBUG ) {
239 printf( "[findcall] %s: 0x%x to 0x%x\n" ,
240 parentp -> name , p_lowpc , p_highpc );
243 for ( instructp = textspace + p_lowpc ;
244 instructp < textspace + p_highpc ;
245 instructp += length ) {
247 if ( *instructp == CALLS ) {
249 * maybe a calls, better check it out.
250 * skip the count of the number of arguments.
253 if ( debug & CALLDEBUG ) {
254 printf( "[findcall]\t0x%x:calls" , instructp - textspace );
257 firstmode = operandmode( (struct modebyte *) (instructp+length) );
258 switch ( firstmode ) {
265 length += operandlength( (struct modebyte *) (instructp+length) );
266 mode = operandmode( (struct modebyte *) ( instructp + length ) );
268 if ( debug & CALLDEBUG ) {
269 printf( "\tfirst operand is %s", operandname( firstmode ) );
270 printf( "\tsecond operand is %s\n" , operandname( mode ) );
282 * indirect call: call through pointer
283 * either *d(r) as a parameter or local
284 * (r) as a return value
285 * *f as a global pointer
286 * [are there others that we miss?,
287 * e.g. arrays of pointers to functions???]
289 addarc( parentp , &indirectchild , (long) 0 );
290 length += operandlength(
291 (struct modebyte *) ( instructp + length ) );
297 * regular pc relative addressing
298 * check that this is the address of
301 destpc = reladdr( (struct modebyte *) (instructp+length) )
302 - (unsigned long) textspace;
303 if ( destpc >= s_lowpc && destpc <= s_highpc ) {
304 childp = nllookup( destpc );
306 if ( debug & CALLDEBUG ) {
307 printf( "[findcall]\tdestpc 0x%x" , destpc );
308 printf( " childp->name %s" , childp -> name );
309 printf( " childp->value 0x%x\n" ,
313 if ( childp -> value == destpc ) {
317 addarc( parentp , childp , (long) 0 );
318 length += operandlength( (struct modebyte *)
319 ( instructp + length ) );
326 * it looked like a calls,
327 * but it wasn't to anywhere.
333 * something funny going on.
336 if ( debug & CALLDEBUG ) {
337 printf( "[findcall]\tbut it's a botch\n" );