Commit 828808f5ece20fd606218e000139799921c89d93

Authored by malc
1 parent becfc390

Fix alignment problem with some 64bit load/store instructions

LD/STD/LWA require displacement to be multiple of 4, provide
tcg_out_ldsta which checks the supplied displacement and falls
back on indexed variant when the check fails. All uses of
LD/STD/LWA outside of tcg_out_ldst appear to be safe.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5670 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 16 additions and 5 deletions
tcg/ppc64/tcg-target.c
@@ -497,6 +497,17 @@ static void tcg_out_ldst (TCGContext *s, int ret, int addr, @@ -497,6 +497,17 @@ static void tcg_out_ldst (TCGContext *s, int ret, int addr,
497 } 497 }
498 } 498 }
499 499
  500 +static void tcg_out_ldsta (TCGContext *s, int ret, int addr,
  501 + int offset, int op1, int op2)
  502 +{
  503 + if (offset == (int16_t) (offset & ~3))
  504 + tcg_out32 (s, op1 | RT (ret) | RA (addr) | (offset & 0xffff));
  505 + else {
  506 + tcg_out_movi (s, TCG_TYPE_I64, 0, offset);
  507 + tcg_out32 (s, op2 | RT (ret) | RA (addr) | RB (0));
  508 + }
  509 +}
  510 +
500 static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target) 511 static void tcg_out_b (TCGContext *s, int mask, tcg_target_long target)
501 { 512 {
502 tcg_target_long disp; 513 tcg_target_long disp;
@@ -860,7 +871,7 @@ static void tcg_out_ld (TCGContext *s, TCGType type, int ret, int arg1, @@ -860,7 +871,7 @@ static void tcg_out_ld (TCGContext *s, TCGType type, int ret, int arg1,
860 if (type == TCG_TYPE_I32) 871 if (type == TCG_TYPE_I32)
861 tcg_out_ldst (s, ret, arg1, arg2, LWZ, LWZX); 872 tcg_out_ldst (s, ret, arg1, arg2, LWZ, LWZX);
862 else 873 else
863 - tcg_out_ldst (s, ret, arg1, arg2, LD, LDX); 874 + tcg_out_ldsta (s, ret, arg1, arg2, LD, LDX);
864 } 875 }
865 876
866 static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1, 877 static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
@@ -869,7 +880,7 @@ static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1, @@ -869,7 +880,7 @@ static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
869 if (type == TCG_TYPE_I32) 880 if (type == TCG_TYPE_I32)
870 tcg_out_ldst (s, arg, arg1, arg2, STW, STWX); 881 tcg_out_ldst (s, arg, arg1, arg2, STW, STWX);
871 else 882 else
872 - tcg_out_ldst (s, arg, arg1, arg2, STD, STDX); 883 + tcg_out_ldsta (s, arg, arg1, arg2, STD, STDX);
873 } 884 }
874 885
875 static void ppc_addi32 (TCGContext *s, int rt, int ra, tcg_target_long si) 886 static void ppc_addi32 (TCGContext *s, int rt, int ra, tcg_target_long si)
@@ -1088,10 +1099,10 @@ static void tcg_out_op (TCGContext *s, int opc, const TCGArg *args, @@ -1088,10 +1099,10 @@ static void tcg_out_op (TCGContext *s, int opc, const TCGArg *args,
1088 tcg_out_ldst (s, args[0], args[1], args[2], LWZ, LWZX); 1099 tcg_out_ldst (s, args[0], args[1], args[2], LWZ, LWZX);
1089 break; 1100 break;
1090 case INDEX_op_ld32s_i64: 1101 case INDEX_op_ld32s_i64:
1091 - tcg_out_ldst (s, args[0], args[1], args[2], LWA, LWAX); 1102 + tcg_out_ldsta (s, args[0], args[1], args[2], LWA, LWAX);
1092 break; 1103 break;
1093 case INDEX_op_ld_i64: 1104 case INDEX_op_ld_i64:
1094 - tcg_out_ldst (s, args[0], args[1], args[2], LD, LDX); 1105 + tcg_out_ldsta (s, args[0], args[1], args[2], LD, LDX);
1095 break; 1106 break;
1096 case INDEX_op_st8_i32: 1107 case INDEX_op_st8_i32:
1097 case INDEX_op_st8_i64: 1108 case INDEX_op_st8_i64:
@@ -1106,7 +1117,7 @@ static void tcg_out_op (TCGContext *s, int opc, const TCGArg *args, @@ -1106,7 +1117,7 @@ static void tcg_out_op (TCGContext *s, int opc, const TCGArg *args,
1106 tcg_out_ldst (s, args[0], args[1], args[2], STW, STWX); 1117 tcg_out_ldst (s, args[0], args[1], args[2], STW, STWX);
1107 break; 1118 break;
1108 case INDEX_op_st_i64: 1119 case INDEX_op_st_i64:
1109 - tcg_out_ldst (s, args[0], args[1], args[2], STD, STDX); 1120 + tcg_out_ldsta (s, args[0], args[1], args[2], STD, STDX);
1110 break; 1121 break;
1111 1122
1112 case INDEX_op_add_i32: 1123 case INDEX_op_add_i32: