Skip to contentSkip to conversation

target/riscv: set tval for triggered watchpoints

PATCH Applied Sergey Matyukevich 3 participants 4 messages Jan 31, 2023 – Feb 2, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: set tval for triggered watchpoints

From: Sergey Matyukevich <[email protected]>

According to priviledged spec, if [sm]tval is written with a nonzero value when a breakpoint exception occurs, then [sm]tval will contain the faulting virtual address. Set tval to hit address when breakpoint exception is triggered by hardware watchpoint.

---

v1 -> v2
- do not set tval blindly for every breakpoint exception, handle current specific case under consideration

 target/riscv/cpu_helper.c | 6 ++++++
 target/riscv/debug.c      | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +6 -0
index 9a28816521..f1a0c65ad3 100644
@@ -1641,6 +1641,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)
         case RISCV_EXCP_VIRT_INSTRUCTION_FAULT:
             tval = env->bins;
             break;
+        case RISCV_EXCP_BREAKPOINT:
+            if (cs->watchpoint_hit) {
+                tval = cs->watchpoint_hit->hitaddr;
+                cs->watchpoint_hit = NULL;
+            }
+            break;
         default:
             break;
         }
target/riscv/debug.c +0 -1
index bf4840a6a3..b091293069 100644
@@ -761,7 +761,6 @@ void riscv_cpu_debug_excp_handler(CPUState *cs)
 
     if (cs->watchpoint_hit) {
         if (cs->watchpoint_hit->flags & BP_CPU) {
-            cs->watchpoint_hit = NULL;
             do_trigger_action(env, DBG_ACTION_BP);
         }
     } else {
Signature · 1 line
2.39.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 4 lines · Sergey Matyukevich

From: Sergey Matyukevich <[email protected]>

According to priviledged spec, if [sm]tval is written with a nonzero

typo: privileged

Quoted 8 lines

value when a breakpoint exception occurs, then [sm]tval will contain the faulting virtual address. Set tval to hit address when breakpoint exception is triggered by hardware watchpoint.

---

Quoted 8 lines

v1 -> v2
- do not set tval blindly for every breakpoint exception, handle current specific case under consideration

 target/riscv/cpu_helper.c | 6 ++++++
 target/riscv/debug.c      | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Sergey Matyukevich
Quoted 9 lines · Sergey Matyukevich

From: Sergey Matyukevich <[email protected]>

According to priviledged spec, if [sm]tval is written with a nonzero value when a breakpoint exception occurs, then [sm]tval will contain the faulting virtual address. Set tval to hit address when breakpoint exception is triggered by hardware watchpoint.

Alistair

Quoted 44 lines

---

v1 -> v2
- do not set tval blindly for every breakpoint exception, handle current specific case under consideration

 target/riscv/cpu_helper.c | 6 ++++++
 target/riscv/debug.c      | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +6 -0
index 9a28816521..f1a0c65ad3 100644
@@ -1641,6 +1641,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)
         case RISCV_EXCP_VIRT_INSTRUCTION_FAULT:
             tval = env->bins;
             break;
+        case RISCV_EXCP_BREAKPOINT:
+            if (cs->watchpoint_hit) {
+                tval = cs->watchpoint_hit->hitaddr;
+                cs->watchpoint_hit = NULL;
+            }
+            break;
         default:
             break;
         }
target/riscv/debug.c +0 -2
index bf4840a6a3..b091293069 100644
@@ -761,7 +761,6 @@ void riscv_cpu_debug_excp_handler(CPUState *cs)
 
     if (cs->watchpoint_hit) {
         if (cs->watchpoint_hit->flags & BP_CPU) {
-            cs->watchpoint_hit = NULL;
             do_trigger_action(env, DBG_ACTION_BP);
         }
     } else {
--

2.39.0

#3 lore raw
In reply to Sergey Matyukevich
Quoted 9 lines · Sergey Matyukevich

From: Sergey Matyukevich <[email protected]>

According to priviledged spec, if [sm]tval is written with a nonzero value when a breakpoint exception occurs, then [sm]tval will contain the faulting virtual address. Set tval to hit address when breakpoint exception is triggered by hardware watchpoint.

Thanks!

Applied to riscv-to-apply.next with the typo fixed

Alistair

Quoted 44 lines

---

v1 -> v2
- do not set tval blindly for every breakpoint exception, handle current specific case under consideration

 target/riscv/cpu_helper.c | 6 ++++++
 target/riscv/debug.c      | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +6 -0
index 9a28816521..f1a0c65ad3 100644
@@ -1641,6 +1641,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)
         case RISCV_EXCP_VIRT_INSTRUCTION_FAULT:
             tval = env->bins;
             break;
+        case RISCV_EXCP_BREAKPOINT:
+            if (cs->watchpoint_hit) {
+                tval = cs->watchpoint_hit->hitaddr;
+                cs->watchpoint_hit = NULL;
+            }
+            break;
         default:
             break;
         }
target/riscv/debug.c +0 -2
index bf4840a6a3..b091293069 100644
@@ -761,7 +761,6 @@ void riscv_cpu_debug_excp_handler(CPUState *cs)
 
     if (cs->watchpoint_hit) {
         if (cs->watchpoint_hit->flags & BP_CPU) {
-            cs->watchpoint_hit = NULL;
             do_trigger_action(env, DBG_ACTION_BP);
         }
     } else {
--

2.39.0