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: define register printers #892

Merged
merged 1 commit into from
Sep 28, 2023

Conversation

en-sc
Copy link
Collaborator

@en-sc en-sc commented Jul 19, 2023

This commit implements facilities to decode register fields for each register described in debug_defines.h.

Namely:

  • define <REG_NAME>_FORMAT_STR
  • macro <REG_NAME>_FORMAT_ARGS(value)

The use case is demonstarted by changing debug message in execute_abstract_command()

Change-Id: I63733d8d36385d89ca15de1a43139134bc488c4f

@en-sc
Copy link
Collaborator Author

en-sc commented Jul 19, 2023

This commit fails checkpatch, since the macro argument is reused.

CHECK:MACRO_ARG_REUSE: Macro argument reuse 'value' - possible side-effects?

IMHO, this is an insignificant drawback, since there are other macro which also reuse their's arguments (e.g. get_field)

If you have any suggestions on how to fix or disable (locally) this warning, I would be glad to hear them.

@en-sc
Copy link
Collaborator Author

en-sc commented Jul 19, 2023

The changes to debug_defines.h are generated by applying the patch riscv/riscv-debug-spec#858 on top of previously used version of riscv-debug-spec (d749752).

@en-sc en-sc force-pushed the en-sc/register-printing branch 2 times, most recently from 0e4db6e to 0dfacaa Compare August 1, 2023 16:35
@en-sc
Copy link
Collaborator Author

en-sc commented Aug 1, 2023

debug_register_printers.c implements decoder for register values based on the new interface of debug_defines.h.

riscv_debug_reg_to_s() can be used to decode register value. If the
pointer to buffer is NULL it does not print anything, just returns the
length of the string.

The format is:
<register_value> { <field_name>=<field_value_name or field_value>, ..., }

e.g:

0x400382 { version=2, confstrptrvalid=invalid, hasresethaltreq=0, authbusy=ready, authenticated=true, anyhalted=1, allhalted=1, anyrunning=0, allrunning=0, anyunavail=0, allunavail=0, anynonexistent=0, allnonexistent=0, anyresumeack=0, allresumeack=0, anyhavereset=0, allhavereset=0, impebreak=1, stickyunavail=current, ndmresetpending=false, }

0x321009 { regno=0x1009, write=arg0, transfer=enabled, postexec=disabled, aarpostincrement=disabled, aarsize=64bit, cmdtype=0, }

src/target/riscv/debug_register_printers.c Outdated Show resolved Hide resolved
src/target/riscv/debug_register_printers.c Outdated Show resolved Hide resolved
@en-sc en-sc force-pushed the en-sc/register-printing branch 2 times, most recently from e1105f4 to 154e7aa Compare August 23, 2023 16:12
@en-sc
Copy link
Collaborator Author

en-sc commented Aug 23, 2023

The only warning from checkpatch left is:

WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 1
#27: FILE: src/target/riscv/debug_defines.c:1:

I'm not shure what is the best approach.
Should I leave it as-is (there is no license tag in debug_defines.h also) or should I add it?

@en-sc en-sc requested a review from timsifive August 24, 2023 12:19
src/target/riscv/debug_register_printers.h Outdated Show resolved Hide resolved
src/target/riscv/debug_register_printers.h Outdated Show resolved Hide resolved
src/target/riscv/debug_defines.c Outdated Show resolved Hide resolved
src/target/riscv/riscv-013.c Outdated Show resolved Hide resolved
src/target/riscv/riscv-013.c Outdated Show resolved Hide resolved
@timsifive
Copy link
Collaborator

WARNING:SPDX_LICENSE_TAG: Missing or malformed SPDX-License-Identifier tag in line 1

We can ignore that warning and merge it anyway when the time comes.

@en-sc en-sc force-pushed the en-sc/register-printing branch 2 times, most recently from 5a16f4d to a81b702 Compare August 31, 2023 10:36
@en-sc en-sc requested a review from timsifive August 31, 2023 10:40
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.

This code looks good. I'll head over to riscv/riscv-debug-spec#858 now.

src/target/riscv/debug_register_printers.h Outdated Show resolved Hide resolved
@en-sc
Copy link
Collaborator Author

en-sc commented Sep 14, 2023

@timsifive, @JanMatCodasip, can this be merged (since riscv/riscv-debug-spec#858 is already merged), or should I make some adjustments?

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.

Despite having somewhat different opinion on what the API of debug_defines.h could be, I like this change overall and it looks to me like a nice step forward in unification of the log prints. Thanks!

I believe there are few minor items to address prior to the merge.

@@ -0,0 +1,4145 @@
/*
* This file is auto-generated by running 'make debug_defines' in
* https://github.com/riscv/riscv-debug-spec/ (d749752-dirty)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please, can you re-generate these files from a non-dirty revision of the debug spec repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is intentional. I would like to avoid updating the version of the spec used to generate this file, since it would require a lot of changes in code (some constants were renamed and so on). The version is marked as dirty to indicate that the generators were cherry-picked on top of d749752. If you insist, I will update debug_defines.h to current version, though I'm not sure if it is the best time to do so.

Copy link
Collaborator

@JanMatCodasip JanMatCodasip Sep 18, 2023

Choose a reason for hiding this comment

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

I would like to avoid updating the version of the spec used to generate this file, since it would require a lot of changes in code (some constants were renamed and so on).

Understood. In that case, it is my recommendation to leave this merge request as is, but please make a proper upgrade of the debug_defines (from a clean commit) in a subsequent merge request.

The version is marked as dirty to indicate that the generators were cherry-picked on top of d749752

This is exactly the reason why I suggest to use a clean commit -- we can't expect other developers to figure out what needs to be cherry-picked where (what mixture of commits to make) in order to replicate your work, e.g. during troubleshooting.

Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have re-checked and the changes to the code are limited (only one function), so I updated the version of debug_defines.h in this MR.

src/target/riscv/debug_defines.c Outdated Show resolved Hide resolved
src/target/riscv/debug_defines.h Show resolved Hide resolved
src/target/riscv/debug_register_printers.h Outdated Show resolved Hide resolved
src/target/riscv/riscv-013.c Outdated Show resolved Hide resolved
src/target/riscv/debug_register_printers.c Outdated Show resolved Hide resolved
JanMatCodasip
JanMatCodasip previously approved these changes Sep 18, 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 to me.

I have only one remark #892 (comment) (which can be addressed as a separate merge request to keep the changes easier to review).

Thank you.

`riscv_debug_reg_to_s()` can be used to decode register value.  If the
pointer to buffer is `NULL` it does not print anything, just returns the
length of the string.

The format is:
`<register_value> { <field_name>=<field_value_name or field_value>, ..., }`

e.g:

`0x400382 { version=2, ... ndmresetpending=false, }`

`0x321009 { regno=0x1009, ... cmdtype=0, }`

Change-Id: I63733d8d36385d89ca15de1a43139134bc488c4f
Signed-off-by: Evgeniy Naydanov <[email protected]>
@en-sc
Copy link
Collaborator Author

en-sc commented Sep 27, 2023

@timsifive, @JanMatCodasip can this be merged or is there some action required to be done?

@timsifive timsifive merged commit ef3be96 into riscv-collab:riscv Sep 28, 2023
4 of 5 checks passed
@en-sc en-sc deleted the en-sc/register-printing branch August 14, 2024 18:42
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.

3 participants