A32: Introduce PreCodeReadHook (#763)

* A32: Introduce PreCodeReadHook

* A32: Invert code read hook return value
This commit is contained in:
kynex7510 2023-11-16 23:23:27 +01:00 committed by GitHub
parent 0df09e2f6b
commit 9d1bc6ecc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 1 deletions

View file

@ -30,6 +30,11 @@ IR::Block TranslateArm(LocationDescriptor descriptor, TranslateCallbacks* tcb, c
const u32 arm_pc = visitor.ir.current_location.PC(); const u32 arm_pc = visitor.ir.current_location.PC();
u64 ticks_for_instruction = 1; u64 ticks_for_instruction = 1;
if (!tcb->PreCodeReadHook(false, arm_pc, visitor.ir)) {
should_continue = false;
break;
}
if (const auto arm_instruction = tcb->MemoryReadCode(arm_pc)) { if (const auto arm_instruction = tcb->MemoryReadCode(arm_pc)) {
visitor.current_instruction_size = 4; visitor.current_instruction_size = 4;

View file

@ -18,7 +18,13 @@ struct TranslateCallbacks {
// Memory must be interpreted as little endian. // Memory must be interpreted as little endian.
virtual std::optional<std::uint32_t> MemoryReadCode(VAddr vaddr) = 0; virtual std::optional<std::uint32_t> MemoryReadCode(VAddr vaddr) = 0;
// Thus function is called before the instruction at pc is interpreted. // This function is called before the instruction at pc is read.
// IR code can be emitted by the callee prior to instruction handling.
// By returning false the callee precludes the translation of the instruction;
// in such case the callee is responsible for setting the terminal.
virtual bool PreCodeReadHook(bool is_thumb, VAddr pc, A32::IREmitter& ir) = 0;
// This function is called before the instruction at pc is interpreted.
// IR code can be emitted by the callee prior to translation of the instruction. // IR code can be emitted by the callee prior to translation of the instruction.
virtual void PreCodeTranslationHook(bool is_thumb, VAddr pc, A32::IREmitter& ir) = 0; virtual void PreCodeTranslationHook(bool is_thumb, VAddr pc, A32::IREmitter& ir) = 0;

View file

@ -111,6 +111,11 @@ IR::Block TranslateThumb(LocationDescriptor descriptor, TranslateCallbacks* tcb,
const u32 arm_pc = visitor.ir.current_location.PC(); const u32 arm_pc = visitor.ir.current_location.PC();
u64 ticks_for_instruction = 1; u64 ticks_for_instruction = 1;
if (!tcb->PreCodeReadHook(true, arm_pc, visitor.ir)) {
should_continue = false;
break;
}
if (const auto maybe_instruction = ReadThumbInstruction(arm_pc, tcb)) { if (const auto maybe_instruction = ReadThumbInstruction(arm_pc, tcb)) {
const auto [thumb_instruction, inst_size] = *maybe_instruction; const auto [thumb_instruction, inst_size] = *maybe_instruction;
const bool is_thumb_16 = inst_size == ThumbInstSize::Thumb16; const bool is_thumb_16 = inst_size == ThumbInstSize::Thumb16;

View file

@ -65,6 +65,12 @@ struct UserCallbacks : public TranslateCallbacks {
// Memory must be interpreted as little endian. // Memory must be interpreted as little endian.
std::optional<std::uint32_t> MemoryReadCode(VAddr vaddr) override { return MemoryRead32(vaddr); } std::optional<std::uint32_t> MemoryReadCode(VAddr vaddr) override { return MemoryRead32(vaddr); }
// This function is called before the instruction at pc is read.
// IR code can be emitted by the callee prior to instruction handling.
// By returning true the callee precludes the translation of the instruction;
// in such case the callee is responsible for setting the terminal.
bool PreCodeReadHook(bool /*is_thumb*/, VAddr /*pc*/, A32::IREmitter& /*ir*/) override { return true; }
// Thus function is called before the instruction at pc is interpreted. // Thus function is called before the instruction at pc is interpreted.
// IR code can be emitted by the callee prior to translation of the instruction. // IR code can be emitted by the callee prior to translation of the instruction.
void PreCodeTranslationHook(bool /*is_thumb*/, VAddr /*pc*/, A32::IREmitter& /*ir*/) override {} void PreCodeTranslationHook(bool /*is_thumb*/, VAddr /*pc*/, A32::IREmitter& /*ir*/) override {}