From 4256d2148182271728a2811e4d3248253a66af10 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 25 May 2021 21:56:59 +0100 Subject: [PATCH] common: Add x64_disassemble --- src/dynarmic/CMakeLists.txt | 19 ++++++++------ src/dynarmic/common/x64_disassemble.cpp | 35 +++++++++++++++++++++++++ src/dynarmic/common/x64_disassemble.h | 14 ++++++++++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 src/dynarmic/common/x64_disassemble.cpp create mode 100644 src/dynarmic/common/x64_disassemble.h diff --git a/src/dynarmic/CMakeLists.txt b/src/dynarmic/CMakeLists.txt index 03769dad..5c85b08e 100644 --- a/src/dynarmic/CMakeLists.txt +++ b/src/dynarmic/CMakeLists.txt @@ -62,6 +62,8 @@ add_library(dynarmic common/u128.cpp common/u128.h common/variant_util.h + common/x64_disassemble.cpp + common/x64_disassemble.h frontend/A32/types.cpp frontend/A32/types.h frontend/A64/types.cpp @@ -99,12 +101,6 @@ add_library(dynarmic if ("A32" IN_LIST DYNARMIC_FRONTENDS) target_sources(dynarmic PRIVATE - interface/A32/a32.h - interface/A32/arch_version.h - interface/A32/config.h - interface/A32/coprocessor.h - interface/A32/coprocessor_util.h - interface/A32/disassembler.h frontend/A32/decoder/arm.h frontend/A32/decoder/arm.inc frontend/A32/decoder/asimd.h @@ -177,6 +173,12 @@ if ("A32" IN_LIST DYNARMIC_FRONTENDS) frontend/A32/translate/translate.h frontend/A32/translate/translate_arm.cpp frontend/A32/translate/translate_thumb.cpp + interface/A32/a32.h + interface/A32/arch_version.h + interface/A32/config.h + interface/A32/coprocessor.h + interface/A32/coprocessor_util.h + interface/A32/disassembler.h ir/opt/a32_constant_memory_reads_pass.cpp ir/opt/a32_get_set_elimination_pass.cpp ) @@ -286,9 +288,9 @@ if (ARCHITECTURE STREQUAL "x86_64") backend/x64/emit_x64_vector_saturation.cpp backend/x64/exception_handler.h backend/x64/exclusive_monitor.cpp + backend/x64/host_feature.h backend/x64/hostloc.cpp backend/x64/hostloc.h - backend/x64/host_feature.h backend/x64/jitstate_info.h backend/x64/oparg.h backend/x64/perf_map.cpp @@ -363,12 +365,13 @@ create_target_directory_groups(dynarmic) target_include_directories(dynarmic PUBLIC ..) target_compile_options(dynarmic PRIVATE ${DYNARMIC_CXX_FLAGS}) target_link_libraries(dynarmic - PRIVATE + PUBLIC boost fmt::fmt mp tsl::robin_map xbyak + Zydis $<$:${llvm_libs}> ) if (DYNARMIC_ENABLE_CPU_FEATURE_DETECTION) diff --git a/src/dynarmic/common/x64_disassemble.cpp b/src/dynarmic/common/x64_disassemble.cpp new file mode 100644 index 00000000..0cfb204d --- /dev/null +++ b/src/dynarmic/common/x64_disassemble.cpp @@ -0,0 +1,35 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2021 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#include "dynarmic/common/x64_disassemble.h" + +#include +#include + +#include "dynarmic/common/common_types.h" + +namespace Dynarmic::Common { + +void DumpDisassembledX64(const void* ptr, size_t size) { + ZydisDecoder decoder; + ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_ADDRESS_WIDTH_64); + + ZydisFormatter formatter; + ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL); + + size_t offset = 0; + ZydisDecodedInstruction instruction; + while (ZYAN_SUCCESS(ZydisDecoderDecodeBuffer(&decoder, (const char*)ptr + offset, size - offset, &instruction))) { + fmt::print("{:016x} ", (u64)ptr + offset); + + char buffer[256]; + ZydisFormatterFormatInstruction(&formatter, &instruction, buffer, sizeof(buffer), (u64)ptr + offset); + puts(buffer); + + offset += instruction.length; + } +} + +} // namespace Dynarmic::Common diff --git a/src/dynarmic/common/x64_disassemble.h b/src/dynarmic/common/x64_disassemble.h new file mode 100644 index 00000000..4b1e6660 --- /dev/null +++ b/src/dynarmic/common/x64_disassemble.h @@ -0,0 +1,14 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2021 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#pragma once + +#include "dynarmic/common/common_types.h" + +namespace Dynarmic::Common { + +void DumpDisassembledX64(const void* ptr, size_t size); + +} // namespace Dynarmic::Common