From 84f5c416bffb66c8b47fd94b90afa888af7e819e Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 31 Aug 2016 15:51:58 -0700 Subject: [PATCH] Rename tdata[0-2] to tdata[1-3]. Add timing bit (but it doesn't do anything). Implement dmode bit. --- riscv/processor.cc | 17 +++++++++++++---- riscv/processor.h | 26 ++++++++++++++------------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/riscv/processor.cc b/riscv/processor.cc index 04d483c..57823f5 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -381,12 +381,20 @@ void processor_t::set_csr(int which, reg_t val) 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); @@ -403,7 +411,7 @@ void processor_t::set_csr(int which, reg_t val) break; case CSR_TDATA2: if (state.tselect < state.num_triggers) { - state.tdata1[state.tselect] = val; + state.tdata2[state.tselect] = val; } break; case CSR_DCSR: @@ -518,6 +526,7 @@ reg_t processor_t::get_csr(int which) 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); @@ -535,7 +544,7 @@ reg_t processor_t::get_csr(int which) break; case CSR_TDATA2: if (state.tselect < state.num_triggers) { - return state.tdata1[state.tselect]; + return state.tdata2[state.tselect]; } else { return 0; } diff --git a/riscv/processor.h b/riscv/processor.h index 2eac770..d5e8bc0 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -65,9 +65,10 @@ typedef enum 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; @@ -117,7 +118,7 @@ struct state_t 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; @@ -231,42 +232,43 @@ public: 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; -- 2.30.2