Skip to content

Commit

Permalink
target/riscv: Allow debugger to access sstc CSRs
Browse files Browse the repository at this point in the history
At present with a debugger attached sstc CSRs can only be accssed
when CPU is in M-mode, or configured correctly.

Fix it by adjusting their predicate() routine logic so that the
static config check comes before the run-time check, as well as
adding a debugger check.

Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
Message-ID: <20230228104035.1879882-17-bmeng@tinylab.org>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
lbmeng authored and palmer-dabbelt committed Mar 2, 2023
1 parent 0308fc6 commit e4e1f21
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions target/riscv/csr.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,19 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
return RISCV_EXCP_ILLEGAL_INST;
}

if ((csrno == CSR_VSTIMECMP) || (csrno == CSR_VSTIMECMPH)) {
hmode_check = true;
}

RISCVException ret = hmode_check ? hmode(env, csrno) : smode(env, csrno);
if (ret != RISCV_EXCP_NONE) {
return ret;
}

if (env->debugger) {
return RISCV_EXCP_NONE;
}

if (env->priv == PRV_M) {
return RISCV_EXCP_NONE;
}
Expand All @@ -972,11 +985,7 @@ static RISCVException sstc(CPURISCVState *env, int csrno)
}
}

if ((csrno == CSR_VSTIMECMP) || (csrno == CSR_VSTIMECMPH)) {
hmode_check = true;
}

return hmode_check ? hmode(env, csrno) : smode(env, csrno);
return RISCV_EXCP_NONE;
}

static RISCVException sstc_32(CPURISCVState *env, int csrno)
Expand Down

0 comments on commit e4e1f21

Please sign in to comment.