From f5ce311103cac65a0d5000891d6ebebfe51e93ed Mon Sep 17 00:00:00 2001 From: Sriram Shanmuga Date: Mon, 7 Jul 2025 18:17:04 +0300 Subject: [PATCH] target/riscv: improve error messaging in case `sbasize` is zero Imported from https://github.com/riscv-collab/riscv-openocd/pull/1274 From: Sriram Shanmuga RISC-V Debug Specification v1.0 [3.14.22. System Bus Access Control and Status (`sbcs`, at 0x38)] states in `sbasize` field description: > Width of system bus addresses in bits. (0 indicates there is no bus access support.) Before the patch, the error message did not include the information about `sbcs.sbasize` being zero wich made it quite undescriptive: ``` [riscv.cpu] Turning off memory sampling because it failed. ``` Fixes #1270 Change-Id: I5402dd57dc9a81f65ee4c67d24e11c366006427c Signed-off-by: Sriram Shanmuga Signed-off-by: Evgeniy Naydanov Reviewed-on: https://review.openocd.org/c/openocd/+/9142 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/riscv/riscv-013.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 3308f40b9..370a15607 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2610,8 +2610,8 @@ static int sample_memory_bus_v1(struct target *target, { RISCV013_INFO(info); unsigned int sbasize = get_field(info->sbcs, DM_SBCS_SBASIZE); - if (sbasize > 64) { - LOG_TARGET_ERROR(target, "Memory sampling is only implemented for sbasize <= 64."); + if (sbasize == 0 || sbasize > 64) { + LOG_TARGET_ERROR(target, "Memory sampling is only implemented for non-zero sbasize <= 64."); return ERROR_NOT_IMPLEMENTED; }