[Project64] Cleanup RecompilerClass.cpp

This commit is contained in:
zilmar 2015-12-13 18:52:22 +11:00
parent 21bce73cca
commit c3a9525006
2 changed files with 114 additions and 114 deletions

View File

@ -17,10 +17,10 @@
#include <Objbase.h> #include <Objbase.h>
CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation) : CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation) :
m_Registers(Registers), m_Registers(Registers),
m_Profile(Profile), m_Profile(Profile),
m_EndEmulation(EndEmulation), m_EndEmulation(EndEmulation),
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER) PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER)
{ {
if (g_MMU != NULL) if (g_MMU != NULL)
{ {
@ -57,7 +57,7 @@ void CRecompiler::Run()
*g_MemoryStack = (uint32_t)(RDRAM+(_GPR[29].W[0] & 0x1FFFFFFF)); *g_MemoryStack = (uint32_t)(RDRAM+(_GPR[29].W[0] & 0x1FFFFFFF));
#endif #endif
__try __try
{ {
if (g_System->LookUpMode() == FuncFind_VirtualLookup) if (g_System->LookUpMode() == FuncFind_VirtualLookup)
{ {
if (g_System->bSMM_ValidFunc()) if (g_System->bSMM_ValidFunc())
@ -65,7 +65,7 @@ void CRecompiler::Run()
RecompilerMain_VirtualTable_validate(); RecompilerMain_VirtualTable_validate();
} }
else else
{ {
RecompilerMain_VirtualTable(); RecompilerMain_VirtualTable();
} }
} }
@ -82,18 +82,18 @@ void CRecompiler::Run()
RecompilerMain_Lookup_validate_TLB(); RecompilerMain_Lookup_validate_TLB();
} }
else else
{ {
RecompilerMain_Lookup_TLB(); RecompilerMain_Lookup_TLB();
} }
} }
else else
{ {
if (g_System->bSMM_ValidFunc()) if (g_System->bSMM_ValidFunc())
{ {
RecompilerMain_Lookup_validate(); RecompilerMain_Lookup_validate();
} }
else else
{ {
RecompilerMain_Lookup(); RecompilerMain_Lookup();
} }
} }
@ -358,7 +358,7 @@ void CRecompiler::RecompilerMain_Lookup()
(info->Function())(); (info->Function())();
} }
else else
{ {
uint32_t opsExecuted = 0; uint32_t opsExecuted = 0;
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
@ -602,7 +602,7 @@ void CRecompiler::RecompilerMain_Lookup_validate()
JumpTable()[PhysicalAddr >> 2] = info; JumpTable()[PhysicalAddr >> 2] = info;
} }
else else
{ {
if (*(info->MemLocation(0)) != info->MemContents(0) || if (*(info->MemLocation(0)) != info->MemContents(0) ||
*(info->MemLocation(1)) != info->MemContents(1)) *(info->MemLocation(1)) != info->MemContents(1))
{ {
@ -614,7 +614,7 @@ void CRecompiler::RecompilerMain_Lookup_validate()
(info->Function())(); (info->Function())();
} }
else else
{ {
uint32_t opsExecuted = 0; uint32_t opsExecuted = 0;
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
@ -666,7 +666,7 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB()
JumpTable()[PhysicalAddr >> 2] = info; JumpTable()[PhysicalAddr >> 2] = info;
} }
else else
{ {
if (*(info->MemLocation(0)) != info->MemContents(0) || if (*(info->MemLocation(0)) != info->MemContents(0) ||
*(info->MemLocation(1)) != info->MemContents(1)) *(info->MemLocation(1)) != info->MemContents(1))
{ {
@ -675,7 +675,7 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB()
ClearRecompCode_Phys((PhysicalAddr - 0x1000) & ~0xFFF, 0x3000, Remove_ValidateFunc); ClearRecompCode_Phys((PhysicalAddr - 0x1000) & ~0xFFF, 0x3000, Remove_ValidateFunc);
} }
else else
{ {
ClearRecompCode_Phys(0, 0x2000, Remove_ValidateFunc); ClearRecompCode_Phys(0, 0x2000, Remove_ValidateFunc);
} }
info = JumpTable()[PhysicalAddr >> 2]; info = JumpTable()[PhysicalAddr >> 2];
@ -690,7 +690,7 @@ void CRecompiler::RecompilerMain_Lookup_validate_TLB()
(info->Function())(); (info->Function())();
} }
else else
{ {
uint32_t opsExecuted = 0; uint32_t opsExecuted = 0;
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize()) while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
@ -741,15 +741,15 @@ void CRecompiler::RecompilerMain_ChangeMemory()
uint8_t * Block; uint8_t * Block;
while(!EndEmulation()) while(!EndEmulation())
{ {
if (UseTlb) if (UseTlb)
{ {
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) if (!TranslateVaddr(PROGRAM_COUNTER, &Addr))
{ {
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER); DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
NextInstruction = NORMAL; NextInstruction = NORMAL;
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) if (!TranslateVaddr(PROGRAM_COUNTER, &Addr))
{ {
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER); g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
ExitThread(0); ExitThread(0);
} }
@ -759,30 +759,30 @@ void CRecompiler::RecompilerMain_ChangeMemory()
} }
if (NextInstruction == DELAY_SLOT) if (NextInstruction == DELAY_SLOT)
{ {
__try __try
{ {
Value = (uint32_t)(*(DelaySlotTable + (Addr >> 12))); Value = (uint32_t)(*(DelaySlotTable + (Addr >> 12)));
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
g_Notify->DisplayError(L"Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X",PROGRAM_COUNTER); g_Notify->DisplayError(L"Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X",PROGRAM_COUNTER);
ExitThread(0); ExitThread(0);
} }
if ( (Value >> 16) == 0x7C7C) if ( (Value >> 16) == 0x7C7C)
{ {
uint32_t Index = (Value & 0xFFFF); uint32_t Index = (Value & 0xFFFF);
Block = (uint8_t *)OrigMem[Index].CompiledLocation; Block = (uint8_t *)OrigMem[Index].CompiledLocation;
if (OrigMem[Index].PAddr != Addr) { Block = NULL; } if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; } if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
if (Index >= TargetIndex) { Block = NULL; } if (Index >= TargetIndex) { Block = NULL; }
} }
else else
{ {
Block = NULL; Block = NULL;
} }
if (Block == NULL) if (Block == NULL)
{ {
uint32_t MemValue; uint32_t MemValue;
Block = CompileDelaySlot(); Block = CompileDelaySlot();
@ -790,7 +790,7 @@ void CRecompiler::RecompilerMain_ChangeMemory()
Value += (uint16_t)(TargetIndex); Value += (uint16_t)(TargetIndex);
MemValue = *(uint32_t *)(RDRAM + Addr); MemValue = *(uint32_t *)(RDRAM + Addr);
if ( (MemValue >> 16) == 0x7C7C) if ( (MemValue >> 16) == 0x7C7C)
{ {
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue; MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
} }
OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue; OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue;
@ -802,46 +802,46 @@ void CRecompiler::RecompilerMain_ChangeMemory()
NextInstruction = NORMAL; NextInstruction = NORMAL;
} }
_asm _asm
{ {
pushad pushad
call Block call Block
popad popad
} }
continue; continue;
} }
__try __try
{ {
Value = *(uint32_t *)(RDRAM + Addr); Value = *(uint32_t *)(RDRAM + Addr);
if ( (Value >> 16) == 0x7C7C) if ( (Value >> 16) == 0x7C7C)
{ {
uint32_t Index = (Value & 0xFFFF); uint32_t Index = (Value & 0xFFFF);
Block = (uint8_t *)OrigMem[Index].CompiledLocation; Block = (uint8_t *)OrigMem[Index].CompiledLocation;
if (OrigMem[Index].PAddr != Addr) { Block = NULL; } if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; } if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
if (Index >= TargetIndex) { Block = NULL; } if (Index >= TargetIndex) { Block = NULL; }
} }
else else
{ {
Block = NULL; Block = NULL;
} }
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE)); g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE));
ExitThread(0); ExitThread(0);
} }
if (Block == NULL) if (Block == NULL)
{ {
uint32_t MemValue; uint32_t MemValue;
__try __try
{ {
Block = Compiler4300iBlock(); Block = Compiler4300iBlock();
} }
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
ResetRecompCode(); ResetRecompCode();
Block = Compiler4300iBlock(); Block = Compiler4300iBlock();
} }
@ -850,7 +850,7 @@ void CRecompiler::RecompilerMain_ChangeMemory()
continue; continue;
} }
if (TargetIndex == MaxOrigMem) if (TargetIndex == MaxOrigMem)
{ {
ResetRecompCode(); ResetRecompCode();
continue; continue;
} }
@ -858,7 +858,7 @@ void CRecompiler::RecompilerMain_ChangeMemory()
Value += (uint16_t)(TargetIndex); Value += (uint16_t)(TargetIndex);
MemValue = *(uint32_t *)(RDRAM + Addr); MemValue = *(uint32_t *)(RDRAM + Addr);
if ( (MemValue >> 16) == 0x7C7C) if ( (MemValue >> 16) == 0x7C7C)
{ {
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue; MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
} }
OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue; OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue;
@ -870,11 +870,11 @@ void CRecompiler::RecompilerMain_ChangeMemory()
NextInstruction = NORMAL; NextInstruction = NORMAL;
} }
if (Profiling && IndvidualBlock) if (Profiling && IndvidualBlock)
{ {
static uint32_t ProfAddress = 0; static uint32_t ProfAddress = 0;
/*if ((PROGRAM_COUNTER & ~0xFFF) != ProfAddress) /*if ((PROGRAM_COUNTER & ~0xFFF) != ProfAddress)
{ {
char Label[100]; char Label[100];
ProfAddress = PROGRAM_COUNTER & ~0xFFF; ProfAddress = PROGRAM_COUNTER & ~0xFFF;
@ -882,7 +882,7 @@ void CRecompiler::RecompilerMain_ChangeMemory()
StartTimer(Label); StartTimer(Label);
}*/ }*/
/*if (PROGRAM_COUNTER >= 0x800DD000 && PROGRAM_COUNTER <= 0x800DDFFC) /*if (PROGRAM_COUNTER >= 0x800DD000 && PROGRAM_COUNTER <= 0x800DDFFC)
{ {
char Label[100]; char Label[100];
sprintf(Label,"PC: %X Block: %X",PROGRAM_COUNTER,Block); sprintf(Label,"PC: %X Block: %X",PROGRAM_COUNTER,Block);
StartTimer(Label); StartTimer(Label);
@ -891,10 +891,10 @@ void CRecompiler::RecompilerMain_ChangeMemory()
// StartTimer("r4300i Running"); // StartTimer("r4300i Running");
} }
_asm _asm
{ {
pushad pushad
call Block call Block
popad popad
} }
} // end for(;;) } // end for(;;)
#endif #endif
@ -989,7 +989,7 @@ void CRecompiler::ClearRecompCode_Phys(uint32_t Address, int length, REMOVE_REAS
} }
} }
else else
{ {
WriteTraceF(TraceRecompiler, __FUNCTION__ ": Ignoring reset of Jump Table, Addr: %X len: %d", Address, ((length + 3) & ~3)); WriteTraceF(TraceRecompiler, __FUNCTION__ ": Ignoring reset of Jump Table, Addr: %X len: %d", Address, ((length + 3) & ~3));
} }
} }
@ -1000,39 +1000,39 @@ void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REAS
switch (g_System->LookUpMode()) switch (g_System->LookUpMode())
{ {
case FuncFind_VirtualLookup: case FuncFind_VirtualLookup:
{
uint32_t AddressIndex = Address >> 0xC;
uint32_t WriteStart = (Address & 0xFFC);
length = ((length + 3) & ~0x3);
int DataInBlock = 0x1000 - WriteStart;
int DataToWrite = length < DataInBlock ? length : DataInBlock;
int DataLeft = length - DataToWrite;
PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex];
if (table)
{ {
uint32_t AddressIndex = Address >> 0xC; WriteTraceF(TraceError, __FUNCTION__ ": Delete Table (%X): Index = %d", table, AddressIndex);
uint32_t WriteStart = (Address & 0xFFC); delete table;
length = ((length + 3) & ~0x3); table = NULL;
g_MMU->UnProtectMemory(Address, Address + length);
int DataInBlock = 0x1000 - WriteStart;
int DataToWrite = length < DataInBlock ? length : DataInBlock;
int DataLeft = length - DataToWrite;
PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex];
if (table)
{
WriteTraceF(TraceError, __FUNCTION__ ": Delete Table (%X): Index = %d", table, AddressIndex);
delete table;
table = NULL;
g_MMU->UnProtectMemory(Address, Address + length);
}
if (DataLeft > 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
} }
break;
if (DataLeft > 0)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
}
break;
case FuncFind_PhysicalLookup: case FuncFind_PhysicalLookup:
{
uint32_t pAddr = 0;
if (g_TransVaddr->TranslateVaddr(Address, pAddr))
{ {
uint32_t pAddr = 0; ClearRecompCode_Phys(pAddr, length, Reason);
if (g_TransVaddr->TranslateVaddr(Address, pAddr))
{
ClearRecompCode_Phys(pAddr, length, Reason);
}
} }
break; }
break;
default: default:
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
@ -1057,7 +1057,7 @@ void CRecompiler::ResetMemoryStackPos()
m_MemoryStack = (uint32_t)(g_MMU->Rdram() + pAddr); m_MemoryStack = (uint32_t)(g_MMU->Rdram() + pAddr);
} }
else else
{ {
WriteTraceF(TraceError, __FUNCTION__ ": Failed to translate SP address (%s)", m_Registers.m_GPR[29].UW[0]); WriteTraceF(TraceError, __FUNCTION__ ": Failed to translate SP address (%s)", m_Registers.m_GPR[29].UW[0]);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }

View File

@ -34,7 +34,7 @@ public:
Remove_StoreInstruc, Remove_StoreInstruc,
}; };
typedef void (*DelayFunc)(); typedef void(*DelayFunc)();
public: public:
CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation); CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation);
@ -45,8 +45,8 @@ public:
void ResetRecompCode(bool bAllocate); void ResetRecompCode(bool bAllocate);
//Self modifying code methods //Self modifying code methods
void ClearRecompCode_Virt ( uint32_t VirtualAddress, int32_t length, REMOVE_REASON Reason ); void ClearRecompCode_Virt(uint32_t VirtualAddress, int32_t length, REMOVE_REASON Reason);
void ClearRecompCode_Phys ( uint32_t PhysicalAddress, int32_t length, REMOVE_REASON Reason ); void ClearRecompCode_Phys(uint32_t PhysicalAddress, int32_t length, REMOVE_REASON Reason);
void ResetMemoryStackPos(); void ResetMemoryStackPos();