From patchwork Thu Apr 30 00:32:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 6496 Received: (qmail 103848 invoked by alias); 30 Apr 2015 00:33:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 103834 invoked by uid 89); 30 Apr 2015 00:33:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 Apr 2015 00:33:06 +0000 Received: from svr-orw-fem-04.mgc.mentorg.com ([147.34.97.41]) by relay1.mentorg.com with esmtp id 1YncPX-0003W8-8Z from Sandra_Loosemore@mentor.com ; Wed, 29 Apr 2015 17:33:03 -0700 Received: from [IPv6:::1] (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.3.224.2; Wed, 29 Apr 2015 17:33:02 -0700 Message-ID: <55417801.5070507@codesourcery.com> Date: Wed, 29 Apr 2015 18:32:01 -0600 From: Sandra Loosemore User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: , Yao Qi Subject: [patch v2 3/5, nios2] fix register save offset for signal handler trampolines References: <554172F8.2020108@codesourcery.com> In-Reply-To: <554172F8.2020108@codesourcery.com> 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 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++)