mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-04 10:02:58 +00:00
callbacks: Read code using MemoryReadCode callback
This commit is contained in:
@@ -103,7 +103,7 @@ private:
|
||||
if (block)
|
||||
return *block;
|
||||
|
||||
IR::Block ir_block = Arm::Translate(descriptor, callbacks.MemoryRead32);
|
||||
IR::Block ir_block = Arm::Translate(descriptor, callbacks.MemoryReadCode);
|
||||
Optimization::GetSetElimination(ir_block);
|
||||
Optimization::DeadCodeElimination(ir_block);
|
||||
Optimization::VerificationPass(ir_block);
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
namespace Dynarmic {
|
||||
namespace Arm {
|
||||
|
||||
IR::Block TranslateArm(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32);
|
||||
IR::Block TranslateThumb(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32);
|
||||
IR::Block TranslateArm(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code);
|
||||
IR::Block TranslateThumb(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code);
|
||||
|
||||
IR::Block Translate(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32) {
|
||||
return (descriptor.TFlag() ? TranslateThumb : TranslateArm)(descriptor, memory_read_32);
|
||||
IR::Block Translate(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code) {
|
||||
return (descriptor.TFlag() ? TranslateThumb : TranslateArm)(descriptor, memory_read_code);
|
||||
}
|
||||
|
||||
} // namespace Arm
|
||||
|
||||
@@ -18,15 +18,15 @@ namespace Arm {
|
||||
|
||||
struct LocationDescriptor;
|
||||
|
||||
using MemoryRead32FuncType = u32 (*)(u32 vaddr);
|
||||
using MemoryReadCodeFuncType = u32 (*)(u32 vaddr);
|
||||
|
||||
/**
|
||||
* This function translates instructions in memory into our intermediate representation.
|
||||
* @param descriptor The starting location of the basic block. Includes information like PC, Thumb state, &c.
|
||||
* @param memory_read_32 The function we should use to read emulated memory.
|
||||
* @param memory_read_code The function we should use to read emulated memory.
|
||||
* @return A translated basic block in the intermediate representation.
|
||||
*/
|
||||
IR::Block Translate(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32);
|
||||
IR::Block Translate(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code);
|
||||
|
||||
} // namespace Arm
|
||||
} // namespace Dynarmic
|
||||
|
||||
@@ -28,13 +28,13 @@ static bool CondCanContinue(ConditionalState cond_state, const IR::IREmitter& ir
|
||||
return std::all_of(ir.block.begin(), ir.block.end(), [](const IR::Inst& inst) { return !inst.WritesToCPSR(); });
|
||||
}
|
||||
|
||||
IR::Block TranslateArm(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32) {
|
||||
IR::Block TranslateArm(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code) {
|
||||
ArmTranslatorVisitor visitor{descriptor};
|
||||
|
||||
bool should_continue = true;
|
||||
while (should_continue && CondCanContinue(visitor.cond_state, visitor.ir)) {
|
||||
const u32 arm_pc = visitor.ir.current_location.PC();
|
||||
const u32 arm_instruction = memory_read_32(arm_pc);
|
||||
const u32 arm_instruction = memory_read_code(arm_pc);
|
||||
|
||||
if (auto vfp_decoder = DecodeVFP2<ArmTranslatorVisitor>(arm_instruction)) {
|
||||
should_continue = vfp_decoder->call(visitor, arm_instruction);
|
||||
|
||||
@@ -836,8 +836,8 @@ enum class ThumbInstSize {
|
||||
Thumb16, Thumb32
|
||||
};
|
||||
|
||||
std::tuple<u32, ThumbInstSize> ReadThumbInstruction(u32 arm_pc, MemoryRead32FuncType memory_read_32) {
|
||||
u32 first_part = memory_read_32(arm_pc & 0xFFFFFFFC);
|
||||
std::tuple<u32, ThumbInstSize> ReadThumbInstruction(u32 arm_pc, MemoryReadCodeFuncType memory_read_code) {
|
||||
u32 first_part = memory_read_code(arm_pc & 0xFFFFFFFC);
|
||||
if ((arm_pc & 0x2) != 0)
|
||||
first_part >>= 16;
|
||||
first_part &= 0xFFFF;
|
||||
@@ -850,7 +850,7 @@ std::tuple<u32, ThumbInstSize> ReadThumbInstruction(u32 arm_pc, MemoryRead32Func
|
||||
// 32-bit thumb instruction
|
||||
// These always start with 0b11101, 0b11110 or 0b11111.
|
||||
|
||||
u32 second_part = memory_read_32((arm_pc + 2) & 0xFFFFFFFC);
|
||||
u32 second_part = memory_read_code((arm_pc + 2) & 0xFFFFFFFC);
|
||||
if (((arm_pc + 2) & 0x2) != 0)
|
||||
second_part >>= 16;
|
||||
second_part &= 0xFFFF;
|
||||
@@ -860,7 +860,7 @@ std::tuple<u32, ThumbInstSize> ReadThumbInstruction(u32 arm_pc, MemoryRead32Func
|
||||
|
||||
} // local namespace
|
||||
|
||||
IR::Block TranslateThumb(IR::LocationDescriptor descriptor, MemoryRead32FuncType memory_read_32) {
|
||||
IR::Block TranslateThumb(IR::LocationDescriptor descriptor, MemoryReadCodeFuncType memory_read_code) {
|
||||
ThumbTranslatorVisitor visitor{descriptor};
|
||||
|
||||
bool should_continue = true;
|
||||
@@ -869,7 +869,7 @@ IR::Block TranslateThumb(IR::LocationDescriptor descriptor, MemoryRead32FuncType
|
||||
|
||||
u32 thumb_instruction;
|
||||
ThumbInstSize inst_size;
|
||||
std::tie(thumb_instruction, inst_size) = ReadThumbInstruction(arm_pc, memory_read_32);
|
||||
std::tie(thumb_instruction, inst_size) = ReadThumbInstruction(arm_pc, memory_read_code);
|
||||
|
||||
if (inst_size == ThumbInstSize::Thumb16) {
|
||||
auto decoder = DecodeThumb16<ThumbTranslatorVisitor>(static_cast<u16>(thumb_instruction));
|
||||
|
||||
Reference in New Issue
Block a user