From af33155ef80fe4ca323c3132f088ec69db085419 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 6 Mar 2021 19:39:37 +0000 Subject: [PATCH] thumb32: Implement ADD (reg) --- src/frontend/A32/decoder/thumb32.inc | 2 +- ...umb32_data_processing_shifted_register.cpp | 19 +++++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 62fe7bc4..83d1fab7 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -40,7 +40,7 @@ INST(thumb32_TEQ_reg, "TEQ (reg)", "111010101001nnnn0vvv11 INST(thumb32_EOR_reg, "EOR (reg)", "11101010100Snnnn0vvvddddvvttmmmm") INST(thumb32_PKH, "PKH", "111010101100nnnn0vvvddddvvt0mmmm") INST(thumb32_CMN_reg, "CMN (reg)", "111010110001nnnn0vvv1111vvttmmmm") -//INST(thumb32_ADD_reg, "ADD (reg)", "11101011000---------------------") +INST(thumb32_ADD_reg, "ADD (reg)", "11101011000Snnnn0vvvddddvvttmmmm") //INST(thumb32_ADC_reg, "ADC (reg)", "11101011010---------------------") //INST(thumb32_SBC_reg, "SBC (reg)", "11101011011---------------------") //INST(thumb32_CMP_reg, "CMP (reg)", "111010111011--------1111--------") diff --git a/src/frontend/A32/translate/impl/thumb32_data_processing_shifted_register.cpp b/src/frontend/A32/translate/impl/thumb32_data_processing_shifted_register.cpp index 2156e17e..eef1ab31 100644 --- a/src/frontend/A32/translate/impl/thumb32_data_processing_shifted_register.cpp +++ b/src/frontend/A32/translate/impl/thumb32_data_processing_shifted_register.cpp @@ -185,4 +185,23 @@ bool ThumbTranslatorVisitor::thumb32_CMN_reg(Reg n, Imm<3> imm3, Imm<2> imm2, Sh return true; } +bool ThumbTranslatorVisitor::thumb32_ADD_reg(bool S, Reg n, Imm<3> imm3, Reg d, Imm<2> imm2, ShiftType type, Reg m) { + ASSERT_MSG(!(d == Reg::PC && S), "Decode error"); + + if ((d == Reg::PC && !S) || n == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto shifted = EmitImmShift(ir.GetRegister(m), type, imm3, imm2, ir.GetCFlag()); + const auto result = ir.AddWithCarry(ir.GetRegister(n), shifted.result, ir.Imm1(0)); + ir.SetRegister(d, result.result); + if (S) { + ir.SetNFlag(ir.MostSignificantBit(result.result)); + ir.SetZFlag(ir.IsZero(result.result)); + ir.SetCFlag(result.carry); + ir.SetVFlag(result.overflow); + } + return true; +} + } // namespace Dynarmic::A32 diff --git a/src/frontend/A32/translate/impl/translate_thumb.h b/src/frontend/A32/translate/impl/translate_thumb.h index b6ff5749..1a025b7d 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -183,6 +183,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_EOR_reg(bool S, Reg n, Imm<3> imm3, Reg d, Imm<2> imm2, ShiftType type, Reg m); bool thumb32_PKH(Reg n, Imm<3> imm3, Reg d, Imm<2> imm2, Imm<1> tb, Reg m); bool thumb32_CMN_reg(Reg n, Imm<3> imm3, Imm<2> imm2, ShiftType type, Reg m); + bool thumb32_ADD_reg(bool S, Reg n, Imm<3> imm3, Reg d, Imm<2> imm2, ShiftType type, Reg m); // thumb32 data processing (modified immediate) instructions bool thumb32_TST_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8> imm8);