On 10/28/20 7:42 AM, Alistair Francis wrote: > +target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong address) > { > if (env->priv == PRV_M || > (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || > (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) && > get_field(env->hstatus, HSTATUS_HU))) { > + int mmu_idx = cpu_mmu_index(env, true) | > TB_FLAGS_PRIV_HYP_ACCESS_MASK; > + > + return cpu_lduw_mmuidx_ra(env, address, mmu_idx, GETPC()); > + } > + > + if (riscv_cpu_virt_enabled(env)) { > + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, > GETPC()); > + } else { > + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); > + } > + return 0; > +} > + > +target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong address) > +{ > + if (env->priv == PRV_M || > + (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || > + (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) && > + get_field(env->hstatus, HSTATUS_HU))) { > + int mmu_idx = cpu_mmu_index(env, true) | > TB_FLAGS_PRIV_HYP_ACCESS_MASK; > > + return cpu_ldl_mmuidx_ra(env, address, mmu_idx, GETPC()); > }
Do not replicate the PRV tests. My first suggestion is to compute this into TBFLAGS and test it at translate time, so that these functions just become the one cpu_ld* call. But failing that, at least split out the test + exception into a common helper function. r~