From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28677 invoked by alias); 25 Jun 2014 16:49:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 28408 invoked by uid 89); 25 Jun 2014 16:49:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: e06smtp13.uk.ibm.com Received: from e06smtp13.uk.ibm.com (HELO e06smtp13.uk.ibm.com) (195.75.94.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 25 Jun 2014 16:49:21 +0000 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Jun 2014 17:49:17 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 25 Jun 2014 17:49:15 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id A366F17D8056 for ; Wed, 25 Jun 2014 17:50:42 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5PGnEic32899300 for ; Wed, 25 Jun 2014 16:49:14 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5PGnEig024990 for ; Wed, 25 Jun 2014 10:49:14 -0600 Received: from br87z6lw.boeblingen.de.ibm.com (dyn-9-152-212-196.boeblingen.de.ibm.com [9.152.212.196]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5PGn9Gx024835 for ; Wed, 25 Jun 2014 10:49:14 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH v2 08/13] M32R Linux: Fill 'collect_regset' in regset structure. Date: Wed, 25 Jun 2014 16:49:00 -0000 Message-Id: <1403714949-28133-9-git-send-email-arnez@linux.vnet.ibm.com> In-Reply-To: <1403714949-28133-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1403714949-28133-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14062516-2966-0000-0000-000000505611 X-IsSubscribed: yes X-SW-Source: 2014-06/txt/msg00893.txt.bz2 gdb/ * m32r-linux-tdep.c (M32R_LINUX_GREGS_SIZE): New macro. (m32r_linux_supply_gregset): Make platform-independent and don't write to read-only input buffer. (m32r_linux_collect_gregset): New function. (m32r_linux_gregset): Add collect method. --- gdb/m32r-linux-tdep.c | 81 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/gdb/m32r-linux-tdep.c b/gdb/m32r-linux-tdep.c index bf1ffff..5eaca6e 100644 --- a/gdb/m32r-linux-tdep.c +++ b/gdb/m32r-linux-tdep.c @@ -346,19 +346,26 @@ static int m32r_pt_regs_offset[] = { #define SPU_OFFSET (4 * 23) #define SPI_OFFSET (4 * 26) +#define M32R_LINUX_GREGS_SIZE (4 * 27) + static void m32r_linux_supply_gregset (const struct regset *regset, struct regcache *regcache, int regnum, const void *gregs, size_t size) { - const char *regs = gregs; - unsigned long psw, bbpsw; + const gdb_byte *regs = gregs; + enum bfd_endian byte_order = + gdbarch_byte_order (get_regcache_arch (regcache)); + ULONGEST psw, bbpsw; + gdb_byte buf[4]; + const gdb_byte *p; int i; - psw = *((unsigned long *) (regs + PSW_OFFSET)); - bbpsw = *((unsigned long *) (regs + BBPSW_OFFSET)); + psw = extract_unsigned_integer (regs + PSW_OFFSET, 4, byte_order); + bbpsw = extract_unsigned_integer (regs + BBPSW_OFFSET, 4, byte_order); + psw = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8); - for (i = 0; i < sizeof (m32r_pt_regs_offset) / 4; i++) + for (i = 0; i < ARRAY_SIZE (m32r_pt_regs_offset); i++) { if (regnum != -1 && regnum != i) continue; @@ -366,30 +373,68 @@ m32r_linux_supply_gregset (const struct regset *regset, switch (i) { case PSW_REGNUM: - *((unsigned long *) (regs + m32r_pt_regs_offset[i])) = - ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8); + store_unsigned_integer (buf, 4, byte_order, psw); + p = buf; break; case CBR_REGNUM: - *((unsigned long *) (regs + m32r_pt_regs_offset[i])) = - ((psw >> 8) & 1); + store_unsigned_integer (buf, 4, byte_order, psw & 1); + p = buf; break; case M32R_SP_REGNUM: - if (psw & 0x8000) - *((unsigned long *) (regs + m32r_pt_regs_offset[i])) = - *((unsigned long *) (regs + SPU_OFFSET)); - else - *((unsigned long *) (regs + m32r_pt_regs_offset[i])) = - *((unsigned long *) (regs + SPI_OFFSET)); + p = regs + ((psw & 0x80) ? SPU_OFFSET : SPI_OFFSET); break; + default: + p = regs + m32r_pt_regs_offset[i]; } - regcache_raw_supply (regcache, i, - regs + m32r_pt_regs_offset[i]); + regcache_raw_supply (regcache, i, p); + } +} + +static void +m32r_linux_collect_gregset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *gregs, size_t size) +{ + gdb_byte *regs = gregs; + int i; + enum bfd_endian byte_order = + gdbarch_byte_order (get_regcache_arch (regcache)); + ULONGEST psw; + gdb_byte buf[4]; + + regcache_raw_collect (regcache, PSW_REGNUM, buf); + psw = extract_unsigned_integer (buf, 4, byte_order); + + for (i = 0; i < ARRAY_SIZE (m32r_pt_regs_offset); i++) + { + if (regnum != -1 && regnum != i) + continue; + + switch (i) + { + case PSW_REGNUM: + store_unsigned_integer (regs + PSW_OFFSET, 4, byte_order, + (psw & 0xc1) << 8); + store_unsigned_integer (regs + BBPSW_OFFSET, 4, byte_order, + (psw >> 8) & 0xc1); + break; + case CBR_REGNUM: + break; + case M32R_SP_REGNUM: + regcache_raw_collect (regcache, i, regs + + ((psw & 0x80) ? SPU_OFFSET : SPI_OFFSET)); + break; + default: + regcache_raw_collect (regcache, i, + regs + m32r_pt_regs_offset[i]); + } } } static const struct regset m32r_linux_gregset = { - NULL, m32r_linux_supply_gregset + NULL, + m32r_linux_supply_gregset, m32r_linux_collect_gregset }; static const struct regset * -- 1.8.4.2