From: Richard Henderson <rth@redhat.com>
To: "Petr Hluzín" <petr.hluzin@gmail.com>
Cc: Anitha Boyapati <anitha.boyapati@gmail.com>,
binutils@sourceware.org, gdb@sourceware.org,
GCC Patches <gcc-patches@gcc.gnu.org>,
chertykov@gmail.com, aesok@post.ru,
eric.weddington@atmel.com
Subject: Re: [avr] gas support for cfi info
Date: Wed, 16 Feb 2011 17:59:00 -0000 [thread overview]
Message-ID: <4D5C104D.7050707@redhat.com> (raw)
In-Reply-To: <AANLkTinco6ZrrBGYh3ipDzPmw8D3jt5_KjfJF1xvE4WM@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]
On 02/15/2011 02:44 PM, Petr HluzÃn wrote:
> In avr-tdep.c [1] near avr_dwarf_reg_to_regnum():
> /* Unfortunately dwarf2 register for SP is 32. */
Excellent. We're all on the same page for this.
> (I can't help you with the value for #define DWARF2_DEFAULT_RETURN_COLUMN 36)
> AFAIK there is no written ABI. Only the calling convention is
> documented (and only the easy cases), the rest is in gdb/gcc/binutils
> sources and people's heads.
As I recall, GCC defaults to using FIRST_PSEUDO_REGISTER for this,
so as to not overlap any hard registers. I'll continue to so the same.
> /* Avr-6 call instructions save 3 bytes. */
> switch (info.bfd_arch_info->mach)
Thanks. That value is readily available in the assembler as well.
Anitha pointed out to me via gcc pr17994 that AVR uses post-decrement
for its pushes. I had a brief read over the AVR insn manual, and it's
not crystal clear how multi-byte post-decrement pushes operate.
I've made an assumption that it happens as-if each byte is pushed
separately. I.e.
caller: callee:
save rN
save rM
trash <- SP hi(ret) <- CFA
lo(ret)
trash <- SP
This is the only way I can imagine that call insns interoperate with
byte push/pop insns.
All of which means that the return address is at a different offset
from the CFA than I originally thought. This ought to be fixed in
the following.
Can someone please test these two patches and see if they actually
agree with the hardware?
r~
[-- Attachment #2: z-gas --]
[-- Type: text/plain, Size: 1947 bytes --]
Index: config/tc-avr.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-avr.c,v
retrieving revision 1.74
diff -u -p -r1.74 tc-avr.c
--- config/tc-avr.c 28 Jun 2010 14:06:57 -0000 1.74
+++ config/tc-avr.c 16 Feb 2011 17:39:55 -0000
@@ -24,6 +24,8 @@
#include "as.h"
#include "safe-ctype.h"
#include "subsegs.h"
+#include "dw2gencfi.h"
+
struct avr_opcodes_s
{
@@ -1488,3 +1490,18 @@ avr_cons_fix_new (fragS *frag,
exp_mod_pm = 0;
}
}
+
+void
+tc_cfi_frame_initial_instructions (void)
+{
+ /* AVR6 pushes 3 bytes for calls. */
+ int return_size = (avr_mcu->mach == bfd_mach_avr6 ? 3 : 2);
+
+ /* The CFA is the caller's stack location before the call insn. */
+ /* Note that the stack pointer is dwarf register number 32. */
+ cfi_add_CFA_def_cfa (32, return_size);
+
+ /* Note that AVR consistently uses post-decrement, which means that things
+ do not line up the same way as for targers that use pre-decrement. */
+ cfi_add_CFA_offset (DWARF2_DEFAULT_RETURN_COLUMN, 1-return_size);
+}
Index: config/tc-avr.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-avr.h,v
retrieving revision 1.17
diff -u -p -r1.17 tc-avr.h
--- config/tc-avr.h 27 Oct 2009 15:39:27 -0000 1.17
+++ config/tc-avr.h 16 Feb 2011 17:39:55 -0000
@@ -153,3 +153,16 @@ extern long md_pcrel_from_section (struc
/* 32 bits pseudo-addresses are used on AVR. */
#define DWARF2_ADDR_SIZE(bfd) 4
+
+/* Enable cfi directives. */
+#define TARGET_USE_CFIPOP 1
+
+/* The stack grows down, and is only byte aligned. */
+#define DWARF2_CIE_DATA_ALIGNMENT -1
+
+/* Define the column that represents the PC. */
+#define DWARF2_DEFAULT_RETURN_COLUMN 36
+
+/* Define a hook to setup initial CFI state. */
+extern void tc_cfi_frame_initial_instructions (void);
+#define tc_cfi_frame_initial_instructions tc_cfi_frame_initial_instructions
[-- Attachment #3: z-gcc --]
[-- Type: text/plain, Size: 3012 bytes --]
diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h
index 4569359..06c9254 100644
--- a/gcc/config/avr/avr-protos.h
+++ b/gcc/config/avr/avr-protos.h
@@ -109,6 +109,7 @@ extern RTX_CODE avr_normalize_condition (RTX_CODE condition);
extern int compare_eq_p (rtx insn);
extern void out_shift_with_cnt (const char *templ, rtx insn,
rtx operands[], int *len, int t_len);
+extern rtx avr_incoming_return_addr_rtx (void);
#endif /* RTX_CODE */
#ifdef HAVE_MACHINE_MODES
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 30e4626..761eea3 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -534,6 +534,16 @@ get_sequence_length (rtx insns)
return length;
}
+/* Implement INCOMING_RETURN_ADDR_RTX. */
+
+rtx
+avr_incoming_return_addr_rtx (void)
+{
+ /* The return address is at the top of the stack. Note that the push
+ was via post-decrement, which means the actual address is off by one. */
+ return gen_frame_mem (HImode, plus_constant (stack_pointer_rtx, 1));
+}
+
/* Output function prologue. */
void
diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h
index 9a71078..385b4e6 100644
--- a/gcc/config/avr/avr.h
+++ b/gcc/config/avr/avr.h
@@ -809,6 +809,9 @@ mmcu=*:-mmcu=%*}"
#define OBJECT_FORMAT_ELF
+#define INCOMING_RETURN_ADDR_RTX avr_incoming_return_addr_rtx ()
+#define INCOMING_FRAME_SP_OFFSET (AVR_3_BYTE_PC ? 3 : 2)
+
#define HARD_REGNO_RENAME_OK(OLD_REG, NEW_REG) \
avr_hard_regno_rename_ok (OLD_REG, NEW_REG)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fea8209..b5e660c 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -2240,7 +2240,7 @@ dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
cfa.base_offset = -cfa_store.offset
Rule 11:
- (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
+ (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
effects: cfa_store.offset += -/+ mode_size(mem)
cfa.offset = cfa_store.offset if cfa.reg == sp
cfa.reg = sp
@@ -2259,7 +2259,7 @@ dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
cfa.base_offset = -{cfa_store,cfa_temp}.offset
Rule 14:
- (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
+ (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
effects: cfa.reg = <reg1>
cfa.base_offset = -cfa_temp.offset
cfa_temp.offset -= mode_size(mem)
@@ -2592,6 +2592,7 @@ dwarf2out_frame_debug_expr (rtx expr, const char *label)
/* Rule 11 */
case PRE_INC:
case PRE_DEC:
+ case POST_DEC:
offset = GET_MODE_SIZE (GET_MODE (dest));
if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
offset = -offset;
@@ -2616,7 +2617,10 @@ dwarf2out_frame_debug_expr (rtx expr, const char *label)
if (cfa.reg == STACK_POINTER_REGNUM)
cfa.offset = cfa_store.offset;
- offset = -cfa_store.offset;
+ if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
+ offset += -cfa_store.offset;
+ else
+ offset = -cfa_store.offset;
break;
/* Rule 12 */
next prev parent reply other threads:[~2011-02-16 17:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <AANLkTim6hyXysiV-025BDgNJ84qaqTnkRdHi+e7bF2gx@mail.gmail.com>
[not found] ` <AANLkTi=Rnu-wb2W8FejN=XQHmHuTq7rZovKuDdO-QLwi@mail.gmail.com>
[not found] ` <AANLkTimOXF1V__SSFs1gtqJh5nc183EdeHm5NoeU6YXs@mail.gmail.com>
[not found] ` <AANLkTike2osnZS=sUphuN_=oFQLCDUs54uuGCWL6cLVQ@mail.gmail.com>
2011-02-15 17:41 ` Testing Call frame information in .debug_frame section Richard Henderson
2011-02-15 18:02 ` Richard Henderson
2011-02-15 22:13 ` Petr Hluzín
2011-02-16 16:51 ` Richard Henderson
2011-02-15 18:09 ` Anitha Boyapati
2011-02-15 18:48 ` Richard Henderson
2011-02-15 19:15 ` Anitha Boyapati
2011-02-15 19:03 ` [avr] gas support for cfi info Richard Henderson
2011-02-15 22:45 ` Petr Hluzín
2011-02-16 17:59 ` Richard Henderson [this message]
2011-02-16 22:49 ` Petr Hluzín
2011-02-17 16:12 ` Richard Henderson
2011-02-17 16:16 ` Tristan Gingold
2011-02-17 15:35 ` Anitha Boyapati
2011-02-17 16:05 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D5C104D.7050707@redhat.com \
--to=rth@redhat.com \
--cc=aesok@post.ru \
--cc=anitha.boyapati@gmail.com \
--cc=binutils@sourceware.org \
--cc=chertykov@gmail.com \
--cc=eric.weddington@atmel.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb@sourceware.org \
--cc=petr.hluzin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).