diff --git a/.gitmodules b/.gitmodules index adfb268a2..08f05c797 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "third_party/libav-bin"] path = third_party/libav-bin url = https://github.com/DrChat/xenia-libav-bin.git +[submodule "third_party/capstone"] + path = third_party/capstone + url = https://github.com/xenia-project/capstone.git diff --git a/build/Xenia.Cpp.x64.Common.props b/build/Xenia.Cpp.x64.Common.props index c63850297..a62e7acbe 100644 --- a/build/Xenia.Cpp.x64.Common.props +++ b/build/Xenia.Cpp.x64.Common.props @@ -10,7 +10,7 @@ true $(SolutionDir)\third_party\flatbuffers\include\;$(SolutionDir)\third_party\gflags\src\;$(SolutionDir)\src\;$(SolutionDir)\third_party;$(SolutionDir)\ - GLEW_STATIC=1;GLEW_MX=1;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32;_WIN64=1;_AMD64=1;MICROPROFILE_MAX_THREADS=128;%(PreprocessorDefinitions) + GLEW_STATIC=1;GLEW_MX=1;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;WIN32;_WIN64=1;_AMD64=1;MICROPROFILE_MAX_THREADS=128;CAPSTONE_X86_ATT_DISABLE;CAPSTONE_DIET_NO;CAPSTONE_X86_REDUCE_NO;CAPSTONE_HAS_X86;CAPSTONE_USE_SYS_DYN_MEM;%(PreprocessorDefinitions) Level4 true MultiThreadedDLL diff --git a/build/Xenia.Cpp.x64.Release.props b/build/Xenia.Cpp.x64.Release.props index fed1ffb46..42a0a181d 100644 --- a/build/Xenia.Cpp.x64.Release.props +++ b/build/Xenia.Cpp.x64.Release.props @@ -13,7 +13,7 @@ false false AdvancedVectorExtensions - NDEBUG;_STATIC_CPPLIB;%(PreprocessorDefinitions) + NDEBUG;%(PreprocessorDefinitions) MultiThreaded true diff --git a/libxenia.vcxproj b/libxenia.vcxproj index 1b3de68d2..c7a93d683 100644 --- a/libxenia.vcxproj +++ b/libxenia.vcxproj @@ -204,6 +204,61 @@ + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + + + CompileAsCpp + CompileAsCpp + CompileAsCpp + @@ -412,6 +467,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -444,6 +519,15 @@ + + + + + + + + + {0CE149F6-41C3-4224-9E57-C02E8C7CD312} @@ -502,7 +586,7 @@ Level3 Disabled BEA_ENGINE_STATIC=1;_LIB;%(PreprocessorDefinitions) - $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;%(AdditionalIncludeDirectories) + $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;$(SolutionDir)\third_party\capstone\include\;%(AdditionalIncludeDirectories) Windows @@ -518,8 +602,8 @@ Level3 Disabled - BEA_ENGINE_STATIC=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;%(AdditionalIncludeDirectories) + BEA_ENGINE_STATIC=1;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;$(SolutionDir)\third_party\capstone\include\;%(AdditionalIncludeDirectories) Windows @@ -537,8 +621,8 @@ MaxSpeed true true - BEA_ENGINE_STATIC=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;%(AdditionalIncludeDirectories) + BEA_ENGINE_STATIC=1;_LIB;%(PreprocessorDefinitions) + $(SolutionDir)\third_party\libav-bin\include\;$(SolutionDir)\third_party\beaengine\include\;$(SolutionDir)\third_party\llvm\include\;$(SolutionDir)\third_party\capstone\include\;%(AdditionalIncludeDirectories) Windows diff --git a/libxenia.vcxproj.filters b/libxenia.vcxproj.filters index d02907f53..851054935 100644 --- a/libxenia.vcxproj.filters +++ b/libxenia.vcxproj.filters @@ -149,6 +149,18 @@ {d1405e1d-d9b0-4d8d-89ce-29d43698c415} + + {49d9a353-9cc1-4ca3-95a1-9db2bd2d0eca} + + + {56f75ad9-d903-475a-a68c-0f7892e24808} + + + {23674cd7-7387-4947-baa5-5216f6a08830} + + + {00596876-a323-4570-a5fb-71343024d429} + @@ -724,6 +736,39 @@ src\xenia\kernel + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + src\xenia\gpu @@ -1386,6 +1431,66 @@ src\xenia\base + + third_party\capstone\include + + + third_party\capstone\include + + + third_party\capstone\include + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + @@ -1433,5 +1538,32 @@ src\xenia\debug\proto + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + \ No newline at end of file diff --git a/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj b/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj new file mode 100644 index 000000000..8be633075 --- /dev/null +++ b/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj @@ -0,0 +1,140 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {5AE85790-F2EA-4077-8953-825E9C0AADE9} + v4.5 + ManagedCProj + XeniaDebugNative + + + + DynamicLibrary + true + v140 + true + Unicode + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + false + + + + Level2 + Disabled + true + CompileAsCpp + $(SolutionDir)\third_party\capstone\include\;%(AdditionalIncludeDirectories) + + + true + + + + + + + Level2 + true + CompileAsCpp + $(SolutionDir)\third_party\capstone\include\;%(AdditionalIncludeDirectories) + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj.filters b/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj.filters new file mode 100644 index 000000000..cb7801187 --- /dev/null +++ b/src/Xenia.Debug.Native/Xenia.Debug.Native.vcxproj.filters @@ -0,0 +1,170 @@ + + + + + {f0462696-4abd-4dc9-8290-aafff5ca6158} + + + {1a3b1c52-32cb-477e-9008-f2f9a6171c8c} + + + {5fb51b29-2462-49de-89c1-e332aafa0ca9} + + + {15585f2e-55a4-4af5-bb24-6d6649d74ed0} + + + {920bc92f-e430-4c48-86dd-1a697c9a5fd1} + + + {d26b9a34-94fd-493b-841e-2ae2561bc584} + + + {c9adeb1a-189d-4877-9bbd-c9948401b63e} + + + {4e8ea226-a18e-413a-95bd-6b3e5f4f8460} + + + {fc34f72d-e3c6-4fe7-9645-7b422ffaad57} + + + {e530b0a2-9f4a-4b85-aee8-7185042251b1} + + + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone\include + + + third_party\capstone\include + + + third_party\capstone\include + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + src\Xenia.Debug.Native + + + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + src\Xenia.Debug.Native + + + src\Xenia.Debug.Native + + + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + third_party\capstone\arch\X86 + + + \ No newline at end of file diff --git a/src/Xenia.Debug.Native/assembly_info.cc b/src/Xenia.Debug.Native/assembly_info.cc new file mode 100644 index 000000000..97169e5b7 --- /dev/null +++ b/src/Xenia.Debug.Native/assembly_info.cc @@ -0,0 +1,45 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +using namespace System; +using namespace System::Reflection; +using namespace System::Runtime::CompilerServices; +using namespace System::Runtime::InteropServices; +using namespace System::Security::Permissions; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly:AssemblyTitleAttribute(L"Xenia.Debug.Native")]; +[assembly:AssemblyDescriptionAttribute(L"")]; +[assembly:AssemblyConfigurationAttribute(L"")]; +[assembly:AssemblyCompanyAttribute(L"")]; +[assembly:AssemblyProductAttribute(L"Xenia.Debug.Native")]; +[assembly:AssemblyCopyrightAttribute(L"Copyright (c) Ben Vanik 2015")]; +[assembly:AssemblyTrademarkAttribute(L"")]; +[assembly:AssemblyCultureAttribute(L"")]; + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the value or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly:AssemblyVersionAttribute("1.0.*")]; + +[assembly:ComVisible(false)]; + +[assembly:CLSCompliantAttribute(true)]; \ No newline at end of file diff --git a/src/Xenia.Debug.Native/x64_disassembler.cc b/src/Xenia.Debug.Native/x64_disassembler.cc new file mode 100644 index 000000000..7405a1aad --- /dev/null +++ b/src/Xenia.Debug.Native/x64_disassembler.cc @@ -0,0 +1,52 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#include "Xenia.Debug.Native/x64_disassembler.h" + +#include "third_party/capstone/include/capstone.h" +#include "third_party/capstone/include/x86.h" + +namespace Xenia { +namespace Debug { +namespace Native { + +using namespace System; +using namespace System::Text; + +X64Disassembler::X64Disassembler() + : capstone_handle_(0), string_builder_(gcnew StringBuilder(16 * 1024)) { + uintptr_t capstone_handle; + if (cs_open(CS_ARCH_X86, CS_MODE_64, &capstone_handle) != CS_ERR_OK) { + System::Diagnostics::Debug::Fail("Failed to initialize capstone"); + return; + } + capstone_handle_ = capstone_handle; + cs_option(capstone_handle_, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL); + cs_option(capstone_handle_, CS_OPT_DETAIL, CS_OPT_OFF); +} + +X64Disassembler::~X64Disassembler() { + if (capstone_handle_) { + pin_ptr capstone_handle = &capstone_handle_; + cs_close(capstone_handle); + } +} + +String^ X64Disassembler::GenerateString(IntPtr code_address, + size_t code_size) { + string_builder_->Clear(); + + // + + return string_builder_->ToString(); +} + +} // namespace Native +} // namespace Debug +} // namespace Xenia diff --git a/src/Xenia.Debug.Native/x64_disassembler.h b/src/Xenia.Debug.Native/x64_disassembler.h new file mode 100644 index 000000000..5ac5ecc52 --- /dev/null +++ b/src/Xenia.Debug.Native/x64_disassembler.h @@ -0,0 +1,38 @@ +/** + ****************************************************************************** + * Xenia : Xbox 360 Emulator Research Project * + ****************************************************************************** + * Copyright 2015 Ben Vanik. All rights reserved. * + * Released under the BSD license - see LICENSE in the root for more details. * + ****************************************************************************** + */ + +#ifndef XENIA_DEBUG_NATIVE_X64_DISASSEMBLER_H_ +#define XENIA_DEBUG_NATIVE_X64_DISASSEMBLER_H_ + +#include + +namespace Xenia { +namespace Debug { +namespace Native { + +using namespace System; +using namespace System::Text; + +public ref class X64Disassembler { + public: + X64Disassembler(); + ~X64Disassembler(); + + String^ GenerateString(IntPtr code_address, size_t code_size); + + private: + uintptr_t capstone_handle_; + StringBuilder^ string_builder_; +}; + +} // namespace Native +} // namespace Debug +} // namespace Xenia + +#endif // XENIA_DEBUG_NATIVE_X64_DISASSEMBLER_H_ diff --git a/src/Xenia.Debug/Function.cs b/src/Xenia.Debug/Function.cs index 58671dba5..a597233bc 100644 --- a/src/Xenia.Debug/Function.cs +++ b/src/Xenia.Debug/Function.cs @@ -113,7 +113,17 @@ namespace Xenia.Debug { DisasmMachineCode = DisasmMachineCode.Replace("\n", "\r\n"); } + DisassembleX64(); + OnChanged(); } + + private static Native.X64Disassembler disassembler = new Native.X64Disassembler(); + + private void DisassembleX64() { + var str = disassembler.GenerateString(IntPtr.Zero, 0); + System.Diagnostics.Debug.WriteLine(str); + disassembler.Dispose(); + } } } diff --git a/src/Xenia.Debug/Xenia.Debug.csproj b/src/Xenia.Debug/Xenia.Debug.csproj index 8bd96dc71..ccd66481b 100644 --- a/src/Xenia.Debug/Xenia.Debug.csproj +++ b/src/Xenia.Debug/Xenia.Debug.csproj @@ -125,6 +125,12 @@ + + + {5ae85790-f2ea-4077-8953-825e9c0aade9} + Xenia.Debug.Native + +