Revision | 4302bef9e17831902a7e7c8082cac1c8ed151759 (tree) |
---|---|
Time | 2022-01-21 14:52:57 |
Author | LIU Zhiwei <zhiwei_liu@c-sk...> |
Commiter | Alistair Francis |
target/riscv: Calculate address according to XLEN
Define one common function to compute a canonical address from a register
plus offset. Merge gen_pm_adjust_address into this function.
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20220120122050.41546-14-zhiwei_liu@c-sky.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
@@ -20,12 +20,11 @@ | ||
20 | 20 | |
21 | 21 | static bool gen_lr(DisasContext *ctx, arg_atomic *a, MemOp mop) |
22 | 22 | { |
23 | - TCGv src1 = get_gpr(ctx, a->rs1, EXT_ZERO); | |
23 | + TCGv src1 = get_address(ctx, a->rs1, 0); | |
24 | 24 | |
25 | 25 | if (a->rl) { |
26 | 26 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); |
27 | 27 | } |
28 | - src1 = gen_pm_adjust_address(ctx, src1); | |
29 | 28 | tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop); |
30 | 29 | if (a->aq) { |
31 | 30 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); |
@@ -44,8 +43,7 @@ static bool gen_sc(DisasContext *ctx, arg_atomic *a, MemOp mop) | ||
44 | 43 | TCGLabel *l1 = gen_new_label(); |
45 | 44 | TCGLabel *l2 = gen_new_label(); |
46 | 45 | |
47 | - src1 = get_gpr(ctx, a->rs1, EXT_ZERO); | |
48 | - src1 = gen_pm_adjust_address(ctx, src1); | |
46 | + src1 = get_address(ctx, a->rs1, 0); | |
49 | 47 | tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1); |
50 | 48 | |
51 | 49 | /* |
@@ -83,10 +81,9 @@ static bool gen_amo(DisasContext *ctx, arg_atomic *a, | ||
83 | 81 | MemOp mop) |
84 | 82 | { |
85 | 83 | TCGv dest = dest_gpr(ctx, a->rd); |
86 | - TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); | |
84 | + TCGv src1 = get_address(ctx, a->rs1, 0); | |
87 | 85 | TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); |
88 | 86 | |
89 | - src1 = gen_pm_adjust_address(ctx, src1); | |
90 | 87 | func(dest, src1, src2, ctx->mem_idx, mop); |
91 | 88 | |
92 | 89 | gen_set_gpr(ctx, a->rd, dest); |
@@ -25,14 +25,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a) | ||
25 | 25 | REQUIRE_FPU; |
26 | 26 | REQUIRE_EXT(ctx, RVD); |
27 | 27 | |
28 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
29 | - if (a->imm) { | |
30 | - TCGv temp = temp_new(ctx); | |
31 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
32 | - addr = temp; | |
33 | - } | |
34 | - addr = gen_pm_adjust_address(ctx, addr); | |
35 | - | |
28 | + addr = get_address(ctx, a->rs1, a->imm); | |
36 | 29 | tcg_gen_qemu_ld_i64(cpu_fpr[a->rd], addr, ctx->mem_idx, MO_TEUQ); |
37 | 30 | |
38 | 31 | mark_fs_dirty(ctx); |
@@ -46,16 +39,8 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a) | ||
46 | 39 | REQUIRE_FPU; |
47 | 40 | REQUIRE_EXT(ctx, RVD); |
48 | 41 | |
49 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
50 | - if (a->imm) { | |
51 | - TCGv temp = temp_new(ctx); | |
52 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
53 | - addr = temp; | |
54 | - } | |
55 | - addr = gen_pm_adjust_address(ctx, addr); | |
56 | - | |
42 | + addr = get_address(ctx, a->rs1, a->imm); | |
57 | 43 | tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUQ); |
58 | - | |
59 | 44 | return true; |
60 | 45 | } |
61 | 46 |
@@ -31,14 +31,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a) | ||
31 | 31 | REQUIRE_FPU; |
32 | 32 | REQUIRE_EXT(ctx, RVF); |
33 | 33 | |
34 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
35 | - if (a->imm) { | |
36 | - TCGv temp = temp_new(ctx); | |
37 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
38 | - addr = temp; | |
39 | - } | |
40 | - addr = gen_pm_adjust_address(ctx, addr); | |
41 | - | |
34 | + addr = get_address(ctx, a->rs1, a->imm); | |
42 | 35 | dest = cpu_fpr[a->rd]; |
43 | 36 | tcg_gen_qemu_ld_i64(dest, addr, ctx->mem_idx, MO_TEUL); |
44 | 37 | gen_nanbox_s(dest, dest); |
@@ -54,16 +47,8 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a) | ||
54 | 47 | REQUIRE_FPU; |
55 | 48 | REQUIRE_EXT(ctx, RVF); |
56 | 49 | |
57 | - addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
58 | - if (a->imm) { | |
59 | - TCGv temp = tcg_temp_new(); | |
60 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
61 | - addr = temp; | |
62 | - } | |
63 | - addr = gen_pm_adjust_address(ctx, addr); | |
64 | - | |
50 | + addr = get_address(ctx, a->rs1, a->imm); | |
65 | 51 | tcg_gen_qemu_st_i64(cpu_fpr[a->rs2], addr, ctx->mem_idx, MO_TEUL); |
66 | - | |
67 | 52 | return true; |
68 | 53 | } |
69 | 54 |
@@ -226,14 +226,7 @@ static bool trans_bgeu(DisasContext *ctx, arg_bgeu *a) | ||
226 | 226 | static bool gen_load_tl(DisasContext *ctx, arg_lb *a, MemOp memop) |
227 | 227 | { |
228 | 228 | TCGv dest = dest_gpr(ctx, a->rd); |
229 | - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
230 | - | |
231 | - if (a->imm) { | |
232 | - TCGv temp = temp_new(ctx); | |
233 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
234 | - addr = temp; | |
235 | - } | |
236 | - addr = gen_pm_adjust_address(ctx, addr); | |
229 | + TCGv addr = get_address(ctx, a->rs1, a->imm); | |
237 | 230 | |
238 | 231 | tcg_gen_qemu_ld_tl(dest, addr, ctx->mem_idx, memop); |
239 | 232 | gen_set_gpr(ctx, a->rd, dest); |
@@ -330,16 +323,9 @@ static bool trans_ldu(DisasContext *ctx, arg_ldu *a) | ||
330 | 323 | |
331 | 324 | static bool gen_store_tl(DisasContext *ctx, arg_sb *a, MemOp memop) |
332 | 325 | { |
333 | - TCGv addr = get_gpr(ctx, a->rs1, EXT_NONE); | |
326 | + TCGv addr = get_address(ctx, a->rs1, a->imm); | |
334 | 327 | TCGv data = get_gpr(ctx, a->rs2, EXT_NONE); |
335 | 328 | |
336 | - if (a->imm) { | |
337 | - TCGv temp = temp_new(ctx); | |
338 | - tcg_gen_addi_tl(temp, addr, a->imm); | |
339 | - addr = temp; | |
340 | - } | |
341 | - addr = gen_pm_adjust_address(ctx, addr); | |
342 | - | |
343 | 329 | tcg_gen_qemu_st_tl(data, addr, ctx->mem_idx, memop); |
344 | 330 | return true; |
345 | 331 | } |
@@ -390,21 +390,20 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
390 | 390 | ctx->base.is_jmp = DISAS_NORETURN; |
391 | 391 | } |
392 | 392 | |
393 | -/* | |
394 | - * Generates address adjustment for PointerMasking | |
395 | - */ | |
396 | -static TCGv gen_pm_adjust_address(DisasContext *s, TCGv src) | |
393 | +/* Compute a canonical address from a register plus offset. */ | |
394 | +static TCGv get_address(DisasContext *ctx, int rs1, int imm) | |
397 | 395 | { |
398 | - TCGv temp; | |
399 | - if (!s->pm_enabled) { | |
400 | - /* Load unmodified address */ | |
401 | - return src; | |
402 | - } else { | |
403 | - temp = temp_new(s); | |
404 | - tcg_gen_andc_tl(temp, src, pm_mask); | |
405 | - tcg_gen_or_tl(temp, temp, pm_base); | |
406 | - return temp; | |
396 | + TCGv addr = temp_new(ctx); | |
397 | + TCGv src1 = get_gpr(ctx, rs1, EXT_NONE); | |
398 | + | |
399 | + tcg_gen_addi_tl(addr, src1, imm); | |
400 | + if (ctx->pm_enabled) { | |
401 | + tcg_gen_and_tl(addr, addr, pm_mask); | |
402 | + tcg_gen_or_tl(addr, addr, pm_base); | |
403 | + } else if (get_xl(ctx) == MXL_RV32) { | |
404 | + tcg_gen_ext32u_tl(addr, addr); | |
407 | 405 | } |
406 | + return addr; | |
408 | 407 | } |
409 | 408 | |
410 | 409 | #ifndef CONFIG_USER_ONLY |