mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
target/riscv: Enable PC-relative translation
Add a base pc_save for PC-relative translation(CF_PCREL). Diable the directly sync pc from tb by riscv_cpu_synchronize_from_tb. Use gen_pc_plus_diff to get the pc-relative address. Enable CF_PCREL in System mode. Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-Id: <20230526072124.298466-7-liweiwei@iscas.ac.cn> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
parent
227fb82f99
commit
356c13f94d
4 changed files with 74 additions and 20 deletions
|
@ -38,7 +38,9 @@ static bool trans_lui(DisasContext *ctx, arg_lui *a)
|
|||
|
||||
static bool trans_auipc(DisasContext *ctx, arg_auipc *a)
|
||||
{
|
||||
gen_set_gpri(ctx, a->rd, a->imm + ctx->base.pc_next);
|
||||
TCGv target_pc = dest_gpr(ctx, a->rd);
|
||||
gen_pc_plus_diff(target_pc, ctx, a->imm);
|
||||
gen_set_gpr(ctx, a->rd, target_pc);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -52,6 +54,7 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
|
|||
{
|
||||
TCGLabel *misaligned = NULL;
|
||||
TCGv target_pc = tcg_temp_new();
|
||||
TCGv succ_pc = dest_gpr(ctx, a->rd);
|
||||
|
||||
tcg_gen_addi_tl(target_pc, get_gpr(ctx, a->rs1, EXT_NONE), a->imm);
|
||||
tcg_gen_andi_tl(target_pc, target_pc, (target_ulong)-2);
|
||||
|
@ -68,7 +71,9 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
|
|||
tcg_gen_brcondi_tl(TCG_COND_NE, t0, 0x0, misaligned);
|
||||
}
|
||||
|
||||
gen_set_gpri(ctx, a->rd, ctx->pc_succ_insn);
|
||||
gen_pc_plus_diff(succ_pc, ctx, ctx->cur_insn_len);
|
||||
gen_set_gpr(ctx, a->rd, succ_pc);
|
||||
|
||||
tcg_gen_mov_tl(cpu_pc, target_pc);
|
||||
lookup_and_goto_ptr(ctx);
|
||||
|
||||
|
@ -158,6 +163,7 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond)
|
|||
TCGLabel *l = gen_new_label();
|
||||
TCGv src1 = get_gpr(ctx, a->rs1, EXT_SIGN);
|
||||
TCGv src2 = get_gpr(ctx, a->rs2, EXT_SIGN);
|
||||
target_ulong orig_pc_save = ctx->pc_save;
|
||||
|
||||
if (get_xl(ctx) == MXL_RV128) {
|
||||
TCGv src1h = get_gprh(ctx, a->rs1);
|
||||
|
@ -171,6 +177,7 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond)
|
|||
tcg_gen_brcond_tl(cond, src1, src2, l);
|
||||
}
|
||||
gen_goto_tb(ctx, 1, ctx->cur_insn_len);
|
||||
ctx->pc_save = orig_pc_save;
|
||||
|
||||
gen_set_label(l); /* branch taken */
|
||||
|
||||
|
@ -183,6 +190,7 @@ static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond)
|
|||
} else {
|
||||
gen_goto_tb(ctx, 0, a->imm);
|
||||
}
|
||||
ctx->pc_save = -1;
|
||||
ctx->base.is_jmp = DISAS_NORETURN;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -302,7 +302,9 @@ static bool trans_cm_jalt(DisasContext *ctx, arg_cm_jalt *a)
|
|||
|
||||
/* c.jt vs c.jalt depends on the index. */
|
||||
if (a->index >= 32) {
|
||||
gen_set_gpri(ctx, xRA, ctx->pc_succ_insn);
|
||||
TCGv succ_pc = dest_gpr(ctx, xRA);
|
||||
gen_pc_plus_diff(succ_pc, ctx, ctx->cur_insn_len);
|
||||
gen_set_gpr(ctx, xRA, succ_pc);
|
||||
}
|
||||
|
||||
tcg_gen_lookup_and_goto_ptr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue