For privilege version 1.12 or newer, C always implies Zca. We can only
check ext_zca to allow 16-bit aligned PC addresses. For older privilege
versions, we only check C.
Signed-off-by: Yu-Ming Chang <yumin686@andestech.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <
174184718265.10540.
10120024221661781046-0@git.sr.ht>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
}
#endif
+static inline bool riscv_cpu_allow_16bit_insn(const RISCVCPUConfig *cfg,
+ target_long priv_ver,
+ uint32_t misa_ext)
+{
+ /* In priv spec version 1.12 or newer, C always implies Zca */
+ if (priv_ver >= PRIV_VERSION_1_12_0) {
+ return cfg->ext_zca;
+ } else {
+ return misa_ext & RVC;
+ }
+}
+
/*
* Encode LMUL to lmul as follows:
* LMUL vlmul lmul
tcg_gen_ext32s_tl(target_pc, target_pc);
}
- if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) {
+ if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr,
+ ctx->priv_ver,
+ ctx->misa_ext)) {
TCGv t0 = tcg_temp_new();
misaligned = gen_new_label();
gen_set_label(l); /* branch taken */
- if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca &&
+ if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr,
+ ctx->priv_ver,
+ ctx->misa_ext) &&
(a->imm & 0x3)) {
/* misaligned */
TCGv target_pc = tcg_temp_new();
}
target_ulong retpc = env->sepc;
- if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) {
+ if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg,
+ env->priv_ver,
+ env->misa_ext) && (retpc & 0x3)) {
riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
}
riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
}
- if (!riscv_has_ext(env, RVC) && (retpc & 0x3)) {
+ if (!riscv_cpu_allow_16bit_insn(&env_archcpu(env)->cfg,
+ env->priv_ver,
+ env->misa_ext) && (retpc & 0x3)) {
riscv_raise_exception(env, RISCV_EXCP_INST_ADDR_MIS, GETPC());
}
TCGv succ_pc = dest_gpr(ctx, rd);
/* check misaligned: */
- if (!has_ext(ctx, RVC) && !ctx->cfg_ptr->ext_zca) {
+ if (!riscv_cpu_allow_16bit_insn(ctx->cfg_ptr,
+ ctx->priv_ver,
+ ctx->misa_ext)) {
if ((imm & 0x3) != 0) {
TCGv target_pc = tcg_temp_new();
gen_pc_plus_diff(target_pc, ctx, imm);