target/riscv: Update tval for hardware watchpoint
PATCH 1/1 target/riscv: Update tval for hardware watchpoint
From: Bin Meng <[email protected]>
When watchpoint is hit, the breakpoint exception should update tval to point to the faulting virtual address.
Signed-off-by Bin Meng <[email protected]>
---
target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 6 ++++++ target/riscv/debug.c | 2 ++ 3 files changed, 9 insertions(+)
target/riscv/cpu.h +1 -0
@@ -289,6 +289,7 @@ struct CPUArchState {/* trigger module */ target_ulong trigger_cur; +bool wp_hit;type2_trigger_t type2_trig[TRIGGER_TYPE2_NUM ];/* machine specific rdtime callback */
target/riscv/cpu_helper.c +6 -0
@@ -1345,6 +1345,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)target_ulong htval =0 ;target_ulong mtval2 =0 ; +/* only update tval for watchpoint */ +if (cause ==RISCV_EXCP_BREAKPOINT && env->wp_hit) { + env->wp_hit = false; + tval = env->badaddr; + } +if (cause ==RISCV_EXCP_SEMIHOST ) {if (env->priv >=PRV_S ) { env->gpr[xA0] =do_common_semihosting (cs);
target/riscv/debug.c +2 -0
@@ -407,6 +407,8 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)if ((wp->flags & flags) && (wp->vaddr == addr)) {/* check U/S/M bit against current privilege level */ if ((ctrl >>3 ) &BIT (env->priv)) { + env->wp_hit = true; + env->badaddr = addr;return true; } }
Signature · 1 line
2.34.1
Quoted 18 lines · Bin Meng
From: Bin Meng <[email protected]>
When watchpoint is hit, the breakpoint exception should update tval to point to the faulting virtual address.
Signed-off-by Bin Meng <[email protected]>---
target/riscv/cpu.h | 1 + target/riscv/cpu_helper.c | 6 ++++++ target/riscv/debug.c | 2 ++ 3 files changed, 9 insertions(+)target/riscv/cpu.h +0
-0
target/riscv/cpu.h struct CPUArchState { · line 292
Quoted 4 lines
target/riscv/cpu.h +1
-0@@ -289,6 +289,7 @@ struct CPUArchState {/* trigger module */ target_ulong trigger_cur; +bool wp_hit;
It would be better to not add this, which duplicates cs->watchpoint_hit.
In riscv_cpu_debug_excp_handler, raise a synthetic exception number (RISCV_EXCP_WATCHPOINT?), then set tval in the same switch as the others.
r~