From 5bf676d93e6fc4e5212241a19d8cd371832892d3 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Thu, 18 Feb 2021 01:05:45 +0000 Subject: [PATCH] thumb32: Implement TST (immediate) --- src/CMakeLists.txt | 1 + src/frontend/A32/decoder/thumb32.inc | 2 +- ...b32_data_processing_modified_immediate.cpp | 24 +++++++++++++++++++ .../A32/translate/impl/translate_thumb.h | 3 +++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index acfe9a43..4b189ff0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -156,6 +156,7 @@ if ("A32" IN_LIST DYNARMIC_FRONTENDS) frontend/A32/translate/impl/thumb32_branch.cpp frontend/A32/translate/impl/thumb32_control.cpp frontend/A32/translate/impl/thumb32_data_processing_register.cpp + frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp frontend/A32/translate/impl/thumb32_long_multiply.cpp frontend/A32/translate/impl/thumb32_misc.cpp frontend/A32/translate/impl/thumb32_multiply.cpp diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index 32ce0960..05880d26 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -53,7 +53,7 @@ //INST(thumb32_RSB_reg, "RSB (reg)", "11101011110---------------------") // Data Processing (Modified Immediate) -//INST(thumb32_TST_imm, "TST (imm)", "11110-000001----0---1111--------") +INST(thumb32_TST_imm, "TST (imm)", "11110v000001nnnn0vvv1111vvvvvvvv") //INST(thumb32_AND_imm, "AND (imm)", "11110-00000-----0---------------") //INST(thumb32_BIC_imm, "BIC (imm)", "11110-00001-----0---------------") //INST(thumb32_MOV_imm, "MOV (imm)", "11110000010-11110---------------") 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 new file mode 100644 index 00000000..5f96e840 --- /dev/null +++ b/src/frontend/A32/translate/impl/thumb32_data_processing_modified_immediate.cpp @@ -0,0 +1,24 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2021 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#include "frontend/A32/translate/impl/translate_thumb.h" + +namespace Dynarmic::A32 { + +bool ThumbTranslatorVisitor::thumb32_TST_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8> imm8) { + if (n == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto imm_carry = ThumbExpandImm_C(rotate, imm8, ir.GetCFlag()); + const auto result = ir.And(ir.GetRegister(n), ir.Imm32(imm_carry.imm32)); + + ir.SetNFlag(ir.MostSignificantBit(result)); + ir.SetZFlag(ir.IsZero(result)); + ir.SetCFlag(imm_carry.carry); + 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 c29086bc..e8efffca 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -148,6 +148,9 @@ struct ThumbTranslatorVisitor final { bool thumb16_B_t1(Cond cond, Imm<8> imm8); bool thumb16_B_t2(Imm<11> imm11); + // thumb32 data processing (modified immediate) instructions + bool thumb32_TST_imm(Imm<1> i, Reg n, Imm<3> imm3, Imm<8> imm8); + // thumb32 miscellaneous control instructions bool thumb32_UDF();