diff --git a/src/frontend/A32/decoder/thumb32.inc b/src/frontend/A32/decoder/thumb32.inc index dc0dc136..acee99a4 100644 --- a/src/frontend/A32/decoder/thumb32.inc +++ b/src/frontend/A32/decoder/thumb32.inc @@ -199,7 +199,7 @@ INST(thumb32_SXTH, "SXTH", "11111010000011111111dd INST(thumb32_SXTAH, "SXTAH", "111110100000nnnn1111dddd10rrmmmm") INST(thumb32_UXTH, "UXTH", "11111010000111111111dddd10rrmmmm") INST(thumb32_UXTAH, "UXTAH", "111110100001nnnn1111dddd10rrmmmm") -//INST(thumb32_SXTB16, "SXTB16", "11111010001011111111----1-------") +INST(thumb32_SXTB16, "SXTB16", "11111010001011111111dddd10rrmmmm") //INST(thumb32_SXTAB16, "SXTAB16", "111110100010----1111----1-------") //INST(thumb32_UXTB16, "UXTB16", "11111010001111111111----1-------") //INST(thumb32_UXTAB16, "UXTAB16", "111110100011----1111----1-------") diff --git a/src/frontend/A32/translate/impl/thumb32_data_processing_register.cpp b/src/frontend/A32/translate/impl/thumb32_data_processing_register.cpp index 2ca195c7..0c5715fe 100644 --- a/src/frontend/A32/translate/impl/thumb32_data_processing_register.cpp +++ b/src/frontend/A32/translate/impl/thumb32_data_processing_register.cpp @@ -11,6 +11,20 @@ static IR::U32 Rotate(A32::IREmitter& ir, Reg m, SignExtendRotation rotate) { return ir.RotateRight(ir.GetRegister(m), ir.Imm8(rotate_by), ir.Imm1(0)).result; } +bool ThumbTranslatorVisitor::thumb32_SXTB16(Reg d, SignExtendRotation rotate, Reg m) { + if (d == Reg::PC || m == Reg::PC) { + return UnpredictableInstruction(); + } + + const auto rotated = Rotate(ir, m, rotate); + const auto low_byte = ir.And(rotated, ir.Imm32(0x00FF00FF)); + const auto sign_bit = ir.And(rotated, ir.Imm32(0x00800080)); + const auto result = ir.Or(low_byte, ir.Mul(sign_bit, ir.Imm32(0x1FE))); + + ir.SetRegister(d, result); + return true; +} + bool ThumbTranslatorVisitor::thumb32_SXTH(Reg d, SignExtendRotation rotate, Reg m) { if (d == Reg::PC || m == Reg::PC) { return UnpredictableInstruction(); diff --git a/src/frontend/A32/translate/impl/translate_thumb.h b/src/frontend/A32/translate/impl/translate_thumb.h index 33792a82..af2bf46d 100644 --- a/src/frontend/A32/translate/impl/translate_thumb.h +++ b/src/frontend/A32/translate/impl/translate_thumb.h @@ -122,6 +122,7 @@ struct ThumbTranslatorVisitor final { bool thumb32_UDF(); // thumb32 data processing (register) instructions + bool thumb32_SXTB16(Reg d, SignExtendRotation rotate, Reg m); bool thumb32_SXTH(Reg d, SignExtendRotation rotate, Reg m); bool thumb32_SXTAH(Reg n, Reg d, SignExtendRotation rotate, Reg m); bool thumb32_UXTH(Reg d, SignExtendRotation rotate, Reg m);