aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Matyas <50193733+JanMatCodasip@users.noreply.github.com>2024-01-25 06:53:51 +0100
committerGitHub <noreply@github.com>2024-01-25 06:53:51 +0100
commitec28cf03aef7539ff8c02db4a9ac558545d4e7c6 (patch)
treeae1d0017033e3230601945a0f09ba8051da95eef
parentaa4a80dbed9e664aa802f1b6f56cfce1ea7c9a4e (diff)
parentca3abcaa06e2d799bde7f883329dfc3b001d5dc5 (diff)
downloadriscv-openocd-ec28cf03aef7539ff8c02db4a9ac558545d4e7c6.zip
riscv-openocd-ec28cf03aef7539ff8c02db4a9ac558545d4e7c6.tar.gz
riscv-openocd-ec28cf03aef7539ff8c02db4a9ac558545d4e7c6.tar.bz2
Merge pull request #997 from en-sc/en-sc/priv-access
target/riscv: move read redirection for `priv` to `riscv-013.c`
-rw-r--r--src/target/riscv/riscv-013.c13
-rw-r--r--src/target/riscv/riscv.c10
2 files changed, 14 insertions, 9 deletions
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 423a043..8b3260c 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -4855,6 +4855,19 @@ struct target_type riscv013_target = {
static int riscv013_get_register(struct target *target,
riscv_reg_t *value, enum gdb_regno rid)
{
+ /* It would be beneficial to move this redirection to the
+ * version-independent section, but there is a conflict:
+ * `dcsr[5]` is `dcsr.v` in current spec, but it is `dcsr.debugint` in 0.11.
+ */
+ if (rid == GDB_REGNO_PRIV) {
+ uint64_t dcsr;
+ if (riscv_get_register(target, &dcsr, GDB_REGNO_DCSR) != ERROR_OK)
+ return ERROR_FAIL;
+ *value = set_field(0, VIRT_PRIV_V, get_field(dcsr, CSR_DCSR_V));
+ *value = set_field(*value, VIRT_PRIV_PRV, get_field(dcsr, CSR_DCSR_PRV));
+ return ERROR_OK;
+ }
+
LOG_TARGET_DEBUG(target, "reading register %s", gdb_regno_name(target, rid));
if (dm013_select_target(target) != ERROR_OK)
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index b187161..c476e7e 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -5240,16 +5240,8 @@ int riscv_get_register(struct target *target, riscv_reg_t *value,
if (openocd_is_shutdown_pending())
return ERROR_SERVER_INTERRUPTED;
- if (regid == GDB_REGNO_PC) {
+ if (regid == GDB_REGNO_PC)
return riscv_get_register(target, value, GDB_REGNO_DPC);
- } else if (regid == GDB_REGNO_PRIV) {
- uint64_t dcsr;
- if (riscv_get_register(target, &dcsr, GDB_REGNO_DCSR) != ERROR_OK)
- return ERROR_FAIL;
- *value = set_field(0, VIRT_PRIV_V, get_field(dcsr, CSR_DCSR_V));
- *value = set_field(*value, VIRT_PRIV_PRV, get_field(dcsr, CSR_DCSR_PRV));
- return ERROR_OK;
- }
if (!target->reg_cache) {
assert(!target_was_examined(target));