2002-12-06 Andrew Cagney <ac131313@redhat.com>
[deliverable/binutils-gdb.git] / gdb / fr30-tdep.c
1 // OBSOLETE /* Target-dependent code for the Fujitsu FR30.
2 // OBSOLETE Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3 // OBSOLETE
4 // OBSOLETE This file is part of GDB.
5 // OBSOLETE
6 // OBSOLETE This program is free software; you can redistribute it and/or modify
7 // OBSOLETE it under the terms of the GNU General Public License as published by
8 // OBSOLETE the Free Software Foundation; either version 2 of the License, or
9 // OBSOLETE (at your option) any later version.
10 // OBSOLETE
11 // OBSOLETE This program is distributed in the hope that it will be useful,
12 // OBSOLETE but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // OBSOLETE MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // OBSOLETE GNU General Public License for more details.
15 // OBSOLETE
16 // OBSOLETE You should have received a copy of the GNU General Public License
17 // OBSOLETE along with this program; if not, write to the Free Software
18 // OBSOLETE Foundation, Inc., 59 Temple Place - Suite 330,
19 // OBSOLETE Boston, MA 02111-1307, USA. */
20 // OBSOLETE
21 // OBSOLETE #include "defs.h"
22 // OBSOLETE #include "frame.h"
23 // OBSOLETE #include "inferior.h"
24 // OBSOLETE #include "obstack.h"
25 // OBSOLETE #include "target.h"
26 // OBSOLETE #include "value.h"
27 // OBSOLETE #include "bfd.h"
28 // OBSOLETE #include "gdb_string.h"
29 // OBSOLETE #include "gdbcore.h"
30 // OBSOLETE #include "symfile.h"
31 // OBSOLETE #include "regcache.h"
32 // OBSOLETE
33 // OBSOLETE /* An expression that tells us whether the function invocation represented
34 // OBSOLETE by FI does not have a frame on the stack associated with it. */
35 // OBSOLETE int
36 // OBSOLETE fr30_frameless_function_invocation (struct frame_info *fi)
37 // OBSOLETE {
38 // OBSOLETE int frameless;
39 // OBSOLETE CORE_ADDR func_start, after_prologue;
40 // OBSOLETE func_start = (get_pc_function_start ((fi)->pc) +
41 // OBSOLETE FUNCTION_START_OFFSET);
42 // OBSOLETE after_prologue = func_start;
43 // OBSOLETE after_prologue = SKIP_PROLOGUE (after_prologue);
44 // OBSOLETE frameless = (after_prologue == func_start);
45 // OBSOLETE return frameless;
46 // OBSOLETE }
47 // OBSOLETE
48 // OBSOLETE /* Function: pop_frame
49 // OBSOLETE This routine gets called when either the user uses the `return'
50 // OBSOLETE command, or the call dummy breakpoint gets hit. */
51 // OBSOLETE
52 // OBSOLETE void
53 // OBSOLETE fr30_pop_frame (void)
54 // OBSOLETE {
55 // OBSOLETE struct frame_info *frame = get_current_frame ();
56 // OBSOLETE int regnum;
57 // OBSOLETE CORE_ADDR sp = read_register (SP_REGNUM);
58 // OBSOLETE
59 // OBSOLETE if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
60 // OBSOLETE generic_pop_dummy_frame ();
61 // OBSOLETE else
62 // OBSOLETE {
63 // OBSOLETE write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
64 // OBSOLETE
65 // OBSOLETE for (regnum = 0; regnum < NUM_REGS; regnum++)
66 // OBSOLETE if (frame->fsr.regs[regnum] != 0)
67 // OBSOLETE {
68 // OBSOLETE write_register (regnum,
69 // OBSOLETE read_memory_unsigned_integer (frame->fsr.regs[regnum],
70 // OBSOLETE REGISTER_RAW_SIZE (regnum)));
71 // OBSOLETE }
72 // OBSOLETE write_register (SP_REGNUM, sp + frame->framesize);
73 // OBSOLETE }
74 // OBSOLETE flush_cached_frames ();
75 // OBSOLETE }
76 // OBSOLETE
77 // OBSOLETE
78 // OBSOLETE /* Function: fr30_store_return_value
79 // OBSOLETE Put a value where a caller expects to see it. Used by the 'return'
80 // OBSOLETE command. */
81 // OBSOLETE void
82 // OBSOLETE fr30_store_return_value (struct type *type,
83 // OBSOLETE char *valbuf)
84 // OBSOLETE {
85 // OBSOLETE /* Here's how the FR30 returns values (gleaned from gcc/config/
86 // OBSOLETE fr30/fr30.h):
87 // OBSOLETE
88 // OBSOLETE If the return value is 32 bits long or less, it goes in r4.
89 // OBSOLETE
90 // OBSOLETE If the return value is 64 bits long or less, it goes in r4 (most
91 // OBSOLETE significant word) and r5 (least significant word.
92 // OBSOLETE
93 // OBSOLETE If the function returns a structure, of any size, the caller
94 // OBSOLETE passes the function an invisible first argument where the callee
95 // OBSOLETE should store the value. But GDB doesn't let you do that anyway.
96 // OBSOLETE
97 // OBSOLETE If you're returning a value smaller than a word, it's not really
98 // OBSOLETE necessary to zero the upper bytes of the register; the caller is
99 // OBSOLETE supposed to ignore them. However, the FR30 typically keeps its
100 // OBSOLETE values extended to the full register width, so we should emulate
101 // OBSOLETE that. */
102 // OBSOLETE
103 // OBSOLETE /* The FR30 is big-endian, so if we return a small value (like a
104 // OBSOLETE short or a char), we need to position it correctly within the
105 // OBSOLETE register. We round the size up to a register boundary, and then
106 // OBSOLETE adjust the offset so as to place the value at the right end. */
107 // OBSOLETE int value_size = TYPE_LENGTH (type);
108 // OBSOLETE int returned_size = (value_size + FR30_REGSIZE - 1) & ~(FR30_REGSIZE - 1);
109 // OBSOLETE int offset = (REGISTER_BYTE (RETVAL_REG)
110 // OBSOLETE + (returned_size - value_size));
111 // OBSOLETE char *zeros = alloca (returned_size);
112 // OBSOLETE memset (zeros, 0, returned_size);
113 // OBSOLETE
114 // OBSOLETE write_register_bytes (REGISTER_BYTE (RETVAL_REG), zeros, returned_size);
115 // OBSOLETE write_register_bytes (offset, valbuf, value_size);
116 // OBSOLETE }
117 // OBSOLETE
118 // OBSOLETE
119 // OBSOLETE /* Function: skip_prologue
120 // OBSOLETE Return the address of the first code past the prologue of the function. */
121 // OBSOLETE
122 // OBSOLETE CORE_ADDR
123 // OBSOLETE fr30_skip_prologue (CORE_ADDR pc)
124 // OBSOLETE {
125 // OBSOLETE CORE_ADDR func_addr, func_end;
126 // OBSOLETE
127 // OBSOLETE /* See what the symbol table says */
128 // OBSOLETE
129 // OBSOLETE if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
130 // OBSOLETE {
131 // OBSOLETE struct symtab_and_line sal;
132 // OBSOLETE
133 // OBSOLETE sal = find_pc_line (func_addr, 0);
134 // OBSOLETE
135 // OBSOLETE if (sal.line != 0 && sal.end < func_end)
136 // OBSOLETE {
137 // OBSOLETE return sal.end;
138 // OBSOLETE }
139 // OBSOLETE }
140 // OBSOLETE
141 // OBSOLETE /* Either we didn't find the start of this function (nothing we can do),
142 // OBSOLETE or there's no line info, or the line after the prologue is after
143 // OBSOLETE the end of the function (there probably isn't a prologue). */
144 // OBSOLETE
145 // OBSOLETE return pc;
146 // OBSOLETE }
147 // OBSOLETE
148 // OBSOLETE
149 // OBSOLETE /* Function: push_arguments
150 // OBSOLETE Setup arguments and RP for a call to the target. First four args
151 // OBSOLETE go in FIRST_ARGREG -> LAST_ARGREG, subsequent args go on stack...
152 // OBSOLETE Structs are passed by reference. XXX not right now Z.R.
153 // OBSOLETE 64 bit quantities (doubles and long longs) may be split between
154 // OBSOLETE the regs and the stack.
155 // OBSOLETE When calling a function that returns a struct, a pointer to the struct
156 // OBSOLETE is passed in as a secret first argument (always in FIRST_ARGREG).
157 // OBSOLETE
158 // OBSOLETE Stack space for the args has NOT been allocated: that job is up to us.
159 // OBSOLETE */
160 // OBSOLETE
161 // OBSOLETE CORE_ADDR
162 // OBSOLETE fr30_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
163 // OBSOLETE int struct_return, CORE_ADDR struct_addr)
164 // OBSOLETE {
165 // OBSOLETE int argreg;
166 // OBSOLETE int argnum;
167 // OBSOLETE int stack_offset;
168 // OBSOLETE struct stack_arg
169 // OBSOLETE {
170 // OBSOLETE char *val;
171 // OBSOLETE int len;
172 // OBSOLETE int offset;
173 // OBSOLETE };
174 // OBSOLETE struct stack_arg *stack_args =
175 // OBSOLETE (struct stack_arg *) alloca (nargs * sizeof (struct stack_arg));
176 // OBSOLETE int nstack_args = 0;
177 // OBSOLETE
178 // OBSOLETE argreg = FIRST_ARGREG;
179 // OBSOLETE
180 // OBSOLETE /* the struct_return pointer occupies the first parameter-passing reg */
181 // OBSOLETE if (struct_return)
182 // OBSOLETE write_register (argreg++, struct_addr);
183 // OBSOLETE
184 // OBSOLETE stack_offset = 0;
185 // OBSOLETE
186 // OBSOLETE /* Process args from left to right. Store as many as allowed in
187 // OBSOLETE registers, save the rest to be pushed on the stack */
188 // OBSOLETE for (argnum = 0; argnum < nargs; argnum++)
189 // OBSOLETE {
190 // OBSOLETE char *val;
191 // OBSOLETE struct value *arg = args[argnum];
192 // OBSOLETE struct type *arg_type = check_typedef (VALUE_TYPE (arg));
193 // OBSOLETE struct type *target_type = TYPE_TARGET_TYPE (arg_type);
194 // OBSOLETE int len = TYPE_LENGTH (arg_type);
195 // OBSOLETE enum type_code typecode = TYPE_CODE (arg_type);
196 // OBSOLETE CORE_ADDR regval;
197 // OBSOLETE int newarg;
198 // OBSOLETE
199 // OBSOLETE val = (char *) VALUE_CONTENTS (arg);
200 // OBSOLETE
201 // OBSOLETE {
202 // OBSOLETE /* Copy the argument to general registers or the stack in
203 // OBSOLETE register-sized pieces. Large arguments are split between
204 // OBSOLETE registers and stack. */
205 // OBSOLETE while (len > 0)
206 // OBSOLETE {
207 // OBSOLETE if (argreg <= LAST_ARGREG)
208 // OBSOLETE {
209 // OBSOLETE int partial_len = len < REGISTER_SIZE ? len : REGISTER_SIZE;
210 // OBSOLETE regval = extract_address (val, partial_len);
211 // OBSOLETE
212 // OBSOLETE /* It's a simple argument being passed in a general
213 // OBSOLETE register. */
214 // OBSOLETE write_register (argreg, regval);
215 // OBSOLETE argreg++;
216 // OBSOLETE len -= partial_len;
217 // OBSOLETE val += partial_len;
218 // OBSOLETE }
219 // OBSOLETE else
220 // OBSOLETE {
221 // OBSOLETE /* keep for later pushing */
222 // OBSOLETE stack_args[nstack_args].val = val;
223 // OBSOLETE stack_args[nstack_args++].len = len;
224 // OBSOLETE break;
225 // OBSOLETE }
226 // OBSOLETE }
227 // OBSOLETE }
228 // OBSOLETE }
229 // OBSOLETE /* now do the real stack pushing, process args right to left */
230 // OBSOLETE while (nstack_args--)
231 // OBSOLETE {
232 // OBSOLETE sp -= stack_args[nstack_args].len;
233 // OBSOLETE write_memory (sp, stack_args[nstack_args].val,
234 // OBSOLETE stack_args[nstack_args].len);
235 // OBSOLETE }
236 // OBSOLETE
237 // OBSOLETE /* Return adjusted stack pointer. */
238 // OBSOLETE return sp;
239 // OBSOLETE }
240 // OBSOLETE
241 // OBSOLETE void _initialize_fr30_tdep (void);
242 // OBSOLETE
243 // OBSOLETE void
244 // OBSOLETE _initialize_fr30_tdep (void)
245 // OBSOLETE {
246 // OBSOLETE extern int print_insn_fr30 (bfd_vma, disassemble_info *);
247 // OBSOLETE tm_print_insn = print_insn_fr30;
248 // OBSOLETE }
249 // OBSOLETE
250 // OBSOLETE /* Function: check_prologue_cache
251 // OBSOLETE Check if prologue for this frame's PC has already been scanned.
252 // OBSOLETE If it has, copy the relevant information about that prologue and
253 // OBSOLETE return non-zero. Otherwise do not copy anything and return zero.
254 // OBSOLETE
255 // OBSOLETE The information saved in the cache includes:
256 // OBSOLETE * the frame register number;
257 // OBSOLETE * the size of the stack frame;
258 // OBSOLETE * the offsets of saved regs (relative to the old SP); and
259 // OBSOLETE * the offset from the stack pointer to the frame pointer
260 // OBSOLETE
261 // OBSOLETE The cache contains only one entry, since this is adequate
262 // OBSOLETE for the typical sequence of prologue scan requests we get.
263 // OBSOLETE When performing a backtrace, GDB will usually ask to scan
264 // OBSOLETE the same function twice in a row (once to get the frame chain,
265 // OBSOLETE and once to fill in the extra frame information).
266 // OBSOLETE */
267 // OBSOLETE
268 // OBSOLETE static struct frame_info prologue_cache;
269 // OBSOLETE
270 // OBSOLETE static int
271 // OBSOLETE check_prologue_cache (struct frame_info *fi)
272 // OBSOLETE {
273 // OBSOLETE int i;
274 // OBSOLETE
275 // OBSOLETE if (fi->pc == prologue_cache.pc)
276 // OBSOLETE {
277 // OBSOLETE fi->framereg = prologue_cache.framereg;
278 // OBSOLETE fi->framesize = prologue_cache.framesize;
279 // OBSOLETE fi->frameoffset = prologue_cache.frameoffset;
280 // OBSOLETE for (i = 0; i <= NUM_REGS; i++)
281 // OBSOLETE fi->fsr.regs[i] = prologue_cache.fsr.regs[i];
282 // OBSOLETE return 1;
283 // OBSOLETE }
284 // OBSOLETE else
285 // OBSOLETE return 0;
286 // OBSOLETE }
287 // OBSOLETE
288 // OBSOLETE
289 // OBSOLETE /* Function: save_prologue_cache
290 // OBSOLETE Copy the prologue information from fi to the prologue cache.
291 // OBSOLETE */
292 // OBSOLETE
293 // OBSOLETE static void
294 // OBSOLETE save_prologue_cache (struct frame_info *fi)
295 // OBSOLETE {
296 // OBSOLETE int i;
297 // OBSOLETE
298 // OBSOLETE prologue_cache.pc = fi->pc;
299 // OBSOLETE prologue_cache.framereg = fi->framereg;
300 // OBSOLETE prologue_cache.framesize = fi->framesize;
301 // OBSOLETE prologue_cache.frameoffset = fi->frameoffset;
302 // OBSOLETE
303 // OBSOLETE for (i = 0; i <= NUM_REGS; i++)
304 // OBSOLETE {
305 // OBSOLETE prologue_cache.fsr.regs[i] = fi->fsr.regs[i];
306 // OBSOLETE }
307 // OBSOLETE }
308 // OBSOLETE
309 // OBSOLETE
310 // OBSOLETE /* Function: scan_prologue
311 // OBSOLETE Scan the prologue of the function that contains PC, and record what
312 // OBSOLETE we find in PI. PI->fsr must be zeroed by the called. Returns the
313 // OBSOLETE pc after the prologue. Note that the addresses saved in pi->fsr
314 // OBSOLETE are actually just frame relative (negative offsets from the frame
315 // OBSOLETE pointer). This is because we don't know the actual value of the
316 // OBSOLETE frame pointer yet. In some circumstances, the frame pointer can't
317 // OBSOLETE be determined till after we have scanned the prologue. */
318 // OBSOLETE
319 // OBSOLETE static void
320 // OBSOLETE fr30_scan_prologue (struct frame_info *fi)
321 // OBSOLETE {
322 // OBSOLETE int sp_offset, fp_offset;
323 // OBSOLETE CORE_ADDR prologue_start, prologue_end, current_pc;
324 // OBSOLETE
325 // OBSOLETE /* Check if this function is already in the cache of frame information. */
326 // OBSOLETE if (check_prologue_cache (fi))
327 // OBSOLETE return;
328 // OBSOLETE
329 // OBSOLETE /* Assume there is no frame until proven otherwise. */
330 // OBSOLETE fi->framereg = SP_REGNUM;
331 // OBSOLETE fi->framesize = 0;
332 // OBSOLETE fi->frameoffset = 0;
333 // OBSOLETE
334 // OBSOLETE /* Find the function prologue. If we can't find the function in
335 // OBSOLETE the symbol table, peek in the stack frame to find the PC. */
336 // OBSOLETE if (find_pc_partial_function (fi->pc, NULL, &prologue_start, &prologue_end))
337 // OBSOLETE {
338 // OBSOLETE /* Assume the prologue is everything between the first instruction
339 // OBSOLETE in the function and the first source line. */
340 // OBSOLETE struct symtab_and_line sal = find_pc_line (prologue_start, 0);
341 // OBSOLETE
342 // OBSOLETE if (sal.line == 0) /* no line info, use current PC */
343 // OBSOLETE prologue_end = fi->pc;
344 // OBSOLETE else if (sal.end < prologue_end) /* next line begins after fn end */
345 // OBSOLETE prologue_end = sal.end; /* (probably means no prologue) */
346 // OBSOLETE }
347 // OBSOLETE else
348 // OBSOLETE {
349 // OBSOLETE /* XXX Z.R. What now??? The following is entirely bogus */
350 // OBSOLETE prologue_start = (read_memory_integer (fi->frame, 4) & 0x03fffffc) - 12;
351 // OBSOLETE prologue_end = prologue_start + 40;
352 // OBSOLETE }
353 // OBSOLETE
354 // OBSOLETE /* Now search the prologue looking for instructions that set up the
355 // OBSOLETE frame pointer, adjust the stack pointer, and save registers. */
356 // OBSOLETE
357 // OBSOLETE sp_offset = fp_offset = 0;
358 // OBSOLETE for (current_pc = prologue_start; current_pc < prologue_end; current_pc += 2)
359 // OBSOLETE {
360 // OBSOLETE unsigned int insn;
361 // OBSOLETE
362 // OBSOLETE insn = read_memory_unsigned_integer (current_pc, 2);
363 // OBSOLETE
364 // OBSOLETE if ((insn & 0xfe00) == 0x8e00) /* stm0 or stm1 */
365 // OBSOLETE {
366 // OBSOLETE int reg, mask = insn & 0xff;
367 // OBSOLETE
368 // OBSOLETE /* scan in one sweep - create virtual 16-bit mask from either insn's mask */
369 // OBSOLETE if ((insn & 0x0100) == 0)
370 // OBSOLETE {
371 // OBSOLETE mask <<= 8; /* stm0 - move to upper byte in virtual mask */
372 // OBSOLETE }
373 // OBSOLETE
374 // OBSOLETE /* Calculate offsets of saved registers (to be turned later into addresses). */
375 // OBSOLETE for (reg = R4_REGNUM; reg <= R11_REGNUM; reg++)
376 // OBSOLETE if (mask & (1 << (15 - reg)))
377 // OBSOLETE {
378 // OBSOLETE sp_offset -= 4;
379 // OBSOLETE fi->fsr.regs[reg] = sp_offset;
380 // OBSOLETE }
381 // OBSOLETE }
382 // OBSOLETE else if ((insn & 0xfff0) == 0x1700) /* st rx,@-r15 */
383 // OBSOLETE {
384 // OBSOLETE int reg = insn & 0xf;
385 // OBSOLETE
386 // OBSOLETE sp_offset -= 4;
387 // OBSOLETE fi->fsr.regs[reg] = sp_offset;
388 // OBSOLETE }
389 // OBSOLETE else if ((insn & 0xff00) == 0x0f00) /* enter */
390 // OBSOLETE {
391 // OBSOLETE fp_offset = fi->fsr.regs[FP_REGNUM] = sp_offset - 4;
392 // OBSOLETE sp_offset -= 4 * (insn & 0xff);
393 // OBSOLETE fi->framereg = FP_REGNUM;
394 // OBSOLETE }
395 // OBSOLETE else if (insn == 0x1781) /* st rp,@-sp */
396 // OBSOLETE {
397 // OBSOLETE sp_offset -= 4;
398 // OBSOLETE fi->fsr.regs[RP_REGNUM] = sp_offset;
399 // OBSOLETE }
400 // OBSOLETE else if (insn == 0x170e) /* st fp,@-sp */
401 // OBSOLETE {
402 // OBSOLETE sp_offset -= 4;
403 // OBSOLETE fi->fsr.regs[FP_REGNUM] = sp_offset;
404 // OBSOLETE }
405 // OBSOLETE else if (insn == 0x8bfe) /* mov sp,fp */
406 // OBSOLETE {
407 // OBSOLETE fi->framereg = FP_REGNUM;
408 // OBSOLETE }
409 // OBSOLETE else if ((insn & 0xff00) == 0xa300) /* addsp xx */
410 // OBSOLETE {
411 // OBSOLETE sp_offset += 4 * (signed char) (insn & 0xff);
412 // OBSOLETE }
413 // OBSOLETE else if ((insn & 0xff0f) == 0x9b00 && /* ldi:20 xx,r0 */
414 // OBSOLETE read_memory_unsigned_integer (current_pc + 4, 2)
415 // OBSOLETE == 0xac0f) /* sub r0,sp */
416 // OBSOLETE {
417 // OBSOLETE /* large stack adjustment */
418 // OBSOLETE sp_offset -= (((insn & 0xf0) << 12) | read_memory_unsigned_integer (current_pc + 2, 2));
419 // OBSOLETE current_pc += 4;
420 // OBSOLETE }
421 // OBSOLETE else if (insn == 0x9f80 && /* ldi:32 xx,r0 */
422 // OBSOLETE read_memory_unsigned_integer (current_pc + 6, 2)
423 // OBSOLETE == 0xac0f) /* sub r0,sp */
424 // OBSOLETE {
425 // OBSOLETE /* large stack adjustment */
426 // OBSOLETE sp_offset -=
427 // OBSOLETE (read_memory_unsigned_integer (current_pc + 2, 2) << 16 |
428 // OBSOLETE read_memory_unsigned_integer (current_pc + 4, 2));
429 // OBSOLETE current_pc += 6;
430 // OBSOLETE }
431 // OBSOLETE }
432 // OBSOLETE
433 // OBSOLETE /* The frame size is just the negative of the offset (from the original SP)
434 // OBSOLETE of the last thing thing we pushed on the stack. The frame offset is
435 // OBSOLETE [new FP] - [new SP]. */
436 // OBSOLETE fi->framesize = -sp_offset;
437 // OBSOLETE fi->frameoffset = fp_offset - sp_offset;
438 // OBSOLETE
439 // OBSOLETE save_prologue_cache (fi);
440 // OBSOLETE }
441 // OBSOLETE
442 // OBSOLETE /* Function: init_extra_frame_info
443 // OBSOLETE Setup the frame's frame pointer, pc, and frame addresses for saved
444 // OBSOLETE registers. Most of the work is done in scan_prologue().
445 // OBSOLETE
446 // OBSOLETE Note that when we are called for the last frame (currently active frame),
447 // OBSOLETE that fi->pc and fi->frame will already be setup. However, fi->frame will
448 // OBSOLETE be valid only if this routine uses FP. For previous frames, fi-frame will
449 // OBSOLETE always be correct (since that is derived from fr30_frame_chain ()).
450 // OBSOLETE
451 // OBSOLETE We can be called with the PC in the call dummy under two circumstances.
452 // OBSOLETE First, during normal backtracing, second, while figuring out the frame
453 // OBSOLETE pointer just prior to calling the target function (see run_stack_dummy). */
454 // OBSOLETE
455 // OBSOLETE void
456 // OBSOLETE fr30_init_extra_frame_info (struct frame_info *fi)
457 // OBSOLETE {
458 // OBSOLETE int reg;
459 // OBSOLETE
460 // OBSOLETE if (fi->next)
461 // OBSOLETE fi->pc = FRAME_SAVED_PC (fi->next);
462 // OBSOLETE
463 // OBSOLETE memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
464 // OBSOLETE
465 // OBSOLETE if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
466 // OBSOLETE {
467 // OBSOLETE /* We need to setup fi->frame here because run_stack_dummy gets it wrong
468 // OBSOLETE by assuming it's always FP. */
469 // OBSOLETE fi->frame = generic_read_register_dummy (fi->pc, fi->frame, SP_REGNUM);
470 // OBSOLETE fi->framesize = 0;
471 // OBSOLETE fi->frameoffset = 0;
472 // OBSOLETE return;
473 // OBSOLETE }
474 // OBSOLETE fr30_scan_prologue (fi);
475 // OBSOLETE
476 // OBSOLETE if (!fi->next) /* this is the innermost frame? */
477 // OBSOLETE fi->frame = read_register (fi->framereg);
478 // OBSOLETE else
479 // OBSOLETE /* not the innermost frame */
480 // OBSOLETE /* If we have an FP, the callee saved it. */
481 // OBSOLETE if (fi->framereg == FP_REGNUM)
482 // OBSOLETE if (fi->next->fsr.regs[fi->framereg] != 0)
483 // OBSOLETE fi->frame = read_memory_integer (fi->next->fsr.regs[fi->framereg], 4);
484 // OBSOLETE
485 // OBSOLETE /* Calculate actual addresses of saved registers using offsets determined
486 // OBSOLETE by fr30_scan_prologue. */
487 // OBSOLETE for (reg = 0; reg < NUM_REGS; reg++)
488 // OBSOLETE if (fi->fsr.regs[reg] != 0)
489 // OBSOLETE {
490 // OBSOLETE fi->fsr.regs[reg] += fi->frame + fi->framesize - fi->frameoffset;
491 // OBSOLETE }
492 // OBSOLETE }
493 // OBSOLETE
494 // OBSOLETE /* Function: find_callers_reg
495 // OBSOLETE Find REGNUM on the stack. Otherwise, it's in an active register.
496 // OBSOLETE One thing we might want to do here is to check REGNUM against the
497 // OBSOLETE clobber mask, and somehow flag it as invalid if it isn't saved on
498 // OBSOLETE the stack somewhere. This would provide a graceful failure mode
499 // OBSOLETE when trying to get the value of caller-saves registers for an inner
500 // OBSOLETE frame. */
501 // OBSOLETE
502 // OBSOLETE CORE_ADDR
503 // OBSOLETE fr30_find_callers_reg (struct frame_info *fi, int regnum)
504 // OBSOLETE {
505 // OBSOLETE for (; fi; fi = fi->next)
506 // OBSOLETE if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
507 // OBSOLETE return generic_read_register_dummy (fi->pc, fi->frame, regnum);
508 // OBSOLETE else if (fi->fsr.regs[regnum] != 0)
509 // OBSOLETE return read_memory_unsigned_integer (fi->fsr.regs[regnum],
510 // OBSOLETE REGISTER_RAW_SIZE (regnum));
511 // OBSOLETE
512 // OBSOLETE return read_register (regnum);
513 // OBSOLETE }
514 // OBSOLETE
515 // OBSOLETE
516 // OBSOLETE /* Function: frame_chain
517 // OBSOLETE Figure out the frame prior to FI. Unfortunately, this involves
518 // OBSOLETE scanning the prologue of the caller, which will also be done
519 // OBSOLETE shortly by fr30_init_extra_frame_info. For the dummy frame, we
520 // OBSOLETE just return the stack pointer that was in use at the time the
521 // OBSOLETE function call was made. */
522 // OBSOLETE
523 // OBSOLETE
524 // OBSOLETE CORE_ADDR
525 // OBSOLETE fr30_frame_chain (struct frame_info *fi)
526 // OBSOLETE {
527 // OBSOLETE CORE_ADDR fn_start, callers_pc, fp;
528 // OBSOLETE struct frame_info caller_fi;
529 // OBSOLETE int framereg;
530 // OBSOLETE
531 // OBSOLETE /* is this a dummy frame? */
532 // OBSOLETE if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
533 // OBSOLETE return fi->frame; /* dummy frame same as caller's frame */
534 // OBSOLETE
535 // OBSOLETE /* is caller-of-this a dummy frame? */
536 // OBSOLETE callers_pc = FRAME_SAVED_PC (fi); /* find out who called us: */
537 // OBSOLETE fp = fr30_find_callers_reg (fi, FP_REGNUM);
538 // OBSOLETE if (PC_IN_CALL_DUMMY (callers_pc, fp, fp))
539 // OBSOLETE return fp; /* dummy frame's frame may bear no relation to ours */
540 // OBSOLETE
541 // OBSOLETE if (find_pc_partial_function (fi->pc, 0, &fn_start, 0))
542 // OBSOLETE if (fn_start == entry_point_address ())
543 // OBSOLETE return 0; /* in _start fn, don't chain further */
544 // OBSOLETE
545 // OBSOLETE framereg = fi->framereg;
546 // OBSOLETE
547 // OBSOLETE /* If the caller is the startup code, we're at the end of the chain. */
548 // OBSOLETE if (find_pc_partial_function (callers_pc, 0, &fn_start, 0))
549 // OBSOLETE if (fn_start == entry_point_address ())
550 // OBSOLETE return 0;
551 // OBSOLETE
552 // OBSOLETE memset (&caller_fi, 0, sizeof (caller_fi));
553 // OBSOLETE caller_fi.pc = callers_pc;
554 // OBSOLETE fr30_scan_prologue (&caller_fi);
555 // OBSOLETE framereg = caller_fi.framereg;
556 // OBSOLETE
557 // OBSOLETE /* If the caller used a frame register, return its value.
558 // OBSOLETE Otherwise, return the caller's stack pointer. */
559 // OBSOLETE if (framereg == FP_REGNUM)
560 // OBSOLETE return fr30_find_callers_reg (fi, framereg);
561 // OBSOLETE else
562 // OBSOLETE return fi->frame + fi->framesize;
563 // OBSOLETE }
564 // OBSOLETE
565 // OBSOLETE /* Function: frame_saved_pc
566 // OBSOLETE Find the caller of this frame. We do this by seeing if RP_REGNUM
567 // OBSOLETE is saved in the stack anywhere, otherwise we get it from the
568 // OBSOLETE registers. If the inner frame is a dummy frame, return its PC
569 // OBSOLETE instead of RP, because that's where "caller" of the dummy-frame
570 // OBSOLETE will be found. */
571 // OBSOLETE
572 // OBSOLETE CORE_ADDR
573 // OBSOLETE fr30_frame_saved_pc (struct frame_info *fi)
574 // OBSOLETE {
575 // OBSOLETE if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
576 // OBSOLETE return generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
577 // OBSOLETE else
578 // OBSOLETE return fr30_find_callers_reg (fi, RP_REGNUM);
579 // OBSOLETE }
580 // OBSOLETE
581 // OBSOLETE /* Function: fix_call_dummy
582 // OBSOLETE Pokes the callee function's address into the CALL_DUMMY assembly stub.
583 // OBSOLETE Assumes that the CALL_DUMMY looks like this:
584 // OBSOLETE jarl <offset24>, r31
585 // OBSOLETE trap
586 // OBSOLETE */
587 // OBSOLETE
588 // OBSOLETE int
589 // OBSOLETE fr30_fix_call_dummy (char *dummy, CORE_ADDR sp, CORE_ADDR fun, int nargs,
590 // OBSOLETE struct value **args, struct type *type, int gcc_p)
591 // OBSOLETE {
592 // OBSOLETE long offset24;
593 // OBSOLETE
594 // OBSOLETE offset24 = (long) fun - (long) entry_point_address ();
595 // OBSOLETE offset24 &= 0x3fffff;
596 // OBSOLETE offset24 |= 0xff800000; /* jarl <offset24>, r31 */
597 // OBSOLETE
598 // OBSOLETE store_unsigned_integer ((unsigned int *) &dummy[2], 2, offset24 & 0xffff);
599 // OBSOLETE store_unsigned_integer ((unsigned int *) &dummy[0], 2, offset24 >> 16);
600 // OBSOLETE return 0;
601 // OBSOLETE }
This page took 0.042043 seconds and 4 git commands to generate.