[PATCH v2 3/3] RISC-V: Support new CSR macro DECLARE_CSR_REUSE to handle the reused CSR.

Jim Wilson jimw@sifive.com
Mon Jun 29 23:52:10 GMT 2020


On Wed, Jun 24, 2020 at 8:38 PM Nelson Chu <nelson.chu@sifive.com> wrote:
> * DECLARE_CSR_REUSE: The CSR address was defined.  The old CSR is aborted,
> but the CSR address is reused to define a new CSR with different semantic.
>
> There are five reused CSR defined currently,
> DECLARE_CSR_REUSE(ubadaddr, CSR_UTVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9P1, PRIV_SPEC_CLASS_1P10)
> DECLARE_CSR_REUSE(sbadaddr, CSR_STVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9P1, PRIV_SPEC_CLASS_1P10)
> DECLARE_CSR_REUSE(sptbr, CSR_SATP, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9P1, PRIV_SPEC_CLASS_1P10)
> DECLARE_CSR_REUSE(mbadaddr, CSR_MTVAL, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9P1, PRIV_SPEC_CLASS_1P10)
> DECLARE_CSR_REUSE(mucounteren, CSR_MCOUNTINHIBIT, CSR_CLASS_I, PRIV_SPEC_CLASS_1P9P1, PRIV_SPEC_CLASS_1P10)
>
> gdb only handle the CSR which are defined by DECLARE_CSR, and the aliases CSR
> which are defined by DECLARE_CSR_ALIAS.  Support the reused CSR in gdb is not
> good enough and may cause problems so far, so just skip the DECLARE_CSR_REUSE.

I think this breaks gdb/qemu interaction.  qemu will send an xml file
that mentions mucounteren, and gdb will error because it doesn't know
what the mucounteren register is anymore.  You have to update gdb to
handle DECLARE_CSR_REUSE same as DECLARE_CSR_ALIAS.  Once they are
handled the same, it isn't clear why we need both of them, unless you
plan to handle them differently in the future.

It doesn't really matter that we have two different registers with the
same address, as long as the gdb client doesn't submit an XML file
that tries to define both registers.  So a gdb client will send an xml
file that says that either mucounteren or mcountinhibit exists, and
gdb will map that to an address, and gdb doesn't have to know what the
registers do, or that these are two different registers. From a
binutils point of view, the only real problem is that disassembly will
be wrong if we print the wrong register name, but that would require
teaching the disassembler about priv spec versions which may not be
worth the trouble.

Jim


More information about the Binutils mailing list