From patchwork Thu Jul 31 11:04:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 2254 Received: (qmail 26514 invoked by alias); 31 Jul 2014 11:05: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 26166 invoked by uid 89); 31 Jul 2014 11:05:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp10.uk.ibm.com Received: from e06smtp10.uk.ibm.com (HELO e06smtp10.uk.ibm.com) (195.75.94.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 31 Jul 2014 11:05:00 +0000 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 31 Jul 2014 12:04:57 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 31 Jul 2014 12:04:55 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id E2D1D2190041 for ; Thu, 31 Jul 2014 12:04:38 +0100 (BST) Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s6VB4sBl32243892 for ; Thu, 31 Jul 2014 11:04:54 GMT Received: from d06av01.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s6VB4sQt016512 for ; Thu, 31 Jul 2014 05:04:54 -0600 Received: from br87z6lw.boeblingen.de.ibm.com (dyn-9-152-212-196.boeblingen.de.ibm.com [9.152.212.196]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s6VB4kJw016128; Thu, 31 Jul 2014 05:04:53 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Qinwei Subject: [PATCH v3 10/13] SCORE: Fill 'collect_regset' in regset structure. Date: Thu, 31 Jul 2014 13:04:43 +0200 Message-Id: <1406804686-9437-11-git-send-email-arnez@linux.vnet.ibm.com> In-Reply-To: <1406804686-9437-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1406804686-9437-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14073111-4966-0000-0000-000000E4F783 X-IsSubscribed: yes Also rewrite the 'supply_regset' method, making it platform independent. To avoid code duplication, move the logic for both to a register map in regcache_map_entry format. gdb/ * score-tdep.c (score7_linux_supply_gregset): Reduce to small stub that calls regcache_supply_regset and handles the EPC register separately. Move main logic to... (score7_linux_gregmap): ... this new register map. (SCORE7_LINUX_SIZEOF_GREGSET, SCORE7_LINUX_EPC_OFFSET): New macros. (score7_linux_gregset): Refer to register map. Add collect method. (score7_linux_regset_from_core_section): Replace sizeof elf_gregset_t by SCORE7_LINUX_SIZEOF_GREGSET. * score-tdep.h (enum gdb_regnum): New enum value SCORE_EPC_REGNUM. (struct regset): Delete unused forward declaraction. (struct pt_regs): Delete structure definition. (elf_gregset_t): Delete typedef. --- gdb/score-tdep.c | 86 ++++++++++++++++++++++++++------------------------------ gdb/score-tdep.h | 34 +--------------------- 2 files changed, 41 insertions(+), 79 deletions(-) diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c index c224189..77b8a8c 100644 --- a/gdb/score-tdep.c +++ b/gdb/score-tdep.c @@ -1398,59 +1398,52 @@ score_prologue_frame_base_sniffer (struct frame_info *this_frame) return &score_prologue_frame_base; } -/* Core file support (dirty hack) - - The core file MUST be generated by GNU/Linux on S+core. */ +/* Core file support. */ + +static const struct regcache_map_entry score7_linux_gregmap[] = + { + /* FIXME: According to the current Linux kernel, r0 is preceded by + 9 rather than 7 words. */ + { 7, REGCACHE_MAP_SKIP, 4 }, + { 32, 0, 4 }, /* r0 ... r31 */ + { 1, 55, 4 }, /* CEL */ + { 1, 54, 4 }, /* CEH */ + { 1, 53, 4 }, /* sr0, i.e. cnt or COUNTER */ + { 1, 52, 4 }, /* sr1, i.e. lcr or LDCR */ + { 1, 51, 4 }, /* sr2, i.e. scr or STCR */ + { 1, 49, 4 }, /* PC (same slot as EPC) */ + { 1, 38, 4 }, /* EMA */ + { 1, 32, 4 }, /* PSR */ + { 1, 34, 4 }, /* ECR */ + { 1, 33, 4 }, /* COND */ + { 0 } + }; + +#define SCORE7_LINUX_EPC_OFFSET (44 * 4) +#define SCORE7_LINUX_SIZEOF_GREGSET (49 * 4) static void score7_linux_supply_gregset(const struct regset *regset, - struct regcache *regcache, - int regnum, const void *gregs_buf, size_t len) + struct regcache *regcache, + int regnum, const void *buf, + size_t size) { - int regno; - elf_gregset_t *gregs; - - gdb_assert (regset != NULL); - gdb_assert ((regcache != NULL) && (gregs_buf != NULL)); - - gregs = (elf_gregset_t *) gregs_buf; - - for (regno = 0; regno < 32; regno++) - if (regnum == -1 || regnum == regno) - regcache_raw_supply (regcache, regno, gregs->regs + regno); - - { - struct sreg { - int regnum; - void *buf; - } sregs [] = { - { 55, &(gregs->cel) }, /* CEL */ - { 54, &(gregs->ceh) }, /* CEH */ - { 53, &(gregs->sr0) }, /* sr0, i.e. cnt or COUNTER */ - { 52, &(gregs->sr1) }, /* sr1, i.e. lcr or LDCR */ - { 51, &(gregs->sr1) }, /* sr2, i.e. scr or STCR */ - - /* Exception occured at this address, exactly the PC we want */ - { 49, &(gregs->cp0_epc) }, /* PC */ - - { 38, &(gregs->cp0_ema) }, /* EMA */ - { 37, &(gregs->cp0_epc) }, /* EPC */ - { 34, &(gregs->cp0_ecr) }, /* ECR */ - { 33, &(gregs->cp0_condition) }, /* COND */ - { 32, &(gregs->cp0_psr) }, /* PSR */ - }; - - for (regno = 0; regno < sizeof(sregs)/sizeof(sregs[0]); regno++) - if (regnum == -1 || regnum == sregs[regno].regnum) - regcache_raw_supply (regcache, - sregs[regno].regnum, sregs[regno].buf); - } + regcache_supply_regset (regset, regcache, regnum, buf, size); + + /* Supply the EPC from the same slot as the PC. Note that the + collect function will store the PC in that slot. */ + if ((regnum == -1 || regnum == SCORE_EPC_REGNUM) + && size >= SCORE7_LINUX_EPC_OFFSET + 4) + regcache_raw_supply (regcache, SCORE_EPC_REGNUM, + (const gdb_byte *) buf + + SCORE7_LINUX_EPC_OFFSET); } static const struct regset score7_linux_gregset = { - NULL, - score7_linux_supply_gregset, NULL + score7_linux_gregmap, + score7_linux_supply_gregset, + regcache_collect_regset }; /* Return the appropriate register set from the core section identified @@ -1463,7 +1456,8 @@ score7_linux_regset_from_core_section(struct gdbarch *gdbarch, gdb_assert (gdbarch != NULL); gdb_assert (sect_name != NULL); - if (strcmp(sect_name, ".reg") == 0 && sect_size == sizeof(elf_gregset_t)) + if (strcmp(sect_name, ".reg") == 0 + && sect_size == SCORE7_LINUX_SIZEOF_GREGSET) return &score7_linux_gregset; return NULL; diff --git a/gdb/score-tdep.h b/gdb/score-tdep.h index 02a334e..cef0e6a 100644 --- a/gdb/score-tdep.h +++ b/gdb/score-tdep.h @@ -32,6 +32,7 @@ enum gdb_regnum SCORE_RA_REGNUM = 3, SCORE_A0_REGNUM = 4, SCORE_AL_REGNUM = 7, + SCORE_EPC_REGNUM = 37, SCORE_PC_REGNUM = 49, }; @@ -46,37 +47,4 @@ enum gdb_regnum #define SCORE_INSTLEN 4 #define SCORE16_INSTLEN 2 -/* Forward declarations. */ -struct regset; - -/* Linux Core file support (dirty hack) - - S+core Linux register set definition, copy from S+core Linux. */ -struct pt_regs { - /* Pad bytes for argument save space on the stack. */ - unsigned long pad0[6]; /* may be 4, MIPS accept 6var, SCore - accepts 4 Var--yuchen */ - - /* Saved main processor registers. */ - unsigned long orig_r4; - unsigned long regs[32]; - - /* Other saved registers. */ - unsigned long cel; - unsigned long ceh; - - unsigned long sr0; /*cnt*/ - unsigned long sr1; /*lcr*/ - unsigned long sr2; /*scr*/ - - /* saved cp0 registers */ - unsigned long cp0_epc; - unsigned long cp0_ema; - unsigned long cp0_psr; - unsigned long cp0_ecr; - unsigned long cp0_condition; -}; - -typedef struct pt_regs elf_gregset_t; - #endif /* SCORE_TDEP_H */