@@ -66,8 +66,7 @@ bool trigger_t::common_match(processor_t * const proc, bool use_prev_prv) const
66
66
auto state = proc->get_state ();
67
67
auto prv = use_prev_prv ? state->prev_prv : state->prv ;
68
68
auto v = use_prev_prv ? state->prev_v : state->v ;
69
- auto m_enabled = get_action () != 0 || (tcontrol_value (state) & CSR_TCONTROL_MTE);
70
- return (prv < PRV_M || m_enabled) && mode_match (prv, v) && textra_match (proc);
69
+ return (prv < PRV_M) && mode_match (prv, v) && textra_match (proc);
71
70
}
72
71
73
72
bool trigger_t::mode_match (reg_t prv, bool v) const noexcept
@@ -121,14 +120,25 @@ bool trigger_t::allow_action(processor_t * const proc) const
121
120
{
122
121
const state_t *state = proc->get_state ();
123
122
if (get_action () == ACTION_DEBUG_EXCEPTION) {
124
- const bool mstatus_mie = state->mstatus ->read () & MSTATUS_MIE;
125
- const bool sstatus_sie = state->sstatus ->read () & MSTATUS_SIE;
126
- const bool vsstatus_sie = state->vsstatus ->read () & MSTATUS_SIE;
127
- const bool medeleg_breakpoint = (state->medeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
128
- const bool hedeleg_breakpoint = (state->hedeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
129
- return (state->prv != PRV_M || mstatus_mie) &&
130
- (state->prv != PRV_S || state->v || !medeleg_breakpoint || sstatus_sie) &&
131
- (state->prv != PRV_S || !state->v || !medeleg_breakpoint || !hedeleg_breakpoint || vsstatus_sie);
123
+ if (proc->extension_enabled (' S' )) {
124
+ // The hardware prevents triggers with action=0 from matching or firing
125
+ // while in M-mode and while MIE in mstatus is 0. If medeleg [3]=1 then it
126
+ // prevents triggers with action=0 from matching or firing while in S-mode
127
+ // and while SIE in sstatus is 0. If medeleg [3]=1 and hedeleg [3]=1 then
128
+ // it prevents triggers with action=0 from matching or firing while in
129
+ // VS-mode and while SIE in vstatus is 0.
130
+ const bool mstatus_mie = state->mstatus ->read () & MSTATUS_MIE;
131
+ const bool sstatus_sie = state->sstatus ->read () & MSTATUS_SIE;
132
+ const bool vsstatus_sie = state->vsstatus ->read () & MSTATUS_SIE;
133
+ const bool medeleg_breakpoint = (state->medeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
134
+ const bool hedeleg_breakpoint = (state->hedeleg ->read () >> CAUSE_BREAKPOINT) & 1 ;
135
+ return (state->prv != PRV_M || mstatus_mie) &&
136
+ (state->prv != PRV_S || state->v || !medeleg_breakpoint || sstatus_sie) &&
137
+ (state->prv != PRV_S || !state->v || !medeleg_breakpoint || !hedeleg_breakpoint || vsstatus_sie);
138
+ } else {
139
+ // mte and mpte in tcontrol is implemented. medeleg [3] is hard-wired to 0.
140
+ return (state->prv != PRV_M) || (tcontrol_value (state) & CSR_TCONTROL_MTE);
141
+ }
132
142
}
133
143
return true ;
134
144
}
0 commit comments