target/riscv: warn about truncating register values#1233
Closed
en-sc wants to merge 1 commit intoriscv-collab:riscvfrom
en-sc:en-sc/truncate-progbuf
Closed
target/riscv: warn about truncating register values#1233en-sc wants to merge 1 commit intoriscv-collab:riscvfrom en-sc:en-sc/truncate-progbuf
en-sc wants to merge 1 commit intoriscv-collab:riscvfrom
en-sc:en-sc/truncate-progbuf
Conversation
When reading a register via Program Buffer the actual value is read from a GPR. The GPR size (XLEN) can be greater than the length of the target register (e.g. `dcsr` is always 32-bit wide). Due to some HW issue GPR read may return a value that needs to be truncated to fit into the target register. Warn the user about it. Moreover, the value in cache was and is truncated, but the `riscv_reg_t` that is filled by `riscv_reg_get()` didn't use to be. This may lead to an assertion failure in `abstract_data_write_fill_batch()`: Link: https://github.com/riscv-collab/riscv-openocd/blob/fa7e2351c834d63016db65923f25ec599bb7ceac/src/target/riscv/riscv-013.c#L757 Change-Id: I4d8a5ba2451fc5a60f51b9143b6b140dfe3b73b8 Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Comment on lines
+1392
to
+1395
| LOG_TARGET_WARNING(target, "Value read for register %s of %" PRIx64 | ||
| " does not fit into the size of the register (%u bits)." | ||
| " This is a HW bug. Truncating the value to fit into the register.", | ||
| riscv_reg_gdb_regno_name(target, number), *value, size_bits); |
Collaborator
There was a problem hiding this comment.
If this HW problem occurs, it is a serious thing, and we better not trust the returned value at all.
Instead of truncating the value, I would recommend to change the message level to ERROR and end the operation with an error code.
Few additional details:
- Added prefix
0xin front of the hex number - I'd suggest minor change of word order for readability
does not fit into the size-->exceeds the size(shorter and more formal)
Suggested change
| LOG_TARGET_WARNING(target, "Value read for register %s of %" PRIx64 | |
| " does not fit into the size of the register (%u bits)." | |
| " This is a HW bug. Truncating the value to fit into the register.", | |
| riscv_reg_gdb_regno_name(target, number), *value, size_bits); | |
| LOG_TARGET_ERROR(target, "Value 0x%" PRIx64 " read from register %s" | |
| " exceeds the size of the register (%u bits). This is a HW bug. " | |
| *value, riscv_reg_gdb_regno_name(target, number), size_bits); | |
| return ERROR_FAIL; |
Otherwise this change looks good.
Collaborator
Author
|
@JanMatCodasip, I've closed this one by mistake, reopened as #1268. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When reading a register via Program Buffer the actual value is read from a GPR. The GPR size (XLEN) can be greater than the length of the target register (e.g.
dcsris always 32-bit wide). Due to some HW issue GPR read may return a value that needs to be truncated to fit into the target register. Warn the user about it.Moreover, the value in cache was and is truncated, but the
riscv_reg_tthat is filled byriscv_reg_get()didn't use to be. This may lead to an assertion failure inabstract_data_write_fill_batch(): Link:riscv-openocd/src/target/riscv/riscv-013.c
Line 757 in fa7e235
Change-Id: I4d8a5ba2451fc5a60f51b9143b6b140dfe3b73b8