sal = find_pc_line (prologue_start, 0);
if (sal.line == 0) /* no line info, use current PC */
- prologue_end = fi->pc;
+ if (prologue_start != entry_point_address ())
+ prologue_end = fi->pc;
+ else
+ return 0; /* _start has no frame or prologue */
else if (sal.end < prologue_end) /* next line begins after fn end */
prologue_end = sal.end; /* (probably means no prologue) */
}
else
- prologue_end = prologue_start + 100; /* We're in the boondocks */
+ prologue_end = prologue_start + 40; /* We're in the boondocks: allow for */
+ /* 16 pushes, an add, and "mv fp,sp" */
prologue_end = min (prologue_end, fi->pc);
rp (and other regs), adjust sp and such. */
framesize = 0;
- memset (fsr->regs, '\000', sizeof fsr->regs);
-
for (current_pc = prologue_start; current_pc < prologue_end; current_pc += 2)
{
int insn;
int regno;
insn = read_memory_unsigned_integer (current_pc, 2);
- if (insn & 0x80) /* Four byte instruction? */
+ if (insn & 0x8000) /* Four byte instruction? */
current_pc += 2;
if ((insn & 0xf0ff) == 0x207f) { /* st reg, @-sp */
framesize += 4;
regno = ((insn >> 8) & 0xf);
- fsr->regs[regno] = framesize;
+ if (fsr) /* save_regs offset */
+ fsr->regs[regno] = framesize;
}
- else if ((insn >> 8) == 0x4f) { /* addi sp */
- framesize += -((char) (insn & 0xff)); /* offset */
- break; /* end of stack adjustments */
+ else if ((insn >> 8) == 0x4f) /* addi sp, xx */
+ /* add 8 bit sign-extended offset */
+ framesize += -((char) (insn & 0xff));
+ else if (insn == 0x8faf) /* add3 sp, sp, xxxx */
+ /* add 16 bit sign-extended offset */
+ framesize += -((short) read_memory_unsigned_integer (current_pc, 2));
+ else if (((insn >> 8) == 0xe4) && /* ld24 r4, xxxxxx ; sub sp, r4 */
+ read_memory_unsigned_integer (current_pc + 2, 2) == 0x0f24)
+ { /* subtract 24 bit sign-extended negative-offset */
+ insn = read_memory_unsigned_integer (current_pc - 2, 4);
+ if (insn & 0x00800000) /* sign extend */
+ insn |= 0xff000000; /* negative */
+ else
+ insn &= 0x00ffffff; /* positive */
+ framesize += insn;
+ }
+ else if (insn == 0x1d8f) { /* mv fp, sp */
+ fi->using_frame_pointer = 1; /* fp is now valid */
+ break; /* end of stack adjustments */
}
+ else
+ break; /* anything else isn't prologue */
}
return framesize;
}
/* This function actually figures out the frame address for a given pc and
- sp. This is tricky on the v850 because we only use an explicit frame
- pointer when using alloca(). The only reliable way to get this info is to
+ sp. This is tricky on the m32r because we sometimes don't use an explicit
+ frame pointer, and the previous stack pointer isn't necessarily recorded
+ on the stack. The only reliable way to get this info is to
examine the prologue.
*/
struct frame_info *fi;
{
int reg;
- int framesize;
if (fi->next)
fi->pc = FRAME_SAVED_PC (fi->next);
- framesize = m32r_scan_prologue (fi, &fi->fsr);
-
+ memset (fi->fsr.regs, '\000', sizeof fi->fsr.regs);
+ fi->using_frame_pointer = 0;
+ fi->framesize = m32r_scan_prologue (fi, &fi->fsr);
+#if 0
if (PC_IN_CALL_DUMMY (fi->pc, NULL, NULL))
fi->frame = dummy_frame_stack->sp;
- else if (!fi->next)
- fi->frame = read_register (SP_REGNUM);
+ else
+#endif
+ if (!fi->next)
+ if (fi->using_frame_pointer)
+ fi->frame = read_register (FP_REGNUM);
+ else
+ fi->frame = read_register (SP_REGNUM);
+ else /* fi->next means this is not the innermost frame */
+ if (fi->using_frame_pointer) /* we have an FP */
+ if (fi->next->fsr.regs[FP_REGNUM] != 0) /* caller saved our FP */
+ fi->frame = read_memory_integer (fi->next->fsr.regs[FP_REGNUM], 4);
for (reg = 0; reg < NUM_REGS; reg++)
if (fi->fsr.regs[reg] != 0)
- fi->fsr.regs[reg] = fi->frame + framesize - fi->fsr.regs[reg];
+ fi->fsr.regs[reg] = fi->frame + fi->framesize - fi->fsr.regs[reg];
}
/* Find the caller of this frame. We do this by seeing if RP_REGNUM is saved
/* Given a GDB frame, determine the address of the calling function's frame.
This will be used to create a new GDB frame struct, and then
INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
- For m32r, simply get the saved FP off the stack.
+ For m32r, we save the frame size when we initialize the frame_info.
*/
CORE_ADDR
m32r_frame_chain (fi)
struct frame_info *fi;
{
- CORE_ADDR saved_fp = fi->fsr.regs[FP_REGNUM];
-
- if (saved_fp == 0)
- return 0; /* frameless assembly language fn (such as _start) */
+ CORE_ADDR fn_start;
- return read_memory_integer (saved_fp, 4);
+ if (find_pc_partial_function (fi->pc, 0, &fn_start, 0))
+ if (fn_start == entry_point_address ())
+ return 0; /* in _start fn, don't chain further */
+ return fi->frame + fi->framesize;
}
/* All we do here is record SP and FP on the call dummy stack */
m32r_pc_in_call_dummy (pc)
CORE_ADDR pc;
{
+#if 0
return dummy_frame_stack
&& pc >= CALL_DUMMY_ADDRESS ()
&& pc <= CALL_DUMMY_ADDRESS () + DECR_PC_AFTER_BREAK;
+#else
+ return 0;
+#endif
}
/* Discard from the stack the innermost frame,