1 /* Target-dependent code for the Mitsubishi m32r for GDB, the GNU debugger.
2 Copyright 1996, 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"
33 struct dummy_frame *next;
42 m32r_frame_find_saved_regs PARAMS ((struct frame_info *fi,
43 struct frame_saved_regs *regaddr))
48 static struct dummy_frame *dummy_frame_stack = NULL;
50 /* Find end of function prologue */
53 m32r_skip_prologue (pc)
56 CORE_ADDR func_addr, func_end;
57 struct symtab_and_line sal;
59 /* See what the symbol table says */
61 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
63 sal = find_pc_line (func_addr, 0);
65 if (sal.line != 0 && sal.end < func_end)
68 /* Either there's no line info, or the line after the prologue is after
69 the end of the function. In this case, there probably isn't a
74 /* We can't find the start of this function, so there's nothing we can do. */
78 /* This function decodes the target function prologue to determine
79 1) the size of the stack frame, and 2) which registers are saved on it.
80 It saves the offsets of saved regs in the frame_saved_regs argument,
81 and returns the frame size.
85 m32r_scan_prologue (fi, fsr)
86 struct frame_info *fi;
87 struct frame_saved_regs *fsr;
89 struct symtab_and_line sal;
90 CORE_ADDR prologue_start, prologue_end, current_pc;
91 unsigned long framesize;
93 /* this code essentially duplicates skip_prologue,
94 but we need the start address below. */
96 if (find_pc_partial_function (fi->pc, NULL, &prologue_start, &prologue_end))
98 sal = find_pc_line (prologue_start, 0);
100 if (sal.line == 0) /* no line info, use current PC */
101 prologue_end = fi->pc;
102 else if (sal.end < prologue_end) /* next line begins after fn end */
103 prologue_end = sal.end; /* (probably means no prologue) */
106 prologue_end = prologue_start + 100; /* We're in the boondocks */
108 prologue_end = min (prologue_end, fi->pc);
110 /* Now, search the prologue looking for instructions that setup fp, save
111 rp (and other regs), adjust sp and such. */
114 memset (fsr->regs, '\000', sizeof fsr->regs);
116 for (current_pc = prologue_start; current_pc < prologue_end; current_pc += 2)
121 insn = read_memory_unsigned_integer (current_pc, 2);
122 if (insn & 0x80) /* Four byte instruction? */
125 if ((insn & 0xf0ff) == 0x207f) { /* st reg, @-sp */
127 regno = ((insn >> 8) & 0xf);
128 fsr->regs[regno] = framesize;
130 else if ((insn >> 8) == 0x4f) { /* addi sp */
131 framesize += -((char) (insn & 0xff)); /* offset */
132 break; /* end of stack adjustments */
138 /* This function actually figures out the frame address for a given pc and
139 sp. This is tricky on the v850 because we only use an explicit frame
140 pointer when using alloca(). The only reliable way to get this info is to
141 examine the prologue.
145 m32r_init_extra_frame_info (fi)
146 struct frame_info *fi;
152 fi->pc = FRAME_SAVED_PC (fi->next);
154 framesize = m32r_scan_prologue (fi, &fi->fsr);
156 if (PC_IN_CALL_DUMMY (fi->pc, NULL, NULL))
157 fi->frame = dummy_frame_stack->sp;
159 fi->frame = read_register (SP_REGNUM);
161 for (reg = 0; reg < NUM_REGS; reg++)
162 if (fi->fsr.regs[reg] != 0)
163 fi->fsr.regs[reg] = fi->frame + framesize - fi->fsr.regs[reg];
166 /* Find the caller of this frame. We do this by seeing if RP_REGNUM is saved
167 in the stack anywhere, otherwise we get it from the registers. */
170 m32r_find_callers_reg (fi, regnum)
171 struct frame_info *fi;
175 /* XXX - Won't work if multiple dummy frames are active */
176 if (PC_IN_CALL_DUMMY (fi->pc, NULL, NULL))
180 return dummy_frame_stack->sp;
183 return dummy_frame_stack->fp;
186 return dummy_frame_stack->pc;
189 return dummy_frame_stack->pc;
194 for (; fi; fi = fi->next)
195 if (fi->fsr.regs[regnum] != 0)
196 return read_memory_integer (fi->fsr.regs[regnum], 4);
197 return read_register (regnum);
200 /* Given a GDB frame, determine the address of the calling function's frame.
201 This will be used to create a new GDB frame struct, and then
202 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
203 For m32r, simply get the saved FP off the stack.
207 m32r_frame_chain (fi)
208 struct frame_info *fi;
210 CORE_ADDR saved_fp = fi->fsr.regs[FP_REGNUM];
213 return 0; /* frameless assembly language fn (such as _start) */
215 return read_memory_integer (saved_fp, 4);
218 /* All we do here is record SP and FP on the call dummy stack */
221 m32r_push_dummy_frame ()
223 struct dummy_frame *dummy_frame;
225 dummy_frame = xmalloc (sizeof (struct dummy_frame));
227 dummy_frame->fp = read_register (FP_REGNUM);
228 dummy_frame->sp = read_register (SP_REGNUM);
229 dummy_frame->rp = read_register (RP_REGNUM);
230 dummy_frame->pc = read_register (PC_REGNUM);
231 dummy_frame->next = dummy_frame_stack;
232 dummy_frame_stack = dummy_frame;
236 * MISSING FUNCTION HEADER COMMENT
240 m32r_pc_in_call_dummy (pc)
243 return dummy_frame_stack
244 && pc >= CALL_DUMMY_ADDRESS ()
245 && pc <= CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK;
248 /* Discard from the stack the innermost frame,
249 restoring all saved registers. */
252 m32r_pop_frame (frame)
253 struct frame_info *frame;
258 if (PC_IN_CALL_DUMMY (frame->pc, NULL, NULL))
260 struct dummy_frame *dummy_frame;
262 dummy_frame = dummy_frame_stack;
264 error ("Can't pop dummy frame!");
266 dummy_frame_stack = dummy_frame->next;
268 write_register (FP_REGNUM, dummy_frame->fp);
269 write_register (SP_REGNUM, dummy_frame->sp);
270 write_register (RP_REGNUM, dummy_frame->rp);
271 write_register (PC_REGNUM, dummy_frame->pc);
275 flush_cached_frames ();
281 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
283 for (regnum = 0; regnum < NUM_REGS; regnum++)
284 if (frame->fsr.regs[regnum] != 0)
285 write_register (regnum,
286 read_memory_integer (frame->fsr.regs[regnum], 4));
288 write_register (SP_REGNUM, read_register (FP_REGNUM));
289 if (read_register (PSW_REGNUM) & 0x80)
290 write_register (SPU_REGNUM, read_register (SP_REGNUM));
292 write_register (SPI_REGNUM, read_register (SP_REGNUM));
293 /* registers_changed (); */
294 flush_cached_frames ();
299 /* Put arguments in the right places, and setup return address register (RP) to
300 point at a convenient place to put a breakpoint. First four args go in
301 R6->R9, subsequent args go into sp + 16 -> sp + ... Structs are passed by
302 reference. 64 bit quantities (doubles and long longs) may be split between
303 the regs and the stack. When calling a function that returns a struct, a
304 pointer to the struct is passed in as a secret first argument (always in R6).
306 By the time we get here, stack space has been allocated for the args, but
307 not for the struct return pointer. */
310 m32r_push_arguments (nargs, args, sp, struct_return, struct_addr)
314 unsigned char struct_return;
315 CORE_ADDR struct_addr;
320 argreg = ARG0_REGNUM;
325 write_register (argreg++, struct_addr);
329 for (argnum = 0; argnum < nargs; argnum++)
335 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
336 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
338 store_address (valbuf, 4, VALUE_ADDRESS (*args));
344 len = TYPE_LENGTH (VALUE_TYPE (*args));
345 val = (char *)VALUE_CONTENTS (*args);
349 if (argreg <= ARGLAST_REGNUM)
353 regval = extract_address (val, REGISTER_RAW_SIZE (argreg));
354 write_register (argreg, regval);
356 len -= REGISTER_RAW_SIZE (argreg);
357 val += REGISTER_RAW_SIZE (argreg);
362 write_memory (sp + argnum * 4, val, 4);
370 write_register (RP_REGNUM, entry_point_address ());
377 _initialize_m32r_tdep ()
379 tm_print_insn = print_insn_m32r;