early-access version 1475
This commit is contained in:
11
externals/dynarmic/src/common/bit_util.h
vendored
11
externals/dynarmic/src/common/bit_util.h
vendored
@@ -218,18 +218,23 @@ constexpr T RotateRight(T value, size_t amount) {
|
||||
return static_cast<T>((x >> amount) | (x << (BitSize<T>() - amount)));
|
||||
}
|
||||
|
||||
constexpr u16 Swap16(u16 value) {
|
||||
constexpr u32 SwapHalves32(u32 value) {
|
||||
return ((value & 0xFFFF0000U) >> 16) |
|
||||
((value & 0x0000FFFFU) << 16);
|
||||
}
|
||||
|
||||
constexpr u16 SwapBytes16(u16 value) {
|
||||
return static_cast<u16>(u32{value} >> 8 | u32{value} << 8);
|
||||
}
|
||||
|
||||
constexpr u32 Swap32(u32 value) {
|
||||
constexpr u32 SwapBytes32(u32 value) {
|
||||
return ((value & 0xFF000000U) >> 24) |
|
||||
((value & 0x00FF0000U) >> 8) |
|
||||
((value & 0x0000FF00U) << 8) |
|
||||
((value & 0x000000FFU) << 24);
|
||||
}
|
||||
|
||||
constexpr u64 Swap64(u64 value) {
|
||||
constexpr u64 SwapBytes64(u64 value) {
|
||||
return ((value & 0xFF00000000000000ULL) >> 56) |
|
||||
((value & 0x00FF000000000000ULL) >> 40) |
|
||||
((value & 0x0000FF0000000000ULL) >> 24) |
|
||||
|
@@ -54,20 +54,38 @@ std::string DisassembleX64(const void* begin, const void* end) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string DisassembleAArch32([[maybe_unused]] u32 instruction, [[maybe_unused]] u64 pc) {
|
||||
std::string DisassembleAArch32([[maybe_unused]] bool is_thumb, [[maybe_unused]] u32 pc, [[maybe_unused]] const u8* instructions, [[maybe_unused]] size_t length) {
|
||||
std::string result;
|
||||
|
||||
#ifdef DYNARMIC_USE_LLVM
|
||||
LLVMInitializeARMTargetInfo();
|
||||
LLVMInitializeARMTargetMC();
|
||||
LLVMInitializeARMDisassembler();
|
||||
LLVMDisasmContextRef llvm_ctx = LLVMCreateDisasm("armv8-arm", nullptr, 0, nullptr, nullptr);
|
||||
LLVMDisasmContextRef llvm_ctx = LLVMCreateDisasm(is_thumb ? "thumbv8-arm" : "armv8-arm", nullptr, 0, nullptr, nullptr);
|
||||
LLVMSetDisasmOptions(llvm_ctx, LLVMDisassembler_Option_AsmPrinterVariant);
|
||||
|
||||
char buffer[80];
|
||||
size_t inst_size = LLVMDisasmInstruction(llvm_ctx, (u8*)&instruction, sizeof(instruction), pc, buffer, sizeof(buffer));
|
||||
result = inst_size > 0 ? buffer : "<invalid instruction>";
|
||||
result += '\n';
|
||||
char buffer[1024];
|
||||
while (length) {
|
||||
size_t inst_size = LLVMDisasmInstruction(llvm_ctx, const_cast<u8*>(instructions), length, pc, buffer, sizeof(buffer));
|
||||
|
||||
result += fmt::format("{:08x} ", pc);
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (i < inst_size) {
|
||||
result += fmt::format("{:02x}", instructions[inst_size - i - 1]);
|
||||
} else {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
result += inst_size > 0 ? buffer : "<invalid instruction>";
|
||||
result += '\n';
|
||||
|
||||
if (inst_size == 0) inst_size = is_thumb ? 2 : 4;
|
||||
if (length <= inst_size) break;
|
||||
|
||||
pc += inst_size;
|
||||
instructions += inst_size;
|
||||
length -= inst_size;
|
||||
}
|
||||
|
||||
LLVMDisasmDispose(llvm_ctx);
|
||||
#else
|
||||
|
@@ -12,7 +12,7 @@
|
||||
namespace Dynarmic::Common {
|
||||
|
||||
std::string DisassembleX64(const void* pos, const void* end);
|
||||
std::string DisassembleAArch32(u32 instruction, u64 pc = 0);
|
||||
std::string DisassembleAArch32(bool is_thumb, u32 pc, const u8* instructions, size_t length);
|
||||
std::string DisassembleAArch64(u32 instruction, u64 pc = 0);
|
||||
|
||||
} // namespace Dynarmic::Common
|
||||
|
Reference in New Issue
Block a user