From 0d0f4b1b4fa40bec6323d0f1bca2176d1ac99ac0 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 19 Aug 2016 00:29:51 +0100 Subject: [PATCH] translate_arm/load_store: Correct implementation for LDM* --- src/frontend/translate/translate_arm/load_store.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frontend/translate/translate_arm/load_store.cpp b/src/frontend/translate/translate_arm/load_store.cpp index 17f75e20..75aa220b 100644 --- a/src/frontend/translate/translate_arm/load_store.cpp +++ b/src/frontend/translate/translate_arm/load_store.cpp @@ -645,7 +645,7 @@ static bool LDMHelper(IREmitter& ir, bool W, Reg n, RegList list, IR::Value star address = ir.Add(address, ir.Imm32(4)); } } - if (W) { + if (W && !Common::Bit(RegNumber(n), list)) { ir.SetRegister(n, writeback_address); } if (Common::Bit<15>(list)) { @@ -677,7 +677,7 @@ bool ArmTranslatorVisitor::arm_LDMDA(Cond cond, bool W, Reg n, RegList list) { // LDMDA {!}, if (ConditionPassed(cond)) { auto start_address = ir.Sub(ir.GetRegister(n), ir.Imm32(u32(4 * Common::BitCount(list) - 4))); - auto writeback_address = ir.Add(start_address, ir.Imm32(4)); + auto writeback_address = ir.Sub(start_address, ir.Imm32(4)); return LDMHelper(ir, W, n, list, start_address, writeback_address); } return true; @@ -750,7 +750,7 @@ bool ArmTranslatorVisitor::arm_STMDA(Cond cond, bool W, Reg n, RegList list) { // STMDA {!}, if (ConditionPassed(cond)) { auto start_address = ir.Sub(ir.GetRegister(n), ir.Imm32(u32(4 * Common::BitCount(list) - 4))); - auto writeback_address = ir.Add(start_address, ir.Imm32(4)); + auto writeback_address = ir.Sub(start_address, ir.Imm32(4)); return STMHelper(ir, W, n, list, start_address, writeback_address); } return true;