2 * Copyright (c) 1983 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.
20 #include "time_host.h"
23 * A symbol to be the child of indirect callf:
32 long usesreg = ((long)*modep) & 0xf;
34 switch (((long)*modep) >> 4) {
49 return usesreg != 0xe ? autoinc : immediate;
51 return usesreg != PC ? autoincdef : absolute;
53 return usesreg != PC ? bytedisp : byterel;
55 return usesreg != PC ? bytedispdef : bytereldef;
57 return usesreg != PC ? worddisp : wordrel;
59 return usesreg != PC ? worddispdef : wordreldef;
61 return usesreg != PC ? longdisp : longrel;
63 return usesreg != PC ? longdispdef : longreldef;
81 return "register deferred";
83 return "autodecrement";
85 return "autoincrement";
87 return "autoincrement deferred";
89 return "byte displacement";
91 return "byte displacement deferred";
93 return "byte relative";
95 return "byte relative deferred";
97 return "word displacement";
99 return "word displacement deferred";
101 return "word relative";
103 return "word relative deferred";
109 return "long displacement";
111 return "long displacement deferred";
113 return "long relative";
115 return "long relative deferred";
122 unsigned char *modep;
125 switch (operandmode(modep)) {
151 return 1+operandlength(modep + 1);
160 operandenum mode = operandmode(modep);
168 ++cp; /* skip over the mode */
171 fprintf(stderr, "[reladdr] not relative address\n");
172 return (bfd_vma) modep;
174 return (bfd_vma) (cp + sizeof *cp + *cp);
176 for (i = 0; i < sizeof *sp; i++)
177 value = (value << 8) + (cp[i] & 0xff);
178 return (bfd_vma) (cp + sizeof *sp + value);
180 for (i = 0; i < sizeof *lp; i++)
181 value = (value << 8) + (cp[i] & 0xff);
182 return (bfd_vma) (cp + sizeof *lp + value);
186 find_call(parent, p_lowpc, p_highpc)
191 unsigned char *instructp;
195 operandenum firstmode;
197 static bool inited = FALSE;
201 sym_init(&indirectchild);
202 indirectchild.cg.prop.fract = 1.0;
203 indirectchild.cg.cyc.head = &indirectchild;
206 if (textspace == 0) {
209 if (p_lowpc < s_lowpc) {
212 if (p_highpc > s_highpc) {
215 DBG(CALLDEBUG, printf("[findcall] %s: 0x%x to 0x%x\n",
216 parent -> name, p_lowpc, p_highpc));
217 for ( instructp = textspace + p_lowpc ;
218 instructp < textspace + p_highpc ;
219 instructp += length) {
221 if (*instructp == CALLF) {
223 * maybe a callf, better check it out.
224 * skip the count of the number of arguments.
226 DBG(CALLDEBUG, printf("[findcall]\t0x%x:callf",
227 instructp - textspace));
228 firstmode = operandmode(instructp+length);
236 length += operandlength(instructp+length);
237 mode = operandmode(instructp + length);
239 printf("\tfirst operand is %s", operandname(firstmode));
240 printf("\tsecond operand is %s\n", operandname(mode));
251 * indirect call: call through pointer
252 * either *d(r) as a parameter or local
253 * (r) as a return value
254 * *f as a global pointer
255 * [are there others that we miss?,
256 * e.g. arrays of pointers to functions???]
258 arc_add(parent, &indirectchild, (long) 0);
259 length += operandlength(instructp + length);
265 * regular pc relative addressing
266 * check that this is the address of
269 destpc = reladdr(instructp+length)
270 - (bfd_vma) textspace;
271 if (destpc >= s_lowpc && destpc <= s_highpc) {
272 child = sym_lookup(destpc);
274 printf("[findcall]\tdestpc 0x%x", destpc);
275 printf(" child->name %s", child -> name);
276 printf(" child->addr 0x%x\n", child -> addr);
278 if (child -> addr == destpc) {
282 arc_add(parent, child, (long) 0);
283 length += operandlength(instructp + length);
290 * it looked like a callf,
291 * but it wasn't to anywhere.
297 * something funny going on.
299 DBG(CALLDEBUG, printf("[findcall]\tbut it's a botch\n"));