From ad05c35a7e98a36b051d41002acb22e440361b6e Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Fri, 29 Jun 2018 15:19:49 +0200 Subject: [PATCH] Implement CheckBlock for x64 --- core/rec-x64/rec_x64.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/rec-x64/rec_x64.cpp b/core/rec-x64/rec_x64.cpp index 1d46ef16f..fb178658c 100644 --- a/core/rec-x64/rec_x64.cpp +++ b/core/rec-x64/rec_x64.cpp @@ -81,6 +81,11 @@ u32* GetRegPtr(u32 reg) return Sh4_int_GetRegisterPtr((Sh4RegType)reg); } +void ngen_blockcheckfail(u32 pc) { + printf("X64 JIT: SMC invalidation at %08X\n", pc); + rdv_BlockCheckFail(pc); +} + class BlockCompiler : public Xbyak::CodeGenerator{ public: @@ -157,7 +162,39 @@ public: movss(dword[rax], rs); \ } while (0) + void CheckBlock(RuntimeBlockInfo* block) { + mov(ecx,block->addr); + + s32 sz=block->sh4_code_size; + u32 sa=block->addr; + + while(sz>0) { + void* ptr=(void*)GetMemPtr(sa,4); + if (ptr) { + mov(rax, reinterpret_cast(ptr)); + + if (sz==2) { + mov(edx, *(u16*)ptr); + cmp(word[rax],dx); + } + else { + mov(edx, *(u32*)ptr); + cmp(dword[rax],edx); + } + jne(reinterpret_cast(&ngen_blockcheckfail)); + } + sz-=4; + sa+=4; + } + + } + void compile(RuntimeBlockInfo* block, bool force_checks, bool reset, bool staging, bool optimise) { + + if (force_checks) { + CheckBlock(block); + } + mov(rax, (size_t)&cycle_counter); sub(dword[rax], block->guest_cycles);