As ssp holds a pointer, fix to 64 bits in size and make sure stores from
TCG use the correct size to avoid problems on big endian hosts.
Signed-off-by: Anton Johansson <anjo@rev.ng>
---
target/riscv/cpu.h | 2 +-
target/riscv/machine.c | 2 +-
target/riscv/insn_trans/trans_rvzicfiss.c.inc | 18 +++++++++++++-----
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index ffc2c1b424..1c544bc260 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -255,7 +255,7 @@ struct CPUArchState {
/* elp state for zicfilp extension */
bool elp;
/* shadow stack register for zicfiss extension */
- target_ulong ssp;
+ uint64_t ssp;
/* env place holder for extra word 2 during unwind */
target_ulong excp_uw2;
/* sw check code for sw check exception */
diff --git a/target/riscv/machine.c b/target/riscv/machine.c
index 9a2fd3267d..b95d432e0e 100644
--- a/target/riscv/machine.c
+++ b/target/riscv/machine.c
@@ -393,7 +393,7 @@ static const VMStateDescription vmstate_ssp = {
.minimum_version_id = 1,
.needed = ssp_needed,
.fields = (const VMStateField[]) {
- VMSTATE_UINTTL(env.ssp, RISCVCPU),
+ VMSTATE_UINT64(env.ssp, RISCVCPU),
VMSTATE_END_OF_LIST()
}
};
diff --git a/target/riscv/insn_trans/trans_rvzicfiss.c.inc b/target/riscv/insn_trans/trans_rvzicfiss.c.inc
index b0096adcd0..4333854979 100644
--- a/target/riscv/insn_trans/trans_rvzicfiss.c.inc
+++ b/target/riscv/insn_trans/trans_rvzicfiss.c.inc
@@ -32,7 +32,9 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a)
TCGLabel *skip = gen_new_label();
uint32_t tmp = (get_xl(ctx) == MXL_RV64) ? 8 : 4;
TCGv data = tcg_temp_new();
- tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp));
+ TCGv_i64 wide_addr = tcg_temp_new_i64();
+ tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_trunc_i64_tl(addr, wide_addr);
decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO);
tcg_gen_qemu_ld_tl(data, addr, SS_MMU_INDEX(ctx),
mxl_memop(ctx) | MO_ALIGN);
@@ -44,7 +46,8 @@ static bool trans_sspopchk(DisasContext *ctx, arg_sspopchk *a)
tcg_constant_i32(RISCV_EXCP_SW_CHECK));
gen_set_label(skip);
tcg_gen_addi_tl(addr, addr, tmp);
- tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_ext_tl_i64(wide_addr, addr);
+ tcg_gen_st_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp));
return true;
}
@@ -58,12 +61,15 @@ static bool trans_sspush(DisasContext *ctx, arg_sspush *a)
TCGv addr = tcg_temp_new();
int tmp = (get_xl(ctx) == MXL_RV64) ? -8 : -4;
TCGv data = get_gpr(ctx, a->rs2, EXT_NONE);
+ TCGv_i64 wide_addr = tcg_temp_new_i64();
decode_save_opc(ctx, RISCV_UW2_ALWAYS_STORE_AMO);
- tcg_gen_ld_tl(addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_trunc_i64_tl(addr, wide_addr);
tcg_gen_addi_tl(addr, addr, tmp);
tcg_gen_qemu_st_tl(data, addr, SS_MMU_INDEX(ctx),
mxl_memop(ctx) | MO_ALIGN);
- tcg_gen_st_tl(addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_ext_tl_i64(wide_addr, addr);
+ tcg_gen_st_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp));
return true;
}
@@ -75,7 +81,9 @@ static bool trans_ssrdp(DisasContext *ctx, arg_ssrdp *a)
}
TCGv dest = dest_gpr(ctx, a->rd);
- tcg_gen_ld_tl(dest, tcg_env, offsetof(CPURISCVState, ssp));
+ TCGv_i64 wide_addr = tcg_temp_new_i64();
+ tcg_gen_ld_i64(wide_addr, tcg_env, offsetof(CPURISCVState, ssp));
+ tcg_gen_trunc_i64_tl(dest, wide_addr);
gen_set_gpr(ctx, a->rd, dest);
return true;
--
2.51.0