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

Nelson Chu nelson.chu@sifive.com
Wed Jul 1 03:34:19 GMT 2020


Hi Jim and Andrew,

Thank you very much for your description and suggestions.

(Andrew)
> GDB does (currently) try to assign known register numbers to all of
> the "current" CSRs, but any of the now deprecated CSRs are not
> assigned known registers numbers.  GDB will only understand these
> registers if the remote target announces them in the XML file.
(Andrew)
> the only different is that mcountinhibit will
> be assigned a known register number inside GDB, while mucounteren will
> be assigned an unknown register number.

* My recent patch used to support the debug CSRs,
08ccfccf0ed825be9be2972594d4be4a2207ef13  RISC-V: Support debug and
float CSR as the unprivileged ones.

I think (current) gdb only adds the aliases (user_reg_add) for the CSR
which are defined by DECLARE_ALIAS and mentioned in the xml files.
And for now gdb will filter the DECLARE_CSR_ALIAS and only check that
the aborted version is newer than v1.11.  Other aliases will be
regarded as the unknown CSR.  Please feel free to let me know if I'm
wrong :)

Before my debug CSRs patch, only one alias CSR can be defined, that is dscratch.

After my debug CSRs patch, since dscratch is regarded as an
unprivileged CSR, it's aborted version is changed to
PRIV_SPEC_CLASS_NONE, and it couldn't be defined as an alias in gdb.
But it is an unknown CSR in gdb, and still can be used if the qemu's
xml file defines it.

So I try to improve it in this patch ([3/3]) and the first patch
[0/3].  Remove the priv spec version checking in the
riscv_create_csr_aliases.  The gdb will check all DECLARE_CSR_ALIAS,
and then add the aliases if they are mentioned in the xml files.  But
there are five CSRs that gdb don't want to add to aliases (aborted
version is older than v1.11),

* ubadaddr, sbadaddr, sptbr, mbadaddr and mucounteren.

Since I try to remove the priv spec version checking in the gdb, I use
another new macro DECLARE_CSR_REUSE rather than DECLARE_CSR_ALIAS to
define them.  Therefore, gdb will continue trying to define the
dscratch as an alias.  Besides, the following debug CSRs also have the
opportunity to be the aliases.

* mcontrol, icount, itrigger, etrigger, textra32, textra64

(Jim)
> FYI The gdb folks are planning to create a release branch next weekend
> I think, so now would be a bad time to accidentally break gdb.  But
> this patch looks OK.

Yes I'm also worried to break the gdb when it is being released...
The current behavior is that,

"There is no CSR that could be regarded as an alias, but it should be
fine.  Since what could have become the aliases, including dscratch
and some debug CSR (itrigger, ...), will be regarded as unknown CSRs
and can be used in gdb ''.

I plan to add the gdb changes (remove the priv spec checking) and the
binutils' DECLARE_CSR_REUSE changes into one patch, and resent it
recently.  But in case it might break the current gdb, I will commit
it after the gdb is released, even if it is approved and good to Jim
and Andrew.

(Andrew)
> Agree with the disassembler statements, from the GDB side there's the
> option of passing flag to the disassembler within GDB, so if we _did_
> have a flag to change the priv spec version, a GDB user could
> configure their disassembler to match.

Thanks for pointing this out, that's great!  We do have some RISC-V objdump
options, including the option used to choose the priv spec version.
Currently, "set disassembler-options" is only supported on targets ARM, MIPS,
PowerPC and S/390.  Therefore we can do the similar porting for RISC-V in the
future.  For now this may not be worth the trouble :)

* riscv64-unknown-elf-objdump --help

The following RISC-V-specific disassembler options are supported for use
with the -M switch (multiple options should be separated by commas):

  numeric         Print numeric register names, rather than ABI names.

  no-aliases      Disassemble only into canonical instructions, rather
                  than into pseudoinstructions.

  priv-spec=PRIV  Print the CSR according to the chosen privilege spec
                  (1.9, 1.9.1, 1.10, 1.11).


Thanks
Nelson


More information about the Binutils mailing list