Re: RFA: PowerPC sim & GDB: use fixed register numbering

Jim Blandy
2004-08-05T15:22:31Z

Andrew Cagney <cagney@gnu.org> writes:
> Close, I checked this in.
>
> Andrew
>
> 2004-08-04 Andrew Cagney <cagney@gnu.org>
> Jim Blandy <jimb@redhat.com>
>
> * sim_callbacks.h (simulator): Declare.
> * Makefile.in (gdb-sim.o): New rule.
> (MAIN_SRC, GDB_OBJ): Add gdb-sim.o, gdb-sim.c.
> (DEFS_H): Delete.
> (GDB_SIM_PPC_H): Define.
> * gdb-sim.c: New file.
> * sim_calls.c: Do not include "defs.h".
> (simulator): Drop static.
> (sim_store_register, sim_fetch_register): Delete.

Works for me. Thanks very much.

In light of the changes you asked for, I have a question about the
D10v simulator. It has code like this:

switch ((enum sim_d10v_regs) rn)
{
case SIM_D10V_R0_REGNUM:
case SIM_D10V_R1_REGNUM:
case SIM_D10V_R2_REGNUM:
case SIM_D10V_R3_REGNUM:
case SIM_D10V_R4_REGNUM:
case SIM_D10V_R5_REGNUM:
case SIM_D10V_R6_REGNUM:
case SIM_D10V_R7_REGNUM:
case SIM_D10V_R8_REGNUM:
case SIM_D10V_R9_REGNUM:
case SIM_D10V_R10_REGNUM:
case SIM_D10V_R11_REGNUM:
case SIM_D10V_R12_REGNUM:
case SIM_D10V_R13_REGNUM:
case SIM_D10V_R14_REGNUM:
case SIM_D10V_R15_REGNUM:
SET_GPR (rn - SIM_D10V_R0_REGNUM, READ_16 (memory));
size = 2;
break;

By doing arithmetic on the enum values, this code assumes that they're
listed contiguously in the enum, in the order given. Is this kosher?
Wouldn't it be preferable to have something like:

/* If REGNUM is a general-purpose register number, return the
gpr index (0 for R0, 7 for R7, ...). Otherwise, return -1. */
int
d10v_gpr_regnum (enum sim_d10v_regs regnum)
{
switch (regnum)
{
case SIM_D10V_R0_REGNUM: return 0;
case SIM_D10V_R1_REGNUM: return 1;
case SIM_D10V_R2_REGNUM: return 2;
case SIM_D10V_R3_REGNUM: return 3;
case SIM_D10V_R4_REGNUM: return 4;
case SIM_D10V_R5_REGNUM: return 5;
case SIM_D10V_R6_REGNUM: return 6;
case SIM_D10V_R7_REGNUM: return 7;
case SIM_D10V_R8_REGNUM: return 8;
case SIM_D10V_R9_REGNUM: return 9;
case SIM_D10V_R10_REGNUM: return 10;
case SIM_D10V_R11_REGNUM: return 11;
case SIM_D10V_R12_REGNUM: return 12;
case SIM_D10V_R13_REGNUM: return 13;
case SIM_D10V_R14_REGNUM: return 14;
case SIM_D10V_R15_REGNUM: return 15;

default:
return -1;
}
}

with corresponding functions for the other register banks, and then
write sim_store_register as a chain of 'if's?