From 62ecc2537e9a28750cbf035f5d78b2783bf8cd0a Mon Sep 17 00:00:00 2001 From: MerryMage Date: Fri, 7 May 2021 08:24:51 +0100 Subject: [PATCH] print_info: Add thumb mode --- tests/print_info.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/print_info.cpp b/tests/print_info.cpp index 9e20d3b7..494b9e54 100644 --- a/tests/print_info.cpp +++ b/tests/print_info.cpp @@ -15,6 +15,7 @@ #include #include +#include "common/bit_util.h" #include "common/common_types.h" #include "common/llvm_disassemble.h" #include "frontend/A32/decoder/arm.h" @@ -95,6 +96,29 @@ void PrintA64Instruction(u32 instruction) { fmt::print("{}\n", IR::DumpBlock(block)); } +void PrintThumbInstruction(u32 instruction) { + const size_t inst_size = (instruction >> 16) == 0 ? 2 : 4; + if (inst_size == 4) instruction = Common::SwapHalves32(instruction); + + fmt::print("{:08x} {}\n", instruction, Common::DisassembleAArch32(true, 0, (u8*)&instruction, inst_size)); + + const A32::LocationDescriptor location{0, A32::PSR{0x1F0}, {}}; + IR::Block block{location}; + const bool should_continue = A32::TranslateSingleInstruction(block, location, instruction); + fmt::print("should_continue: {}\n\n", should_continue); + fmt::print("IR:\n"); + fmt::print("{}\n", IR::DumpBlock(block)); + + Optimization::A32GetSetElimination(block); + Optimization::DeadCodeElimination(block); + Optimization::ConstantPropagation(block); + Optimization::DeadCodeElimination(block); + Optimization::IdentityRemovalPass(block); + + fmt::print("Optimized IR:\n"); + fmt::print("{}\n", IR::DumpBlock(block)); +} + class ExecEnv final : public Dynarmic::A32::UserCallbacks { public: u64 ticks_left = 0; @@ -259,7 +283,7 @@ void ExecuteA32Instruction(u32 instruction) { int main(int argc, char** argv) { if (argc < 3 || argc > 4) { - fmt::print("usage: {} [-exec]\n", argv[0]); + fmt::print("usage: {} [-exec]\n", argv[0]); return 1; } @@ -281,8 +305,10 @@ int main(int argc, char** argv) { PrintA32Instruction(instruction); } else if (strcmp(argv[1], "a64") == 0) { PrintA64Instruction(instruction); + } else if (strcmp(argv[1], "t32") == 0 || strcmp(argv[1], "t16") == 0 || strcmp(argv[1], "thumb") == 0) { + PrintThumbInstruction(instruction); } else { - fmt::print("Invalid mode: {}\nValid values: a32, a64\n", argv[1]); + fmt::print("Invalid mode: {}\nValid values: a32, a64, thumb\n", argv[1]); return 1; } @@ -294,8 +320,8 @@ int main(int argc, char** argv) { if (strcmp(argv[1], "a32") == 0) { ExecuteA32Instruction(instruction); - } else if (strcmp(argv[1], "a64") == 0) { - fmt::print("Executing a64 code not currently supported\n"); + } else { + fmt::print("Executing in this mode not currently supported\n"); return 1; } }