2010-06-04 06:25:07 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-31 00:21:08 +00:00
|
|
|
CRecompiler::CRecompiler(CProfiling & Profile, bool & EndEmulation ) :
|
2008-09-18 03:15:49 +00:00
|
|
|
m_Profile(Profile),
|
2010-05-23 10:05:41 +00:00
|
|
|
PROGRAM_COUNTER(_Reg->m_PROGRAM_COUNTER),
|
2010-06-12 02:02:06 +00:00
|
|
|
m_EndEmulation(EndEmulation)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CRecompiler::~CRecompiler()
|
|
|
|
{
|
2010-06-04 06:25:07 +00:00
|
|
|
for (int i = 0, n = m_Functions.size(); i < n; i++)
|
|
|
|
{
|
|
|
|
delete m_Functions[i];
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::Run()
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
if (g_LogX86Code)
|
|
|
|
{
|
|
|
|
Start_x86_Log();
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!CRecompMemory::AllocateMemory())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceError,"CRecompiler::Run: CRecompMemory::AllocateMemory failed");
|
|
|
|
return;
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
m_EndEmulation = false;
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
WriteTrace(TraceError,"CRecompiler::Run Fix g_MemoryStack");
|
|
|
|
#ifdef tofix
|
|
|
|
*g_MemoryStack = (DWORD)(RDRAM+(_GPR[29].W[0] & 0x1FFFFFFF));
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
__try {
|
2008-11-14 20:51:06 +00:00
|
|
|
if (LookUpMode() == FuncFind_VirtualLookup)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!CFunctionMap::AllocateMemory())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceError,"CRecompiler::Run: CFunctionMap::AllocateMemory failed");
|
|
|
|
return;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_ValidFunc())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
RecompilerMain_VirtualTable_validate();
|
|
|
|
} else {
|
|
|
|
RecompilerMain_VirtualTable();
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
else if (LookUpMode() == FuncFind_ChangeMemory)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
RecompilerMain_ChangeMemory();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RecompilerMain_Lookup();
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
__except( _MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
Notify().DisplayError(MSG_UNKNOWN_MEM_ACTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::RecompilerMain_VirtualTable ( void )
|
|
|
|
{
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
2010-06-12 02:02:06 +00:00
|
|
|
PCCompiledFunc_TABLE & table = FunctionTable()[PROGRAM_COUNTER >> 0xC];
|
2010-05-31 00:21:08 +00:00
|
|
|
DWORD TableEntry = (PROGRAM_COUNTER & 0xFFF) >> 2;
|
2010-05-25 09:15:19 +00:00
|
|
|
if (table)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-31 00:21:08 +00:00
|
|
|
CCompiledFunc * info = table[TableEntry];
|
2010-05-25 09:15:19 +00:00
|
|
|
if (info != NULL)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
(info->Function())();
|
|
|
|
continue;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
}
|
|
|
|
if (!_TransVaddr->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
_Reg->DoTLBMiss(false,PROGRAM_COUNTER);
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!_TransVaddr->ValidVaddr(PROGRAM_COUNTER))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
|
|
|
|
CCompiledFunc * info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-05-31 00:21:08 +00:00
|
|
|
|
|
|
|
if (table == NULL)
|
|
|
|
{
|
|
|
|
table = new PCCompiledFunc[(0x1000 >> 2)];
|
|
|
|
if (table == NULL)
|
|
|
|
{
|
|
|
|
Notify().FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
}
|
|
|
|
memset(table,0,sizeof(PCCompiledFunc) * (0x1000 >> 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
table[TableEntry] = info;
|
2010-05-25 09:15:19 +00:00
|
|
|
(info->Function())();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::RecompilerMain_VirtualTable_validate ( void )
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
2010-06-04 06:25:07 +00:00
|
|
|
/* PCCompiledFunc_TABLE * m_FunctionTable = m_Functions.GetFunctionTable();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (NextInstruction == DELAY_SLOT)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
2008-09-18 03:15:49 +00:00
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
|
|
|
if (!_TLB->ValidVaddr(PROGRAM_COUNTER))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
2010-05-22 04:47:15 +00:00
|
|
|
if (!_TLB->ValidVaddr(PROGRAM_COUNTER))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
//Find Block on hash table
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const BYTE * Block = Info->FunctionAddr();
|
|
|
|
if ((*Info->MemLocation[0] != Info->MemContents[0]) ||
|
|
|
|
(*Info->MemLocation[1] != Info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((Info->VStartPC() - 0x1000) & ~0xFFF,0x2000,Remove_ValidateFunc);
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
Info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
2010-05-25 09:15:19 +00:00
|
|
|
}*/
|
2010-06-04 06:25:07 +00:00
|
|
|
/* PCCompiledFunc_TABLE table = m_FunctionTable[PROGRAM_COUNTER >> 0xC];
|
2008-09-18 03:15:49 +00:00
|
|
|
if (table)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * info = table[(PROGRAM_COUNTER & 0xFFF) >> 2];
|
2008-09-18 03:15:49 +00:00
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
if ((*info->MemLocation[0] != info->MemContents[0]) ||
|
|
|
|
(*info->MemLocation[1] != info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((info->VStartPC() - 0x1000) & ~0xFFF,0x3000,Remove_ValidateFunc);
|
|
|
|
info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const BYTE * Block = info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
|
|
|
if (!_TLB->ValidVaddr(PROGRAM_COUNTER))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
2010-05-22 04:47:15 +00:00
|
|
|
if (!_TLB->ValidVaddr(PROGRAM_COUNTER))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * info = CompilerCode();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
|
|
|
if (!_MMU->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!_MMU->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NextInstruction == DELAY_SLOT)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_ValidFunc())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if ((*Info->MemLocation[0] != Info->MemContents[0]) ||
|
|
|
|
(*Info->MemLocation[1] != Info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((Info->StartPC() - 0x1000) & ~0xFFF,0x2000,Remove_ValidateFunc);
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
Info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const BYTE * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info = m_Functions.FindFunction(PROGRAM_COUNTER);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompilerCode();
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_ValidFunc())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if ((*Info->MemLocation[0] != Info->MemContents[0]) ||
|
|
|
|
(*Info->MemLocation[1] != Info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((Info->StartPC() - 0x1000) & ~0xFFF,0x3000,Remove_ValidateFunc);
|
|
|
|
Info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const BYTE * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::RecompilerMain_Lookup( void )
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
|
|
|
|
/*
|
2008-09-18 03:15:49 +00:00
|
|
|
DWORD Addr;
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info;
|
2008-09-18 03:15:49 +00:00
|
|
|
//const BYTE * Block;
|
|
|
|
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (g_UseTlb)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
|
|
|
if (!_TLB->TranslateVaddr(PROGRAM_COUNTER, Addr))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) {
|
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
Addr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
2010-05-25 09:15:19 +00:00
|
|
|
}*/
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
/* if (NextInstruction == DELAY_SLOT) {
|
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_ValidFunc())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if ((*Info->MemLocation[0] != Info->MemContents[0]) ||
|
|
|
|
(*Info->MemLocation[1] != Info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((Info->VStartPC() - 0x1000) & ~0xFFF,0x2000,Remove_ValidateFunc);
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
Info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const BYTE * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
__try {
|
|
|
|
if (Addr > 0x10000000)
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bRomInMemory())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if (Addr > 0x20000000)
|
|
|
|
{
|
|
|
|
WriteTraceF(TraceDebug,"Executing from non mapped space .1 PC: %X Addr: %X",PROGRAM_COUNTER, Addr);
|
|
|
|
DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
Info = (CCompiledFunc *)*(JumpTable + (Addr >> 2));
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
if (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) {
|
|
|
|
while (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) {
|
|
|
|
ExecuteInterpreterOpCode();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
WriteTraceF(TraceDebug,"Executing from non mapped space .1 PC: %X Addr: %X",PROGRAM_COUNTER, Addr);
|
|
|
|
DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-25 09:15:19 +00:00
|
|
|
Info = (CCompiledFunc *)*(JumpTable + (Addr >> 2));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
if (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) {
|
|
|
|
while (PROGRAM_COUNTER >= 0xB0000000 && PROGRAM_COUNTER < (RomFileSize | 0xB0000000)) {
|
|
|
|
ExecuteInterpreterOpCode();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
WriteTraceF(TraceDebug,"Executing from non mapped space .2 PC: %X Addr: %X",PROGRAM_COUNTER, Addr);
|
|
|
|
DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompilerCode();
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*(JumpTable + (Addr >> 2)) = (void *)Info;
|
|
|
|
|
|
|
|
// if (SelfModCheck == ModCode_ProtectedMemory) {
|
2010-05-22 04:47:15 +00:00
|
|
|
// VirtualProtect(RDRAM + Addr, 4, PAGE_READONLY, &OldProtect);
|
2008-09-18 03:15:49 +00:00
|
|
|
// }
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_ValidFunc())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if ((*Info->MemLocation[0] != Info->MemContents[0]) ||
|
|
|
|
(*Info->MemLocation[1] != Info->MemContents[1]))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((Info->VStartPC() - 0x1000) & ~0xFFF,0x3000,Remove_ValidateFunc);
|
|
|
|
Info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
2008-09-18 03:15:49 +00:00
|
|
|
#ifdef tofix
|
|
|
|
if (Profiling && IndvidualBlock) {
|
|
|
|
static DWORD ProfAddress = 0;
|
|
|
|
|
|
|
|
if ((PROGRAM_COUNTER & ~0xFFF) != ProfAddress) {
|
|
|
|
char Label[100];
|
|
|
|
|
|
|
|
ProfAddress = PROGRAM_COUNTER & ~0xFFF;
|
|
|
|
sprintf(Label,"PC: %X to %X",ProfAddress,ProfAddress+ 0xFFC);
|
|
|
|
// StartTimer(Label);
|
|
|
|
}
|
|
|
|
/*if (PROGRAM_COUNTER >= 0x800DD000 && PROGRAM_COUNTER <= 0x800DDFFC) {
|
|
|
|
char Label[100];
|
|
|
|
sprintf(Label,"PC: %X Block: %X",PROGRAM_COUNTER,Block);
|
|
|
|
StartTimer(Label);
|
|
|
|
}*/
|
|
|
|
// } else if ((Profiling || ShowCPUPer) && ProfilingLabel[0] == 0) {
|
|
|
|
// StartTimer("r4300i Running");
|
2010-05-25 09:15:19 +00:00
|
|
|
/* }
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
const BYTE * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
}*/
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::ResetRecompCode()
|
|
|
|
{
|
2010-06-12 02:02:06 +00:00
|
|
|
CRecompMemory::Reset();
|
|
|
|
CFunctionMap::Reset();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 02:23:58 +00:00
|
|
|
BYTE * CRecompiler::CompileDelaySlot(DWORD PC)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-06-07 02:23:58 +00:00
|
|
|
int Index = PC >> 0xC;
|
2010-06-12 02:02:06 +00:00
|
|
|
BYTE * delayFunc = DelaySlotTable()[Index];
|
2010-06-07 02:23:58 +00:00
|
|
|
if (delayFunc)
|
|
|
|
{
|
|
|
|
return delayFunc;
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
WriteTraceF(TraceRecompiler,"Compile Delay Slot: %X",PC);
|
|
|
|
if ((PC & 0xFFC) != 0) {
|
|
|
|
DisplayError("Why are you compiling the Delay Slot at %X",PC);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-07 02:23:58 +00:00
|
|
|
CheckRecompMem();
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-06-07 02:23:58 +00:00
|
|
|
CCodeBlock CodeBlock(PC, RecompPos(), true);
|
|
|
|
if (!CodeBlock.Compile())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-07 02:23:58 +00:00
|
|
|
CCompiledFunc * Func = new CCompiledFunc(CodeBlock);
|
|
|
|
delayFunc = (BYTE *)Func->Function();
|
2010-06-12 02:02:06 +00:00
|
|
|
DelaySlotTable()[Index] = delayFunc;
|
|
|
|
delete Func;
|
2010-06-07 02:23:58 +00:00
|
|
|
return delayFunc;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
bool CRecompiler::AnalyseBlock ( CCodeBlock & BlockInfo)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bLinkBlocks())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Section = &BlockInfo.ParentSection;
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!CreateSectionLinkage (Section)) { return false; }
|
2010-05-30 01:54:42 +00:00
|
|
|
DetermineLoop(Section,CCodeSection::GetNewTestValue(),CCodeSection::GetNewTestValue(), Section->m_SectionID);
|
2010-05-25 09:15:19 +00:00
|
|
|
while (FixConstants(Section,CCodeSection::GetNewTestValue())) {}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::FixConstants (CCodeSection * Section, DWORD Test)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Section == NULL) { return false; }
|
|
|
|
if (Section->Test == Test) { return false; }
|
|
|
|
Section->Test = Test;
|
|
|
|
|
|
|
|
InheritConstants(Section);
|
|
|
|
|
|
|
|
bool Changed = false;
|
|
|
|
/* BLOCK_SECTION * Parent;
|
|
|
|
int count, NoOfParents;
|
|
|
|
REG_INFO Original[2];
|
|
|
|
*/
|
2010-05-30 01:54:42 +00:00
|
|
|
CRegInfo Original[2] = { Section->m_Cont.RegSet, Section->m_Jump.RegSet };
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (!Section->ParentSection.empty()) {
|
|
|
|
for (SECTION_LIST::iterator iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Parent->m_ContinueSection == Section) {
|
2008-09-18 03:15:49 +00:00
|
|
|
for (int count = 0; count < 32; count++) {
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->RegStart.MipsRegState(count) != Parent->m_Cont.RegSet.MipsRegState(count)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
//*Changed = true;
|
|
|
|
}
|
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Parent->m_JumpSection == Section) {
|
2008-09-18 03:15:49 +00:00
|
|
|
for (int count = 0; count < 32; count++) {
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->RegStart.MipsRegState(count) != Parent->m_Jump.RegSet.MipsRegState(count)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
//*Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FillSectionInfo(Section, NORMAL);
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Original[0] != Section->m_Cont.RegSet)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Original[1] != Section->m_Jump.RegSet)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->m_JumpSection && FixConstants(Section->m_JumpSection,Test)) { Changed = true; }
|
|
|
|
if (Section->m_ContinueSection && FixConstants(Section->m_ContinueSection,Test)) { Changed = true; }
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
return Changed;
|
2010-05-30 01:54:42 +00:00
|
|
|
#endif
|
|
|
|
return false;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::InheritConstants(CCodeSection * Section)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Section->ParentSection.empty())
|
|
|
|
{
|
|
|
|
Section->RegStart.Initilize();
|
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *(Section->ParentSection.begin());
|
2010-05-30 01:54:42 +00:00
|
|
|
CRegInfo * RegSet = (Section == Parent->m_ContinueSection?&Parent->m_Cont.RegSet:&Parent->m_Jump.RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->RegStart = *RegSet;
|
|
|
|
Section->RegWorking = *RegSet;
|
|
|
|
|
|
|
|
for (SECTION_LIST::iterator iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
|
|
|
if (iter == Section->ParentSection.begin()) { continue; }
|
|
|
|
Parent = *iter;
|
2010-05-30 01:54:42 +00:00
|
|
|
RegSet = Section == Parent->m_ContinueSection?&Parent->m_Cont.RegSet:&Parent->m_Jump.RegSet;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
for (int count = 0; count < 32; count++) {
|
|
|
|
if (Section->IsConst(count)) {
|
|
|
|
if (Section->MipsRegState(count) != RegSet->MipsRegState(count)) {
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
} else if (Section->Is32Bit(count) && Section->MipsRegLo(count) != RegSet->MipsRegLo(count)) {
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
} else if (Section->Is64Bit(count) && Section->MipsReg(count) != RegSet->MipsReg(count)) {
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegStart = Section->RegWorking;
|
2010-05-30 01:54:42 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * CRecompiler::ExistingSection(CCodeSection * StartSection, DWORD Addr, DWORD Test)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
if (StartSection == NULL) { return NULL; }
|
|
|
|
if (StartSection->StartPC == Addr && StartSection->LinkAllowed)
|
|
|
|
{
|
|
|
|
return StartSection;
|
|
|
|
}
|
|
|
|
if (StartSection->Test == Test) { return NULL; }
|
|
|
|
StartSection->Test = Test;
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
CCodeSection * Section = ExistingSection(StartSection->m_JumpSection,Addr,Test);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Section != NULL) { return Section; }
|
2010-05-30 01:54:42 +00:00
|
|
|
Section = ExistingSection(StartSection->m_ContinueSection,Addr,Test);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Section != NULL) { return Section; }
|
2010-05-30 01:54:42 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::CreateSectionLinkage (CCodeSection * Section) {
|
2010-05-30 01:54:42 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
InheritConstants(Section);
|
|
|
|
|
|
|
|
if (!FillSectionInfo(Section,NORMAL))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection ** TargetSection[2];
|
2008-09-18 03:15:49 +00:00
|
|
|
CJumpInfo * JumpInfo[2];
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->m_Jump.TargetPC < Section->m_Cont.TargetPC) {
|
|
|
|
TargetSection[0] = (CCodeSection **)&Section->m_JumpSection;
|
|
|
|
TargetSection[1] = (CCodeSection **)&Section->m_ContinueSection;
|
|
|
|
JumpInfo[0] = &Section->m_Jump;
|
|
|
|
JumpInfo[1] = &Section->m_Cont;
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-30 01:54:42 +00:00
|
|
|
TargetSection[0] = (CCodeSection **)&Section->m_ContinueSection;
|
|
|
|
TargetSection[1] = (CCodeSection **)&Section->m_JumpSection;
|
|
|
|
JumpInfo[0] = &Section->m_Cont;
|
|
|
|
JumpInfo[1] = &Section->m_Jump;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
CCodeBlock * BlockInfo = Section->BlockInfo;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
for (int count = 0; count < 2; count ++)
|
|
|
|
{
|
|
|
|
if (JumpInfo[count]->TargetPC == (DWORD)-1 || *TargetSection[count] != NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!JumpInfo[count]->DoneDelaySlot)
|
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.RegSet = Section->RegWorking;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//this is a special delay slot section
|
|
|
|
BlockInfo->NoOfSections += 1;
|
2010-05-30 01:54:42 +00:00
|
|
|
*TargetSection[count] = new CCodeSection(BlockInfo,CRecompilerOps::CompilePC() + 4,BlockInfo->NoOfSections);
|
2008-09-18 03:15:49 +00:00
|
|
|
(*TargetSection[count])->AddParent(Section);
|
|
|
|
(*TargetSection[count])->LinkAllowed = false;
|
|
|
|
InheritConstants((*TargetSection[count]));
|
|
|
|
|
|
|
|
if (!FillSectionInfo((*TargetSection[count]),END_BLOCK))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
(*TargetSection[count])->m_Jump.TargetPC = -1;
|
|
|
|
(*TargetSection[count])->m_Cont.TargetPC = JumpInfo[count]->TargetPC;
|
|
|
|
(*TargetSection[count])->m_Cont.FallThrough = true;
|
|
|
|
(*TargetSection[count])->m_Cont.RegSet = (*TargetSection[count])->RegWorking;
|
|
|
|
JumpInfo[count]->TargetPC = CRecompilerOps::CompilePC() + 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Create the section that joins with that block
|
2010-05-30 01:54:42 +00:00
|
|
|
(*TargetSection[count])->m_ContinueSection = ExistingSection(&BlockInfo->ParentSection,(*TargetSection[count])->m_Cont.TargetPC,CCodeSection::GetNewTestValue());
|
|
|
|
if ((*TargetSection[count])->m_ContinueSection == NULL) {
|
2008-09-18 03:15:49 +00:00
|
|
|
BlockInfo->NoOfSections += 1;
|
2010-05-30 01:54:42 +00:00
|
|
|
(*TargetSection[count])->m_ContinueSection = new CCodeSection(BlockInfo,(*TargetSection[count])->m_Cont.TargetPC,BlockInfo->NoOfSections);
|
|
|
|
(*TargetSection[count])->m_ContinueSection->AddParent((*TargetSection[count]));
|
|
|
|
CreateSectionLinkage((*TargetSection[count])->m_ContinueSection);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-30 01:54:42 +00:00
|
|
|
(*TargetSection[count])->m_ContinueSection->AddParent((*TargetSection[count]));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-05-25 09:15:19 +00:00
|
|
|
*TargetSection[count] = ExistingSection(&BlockInfo->ParentSection,JumpInfo[count]->TargetPC,CCodeSection::GetNewTestValue());
|
2008-09-18 03:15:49 +00:00
|
|
|
if (*TargetSection[count] == NULL) {
|
|
|
|
BlockInfo->NoOfSections += 1;
|
2010-05-25 09:15:19 +00:00
|
|
|
*TargetSection[count] = new CCodeSection(BlockInfo,JumpInfo[count]->TargetPC,BlockInfo->NoOfSections);
|
2008-09-18 03:15:49 +00:00
|
|
|
(*TargetSection[count])->AddParent(Section);
|
|
|
|
CreateSectionLinkage(*TargetSection[count]);
|
|
|
|
} else {
|
|
|
|
(*TargetSection[count])->AddParent(Section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::FillSectionInfo(CCodeSection * Section, STEP_TYPE StartStepType)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
OPCODE Command;
|
|
|
|
|
|
|
|
if (Section->CompiledLocation != NULL) { return true; }
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() = Section->StartPC;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
NextInstruction = StartStepType;
|
|
|
|
do {
|
2010-05-30 01:54:42 +00:00
|
|
|
if (!_MMU->LW_VAddr(CRecompilerOps::CompilePC(), Command.Hex)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (Command.op) {
|
|
|
|
case R4300i_SPECIAL:
|
|
|
|
switch (Command.funct) {
|
|
|
|
case R4300i_SPECIAL_SLL:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) << Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SRL:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) >> Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SRA:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo_S(Command.rt) >> Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SLLV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) << (Section->MipsRegLo(Command.rs) & 0x1F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SRLV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) >> (Section->MipsRegLo(Command.rs) & 0x1F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SRAV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo_S(Command.rt) >> (Section->MipsRegLo(Command.rs) & 0x1F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_JR:
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = Section->MipsRegLo(Command.rs);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_JALR:
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->MipsRegLo(Opcode.rd) = CRecompilerOps::CompilePC() + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(Opcode.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = Section->MipsRegLo(Command.rs);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SYSCALL:
|
|
|
|
case R4300i_SPECIAL_BREAK:
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_MFHI: Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN; break;
|
|
|
|
case R4300i_SPECIAL_MTHI: break;
|
|
|
|
case R4300i_SPECIAL_MFLO: Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN; break;
|
|
|
|
case R4300i_SPECIAL_MTLO: break;
|
|
|
|
case R4300i_SPECIAL_DSLLV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(QWORD)Section->MipsRegLo_S(Command.rt) << (Section->MipsRegLo(Command.rs) & 0x3F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRLV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(QWORD)Section->MipsRegLo_S(Command.rt) >> (Section->MipsRegLo(Command.rs) & 0x3F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRAV:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg_S(Command.rt):(_int64)Section->MipsRegLo_S(Command.rt) >> (Section->MipsRegLo(Command.rs) & 0x3F);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_MULT: break;
|
|
|
|
case R4300i_SPECIAL_MULTU: break;
|
|
|
|
case R4300i_SPECIAL_DIV: break;
|
|
|
|
case R4300i_SPECIAL_DIVU: break;
|
|
|
|
case R4300i_SPECIAL_DMULT: break;
|
|
|
|
case R4300i_SPECIAL_DMULTU: break;
|
|
|
|
case R4300i_SPECIAL_DDIV: break;
|
|
|
|
case R4300i_SPECIAL_DDIVU: break;
|
|
|
|
case R4300i_SPECIAL_ADD:
|
|
|
|
case R4300i_SPECIAL_ADDU:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rs) + Section->MipsRegLo(Command.rt);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SUB:
|
|
|
|
case R4300i_SPECIAL_SUBU:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rs) - Section->MipsRegLo(Command.rt);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_AND:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) && Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) & Section->MipsReg(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) & Section->MipsRegLo(Command.rs);
|
|
|
|
} else {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsRegLo(Command.rt) & Section->MipsReg(Command.rs);
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::ConstantsType(Section->MipsReg(Command.rd));
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) & Section->MipsRegLo(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_OR:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) && Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) | Section->MipsReg(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) | Section->MipsRegLo(Command.rs);
|
|
|
|
} else {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsRegLo(Command.rt) | Section->MipsReg(Command.rs);
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) | Section->MipsRegLo(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_XOR:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) && Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) ^ Section->MipsReg(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsReg(Command.rt) ^ Section->MipsRegLo(Command.rs);
|
|
|
|
} else {
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsRegLo(Command.rt) ^ Section->MipsReg(Command.rs);
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = Section->MipsRegLo(Command.rt) ^ Section->MipsRegLo(Command.rs);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_NOR:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) && Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) = ~(Section->MipsReg(Command.rt) | Section->MipsReg(Command.rs));
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsReg(Command.rd) = ~(Section->MipsReg(Command.rt) | Section->MipsRegLo(Command.rs));
|
|
|
|
} else {
|
|
|
|
Section->MipsReg(Command.rd) = ~(Section->MipsRegLo(Command.rt) | Section->MipsReg(Command.rs));
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = ~(Section->MipsRegLo(Command.rt) | Section->MipsRegLo(Command.rs));
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SLT:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsRegLo_S(Command.rs) < Section->MipsReg_S(Command.rt))?1:0;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsReg_S(Command.rs) < Section->MipsRegLo_S(Command.rt))?1:0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsRegLo_S(Command.rs) < Section->MipsRegLo_S(Command.rt))?1:0;
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SLTU:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt) || Section->Is64Bit(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rt)) {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsRegLo(Command.rs) < Section->MipsReg(Command.rt))?1:0;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsReg(Command.rs) < Section->MipsRegLo(Command.rt))?1:0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rd) = (Section->MipsRegLo(Command.rs) < Section->MipsRegLo(Command.rt))?1:0;
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DADD:
|
|
|
|
case R4300i_SPECIAL_DADDU:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) =
|
|
|
|
Section->Is64Bit(Command.rs)?Section->MipsReg(Command.rs):(_int64)Section->MipsRegLo_S(Command.rs) +
|
|
|
|
Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(_int64)Section->MipsRegLo_S(Command.rt);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSUB:
|
|
|
|
case R4300i_SPECIAL_DSUBU:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && (Command.rt == Command.rd || Command.rs == Command.rd)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt) && Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsReg(Command.rd) =
|
|
|
|
Section->Is64Bit(Command.rs)?Section->MipsReg(Command.rs):(_int64)Section->MipsRegLo_S(Command.rs) -
|
|
|
|
Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(_int64)Section->MipsRegLo_S(Command.rt);
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSLL:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(_int64)Section->MipsRegLo_S(Command.rt) << Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRL:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg(Command.rt):(QWORD)Section->MipsRegLo_S(Command.rt) >> Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRA:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg_S(Command.rd) = Section->Is64Bit(Command.rt)?Section->MipsReg_S(Command.rt):(_int64)Section->MipsRegLo_S(Command.rt) >> Command.sa;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSLL32:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_64;
|
|
|
|
Section->MipsReg(Command.rd) = Section->MipsRegLo(Command.rt) << (Command.sa + 32);
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRL32:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = (DWORD)(Section->MipsReg(Command.rt) >> (Command.sa + 32));
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_DSRA32:
|
|
|
|
if (Command.rd == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rt == Command.rd) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rt)) {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rd) = (DWORD)(Section->MipsReg_S(Command.rt) >> (Command.sa + 32));
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rd) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
if (Command.Hex == 0x00000001) { break; }
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 5\n%s",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM:
|
|
|
|
switch (Command.rt) {
|
|
|
|
case R4300i_REGIMM_BLTZ:
|
|
|
|
case R4300i_REGIMM_BGEZ:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BLTZL:
|
|
|
|
case R4300i_REGIMM_BGEZL:
|
|
|
|
NextInstruction = LIKELY_DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BLTZAL:
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->MipsRegLo(31) = CRecompilerOps::CompilePC() + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BGEZAL:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
if (Section->IsConst(Command.rs))
|
|
|
|
{
|
|
|
|
__int64 Value;
|
|
|
|
if (Section->Is32Bit(Command.rs))
|
|
|
|
{
|
|
|
|
Value = Section->MipsRegLo_S(Command.rs);
|
|
|
|
} else {
|
|
|
|
Value = Section->MipsReg_S(Command.rs);
|
|
|
|
}
|
|
|
|
if (Value >= 0) {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->MipsRegLo(31) = CRecompilerOps::CompilePC() + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),31,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->MipsRegLo(31) = CRecompilerOps::CompilePC() + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
if (Command.Hex == 0x0407000D) { break; }
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 4\n%s",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_JAL:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->MipsRegLo(31) = CRecompilerOps::CompilePC() + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = (CRecompilerOps::CompilePC() & 0xF0000000) + (Command.target << 2);
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),31,0)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_J:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = (CRecompilerOps::CompilePC() & 0xF0000000) + (Command.target << 2);
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) { Section->m_Jump.PermLoop = true; }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case R4300i_BEQ:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,Command.rt)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs) && Section->IsConst(Command.rt))
|
|
|
|
{
|
|
|
|
__int64 Value1, Value2;
|
|
|
|
if (Section->Is32Bit(Command.rs))
|
|
|
|
{
|
|
|
|
Value1 = Section->MipsRegLo_S(Command.rs);
|
|
|
|
} else {
|
|
|
|
Value1 = Section->MipsReg_S(Command.rs);
|
|
|
|
}
|
|
|
|
if (Section->Is32Bit(Command.rt))
|
|
|
|
{
|
|
|
|
Value2 = Section->MipsRegLo_S(Command.rt);
|
|
|
|
} else {
|
|
|
|
Value2 = Section->MipsReg_S(Command.rt);
|
|
|
|
}
|
|
|
|
if (Value1 == Value2)
|
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = -1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BNE:
|
|
|
|
case R4300i_BLEZ:
|
|
|
|
case R4300i_BGTZ:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,Command.rt)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_ADDI:
|
|
|
|
case R4300i_ADDIU:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rs == Command.rt) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegLo(Command.rt) = Section->MipsRegLo(Command.rs) + (short)Command.immediate;
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SLTI:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsRegLo(Command.rt) = (Section->MipsReg_S(Command.rs) < (_int64)((short)Command.immediate))?1:0;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rt) = (Section->MipsRegLo_S(Command.rs) < (int)((short)Command.immediate))?1:0;
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_SLTIU:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rs)) {
|
|
|
|
Section->MipsRegLo(Command.rt) = (Section->MipsReg(Command.rs) < (unsigned _int64)((short)Command.immediate))?1:0;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegLo(Command.rt) = (Section->MipsRegLo(Command.rs) < (DWORD)((short)Command.immediate))?1:0;
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_LUI:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
Section->MipsRegLo(Command.rt) = ((short)Command.offset << 16);
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
break;
|
|
|
|
case R4300i_ANDI:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rs == Command.rt) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rt) = Section->MipsRegLo(Command.rs) & Command.immediate;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_ORI:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rs == Command.rt) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rt) = Section->MipsRegLo(Command.rs) | Command.immediate;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_XORI:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rs == Command.rt) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_32;
|
|
|
|
Section->MipsRegLo(Command.rt) = Section->MipsRegLo(Command.rs) ^ Command.immediate;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP0:
|
|
|
|
switch (Command.rs) {
|
|
|
|
case R4300i_COP0_MF:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case R4300i_COP0_MT: break;
|
|
|
|
default:
|
|
|
|
if ( (Command.rs & 0x10 ) != 0 ) {
|
|
|
|
switch( Command.funct ) {
|
|
|
|
case R4300i_COP0_CO_TLBR: break;
|
|
|
|
case R4300i_COP0_CO_TLBWI: break;
|
|
|
|
case R4300i_COP0_CO_TLBWR: break;
|
|
|
|
case R4300i_COP0_CO_TLBP: break;
|
|
|
|
case R4300i_COP0_CO_ERET: NextInstruction = END_BLOCK; break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo\n%s",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 3\n%s",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP1:
|
|
|
|
switch (Command.fmt) {
|
|
|
|
case R4300i_COP1_CF:
|
|
|
|
case R4300i_COP1_MF:
|
|
|
|
case R4300i_COP1_DMF:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_BC:
|
|
|
|
switch (Command.ft) {
|
|
|
|
case R4300i_COP1_BC_BCFL:
|
|
|
|
case R4300i_COP1_BC_BCTL:
|
|
|
|
NextInstruction = LIKELY_DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int EffectDelaySlot;
|
|
|
|
OPCODE NewCommand;
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
if (!_MMU->LW_VAddr(CRecompilerOps::CompilePC() + 4, NewCommand.Hex)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectDelaySlot = false;
|
|
|
|
if (NewCommand.op == R4300i_CP1) {
|
|
|
|
if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) {
|
|
|
|
EffectDelaySlot = true;
|
|
|
|
}
|
|
|
|
if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) {
|
|
|
|
EffectDelaySlot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!EffectDelaySlot) {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_BC_BCF:
|
|
|
|
case R4300i_COP1_BC_BCT:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int EffectDelaySlot;
|
|
|
|
OPCODE NewCommand;
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
if (!_MMU->LW_VAddr(CRecompilerOps::CompilePC() + 4, NewCommand.Hex)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectDelaySlot = false;
|
|
|
|
if (NewCommand.op == R4300i_CP1) {
|
|
|
|
if (NewCommand.fmt == R4300i_COP1_S && (NewCommand.funct & 0x30) == 0x30 ) {
|
|
|
|
EffectDelaySlot = true;
|
|
|
|
}
|
|
|
|
if (NewCommand.fmt == R4300i_COP1_D && (NewCommand.funct & 0x30) == 0x30 ) {
|
|
|
|
EffectDelaySlot = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!EffectDelaySlot) {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_MT: break;
|
|
|
|
case R4300i_COP1_DMT: break;
|
|
|
|
case R4300i_COP1_CT: break;
|
|
|
|
case R4300i_COP1_S: break;
|
|
|
|
case R4300i_COP1_D: break;
|
|
|
|
case R4300i_COP1_W: break;
|
|
|
|
case R4300i_COP1_L: break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 2\n%s",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BEQL:
|
|
|
|
case R4300i_BNEL:
|
|
|
|
case R4300i_BLEZL:
|
|
|
|
case R4300i_BGTZL:
|
|
|
|
NextInstruction = LIKELY_DELAY_SLOT;
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = CRecompilerOps::CompilePC() + 8;
|
|
|
|
Section->m_Jump.TargetPC = CRecompilerOps::CompilePC() + ((short)Command.offset << 2) + 4;
|
|
|
|
if (CRecompilerOps::CompilePC() == Section->m_Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(CRecompilerOps::CompilePC(),Command.rs,Command.rt)) {
|
|
|
|
Section->m_Jump.PermLoop = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_DADDI:
|
|
|
|
case R4300i_DADDIU:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
if (Section->InLoop && Command.rs == Command.rt) {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
if (Section->Is64Bit(Command.rs)) {
|
|
|
|
int imm32 = (short)Opcode.immediate;
|
|
|
|
__int64 imm64 = imm32;
|
|
|
|
Section->MipsReg_S(Command.rt) = Section->MipsRegLo_S(Command.rs) + imm64;
|
|
|
|
} else {
|
|
|
|
Section->MipsReg_S(Command.rt) = Section->MipsRegLo_S(Command.rs) + (short)Command.immediate;
|
|
|
|
}
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_CONST_64;
|
|
|
|
} else {
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_LDR:
|
|
|
|
case R4300i_LDL:
|
|
|
|
case R4300i_LB:
|
|
|
|
case R4300i_LH:
|
|
|
|
case R4300i_LWL:
|
|
|
|
case R4300i_LW:
|
|
|
|
case R4300i_LWU:
|
|
|
|
case R4300i_LL:
|
|
|
|
case R4300i_LBU:
|
|
|
|
case R4300i_LHU:
|
|
|
|
case R4300i_LWR:
|
|
|
|
case R4300i_SC:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case R4300i_SB: break;
|
|
|
|
case R4300i_SH: break;
|
|
|
|
case R4300i_SWL: break;
|
|
|
|
case R4300i_SW: break;
|
|
|
|
case R4300i_SWR: break;
|
|
|
|
case R4300i_SDL: break;
|
|
|
|
case R4300i_SDR: break;
|
|
|
|
case R4300i_CACHE: break;
|
|
|
|
case R4300i_LWC1: break;
|
|
|
|
case R4300i_SWC1: break;
|
|
|
|
case R4300i_LDC1: break;
|
|
|
|
case R4300i_LD:
|
|
|
|
if (Command.rt == 0) { break; }
|
|
|
|
Section->MipsRegState(Command.rt) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case R4300i_SDC1: break;
|
|
|
|
case R4300i_SD: break;
|
|
|
|
default:
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Command.Hex == 0x7C1C97C0) { break; }
|
|
|
|
if (Command.Hex == 0x7FFFFFFF) { break; }
|
|
|
|
if (Command.Hex == 0xF1F3F5F7) { break; }
|
|
|
|
if (Command.Hex == 0xC1200000) { break; }
|
|
|
|
if (Command.Hex == 0x4C5A5353) { break; }
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 1\n%s\n%X",
|
2010-05-30 01:54:42 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()),Command.Hex);
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
// if (CRecompilerOps::CompilePC() == 0x8005E4B8) {
|
|
|
|
//CPU_Message("%X: %s %s = %d",CRecompilerOps::CompilePC(),R4300iOpcodeName(Command.Hex,CRecompilerOps::CompilePC()),
|
2010-05-23 10:05:41 +00:00
|
|
|
// CRegName::GPR[8],Section->MipsRegState(8));
|
2008-09-18 03:15:49 +00:00
|
|
|
//_asm int 3
|
|
|
|
// }
|
|
|
|
switch (NextInstruction) {
|
|
|
|
case NORMAL:
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case DELAY_SLOT:
|
|
|
|
NextInstruction = DELAY_SLOT_DONE;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case LIKELY_DELAY_SLOT:
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->m_Cont.TargetPC == Section->m_Jump.TargetPC)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Cont.DoneDelaySlot = false;
|
|
|
|
Section->m_Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Cont.DoneDelaySlot = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
} else {
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Cont.DoneDelaySlot = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = LIKELY_DELAY_SLOT_DONE;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DELAY_SLOT_DONE:
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Cont.DoneDelaySlot = true;
|
|
|
|
Section->m_Jump.DoneDelaySlot = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
break;
|
|
|
|
case LIKELY_DELAY_SLOT_DONE:
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->m_Jump.DoneDelaySlot = true;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
if ((CRecompilerOps::CompilePC() & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
if (NextInstruction != END_BLOCK && NextInstruction != NORMAL) {
|
|
|
|
// DisplayError("Branch running over delay slot ???\nNextInstruction == %d",NextInstruction);
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Cont.TargetPC = (DWORD)-1;
|
|
|
|
Section->m_Jump.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-30 01:54:42 +00:00
|
|
|
CRecompilerOps::CompilePC() -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} while (NextInstruction != END_BLOCK);
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->m_Cont.TargetPC != (DWORD)-1) {
|
|
|
|
if ((Section->m_Cont.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) {
|
|
|
|
Section->m_Cont.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
if (Section->m_Jump.TargetPC != (DWORD)-1) {
|
|
|
|
if (Section->m_Jump.TargetPC < Section->BlockInfo->StartVAddr)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-30 01:54:42 +00:00
|
|
|
Section->m_Jump.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-30 01:54:42 +00:00
|
|
|
if ((Section->m_Jump.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) {
|
|
|
|
Section->m_Jump.TargetPC = (DWORD)-1;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::RecompilerMain_ChangeMemory ( void )
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
2008-09-18 03:15:49 +00:00
|
|
|
#ifdef tofix
|
|
|
|
DWORD Value, Addr;
|
|
|
|
BYTE * Block;
|
|
|
|
|
|
|
|
while(!EndEmulation()) {
|
|
|
|
if (UseTlb) {
|
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) {
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) {
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Failed to tranlate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
#endif
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Addr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NextInstruction == DELAY_SLOT) {
|
|
|
|
__try {
|
|
|
|
Value = (DWORD)(*(DelaySlotTable + (Addr >> 12)));
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X",PROGRAM_COUNTER);
|
|
|
|
#endif
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
if ( (Value >> 16) == 0x7C7C) {
|
|
|
|
DWORD Index = (Value & 0xFFFF);
|
|
|
|
Block = (BYTE *)OrigMem[Index].CompiledLocation;
|
|
|
|
if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
|
|
|
|
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
|
|
|
|
if (Index >= TargetIndex) { Block = NULL; }
|
|
|
|
} else {
|
|
|
|
Block = NULL;
|
|
|
|
}
|
|
|
|
if (Block == NULL) {
|
|
|
|
DWORD MemValue;
|
|
|
|
|
|
|
|
Block = CompileDelaySlot();
|
|
|
|
Value = 0x7C7C0000;
|
|
|
|
Value += (WORD)(TargetIndex);
|
2010-05-22 04:47:15 +00:00
|
|
|
MemValue = *(DWORD *)(RDRAM + Addr);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ( (MemValue >> 16) == 0x7C7C) {
|
|
|
|
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
|
|
|
|
}
|
|
|
|
OrigMem[(WORD)(TargetIndex)].OriginalValue = MemValue;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].CompiledLocation = Block;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].PAddr = Addr;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].VAddr = PROGRAM_COUNTER;
|
|
|
|
TargetIndex += 1;
|
|
|
|
*(DelaySlotTable + (Addr >> 12)) = (void *)Value;
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
}
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
__try {
|
2010-05-22 04:47:15 +00:00
|
|
|
Value = *(DWORD *)(RDRAM + Addr);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ( (Value >> 16) == 0x7C7C) {
|
|
|
|
DWORD Index = (Value & 0xFFFF);
|
|
|
|
Block = (BYTE *)OrigMem[Index].CompiledLocation;
|
|
|
|
if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
|
|
|
|
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
|
|
|
|
if (Index >= TargetIndex) { Block = NULL; }
|
|
|
|
} else {
|
|
|
|
Block = NULL;
|
|
|
|
}
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Block == NULL) {
|
|
|
|
DWORD MemValue;
|
|
|
|
|
|
|
|
__try {
|
|
|
|
Block = Compiler4300iBlock();
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
ResetRecompCode();
|
|
|
|
Block = Compiler4300iBlock();
|
|
|
|
}
|
|
|
|
if (EndEmulation())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (TargetIndex == MaxOrigMem) {
|
|
|
|
ResetRecompCode();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Value = 0x7C7C0000;
|
|
|
|
Value += (WORD)(TargetIndex);
|
2010-05-22 04:47:15 +00:00
|
|
|
MemValue = *(DWORD *)(RDRAM + Addr);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ( (MemValue >> 16) == 0x7C7C) {
|
|
|
|
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
|
|
|
|
}
|
|
|
|
OrigMem[(WORD)(TargetIndex)].OriginalValue = MemValue;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].CompiledLocation = Block;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].PAddr = Addr;
|
|
|
|
OrigMem[(WORD)(TargetIndex)].VAddr = PROGRAM_COUNTER;
|
|
|
|
TargetIndex += 1;
|
2010-05-22 04:47:15 +00:00
|
|
|
*(DWORD *)(RDRAM + Addr) = Value;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = NORMAL;
|
|
|
|
}
|
|
|
|
if (Profiling && IndvidualBlock) {
|
|
|
|
static DWORD ProfAddress = 0;
|
|
|
|
|
|
|
|
/*if ((PROGRAM_COUNTER & ~0xFFF) != ProfAddress) {
|
|
|
|
char Label[100];
|
|
|
|
|
|
|
|
ProfAddress = PROGRAM_COUNTER & ~0xFFF;
|
|
|
|
sprintf(Label,"PC: %X to %X",ProfAddress,ProfAddress+ 0xFFC);
|
|
|
|
StartTimer(Label);
|
|
|
|
}*/
|
|
|
|
/*if (PROGRAM_COUNTER >= 0x800DD000 && PROGRAM_COUNTER <= 0x800DDFFC) {
|
|
|
|
char Label[100];
|
|
|
|
sprintf(Label,"PC: %X Block: %X",PROGRAM_COUNTER,Block);
|
|
|
|
StartTimer(Label);
|
|
|
|
}*/
|
|
|
|
// } else if ((Profiling || ShowCPUPer) && ProfilingLabel[0] == 0) {
|
|
|
|
// StartTimer("r4300i Running");
|
|
|
|
}
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
} // end for(;;)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * CRecompiler::CompilerCode ( void )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CheckRecompMem();
|
|
|
|
|
|
|
|
DWORD pAddr;
|
|
|
|
if (!_TransVaddr->TranslateVaddr(*_PROGRAM_COUNTER,pAddr))
|
|
|
|
{
|
|
|
|
WriteTraceF(TraceError,"CRecompiler::CompilerCode: Failed to translate %X",*_PROGRAM_COUNTER);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:54:42 +00:00
|
|
|
DWORD StartTime = timeGetTime();
|
|
|
|
WriteTraceF(TraceRecompiler,"Compile Block-Start: Program Counter: %X pAddr: %X",*_PROGRAM_COUNTER,pAddr);
|
|
|
|
|
|
|
|
|
2010-06-07 02:23:58 +00:00
|
|
|
CCodeBlock CodeBlock(*_PROGRAM_COUNTER, RecompPos(),false);
|
2010-05-30 01:54:42 +00:00
|
|
|
if (!CodeBlock.Compile())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
CCompiledFunc * Func = new CCompiledFunc(CodeBlock);
|
|
|
|
m_Functions.push_back(Func);
|
|
|
|
return Func;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CRecompiler::ClearRecompCode_Phys(DWORD Address, int length, REMOVE_REASON Reason ) {
|
2010-06-04 06:25:07 +00:00
|
|
|
WriteTraceF(TraceError,"CRecompiler::ClearRecompCode_Phys Not Implemented (Address: %X, Length: %d Reason: %d)",Address,length,Reason);
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
bool Result = true;
|
2010-06-04 06:25:07 +00:00
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!ClearRecompCode_Virt(Address + 0x80000000,length,Reason)) { Result = false; }
|
|
|
|
if (!ClearRecompCode_Virt(Address + 0xA0000000,length,Reason)) { Result = false; }
|
|
|
|
|
|
|
|
if (g_UseTlb)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
2010-05-22 04:47:15 +00:00
|
|
|
#ifdef tofix
|
2010-05-25 09:15:19 +00:00
|
|
|
DWORD VAddr, Index = 0;
|
2010-05-22 04:47:15 +00:00
|
|
|
while (_TLB->PAddrToVAddr(Address,VAddr,Index))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
WriteTraceF(TraceRecompiler,"ClearRecompCode Vaddr %X len: %d",VAddr,length);
|
|
|
|
if (!ClearRecompCode_Virt(VAddr,length,Reason))
|
|
|
|
{
|
|
|
|
Result = false;
|
|
|
|
}
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (LookUpMode() == FuncFind_PhysicalLookup)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
WriteTraceF(TraceRecompiler,"Reseting Jump Table, Addr: %X len: %d",Address,((length + 3) & ~3));
|
|
|
|
memset((BYTE *)JumpTable + Address,0,((length + 3) & ~3));
|
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
void CRecompiler::ClearRecompCode_Virt(DWORD Address, int length,REMOVE_REASON Reason )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-06-04 06:25:07 +00:00
|
|
|
switch (LookUpMode())
|
|
|
|
{
|
|
|
|
case FuncFind_VirtualLookup:
|
|
|
|
{
|
|
|
|
DWORD AddressIndex = Address >> 0xC;
|
2010-06-12 02:02:06 +00:00
|
|
|
BYTE ** DelaySlotFuncs = DelaySlotTable();
|
|
|
|
|
|
|
|
if ((Address & 0xFFC) == 0 && DelaySlotFuncs[AddressIndex] != NULL)
|
|
|
|
{
|
|
|
|
DelaySlotFuncs[AddressIndex] = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-04 06:25:07 +00:00
|
|
|
DWORD WriteStart = (Address & 0xFFC);
|
|
|
|
DWORD DataInBlock = 0x1000 - WriteStart;
|
|
|
|
int DataToWrite = length < DataInBlock ? length : DataInBlock;
|
|
|
|
int DataLeft = length - DataToWrite;
|
|
|
|
|
2010-06-12 02:02:06 +00:00
|
|
|
PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex];
|
2010-06-04 06:25:07 +00:00
|
|
|
if (table)
|
|
|
|
{
|
2010-06-14 21:14:58 +00:00
|
|
|
memset(((BYTE *)&table[0]) + WriteStart,0,DataToWrite);
|
2010-06-04 06:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (DataLeft > 0)
|
|
|
|
{
|
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WriteTraceF(TraceError,"CRecompiler::ClearRecompCode_Virt Not Implemented (Address: %X, Length: %d Reason: %d)",Address,length,Reason);
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
/* CCompiledFunc * info;
|
2008-09-18 03:15:49 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
info = m_Functions.FindFunction(Address,length);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
RemoveFunction(info,false,Reason);
|
|
|
|
}
|
|
|
|
} while (info != NULL);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
info = m_FunctionsDelaySlot.FindFunction(Address,length);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
RemoveFunction(info,true,Reason);
|
|
|
|
}
|
|
|
|
} while (info != NULL);
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_Protect())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
DWORD Start = Address & ~0xFFF;
|
|
|
|
info = m_Functions.FindFunction(Start,0xFFF);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
WriteTraceF(TraceDebug,"Function exists at %X End: %X",info->VStartPC(),info->VEndPC());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
info = m_FunctionsDelaySlot.FindFunction(Start,0xFFF);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
WriteTraceF(TraceDebug,"Delay function exists at %X End: %X",info->VStartPC(),info->VEndPC());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2010-05-25 09:15:19 +00:00
|
|
|
}*/
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|