public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sandra Loosemore <sandra@codesourcery.com>
To: <gdb-patches@sourceware.org>, Yao Qi <qiyaoltc@gmail.com>
Subject: [patch v2 3/5, nios2] fix register save offset for signal handler trampolines
Date: Thu, 30 Apr 2015 09:03:00 -0000	[thread overview]
Message-ID: <55417801.5070507@codesourcery.com> (raw)
In-Reply-To: <554172F8.2020108@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 297 bytes --]

It was requested that I split the patch previously posted here:

https://sourceware.org/ml/gdb-patches/2015-04/msg00907.html

into two parts.  This is the first part.  I also expanded the comments 
to indicate how the register save offset magic number was calculated.

OK to commit now?

-Sandra


[-- Attachment #2: gdb-sigtramp-offset.log --]
[-- Type: text/x-log, Size: 244 bytes --]

2015-04-29  Sandra Loosemore  <sandra@codesourcery.com>

	gdb/
	* nios2-linux-tdep.c (NIOS2_SIGRETURN_TRAMP_ADDR): Define.
	(NIOS2_SIGRETURN_REGSAVE_OFFSET): Define.
	(nios2_linux_rt_sigreturn_init): Adjust base address of
	register save area.

[-- Attachment #3: gdb-sigtramp-offset.patch --]
[-- Type: text/x-patch, Size: 1743 bytes --]

diff --git a/gdb/nios2-linux-tdep.c b/gdb/nios2-linux-tdep.c
index b829569..0a837b0 100644
--- a/gdb/nios2-linux-tdep.c
+++ b/gdb/nios2-linux-tdep.c
@@ -114,7 +114,25 @@ nios2_iterate_over_regset_sections (struct gdbarch *gdbarch,
 }
 
 /* Initialize a trad-frame cache corresponding to the tramp-frame.
-   FUNC is the address of the instruction TRAMP[0] in memory.  */
+   FUNC is the address of the instruction TRAMP[0] in memory.
+
+   This ABI is not documented.  It corresponds to rt_setup_ucontext in
+   the kernel arch/nios2/kernel/signal.c file.
+
+   The key points are:
+   - The kernel creates a trampoline at the hard-wired address 0x1044.
+   - The stack pointer points to an object of type struct rt_sigframe.
+     The definition of this structure is not exported from the kernel.
+     The register save area is located at offset 152 bytes (as determined
+     by inspection of the stack contents in the debugger), and the
+     registers are saved as r1-r23, ra, fp, gp, ea, sp.
+
+   This interface was implemented with kernel version 3.19 (the first
+   official mainline kernel).  Older unofficial kernel versions used
+   incompatible conventions; we do not support those here.  */
+
+#define NIOS2_SIGRETURN_TRAMP_ADDR 0x1044
+#define NIOS2_SIGRETURN_REGSAVE_OFFSET 152
 
 static void
 nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
@@ -122,7 +140,8 @@ nios2_linux_rt_sigreturn_init (const struct tramp_frame *self,
 			       struct trad_frame_cache *this_cache,
 			       CORE_ADDR func)
 {
-  CORE_ADDR base = func + 41 * 4;
+  CORE_ADDR sp = get_frame_register_unsigned (next_frame, NIOS2_SP_REGNUM);
+  CORE_ADDR base = sp + NIOS2_SIGRETURN_REGSAVE_OFFSET;
   int i;
 
   for (i = 0; i < 23; i++)

  parent reply	other threads:[~2015-04-30  0:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30  0:33 [patch v2 0/5, nios2] unbreak nios2-linux-gnu GDB Sandra Loosemore
2015-04-30  0:36 ` [patch v2 1/5, nios2] revert to using "trap 31" for breakpoints Sandra Loosemore
2015-05-08  9:21   ` Yao Qi
2015-04-30  0:39 ` [patch v2 2/5, nios2] use PTRACE_GETREGSET/SETREGSET in gdbserver Sandra Loosemore
2015-05-08  9:23   ` Yao Qi
2015-04-30  9:03 ` Sandra Loosemore [this message]
2015-05-08  9:31   ` [patch v2 3/5, nios2] fix register save offset for signal handler trampolines Yao Qi
2015-04-30  9:08 ` [patch v2 4/5, nios2] work around issues with unwritable signal handler trampoline code Sandra Loosemore
2015-05-08 11:08   ` Yao Qi
2015-04-30 12:05 ` [patch v2 5/5, nios2] add NEWS entry for ABI change Sandra Loosemore

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=55417801.5070507@codesourcery.com \
    --to=sandra@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@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).