[PATCH/RFA] Allow register other than SP for DWARF2 CFA

Matt Thomas matt@3am-software.com
Tue Jun 18 11:09:00 GMT 2002

At 10:44 AM 6/18/2002, Richard Henderson wrote:
>On Tue, Jun 18, 2002 at 09:48:46AM -0700, Matt Thomas wrote:
> > The entry mask of a function (target of a CALLS/CALLG) instructs
> > the CPU what register's of the caller's to preserve.  The callee
> > can muck with them and their contents will be restored when the
> > function returns via the RET instruction.
>Ok, so it _is_ the callee that is controling the registers
>that are saved on entry to the function?  If so:
>The CFA should be considered to be just below the pushed arguments.
>I'm going to assume for the moment that the argument count is part
>of the CALLG pre-built argument list and so is not present on the
>stack in the CALLG case.  If I read Jason's diagram correctly, that
>means that CFA == AP in the CALLS case.
>Which means that we then have (for saveregmask of r11+r10+r5)
>   r11 save addr = CFA-4
>   r10 save addr = CFA-8
>   r5 save addr  = CFA-12
>   return addr   = CFA-16
>   fp save addr  = CFA-20
>   ap save addr  = CFA-24
>   FP            = CFA-28
>Correct so far?


>In which case, Jason's CFA_REGNUM change is neither necessary
>or needed.  The called function's FDE can be described with
>   if (dwarf2out_do_frame ())
>     {
>       const char *label = dwarf2out_cfi_label ();
>       int regno, offset = 0;
>       for (regno = FIRST_PSEUDO_REGISTER-1; regno >= 0; --regno)
>         if (regs_ever_live[regno] && !call_used_regs[regno])
>           dwarf2out_reg_save (label, regno, offset += 4);
>       dwarf2out_reg_save (label, PC_REGNUM, offset += 4);
>       dwarf2out_reg_save (label, FRAME_POINTER_REGNUM, offset += 4);
>       dwarf2out_reg_save (label, ARG_POINTER_REGNUM, offset += 4);
>       dwarf2out_def_cfa (label, FRAME_POINTER_REGNUM, offset += 4);
>     }
>This is going to generate an unnecessary DW_CFA_advance_loc4,
>but we don't currently have a way to avoid that.
> > The problem is that RET needs to adjust back up to top of the call
> > frame, but in the usual case of CALLS adjust the SP above the pushed
> > arguments and argument count.  Can you emit an opcode to adjust the
> > stack for a non-existant instruction?
> >
> > <emit dwarf2 to adjust sp down by 4>
> >          pushl $0
> > <emit dwarf2 to adjust sp down by 4>
> > <fake_ap = sp>
> >          calls $1,foo
> > <emit dwarf2 to adjust sp up by 8>
>This is exactly what DW_CFA_GNU_args_size does.
>In order for this to happen properly, the second argument of the
>CALL rtx should have the number of bytes of arguments *including*
>the count word added by the CALLS instruction.
>This is almost, but not quite, already done in the vax backend.  At
>present the extra count word is not included, and the case for >255
>arguments uses a 0.  Note that in the later case, you would still
>be using "calls $0", but you would be telling dwarf2out.c how much
>storage the subsequent manual stack adjustment would have removed.

Do we adjust this in the instruction pattern?  Or someplace else?

> > But to deal with the AP, I think that we need a fake dwarf2 register
> > to hold the new AP generated from calls/callg which can then be used
> > to set the AP after the old AP has been reg_save'd in the function
> > prologue.
>I don't understand this.  Based on the information I've been given
>so far, I'm pretty sure the code written above can be dropped into
>vax_output_function_prologue as-is.  Am I missing something?

Do we need to tell dwarf2 that the AP and FP have new values?

Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt/
Cupertino, CA             Disclaimer: I avow all knowledge of this message

More information about the Gcc-patches mailing list