@@ -74,19 +74,32 @@ bool trigger_t::common_match(processor_t * const proc, bool use_prev_prv) const
7474 return false ;
7575
7676 if (get_action () == ACTION_DEBUG_EXCEPTION) {
77- const bool mstatus_mie = state->mstatus ->read () & MSTATUS_MIE;
78- if (prv == PRV_M && !mstatus_mie)
79- return false ;
80-
81- const bool sstatus_sie = state->sstatus ->read () & MSTATUS_SIE;
82- const bool medeleg_breakpoint = (state->medeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
83- if (prv == PRV_S && !v && medeleg_breakpoint && !sstatus_sie)
84- return false ;
85-
86- const bool vsstatus_sie = state->vsstatus ->read () & MSTATUS_SIE;
87- const bool hedeleg_breakpoint = (state->hedeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
88- if (prv == PRV_S && v && medeleg_breakpoint && hedeleg_breakpoint && !vsstatus_sie)
89- return false ;
77+ if (proc->extension_enabled (' S' )) {
78+ // The hardware prevents triggers with action=0 from matching or firing
79+ // while in M-mode and while MIE in mstatus is 0. If medeleg [3]=1 then it
80+ // prevents triggers with action=0 from matching or firing while in S-mode
81+ // and while SIE in sstatus is 0. If medeleg [3]=1 and hedeleg [3]=1 then
82+ // it prevents triggers with action=0 from matching or firing while in
83+ // VS-mode and while SIE in vstatus is 0.
84+
85+ const bool mstatus_mie = state->mstatus ->read () & MSTATUS_MIE;
86+ if (prv == PRV_M && !mstatus_mie)
87+ return false ;
88+
89+ const bool sstatus_sie = state->sstatus ->read () & MSTATUS_SIE;
90+ const bool medeleg_breakpoint = (state->medeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
91+ if (prv == PRV_S && !v && medeleg_breakpoint && !sstatus_sie)
92+ return false ;
93+
94+ const bool vsstatus_sie = state->vsstatus ->read () & MSTATUS_SIE;
95+ const bool hedeleg_breakpoint = (state->hedeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
96+ if (prv == PRV_S && v && medeleg_breakpoint && hedeleg_breakpoint && !vsstatus_sie)
97+ return false ;
98+ } else {
99+ // mte and mpte in tcontrol is implemented. medeleg [3] is hard-wired to 0.
100+ if (prv == PRV_M && !(tcontrol_value (state) & CSR_TCONTROL_MTE))
101+ return false ;
102+ }
90103 }
91104
92105 return true ;
0 commit comments