Message ID | 20230228104035.1879882-19-bmeng@tinylab.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | target/riscv: Various fixes to gdbstub and CSR access | expand |
On 2023/2/28 21:45, Bin Meng wrote: > From: Bin Meng <bmeng@tinylab.org> > > Move sstc()/sstc32() to where all predicate() routines live, and > smstateen_acc_ok() to near {read,write}_xenvcfg(). > > Signed-off-by: Bin Meng <bmeng@tinylab.org> > Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> > --- > > Changes in v2: > - move smstateen_acc_ok() to near {read,write}_xenvcfg() > > target/riscv/csr.c | 177 ++++++++++++++++++++++----------------------- > 1 file changed, 87 insertions(+), 90 deletions(-) > > diff --git a/target/riscv/csr.c b/target/riscv/csr.c > index 785f6f4d45..3a7e0217e2 100644 > --- a/target/riscv/csr.c > +++ b/target/riscv/csr.c > @@ -40,42 +40,6 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) > csr_ops[csrno & (CSR_TABLE_SIZE - 1)] = *ops; > } > > -/* Predicates */ Don't remove this comment. Otherwise, Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> Zhiwei > -#if !defined(CONFIG_USER_ONLY) > -static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, > - uint64_t bit) > -{ > - bool virt = riscv_cpu_virt_enabled(env); > - RISCVCPU *cpu = env_archcpu(env); > - > - if (env->priv == PRV_M || !cpu->cfg.ext_smstateen) { > - return RISCV_EXCP_NONE; > - } > - > - if (!(env->mstateen[index] & bit)) { > - return RISCV_EXCP_ILLEGAL_INST; > - } > - > - if (virt) { > - if (!(env->hstateen[index] & bit)) { > - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > - } > - > - if (env->priv == PRV_U && !(env->sstateen[index] & bit)) { > - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > - } > - } > - > - if (env->priv == PRV_U && riscv_has_ext(env, RVS)) { > - if (!(env->sstateen[index] & bit)) { > - return RISCV_EXCP_ILLEGAL_INST; > - } > - } > - > - return RISCV_EXCP_NONE; > -} > -#endif > - > static RISCVException fs(CPURISCVState *env, int csrno) > { > #if !defined(CONFIG_USER_ONLY) > @@ -399,6 +363,60 @@ static RISCVException sstateen(CPURISCVState *env, int csrno) > return RISCV_EXCP_NONE; > } > > +static RISCVException sstc(CPURISCVState *env, int csrno) > +{ > + RISCVCPU *cpu = env_archcpu(env); > + bool hmode_check = false; > + > + if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { > + 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; > + } > + > + /* > + * No need of separate function for rv32 as menvcfg stores both menvcfg > + * menvcfgh for RV32. > + */ > + if (!(get_field(env->mcounteren, COUNTEREN_TM) && > + get_field(env->menvcfg, MENVCFG_STCE))) { > + return RISCV_EXCP_ILLEGAL_INST; > + } > + > + if (riscv_cpu_virt_enabled(env)) { > + if (!(get_field(env->hcounteren, COUNTEREN_TM) && > + get_field(env->henvcfg, HENVCFG_STCE))) { > + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > + } > + } > + > + return RISCV_EXCP_NONE; > +} > + > +static RISCVException sstc_32(CPURISCVState *env, int csrno) > +{ > + if (riscv_cpu_mxl(env) != MXL_RV32) { > + return RISCV_EXCP_ILLEGAL_INST; > + } > + > + return sstc(env, csrno); > +} > + > /* Checks if PointerMasking registers could be accessed */ > static RISCVException pointer_masking(CPURISCVState *env, int csrno) > { > @@ -943,60 +961,6 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno, > return RISCV_EXCP_NONE; > } > > -static RISCVException sstc(CPURISCVState *env, int csrno) > -{ > - RISCVCPU *cpu = env_archcpu(env); > - bool hmode_check = false; > - > - if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { > - 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; > - } > - > - /* > - * No need of separate function for rv32 as menvcfg stores both menvcfg > - * menvcfgh for RV32. > - */ > - if (!(get_field(env->mcounteren, COUNTEREN_TM) && > - get_field(env->menvcfg, MENVCFG_STCE))) { > - return RISCV_EXCP_ILLEGAL_INST; > - } > - > - if (riscv_cpu_virt_enabled(env)) { > - if (!(get_field(env->hcounteren, COUNTEREN_TM) && > - get_field(env->henvcfg, HENVCFG_STCE))) { > - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > - } > - } > - > - return RISCV_EXCP_NONE; > -} > - > -static RISCVException sstc_32(CPURISCVState *env, int csrno) > -{ > - if (riscv_cpu_mxl(env) != MXL_RV32) { > - return RISCV_EXCP_ILLEGAL_INST; > - } > - > - return sstc(env, csrno); > -} > - > static RISCVException read_vstimecmp(CPURISCVState *env, int csrno, > target_ulong *val) > { > @@ -1944,6 +1908,39 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, > return RISCV_EXCP_NONE; > } > > +static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, > + uint64_t bit) > +{ > + bool virt = riscv_cpu_virt_enabled(env); > + RISCVCPU *cpu = env_archcpu(env); > + > + if (env->priv == PRV_M || !cpu->cfg.ext_smstateen) { > + return RISCV_EXCP_NONE; > + } > + > + if (!(env->mstateen[index] & bit)) { > + return RISCV_EXCP_ILLEGAL_INST; > + } > + > + if (virt) { > + if (!(env->hstateen[index] & bit)) { > + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > + } > + > + if (env->priv == PRV_U && !(env->sstateen[index] & bit)) { > + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; > + } > + } > + > + if (env->priv == PRV_U && riscv_has_ext(env, RVS)) { > + if (!(env->sstateen[index] & bit)) { > + return RISCV_EXCP_ILLEGAL_INST; > + } > + } > + > + return RISCV_EXCP_NONE; > +} > + > static RISCVException read_senvcfg(CPURISCVState *env, int csrno, > target_ulong *val) > {
diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 785f6f4d45..3a7e0217e2 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -40,42 +40,6 @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops) csr_ops[csrno & (CSR_TABLE_SIZE - 1)] = *ops; } -/* Predicates */ -#if !defined(CONFIG_USER_ONLY) -static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, - uint64_t bit) -{ - bool virt = riscv_cpu_virt_enabled(env); - RISCVCPU *cpu = env_archcpu(env); - - if (env->priv == PRV_M || !cpu->cfg.ext_smstateen) { - return RISCV_EXCP_NONE; - } - - if (!(env->mstateen[index] & bit)) { - return RISCV_EXCP_ILLEGAL_INST; - } - - if (virt) { - if (!(env->hstateen[index] & bit)) { - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; - } - - if (env->priv == PRV_U && !(env->sstateen[index] & bit)) { - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; - } - } - - if (env->priv == PRV_U && riscv_has_ext(env, RVS)) { - if (!(env->sstateen[index] & bit)) { - return RISCV_EXCP_ILLEGAL_INST; - } - } - - return RISCV_EXCP_NONE; -} -#endif - static RISCVException fs(CPURISCVState *env, int csrno) { #if !defined(CONFIG_USER_ONLY) @@ -399,6 +363,60 @@ static RISCVException sstateen(CPURISCVState *env, int csrno) return RISCV_EXCP_NONE; } +static RISCVException sstc(CPURISCVState *env, int csrno) +{ + RISCVCPU *cpu = env_archcpu(env); + bool hmode_check = false; + + if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { + 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; + } + + /* + * No need of separate function for rv32 as menvcfg stores both menvcfg + * menvcfgh for RV32. + */ + if (!(get_field(env->mcounteren, COUNTEREN_TM) && + get_field(env->menvcfg, MENVCFG_STCE))) { + return RISCV_EXCP_ILLEGAL_INST; + } + + if (riscv_cpu_virt_enabled(env)) { + if (!(get_field(env->hcounteren, COUNTEREN_TM) && + get_field(env->henvcfg, HENVCFG_STCE))) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + } + + return RISCV_EXCP_NONE; +} + +static RISCVException sstc_32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) != MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return sstc(env, csrno); +} + /* Checks if PointerMasking registers could be accessed */ static RISCVException pointer_masking(CPURISCVState *env, int csrno) { @@ -943,60 +961,6 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException sstc(CPURISCVState *env, int csrno) -{ - RISCVCPU *cpu = env_archcpu(env); - bool hmode_check = false; - - if (!cpu->cfg.ext_sstc || !env->rdtime_fn) { - 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; - } - - /* - * No need of separate function for rv32 as menvcfg stores both menvcfg - * menvcfgh for RV32. - */ - if (!(get_field(env->mcounteren, COUNTEREN_TM) && - get_field(env->menvcfg, MENVCFG_STCE))) { - return RISCV_EXCP_ILLEGAL_INST; - } - - if (riscv_cpu_virt_enabled(env)) { - if (!(get_field(env->hcounteren, COUNTEREN_TM) && - get_field(env->henvcfg, HENVCFG_STCE))) { - return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; - } - } - - return RISCV_EXCP_NONE; -} - -static RISCVException sstc_32(CPURISCVState *env, int csrno) -{ - if (riscv_cpu_mxl(env) != MXL_RV32) { - return RISCV_EXCP_ILLEGAL_INST; - } - - return sstc(env, csrno); -} - static RISCVException read_vstimecmp(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1944,6 +1908,39 @@ static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static RISCVException smstateen_acc_ok(CPURISCVState *env, int index, + uint64_t bit) +{ + bool virt = riscv_cpu_virt_enabled(env); + RISCVCPU *cpu = env_archcpu(env); + + if (env->priv == PRV_M || !cpu->cfg.ext_smstateen) { + return RISCV_EXCP_NONE; + } + + if (!(env->mstateen[index] & bit)) { + return RISCV_EXCP_ILLEGAL_INST; + } + + if (virt) { + if (!(env->hstateen[index] & bit)) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + + if (env->priv == PRV_U && !(env->sstateen[index] & bit)) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + } + + if (env->priv == PRV_U && riscv_has_ext(env, RVS)) { + if (!(env->sstateen[index] & bit)) { + return RISCV_EXCP_ILLEGAL_INST; + } + } + + return RISCV_EXCP_NONE; +} + static RISCVException read_senvcfg(CPURISCVState *env, int csrno, target_ulong *val) {