2002-05-14 Andrew Cagney * d10v-tdep.c: Include "sim-regno.h". (d10v_ts2_register_sim_regno): Add legacy_regiter_sim_regno check. (d10v_ts3_register_sim_regno): Ditto. * Makefile.in (sim_regno_h): Define. (remote-sim.o): Add $(sim_regno_h) to dependencies. (gdbarch.o): Ditto. * sim-regno.h: New file. * remote-sim.c: Include "sim-regno.h" and "gdb_assert.h". (legacy_register_sim_regno): New function. (one2one_register_sim_regno): New function. (gdbsim_fetch_register): Rewrite. (gdbsim_store_register): Only store a register when REGISTER_SIM_REGNO is valid. * gdbarch.sh: Include "sim-regno.h". (REGISTER_SIM_REGNO): Set default to legacy_register_sim_regno. * gdbarch.h, gdbarch.c: Regenerate. * arch-utils.h (default_register_sim_regno): Delete declaration. * arch-utils.c (default_register_sim_regno): Delete function. Index: arch-utils.c =================================================================== RCS file: /cvs/src/src/gdb/arch-utils.c,v retrieving revision 1.57 diff -u -r1.57 arch-utils.c --- arch-utils.c 12 May 2002 03:09:11 -0000 1.57 +++ arch-utils.c 14 May 2002 22:36:20 -0000 @@ -267,13 +267,6 @@ return 0; } -int -default_register_sim_regno (int num) -{ - return num; -} - - CORE_ADDR core_addr_identity (CORE_ADDR addr) { Index: arch-utils.h =================================================================== RCS file: /cvs/src/src/gdb/arch-utils.h,v retrieving revision 1.32 diff -u -r1.32 arch-utils.h --- arch-utils.h 12 May 2002 03:09:11 -0000 1.32 +++ arch-utils.h 14 May 2002 22:36:21 -0000 @@ -94,11 +94,6 @@ extern int (*target_architecture_hook) (const struct bfd_arch_info *); - -/* Default raw->sim register re-numbering - does nothing. */ - -extern int default_register_sim_regno (int reg_nr); - /* Identity function on a CORE_ADDR. Just returns its parameter. */ extern CORE_ADDR core_addr_identity (CORE_ADDR addr); Index: d10v-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/d10v-tdep.c,v retrieving revision 1.39 diff -u -r1.39 d10v-tdep.c --- d10v-tdep.c 13 May 2002 14:00:35 -0000 1.39 +++ d10v-tdep.c 14 May 2002 22:36:22 -0000 @@ -41,6 +41,7 @@ #include "floatformat.h" #include "sim-d10v.h" +#include "sim-regno.h" struct frame_extra_info { @@ -284,6 +285,8 @@ static int d10v_ts2_register_sim_regno (int nr) { + if (legacy_register_sim_regno (nr) < 0) + return legacy_register_sim_regno (nr); if (nr >= TS2_IMAP0_REGNUM && nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS) return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM; @@ -298,6 +301,8 @@ static int d10v_ts3_register_sim_regno (int nr) { + if (legacy_register_sim_regno (nr) < 0) + return legacy_register_sim_regno (nr); if (nr >= TS3_IMAP0_REGNUM && nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS) return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM; Index: gdbarch.c =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.c,v retrieving revision 1.127 diff -u -r1.127 gdbarch.c --- gdbarch.c 13 May 2002 17:20:57 -0000 1.127 +++ gdbarch.c 14 May 2002 22:36:24 -0000 @@ -39,6 +39,7 @@ #if GDB_MULTI_ARCH #include "gdbcmd.h" #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */ +#include "sim-regno.h" /* For legacy_register_sim_regno(). */ #else /* Just include everything in sight so that the every old definition of macro is visible. */ @@ -488,7 +489,7 @@ current_gdbarch->max_register_virtual_size = -1; current_gdbarch->do_registers_info = do_registers_info; current_gdbarch->print_float_info = default_print_float_info; - current_gdbarch->register_sim_regno = default_register_sim_regno; + current_gdbarch->register_sim_regno = legacy_register_sim_regno; current_gdbarch->cannot_fetch_register = cannot_register_not; current_gdbarch->cannot_store_register = cannot_register_not; current_gdbarch->use_generic_dummy_frames = -1; Index: gdbarch.h =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.h,v retrieving revision 1.95 diff -u -r1.95 gdbarch.h --- gdbarch.h 13 May 2002 17:20:58 -0000 1.95 +++ gdbarch.h 14 May 2002 22:36:25 -0000 @@ -40,6 +40,7 @@ /* Pull in function declarations refered to, indirectly, via macros. */ #include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */ #include "inferior.h" /* For unsigned_address_to_pointer(). */ +#include "sim-regno.h" /* For legacy_register_sim_regno(). */ #endif struct frame_info; @@ -811,7 +812,7 @@ /* Default (function) for non- multi-arch platforms. */ #if (!GDB_MULTI_ARCH) && !defined (REGISTER_SIM_REGNO) -#define REGISTER_SIM_REGNO(reg_nr) (default_register_sim_regno (reg_nr)) +#define REGISTER_SIM_REGNO(reg_nr) (legacy_register_sim_regno (reg_nr)) #endif typedef int (gdbarch_register_sim_regno_ftype) (int reg_nr); Index: gdbarch.sh =================================================================== RCS file: /cvs/src/src/gdb/gdbarch.sh,v retrieving revision 1.138 diff -u -r1.138 gdbarch.sh --- gdbarch.sh 13 May 2002 17:20:58 -0000 1.138 +++ gdbarch.sh 14 May 2002 22:36:27 -0000 @@ -471,7 +471,7 @@ f:2:PRINT_FLOAT_INFO:void:print_float_info:void::::default_print_float_info::0 # MAP a GDB RAW register number onto a simulator register number. See # also include/...-sim.h. -f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::default_register_sim_regno::0 +f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::legacy_register_sim_regno::0 F:2:REGISTER_BYTES_OK:int:register_bytes_ok:long nr_bytes:nr_bytes::0:0 f:2:CANNOT_FETCH_REGISTER:int:cannot_fetch_register:int regnum:regnum:::cannot_register_not::0 f:2:CANNOT_STORE_REGISTER:int:cannot_store_register:int regnum:regnum:::cannot_register_not::0 @@ -759,6 +759,7 @@ /* Pull in function declarations refered to, indirectly, via macros. */ #include "value.h" /* For default_coerce_float_to_double which is referenced by a macro. */ #include "inferior.h" /* For unsigned_address_to_pointer(). */ +#include "sim-regno.h" /* For legacy_register_sim_regno(). */ #endif struct frame_info; @@ -1220,6 +1221,7 @@ #if GDB_MULTI_ARCH #include "gdbcmd.h" #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */ +#include "sim-regno.h" /* For legacy_register_sim_regno(). */ #else /* Just include everything in sight so that the every old definition of macro is visible. */ Index: remote-sim.c =================================================================== RCS file: /cvs/src/src/gdb/remote-sim.c,v retrieving revision 1.21 diff -u -r1.21 remote-sim.c --- remote-sim.c 20 Jan 2002 19:26:48 -0000 1.21 +++ remote-sim.c 14 May 2002 22:36:28 -0000 @@ -40,6 +40,8 @@ #include "remote-utils.h" #include "command.h" #include "regcache.h" +#include "gdb_assert.h" +#include "sim-regno.h" /* Prototypes */ @@ -276,46 +278,86 @@ } } +int +legacy_register_sim_regno (int regnum) +{ + /* Only makes sense to supply raw registers. */ + gdb_assert (regnum >= 0 && regnum < NUM_REGS); + /* NOTE: cagney/2002-05-13: The old code did it this way and it is + suspected that some GDB/SIM combinations may rely on this + behavour. The default should be one2one_register_sim_regno + (below). */ + if (REGISTER_NAME (regnum) != NULL + && REGISTER_NAME (regnum)[0] != '\0') + return regnum; + else + return LEGACY_SIM_REGNO_IGNORE; +} + +int +one2one_register_sim_regno (int regnum) +{ + /* Only makes sense to supply raw registers. */ + gdb_assert (regnum >= 0 && regnum < NUM_REGS); + if (regnum >= 0 && regnum < NUM_REGS) + return regnum; + else + return SIM_REGNO_UNAVAILABLE; +} + static void gdbsim_fetch_register (int regno) { - static int warn_user = 1; if (regno == -1) { for (regno = 0; regno < NUM_REGS; regno++) gdbsim_fetch_register (regno); + return; } - else if (REGISTER_NAME (regno) != NULL - && *REGISTER_NAME (regno) != '\0') + + switch (REGISTER_SIM_REGNO (regno)) { - char buf[MAX_REGISTER_RAW_SIZE]; - int nr_bytes; - if (REGISTER_SIM_REGNO (regno) >= 0) + case LEGACY_SIM_REGNO_IGNORE: + break; + case SIM_REGNO_UNAVAILABLE: + { + char *buf = alloca (MAX_REGISTER_RAW_SIZE); + int nr_bytes; + memset (buf, 0, MAX_REGISTER_RAW_SIZE); + supply_register (regno, buf); + set_register_cached (regno, -1); + break; + } + default: + { + static int warn_user = 1; + char *buf = alloca (MAX_REGISTER_RAW_SIZE); + int nr_bytes; + gdb_assert (regno >= 0 && regno < NUM_REGS); + memset (buf, 0, MAX_REGISTER_RAW_SIZE); nr_bytes = sim_fetch_register (gdbsim_desc, REGISTER_SIM_REGNO (regno), buf, REGISTER_RAW_SIZE (regno)); - else - nr_bytes = 0; - if (nr_bytes == 0) - /* register not applicable, supply zero's */ - memset (buf, 0, MAX_REGISTER_RAW_SIZE); - else if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno) - && warn_user) - { - fprintf_unfiltered (gdb_stderr, - "Size of register %s (%d/%d) incorrect (%d instead of %d))", - REGISTER_NAME (regno), - regno, REGISTER_SIM_REGNO (regno), - nr_bytes, REGISTER_RAW_SIZE (regno)); - warn_user = 0; - } - supply_register (regno, buf); - if (sr_get_debug ()) - { - printf_filtered ("gdbsim_fetch_register: %d", regno); - /* FIXME: We could print something more intelligible. */ - dump_mem (buf, REGISTER_RAW_SIZE (regno)); - } + if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno) && warn_user) + { + fprintf_unfiltered (gdb_stderr, + "Size of register %s (%d/%d) incorrect (%d instead of %d))", + REGISTER_NAME (regno), + regno, REGISTER_SIM_REGNO (regno), + nr_bytes, REGISTER_RAW_SIZE (regno)); + warn_user = 0; + } + /* Else if (nr_bytes < 0): an old simulator, that doesn't + think to return the register size. Just assume all is ok. */ + supply_register (regno, buf); + if (sr_get_debug ()) + { + printf_filtered ("gdbsim_fetch_register: %d", regno); + /* FIXME: We could print something more intelligible. */ + dump_mem (buf, REGISTER_RAW_SIZE (regno)); + } + break; + } } } @@ -327,10 +369,9 @@ { for (regno = 0; regno < NUM_REGS; regno++) gdbsim_store_register (regno); + return; } - else if (REGISTER_NAME (regno) != NULL - && *REGISTER_NAME (regno) != '\0' - && REGISTER_SIM_REGNO (regno) >= 0) + else if (REGISTER_SIM_REGNO (regno) >= 0) { char tmp[MAX_REGISTER_RAW_SIZE]; int nr_bytes; Index: sim-regno.h =================================================================== RCS file: sim-regno.h diff -N sim-regno.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sim-regno.h 14 May 2002 22:36:28 -0000 @@ -0,0 +1,50 @@ +/* Generic remote debugging interface for simulators. + + Copyright 2002 Free Software Foundation, Inc. + + Contributed by Red Hat, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef SIM_REGNO_H +#define SIM_REGNO_H + +/* The REGISTER_SIM_REGNO(REGNUM) method, when there is a + corresponding simulator register, returns that register number as a + cardinal. When there is no corresponding register, it returns a + negative value. */ + +enum { + /* Normal sane architecture. The corresponding register cache + entry is zero filled and the register is marked as unavailable. */ + SIM_REGNO_UNAVAILABLE = -1, + /* For possible backward compatibility. The register cache doesn't + have a corresponding name. Skip the register entirely. */ + LEGACY_SIM_REGNO_IGNORE = -2 +}; + +/* For compatibility with older architectures, returns + (LEGACY_SIM_REGNO_IGNORE) when a register doesn't have. */ + +extern int legacy_register_sim_regno (int regnum); + +/* Treat all raw registers as valid. */ + +extern int one2one_register_sim_regno (int regnum); + +#endif