Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target/riscv: hide_csrs configuration option #787

Merged
merged 3 commits into from
Feb 15, 2023

Conversation

aap-sc
Copy link
Collaborator

@aap-sc aap-sc commented Jan 10, 2023

This option allows users to mark certain CSRs as hidden so they could be expluded from reg output and target.xml

Change-Id: Iddf8456cd3901f572f8590329ebba5229974d24a

@aap-sc
Copy link
Collaborator Author

aap-sc commented Jan 10, 2023

I describe the motivation for this PR here: #785

Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright. Can you document this new command in doc/openocd.texi?

@@ -248,6 +248,10 @@ typedef struct {
* from range 0xc000 ... 0xffff. */
struct list_head expose_custom;

/* The list of registers to mark as "hidden". Hidden registers are available
* but do not appear in gdb targets description or reg command output. */
struct list_head hidden_csr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
struct list_head hidden_csr;
struct list_head hide_csr;

To keep naming consistent with expose_csr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

Comment on lines 3708 to 3709
.help = "Configure a list of inclusive ranges for CSRs to mark them as "
"hidden. Hidden registers are still available, but are not listed in "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.help = "Configure a list of inclusive ranges for CSRs to mark them as "
"hidden. Hidden registers are still available, but are not listed in "
.help = "Configure a list of inclusive ranges for CSRs to hide from gdb. "
"Hidden registers are still available, but are not listed in "

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, addressed

range_list_t *entry;
list_for_each_entry(entry, &info->hidden_csr, list)
if ((entry->low <= csr_number) && (csr_number <= entry->high)) {
LOG_DEBUG("Hiding CSR %d (name=%s)", csr_number, r->name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG_DEBUG("Hiding CSR %d (name=%s)", csr_number, r->name);
LOG_TARGET_DEBUG(target, "Hiding CSR %d (name=%s)", csr_number, r->name);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@TommyMurphyTM1234
Copy link
Collaborator

This option allows users to mark certain CSRs as hidden so they could be expluded from reg output and target.xml

Change-Id: Iddf8456cd3901f572f8590329ebba5229974d24a

If it's going to be added then why not generalise it to allow ANY register to be hidden - integer, floating point, CSR - using any of the canonical name, the assembler mnemonic name, the ABI name(s?), any other relevant names (e.g. CSR alias names, deprecated/demoted CSR names)?

@@ -3675,6 +3700,16 @@ static const struct command_registration riscv_exec_command_handlers[] = {
"expose. custom0 is accessed as abstract register number 0xc000, "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it have to be executed before init?
Might the GDB user want to do monitor ... to change the register list?

Will the commands work via the OpenOCD telnet interface?

See here for my comment about identifying registers by name:

Copy link
Collaborator Author

@aap-sc aap-sc Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it have to be executed before init?

Because list of available registers is built/initialized during target examination procedure.

Might the GDB user want to do monitor ... to change the register list?
Will the commands work via the OpenOCD telnet interface?

This won't work. There are a couple of reasons for that.

  1. As is - the command can be run during the configuration stage only. That is before gdbserver client can connect.
  2. AFAIK the remote target configuration is requested by gdb only once upon connection. Maybe there are ways to re-request it, but I'm not aware of them currently (+ see the next item).
  3. The way registers are initialized in OpenOCD complicates things. These are initialized during the examine procedure. And making OpenOCD to re-examine target may imply way too many changes.

@aap-sc
Copy link
Collaborator Author

aap-sc commented Jan 12, 2023

Regarding this one (from @TommyMurphyTM1234 ):

If it's going to be added then why not generalise it to allow ANY register to be hidden - integer, floating point, CSR - using any of the canonical name, the assembler mnemonic name, the ABI name(s?), any other relevant names (e.g. CSR alias names, deprecated/demoted CSR names)?

  1. Regarding other classes of registers like GPR, FPR and VPR. I'll investigate this, however GDB may have some special handling for these kinds of registers and this may require some additional testing. I'm fairly certain that the code works for CSR's since I experimented with it quite a lot - not so sure for others.

  2. Regarding aliases and canonical/ABI names... I don't believe we have canonical naming scheme present in the current codebase of OpenOCD and GDB. It was removed a couple of years ago from the respected codebases. As for aliases - I'll double check, but I don't believe we have any.

@aap-sc
Copy link
Collaborator Author

aap-sc commented Jan 12, 2023

@timsifive, regarding this one:

Can you document this new command in doc/openocd.texi?

Sure (I've completely forgotten about it).

@timsifive
Copy link
Collaborator

If it's going to be added then why not generalise it to allow ANY register to be hidden - integer, floating point, CSR - using any of the canonical name, the assembler mnemonic name, the ABI name(s?), any other relevant names (e.g. CSR alias names, deprecated/demoted CSR names)?

That sounds like a lot of work for registers that nobody might ever want to hide. As it is the CSR work is already done so easy to hook into for this feature. At a minimum the parser would get a lot more complex to support what you mentioned above.

@TommyMurphyTM1234
Copy link
Collaborator

That sounds like a lot of work for registers that nobody might ever want to hide. As it is the CSR work is already done so easy to hook into for this feature. At a minimum the parser would get a lot more complex to support what you mentioned above.

OK - fair enough. :-)

src/target/riscv/riscv.c Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
@aap-sc aap-sc force-pushed the aap-sc/hide_csr_support branch from 4e0bf6f to 6856cd4 Compare February 9, 2023 22:54
@aap-sc
Copy link
Collaborator Author

aap-sc commented Feb 9, 2023

@timsifive

Looks alright. Can you document this new command in doc/openocd.texi?

I've added a short section.

@TommyMurphyTM1234 and @timsifive

That sounds like a lot of work for registers that nobody might ever want to hide

yep. I would prefer not to touch that code. It's messy even in GDB.

@aap-sc aap-sc requested review from timsifive and JanMatCodasip and removed request for timsifive and JanMatCodasip February 9, 2023 22:59
This option allows users to mark certain CSRs as hidden so they could be
expluded from *reg* output and target.xml

Change-Id: Iddf8456cd3901f572f8590329ebba5229974d24a
@aap-sc aap-sc force-pushed the aap-sc/hide_csr_support branch from 6856cd4 to 57aacec Compare February 10, 2023 21:30
timsifive
timsifive previously approved these changes Feb 13, 2023
Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

JanMatCodasip
JanMatCodasip previously approved these changes Feb 14, 2023
Copy link
Collaborator

@JanMatCodasip JanMatCodasip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine. I have noticed just two small typos.

doc/openocd.texi Outdated Show resolved Hide resolved
src/target/riscv/riscv.c Outdated Show resolved Hide resolved
Co-authored-by: Jan Matyas <50193733+JanMatCodasip@users.noreply.github.com>
Signed-off-by: Anatoly Parshintsev <114445139+aap-sc@users.noreply.github.com>
@aap-sc aap-sc dismissed stale reviews from JanMatCodasip and timsifive via bfaceec February 14, 2023 18:09
Co-authored-by: Jan Matyas <50193733+JanMatCodasip@users.noreply.github.com>
Signed-off-by: Anatoly Parshintsev <114445139+aap-sc@users.noreply.github.com>
Copy link
Collaborator

@timsifive timsifive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's even better now. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants