Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #356 from Sonicadvance1/Fix-MMUAnalyst
Fixes games that use the MMU to page in code(Rogue Leader).
  • Loading branch information
shuffle2 committed May 22, 2014
2 parents 6544d53 + cdec575 commit c4e60d5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 73 deletions.
24 changes: 2 additions & 22 deletions Source/Core/Core/PowerPC/Jit64/Jit.cpp
Expand Up @@ -406,9 +406,6 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
{
int blockSize = code_buf->GetSize();

// Memory exception on instruction fetch
bool memory_exception = false;

if (Core::g_CoreStartupParameter.bEnableDebugging)
{
// Comment out the following to disable breakpoints (speed-up)
Expand All @@ -420,21 +417,6 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
}
}

if (em_address == 0)
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}

if (Core::g_CoreStartupParameter.bMMU && (em_address & JIT_ICACHE_VMEM_BIT))
{
if (!Memory::TranslateAddress(em_address, Memory::FLAG_OPCODE))
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}
}

js.firstFPInstructionFound = false;
js.isLastInstruction = false;
js.blockStart = em_address;
Expand All @@ -448,9 +430,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
u32 nextPC = em_address;
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable instructions.
if (!memory_exception)
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);

nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);

PPCAnalyst::CodeOp *ops = code_buf->codebuffer;

Expand Down Expand Up @@ -678,7 +658,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
}
}

if (memory_exception)
if (code_block.m_memory_exception)
{
// Address of instruction could not be translated
MOV(32, M(&NPC), Imm32(js.compilerPC));
Expand Down
23 changes: 2 additions & 21 deletions Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp
Expand Up @@ -502,9 +502,6 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
{
int blockSize = code_buf->GetSize();

// Memory exception on instruction fetch
bool memory_exception = false;

if (Core::g_CoreStartupParameter.bEnableDebugging)
{
// Comment out the following to disable breakpoints (speed-up)
Expand All @@ -516,21 +513,6 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
}
}

if (em_address == 0)
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}

if (Core::g_CoreStartupParameter.bMMU && (em_address & JIT_ICACHE_VMEM_BIT))
{
if (!Memory::TranslateAddress(em_address, Memory::FLAG_OPCODE))
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}
}

js.isLastInstruction = false;
js.blockStart = em_address;
js.fifoBytesThisBlock = 0;
Expand All @@ -542,8 +524,7 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
u32 nextPC = em_address;
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable instructions.
if (!memory_exception)
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);

PPCAnalyst::CodeOp *ops = code_buf->codebuffer;

Expand Down Expand Up @@ -690,7 +671,7 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBloc
}
}

if (memory_exception)
if (code_block.m_memory_exception)
{
ibuild.EmitISIException(ibuild.EmitIntConst(em_address));
}
Expand Down
17 changes: 3 additions & 14 deletions Source/Core/Core/PowerPC/JitArm32/Jit.cpp
Expand Up @@ -300,8 +300,6 @@ void JitArm::Break(UGeckoInstruction inst)
const u8* JitArm::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBlock *b)
{
int blockSize = code_buf->GetSize();
// Memory exception on instruction fetch
bool memory_exception = false;

if (Core::g_CoreStartupParameter.bEnableDebugging)
{
Expand All @@ -316,15 +314,6 @@ const u8* JitArm::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBlo
PanicAlert("ERROR: Compiling at 0. LR=%08x CTR=%08x", LR, CTR);
}

if (Core::g_CoreStartupParameter.bMMU && (em_address & JIT_ICACHE_VMEM_BIT))
{
if (!Memory::TranslateAddress(em_address, Memory::FLAG_OPCODE))
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}
}

js.isLastInstruction = false;
js.blockStart = em_address;
js.fifoBytesThisBlock = 0;
Expand All @@ -335,8 +324,7 @@ const u8* JitArm::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBlo
u32 nextPC = em_address;
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable instructions.
if (!memory_exception)
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);

PPCAnalyst::CodeOp *ops = code_buf->codebuffer;

Expand Down Expand Up @@ -478,8 +466,9 @@ const u8* JitArm::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBlo
}
}
}
if (memory_exception)
if (code_block.m_memory_exception)
BKPT(0x500);

if (code_block.m_broken)
{
printf("Broken Block going to 0x%08x\n", nextPC);
Expand Down
17 changes: 2 additions & 15 deletions Source/Core/Core/PowerPC/JitArmIL/JitIL.cpp
Expand Up @@ -203,8 +203,6 @@ void STACKALIGN JitArmIL::Jit(u32 em_address)
const u8* JitArmIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitBlock *b)
{
int blockSize = code_buf->GetSize();
// Memory exception on instruction fetch
bool memory_exception = false;

if (Core::g_CoreStartupParameter.bEnableDebugging)
{
Expand All @@ -218,16 +216,6 @@ const u8* JitArmIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitB
PanicAlert("ERROR: Compiling at 0. LR=%08x CTR=%08x", LR, CTR);
}

if (Core::g_CoreStartupParameter.bMMU && (em_address & JIT_ICACHE_VMEM_BIT))
{
if (!Memory::TranslateAddress(em_address, Memory::FLAG_OPCODE))
{
// Memory exception occurred during instruction fetch
memory_exception = true;
}
}


js.isLastInstruction = false;
js.blockStart = em_address;
js.fifoBytesThisBlock = 0;
Expand All @@ -238,8 +226,7 @@ const u8* JitArmIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitB
u32 nextPC = em_address;
// Analyze the block, collect all instructions it is made of (including inlining,
// if that is enabled), reorder instructions for optimal performance, and join joinable instructions.
if (!memory_exception)
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);
nextPC = analyzer.Analyze(em_address, &code_block, code_buf, blockSize);

PPCAnalyst::CodeOp *ops = code_buf->codebuffer;

Expand Down Expand Up @@ -334,7 +321,7 @@ const u8* JitArmIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitB
}
}
}
if (memory_exception)
if (code_block.m_memory_exception)
BKPT(0x500);

if (code_block.m_broken)
Expand Down
20 changes: 19 additions & 1 deletion Source/Core/Core/PowerPC/PPCAnalyst.cpp
Expand Up @@ -15,7 +15,7 @@
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PPCTables.h"
#include "Core/PowerPC/SignatureDB.h"
#include "Core/PowerPC/Interpreter/Interpreter.h"
#include "Core/PowerPC/JitCommon/JitCache.h"

// Analyzes PowerPC code in memory to find functions
// After running, for each function we will know what functions it calls
Expand Down Expand Up @@ -543,8 +543,26 @@ u32 PPCAnalyzer::Analyze(u32 address, CodeBlock *block, CodeBuffer *buffer, u32

// Reset our block state
block->m_broken = false;
block->m_memory_exception = false;
block->m_num_instructions = 0;

if (address == 0)
{
// Memory exception occurred during instruction fetch
block->m_memory_exception = true;
return address;
}

if (Core::g_CoreStartupParameter.bMMU && (address & JIT_ICACHE_VMEM_BIT))
{
if (!Memory::TranslateAddress(address, Memory::FLAG_OPCODE))
{
// Memory exception occurred during instruction fetch
block->m_memory_exception = true;
return address;
}
}

CodeOp *code = buffer->codebuffer;

bool found_exit = false;
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/PowerPC/PPCAnalyst.h
Expand Up @@ -124,6 +124,9 @@ struct CodeBlock

// Are we a broken block?
bool m_broken;

// Did we have a memory_exception?
bool m_memory_exception;
};

class PPCAnalyzer
Expand Down

0 comments on commit c4e60d5

Please sign in to comment.