From b17a5d336522161f98ac55aafbecd8476e6d2494 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 2 May 2019 22:32:40 -0400 Subject: [PATCH] A32: Implement Thumb-16's variant of BKPT --- src/frontend/A32/decoder/thumb16.h | 2 +- src/frontend/A32/disassembler/disassembler_thumb.cpp | 4 ++++ src/frontend/A32/translate/translate_thumb.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/frontend/A32/decoder/thumb16.h b/src/frontend/A32/decoder/thumb16.h index eeb1880a..6fddedd9 100644 --- a/src/frontend/A32/decoder/thumb16.h +++ b/src/frontend/A32/decoder/thumb16.h @@ -99,7 +99,7 @@ std::optional>> DecodeThumb16(u16 INST(&V::thumb16_REV, "REV", "1011101000mmmddd"), // v6 INST(&V::thumb16_REV16, "REV16", "1011101001mmmddd"), // v6 INST(&V::thumb16_REVSH, "REVSH", "1011101011mmmddd"), // v6 - //INST(&V::thumb16_BKPT, "BKPT", "10111110xxxxxxxx"), // v5 + INST(&V::thumb16_BKPT, "BKPT", "10111110xxxxxxxx"), // v5 // Store/Load multiple registers INST(&V::thumb16_STMIA, "STMIA", "11000nnnxxxxxxxx"), diff --git a/src/frontend/A32/disassembler/disassembler_thumb.cpp b/src/frontend/A32/disassembler/disassembler_thumb.cpp index 37e8719c..9ed44da0 100644 --- a/src/frontend/A32/disassembler/disassembler_thumb.cpp +++ b/src/frontend/A32/disassembler/disassembler_thumb.cpp @@ -292,6 +292,10 @@ public: return fmt::format("revsh {}, {}", d, m); } + std::string thumb16_BKPT(Imm<8> imm8) { + return fmt::format("bkpt #{}", imm8.ZeroExtend()); + } + std::string thumb16_STMIA(Reg n, RegList reg_list) { return fmt::format("stm {}!, {{{}}}", n, RegListToString(reg_list)); } diff --git a/src/frontend/A32/translate/translate_thumb.cpp b/src/frontend/A32/translate/translate_thumb.cpp index 1227cda5..e940184a 100644 --- a/src/frontend/A32/translate/translate_thumb.cpp +++ b/src/frontend/A32/translate/translate_thumb.cpp @@ -6,6 +6,8 @@ #include +#include + #include "common/assert.h" #include "common/bit_util.h" #include "frontend/imm.h" @@ -804,6 +806,13 @@ struct ThumbTranslatorVisitor final { return true; } + // BKPT # + bool thumb16_BKPT([[maybe_unused]] Imm<8> imm8) { + ir.ExceptionRaised(Exception::Breakpoint); + ir.SetTerm(IR::Term::CheckHalt{IR::Term::ReturnToDispatch{}}); + return false; + } + // STM !, bool thumb16_STMIA(Reg n, RegList reg_list) { auto address = ir.GetRegister(n);