From 8f9e052c93fc52023f1a8754d7c6b2c9bc393286 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 28 Feb 2021 19:51:00 +0000 Subject: [PATCH] thumb32: Implement ADD (imm, T3) --- src/frontend/A32/decoder/thumb32.inc | 2 +- ...b32_data_processing_modified_immediate.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 6ba2e3ce..8ca26531 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -63,7 +63,7 @@ INST(thumb32_ORN_imm, "ORN (imm)", "11110v00011Snnnn0vvvdd INST(thumb32_TEQ_imm, "TEQ (imm)", "11110v001001nnnn0vvv1111vvvvvvvv") INST(thumb32_EOR_imm, "EOR (imm)", "11110v00100Snnnn0vvvddddvvvvvvvv") INST(thumb32_CMN_imm, "CMN (imm)", "11110v010001nnnn0vvv1111vvvvvvvv") -//INST(thumb32_ADD_imm_1, "ADD (imm)", "11110-01000-----0---------------") +INST(thumb32_ADD_imm_1, "ADD (imm)", "11110v01000Snnnn0vvvddddvvvvvvvv") //INST(thumb32_ADC_imm, "ADC (imm)", "11110-01010-----0---------------") //INST(thumb32_SBC_imm, "SBC (imm)", "11110-01011-----0---------------") //INST(thumb32_CMP_imm, "CMP (imm)", "11110-011011----0---1111--------") diff --git a/src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp b/src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp index 361cd858..cd9ef2b3 100644 --- a/src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp +++ b/src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp @@ -173,4 +173,23 @@ bool ThumbTranslatorVisitor::thumb32_CMN_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8 return true; } +bool ThumbTranslatorVisitor::thumb32_ADD_imm_1(Imm<1> i, bool S, Reg n, Imm<3> imm3, Reg d, Imm<8> imm8) { + ASSERT_MSG(!(d == Reg::PC && S), "Decode error"); + if ((d == Reg::PC && !S) || n == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto imm32 = ThumbExpandImm(i, imm3, imm8); + const auto result = ir.AddWithCarry(ir.GetRegister(n), ir.Imm32(imm32), 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 ccf6b91e..7b3269fa 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -159,6 +159,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_TEQ_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8> imm8); bool thumb32_EOR_imm(Imm<1> i, bool S, Reg n, Imm<3> imm3, Reg d, Imm<8> imm8); bool thumb32_CMN_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8> imm8); + bool thumb32_ADD_imm_1(Imm<1> i, bool S, Reg n, Imm<3> imm3, Reg d, Imm<8> imm8); // thumb32 data processing (plain binary immediate) instructions. bool thumb32_MOVT(Imm<1> imm1, Imm<4> imm4, Imm<3> imm3, Reg d, Imm<8> imm8);