Skip to content

Conversation

@Biancaa-R
Copy link

This PR resolves this issue #1264
These functions currently do not exit early if program the program buffer in the target is insufficient:

csr_read_progbuf()
fpr_read_progbuf()
csr_write_progbuf()
fpr_write_progbuf()

This pr resolves this issue using the pre existing function:
if (!has_sufficient_progbuf(target, 2))

Add a check in CSR read functions to skip the operation when the target's
progbuf is smaller than required. This prevents errors on targets with
limited progbuf size and ensures safer debugging operations.

  • Added has_sufficient_progbuf checks to CSR read functions.
  • Log debug message when skipping due to insufficient progbuf.
  • Improves compatibility with smaller RISC-V targets.
image * checks for the min size

Successful configuring:
image
Successful build ,after build the version was also tested to check working:
image
with ./src/openocd --version

@Biancaa-R
Copy link
Author

This code built and ran without issues ,In case of any needed modification of functionality ,please let me know ,Ill do it :)

Copy link
Collaborator

@en-sc en-sc left a comment

Choose a reason for hiding this comment

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

@Biancaa-R, thank you for submitting the patch!

Please, take a look at Checkpatch failures.
The first ERROR:COMMIT_MESSAGE: can be quite cryptic -- the commit message is split into the title and the description with an empty line in-between.
Please see https://git-scm.com/docs/git-commit#_discussion for more.

The other errors seem descriptive enough.

You can run the script locally with:

> tools/scripts/checkpatch.pl -g HEAD

Also, what about vtype_write_progbuf()/vl_write_progbuf()?

assert(target->state == TARGET_HALTED);
assert(number >= GDB_REGNO_FPR0 && number <= GDB_REGNO_FPR31);
if (!has_sufficient_progbuf(target, 2)) {
LOG_DEBUG("Skipping FPR read: insufficient progbuf (size=%d)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

[here and around] Please, use LOG_TARGET_DEBUG(...) to give a bit more context:

Suggested change
LOG_DEBUG("Skipping FPR read: insufficient progbuf (size=%d)",
LOG_TARGET_DEBUG(target, "Skipping FPR read: insufficient progbuf (size=%d)",

Also progbufsize is unsigned, so the correct format specifier is %u (though this is undoubtedly a nitpick).

Copy link
Author

Choose a reason for hiding this comment

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

Changed it in the updated version.

@en-sc
Copy link
Collaborator

en-sc commented Oct 27, 2025

Also, if you have the time please check #1301 -- I believe it is a better approach to the issue.
It will allow to drop the magic constant from the calls to has_sufficient_progbuf() and to replace them with something like has_progbuf().
In any case this patch is an improvement by itself and can be merged without #1301.

@Biancaa-R
Copy link
Author

@Biancaa-R, thank you for submitting the patch!

Please, take a look at Checkpatch failures. The first ERROR:COMMIT_MESSAGE: can be quite cryptic -- the commit message is split into the title and the description with an empty line in-between. Please see https://git-scm.com/docs/git-commit#_discussion for more.

The other errors seem descriptive enough.

You can run the script locally with:

> tools/scripts/checkpatch.pl -g HEAD

Also, what about vtype_write_progbuf()/vl_write_progbuf()?

Sure I'll check for those errors. In the issue only csr_read_progbuf()
fpr_read_progbuf()
csr_write_progbuf()
fpr_write_progbuf()

Were mentioned, sure I'll add those 2 as well.

Biancaa Ramesh added 2 commits October 27, 2025 20:27
Added additional debug logs to verify correct retrieval and printing
of progbufsize in various code paths within riscv-013.c. This helps
in debugging hardware configurations that expose custom program buffer
sizes.

Signed-off-by: Biancaa Ramesh <[email protected]>
…d-write

Added a check for have_progbuf_size before attempting to execute. This prevents program buffer access on targets
that do not support it, improving robustness and avoiding potential
execution failures when the program buffer is not available or too small.

Signed-off-by: Biancaa Ramesh <[email protected]>
@Biancaa-R Biancaa-R force-pushed the riscv-progbufsize-check branch from 060a08b to 38450ad Compare October 27, 2025 15:29
@Biancaa-R Biancaa-R requested a review from en-sc October 27, 2025 15:30
{
assert(target->state == TARGET_HALTED);
/* Ensure program buffer is large enough for 2 instructions */
if (!has_sufficient_progbuf(target, 2)) {
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
if (!has_sufficient_progbuf(target, 2)) {
if (!has_sufficient_progbuf(target, 3)) {

The sequence is:

csrr ...
vsetvl ...
ebreak

{
assert(target->state == TARGET_HALTED);
/* Ensure program buffer is large enough for 2 instructions */
if (!has_sufficient_progbuf(target, 2)) {
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
if (!has_sufficient_progbuf(target, 2)) {
if (!has_sufficient_progbuf(target, 3)) {

(Same as for vl.)

Copy link
Author

Choose a reason for hiding this comment

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

Oh as For vector register (v1) or vector type (vtype) operations we need to see 3 instructions ,right !
Ill fix it .Thanks @en-sc

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.

2 participants