2 * Copyright (c) 1983, 2001 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that: (1) source distributions retain this entire copyright
7 * notice and comment, and (2) distributions including binaries display
8 * the following acknowledgement: ``This product includes software
9 * developed by the University of California, Berkeley and its contributors''
10 * in the documentation or other materials provided with the distribution
11 * and in all advertising materials mentioning features or use of this
12 * software. Neither the name of the University nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 * opcode of the `calls' instruction
31 * register for pc relative addressing
37 literal
, indexed
, reg
, regdef
, autodec
, autoinc
, autoincdef
,
38 bytedisp
, bytedispdef
, worddisp
, worddispdef
, longdisp
, longdispdef
,
39 immediate
, absolute
, byterel
, bytereldef
, wordrel
, wordreldef
,
42 typedef enum opermodes operandenum
;
46 unsigned int regfield
:4;
47 unsigned int modefield
:4;
51 * A symbol to be the child of indirect calls:
53 static Sym indirectchild
;
55 static operandenum vax_operandmode
PARAMS ((struct modebyte
*));
56 static char *vax_operandname
PARAMS ((operandenum
));
57 static long vax_operandlength
PARAMS ((struct modebyte
*));
58 static bfd_vma vax_reladdr
PARAMS ((struct modebyte
*));
59 void vax_find_call
PARAMS ((Sym
*, bfd_vma
, bfd_vma
));
62 vax_operandmode (modep
)
63 struct modebyte
*modep
;
65 long usesreg
= modep
->regfield
;
67 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
;
104 vax_operandname (mode
)
117 return "register deferred";
119 return "autodecrement";
121 return "autoincrement";
123 return "autoincrement deferred";
125 return "byte displacement";
127 return "byte displacement deferred";
129 return "byte relative";
131 return "byte relative deferred";
133 return "word displacement";
135 return "word displacement deferred";
137 return "word relative";
139 return "word relative deferred";
145 return "long displacement";
147 return "long displacement deferred";
149 return "long relative";
151 return "long relative deferred";
158 vax_operandlength (modep
)
159 struct modebyte
*modep
;
162 switch (vax_operandmode (modep
))
189 return 1 + vax_operandlength ((struct modebyte
*) ((char *) modep
) + 1);
197 struct modebyte
*modep
;
199 operandenum mode
= vax_operandmode (modep
);
205 ++cp
; /* skip over the mode */
209 fprintf (stderr
, "[reladdr] not relative address\n");
210 return (bfd_vma
) modep
;
212 return (bfd_vma
) (cp
+ sizeof *cp
+ *cp
);
215 return (bfd_vma
) (cp
+ sizeof *sp
+ *sp
);
218 return (bfd_vma
) (cp
+ sizeof *lp
+ *lp
);
224 vax_find_call (parent
, p_lowpc
, p_highpc
)
229 unsigned char *instructp
;
233 operandenum firstmode
;
235 static bool inited
= FALSE
;
240 sym_init (&indirectchild
);
241 indirectchild
.cg
.prop
.fract
= 1.0;
242 indirectchild
.cg
.cyc
.head
= &indirectchild
;
245 if (core_text_space
== 0)
249 if (p_lowpc
< s_lowpc
)
253 if (p_highpc
> s_highpc
)
257 DBG (CALLDEBUG
, printf ("[findcall] %s: 0x%lx to 0x%lx\n",
258 parent
->name
, (unsigned long) p_lowpc
,
259 (unsigned long) p_highpc
));
260 for (instructp
= (unsigned char *) core_text_space
+ p_lowpc
;
261 instructp
< (unsigned char *) core_text_space
+ p_highpc
;
265 if (*instructp
== CALLS
)
268 * maybe a calls, better check it out.
269 * skip the count of the number of arguments.
272 printf ("[findcall]\t0x%lx:calls",
274 (instructp
- (unsigned char *) core_text_space
))));
275 firstmode
= vax_operandmode ((struct modebyte
*) (instructp
+ length
));
284 length
+= vax_operandlength ((struct modebyte
*) (instructp
+ length
));
285 mode
= vax_operandmode ((struct modebyte
*) (instructp
+ length
));
287 printf ("\tfirst operand is %s", vax_operandname (firstmode
));
288 printf ("\tsecond operand is %s\n", vax_operandname (mode
)));
299 * indirect call: call through pointer
300 * either *d(r) as a parameter or local
301 * (r) as a return value
302 * *f as a global pointer
303 * [are there others that we miss?,
304 * e.g. arrays of pointers to functions???]
306 arc_add (parent
, &indirectchild
, (unsigned long) 0);
307 length
+= vax_operandlength (
308 (struct modebyte
*) (instructp
+ length
));
314 * regular pc relative addressing
315 * check that this is the address of
318 destpc
= vax_reladdr ((struct modebyte
*) (instructp
+ length
))
319 - (bfd_vma
) core_text_space
;
320 if (destpc
>= s_lowpc
&& destpc
<= s_highpc
)
322 child
= sym_lookup (&symtab
, destpc
);
324 printf ("[findcall]\tdestpc 0x%lx",
325 (unsigned long) destpc
);
326 printf (" child->name %s", child
->name
);
327 printf (" child->addr 0x%lx\n",
328 (unsigned long) child
->addr
);
330 if (child
->addr
== destpc
)
335 arc_add (parent
, child
, (unsigned long) 0);
336 length
+= vax_operandlength ((struct modebyte
*)
337 (instructp
+ length
));
344 * it looked like a calls,
345 * but it wasn't to anywhere.
351 * something funny going on.
353 DBG (CALLDEBUG
, printf ("[findcall]\tbut it's a botch\n"));