1 /* Target-dependent code for the Matsushita MN10200 for GDB, the GNU debugger.
2 Copyright 1997 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
31 /* Info gleaned from scanning a function's prologue. */
33 struct pifsr
/* Info about one saved reg */
35 int framereg
; /* Frame reg (SP or FP) */
36 int offset
; /* Offset from framereg */
37 int reg
; /* Saved register number */
48 /* Function: frame_chain
49 Figure out and return the caller's frame pointer given current
52 We start out knowing the current pc, current sp, current fp.
53 We want to determine the caller's fp and caller's pc. To do this
54 correctly, we have to be able to handle the case where we are in the
55 middle of the prologue which involves scanning the prologue.
57 We don't handle dummy frames yet but we would probably just return the
58 stack pointer that was in use at the time the function call was made?
62 mn10200_frame_chain (fi
)
63 struct frame_info
*fi
;
65 struct prologue_info pi
;
66 CORE_ADDR callers_pc
, callers_fp
, curr_sp
;
67 CORE_ADDR past_prologue_addr
;
68 int past_prologue
= 1; /* default to being past prologue */
71 struct pifsr
*pifsr
, *pifsr_tmp
;
73 /* current pc is fi->pc */
74 /* current fp is fi->frame */
76 curr_sp
= read_register (SP_REGNUM
);
79 printf("curr pc = 0x%x ; curr fp = 0x%x ; curr sp = 0x%x\n",
80 fi->pc, fi->frame, curr_sp);
83 /* first inst after prologue is: */
84 past_prologue_addr
= mn10200_skip_prologue (fi
->pc
);
86 /* Are we in the prologue? */
87 /* Yes if mn10200_skip_prologue returns an address after the
88 current pc in which case we have to scan prologue */
89 if (fi
->pc
< mn10200_skip_prologue (fi
->pc
))
92 /* scan prologue if we're not past it */
95 /* printf("scanning prologue\n"); */
96 /* FIXME -- fill out this case later */
97 return 0x0; /* bogus value */
100 if (past_prologue
) /* if we don't need to scan the prologue */
102 callers_pc
= fi
->frame
- REGISTER_SIZE
;
103 callers_fp
= fi
->frame
- (4 * REGISTER_SIZE
);
106 printf("callers_pc = 0x%x ; callers_fp = 0x%x\n",
107 callers_pc
, callers_fp
);
108 printf("*callers_pc = 0x%x ; *callers_fp = 0x%x\n",
109 read_memory_integer(callers_pc
, REGISTER_SIZE
),
110 read_memory_integer(callers_fp
, REGISTER_SIZE
));
113 return read_memory_integer(callers_fp
, REGISTER_SIZE
);
116 /* we don't get here */
119 /* Function: find_callers_reg
120 Find REGNUM on the stack. Otherwise, it's in an active register.
121 One thing we might want to do here is to check REGNUM against the
122 clobber mask, and somehow flag it as invalid if it isn't saved on
123 the stack somewhere. This would provide a graceful failure mode
124 when trying to get the value of caller-saves registers for an inner
128 mn10200_find_callers_reg (fi
, regnum
)
129 struct frame_info
*fi
;
132 /* printf("mn10200_find_callers_reg\n"); */
134 for (; fi
; fi
= fi
->next
)
135 if (PC_IN_CALL_DUMMY (fi
->pc
, fi
->frame
, fi
->frame
))
136 return generic_read_register_dummy (fi
->pc
, fi
->frame
, regnum
);
137 else if (fi
->fsr
.regs
[regnum
] != 0)
138 return read_memory_unsigned_integer (fi
->fsr
.regs
[regnum
],
139 REGISTER_RAW_SIZE(regnum
));
141 return read_register (regnum
);
144 /* Function: skip_prologue
145 Return the address of the first inst past the prologue of the function.
149 mn10200_skip_prologue (pc
)
152 CORE_ADDR func_addr
, func_end
;
154 /* printf("mn10200_skip_prologue\n"); */
156 /* See what the symbol table says */
158 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
160 struct symtab_and_line sal
;
162 sal
= find_pc_line (func_addr
, 0);
164 if (sal
.line
!= 0 && sal
.end
< func_end
)
167 /* Either there's no line info, or the line after the prologue is after
168 the end of the function. In this case, there probably isn't a
173 /* We can't find the start of this function, so there's nothing we can do. */
177 /* Function: pop_frame
178 This routine gets called when either the user uses the `return'
179 command, or the call dummy breakpoint gets hit. */
182 mn10200_pop_frame (frame
)
183 struct frame_info
*frame
;
187 /* printf("mn10200_pop_frame start\n"); */
189 if (PC_IN_CALL_DUMMY(frame
->pc
, frame
->frame
, frame
->frame
))
190 generic_pop_dummy_frame ();
193 write_register (PC_REGNUM
, FRAME_SAVED_PC (frame
));
195 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
196 if (frame
->fsr
.regs
[regnum
] != 0)
197 write_register (regnum
,
198 read_memory_unsigned_integer (frame
->fsr
.regs
[regnum
],
199 REGISTER_RAW_SIZE(regnum
)));
201 write_register (SP_REGNUM
, FRAME_FP (frame
));
204 flush_cached_frames ();
206 /* printf("mn10200_pop_frame end\n"); */
209 /* Function: push_arguments
210 Setup arguments for a call to the target. Arguments go in
215 mn10200_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
219 unsigned char struct_return
;
220 CORE_ADDR struct_addr
;
224 int stack_offset
= 0; /* copy args to this offset onto stack */
226 /* printf("mn10200_push_arguments start\n"); */
228 /* First, just for safety, make sure stack is aligned */
231 /* Now make space on the stack for the args. */
232 for (argnum
= 0; argnum
< nargs
; argnum
++)
233 len
+= ((TYPE_LENGTH(VALUE_TYPE(args
[argnum
])) + 3) & ~3);
237 /* Push all arguments onto the stack. */
238 for (argnum
= 0; argnum
< nargs
; argnum
++)
243 if (TYPE_CODE (VALUE_TYPE (*args
)) == TYPE_CODE_STRUCT
244 && TYPE_LENGTH (VALUE_TYPE (*args
)) > 8)
246 /* for now, pretend structs aren't special */
247 len
= TYPE_LENGTH (VALUE_TYPE (*args
));
248 val
= (char *)VALUE_CONTENTS (*args
);
252 len
= TYPE_LENGTH (VALUE_TYPE (*args
));
253 val
= (char *)VALUE_CONTENTS (*args
);
258 write_memory (sp
+ stack_offset
, val
, 4);
267 /* printf"mn10200_push_arguments end\n"); */
272 /* Function: push_return_address (pc)
273 Set up the return address for the inferior function call.
274 Needed for targets where we don't actually execute a JSR/BSR instruction */
277 mn10200_push_return_address (pc
, sp
)
281 /* printf("mn10200_push_return_address\n"); */
283 /* write_register (RP_REGNUM, CALL_DUMMY_ADDRESS ()); */
287 /* Function: frame_saved_pc
288 Find the caller of this frame. We do this by seeing if RP_REGNUM
289 is saved in the stack anywhere, otherwise we get it from the
290 registers. If the inner frame is a dummy frame, return its PC
291 instead of RP, because that's where "caller" of the dummy-frame
295 mn10200_frame_saved_pc (fi
)
296 struct frame_info
*fi
;
298 /* printf("mn10200_frame_saved_pc\n"); */
300 return (read_memory_integer(fi
->frame
- REGISTER_SIZE
, REGISTER_SIZE
));
304 get_saved_register (raw_buffer
, optimized
, addrp
, frame
, regnum
, lval
)
308 struct frame_info
*frame
;
310 enum lval_type
*lval
;
312 /* printf("get_saved_register\n"); */
314 generic_get_saved_register (raw_buffer
, optimized
, addrp
,
315 frame
, regnum
, lval
);
318 /* Function: init_extra_frame_info
319 Setup the frame's frame pointer, pc, and frame addresses for saved
320 registers. Most of the work is done in frame_chain().
322 Note that when we are called for the last frame (currently active frame),
323 that fi->pc and fi->frame will already be setup. However, fi->frame will
324 be valid only if this routine uses FP. For previous frames, fi-frame will
325 always be correct (since that is derived from v850_frame_chain ()).
327 We can be called with the PC in the call dummy under two circumstances.
328 First, during normal backtracing, second, while figuring out the frame
329 pointer just prior to calling the target function (see run_stack_dummy).
333 mn10200_init_extra_frame_info (fi
)
334 struct frame_info
*fi
;
336 struct prologue_info pi
;
337 struct pifsr pifsrs
[NUM_REGS
+ 1], *pifsr
;
341 fi
->pc
= FRAME_SAVED_PC (fi
->next
);
343 memset (fi
->fsr
.regs
, '\000', sizeof fi
->fsr
.regs
);
345 /* The call dummy doesn't save any registers on the stack, so we can return
348 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
354 /* v850_scan_prologue (fi->pc, &pi); */
356 if (!fi->next && pi.framereg == SP_REGNUM)
357 fi->frame = read_register (pi.framereg) - pi.frameoffset;
359 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
361 fi->fsr.regs[pifsr->reg] = pifsr->offset + fi->frame;
363 if (pifsr->framereg == SP_REGNUM)
364 fi->fsr.regs[pifsr->reg] += pi.frameoffset;
367 /* printf("init_extra_frame_info\n"); */
371 _initialize_mn10200_tdep ()
373 /* printf("_initialize_mn10200_tdep\n"); */
375 tm_print_insn
= print_insn_mn10200
;