aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Naydanov <109669442+en-sc@users.noreply.github.com>2025-09-08 15:19:31 +0300
committerGitHub <noreply@github.com>2025-09-08 15:19:31 +0300
commit295166b6e77f268130736a3b0cb15def952f5b18 (patch)
tree25f40f52c479d508b9c387cd4eb48fe1718e4e7e
parent6f84e90d5cc0e98f895ea0fa31212326b50ab769 (diff)
parent7639fdd7e1c5a32dce5d6dc6b712f597379b4ac4 (diff)
downloadriscv-openocd-295166b6e77f268130736a3b0cb15def952f5b18.zip
riscv-openocd-295166b6e77f268130736a3b0cb15def952f5b18.tar.gz
riscv-openocd-295166b6e77f268130736a3b0cb15def952f5b18.tar.bz2
Merge pull request #1258 from zqb-all/addr-translate-h-mode
target/riscv: fix address translation in hypervisor mode
-rw-r--r--src/target/riscv/riscv.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index aae5eb3..2e475a5 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -3035,23 +3035,8 @@ static int riscv_mmu(struct target *target, int *enabled)
unsigned int xlen = riscv_xlen(target);
if (v_mode) {
- /* vsatp and hgatp registers are considered active for the
- * purposes of the address-translation algorithm unless the
- * effective privilege mode is U and hstatus.HU=0. */
- if (effective_mode == PRV_U) {
- riscv_reg_t hstatus;
- if (riscv_reg_get(target, &hstatus, GDB_REGNO_HSTATUS) != ERROR_OK) {
- LOG_TARGET_ERROR(target, "Failed to read hstatus register.");
- return ERROR_FAIL;
- }
-
- if (get_field(hstatus, HSTATUS_HU) == 0)
- /* In hypervisor mode regular satp translation
- * doesn't happen. */
- return ERROR_OK;
-
- }
-
+ /* In VU or VS mode, MMU is considered enabled when
+ * either hgatp or vsatp mode is not OFF */
riscv_reg_t vsatp;
if (riscv_reg_get(target, &vsatp, GDB_REGNO_VSATP) != ERROR_OK) {
LOG_TARGET_ERROR(target, "Failed to read vsatp register; priv=0x%" PRIx64,
@@ -3059,7 +3044,7 @@ static int riscv_mmu(struct target *target, int *enabled)
return ERROR_FAIL;
}
/* vsatp is identical to satp, so we can use the satp macros. */
- if (RISCV_SATP_MODE(xlen) != SATP_MODE_OFF) {
+ if (get_field(vsatp, RISCV_SATP_MODE(xlen)) != SATP_MODE_OFF) {
LOG_TARGET_DEBUG(target, "VS-stage translation is enabled.");
*enabled = 1;
return ERROR_OK;
@@ -3071,7 +3056,7 @@ static int riscv_mmu(struct target *target, int *enabled)
priv);
return ERROR_FAIL;
}
- if (RISCV_HGATP_MODE(xlen) != HGATP_MODE_OFF) {
+ if (get_field(hgatp, RISCV_HGATP_MODE(xlen)) != HGATP_MODE_OFF) {
LOG_TARGET_DEBUG(target, "G-stage address translation is enabled.");
*enabled = 1;
} else {