aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>2024-01-11 14:05:05 +0300
committerEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>2024-01-16 21:24:07 +0300
commitcd07c4447b5a3b8f8b3a695d16f253c1c949c0f1 (patch)
tree9c7976004b1bf14074c23cad2978d916cfb683b4
parent4fc0d86ff0c5ac45058777c9f0e5c53d3d17d7f9 (diff)
downloadriscv-openocd-cd07c4447b5a3b8f8b3a695d16f253c1c949c0f1.zip
riscv-openocd-cd07c4447b5a3b8f8b3a695d16f253c1c949c0f1.tar.gz
riscv-openocd-cd07c4447b5a3b8f8b3a695d16f253c1c949c0f1.tar.bz2
target/riscv: cleanup `get_riscv_debug_reg_ctx()`
This commit makes the function safe to use throughout the lifetime of a target. Change-Id: I7a573e5d3b70daec2cf8f47a2aa1e30e39321549
-rw-r--r--src/target/riscv/riscv-013.c12
-rw-r--r--src/target/target.h2
2 files changed, 9 insertions, 5 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 651342a..ad7b28e 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -280,13 +280,17 @@ static dm013_info_t *get_dm(struct target *target)
return dm;
}
-static riscv_debug_reg_ctx_t get_riscv_debug_reg_ctx(struct target *target)
+static riscv_debug_reg_ctx_t get_riscv_debug_reg_ctx(const struct target *target)
{
- RISCV_INFO(r);
+ if (!target_was_examined(target)) {
+ const riscv_debug_reg_ctx_t default_context = {0};
+ return default_context;
+ }
+
RISCV013_INFO(info);
const riscv_debug_reg_ctx_t context = {
- .XLEN = { .value = r->xlen, .is_set = true },
- .DXLEN = { .value = r->xlen, .is_set = true },
+ .XLEN = { .value = riscv_xlen(target), .is_set = true },
+ .DXLEN = { .value = riscv_xlen(target), .is_set = true },
.abits = { .value = info->abits, .is_set = true },
};
return context;
diff --git a/src/target/target.h b/src/target/target.h
index 975561b..8b50dcc 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -438,7 +438,7 @@ const char *target_type_name(struct target *target);
int target_examine_one(struct target *target);
/** @returns @c true if target_set_examined() has been called. */
-static inline bool target_was_examined(struct target *target)
+static inline bool target_was_examined(const struct target *target)
{
return target->examined;
}