From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26442 invoked by alias); 26 Jul 2002 22:32:21 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26432 invoked from network); 26 Jul 2002 22:32:18 -0000 Received: from unknown (HELO potter.sfbay.redhat.com) (205.180.83.107) by sources.redhat.com with SMTP; 26 Jul 2002 22:32:18 -0000 Received: from romulus.sfbay.redhat.com (IDENT:89MbQGkbMmVZBhHejPwEjkg+rw3S+bFm@romulus.sfbay.redhat.com [172.16.27.251]) by potter.sfbay.redhat.com (8.11.6/8.11.6) with ESMTP id g6QMWUQ06888 for ; Fri, 26 Jul 2002 15:32:30 -0700 Received: (from kev@localhost) by romulus.sfbay.redhat.com (8.11.6/8.11.6) id g6QMWDF18991 for gdb-patches@sources.redhat.com; Fri, 26 Jul 2002 15:32:13 -0700 Date: Fri, 26 Jul 2002 16:16:00 -0000 From: Kevin Buettner Message-Id: <1020726223213.ZM18990@localhost.localdomain> To: gdb-patches@sources.redhat.com Subject: [PATCH] rs6000: Eliminate FIRST_UISA_SP_REGNUM, LAST_UISA_SP_REGNUM MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-07/txt/msg00537.txt.bz2 I've just committed the patch below. (Iterating from FIRST_UISA_SP_REGNUM to LAST_UISA_SP_REGNUM doesn't really get you all of the special registers. E.g, in some cases, the MQ register will be missed.) * rs6000-nat.c (language.h): Include. (special_regs): Delete this array. (regmap): New function. (fetch_register, store_register): Use regmap() to map gdb register numbers to ptrace register numbers. Also, use outputs from regmap() to make decisions regarding type of ptrace() call to make. In particular, don't compare against FIRST_UISA_SP_REGNUM or LAST_UISA_SP_REGNUM. (fetch_inferior_registers, store_inferior_registers): Where possible, obtain register numbers from tdep struct. Don't refer to FIRST_UISA_SP_REGNUM or LAST_UISA_SP_REGNUM. * config/rs6000/tm-rs6000.h (FIRST_UISA_SP_REGNUM) (LAST_UISA_SP_REGNUM): Delete. Index: rs6000-nat.c =================================================================== RCS file: /cvs/src/src/gdb/rs6000-nat.c,v retrieving revision 1.25 diff -u -p -r1.25 rs6000-nat.c --- rs6000-nat.c 26 Jul 2002 00:43:30 -0000 1.25 +++ rs6000-nat.c 26 Jul 2002 22:11:37 -0000 @@ -32,6 +32,7 @@ #include "gdb-stabs.h" #include "regcache.h" #include "arch-utils.h" +#include "language.h" /* for local_hex_string(). */ #include "ppc-tdep.h" #include @@ -145,18 +146,41 @@ static void exec_one_dummy_insn (void); extern void fixup_breakpoints (CORE_ADDR low, CORE_ADDR high, CORE_ADDR delta); -/* Conversion from gdb-to-system special purpose register numbers. */ +/* Given REGNO, a gdb register number, return the corresponding + number suitable for use as a ptrace() parameter. Return -1 if + there's no suitable mapping. Also, set the int pointed to by + ISFLOAT to indicate whether REGNO is a floating point register. */ -static int special_regs[] = +static int +regmap (int regno, int *isfloat) { - IAR, /* PC_REGNUM */ - MSR, /* PS_REGNUM */ - CR, /* CR_REGNUM */ - LR, /* LR_REGNUM */ - CTR, /* CTR_REGNUM */ - XER, /* XER_REGNUM */ - MQ /* MQ_REGNUM */ -}; + struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + + *isfloat = 0; + if (tdep->ppc_gp0_regnum <= regno && regno <= tdep->ppc_gplast_regnum) + return regno; + else if (FP0_REGNUM <= regno && regno <= FPLAST_REGNUM) + { + *isfloat = 1; + return regno - FP0_REGNUM + FPR0; + } + else if (regno == PC_REGNUM) + return IAR; + else if (regno == tdep->ppc_ps_regnum) + return MSR; + else if (regno == tdep->ppc_cr_regnum) + return CR; + else if (regno == tdep->ppc_lr_regnum) + return LR; + else if (regno == tdep->ppc_ctr_regnum) + return CTR; + else if (regno == tdep->ppc_xer_regnum) + return XER; + else if (tdep->ppc_mq_regnum >= 0 && regno == tdep->ppc_mq_regnum) + return MQ; + else + return -1; +} /* Call ptrace(REQ, ID, ADDR, DATA, BUF). */ @@ -194,35 +218,30 @@ static void fetch_register (int regno) { int *addr = alloca (MAX_REGISTER_RAW_SIZE); - int nr; + int nr, isfloat; /* Retrieved values may be -1, so infer errors from errno. */ errno = 0; + nr = regmap (regno, &isfloat); + /* Floating-point registers. */ - if (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM) - { - nr = regno - FP0_REGNUM + FPR0; - rs6000_ptrace32 (PT_READ_FPR, PIDGET (inferior_ptid), addr, nr, 0); - } + if (isfloat) + rs6000_ptrace32 (PT_READ_FPR, PIDGET (inferior_ptid), addr, nr, 0); /* Bogus register number. */ - else if (regno > LAST_UISA_SP_REGNUM) + else if (nr < 0) { if (regno >= NUM_REGS) fprintf_unfiltered (gdb_stderr, "gdb error: register no %d not implemented.\n", regno); + return; } /* Fixed-point registers. */ else { - if (regno >= FIRST_UISA_SP_REGNUM) - nr = special_regs[regno - FIRST_UISA_SP_REGNUM]; - else - nr = regno; - if (!ARCH64 ()) *addr = rs6000_ptrace32 (PT_READ_GPR, PIDGET (inferior_ptid), (int *)nr, 0, 0); else @@ -256,7 +275,7 @@ static void store_register (int regno) { int *addr = alloca (MAX_REGISTER_RAW_SIZE); - int nr; + int nr, isfloat; /* Fetch the register's value from the register cache. */ regcache_collect (regno, addr); @@ -264,15 +283,14 @@ store_register (int regno) /* -1 can be a successful return value, so infer errors from errno. */ errno = 0; + nr = regmap (regno, &isfloat); + /* Floating-point registers. */ - if (regno >= FP0_REGNUM && regno <= FPLAST_REGNUM) - { - nr = regno - FP0_REGNUM + FPR0; - rs6000_ptrace32 (PT_WRITE_FPR, PIDGET (inferior_ptid), addr, nr, 0); - } + if (isfloat) + rs6000_ptrace32 (PT_WRITE_FPR, PIDGET (inferior_ptid), addr, nr, 0); /* Bogus register number. */ - else if (regno > LAST_UISA_SP_REGNUM) + else if (nr < 0) { if (regno >= NUM_REGS) fprintf_unfiltered (gdb_stderr, @@ -291,11 +309,6 @@ store_register (int regno) (%sp). */ exec_one_dummy_insn (); - if (regno >= FIRST_UISA_SP_REGNUM) - nr = special_regs[regno - FIRST_UISA_SP_REGNUM]; - else - nr = regno; - /* The PT_WRITE_GPR operation is rather odd. For 32-bit inferiors, the register's value is passed by value, but for 64-bit inferiors, the address of a buffer containing the value is passed. */ @@ -332,17 +345,29 @@ fetch_inferior_registers (int regno) else { - /* read 32 general purpose registers. */ - for (regno = 0; regno < 32; regno++) - fetch_register (regno); + struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); - /* read general purpose floating point registers. */ + /* Read 32 general purpose registers. */ + for (regno = tdep->ppc_gp0_regnum; + regno <= tdep->ppc_gplast_regnum; + regno++) + { + fetch_register (regno); + } + + /* Read general purpose floating point registers. */ for (regno = FP0_REGNUM; regno <= FPLAST_REGNUM; regno++) fetch_register (regno); - /* read special registers. */ - for (regno = FIRST_UISA_SP_REGNUM; regno <= LAST_UISA_SP_REGNUM; regno++) - fetch_register (regno); + /* Read special registers. */ + fetch_register (PC_REGNUM); + fetch_register (tdep->ppc_ps_regnum); + fetch_register (tdep->ppc_cr_regnum); + fetch_register (tdep->ppc_lr_regnum); + fetch_register (tdep->ppc_ctr_regnum); + fetch_register (tdep->ppc_xer_regnum); + if (tdep->ppc_mq_regnum >= 0) + fetch_register (tdep->ppc_mq_regnum); } } @@ -358,18 +383,29 @@ store_inferior_registers (int regno) else { - /* write general purpose registers first! */ - for (regno = GPR0; regno <= GPR31; regno++) - store_register (regno); + struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + + /* Write general purpose registers first. */ + for (regno = tdep->ppc_gp0_regnum; + regno <= tdep->ppc_gplast_regnum; + regno++) + { + store_register (regno); + } - /* write floating point registers now. */ + /* Write floating point registers. */ for (regno = FP0_REGNUM; regno <= FPLAST_REGNUM; regno++) store_register (regno); - /* write special registers. */ - - for (regno = FIRST_UISA_SP_REGNUM; regno <= LAST_UISA_SP_REGNUM; regno++) - store_register (regno); + /* Write special registers. */ + store_register (PC_REGNUM); + store_register (tdep->ppc_ps_regnum); + store_register (tdep->ppc_cr_regnum); + store_register (tdep->ppc_lr_regnum); + store_register (tdep->ppc_ctr_regnum); + store_register (tdep->ppc_xer_regnum); + if (tdep->ppc_mq_regnum >= 0) + store_register (tdep->ppc_mq_regnum); } } Index: config/rs6000/tm-rs6000.h =================================================================== RCS file: /cvs/src/src/gdb/config/rs6000/tm-rs6000.h,v retrieving revision 1.16 diff -u -p -r1.16 tm-rs6000.h --- config/rs6000/tm-rs6000.h 12 Apr 2002 19:48:37 -0000 1.16 +++ config/rs6000/tm-rs6000.h 26 Jul 2002 22:11:37 -0000 @@ -81,11 +81,6 @@ extern void aix_process_linenos (void); #define FP0_REGNUM 32 /* Floating point register 0 */ #define FPLAST_REGNUM 63 /* Last floating point register */ -/* These #defines are used to parse core files and talk to ptrace, so they - must remain fixed. */ -#define FIRST_UISA_SP_REGNUM 64 /* first special register number */ -#define LAST_UISA_SP_REGNUM 70 /* last special register number */ - /* Define other aspects of the stack frame. */ #define INIT_FRAME_PC_FIRST(fromleaf, prev) \