static RISCVException read_mcyclecfg(CPURISCVState *env, int csrno,
target_ulong *val)
{
- *val = env->mcyclecfg;
+ bool rv32 = riscv_cpu_mxl(env) == MXL_RV32;
+ *val = extract64(env->mcyclecfg, 0, rv32 ? 32 : 64);
return RISCV_EXCP_NONE;
}
uint64_t inh_avail_mask;
if (riscv_cpu_mxl(env) == MXL_RV32) {
- env->mcyclecfg = val;
+ env->mcyclecfg = deposit64(env->mcyclecfg, 0, 32, val);
} else {
/* Set xINH fields if priv mode supported */
inh_avail_mask = ~MHPMEVENT_FILTER_MASK | MCYCLECFG_BIT_MINH;
static RISCVException read_mcyclecfgh(CPURISCVState *env, int csrno,
target_ulong *val)
{
- *val = env->mcyclecfgh;
+ *val = extract64(env->mcyclecfg, 32, 32);
return RISCV_EXCP_NONE;
}
inh_avail_mask |= (riscv_has_ext(env, RVH) &&
riscv_has_ext(env, RVS)) ? MCYCLECFGH_BIT_VSINH : 0;
- env->mcyclecfgh = val & inh_avail_mask;
+ env->mcyclecfg = deposit64(env->mcyclecfg, 32, 32, val & inh_avail_mask);
return RISCV_EXCP_NONE;
}
uint64_t cfg_val = 0;
if (counter_idx == 0) {
- cfg_val = upper_half ? ((uint64_t)env->mcyclecfgh << 32) :
- env->mcyclecfg;
+ cfg_val = env->mcyclecfg;
} else if (counter_idx == 2) {
cfg_val = upper_half ? ((uint64_t)env->minstretcfgh << 32) :
env->minstretcfg;
}
static int rmw_cd_ctr_cfg(CPURISCVState *env, int cfg_index, target_ulong *val,
- target_ulong new_val, target_ulong wr_mask)
+ target_ulong new_val, uint64_t wr_mask)
{
+ /*
+ * wr_mask is 64-bit so upper 32 bits of mcyclecfg and minstretcfg
+ * are retained.
+ */
switch (cfg_index) {
case 0: /* CYCLECFG */
if (wr_mask) {
}
static int rmw_cd_ctr_cfgh(CPURISCVState *env, int cfg_index, target_ulong *val,
- target_ulong new_val, target_ulong wr_mask)
+ target_ulong new_val, target_ulong wr_mask)
{
+ uint64_t cfgh;
if (riscv_cpu_mxl(env) != MXL_RV32) {
return RISCV_EXCP_ILLEGAL_INST;
switch (cfg_index) {
case 0: /* CYCLECFGH */
+ cfgh = extract64(env->mcyclecfg, 32, 32);
if (wr_mask) {
wr_mask &= ~MCYCLECFGH_BIT_MINH;
- env->mcyclecfgh = (new_val & wr_mask) |
- (env->mcyclecfgh & ~wr_mask);
+ cfgh = (new_val & wr_mask) | (cfgh & ~wr_mask);
+ env->mcyclecfg = deposit64(env->mcyclecfg, 32, 32, cfgh);
} else {
- *val = env->mcyclecfgh;
+ *val = cfgh;
}
break;
case 2: /* INSTRETCFGH */