* dvp-opc.c (parse_vif_unpackloc,insert_vif_unpackloc): Delete.
[deliverable/binutils-gdb.git] / gdb / mn10300-tdep.c
CommitLineData
3de76938
GN
1/* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2 Copyright 1996, 1997 Free Software Foundation, Inc.
ddc2888e
GN
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
3de76938 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ddc2888e
GN
19
20#include "defs.h"
21#include "frame.h"
22#include "inferior.h"
23#include "obstack.h"
24#include "target.h"
25#include "value.h"
26#include "bfd.h"
27#include "gdb_string.h"
28#include "gdbcore.h"
29#include "symfile.h"
30
31/* Info gleaned from scanning a function's prologue. */
32
33struct pifsr /* Info about one saved reg */
34{
35 int framereg; /* Frame reg (SP or FP) */
36 int offset; /* Offset from framereg */
37 int reg; /* Saved register number */
38};
39
40struct prologue_info
41{
42 int framereg;
43 int frameoffset;
44 int start_function;
45 struct pifsr *pifsrs;
46};
47
95efddf2
GN
48/* Function: frame_chain
49 Figure out and return the caller's frame pointer given current
50 frame_info struct.
3de76938 51
95efddf2
GN
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.
3de76938 56
95efddf2
GN
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?
59*/
3de76938 60
95efddf2
GN
61CORE_ADDR
62mn10300_frame_chain (fi)
ddc2888e
GN
63 struct frame_info *fi;
64{
3de76938 65 struct prologue_info pi;
95efddf2
GN
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 */
69 int n_movm_args = 4;
3de76938 70
95efddf2 71 struct pifsr *pifsr, *pifsr_tmp;
3de76938 72
95efddf2
GN
73 /* current pc is fi->pc */
74 /* current fp is fi->frame */
3de76938 75
95efddf2
GN
76 /* current sp is: */
77 curr_sp = read_register (SP_REGNUM);
3de76938 78
95efddf2
GN
79/*
80 printf("curr pc = 0x%x ; curr fp = 0x%x ; curr sp = 0x%x\n",
81 fi->pc, fi->frame, curr_sp);
82*/
3de76938 83
95efddf2
GN
84 /* first inst after prologue is: */
85 past_prologue_addr = mn10300_skip_prologue (fi->pc);
3de76938 86
95efddf2
GN
87 /* Are we in the prologue? */
88 /* Yes if mn10300_skip_prologue returns an address after the
89 current pc in which case we have to scan prologue */
90 if (fi->pc < mn10300_skip_prologue (fi->pc))
91 past_prologue = 0;
3de76938 92
95efddf2
GN
93 /* scan prologue if we're not past it */
94 if (!past_prologue)
3de76938 95 {
95efddf2
GN
96 /* printf("scanning prologue\n"); */
97 /* FIXME -- fill out this case later */
e385d6e0 98 return 0x0; /* bogus value */
3de76938
GN
99 }
100
95efddf2
GN
101 if (past_prologue) /* if we don't need to scan the prologue */
102 {
103/* printf("we're past the prologue\n"); */
104 callers_pc = fi->frame - REGISTER_SIZE;
105 callers_fp = fi->frame - ((n_movm_args + 1) * REGISTER_SIZE);
106/*
107 printf("callers_pc = 0x%x ; callers_fp = 0x%x\n",
108 callers_pc, callers_fp);
109
110 printf("*callers_pc = 0x%x ; *callers_fp = 0x%x\n",
111 read_memory_integer(callers_pc, REGISTER_SIZE),
112 read_memory_integer(callers_fp, REGISTER_SIZE));
113*/
114 return read_memory_integer(callers_fp, REGISTER_SIZE);
115 }
3de76938 116
95efddf2 117 /* we don't get here */
ddc2888e
GN
118}
119
3de76938
GN
120/* Function: find_callers_reg
121 Find REGNUM on the stack. Otherwise, it's in an active register.
122 One thing we might want to do here is to check REGNUM against the
123 clobber mask, and somehow flag it as invalid if it isn't saved on
124 the stack somewhere. This would provide a graceful failure mode
125 when trying to get the value of caller-saves registers for an inner
126 frame. */
127
ddc2888e
GN
128CORE_ADDR
129mn10300_find_callers_reg (fi, regnum)
130 struct frame_info *fi;
131 int regnum;
132{
95efddf2 133/* printf("mn10300_find_callers_reg\n"); */
3de76938
GN
134
135 for (; fi; fi = fi->next)
136 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
137 return generic_read_register_dummy (fi->pc, fi->frame, regnum);
138 else if (fi->fsr.regs[regnum] != 0)
139 return read_memory_unsigned_integer (fi->fsr.regs[regnum],
140 REGISTER_RAW_SIZE(regnum));
141
142 return read_register (regnum);
ddc2888e
GN
143}
144
3de76938 145/* Function: skip_prologue
95efddf2
GN
146 Return the address of the first inst past the prologue of the function.
147*/
3de76938 148
ddc2888e
GN
149CORE_ADDR
150mn10300_skip_prologue (pc)
151 CORE_ADDR pc;
152{
3de76938
GN
153 CORE_ADDR func_addr, func_end;
154
95efddf2 155/* printf("mn10300_skip_prologue\n"); */
3de76938
GN
156
157 /* See what the symbol table says */
158
159 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
160 {
161 struct symtab_and_line sal;
162
163 sal = find_pc_line (func_addr, 0);
164
165 if (sal.line != 0 && sal.end < func_end)
166 return sal.end;
167 else
168 /* Either there's no line info, or the line after the prologue is after
169 the end of the function. In this case, there probably isn't a
170 prologue. */
171 return pc;
172 }
173
174/* We can't find the start of this function, so there's nothing we can do. */
175 return pc;
ddc2888e
GN
176}
177
178/* Function: pop_frame
179 This routine gets called when either the user uses the `return'
180 command, or the call dummy breakpoint gets hit. */
181
182void
183mn10300_pop_frame (frame)
184 struct frame_info *frame;
185{
3de76938
GN
186 int regnum;
187
95efddf2 188/* printf("mn10300_pop_frame start\n"); */
3de76938
GN
189
190 if (PC_IN_CALL_DUMMY(frame->pc, frame->frame, frame->frame))
191 generic_pop_dummy_frame ();
192 else
193 {
194 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
195
196 for (regnum = 0; regnum < NUM_REGS; regnum++)
197 if (frame->fsr.regs[regnum] != 0)
198 write_register (regnum,
199 read_memory_unsigned_integer (frame->fsr.regs[regnum],
200 REGISTER_RAW_SIZE(regnum)));
201
202 write_register (SP_REGNUM, FRAME_FP (frame));
203 }
204
205 flush_cached_frames ();
206
95efddf2 207/* printf("mn10300_pop_frame end\n"); */
ddc2888e
GN
208}
209
3de76938
GN
210/* Function: push_arguments
211 Setup arguments for a call to the target. Arguments go in
212 order on the stack.
213*/
214
ddc2888e
GN
215CORE_ADDR
216mn10300_push_arguments (nargs, args, sp, struct_return, struct_addr)
217 int nargs;
218 value_ptr *args;
219 CORE_ADDR sp;
220 unsigned char struct_return;
221 CORE_ADDR struct_addr;
222{
3de76938
GN
223 int argnum = 0;
224 int len = 0;
225 int stack_offset = 0; /* copy args to this offset onto stack */
226
95efddf2 227/* printf("mn10300_push_arguments start\n"); */
3de76938
GN
228
229 /* First, just for safety, make sure stack is aligned */
230 sp &= ~3;
231
232 /* Now make space on the stack for the args. */
233 for (argnum = 0; argnum < nargs; argnum++)
234 len += ((TYPE_LENGTH(VALUE_TYPE(args[argnum])) + 3) & ~3);
235
236 sp -= len;
237
238 /* Push all arguments onto the stack. */
239 for (argnum = 0; argnum < nargs; argnum++)
240 {
241 int len;
242 char *val;
243
244 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
245 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
246 {
247 /* for now, pretend structs aren't special */
248 len = TYPE_LENGTH (VALUE_TYPE (*args));
249 val = (char *)VALUE_CONTENTS (*args);
250 }
251 else
252 {
253 len = TYPE_LENGTH (VALUE_TYPE (*args));
254 val = (char *)VALUE_CONTENTS (*args);
255 }
256
257 while (len > 0)
258 {
259 write_memory (sp + stack_offset, val, 4);
260
261 len -= 4;
262 val += 4;
263 stack_offset += 4;
264 }
265 args++;
266 }
267
95efddf2 268/* printf"mn10300_push_arguments end\n"); */
3de76938
GN
269
270 return sp;
ddc2888e
GN
271}
272
3de76938
GN
273/* Function: push_return_address (pc)
274 Set up the return address for the inferior function call.
275 Needed for targets where we don't actually execute a JSR/BSR instruction */
276
ddc2888e
GN
277CORE_ADDR
278mn10300_push_return_address (pc, sp)
279 CORE_ADDR pc;
280 CORE_ADDR sp;
281{
95efddf2 282/* printf("mn10300_push_return_address\n"); */
3de76938
GN
283
284 /* write_register (RP_REGNUM, CALL_DUMMY_ADDRESS ()); */
285 return sp;
ddc2888e
GN
286}
287
3de76938
GN
288/* Function: frame_saved_pc
289 Find the caller of this frame. We do this by seeing if RP_REGNUM
290 is saved in the stack anywhere, otherwise we get it from the
291 registers. If the inner frame is a dummy frame, return its PC
292 instead of RP, because that's where "caller" of the dummy-frame
293 will be found. */
294
ddc2888e
GN
295CORE_ADDR
296mn10300_frame_saved_pc (fi)
297 struct frame_info *fi;
298{
95efddf2 299/* printf("mn10300_frame_saved_pc\n"); */
3de76938 300
95efddf2 301 return (read_memory_integer(fi->frame - REGISTER_SIZE, REGISTER_SIZE));
ddc2888e
GN
302}
303
304void
305get_saved_register (raw_buffer, optimized, addrp, frame, regnum, lval)
306 char *raw_buffer;
307 int *optimized;
308 CORE_ADDR *addrp;
309 struct frame_info *frame;
310 int regnum;
311 enum lval_type *lval;
312{
95efddf2 313/* printf("get_saved_register\n"); */
3de76938 314
ddc2888e
GN
315 generic_get_saved_register (raw_buffer, optimized, addrp,
316 frame, regnum, lval);
317}
318
95efddf2
GN
319/* Function: init_extra_frame_info
320 Setup the frame's frame pointer, pc, and frame addresses for saved
321 registers. Most of the work is done in frame_chain().
3de76938 322
95efddf2
GN
323 Note that when we are called for the last frame (currently active frame),
324 that fi->pc and fi->frame will already be setup. However, fi->frame will
325 be valid only if this routine uses FP. For previous frames, fi-frame will
326 always be correct (since that is derived from v850_frame_chain ()).
327
328 We can be called with the PC in the call dummy under two circumstances.
329 First, during normal backtracing, second, while figuring out the frame
330 pointer just prior to calling the target function (see run_stack_dummy).
331*/
332
333void
334mn10300_init_extra_frame_info (fi)
335 struct frame_info *fi;
ddc2888e 336{
95efddf2
GN
337 struct prologue_info pi;
338 struct pifsr pifsrs[NUM_REGS + 1], *pifsr;
339 int reg;
3de76938 340
95efddf2
GN
341 if (fi->next)
342 fi->pc = FRAME_SAVED_PC (fi->next);
3de76938 343
95efddf2 344 memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
3de76938 345
95efddf2
GN
346 /* The call dummy doesn't save any registers on the stack, so we can return
347 now. */
348/*
349 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
350 return;
351
352 pi.pifsrs = pifsrs;
353*/
3de76938 354
95efddf2
GN
355 /* v850_scan_prologue (fi->pc, &pi); */
356/*
357 if (!fi->next && pi.framereg == SP_REGNUM)
358 fi->frame = read_register (pi.framereg) - pi.frameoffset;
3de76938 359
95efddf2
GN
360 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
361 {
362 fi->fsr.regs[pifsr->reg] = pifsr->offset + fi->frame;
363
364 if (pifsr->framereg == SP_REGNUM)
365 fi->fsr.regs[pifsr->reg] += pi.frameoffset;
366 }
367*/
368/* printf("init_extra_frame_info\n"); */
ddc2888e
GN
369}
370
371void
372_initialize_mn10300_tdep ()
373{
95efddf2 374/* printf("_initialize_mn10300_tdep\n"); */
3de76938 375
ddc2888e
GN
376 tm_print_insn = print_insn_mn10300;
377}
95efddf2 378
This page took 0.108548 seconds and 4 git commands to generate.