case CSR_MSCRATCH: state.mscratch = val; break;
case CSR_MCAUSE: state.mcause = val; break;
case CSR_MBADADDR: state.mbadaddr = val; break;
- case CSR_TSELECT: state.tselect = val; break;
+ case CSR_TSELECT:
+ if (val < state.num_triggers) {
+ state.tselect = val;
+ }
+ break;
case CSR_TDATA1:
- if (state.tselect < state.num_triggers) {
+ {
mcontrol_t *mc = &state.mcontrol[state.tselect];
+ if (mc->dmode && !state.dcsr.cause) {
+ throw trap_illegal_instruction();
+ }
mc->dmode = get_field(val, MCONTROL_DMODE(xlen));
mc->select = get_field(val, MCONTROL_SELECT);
+ mc->timing = get_field(val, MCONTROL_TIMING);
mc->action = (mcontrol_action_t) get_field(val, MCONTROL_ACTION);
mc->chain = get_field(val, MCONTROL_CHAIN);
mc->match = (mcontrol_match_t) get_field(val, MCONTROL_MATCH);
break;
case CSR_TDATA2:
if (state.tselect < state.num_triggers) {
- state.tdata1[state.tselect] = val;
+ state.tdata2[state.tselect] = val;
}
break;
case CSR_DCSR:
v = set_field(v, MCONTROL_DMODE(xlen), mc->dmode);
v = set_field(v, MCONTROL_MASKMAX(xlen), mc->maskmax);
v = set_field(v, MCONTROL_SELECT, mc->select);
+ v = set_field(v, MCONTROL_TIMING, mc->timing);
v = set_field(v, MCONTROL_ACTION, mc->action);
v = set_field(v, MCONTROL_CHAIN, mc->chain);
v = set_field(v, MCONTROL_MATCH, mc->match);
break;
case CSR_TDATA2:
if (state.tselect < state.num_triggers) {
- return state.tdata1[state.tselect];
+ return state.tdata2[state.tselect];
} else {
return 0;
}
typedef struct
{
uint8_t type;
+ bool dmode;
uint8_t maskmax;
bool select;
- bool dmode;
+ bool timing;
mcontrol_action_t action;
bool chain;
mcontrol_match_t match;
dcsr_t dcsr;
reg_t tselect;
mcontrol_t mcontrol[num_triggers];
- reg_t tdata1[num_triggers];
+ reg_t tdata2[num_triggers];
uint32_t fflags;
uint32_t frm;
switch (state.mcontrol[i].match) {
case MATCH_EQUAL:
- if (value != state.tdata1[i])
+ if (value != state.tdata2[i])
continue;
break;
case MATCH_NAPOT:
{
- reg_t mask = ~((1 << cto(state.tdata1[i])) - 1);
- if ((value & mask) != (state.tdata1[i] & mask))
+ reg_t mask = ~((1 << cto(state.tdata2[i])) - 1);
+ if ((value & mask) != (state.tdata2[i] & mask))
continue;
}
break;
case MATCH_GE:
- if (value < state.tdata1[i])
+ if (value < state.tdata2[i])
continue;
break;
case MATCH_LT:
- if (value >= state.tdata1[i])
+ if (value >= state.tdata2[i])
continue;
break;
case MATCH_MASK_LOW:
{
- reg_t mask = state.tdata1[i] >> (xlen/2);
- if ((value & mask) != (state.tdata1[i] & mask))
+ reg_t mask = state.tdata2[i] >> (xlen/2);
+ if ((value & mask) != (state.tdata2[i] & mask))
continue;
}
break;
case MATCH_MASK_HIGH:
{
- reg_t mask = state.tdata1[i] >> (xlen/2);
- if (((value >> (xlen/2)) & mask) != (state.tdata1[i] & mask))
+ reg_t mask = state.tdata2[i] >> (xlen/2);
+ if (((value >> (xlen/2)) & mask) != (state.tdata2[i] & mask))
continue;
}
break;
}
- if (!state.mcontrol[i].chain)
+ if (!state.mcontrol[i].chain) {
return i;
+ }
chain_ok = true;
}
return -1;