1 /* Target-dependent code for the Matsushita MN10300 for GDB, the GNU debugger.
2 Prologue analysis module, extracted from mn10300-tdep.c, Oct. 1, 2004.
4 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
5 Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
29 #include "trad-frame.h"
30 #include "mn10300-tdep.h"
32 enum movm_register_bits
{
33 movm_exother_bit
= 0x01,
34 movm_exreg1_bit
= 0x02,
35 movm_exreg0_bit
= 0x04,
36 movm_other_bit
= 0x08,
43 /* Values for frame_info.status */
54 * status -- actually frame type (SP, FP, or last frame)
55 * stack size -- offset to the next frame
57 * The former might ultimately be stored in the frame_base.
58 * Seems like there'd be a way to store the later too.
60 * Temporarily supply empty stub functions as place holders.
64 my_frame_is_in_sp (struct frame_info
*fi
, void **this_cache
)
66 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
67 trad_frame_set_this_base (cache
,
68 frame_unwind_register_unsigned (fi
,
73 my_frame_is_in_fp (struct frame_info
*fi
, void **this_cache
)
75 struct trad_frame_cache
*cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
76 trad_frame_set_this_base (cache
,
77 frame_unwind_register_unsigned (fi
,
82 my_frame_is_last (struct frame_info
*fi
)
87 is_my_frame_in_sp (struct frame_info
*fi
)
93 is_my_frame_in_fp (struct frame_info
*fi
)
99 is_my_frame_last (struct frame_info
*fi
)
105 set_my_stack_size (struct frame_info
*fi
, CORE_ADDR size
)
110 /* Set offsets of registers saved by movm instruction.
111 This is a helper function for mn10300_analyze_prologue. */
114 set_movm_offsets (struct frame_info
*fi
,
118 struct trad_frame_cache
*cache
;
122 if (cache
== NULL
|| fi
== NULL
)
125 cache
= mn10300_frame_unwind_cache (fi
, this_cache
);
126 base
= trad_frame_get_this_base (cache
);
127 if (movm_args
& movm_other_bit
)
129 /* The `other' bit leaves a blank area of four bytes at the
130 beginning of its block of saved registers, making it 32 bytes
132 trad_frame_set_reg_addr (cache
, E_LAR_REGNUM
, base
+ offset
+ 4);
133 trad_frame_set_reg_addr (cache
, E_LIR_REGNUM
, base
+ offset
+ 8);
134 trad_frame_set_reg_addr (cache
, E_MDR_REGNUM
, base
+ offset
+ 12);
135 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
+ 1, base
+ offset
+ 16);
136 trad_frame_set_reg_addr (cache
, E_A0_REGNUM
, base
+ offset
+ 20);
137 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
+ 1, base
+ offset
+ 24);
138 trad_frame_set_reg_addr (cache
, E_D0_REGNUM
, base
+ offset
+ 28);
142 if (movm_args
& movm_a3_bit
)
144 trad_frame_set_reg_addr (cache
, E_A3_REGNUM
, base
+ offset
);
147 if (movm_args
& movm_a2_bit
)
149 trad_frame_set_reg_addr (cache
, E_A2_REGNUM
, base
+ offset
);
152 if (movm_args
& movm_d3_bit
)
154 trad_frame_set_reg_addr (cache
, E_D3_REGNUM
, base
+ offset
);
157 if (movm_args
& movm_d2_bit
)
159 trad_frame_set_reg_addr (cache
, E_D2_REGNUM
, base
+ offset
);
164 if (movm_args
& movm_exother_bit
)
166 trad_frame_set_reg_addr (cache
, E_MCVF_REGNUM
, base
+ offset
);
167 trad_frame_set_reg_addr (cache
, E_MCRL_REGNUM
, base
+ offset
+ 4);
168 trad_frame_set_reg_addr (cache
, E_MCRH_REGNUM
, base
+ offset
+ 8);
169 trad_frame_set_reg_addr (cache
, E_MDRQ_REGNUM
, base
+ offset
+ 12);
170 trad_frame_set_reg_addr (cache
, E_E1_REGNUM
, base
+ offset
+ 16);
171 trad_frame_set_reg_addr (cache
, E_E0_REGNUM
, base
+ offset
+ 20);
174 if (movm_args
& movm_exreg1_bit
)
176 trad_frame_set_reg_addr (cache
, E_E7_REGNUM
, base
+ offset
);
177 trad_frame_set_reg_addr (cache
, E_E6_REGNUM
, base
+ offset
+ 4);
178 trad_frame_set_reg_addr (cache
, E_E5_REGNUM
, base
+ offset
+ 8);
179 trad_frame_set_reg_addr (cache
, E_E4_REGNUM
, base
+ offset
+ 12);
182 if (movm_args
& movm_exreg0_bit
)
184 trad_frame_set_reg_addr (cache
, E_E3_REGNUM
, base
+ offset
);
185 trad_frame_set_reg_addr (cache
, E_E2_REGNUM
, base
+ offset
+ 4);
189 /* The last (or first) thing on the stack will be the PC. */
190 trad_frame_set_reg_addr (cache
, E_PC_REGNUM
, base
+ offset
);
191 /* Save the SP in the 'traditional' way.
192 This will be the same location where the PC is saved. */
193 trad_frame_set_reg_value (cache
, E_SP_REGNUM
, base
+ offset
);
196 /* The main purpose of this file is dealing with prologues to extract
197 information about stack frames and saved registers.
199 In gcc/config/mn13000/mn10300.c, the expand_prologue prologue
200 function is pretty readable, and has a nice explanation of how the
201 prologue is generated. The prologues generated by that code will
202 have the following form (NOTE: the current code doesn't handle all
205 + If this is an old-style varargs function, then its arguments
206 need to be flushed back to the stack:
211 + If we use any of the callee-saved registers, save them now.
213 movm [some callee-saved registers],(sp)
215 + If we have any floating-point registers to save:
217 - Decrement the stack pointer to reserve space for the registers.
218 If the function doesn't need a frame pointer, we may combine
219 this with the adjustment that reserves space for the frame.
223 - Save the floating-point registers. We have two possible
226 . Save them at fixed offset from the SP:
228 fmov fsN,(OFFSETN,sp)
229 fmov fsM,(OFFSETM,sp)
232 Note that, if OFFSETN happens to be zero, you'll get the
233 different opcode: fmov fsN,(sp)
235 . Or, set a0 to the start of the save area, and then use
236 post-increment addressing to save the FP registers.
244 + If the function needs a frame pointer, we set it here.
248 + Now we reserve space for the stack frame proper. This could be
249 merged into the `add -SIZE, sp' instruction for FP saves up
250 above, unless we needed to set the frame pointer in the previous
251 step, or the frame is so large that allocating the whole thing at
252 once would put the FP register save slots out of reach of the
253 addressing mode (128 bytes).
257 One day we might keep the stack pointer constant, that won't
258 change the code for prologues, but it will make the frame
259 pointerless case much more common. */
261 /* Analyze the prologue to determine where registers are saved,
262 the end of the prologue, etc etc. Return the end of the prologue
265 We store into FI (if non-null) several tidbits of information:
267 * stack_size -- size of this stack frame. Note that if we stop in
268 certain parts of the prologue/epilogue we may claim the size of the
269 current frame is zero. This happens when the current frame has
270 not been allocated yet or has already been deallocated.
272 * fsr -- Addresses of registers saved in the stack by this frame.
274 * status -- A (relatively) generic status indicator. It's a bitmask
275 with the following bits:
277 MY_FRAME_IN_SP: The base of the current frame is actually in
278 the stack pointer. This can happen for frame pointerless
279 functions, or cases where we're stopped in the prologue/epilogue
280 itself. For these cases mn10300_analyze_prologue will need up
281 update fi->frame before returning or analyzing the register
284 MY_FRAME_IN_FP: The base of the current frame is in the
285 frame pointer register ($a3).
287 NO_MORE_FRAMES: Set this if the current frame is "start" or
288 if the first instruction looks like mov <imm>,sp. This tells
289 frame chain to not bother trying to unwind past this frame. */
292 mn10300_analyze_prologue (struct frame_info
*fi
,
296 CORE_ADDR func_addr
, func_end
, addr
, stop
;
299 unsigned char buf
[4];
300 int status
, movm_args
= 0;
303 /* Use the PC in the frame if it's provided to look up the
304 start of this function.
306 Note: kevinb/2003-07-16: We used to do the following here:
307 pc = (fi ? get_frame_pc (fi) : pc);
308 But this is (now) badly broken when called from analyze_dummy_frame().
312 pc
= (pc
? pc
: get_frame_pc (fi
));
313 /* At the start of a function our frame is in the stack pointer. */
314 my_frame_is_in_sp (fi
, this_cache
);
317 /* Find the start of this function. */
318 status
= find_pc_partial_function (pc
, &name
, &func_addr
, &func_end
);
320 /* Do nothing if we couldn't find the start of this function
322 MVS: comment went on to say "or if we're stopped at the first
323 instruction in the prologue" -- but code doesn't reflect that,
324 and I don't want to do that anyway. */
330 /* If we're in start, then give up. */
331 if (strcmp (name
, "start") == 0)
334 my_frame_is_last (fi
);
339 /* Get the next two bytes into buf, we need two because rets is a two
340 byte insn and the first isn't enough to uniquely identify it. */
341 status
= deprecated_read_memory_nobpt (pc
, buf
, 2);
345 /* Note: kevinb/2003-07-16: We shouldn't be making these sorts of
346 changes to the frame in prologue examination code. */
347 /* If we're physically on an "rets" instruction, then our frame has
348 already been deallocated. Note this can also be true for retf
349 and ret if they specify a size of zero.
351 In this case fi->frame is bogus, we need to fix it. */
352 if (fi
&& buf
[0] == 0xf0 && buf
[1] == 0xfc)
354 if (get_next_frame (fi
) == NULL
)
355 deprecated_update_frame_base_hack (fi
, read_sp ());
356 return get_frame_pc (fi
);
359 /* Similarly if we're stopped on the first insn of a prologue as our
360 frame hasn't been allocated yet. */
361 if (fi
&& get_frame_pc (fi
) == func_addr
)
363 if (get_next_frame (fi
) == NULL
)
364 deprecated_update_frame_base_hack (fi
, read_sp ());
365 return get_frame_pc (fi
);
369 /* NOTE: from here on, we don't want to return without jumping to
373 /* Figure out where to stop scanning. */
374 stop
= fi
? pc
: func_end
;
376 /* Don't walk off the end of the function. */
377 stop
= stop
> func_end
? func_end
: stop
;
379 /* Start scanning on the first instruction of this function. */
382 /* Suck in two bytes. */
384 || (status
= deprecated_read_memory_nobpt (addr
, buf
, 2)) != 0)
385 goto finish_prologue
;
387 /* First see if this insn sets the stack pointer from a register; if
388 so, it's probably the initialization of the stack pointer in _start,
389 so mark this as the bottom-most frame. */
390 if (buf
[0] == 0xf2 && (buf
[1] & 0xf3) == 0xf0)
393 my_frame_is_last (fi
);
394 goto finish_prologue
;
397 /* Now look for movm [regs],sp, which saves the callee saved registers.
399 At this time we don't know if fi->frame is valid, so we only note
400 that we encountered a movm instruction. Later, we'll set the entries
401 in fsr.regs as needed. */
404 /* Extract the register list for the movm instruction. */
409 /* Quit now if we're beyond the stop point. */
411 goto finish_prologue
;
413 /* Get the next two bytes so the prologue scan can continue. */
414 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
416 goto finish_prologue
;
419 /* Now see if we set up a frame pointer via "mov sp,a3" */
424 /* The frame pointer is now valid. */
427 my_frame_is_in_fp (fi
, this_cache
);
430 /* Quit now if we're beyond the stop point. */
432 goto finish_prologue
;
434 /* Get two more bytes so scanning can continue. */
435 status
= deprecated_read_memory_nobpt (addr
, buf
, 2);
437 goto finish_prologue
;
440 /* Next we should allocate the local frame. No more prologue insns
441 are found after allocating the local frame.
443 Search for add imm8,sp (0xf8feXX)
444 or add imm16,sp (0xfafeXXXX)
445 or add imm32,sp (0xfcfeXXXXXXXX).
447 If none of the above was found, then this prologue has no
451 if (buf
[0] == 0xf8 && buf
[1] == 0xfe)
453 else if (buf
[0] == 0xfa && buf
[1] == 0xfe)
455 else if (buf
[0] == 0xfc && buf
[1] == 0xfe)
460 /* Suck in imm_size more bytes, they'll hold the size of the
462 status
= deprecated_read_memory_nobpt (addr
+ 2, buf
, imm_size
);
464 goto finish_prologue
;
466 /* Note the size of the stack in the frame info structure. */
467 stack_size
= extract_signed_integer (buf
, imm_size
);
469 set_my_stack_size (fi
, stack_size
);
471 /* We just consumed 2 + imm_size bytes. */
472 addr
+= 2 + imm_size
;
474 /* No more prologue insns follow, so begin preparation to return. */
475 goto finish_prologue
;
477 /* Do the essentials and get out of here. */
479 /* Note if/where callee saved registers were saved. */
481 set_movm_offsets (fi
, this_cache
, movm_args
);
This page took 0.039148 seconds and 4 git commands to generate.