Skip to content

Commit cd95576

Browse files
committed
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20200706' into staging
Fix for ppc shifts Fix for non-parallel atomic ops # gpg: Signature made Mon 06 Jul 2020 19:49:08 BST # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "[email protected]" # gpg: Good signature from "Richard Henderson <[email protected]>" [full] # Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A 05C0 64DF 38E8 AF7E 215F * remotes/rth/tags/pull-tcg-20200706: tcg: Fix do_nonatomic_op_* vs signed operations tcg/ppc: Sanitize immediate shifts Signed-off-by: Peter Maydell <[email protected]>
2 parents eb2c66b + 852f933 commit cd95576

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

tcg/ppc/tcg-target.inc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,21 +2610,24 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
26102610

26112611
case INDEX_op_shl_i32:
26122612
if (const_args[2]) {
2613-
tcg_out_shli32(s, args[0], args[1], args[2]);
2613+
/* Limit immediate shift count lest we create an illegal insn. */
2614+
tcg_out_shli32(s, args[0], args[1], args[2] & 31);
26142615
} else {
26152616
tcg_out32(s, SLW | SAB(args[1], args[0], args[2]));
26162617
}
26172618
break;
26182619
case INDEX_op_shr_i32:
26192620
if (const_args[2]) {
2620-
tcg_out_shri32(s, args[0], args[1], args[2]);
2621+
/* Limit immediate shift count lest we create an illegal insn. */
2622+
tcg_out_shri32(s, args[0], args[1], args[2] & 31);
26212623
} else {
26222624
tcg_out32(s, SRW | SAB(args[1], args[0], args[2]));
26232625
}
26242626
break;
26252627
case INDEX_op_sar_i32:
26262628
if (const_args[2]) {
2627-
tcg_out32(s, SRAWI | RS(args[1]) | RA(args[0]) | SH(args[2]));
2629+
/* Limit immediate shift count lest we create an illegal insn. */
2630+
tcg_out32(s, SRAWI | RS(args[1]) | RA(args[0]) | SH(args[2] & 31));
26282631
} else {
26292632
tcg_out32(s, SRAW | SAB(args[1], args[0], args[2]));
26302633
}
@@ -2696,14 +2699,16 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
26962699

26972700
case INDEX_op_shl_i64:
26982701
if (const_args[2]) {
2699-
tcg_out_shli64(s, args[0], args[1], args[2]);
2702+
/* Limit immediate shift count lest we create an illegal insn. */
2703+
tcg_out_shli64(s, args[0], args[1], args[2] & 63);
27002704
} else {
27012705
tcg_out32(s, SLD | SAB(args[1], args[0], args[2]));
27022706
}
27032707
break;
27042708
case INDEX_op_shr_i64:
27052709
if (const_args[2]) {
2706-
tcg_out_shri64(s, args[0], args[1], args[2]);
2710+
/* Limit immediate shift count lest we create an illegal insn. */
2711+
tcg_out_shri64(s, args[0], args[1], args[2] & 63);
27072712
} else {
27082713
tcg_out32(s, SRD | SAB(args[1], args[0], args[2]));
27092714
}

tcg/tcg-op.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,8 +3189,9 @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGv addr, TCGv_i32 val,
31893189

31903190
memop = tcg_canonicalize_memop(memop, 0, 0);
31913191

3192-
tcg_gen_qemu_ld_i32(t1, addr, idx, memop & ~MO_SIGN);
3193-
gen(t2, t1, val);
3192+
tcg_gen_qemu_ld_i32(t1, addr, idx, memop);
3193+
tcg_gen_ext_i32(t2, val, memop);
3194+
gen(t2, t1, t2);
31943195
tcg_gen_qemu_st_i32(t2, addr, idx, memop);
31953196

31963197
tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop);
@@ -3232,8 +3233,9 @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val,
32323233

32333234
memop = tcg_canonicalize_memop(memop, 1, 0);
32343235

3235-
tcg_gen_qemu_ld_i64(t1, addr, idx, memop & ~MO_SIGN);
3236-
gen(t2, t1, val);
3236+
tcg_gen_qemu_ld_i64(t1, addr, idx, memop);
3237+
tcg_gen_ext_i64(t2, val, memop);
3238+
gen(t2, t1, t2);
32373239
tcg_gen_qemu_st_i64(t2, addr, idx, memop);
32383240

32393241
tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);

0 commit comments

Comments
 (0)