2008-09-18 03:15:49 +00:00
|
|
|
#include "..\..\N64 System.h"
|
|
|
|
#include "..\C Core\c core.h"
|
|
|
|
#include "..\C Core\Recompiler Ops.h"
|
|
|
|
#include "..\C Core\X86.h"
|
|
|
|
#include "..\C Core\CPU.h"
|
|
|
|
|
|
|
|
#undef PROGRAM_COUNTER
|
|
|
|
#undef RdramSize
|
2008-11-14 20:51:06 +00:00
|
|
|
#undef LookUpMode
|
|
|
|
#undef LinkBlocks
|
|
|
|
#undef CountPerOp
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
CRecompiler::CRecompiler(CProfiling & Profile, bool & EndEmulation, bool SyncSystem) :
|
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),
|
2008-09-18 03:15:49 +00:00
|
|
|
m_EndEmulation(EndEmulation),
|
|
|
|
m_SyncSystem(SyncSystem),
|
|
|
|
m_FunctionsDelaySlot()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CRecompiler::~CRecompiler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteTrace(TraceError,"CRecompiler::Run Fix _MMU->AllocateRecompilerMemory");
|
2010-05-22 04:47:15 +00:00
|
|
|
#ifdef tofix
|
|
|
|
if (!_MMU->AllocateRecompilerMemory(LookUpMode() != FuncFind_VirtualLookup && LookUpMode() != FuncFind_ChangeMemory))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
JumpTable = _MMU->GetJumpTable();
|
|
|
|
RecompCode = _MMU->GetRecompCode();
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
ResetRecompCode();
|
|
|
|
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-05-25 09:15:19 +00:00
|
|
|
CFunctionMap::PCCompiledFunc_TABLE table = m_FunctionTable[PROGRAM_COUNTER >> 0xC];
|
|
|
|
if (table)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * info = table[(PROGRAM_COUNTER & 0xFFF) >> 2];
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
(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__);
|
|
|
|
/* CFunctionMap::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
|
|
|
}*/
|
|
|
|
/* CFunctionMap::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-05-25 09:15:19 +00:00
|
|
|
/*
|
2008-09-18 03:15:49 +00:00
|
|
|
RecompPos = RecompCode;
|
|
|
|
|
|
|
|
m_Functions.Reset();
|
|
|
|
m_FunctionsDelaySlot.Reset();
|
|
|
|
if (JumpTable)
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
memset(JumpTable,0,_MMU->RdramSize());
|
2008-09-18 03:15:49 +00:00
|
|
|
memset(JumpTable + (0x04000000 >> 2),0,0x1000);
|
|
|
|
memset(JumpTable + (0x04001000 >> 2),0,0x1000);
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bRomInMemory())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
memset(JumpTable + (0x10000000 >> 2),0,RomFileSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef to_clean
|
|
|
|
DWORD count, OldProtect;
|
|
|
|
if (SelfModCheck == ModCode_ChangeMemory) {
|
|
|
|
DWORD count, PAddr, Value;
|
|
|
|
|
|
|
|
for (count = 0; count < TargetIndex; count++) {
|
|
|
|
PAddr = OrigMem[(WORD)(count)].PAddr;
|
2010-05-22 04:47:15 +00:00
|
|
|
Value = *(DWORD *)(RDRAM + PAddr);
|
2008-09-18 03:15:49 +00:00
|
|
|
if ( ((Value >> 16) == 0x7C7C) && ((Value & 0xFFFF) == count)) {
|
2010-05-22 04:47:15 +00:00
|
|
|
*(DWORD *)(RDRAM + PAddr) = OrigMem[(WORD)(count)].OriginalValue;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TargetIndex = 0;
|
|
|
|
|
|
|
|
//Jump Table
|
|
|
|
for (count = 0; count < (RdramSize >> 12); count ++ ) {
|
|
|
|
if (N64_Blocks.NoOfRDRamBlocks[count] > 0) {
|
|
|
|
N64_Blocks.NoOfRDRamBlocks[count] = 0;
|
|
|
|
memset(JumpTable + (count << 10),0,0x1000);
|
|
|
|
*(DelaySlotTable + count) = NULL;
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
if (VirtualProtect((RDRAM + (count << 12)), 4, PAGE_READWRITE, &OldProtect) == 0) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("Failed to unprotect %X\n1", (count << 12));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (N64_Blocks.NoOfDMEMBlocks > 0) {
|
|
|
|
N64_Blocks.NoOfDMEMBlocks = 0;
|
|
|
|
memset(JumpTable + (0x04000000 >> 2),0,0x1000);
|
|
|
|
*(DelaySlotTable + (0x04000000 >> 12)) = NULL;
|
2010-05-22 04:47:15 +00:00
|
|
|
if (VirtualProtect((RDRAM + 0x04000000), 4, PAGE_READWRITE, &OldProtect) == 0) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("Failed to unprotect %X\n0", 0x04000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (N64_Blocks.NoOfIMEMBlocks > 0) {
|
|
|
|
N64_Blocks.NoOfIMEMBlocks = 0;
|
|
|
|
memset(JumpTable + (0x04001000 >> 2),0,0x1000);
|
|
|
|
*(DelaySlotTable + (0x04001000 >> 12)) = NULL;
|
2010-05-22 04:47:15 +00:00
|
|
|
if (VirtualProtect((RDRAM + 0x04001000), 4, PAGE_READWRITE, &OldProtect) == 0) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("Failed to unprotect %X\n4", 0x04001000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if (N64_Blocks.NoOfPifRomBlocks > 0) {
|
|
|
|
// N64_Blocks.NoOfPifRomBlocks = 0;
|
|
|
|
// memset(JumpTable + (0x1FC00000 >> 2),0,0x1000);
|
|
|
|
// }
|
|
|
|
#endif
|
2010-05-25 09:15:19 +00:00
|
|
|
*/
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * CRecompiler::CompileDelaySlot(DWORD PC)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
WriteTraceF(TraceRecompiler,"Compile Delay Slot: %X",PC);
|
2010-05-25 09:15:19 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
if ((PC & 0xFFC) != 0) {
|
|
|
|
DisplayError("Why are you compiling the Delay Slot at %X",PC);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
if (!_MMU->LW_VAddr(PC, g_Opcode.Hex)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("TLB Miss in delay slot\nEmulation will know stop");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * info = m_FunctionsDelaySlot.AddFunctionInfo(PC, _TLB->TranslateVaddr(PC));
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
CBlockInfo BlockInfo(PROGRAM_COUNTER, RecompPos);
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Section = &BlockInfo.ParentSection;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
BYTE * Block = RecompPos;
|
|
|
|
DWORD StartAddress;
|
|
|
|
if (!TranslateVaddr(PC, &StartAddress))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
if (StartAddress < RdramSize()) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CPU_Message("====== RDRAM: Delay Slot ======");
|
|
|
|
} else if (StartAddress >= 0x04000000 && StartAddress <= 0x04000FFC) {
|
|
|
|
CPU_Message("====== DMEM: Delay Slot ======");
|
|
|
|
} else if (StartAddress >= 0x04001000 && StartAddress <= 0x04001FFC) {
|
|
|
|
CPU_Message("====== IMEM: Delay Slot ======");
|
|
|
|
} else if (StartAddress >= 0x1FC00000 && StartAddress <= 0x1FC00800) {
|
|
|
|
CPU_Message("====== PIF ROM: Delay Slot ======");
|
|
|
|
} else {
|
|
|
|
CPU_Message("====== Unknown: Delay Slot ======");
|
|
|
|
}
|
|
|
|
CPU_Message("x86 code at: %X",Block);
|
|
|
|
CPU_Message("Delay Slot location: %X",PROGRAM_COUNTER );
|
|
|
|
CPU_Message("====== recompiled code ======");
|
|
|
|
|
|
|
|
Section->AddParent(NULL);
|
2008-11-14 20:51:06 +00:00
|
|
|
Section->BlockCycleCount() += CountPerOp();
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->BlockRandomModifier() += 1;
|
|
|
|
|
|
|
|
switch (Opcode.op) {
|
|
|
|
case R4300i_SPECIAL:
|
|
|
|
switch (Opcode.funct) {
|
|
|
|
case R4300i_SPECIAL_SLL: Compile_R4300i_SPECIAL_SLL(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRL: Compile_R4300i_SPECIAL_SRL(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRA: Compile_R4300i_SPECIAL_SRA(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLLV: Compile_R4300i_SPECIAL_SLLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRLV: Compile_R4300i_SPECIAL_SRLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRAV: Compile_R4300i_SPECIAL_SRAV(Section); break;
|
|
|
|
case R4300i_SPECIAL_MFLO: Compile_R4300i_SPECIAL_MFLO(Section); break;
|
|
|
|
case R4300i_SPECIAL_MTLO: Compile_R4300i_SPECIAL_MTLO(Section); break;
|
|
|
|
case R4300i_SPECIAL_MFHI: Compile_R4300i_SPECIAL_MFHI(Section); break;
|
|
|
|
case R4300i_SPECIAL_MTHI: Compile_R4300i_SPECIAL_MTHI(Section); break;
|
|
|
|
case R4300i_SPECIAL_MULT: Compile_R4300i_SPECIAL_MULT(Section); break;
|
|
|
|
case R4300i_SPECIAL_DIV: Compile_R4300i_SPECIAL_DIV(Section); break;
|
|
|
|
case R4300i_SPECIAL_DIVU: Compile_R4300i_SPECIAL_DIVU(Section); break;
|
|
|
|
case R4300i_SPECIAL_MULTU: Compile_R4300i_SPECIAL_MULTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DMULTU: Compile_R4300i_SPECIAL_DMULTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DDIVU: Compile_R4300i_SPECIAL_DDIVU(Section); break;
|
|
|
|
case R4300i_SPECIAL_ADD: Compile_R4300i_SPECIAL_ADD(Section); break;
|
|
|
|
case R4300i_SPECIAL_ADDU: Compile_R4300i_SPECIAL_ADDU(Section); break;
|
|
|
|
case R4300i_SPECIAL_SUB: Compile_R4300i_SPECIAL_SUB(Section); break;
|
|
|
|
case R4300i_SPECIAL_SUBU: Compile_R4300i_SPECIAL_SUBU(Section); break;
|
|
|
|
case R4300i_SPECIAL_AND: Compile_R4300i_SPECIAL_AND(Section); break;
|
|
|
|
case R4300i_SPECIAL_OR: Compile_R4300i_SPECIAL_OR(Section); break;
|
|
|
|
case R4300i_SPECIAL_XOR: Compile_R4300i_SPECIAL_XOR(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLT: Compile_R4300i_SPECIAL_SLT(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLTU: Compile_R4300i_SPECIAL_SLTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DADD: Compile_R4300i_SPECIAL_DADD(Section); break;
|
|
|
|
case R4300i_SPECIAL_DADDU: Compile_R4300i_SPECIAL_DADDU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSLL32: Compile_R4300i_SPECIAL_DSLL32(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRA32: Compile_R4300i_SPECIAL_DSRA32(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_ADDI: Compile_R4300i_ADDI(Section); break;
|
|
|
|
case R4300i_ADDIU: Compile_R4300i_ADDIU(Section); break;
|
|
|
|
case R4300i_SLTI: Compile_R4300i_SLTI(Section); break;
|
|
|
|
case R4300i_SLTIU: Compile_R4300i_SLTIU(Section); break;
|
|
|
|
case R4300i_ANDI: Compile_R4300i_ANDI(Section); break;
|
|
|
|
case R4300i_ORI: Compile_R4300i_ORI(Section); break;
|
|
|
|
case R4300i_XORI: Compile_R4300i_XORI(Section); break;
|
|
|
|
case R4300i_LUI: Compile_R4300i_LUI(Section); break;
|
|
|
|
case R4300i_CP1:
|
|
|
|
switch (Opcode.rs) {
|
|
|
|
case R4300i_COP1_CF: Compile_R4300i_COP1_CF(Section); break;
|
|
|
|
case R4300i_COP1_MT: Compile_R4300i_COP1_MT(Section); break;
|
|
|
|
case R4300i_COP1_CT: Compile_R4300i_COP1_CT(Section); break;
|
|
|
|
case R4300i_COP1_MF: Compile_R4300i_COP1_MF(Section); break;
|
|
|
|
case R4300i_COP1_S:
|
|
|
|
switch (Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_S_ADD(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_S_SUB(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_S_MUL(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_S_DIV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_S_ABS(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_S_NEG(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_S_SQRT(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_S_MOV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_S_CVT_D(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_S_ROUND_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_S_TRUNC_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_S_FLOOR_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
|
|
|
|
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
|
|
|
|
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
|
|
|
|
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
|
|
|
|
Compile_R4300i_COP1_S_CMP(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_D:
|
|
|
|
switch (Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_D_ADD(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_D_SUB(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_D_MUL(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_D_DIV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_D_ABS(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_D_NEG(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_D_SQRT(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_D_MOV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_D_TRUNC_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_D_CVT_S(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_D_CVT_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
|
|
|
|
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
|
|
|
|
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
|
|
|
|
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
|
|
|
|
Compile_R4300i_COP1_D_CMP(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_W:
|
|
|
|
switch (Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_W_CVT_S(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_W_CVT_D(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_LB: Compile_R4300i_LB(Section); break;
|
|
|
|
case R4300i_LH: Compile_R4300i_LH(Section); break;
|
|
|
|
case R4300i_LW: Compile_R4300i_LW(Section); break;
|
|
|
|
case R4300i_LBU: Compile_R4300i_LBU(Section); break;
|
|
|
|
case R4300i_LHU: Compile_R4300i_LHU(Section); break;
|
|
|
|
case R4300i_SB: Compile_R4300i_SB(Section); break;
|
|
|
|
case R4300i_SH: Compile_R4300i_SH(Section); break;
|
|
|
|
case R4300i_SW: Compile_R4300i_SW(Section); break;
|
|
|
|
case R4300i_SWR: Compile_R4300i_SWR(Section); break;
|
|
|
|
case R4300i_CACHE: Compile_R4300i_CACHE(Section); break;
|
|
|
|
case R4300i_LWC1: Compile_R4300i_LWC1(Section); break;
|
|
|
|
case R4300i_LDC1: Compile_R4300i_LDC1(Section); break;
|
|
|
|
case R4300i_LD: Compile_R4300i_LD(Section); break;
|
|
|
|
case R4300i_SWC1: Compile_R4300i_SWC1(Section); break;
|
|
|
|
case R4300i_SDC1: Compile_R4300i_SDC1(Section); break;
|
|
|
|
case R4300i_SD: Compile_R4300i_SD(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Section->ResetX86Protection();
|
|
|
|
|
|
|
|
WriteBackRegisters(Section);
|
|
|
|
UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(), FALSE);
|
|
|
|
int x86Reg = Map_TempReg(Section,x86_Any,-1,FALSE);
|
|
|
|
MoveVariableToX86reg(&JumpToLocation,"JumpToLocation",x86Reg);
|
|
|
|
MoveX86regToVariable(x86Reg,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
|
|
|
MoveConstToVariable(NORMAL,&NextInstruction,"NextInstruction");
|
|
|
|
if (CPU_Type == CPU_SyncCores) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
Ret();
|
|
|
|
CompileExitCode(BlockInfo);
|
|
|
|
CPU_Message("====== End of recompiled code ======");
|
|
|
|
|
|
|
|
info->SetVEndPC(BlockInfo.EndVAddr);
|
|
|
|
info->SetFunctionAddr(BlockInfo.CompiledLocation);
|
2010-05-22 04:47:15 +00:00
|
|
|
_TLB->VAddrToRealAddr(info->VStartPC(),*(reinterpret_cast<void **>(&info->MemLocation[0])));
|
2008-09-18 03:15:49 +00:00
|
|
|
info->MemLocation[1] = info->MemLocation[0] + 1;
|
|
|
|
info->MemContents[0] = *info->MemLocation[0];
|
|
|
|
info->MemContents[1] = *info->MemLocation[1];
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
return info;
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
|
|
|
return NULL;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRecompiler::AnalyseBlock ( CBlockInfo & BlockInfo)
|
|
|
|
{
|
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-25 09:15:19 +00:00
|
|
|
DetermineLoop(Section,CCodeSection::GetNewTestValue(),CCodeSection::GetNewTestValue(), Section->SectionID);
|
|
|
|
while (FixConstants(Section,CCodeSection::GetNewTestValue())) {}
|
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
|
|
|
{
|
|
|
|
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];
|
|
|
|
*/
|
|
|
|
CRegInfo Original[2] = { Section->Cont.RegSet, Section->Jump.RegSet };
|
|
|
|
|
|
|
|
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;
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Parent->ContinueSection == Section) {
|
|
|
|
for (int count = 0; count < 32; count++) {
|
|
|
|
if (Section->RegStart.MipsRegState(count) != Parent->Cont.RegSet.MipsRegState(count)) {
|
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
//*Changed = true;
|
|
|
|
}
|
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Parent->JumpSection == Section) {
|
|
|
|
for (int count = 0; count < 32; count++) {
|
|
|
|
if (Section->RegStart.MipsRegState(count) != Parent->Jump.RegSet.MipsRegState(count)) {
|
|
|
|
Section->RegStart.MipsRegState(count) = CRegInfo::STATE_UNKNOWN;
|
|
|
|
//*Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FillSectionInfo(Section, NORMAL);
|
|
|
|
if (Original[0] != Section->Cont.RegSet)
|
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
if (Original[1] != Section->Jump.RegSet)
|
|
|
|
{
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Section->JumpSection && FixConstants(Section->JumpSection,Test)) { Changed = true; }
|
|
|
|
if (Section->ContinueSection && FixConstants(Section->ContinueSection,Test)) { Changed = true; }
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::InheritConstants(CCodeSection * Section)
|
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());
|
2008-09-18 03:15:49 +00:00
|
|
|
CRegInfo * RegSet = (Section == Parent->ContinueSection?&Parent->Cont.RegSet:&Parent->Jump.RegSet);
|
|
|
|
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;
|
|
|
|
RegSet = Section == Parent->ContinueSection?&Parent->Cont.RegSet:&Parent->Jump.RegSet;
|
|
|
|
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
CCodeSection * CRecompiler::ExistingSection(CCodeSection * StartSection, DWORD Addr, DWORD Test)
|
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-25 09:15:19 +00:00
|
|
|
CCodeSection * Section = ExistingSection(StartSection->JumpSection,Addr,Test);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Section != NULL) { return Section; }
|
|
|
|
Section = ExistingSection(StartSection->ContinueSection,Addr,Test);
|
|
|
|
if (Section != NULL) { return Section; }
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::CreateSectionLinkage (CCodeSection * Section) {
|
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];
|
|
|
|
if (Section->Jump.TargetPC < Section->Cont.TargetPC) {
|
2010-05-25 09:15:19 +00:00
|
|
|
TargetSection[0] = (CCodeSection **)&Section->JumpSection;
|
|
|
|
TargetSection[1] = (CCodeSection **)&Section->ContinueSection;
|
2008-09-18 03:15:49 +00:00
|
|
|
JumpInfo[0] = &Section->Jump;
|
|
|
|
JumpInfo[1] = &Section->Cont;
|
|
|
|
} else {
|
2010-05-25 09:15:19 +00:00
|
|
|
TargetSection[0] = (CCodeSection **)&Section->ContinueSection;
|
|
|
|
TargetSection[1] = (CCodeSection **)&Section->JumpSection;
|
2008-09-18 03:15:49 +00:00
|
|
|
JumpInfo[0] = &Section->Cont;
|
|
|
|
JumpInfo[1] = &Section->Jump;
|
|
|
|
}
|
|
|
|
|
|
|
|
CBlockInfo * BlockInfo = Section->BlockInfo;
|
|
|
|
|
|
|
|
for (int count = 0; count < 2; count ++)
|
|
|
|
{
|
|
|
|
if (JumpInfo[count]->TargetPC == (DWORD)-1 || *TargetSection[count] != NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!JumpInfo[count]->DoneDelaySlot)
|
|
|
|
{
|
|
|
|
Section->Jump.RegSet = Section->RegWorking;
|
|
|
|
|
|
|
|
//this is a special delay slot section
|
|
|
|
BlockInfo->NoOfSections += 1;
|
2010-05-25 09:15:19 +00:00
|
|
|
*TargetSection[count] = new CCodeSection(BlockInfo,Section->m_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;
|
|
|
|
}
|
|
|
|
(*TargetSection[count])->Jump.TargetPC = -1;
|
|
|
|
(*TargetSection[count])->Cont.TargetPC = JumpInfo[count]->TargetPC;
|
|
|
|
(*TargetSection[count])->Cont.FallThrough = true;
|
|
|
|
(*TargetSection[count])->Cont.RegSet = (*TargetSection[count])->RegWorking;
|
2010-05-25 09:15:19 +00:00
|
|
|
JumpInfo[count]->TargetPC = Section->m_CompilePC + 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
//Create the section that joins with that block
|
2010-05-25 09:15:19 +00:00
|
|
|
(*TargetSection[count])->ContinueSection = ExistingSection(&BlockInfo->ParentSection,(*TargetSection[count])->Cont.TargetPC,CCodeSection::GetNewTestValue());
|
2008-09-18 03:15:49 +00:00
|
|
|
if ((*TargetSection[count])->ContinueSection == NULL) {
|
|
|
|
BlockInfo->NoOfSections += 1;
|
2010-05-25 09:15:19 +00:00
|
|
|
(*TargetSection[count])->ContinueSection = new CCodeSection(BlockInfo,(*TargetSection[count])->Cont.TargetPC,BlockInfo->NoOfSections);
|
2008-09-18 03:15:49 +00:00
|
|
|
(*TargetSection[count])->ContinueSection->AddParent((*TargetSection[count]));
|
|
|
|
CreateSectionLinkage((*TargetSection[count])->ContinueSection);
|
|
|
|
} else {
|
|
|
|
(*TargetSection[count])->ContinueSection->AddParent((*TargetSection[count]));
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC = Section->StartPC;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
NextInstruction = StartStepType;
|
|
|
|
do {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!_MMU->LW_VAddr(Section->m_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)) {
|
|
|
|
Section->Jump.TargetPC = Section->MipsRegLo(Command.rs);
|
|
|
|
} else {
|
|
|
|
Section->Jump.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_JALR:
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->MipsRegLo(Opcode.rd) = Section->m_CompilePC + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(Opcode.rd) = CRegInfo::STATE_CONST_32;
|
|
|
|
if (Section->IsConst(Command.rs)) {
|
|
|
|
Section->Jump.TargetPC = Section->MipsRegLo(Command.rs);
|
|
|
|
} else {
|
|
|
|
Section->Jump.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
NextInstruction = DELAY_SLOT;
|
|
|
|
break;
|
|
|
|
case R4300i_SPECIAL_SYSCALL:
|
|
|
|
case R4300i_SPECIAL_BREAK:
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BLTZL:
|
|
|
|
case R4300i_REGIMM_BGEZL:
|
|
|
|
NextInstruction = LIKELY_DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM_BLTZAL:
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->MipsRegLo(31) = Section->m_CompilePC + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
Section->MipsRegLo(31) = Section->m_CompilePC + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,31,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->MipsRegLo(31) = Section->m_CompilePC + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
if (Command.Hex == 0x0407000D) { break; }
|
|
|
|
DisplayError("Unhandled R4300i OpCode in FillSectionInfo 4\n%s",
|
2010-05-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_JAL:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->MipsRegLo(31) = Section->m_CompilePC + 8;
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->MipsRegState(31) = CRegInfo::STATE_CONST_32;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Jump.TargetPC = (Section->m_CompilePC & 0xF0000000) + (Command.target << 2);
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,31,0)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_J:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Jump.TargetPC = (Section->m_CompilePC & 0xF0000000) + (Command.target << 2);
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) { Section->Jump.PermLoop = true; }
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case R4300i_BEQ:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,Command.rt)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Section->Cont.TargetPC = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BNE:
|
|
|
|
case R4300i_BLEZ:
|
|
|
|
case R4300i_BGTZ:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,Command.rt)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int EffectDelaySlot;
|
|
|
|
OPCODE NewCommand;
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!_MMU->LW_VAddr(Section->m_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) {
|
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_BC_BCF:
|
|
|
|
case R4300i_COP1_BC_BCT:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int EffectDelaySlot;
|
|
|
|
OPCODE NewCommand;
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!_MMU->LW_VAddr(Section->m_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) {
|
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC));
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
Section->Cont.TargetPC = Section->m_CompilePC + 8;
|
|
|
|
Section->Jump.TargetPC = Section->m_CompilePC + ((short)Command.offset << 2) + 4;
|
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC) {
|
|
|
|
if (!DelaySlotEffectsCompare(Section->m_CompilePC,Command.rs,Command.rt)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->Jump.PermLoop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-25 09:15:19 +00:00
|
|
|
Section->m_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-25 09:15:19 +00:00
|
|
|
R4300iOpcodeName(Command.Hex,Section->m_CompilePC),Command.Hex);
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
// if (Section->m_CompilePC == 0x8005E4B8) {
|
|
|
|
//CPU_Message("%X: %s %s = %d",Section->m_CompilePC,R4300iOpcodeName(Command.Hex,Section->m_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-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case DELAY_SLOT:
|
|
|
|
NextInstruction = DELAY_SLOT_DONE;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case LIKELY_DELAY_SLOT:
|
|
|
|
if (Section->Cont.TargetPC == Section->Jump.TargetPC)
|
|
|
|
{
|
|
|
|
Section->Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->Cont.DoneDelaySlot = false;
|
|
|
|
Section->Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->Cont.DoneDelaySlot = true;
|
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
} else {
|
|
|
|
Section->Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->Cont.DoneDelaySlot = true;
|
|
|
|
NextInstruction = LIKELY_DELAY_SLOT_DONE;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DELAY_SLOT_DONE:
|
|
|
|
Section->Cont.RegSet = Section->RegWorking;
|
|
|
|
Section->Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->Cont.DoneDelaySlot = true;
|
|
|
|
Section->Jump.DoneDelaySlot = true;
|
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
break;
|
|
|
|
case LIKELY_DELAY_SLOT_DONE:
|
|
|
|
Section->Jump.RegSet = Section->RegWorking;
|
|
|
|
Section->Jump.DoneDelaySlot = true;
|
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
if ((Section->m_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);
|
|
|
|
Section->Cont.TargetPC = (DWORD)-1;
|
|
|
|
Section->Jump.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
NextInstruction = END_BLOCK;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} while (NextInstruction != END_BLOCK);
|
|
|
|
|
|
|
|
if (Section->Cont.TargetPC != (DWORD)-1) {
|
|
|
|
if ((Section->Cont.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) {
|
|
|
|
Section->Cont.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Section->Jump.TargetPC != (DWORD)-1) {
|
|
|
|
if (Section->Jump.TargetPC < Section->BlockInfo->StartVAddr)
|
|
|
|
{
|
|
|
|
Section->Jump.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
if ((Section->Jump.TargetPC & 0xFFFFF000) != (Section->StartPC & 0xFFFFF000)) {
|
|
|
|
Section->Jump.TargetPC = (DWORD)-1;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::CompileExitCode ( CBlockInfo & BlockInfo )
|
|
|
|
{
|
|
|
|
for (EXIT_LIST::iterator ExitIter = BlockInfo.ExitInfo.begin(); ExitIter != BlockInfo.ExitInfo.end(); ExitIter++)
|
|
|
|
{
|
|
|
|
CPU_Message("");
|
|
|
|
CPU_Message(" $Exit_%d",ExitIter->ID);
|
|
|
|
SetJump32(ExitIter->JumpLoc,RecompPos);
|
|
|
|
NextInstruction = ExitIter->NextInstruction;
|
|
|
|
CompileExit(&BlockInfo.ParentSection, -1, ExitIter->TargetPC,ExitIter->ExitRegSet,ExitIter->reason,true,NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCompiledFunc * info = new CCompiledFunc(PROGRAM_COUNTER,pAddr);
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
WriteTrace(TraceError,"CRecompiler::CompilerCode: Failed to allocate CCompiledFunc");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!info->CompilerCodeBlock())
|
|
|
|
{
|
|
|
|
WriteTrace(TraceError,"CRecompiler::CompilerCode: Failed to compile code block");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-22 04:47:15 +00:00
|
|
|
#ifdef tofix
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info = m_Functions.AddFunctionInfo(PROGRAM_COUNTER,_TLB->TranslateVaddr(PROGRAM_COUNTER));
|
2008-09-18 03:15:49 +00:00
|
|
|
__try {
|
|
|
|
if (!Compiler4300iBlock(Info))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Info;
|
|
|
|
} __except(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
ResetRecompCode();
|
2010-05-22 04:47:15 +00:00
|
|
|
Info = m_Functions.AddFunctionInfo(PROGRAM_COUNTER,_TLB->TranslateVaddr(PROGRAM_COUNTER));
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!Compiler4300iBlock(Info))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Info;
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::CheckRecompMem ( void )
|
|
|
|
{
|
|
|
|
int Size = (int)((BYTE *)RecompPos - (BYTE *)m_RecompCode);
|
|
|
|
if ((Size + 0x20000) < m_RecompSize)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_RecompSize == MaxCompileBufferSize)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LPVOID MemAddr = VirtualAlloc( m_RecompCode + m_RecompSize , IncreaseCompileBufferSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
m_RecompSize += IncreaseCompileBufferSize;
|
|
|
|
|
|
|
|
if (MemAddr == NULL)
|
|
|
|
{
|
|
|
|
_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::DetermineLoop(CCodeSection * Section, DWORD Test, DWORD Test2, DWORD TestID)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if (Section == NULL) { return; }
|
|
|
|
if (Section->SectionID != TestID) {
|
|
|
|
if (Section->Test2 == Test2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Section->Test2 = Test2;
|
|
|
|
DetermineLoop(Section->ContinueSection,Test,Test2,TestID);
|
|
|
|
DetermineLoop(Section->JumpSection,Test,Test2,TestID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Section->Test2 == Test2) {
|
|
|
|
Section->InLoop = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Section->Test2 = Test2;
|
|
|
|
DetermineLoop(Section->ContinueSection,Test,Test2,TestID);
|
|
|
|
DetermineLoop(Section->JumpSection,Test,Test2,TestID);
|
|
|
|
if (Section->Test == Test) { return; }
|
|
|
|
Section->Test = Test;
|
|
|
|
if (Section->ContinueSection != NULL) {
|
2010-05-25 09:15:19 +00:00
|
|
|
DetermineLoop(Section->ContinueSection,Test,CCodeSection::GetNewTestValue(),Section->ContinueSection->SectionID);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
if (Section->JumpSection != NULL) {
|
2010-05-25 09:15:19 +00:00
|
|
|
DetermineLoop(Section->JumpSection,Test,CCodeSection::GetNewTestValue(),Section->JumpSection->SectionID);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::DisplaySectionInformation (CCodeSection * Section, DWORD ID, DWORD Test)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
if (!IsX86Logging())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Section == NULL) { return false; }
|
|
|
|
if (Section->Test == Test) { return false; }
|
|
|
|
Section->Test = Test;
|
|
|
|
if (Section->SectionID != ID) {
|
|
|
|
if (DisplaySectionInformation(Section->ContinueSection,ID,Test)) { return true; }
|
|
|
|
if (DisplaySectionInformation(Section->JumpSection,ID,Test)) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
CPU_Message("====== Section %d ======",Section->SectionID);
|
|
|
|
CPU_Message("Start PC: %X",Section->StartPC);
|
|
|
|
CPU_Message("CompiledLocation: %X",RecompPos);
|
|
|
|
if (!Section->ParentSection.empty())
|
|
|
|
{
|
|
|
|
stdstr ParentList;
|
|
|
|
for (SECTION_LIST::iterator iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2008-09-18 03:15:49 +00:00
|
|
|
if (!ParentList.empty())
|
|
|
|
{
|
|
|
|
ParentList += ", ";
|
|
|
|
}
|
|
|
|
ParentList += stdstr_f("%d",Parent->SectionID);
|
|
|
|
}
|
|
|
|
CPU_Message("Number of parents: %d (%s)",Section->ParentSection.size(),ParentList.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Section->JumpSection != NULL) {
|
|
|
|
CPU_Message("Jump Section: %d",Section->JumpSection->SectionID);
|
|
|
|
} else {
|
|
|
|
CPU_Message("Jump Section: None");
|
|
|
|
}
|
|
|
|
if (Section->ContinueSection != NULL) {
|
|
|
|
CPU_Message("Continue Section: %d",Section->ContinueSection->SectionID);
|
|
|
|
} else {
|
|
|
|
CPU_Message("Continue Section: None");
|
|
|
|
}
|
|
|
|
CPU_Message("=======================",Section->SectionID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::InheritParentInfo (CCodeSection * Section)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
/* int count, start, NoOfParents, NoOfCompiledParents, FirstParent,CurrentParent;
|
|
|
|
BLOCK_PARENT * SectionParents;
|
|
|
|
BLOCK_SECTION * Parent;
|
|
|
|
JUMP_INFO * JumpInfo;
|
|
|
|
char Label[100];
|
|
|
|
BOOL NeedSync;
|
|
|
|
*/
|
2010-05-25 09:15:19 +00:00
|
|
|
DisplaySectionInformation(Section,Section->SectionID,CCodeSection::GetNewTestValue());
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (Section->ParentSection.empty())
|
|
|
|
{
|
|
|
|
Section->RegStart.Initilize();
|
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Section->ParentSection.size() == 1)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *(Section->ParentSection.begin());
|
2008-09-18 03:15:49 +00:00
|
|
|
CJumpInfo * JumpInfo = Section == Parent->ContinueSection ? &Parent->Cont : &Parent->Jump;
|
|
|
|
|
|
|
|
Section->RegStart = JumpInfo->RegSet;
|
|
|
|
if (JumpInfo->LinkLocation != NULL) {
|
|
|
|
CPU_Message(" Section_%d:",Section->SectionID);
|
|
|
|
SetJump32(JumpInfo->LinkLocation,RecompPos);
|
|
|
|
if (JumpInfo->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation2,RecompPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegWorking = Section->RegStart;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Multiple Parents
|
|
|
|
BLOCK_PARENT_LIST ParentList;
|
|
|
|
SECTION_LIST::iterator iter;
|
|
|
|
for (iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2008-09-18 03:15:49 +00:00
|
|
|
BLOCK_PARENT BlockParent;
|
|
|
|
|
|
|
|
if (Parent->CompiledLocation == NULL) { continue; }
|
|
|
|
if (Parent->JumpSection != Parent->ContinueSection) {
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = Section == Parent->ContinueSection?&Parent->Cont:&Parent->Jump;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
} else {
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = &Parent->Cont;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = &Parent->Jump;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int NoOfCompiledParents = ParentList.size();
|
|
|
|
if (NoOfCompiledParents == 0)
|
|
|
|
{
|
|
|
|
DisplayError("No Parent has been compiled ????");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all the uncompiled blocks to the end of the list
|
|
|
|
for (iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2008-09-18 03:15:49 +00:00
|
|
|
BLOCK_PARENT BlockParent;
|
|
|
|
|
|
|
|
if (Parent->CompiledLocation != NULL) { continue; }
|
|
|
|
if (Parent->JumpSection != Parent->ContinueSection) {
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = Section == Parent->ContinueSection?&Parent->Cont:&Parent->Jump;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
} else {
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = &Parent->Cont;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
BlockParent.Parent = Parent;
|
|
|
|
BlockParent.JumpInfo = &Parent->Jump;
|
|
|
|
ParentList.push_back(BlockParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int FirstParent = 0;
|
|
|
|
for (int count = 1;count < NoOfCompiledParents;count++) {
|
|
|
|
if (ParentList[count].JumpInfo->FallThrough) {
|
|
|
|
FirstParent = count; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Link First Parent to start
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = ParentList[FirstParent].Parent;
|
2008-09-18 03:15:49 +00:00
|
|
|
CJumpInfo * JumpInfo = ParentList[FirstParent].JumpInfo;
|
|
|
|
|
|
|
|
Section->RegWorking = JumpInfo->RegSet;
|
|
|
|
if (JumpInfo->LinkLocation != NULL) {
|
|
|
|
CPU_Message(" Section_%d (from %d):",Section->SectionID,Parent->SectionID);
|
|
|
|
SetJump32(JumpInfo->LinkLocation,RecompPos);
|
|
|
|
JumpInfo->LinkLocation = NULL;
|
|
|
|
if (JumpInfo->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->StartPC < Parent->m_CompilePC )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
UpdateCounters(&JumpInfo->RegSet.BlockCycleCount(),&JumpInfo->RegSet.BlockRandomModifier(),true);
|
|
|
|
CompileSystemCheck(Section->StartPC,JumpInfo->RegSet);
|
|
|
|
} else {
|
|
|
|
UpdateCounters(&JumpInfo->RegSet.BlockCycleCount(),&JumpInfo->RegSet.BlockRandomModifier(),false);
|
|
|
|
}
|
|
|
|
JumpInfo->FallThrough = false;
|
|
|
|
|
|
|
|
//Fix up initial state
|
|
|
|
UnMap_AllFPRs(Section);
|
|
|
|
for (count = 0;count < ParentList.size();count++) {
|
|
|
|
int count2, MemoryStackPos;
|
|
|
|
|
|
|
|
if (count == FirstParent) { continue; }
|
|
|
|
Parent = ParentList[count].Parent;
|
|
|
|
CRegInfo * RegSet = &ParentList[count].JumpInfo->RegSet;
|
|
|
|
|
|
|
|
if (Section->CurrentRoundingModel() != RegSet->CurrentRoundingModel()) { Section->CurrentRoundingModel() = CRegInfo::RoundUnknown; }
|
|
|
|
if (ParentList.size() != NoOfCompiledParents) { Section->CurrentRoundingModel() = CRegInfo::RoundUnknown; }
|
|
|
|
|
|
|
|
//Find Parent MapRegState
|
|
|
|
MemoryStackPos = -1;
|
|
|
|
for (count2 = 1; count2 < 10; count2++) {
|
|
|
|
if (RegSet->x86Mapped(count2) == CRegInfo::Stack_Mapped) {
|
|
|
|
MemoryStackPos = count2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MemoryStackPos < 0) {
|
|
|
|
// if the memory stack position is not mapped then unmap it
|
|
|
|
int MemStackReg = Map_MemoryStack(Section,x86_Any,false);
|
|
|
|
if (MemStackReg > 0)
|
|
|
|
{
|
|
|
|
UnMap_X86reg(Section,MemStackReg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (count2 = 1; count2 < 32; count2++) {
|
|
|
|
if (Section->Is32BitMapped(count2)) {
|
|
|
|
switch (RegSet->MipsRegState(count2)) {
|
|
|
|
case CRegInfo::STATE_MAPPED_64: Map_GPR_64bit(Section,count2,count2); break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO: break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
if (Section->IsUnsigned(count2)) {
|
|
|
|
Section->MipsRegState(count2) = CRegInfo::STATE_MAPPED_32_SIGN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_64: Map_GPR_64bit(Section,count2,count2); break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if ((RegSet->MipsRegLo_S(count2) < 0) && Section->IsUnsigned(count2)) {
|
|
|
|
Section->MipsRegState(count2) = CRegInfo::STATE_MAPPED_32_SIGN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_UNKNOWN:
|
|
|
|
//Map_GPR_32bit(Section,count2,true,count2);
|
|
|
|
Map_GPR_64bit(Section,count2,count2); //??
|
|
|
|
//UnMap_GPR(Section,count2,true); ??
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
DisplayError("Unknown CPU State(%d) in InheritParentInfo",RegSet->MipsRegState(count2));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Section->IsConst(count2)) {
|
|
|
|
if (Section->MipsRegState(count2) != RegSet->MipsRegState(count2)) {
|
|
|
|
if (Section->Is32Bit(count2)) {
|
|
|
|
Map_GPR_32bit(Section,count2,true,count2);
|
|
|
|
} else {
|
|
|
|
Map_GPR_32bit(Section,count2,true,count2);
|
|
|
|
}
|
|
|
|
} else if (Section->Is32Bit(count2) && Section->MipsRegLo(count2) != RegSet->MipsRegLo(count2)) {
|
|
|
|
Map_GPR_32bit(Section,count2,true,count2);
|
|
|
|
} else if (Section->Is64Bit(count2) && Section->MipsReg(count2) != RegSet->MipsReg(count2)) {
|
|
|
|
Map_GPR_32bit(Section,count2,true,count2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->ResetX86Protection();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MemoryStackPos > 0)
|
|
|
|
{
|
|
|
|
Map_MemoryStack(Section,MemoryStackPos,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegStart = Section->RegWorking;
|
|
|
|
|
|
|
|
//Sync registers for different blocks
|
|
|
|
char Label[100];
|
|
|
|
sprintf(Label,"Section_%d",Section->SectionID);
|
|
|
|
int CurrentParent = FirstParent;
|
|
|
|
bool NeedSync = false;
|
|
|
|
for (count = 0;count < NoOfCompiledParents;count++) {
|
|
|
|
CRegInfo * RegSet;
|
|
|
|
int count2;
|
|
|
|
|
|
|
|
if (count == FirstParent) { continue; }
|
|
|
|
Parent = ParentList[count].Parent;
|
|
|
|
JumpInfo = ParentList[count].JumpInfo;
|
|
|
|
RegSet = &ParentList[count].JumpInfo->RegSet;
|
|
|
|
|
|
|
|
if (JumpInfo->RegSet.BlockCycleCount() != 0) { NeedSync = true; }
|
|
|
|
if (JumpInfo->RegSet.BlockRandomModifier() != 0) { NeedSync = true; }
|
|
|
|
|
|
|
|
for (count2 = 0; count2 < 8; count2++) {
|
|
|
|
if (Section->FpuMappedTo(count2) == (DWORD)-1) {
|
|
|
|
NeedSync = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count2 = 1; count2 < 10; count2++) {
|
|
|
|
if (Section->x86Mapped(count2) == CRegInfo::Stack_Mapped) {
|
|
|
|
if (Section->x86Mapped(count2) != RegSet->x86Mapped(count2)) {
|
|
|
|
NeedSync = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (count2 = 0; count2 < 32; count2++) {
|
|
|
|
if (NeedSync == true) { break; }
|
|
|
|
if (Section->MipsRegState(count2) != RegSet->MipsRegState(count2)) {
|
|
|
|
NeedSync = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (Section->MipsRegState(count2)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN: break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
if (Section->MipsReg(count2) != RegSet->MipsReg(count2)) {
|
|
|
|
NeedSync = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
if (Section->MipsRegLo(count2) != RegSet->MipsRegLo(count2)) {
|
|
|
|
//DisplayError("Parent: %d",Parent->SectionID);
|
|
|
|
NeedSync = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if (Section->MipsRegLo(count2) != RegSet->MipsRegLo(count2)) {
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
|
|
|
DisplayError("Umm.. how ???");
|
|
|
|
#endif
|
|
|
|
NeedSync = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
DisplayError("Unhandled Reg state %d\nin InheritParentInfo",Section->MipsRegState(count2));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NeedSync == false) { continue; }
|
|
|
|
Parent = ParentList[CurrentParent].Parent;
|
|
|
|
JumpInfo = ParentList[CurrentParent].JumpInfo;
|
|
|
|
JmpLabel32(Label,0);
|
|
|
|
JumpInfo->LinkLocation = RecompPos - 4;
|
|
|
|
JumpInfo->LinkLocation2 = NULL;
|
|
|
|
|
|
|
|
CurrentParent = count;
|
|
|
|
Parent = ParentList[CurrentParent].Parent;
|
|
|
|
JumpInfo = ParentList[CurrentParent].JumpInfo;
|
|
|
|
CPU_Message(" Section_%d (from %d):",Section->SectionID,Parent->SectionID);
|
|
|
|
if (JumpInfo->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation,RecompPos);
|
|
|
|
JumpInfo->LinkLocation = NULL;
|
|
|
|
if (JumpInfo->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Section->RegWorking = JumpInfo->RegSet;
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->StartPC < Parent->m_CompilePC )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),true);
|
|
|
|
CompileSystemCheck(Section->StartPC,Section->RegWorking);
|
|
|
|
} else {
|
|
|
|
UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
|
|
|
}
|
|
|
|
SyncRegState(Section,&Section->RegStart); //Sync
|
|
|
|
Section->RegStart = Section->RegWorking;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0;count < NoOfCompiledParents;count++) {
|
|
|
|
Parent = ParentList[count].Parent;
|
|
|
|
JumpInfo = ParentList[count].JumpInfo;
|
|
|
|
|
|
|
|
if (JumpInfo->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation,RecompPos);
|
|
|
|
JumpInfo->LinkLocation = NULL;
|
|
|
|
if (JumpInfo->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPU_Message(" Section_%d:",Section->SectionID);
|
|
|
|
Section->BlockCycleCount() = 0;
|
|
|
|
Section->BlockRandomModifier() = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
bool CRecompiler::GenerateX86Code(CBlockInfo & BlockInfo, CCodeSection * Section, DWORD Test )
|
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
|
|
|
if (Section == NULL) { return false; }
|
|
|
|
|
|
|
|
if (Section->CompiledLocation != NULL) {
|
|
|
|
if (Section->Test == Test) { return false; }
|
|
|
|
Section->Test = Test;
|
|
|
|
if (GenerateX86Code(BlockInfo,Section->ContinueSection,Test)) { return true; }
|
|
|
|
if (GenerateX86Code(BlockInfo,Section->JumpSection,Test)) { return true; }
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Section->ParentSection.size() > 0)
|
|
|
|
{
|
|
|
|
for (SECTION_LIST::iterator iter = Section->ParentSection.begin(); iter != Section->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2008-09-18 03:15:49 +00:00
|
|
|
if (Parent->CompiledLocation != NULL) { continue; }
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->IsAllParentLoops(Parent,true,CCodeSection::GetNewTestValue())) { continue; }
|
2008-09-18 03:15:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!InheritParentInfo(Section)) { return false; }
|
|
|
|
Section->CompiledLocation = RecompPos;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC = Section->StartPC;
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = NORMAL;
|
|
|
|
/*if (m_SyncSystem) {
|
|
|
|
//if (m_SyncSystem && (DWORD)RecompPos > 0x6094C283) {
|
|
|
|
MoveConstToVariable(Section->StartPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
|
|
|
if (BlockCycleCount != 0) {
|
2010-05-23 10:05:41 +00:00
|
|
|
AddConstToVariable(BlockCycleCount,&_CP0[9],CRegName::Cop0[9]);
|
2008-09-18 03:15:49 +00:00
|
|
|
SubConstFromVariable(BlockCycleCount,&Timers.Timer,"Timer");
|
|
|
|
}
|
2010-05-23 10:05:41 +00:00
|
|
|
if (BlockRandomModifier != 0) { SubConstFromVariable(BlockRandomModifier,&_CP0[1],CRegName::Cop0[1]); }
|
2008-09-18 03:15:49 +00:00
|
|
|
BlockCycleCount = 0;
|
|
|
|
BlockRandomModifier = 0;
|
|
|
|
Call_Direct(SyncToPC, "SyncToPC");
|
|
|
|
MoveConstToVariable((DWORD)RecompPos,&CurrentBlock,"CurrentBlock");
|
|
|
|
}*/
|
|
|
|
do {
|
|
|
|
__try {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (!_MMU->LW_VAddr(Section->m_CompilePC, g_Opcode.Hex)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError(GS(MSG_FAIL_LOAD_WORD));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
2010-05-22 04:47:15 +00:00
|
|
|
} __except( _MMU->MemoryFilter( GetExceptionCode(), GetExceptionInformation()) ) {
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError(GS(MSG_UNKNOWN_MEM_ACTION));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
//if (Section->m_CompilePC == 0x800AA51C && NextInstruction == NORMAL) { _asm int 3 }
|
|
|
|
// if (Section->m_CompilePC == 0xF000044 && NextInstruction == NORMAL)
|
2008-09-18 03:15:49 +00:00
|
|
|
// {
|
|
|
|
// WriteBackRegisters(Section);
|
|
|
|
// UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
|
|
|
//
|
2010-05-23 10:05:41 +00:00
|
|
|
// CompConstToVariable(0x26D5BB0,&_CP0[9],CRegName::Cop0[9]);
|
2008-09-18 03:15:49 +00:00
|
|
|
// JlLabel8("blah",0);
|
|
|
|
// BYTE * Jump = RecompPos - 1;
|
|
|
|
// // BreakPoint(__FILE__,__LINE__);
|
|
|
|
// X86BreakPoint(__FILE__,__LINE__);
|
|
|
|
// *((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
|
|
|
|
// }
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (Section->m_CompilePC >= 0x800C4024 && Section->m_CompilePC < 0x800C4030) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CurrentRoundingModel = RoundUnknown;
|
|
|
|
}*/
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
// if (Section->m_CompilePC >= 0x800017A8 && Section->m_CompilePC < 0x800017DC && NextInstruction == NORMAL) {
|
2008-09-18 03:15:49 +00:00
|
|
|
// WriteBackRegisters(Section);
|
|
|
|
// UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
2010-05-25 09:15:19 +00:00
|
|
|
// MoveConstToVariable(Section->m_CompilePC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
// //MoveConstToVariable((DWORD)RecompPos,&CurrentBlock,"CurrentBlock");
|
|
|
|
// if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
// }
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
// if (Section->m_CompilePC >= 0x8005E984 && Section->m_CompilePC < 0x8005EA84 && NextInstruction == NORMAL) {
|
2008-09-18 03:15:49 +00:00
|
|
|
// WriteBackRegisters(Section);
|
|
|
|
// UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
2010-05-25 09:15:19 +00:00
|
|
|
// MoveConstToVariable(Section->m_CompilePC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
// //MoveConstToVariable((DWORD)RecompPos,&CurrentBlock,"CurrentBlock");
|
|
|
|
// if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
// }
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
// if (Section->m_CompilePC >= 0xF000000 && Section->m_CompilePC < 0xF000500 && NextInstruction == NORMAL) {
|
2008-09-18 03:15:49 +00:00
|
|
|
// WriteBackRegisters(Section);
|
|
|
|
// UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
2010-05-25 09:15:19 +00:00
|
|
|
// MoveConstToVariable(Section->m_CompilePC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
// //MoveConstToVariable((DWORD)RecompPos,&CurrentBlock,"CurrentBlock");
|
|
|
|
// if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
// }
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (Section->m_CompilePC == 0x802000D0 && NextInstruction == NORMAL) {
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%s = %d",CRegName::GPR[14],Section->MipsRegState(14));
|
2008-09-18 03:15:49 +00:00
|
|
|
}*/
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (Section->m_CompilePC == 0x150A1514 && NextInstruction == NORMAL) {
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%s = %d",CRegName::GPR[14],Section->MipsRegState(14));
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->m_CompilePC == 0x150A1454 && NextInstruction == NORMAL) {
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%s = %d",CRegName::GPR[14],Section->MipsRegState(14));
|
2008-09-18 03:15:49 +00:00
|
|
|
}*/
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->m_CompilePC > Section->BlockInfo->EndVAddr)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->BlockInfo->EndVAddr = Section->m_CompilePC;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
Section->BlockCycleCount() += CountPerOp();
|
2008-09-18 03:15:49 +00:00
|
|
|
//CPU_Message("BlockCycleCount = %d",BlockCycleCount);
|
|
|
|
Section->BlockRandomModifier() += 1;
|
|
|
|
//CPU_Message("BlockRandomModifier = %d",BlockRandomModifier);
|
|
|
|
|
|
|
|
Section->ResetX86Protection();
|
|
|
|
|
|
|
|
switch (g_Opcode.op) {
|
|
|
|
case R4300i_SPECIAL:
|
|
|
|
switch (g_Opcode.funct) {
|
|
|
|
case R4300i_SPECIAL_SLL: Compile_R4300i_SPECIAL_SLL(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRL: Compile_R4300i_SPECIAL_SRL(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRA: Compile_R4300i_SPECIAL_SRA(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLLV: Compile_R4300i_SPECIAL_SLLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRLV: Compile_R4300i_SPECIAL_SRLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_SRAV: Compile_R4300i_SPECIAL_SRAV(Section); break;
|
|
|
|
case R4300i_SPECIAL_JR: Compile_R4300i_SPECIAL_JR(Section); break;
|
|
|
|
case R4300i_SPECIAL_JALR: Compile_R4300i_SPECIAL_JALR(Section); break;
|
|
|
|
case R4300i_SPECIAL_MFLO: Compile_R4300i_SPECIAL_MFLO(Section); break;
|
|
|
|
case R4300i_SPECIAL_SYSCALL: Compile_R4300i_SPECIAL_SYSCALL(Section); break;
|
|
|
|
case R4300i_SPECIAL_MTLO: Compile_R4300i_SPECIAL_MTLO(Section); break;
|
|
|
|
case R4300i_SPECIAL_MFHI: Compile_R4300i_SPECIAL_MFHI(Section); break;
|
|
|
|
case R4300i_SPECIAL_MTHI: Compile_R4300i_SPECIAL_MTHI(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSLLV: Compile_R4300i_SPECIAL_DSLLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRLV: Compile_R4300i_SPECIAL_DSRLV(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRAV: Compile_R4300i_SPECIAL_DSRAV(Section); break;
|
|
|
|
case R4300i_SPECIAL_MULT: Compile_R4300i_SPECIAL_MULT(Section); break;
|
|
|
|
case R4300i_SPECIAL_DIV: Compile_R4300i_SPECIAL_DIV(Section); break;
|
|
|
|
case R4300i_SPECIAL_DIVU: Compile_R4300i_SPECIAL_DIVU(Section); break;
|
|
|
|
case R4300i_SPECIAL_MULTU: Compile_R4300i_SPECIAL_MULTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DMULT: Compile_R4300i_SPECIAL_DMULT(Section); break;
|
|
|
|
case R4300i_SPECIAL_DMULTU: Compile_R4300i_SPECIAL_DMULTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DDIV: Compile_R4300i_SPECIAL_DDIV(Section); break;
|
|
|
|
case R4300i_SPECIAL_DDIVU: Compile_R4300i_SPECIAL_DDIVU(Section); break;
|
|
|
|
case R4300i_SPECIAL_ADD: Compile_R4300i_SPECIAL_ADD(Section); break;
|
|
|
|
case R4300i_SPECIAL_ADDU: Compile_R4300i_SPECIAL_ADDU(Section); break;
|
|
|
|
case R4300i_SPECIAL_SUB: Compile_R4300i_SPECIAL_SUB(Section); break;
|
|
|
|
case R4300i_SPECIAL_SUBU: Compile_R4300i_SPECIAL_SUBU(Section); break;
|
|
|
|
case R4300i_SPECIAL_AND: Compile_R4300i_SPECIAL_AND(Section); break;
|
|
|
|
case R4300i_SPECIAL_OR: Compile_R4300i_SPECIAL_OR(Section); break;
|
|
|
|
case R4300i_SPECIAL_XOR: Compile_R4300i_SPECIAL_XOR(Section); break;
|
|
|
|
case R4300i_SPECIAL_NOR: Compile_R4300i_SPECIAL_NOR(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLT: Compile_R4300i_SPECIAL_SLT(Section); break;
|
|
|
|
case R4300i_SPECIAL_SLTU: Compile_R4300i_SPECIAL_SLTU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DADD: Compile_R4300i_SPECIAL_DADD(Section); break;
|
|
|
|
case R4300i_SPECIAL_DADDU: Compile_R4300i_SPECIAL_DADDU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSUB: Compile_R4300i_SPECIAL_DSUB(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSUBU: Compile_R4300i_SPECIAL_DSUBU(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSLL: Compile_R4300i_SPECIAL_DSLL(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRL: Compile_R4300i_SPECIAL_DSRL(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRA: Compile_R4300i_SPECIAL_DSRA(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSLL32: Compile_R4300i_SPECIAL_DSLL32(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRL32: Compile_R4300i_SPECIAL_DSRL32(Section); break;
|
|
|
|
case R4300i_SPECIAL_DSRA32: Compile_R4300i_SPECIAL_DSRA32(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_REGIMM:
|
|
|
|
switch (g_Opcode.rt) {
|
|
|
|
case R4300i_REGIMM_BLTZ:Compile_R4300i_Branch(Section,BLTZ_Compare,BranchTypeRs, false); break;
|
|
|
|
case R4300i_REGIMM_BGEZ:Compile_R4300i_Branch(Section,BGEZ_Compare,BranchTypeRs, false); break;
|
|
|
|
case R4300i_REGIMM_BLTZL:Compile_R4300i_BranchLikely(Section,BLTZ_Compare, false); break;
|
|
|
|
case R4300i_REGIMM_BGEZL:Compile_R4300i_BranchLikely(Section,BGEZ_Compare, false); break;
|
|
|
|
case R4300i_REGIMM_BLTZAL:Compile_R4300i_Branch(Section,BLTZ_Compare,BranchTypeRs, true); break;
|
|
|
|
case R4300i_REGIMM_BGEZAL:Compile_R4300i_Branch(Section,BGEZ_Compare,BranchTypeRs, true); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BEQ: Compile_R4300i_Branch(Section,BEQ_Compare,BranchTypeRsRt,false); break;
|
|
|
|
case R4300i_BNE: Compile_R4300i_Branch(Section,BNE_Compare,BranchTypeRsRt,false); break;
|
|
|
|
case R4300i_BGTZ:Compile_R4300i_Branch(Section,BGTZ_Compare,BranchTypeRs,false); break;
|
|
|
|
case R4300i_BLEZ:Compile_R4300i_Branch(Section,BLEZ_Compare,BranchTypeRs,false); break;
|
|
|
|
case R4300i_J: Compile_R4300i_J(Section); break;
|
|
|
|
case R4300i_JAL: Compile_R4300i_JAL(Section); break;
|
|
|
|
case R4300i_ADDI: Compile_R4300i_ADDI(Section); break;
|
|
|
|
case R4300i_ADDIU: Compile_R4300i_ADDIU(Section); break;
|
|
|
|
case R4300i_SLTI: Compile_R4300i_SLTI(Section); break;
|
|
|
|
case R4300i_SLTIU: Compile_R4300i_SLTIU(Section); break;
|
|
|
|
case R4300i_ANDI: Compile_R4300i_ANDI(Section); break;
|
|
|
|
case R4300i_ORI: Compile_R4300i_ORI(Section); break;
|
|
|
|
case R4300i_XORI: Compile_R4300i_XORI(Section); break;
|
|
|
|
case R4300i_LUI: Compile_R4300i_LUI(Section); break;
|
|
|
|
case R4300i_CP0:
|
|
|
|
switch (g_Opcode.rs) {
|
|
|
|
case R4300i_COP0_MF: Compile_R4300i_COP0_MF(Section); break;
|
|
|
|
case R4300i_COP0_MT: Compile_R4300i_COP0_MT(Section); break;
|
|
|
|
default:
|
|
|
|
if ( (g_Opcode.rs & 0x10 ) != 0 ) {
|
|
|
|
switch( g_Opcode.funct ) {
|
|
|
|
case R4300i_COP0_CO_TLBR: Compile_R4300i_COP0_CO_TLBR(Section); break;
|
|
|
|
case R4300i_COP0_CO_TLBWI: Compile_R4300i_COP0_CO_TLBWI(Section); break;
|
|
|
|
case R4300i_COP0_CO_TLBWR: Compile_R4300i_COP0_CO_TLBWR(Section); break;
|
|
|
|
case R4300i_COP0_CO_TLBP: Compile_R4300i_COP0_CO_TLBP(Section); break;
|
|
|
|
case R4300i_COP0_CO_ERET: Compile_R4300i_COP0_CO_ERET(Section); break;
|
|
|
|
default: Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Compile_R4300i_UnknownOpcode(Section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_CP1:
|
|
|
|
switch (g_Opcode.rs) {
|
|
|
|
case R4300i_COP1_MF: Compile_R4300i_COP1_MF(Section); break;
|
|
|
|
case R4300i_COP1_DMF: Compile_R4300i_COP1_DMF(Section); break;
|
|
|
|
case R4300i_COP1_CF: Compile_R4300i_COP1_CF(Section); break;
|
|
|
|
case R4300i_COP1_MT: Compile_R4300i_COP1_MT(Section); break;
|
|
|
|
case R4300i_COP1_DMT: Compile_R4300i_COP1_DMT(Section); break;
|
|
|
|
case R4300i_COP1_CT: Compile_R4300i_COP1_CT(Section); break;
|
|
|
|
case R4300i_COP1_BC:
|
|
|
|
switch (g_Opcode.ft) {
|
|
|
|
case R4300i_COP1_BC_BCF: Compile_R4300i_Branch(Section,COP1_BCF_Compare,BranchTypeCop1,false); break;
|
|
|
|
case R4300i_COP1_BC_BCT: Compile_R4300i_Branch(Section,COP1_BCT_Compare,BranchTypeCop1,false); break;
|
|
|
|
case R4300i_COP1_BC_BCFL: Compile_R4300i_BranchLikely(Section,COP1_BCF_Compare,false); break;
|
|
|
|
case R4300i_COP1_BC_BCTL: Compile_R4300i_BranchLikely(Section,COP1_BCT_Compare,false); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_S:
|
|
|
|
switch (g_Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_S_ADD(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_S_SUB(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_S_MUL(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_S_DIV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_S_ABS(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_S_NEG(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_S_SQRT(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_S_MOV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_L: Compile_R4300i_COP1_S_TRUNC_L(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CEIL_L: Compile_R4300i_COP1_S_CEIL_L(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_FLOOR_L: Compile_R4300i_COP1_S_FLOOR_L(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_S_ROUND_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_S_TRUNC_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CEIL_W: Compile_R4300i_COP1_S_CEIL_W(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_S_FLOOR_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_S_CVT_D(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_S_CVT_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_L: Compile_R4300i_COP1_S_CVT_L(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
|
|
|
|
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
|
|
|
|
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
|
|
|
|
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
|
|
|
|
Compile_R4300i_COP1_S_CMP(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_D:
|
|
|
|
switch (g_Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_ADD: Compile_R4300i_COP1_D_ADD(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SUB: Compile_R4300i_COP1_D_SUB(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MUL: Compile_R4300i_COP1_D_MUL(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_DIV: Compile_R4300i_COP1_D_DIV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_ABS: Compile_R4300i_COP1_D_ABS(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_NEG: Compile_R4300i_COP1_D_NEG(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_SQRT: Compile_R4300i_COP1_D_SQRT(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_MOV: Compile_R4300i_COP1_D_MOV(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_L: Compile_R4300i_COP1_D_TRUNC_L(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_CEIL_L: Compile_R4300i_COP1_D_CEIL_L(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_FLOOR_L: Compile_R4300i_COP1_D_FLOOR_L(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_ROUND_W: Compile_R4300i_COP1_D_ROUND_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_TRUNC_W: Compile_R4300i_COP1_D_TRUNC_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CEIL_W: Compile_R4300i_COP1_D_CEIL_W(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_FLOOR_W: Compile_R4300i_COP1_D_FLOOR_W(Section); break; //added by Witten
|
|
|
|
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_D_CVT_S(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_W: Compile_R4300i_COP1_D_CVT_W(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_L: Compile_R4300i_COP1_D_CVT_L(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_C_F: case R4300i_COP1_FUNCT_C_UN:
|
|
|
|
case R4300i_COP1_FUNCT_C_EQ: case R4300i_COP1_FUNCT_C_UEQ:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLT: case R4300i_COP1_FUNCT_C_ULT:
|
|
|
|
case R4300i_COP1_FUNCT_C_OLE: case R4300i_COP1_FUNCT_C_ULE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SF: case R4300i_COP1_FUNCT_C_NGLE:
|
|
|
|
case R4300i_COP1_FUNCT_C_SEQ: case R4300i_COP1_FUNCT_C_NGL:
|
|
|
|
case R4300i_COP1_FUNCT_C_LT: case R4300i_COP1_FUNCT_C_NGE:
|
|
|
|
case R4300i_COP1_FUNCT_C_LE: case R4300i_COP1_FUNCT_C_NGT:
|
|
|
|
Compile_R4300i_COP1_D_CMP(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_W:
|
|
|
|
switch (g_Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_W_CVT_S(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_W_CVT_D(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_COP1_L:
|
|
|
|
switch (g_Opcode.funct) {
|
|
|
|
case R4300i_COP1_FUNCT_CVT_S: Compile_R4300i_COP1_L_CVT_S(Section); break;
|
|
|
|
case R4300i_COP1_FUNCT_CVT_D: Compile_R4300i_COP1_L_CVT_D(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R4300i_BEQL: Compile_R4300i_BranchLikely(Section,BEQ_Compare,false); break;
|
|
|
|
case R4300i_BNEL: Compile_R4300i_BranchLikely(Section,BNE_Compare,false); break;
|
|
|
|
case R4300i_BGTZL:Compile_R4300i_BranchLikely(Section,BGTZ_Compare,false); break;
|
|
|
|
case R4300i_BLEZL:Compile_R4300i_BranchLikely(Section,BLEZ_Compare,false); break;
|
|
|
|
case R4300i_DADDIU: Compile_R4300i_DADDIU(Section); break;
|
|
|
|
case R4300i_LDL: Compile_R4300i_LDL(Section); break;
|
|
|
|
case R4300i_LDR: Compile_R4300i_LDR(Section); break;
|
|
|
|
case R4300i_LB: Compile_R4300i_LB(Section); break;
|
|
|
|
case R4300i_LH: Compile_R4300i_LH(Section); break;
|
|
|
|
case R4300i_LWL: Compile_R4300i_LWL(Section); break;
|
|
|
|
case R4300i_LW: Compile_R4300i_LW(Section); break;
|
|
|
|
case R4300i_LBU: Compile_R4300i_LBU(Section); break;
|
|
|
|
case R4300i_LHU: Compile_R4300i_LHU(Section); break;
|
|
|
|
case R4300i_LWR: Compile_R4300i_LWR(Section); break;
|
|
|
|
case R4300i_LWU: Compile_R4300i_LWU(Section); break; //added by Witten
|
|
|
|
case R4300i_SB: Compile_R4300i_SB(Section); break;
|
|
|
|
case R4300i_SH: Compile_R4300i_SH(Section); break;
|
|
|
|
case R4300i_SWL: Compile_R4300i_SWL(Section); break;
|
|
|
|
case R4300i_SW: Compile_R4300i_SW(Section); break;
|
|
|
|
case R4300i_SWR: Compile_R4300i_SWR(Section); break;
|
|
|
|
case R4300i_SDL: Compile_R4300i_SDL(Section); break;
|
|
|
|
case R4300i_SDR: Compile_R4300i_SDR(Section); break;
|
|
|
|
case R4300i_CACHE: Compile_R4300i_CACHE(Section); break;
|
|
|
|
case R4300i_LL: Compile_R4300i_LL(Section); break;
|
|
|
|
case R4300i_LWC1: Compile_R4300i_LWC1(Section); break;
|
|
|
|
case R4300i_LDC1: Compile_R4300i_LDC1(Section); break;
|
|
|
|
case R4300i_SC: Compile_R4300i_SC(Section); break;
|
|
|
|
case R4300i_LD: Compile_R4300i_LD(Section); break;
|
|
|
|
case R4300i_SWC1: Compile_R4300i_SWC1(Section); break;
|
|
|
|
case R4300i_SDC1: Compile_R4300i_SDC1(Section); break;
|
|
|
|
case R4300i_SD: Compile_R4300i_SD(Section); break;
|
|
|
|
default:
|
|
|
|
Compile_R4300i_UnknownOpcode(Section); break;
|
|
|
|
}
|
|
|
|
|
2008-11-14 20:51:06 +00:00
|
|
|
if (!bRegCaching()) { WriteBackRegisters(Section); }
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->ResetX86Protection();
|
|
|
|
|
|
|
|
/*if ((DWORD)RecompPos > 0x60B452E6) {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->m_CompilePC == 0x8002D9B8 && Section->m_CompilePC < 0x8002DA20) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CurrentRoundingModel = RoundUnknown;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
UnMap_AllFPRs(Section);
|
|
|
|
|
|
|
|
/*if ((DWORD)RecompPos > 0x60AD0BD3) {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->m_CompilePC >= 0x8008B804 && Section->m_CompilePC < 0x800496D8) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CPU_Message("Blah *");
|
|
|
|
WriteBackRegisters(Section);
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
/*if (Section->m_CompilePC >= 0x80000180 && Section->m_CompilePC < 0x80000190) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CPU_Message("Blah *");
|
|
|
|
//WriteBackRegisters(Section);
|
|
|
|
}*/
|
|
|
|
//}
|
|
|
|
|
|
|
|
/*for (count = 1; count < 10; count ++) {
|
|
|
|
if (Section->x86Mapped(count) == CRegInfo::Stack_Mapped) {
|
|
|
|
UnMap_X86reg (Section, count);
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
//CPU_Message("MemoryStack = %s",Map_MemoryStack(Section, false) > 0?x86_Name(Map_MemoryStack(Section, false)):"Not Mapped");
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
if ((Section->m_CompilePC &0xFFC) == 0xFFC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
if (NextInstruction == DO_DELAY_SLOT) {
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Wanting to do delay slot over end of block");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (NextInstruction == NORMAL) {
|
2010-05-25 09:15:19 +00:00
|
|
|
CompileExit (Section,Section->m_CompilePC, Section->m_CompilePC + 4,Section->RegWorking,CExitInfo::Normal,true,NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Section->DelaySlotSection)
|
|
|
|
{
|
|
|
|
Section->Cont.RegSet = Section->RegWorking;
|
|
|
|
GenerateSectionLinkage(Section);
|
|
|
|
NextInstruction = END_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (NextInstruction) {
|
|
|
|
case NORMAL:
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case DO_DELAY_SLOT:
|
|
|
|
NextInstruction = DELAY_SLOT;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC += 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case DELAY_SLOT:
|
|
|
|
NextInstruction = DELAY_SLOT_DONE;
|
2008-11-14 20:51:06 +00:00
|
|
|
Section->BlockCycleCount() -= CountPerOp();
|
2008-09-18 03:15:49 +00:00
|
|
|
Section->BlockRandomModifier() -= 1;
|
2010-05-25 09:15:19 +00:00
|
|
|
Section->m_CompilePC -= 4;
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (NextInstruction != END_BLOCK);
|
2010-05-25 09:15:19 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::CompileExit ( CCodeSection * Section, DWORD JumpPC, DWORD TargetPC, CRegInfo ExitRegSet, CExitInfo::EXIT_REASON reason, int CompileNow, void (*x86Jmp)(char * Label, DWORD Value))
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
CBlockInfo * const BlockInfo = Section->BlockInfo;
|
|
|
|
|
|
|
|
if (!CompileNow)
|
|
|
|
{
|
|
|
|
char String[100];
|
|
|
|
sprintf(String,"Exit_%d",BlockInfo->ExitInfo.size());
|
|
|
|
if (x86Jmp == NULL)
|
|
|
|
{
|
|
|
|
DisplayError("CompileExit error");
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
x86Jmp(String,0);
|
|
|
|
|
|
|
|
CExitInfo ExitInfo;
|
|
|
|
ExitInfo.ID = BlockInfo->ExitInfo.size();
|
|
|
|
ExitInfo.TargetPC = TargetPC;
|
|
|
|
ExitInfo.ExitRegSet = ExitRegSet;
|
|
|
|
ExitInfo.reason = reason;
|
|
|
|
ExitInfo.NextInstruction = NextInstruction;
|
|
|
|
ExitInfo.JumpLoc = RecompPos - 4;
|
|
|
|
BlockInfo->ExitInfo.push_back(ExitInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//CPU_Message("CompileExit: %d",reason);
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection TempSection(BlockInfo,-1,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
TempSection.AddParent(NULL);
|
|
|
|
TempSection.RegWorking = ExitRegSet;
|
|
|
|
|
|
|
|
if (TargetPC != (DWORD)-1)
|
|
|
|
{
|
|
|
|
MoveConstToVariable(TargetPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
|
|
|
UpdateCounters(&ExitRegSet.BlockCycleCount(),&ExitRegSet.BlockRandomModifier(),TargetPC <= JumpPC && reason == CExitInfo::Normal);
|
|
|
|
} else {
|
|
|
|
UpdateCounters(&ExitRegSet.BlockCycleCount(),&ExitRegSet.BlockRandomModifier(),reason == CExitInfo::Normal);
|
|
|
|
}
|
|
|
|
WriteBackRegisters(&TempSection);
|
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
case CExitInfo::Normal: case CExitInfo::Normal_NoSysCheck:
|
|
|
|
TempSection.RegWorking.BlockRandomModifier() = 0;
|
|
|
|
TempSection.RegWorking.BlockCycleCount() = 0;
|
|
|
|
if (TargetPC != (DWORD)-1)
|
|
|
|
{
|
|
|
|
if (TargetPC <= JumpPC && reason == CExitInfo::Normal)
|
|
|
|
{
|
|
|
|
CompileSystemCheck((DWORD)-1,TempSection.RegWorking);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (reason == CExitInfo::Normal) { CompileSystemCheck((DWORD)-1,TempSection.RegWorking); }
|
|
|
|
}
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
#ifdef LinkBlocks
|
|
|
|
if (bSMM_ValidFunc == false)
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
if (LookUpMode() == FuncFind_ChangeMemory)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
BreakPoint(__FILE__,__LINE__);
|
|
|
|
// BYTE * Jump, * Jump2;
|
|
|
|
// if (TargetPC >= 0x80000000 && TargetPC < 0xC0000000) {
|
|
|
|
// DWORD pAddr = TargetPC & 0x1FFFFFFF;
|
|
|
|
//
|
2010-05-22 04:47:15 +00:00
|
|
|
// MoveVariableToX86reg((BYTE *)RDRAM + pAddr,"RDRAM + pAddr",x86_EAX);
|
2008-09-18 03:15:49 +00:00
|
|
|
// Jump2 = NULL;
|
|
|
|
// } else {
|
|
|
|
// MoveConstToX86reg((TargetPC >> 12),x86_ECX);
|
|
|
|
// MoveConstToX86reg(TargetPC,x86_EBX);
|
|
|
|
// MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4);
|
|
|
|
// TestX86RegToX86Reg(x86_ECX,x86_ECX);
|
|
|
|
// JeLabel8("NoTlbEntry",0);
|
|
|
|
// Jump2 = RecompPos - 1;
|
|
|
|
// MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_EAX);
|
|
|
|
// }
|
|
|
|
// MoveX86RegToX86Reg(x86_EAX,x86_ECX);
|
|
|
|
// AndConstToX86Reg(x86_ECX,0xFFFF0000);
|
|
|
|
// CompConstToX86reg(x86_ECX,0x7C7C0000);
|
|
|
|
// JneLabel8("NoCode",0);
|
|
|
|
// Jump = RecompPos - 1;
|
|
|
|
// AndConstToX86Reg(x86_EAX,0xFFFF);
|
|
|
|
// ShiftLeftSignImmed(x86_EAX,4);
|
|
|
|
// AddConstToX86Reg(x86_EAX,0xC);
|
|
|
|
// MoveVariableDispToX86Reg(OrigMem,"OrigMem",x86_ECX,x86_EAX,1);
|
|
|
|
// JmpDirectReg(x86_ECX);
|
|
|
|
// CPU_Message(" NoCode:");
|
|
|
|
// *((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
|
|
|
|
// if (Jump2 != NULL) {
|
|
|
|
// CPU_Message(" NoTlbEntry:");
|
|
|
|
// *((BYTE *)(Jump2))=(BYTE)(RecompPos - Jump2 - 1);
|
|
|
|
// }
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
else if (LookUpMode() == FuncFind_VirtualLookup)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
MoveConstToX86reg(TargetPC,x86_EDX);
|
|
|
|
MoveConstToX86reg((DWORD)&m_Functions,x86_ECX);
|
|
|
|
Call_Direct(AddressOf(CFunctionMap::CompilerFindFunction), "CFunctionMap::CompilerFindFunction");
|
|
|
|
MoveX86RegToX86Reg(x86_EAX,x86_ECX);
|
|
|
|
JecxzLabel8("NullPointer",0);
|
|
|
|
BYTE * Jump = RecompPos - 1;
|
|
|
|
MoveX86PointerToX86regDisp(x86_EBX,x86_ECX,0xC);
|
|
|
|
JmpDirectReg(x86_EBX);
|
|
|
|
CPU_Message(" NullPointer:");
|
|
|
|
*((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
|
|
|
|
}
|
2008-11-14 20:51:06 +00:00
|
|
|
else if (LookUpMode() == FuncFind_PhysicalLookup)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
BYTE * Jump2 = NULL;
|
|
|
|
if (TargetPC >= 0x80000000 && TargetPC < 0x90000000) {
|
|
|
|
DWORD pAddr = TargetPC & 0x1FFFFFFF;
|
|
|
|
MoveVariableToX86reg((BYTE *)JumpTable + pAddr,"JumpTable + pAddr",x86_ECX);
|
|
|
|
} else if (TargetPC >= 0x90000000 && TargetPC < 0xC0000000) {
|
|
|
|
} else {
|
|
|
|
MoveConstToX86reg((TargetPC >> 12),x86_ECX);
|
|
|
|
MoveConstToX86reg(TargetPC,x86_EBX);
|
|
|
|
MoveVariableDispToX86Reg(TLB_ReadMap,"TLB_ReadMap",x86_ECX,x86_ECX,4);
|
|
|
|
TestX86RegToX86Reg(x86_ECX,x86_ECX);
|
|
|
|
JeLabel8("NoTlbEntry",0);
|
|
|
|
Jump2 = RecompPos - 1;
|
2010-05-22 04:47:15 +00:00
|
|
|
AddConstToX86Reg(x86_ECX,(DWORD)JumpTable - (DWORD)RDRAM);
|
2008-09-18 03:15:49 +00:00
|
|
|
MoveX86regPointerToX86reg(x86_ECX, x86_EBX,x86_ECX);
|
|
|
|
}
|
|
|
|
if (TargetPC < 0x90000000 || TargetPC >= 0xC0000000)
|
|
|
|
{
|
|
|
|
JecxzLabel8("NullPointer",0);
|
|
|
|
BYTE * Jump = RecompPos - 1;
|
|
|
|
MoveX86PointerToX86regDisp(x86_EAX,x86_ECX,0xC);
|
|
|
|
JmpDirectReg(x86_EAX);
|
|
|
|
CPU_Message(" NullPointer:");
|
|
|
|
*((BYTE *)(Jump))=(BYTE)(RecompPos - Jump - 1);
|
|
|
|
if (Jump2 != NULL) {
|
|
|
|
CPU_Message(" NoTlbEntry:");
|
|
|
|
*((BYTE *)(Jump2))=(BYTE)(RecompPos - Jump2 - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ret();
|
|
|
|
#else
|
|
|
|
Ret();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case CExitInfo::DoCPU_Action:
|
|
|
|
Call_Direct(DoSomething,"DoSomething");
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
Ret();
|
|
|
|
break;
|
|
|
|
case CExitInfo::DoSysCall:
|
|
|
|
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
|
|
|
|
Call_Direct(DoSysCallException,"DoSysCallException");
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
Ret();
|
|
|
|
break;
|
|
|
|
case CExitInfo::COP1_Unuseable:
|
|
|
|
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
|
|
|
|
MoveConstToX86reg(1,x86_EDX);
|
|
|
|
Call_Direct(DoCopUnusableException,"DoCopUnusableException");
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
Ret();
|
|
|
|
break;
|
|
|
|
case CExitInfo::ExitResetRecompCode:
|
|
|
|
if (NextInstruction == JUMP || NextInstruction == DELAY_SLOT) {
|
|
|
|
X86BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
X86BreakPoint(__FILE__,__LINE__);
|
|
|
|
MoveVariableToX86reg(this,"this",x86_ECX);
|
|
|
|
Call_Direct(AddressOf(ResetRecompCode), "ResetRecompCode");
|
|
|
|
Ret();
|
|
|
|
break;
|
|
|
|
case CExitInfo::TLBReadMiss:
|
|
|
|
MoveConstToX86reg(NextInstruction == JUMP || NextInstruction == DELAY_SLOT,x86_ECX);
|
|
|
|
MoveVariableToX86reg(&TLBLoadAddress,"TLBLoadAddress",x86_EDX);
|
|
|
|
Call_Direct(DoTLBMiss,"DoTLBMiss");
|
|
|
|
if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
Ret();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DisplayError("how did you want to exit on reason (%d) ???",reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::UpdateCounters ( DWORD * Cycles, DWORD * RandomMod, BOOL CheckTimer)
|
|
|
|
{
|
|
|
|
if (Cycles == NULL || RandomMod == NULL)
|
|
|
|
{
|
|
|
|
BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if (*RandomMod != 0 || *Cycles != 0) {
|
|
|
|
WriteX86Comment("Update Counters");
|
|
|
|
}
|
2010-05-23 10:05:41 +00:00
|
|
|
if (*RandomMod != 0) { SubConstFromVariable(*RandomMod,&_CP0[1],CRegName::Cop0[1]); }
|
2008-09-18 03:15:49 +00:00
|
|
|
if (*Cycles != 0) {
|
|
|
|
if (m_SyncSystem) {
|
|
|
|
char text[100];
|
|
|
|
|
|
|
|
WriteX86Comment("Sync CPU after update of cycles");
|
|
|
|
Pushad();
|
|
|
|
sprintf(text,"%d",(DWORD)*Cycles);
|
|
|
|
PushImm32(text,(DWORD)*Cycles);
|
|
|
|
Call_Direct(UpdateSyncCPU,"UpdateSyncCPU");
|
|
|
|
Popad();
|
|
|
|
}
|
2010-05-23 10:05:41 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
|
|
|
AddConstToVariable(*Cycles,&_CP0[9],CRegName::Cop0[9]);
|
2010-05-22 04:47:15 +00:00
|
|
|
SubConstFromVariable(*Cycles,_Timer,"Timer");
|
2010-05-23 10:05:41 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
*Cycles = 0;
|
|
|
|
*RandomMod = 0;
|
|
|
|
|
|
|
|
if (CheckTimer)
|
|
|
|
{
|
|
|
|
BYTE * Jump;
|
|
|
|
|
|
|
|
// Timer
|
|
|
|
if (*Cycles == 0) {
|
2010-05-23 10:05:41 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2010-05-22 04:47:15 +00:00
|
|
|
CompConstToVariable(0,_Timer,"Timer");
|
2010-05-23 10:05:41 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
//} else{
|
2010-05-22 04:47:15 +00:00
|
|
|
// uses SubConstFromVariable(Cycles,_Timer,"Timer"); for compare flag
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
JnsLabel8("Continue_From_Timer_Test",0);
|
|
|
|
Jump = RecompPos - 1;
|
|
|
|
Pushad();
|
2010-05-23 10:05:41 +00:00
|
|
|
X86BreakPoint(__FILE__,__LINE__);
|
|
|
|
MoveConstToX86reg((DWORD)_SystemTimer,x86_ECX);
|
|
|
|
Call_Direct(AddressOf(CSystemTimer::TimerDone),"CSystemTimer::TimerDone");
|
2008-09-18 03:15:49 +00:00
|
|
|
Popad();
|
|
|
|
|
|
|
|
CPU_Message("");
|
|
|
|
CPU_Message(" $Continue_From_Timer_Test:");
|
|
|
|
SetJump8(Jump,RecompPos);
|
|
|
|
}
|
|
|
|
/* if (CheckTimer)
|
|
|
|
|
|
|
|
{
|
|
|
|
x86ops.CompConstToVariable(0,(DWORD *)&_Reg->Timer,"_Reg->Timer");
|
|
|
|
x86ops.JgLabel8("Timer_Fine",0); BYTE * Jump = x86ops.RecompPos.WritePos() - 1;
|
|
|
|
Section->SaveX86Registers();
|
|
|
|
x86ops.Call_NonStatic_Direct((CSystemTimer *)_Reg,AddressOf(CSystemTimer::CheckTimer),"CSystemTimer::CheckTimer");
|
|
|
|
Section->RestoreX86Registers();
|
|
|
|
x86ops.WriteLabel("Timer_Fine"); x86ops.SetJump8(Jump, x86ops.RecompPos.WritePos());
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::CompileSystemCheck (DWORD TargetPC, CRegInfo & RegSet)
|
|
|
|
{
|
|
|
|
CompConstToVariable(0,&CPU_Action.DoSomething,"CPU_Action.DoSomething");
|
|
|
|
JeLabel32("Continue_From_Interrupt_Test",0);
|
|
|
|
BYTE * Jump = RecompPos - 4;
|
|
|
|
if (TargetPC != (DWORD)-1)
|
|
|
|
{
|
|
|
|
MoveConstToVariable(TargetPC,&PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection Section(NULL,-1,0);
|
2008-09-18 03:15:49 +00:00
|
|
|
Section.AddParent(NULL);
|
|
|
|
Section.RegWorking = RegSet;
|
|
|
|
WriteBackRegisters(&Section);
|
|
|
|
CompileExit(&Section,-1, -1,Section.RegWorking,CExitInfo::DoCPU_Action,true,NULL);
|
|
|
|
CPU_Message("");
|
|
|
|
CPU_Message(" $Continue_From_Interrupt_Test:");
|
|
|
|
SetJump32(Jump,RecompPos);
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void SyncRegState (CCodeSection * Section, CRegInfo * SyncTo) {
|
2008-09-18 03:15:49 +00:00
|
|
|
int count, x86Reg,x86RegHi, changed;
|
|
|
|
|
|
|
|
changed = false;
|
|
|
|
UnMap_AllFPRs(Section);
|
|
|
|
if (Section->CurrentRoundingModel() != SyncTo->CurrentRoundingModel()) { Section->CurrentRoundingModel() = CRegInfo::RoundUnknown; }
|
|
|
|
x86Reg = Map_MemoryStack(Section, x86_Any, false);
|
|
|
|
//CPU_Message("MemoryStack for Original State = %s",x86Reg > 0?x86_Name(x86Reg):"Not Mapped");
|
|
|
|
|
|
|
|
for (x86Reg = 1; x86Reg < 10; x86Reg ++) {
|
|
|
|
if (Section->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) { continue; }
|
|
|
|
if (SyncTo->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) {
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
for (count = 1; count < 10; count ++) {
|
|
|
|
if (SyncTo->x86Mapped(count) == CRegInfo::Stack_Mapped) {
|
|
|
|
MoveX86RegToX86Reg(count,x86Reg);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!changed) {
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
MoveVariableToX86reg(g_MemoryStack,"MemoryStack",x86Reg);
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (x86Reg = 1; x86Reg < 10; x86Reg ++) {
|
|
|
|
if (SyncTo->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) { continue; }
|
|
|
|
//CPU_Message("MemoryStack for Sync State = %s",x86Reg > 0?x86_Name(x86Reg):"Not Mapped");
|
|
|
|
if (Section->x86Mapped(x86Reg) == CRegInfo::Stack_Mapped) { break; }
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 1; count < 32; count ++) {
|
|
|
|
if (Section->MipsRegState(count) == SyncTo->MipsRegState(count)) {
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN: continue;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
if (Section->MipsReg(count) == SyncTo->MipsReg(count)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
if (Section->MipsRegLo(count) == SyncTo->MipsRegLo(count)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
if (Section->MipsReg(count) != SyncTo->MipsReg(count)) {
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
|
|
|
DisplayError("Umm.. how ???");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if (Section->MipsRegLo(count) != SyncTo->MipsRegLo(count)) {
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
|
|
|
DisplayError("Umm.. how ???");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
DisplayError("Unhandled Reg state %d\nin SyncRegState",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
|
|
|
|
switch (SyncTo->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN: UnMap_GPR(Section,count,true); break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
x86RegHi = SyncTo->MipsRegHi(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
UnMap_X86reg(Section,x86RegHi);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN:
|
2010-05-23 10:05:41 +00:00
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg);
|
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[1],CRegName::GPR_Hi[count],x86RegHi);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegHi(count),x86RegHi);
|
|
|
|
Section->x86Mapped(Section->MipsRegHi(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86RegHi);
|
|
|
|
ShiftRightSignImmed(x86RegHi,31);
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
XorX86RegToX86Reg(x86RegHi,x86RegHi);
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
MoveConstToX86reg(Section->MipsRegHi(count),x86RegHi);
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo_S(count) >> 31,x86RegHi);
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegHi(count) = x86RegHi;
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_MAPPED_64;
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86Mapped(x86RegHi) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
Section->x86MapOrder(x86RegHi) = 1;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
2010-05-23 10:05:41 +00:00
|
|
|
case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg); break;
|
2008-09-18 03:15:49 +00:00
|
|
|
case CRegInfo::STATE_CONST_32: MoveConstToX86reg(Section->MipsRegLo(count),x86Reg); break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
if (Section->MipsRegLo(count) != (DWORD)x86Reg) {
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
Section->x86Mapped(Section->MipsRegHi(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
DisplayError("hi %X\nLo %X",Section->MipsRegHi(count),Section->MipsRegLo(count));
|
|
|
|
default:
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_MAPPED_32_SIGN;
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
case CRegInfo::STATE_UNKNOWN:
|
2010-05-23 10:05:41 +00:00
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if (Section->MipsRegLo_S(count) < 0) {
|
|
|
|
CPU_Message("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO");
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%s: %X",CRegName::GPR[count],Section->MipsRegLo_S(count));
|
2008-09-18 03:15:49 +00:00
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegState(count) = SyncTo->MipsRegState(count);
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%d\n%d\nreg: %s (%d)",SyncTo->MipsRegState(count),Section->MipsRegState(count),CRegName::GPR[count],count);
|
|
|
|
DisplayError("%d\n%d\nreg: %s (%d)",SyncTo->MipsRegState(count),Section->MipsRegState(count),CRegName::GPR[count],count);
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("Do something with states in SyncRegState");
|
|
|
|
#endif
|
|
|
|
changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::GenerateSectionLinkage (CCodeSection * Section) {
|
|
|
|
CCodeSection ** TargetSection[2];
|
2008-09-18 03:15:49 +00:00
|
|
|
CJumpInfo * JumpInfo[2];
|
|
|
|
BYTE * Jump;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
TargetSection[0] = &Section->ContinueSection;
|
|
|
|
TargetSection[1] = &Section->JumpSection;
|
|
|
|
JumpInfo[0] = &Section->Cont;
|
|
|
|
JumpInfo[1] = &Section->Jump;
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->LinkLocation == NULL && JumpInfo[count]->FallThrough == false) {
|
|
|
|
JumpInfo[count]->TargetPC = -1;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
if ((Section->m_CompilePC & 0xFFC) == 0xFFC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
//Handle Fall througth
|
|
|
|
Jump = NULL;
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (!JumpInfo[count]->FallThrough) { continue; }
|
|
|
|
JumpInfo[count]->FallThrough = false;
|
|
|
|
if (JumpInfo[count]->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MoveConstToVariable(JumpInfo[count]->TargetPC,&JumpToLocation,"JumpToLocation");
|
|
|
|
if (JumpInfo[(count + 1) & 1]->LinkLocation == NULL) { break; }
|
|
|
|
JmpLabel8("FinishBlock",0);
|
|
|
|
Jump = RecompPos - 1;
|
|
|
|
}
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->LinkLocation == NULL) { continue; }
|
|
|
|
JumpInfo[count]->FallThrough = false;
|
|
|
|
if (JumpInfo[count]->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MoveConstToVariable(JumpInfo[count]->TargetPC,&JumpToLocation,"JumpToLocation");
|
|
|
|
if (JumpInfo[(count + 1) & 1]->LinkLocation == NULL) { break; }
|
|
|
|
JmpLabel8("FinishBlock",0);
|
|
|
|
Jump = RecompPos - 1;
|
|
|
|
}
|
|
|
|
if (Jump != NULL) {
|
|
|
|
CPU_Message(" $FinishBlock:");
|
|
|
|
SetJump8(Jump,RecompPos);
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
MoveConstToVariable(Section->m_CompilePC + 4,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
WriteBackRegisters(Section);
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&Section->BlockCycleCount(),&Section->BlockRandomModifier(),false);
|
2008-09-18 03:15:49 +00:00
|
|
|
// WriteBackRegisters(Section);
|
|
|
|
// if (m_SyncSystem) { Call_Direct(SyncToPC, "SyncToPC"); }
|
|
|
|
MoveConstToVariable(DELAY_SLOT,&NextInstruction,"NextInstruction");
|
|
|
|
Ret();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!UseLinking) {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (Section->m_CompilePC == Section->Jump.TargetPC && (Section->Cont.FallThrough == false)) {
|
|
|
|
if (!DelaySlotEffectsJump(Section->m_CompilePC)) {
|
2008-09-18 03:15:49 +00:00
|
|
|
CPU_Message("PermLoop *** a");
|
2010-05-25 09:15:19 +00:00
|
|
|
MoveConstToVariable(Section->m_CompilePC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
WriteBackRegisters(Section);
|
2008-11-14 20:51:06 +00:00
|
|
|
Section->RegWorking.BlockCycleCount() -= CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&Section->RegWorking.BlockCycleCount(),&Section->RegWorking.BlockRandomModifier(), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
Call_Direct(InPermLoop,"InPermLoop");
|
2008-11-14 20:51:06 +00:00
|
|
|
Section->RegWorking.BlockCycleCount() += CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&Section->RegWorking.BlockCycleCount(),&Section->RegWorking.BlockRandomModifier(), true);
|
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(-1,Section->RegWorking);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((*TargetSection[0]) != (*TargetSection[1]) || (*TargetSection[0]) == NULL) {
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->LinkLocation == NULL && JumpInfo[count]->FallThrough == false) {
|
|
|
|
if ((*TargetSection[count]))
|
|
|
|
{
|
|
|
|
(*TargetSection[count])->UnlinkParent(Section,true, count == 0);
|
|
|
|
}
|
|
|
|
} else if ((*TargetSection[count]) == NULL && JumpInfo[count]->FallThrough) {
|
|
|
|
if (JumpInfo[count]->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
_N64System->GetRecompiler()->CompileExit (Section,Section->m_CompilePC, JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet,CExitInfo::Normal,true,NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
JumpInfo[count]->FallThrough = false;
|
|
|
|
} else if ((*TargetSection[count]) != NULL && JumpInfo[count] != NULL) {
|
|
|
|
if (!JumpInfo[count]->FallThrough) { continue; }
|
|
|
|
if (JumpInfo[count]->TargetPC == (*TargetSection[count])->StartPC) { continue; }
|
|
|
|
if (JumpInfo[count]->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
_N64System->GetRecompiler()->CompileExit (Section,Section->m_CompilePC, JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet,CExitInfo::Normal,true,NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
//FreeSection((*TargetSection[count]),Section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Section->Cont.LinkLocation == NULL && Section->Cont.FallThrough == false) { Section->ContinueSection = NULL; }
|
|
|
|
if (Section->Jump.LinkLocation == NULL && Section->Jump.FallThrough == false) { Section->JumpSection = NULL; }
|
|
|
|
if (Section->JumpSection == NULL && Section->ContinueSection == NULL) {
|
|
|
|
//FreeSection(TargetSection[0],Section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetSection[0] = &Section->ContinueSection;
|
|
|
|
TargetSection[1] = &Section->JumpSection;
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if ((*TargetSection[count]) == NULL) { continue; }
|
|
|
|
if (!JumpInfo[count]->FallThrough) { continue; }
|
|
|
|
|
|
|
|
if ((*TargetSection[count])->CompiledLocation != NULL) {
|
|
|
|
char Label[100];
|
|
|
|
sprintf(Label,"Section_%d",(*TargetSection[count])->SectionID);
|
|
|
|
JumpInfo[count]->FallThrough = false;
|
|
|
|
if (JumpInfo[count]->LinkLocation != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
if (JumpInfo[count]->TargetPC <= Section->m_CompilePC) {
|
2008-09-18 03:15:49 +00:00
|
|
|
if (JumpInfo[count]->PermLoop) {
|
|
|
|
CPU_Message("PermLoop *** 1");
|
2010-05-22 04:47:15 +00:00
|
|
|
MoveConstToVariable(JumpInfo[count]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-11-14 20:51:06 +00:00
|
|
|
JumpInfo[count]->RegSet.BlockCycleCount() -= CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
Call_Direct(InPermLoop,"InPermLoop");
|
2008-11-14 20:51:06 +00:00
|
|
|
JumpInfo[count]->RegSet.BlockCycleCount() += CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), true);
|
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(-1,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(), &JumpInfo[count]->RegSet.BlockRandomModifier(), true);
|
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(), &JumpInfo[count]->RegSet.BlockRandomModifier(), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
JumpInfo[count]->RegSet.BlockRandomModifier() = 0;
|
|
|
|
JumpInfo[count]->RegSet.BlockCycleCount() = 0;
|
|
|
|
Section->RegWorking = JumpInfo[count]->RegSet;
|
|
|
|
SyncRegState(Section,&(*TargetSection[count])->RegStart);
|
|
|
|
JmpLabel32(Label,0);
|
|
|
|
SetJump32((DWORD *)RecompPos - 1,(*TargetSection[count])->CompiledLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Section->BlockCycleCount() = 0;
|
|
|
|
//Section->BlockRandomModifier() = 0;
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if ((*TargetSection[count]) == NULL) { continue; }
|
|
|
|
if ((*TargetSection[count])->ParentSection.empty()) { continue; }
|
|
|
|
|
|
|
|
for (SECTION_LIST::iterator iter = (*TargetSection[count])->ParentSection.begin(); iter != (*TargetSection[count])->ParentSection.end(); iter++)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCodeSection * Parent = *iter;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (Parent->CompiledLocation != NULL) { continue; }
|
|
|
|
if (JumpInfo[count]->PermLoop) {
|
|
|
|
CPU_Message("PermLoop *** 2");
|
2010-05-22 04:47:15 +00:00
|
|
|
MoveConstToVariable(JumpInfo[count]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-11-14 20:51:06 +00:00
|
|
|
JumpInfo[count]->RegSet.BlockCycleCount() -= CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
Call_Direct(InPermLoop,"InPermLoop");
|
2008-11-14 20:51:06 +00:00
|
|
|
JumpInfo[count]->RegSet.BlockCycleCount() += CountPerOp();
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), true);
|
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(-1,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
if (JumpInfo[count]->FallThrough) {
|
|
|
|
JumpInfo[count]->FallThrough = false;
|
|
|
|
JmpLabel32(JumpInfo[count]->BranchLabel,0);
|
|
|
|
JumpInfo[count]->LinkLocation = RecompPos - 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->FallThrough) {
|
2010-05-25 09:15:19 +00:00
|
|
|
if (JumpInfo[count]->TargetPC < Section->m_CompilePC) {
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(),true);
|
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CPU_Message("====== End of Section %d ======",Section->SectionID);
|
|
|
|
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->FallThrough) {
|
2010-05-25 09:15:19 +00:00
|
|
|
_N64System->GetRecompiler()->GenerateX86Code(*(Section->BlockInfo),(*TargetSection[count]),CCodeSection::GetNewTestValue());
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//CPU_Message("Section %d",Section->SectionID);
|
|
|
|
for (count = 0; count < 2; count ++) {
|
|
|
|
if (JumpInfo[count]->LinkLocation == NULL) { continue; }
|
|
|
|
if ((*TargetSection[count]) == NULL) {
|
|
|
|
CPU_Message("ExitBlock (from %d):",Section->SectionID);
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
_N64System->GetRecompiler()->CompileExit (Section,Section->m_CompilePC,JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet,CExitInfo::Normal,true,NULL);
|
2008-09-18 03:15:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (JumpInfo[count]->TargetPC != (*TargetSection[count])->StartPC) {
|
|
|
|
DisplayError("I need to add more code in GenerateSectionLinkage cause this is going to cause an exception");
|
|
|
|
BreakPoint(__FILE__,__LINE__);
|
|
|
|
}
|
|
|
|
if ((*TargetSection[count])->CompiledLocation == NULL) {
|
2010-05-25 09:15:19 +00:00
|
|
|
_N64System->GetRecompiler()->GenerateX86Code(*(*TargetSection[count])->BlockInfo,(*TargetSection[count]),CCodeSection::GetNewTestValue());
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
char Label[100];
|
|
|
|
|
|
|
|
CPU_Message("Section_%d (from %d):",(*TargetSection[count])->SectionID,Section->SectionID);
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation = NULL;
|
|
|
|
if (JumpInfo[count]->LinkLocation2 != NULL) {
|
|
|
|
SetJump32(JumpInfo[count]->LinkLocation2,RecompPos);
|
|
|
|
JumpInfo[count]->LinkLocation2 = NULL;
|
|
|
|
}
|
|
|
|
Section->RegWorking = JumpInfo[count]->RegSet;
|
2010-05-25 09:15:19 +00:00
|
|
|
if (JumpInfo[count]->TargetPC <= Section->m_CompilePC) {
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), true);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (JumpInfo[count]->PermLoop) {
|
|
|
|
CPU_Message("PermLoop *** 3");
|
2010-05-22 04:47:15 +00:00
|
|
|
MoveConstToVariable(JumpInfo[count]->TargetPC,_PROGRAM_COUNTER,"PROGRAM_COUNTER");
|
2008-09-18 03:15:49 +00:00
|
|
|
Call_Direct(InPermLoop,"InPermLoop");
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(-1,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->CompileSystemCheck(JumpInfo[count]->TargetPC,JumpInfo[count]->RegSet);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
} else{
|
2010-05-22 04:47:15 +00:00
|
|
|
_N64System->GetRecompiler()->UpdateCounters(&JumpInfo[count]->RegSet.BlockCycleCount(),&JumpInfo[count]->RegSet.BlockRandomModifier(), false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
Section->RegWorking = JumpInfo[count]->RegSet;
|
|
|
|
SyncRegState(Section,&(*TargetSection[count])->RegStart);
|
|
|
|
JmpLabel32(Label,0);
|
|
|
|
SetJump32((DWORD *)RecompPos - 1,(*TargetSection[count])->CompiledLocation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::RemoveFunction (CCompiledFunc * FunInfo, bool DelaySlot, REMOVE_REASON Reason )
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
LPCSTR lpReason = "Unknown";
|
|
|
|
switch (Reason)
|
|
|
|
{
|
|
|
|
case Remove_InitialCode: lpReason = "Remove_InitialCode"; break;
|
|
|
|
case Remove_Cache: lpReason = "Remove_Cache"; break;
|
|
|
|
case Remove_ProtectedMem: lpReason = "Remove_ProtectedMem"; break;
|
|
|
|
case Remove_ValidateFunc: lpReason = "Remove_ValidateFunc"; break;
|
|
|
|
case Remove_TLB: lpReason = "Remove_TLB"; break;
|
|
|
|
case Remove_DMA: lpReason = "Remove_DMA"; break;
|
|
|
|
}
|
|
|
|
WriteTraceF(TraceRecompiler,"Remove Func (%s): %X-%X",lpReason, FunInfo->VStartPC(), FunInfo->VEndPC());
|
|
|
|
if (JumpTable && !DelaySlot)
|
|
|
|
{
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * Info = FunInfo;
|
2008-09-18 03:15:49 +00:00
|
|
|
while (Info)
|
|
|
|
{
|
|
|
|
if (*(JumpTable + (Info->PStartPC() >> 2)) == Info)
|
|
|
|
{
|
|
|
|
*(JumpTable + (Info->PStartPC() >> 2)) = NULL;
|
|
|
|
}
|
|
|
|
Info = Info->Next;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
TlbLog.Log("Clear %X",FunInfo->StartPC());
|
|
|
|
|
|
|
|
//Remove from the list of called functions
|
|
|
|
FunInfo->RemoveFromCallList();
|
|
|
|
|
|
|
|
//remove all functions that call this
|
|
|
|
if (_Settings->LoadDword(SMM_Linked)) {
|
|
|
|
for (FUNCTION_PTR_MAP::iterator item = FunInfo->CallingList().begin();
|
|
|
|
FunInfo->CallingList().begin() != FunInfo->CallingList().end();
|
|
|
|
item = FunInfo->CallingList().begin())
|
|
|
|
{
|
|
|
|
RemoveFunction(m_Functions.find(item->first));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//Remove from the list of called functions
|
|
|
|
FunInfo->RemoveFromCallingList();
|
|
|
|
}
|
|
|
|
*/
|
2010-05-25 09:15:19 +00:00
|
|
|
/* DWORD StartBlock = FunInfo->VStartPC() & ~0xFFF;
|
2008-09-18 03:15:49 +00:00
|
|
|
DWORD EndBlock = FunInfo->VEndPC() & ~0xFFF;
|
|
|
|
|
|
|
|
//Remove this item from the main list
|
|
|
|
if (DelaySlot)
|
|
|
|
{
|
|
|
|
m_FunctionsDelaySlot.Remove(FunInfo);
|
|
|
|
} else {
|
|
|
|
m_Functions.Remove(FunInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if no more functions in this block then unprotect the memory
|
2008-11-14 20:51:06 +00:00
|
|
|
if (bSMM_Protect())
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
for (DWORD Addr = StartBlock; Addr <= EndBlock; Addr += 0x1000 ){
|
2010-05-25 09:15:19 +00:00
|
|
|
CCompiledFunc * info = m_Functions.FindFunction(Addr,0xFFF);
|
2008-09-18 03:15:49 +00:00
|
|
|
if (info == NULL)
|
|
|
|
{
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
_MMU->UnProtectMemory(Addr,Addr + 0xFFC);
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-25 09:15:19 +00:00
|
|
|
}*/
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRecompiler::ClearRecompCode_Phys(DWORD Address, int length, REMOVE_REASON Reason ) {
|
|
|
|
bool Result = true;
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CRecompiler::ClearRecompCode_Virt(DWORD Address, int length,REMOVE_REASON 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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 09:15:19 +00:00
|
|
|
void CRecompiler::SyncRegState (CCodeSection * Section, CRegInfo * SyncTo)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
|
|
|
int count, x86Reg,x86RegHi;
|
|
|
|
|
|
|
|
bool changed = FALSE;
|
|
|
|
UnMap_AllFPRs(Section);
|
|
|
|
if (Section->CurrentRoundingModel() != SyncTo->CurrentRoundingModel()) { Section->CurrentRoundingModel() = CRegInfo::RoundUnknown; }
|
|
|
|
|
|
|
|
//x86Reg = Map_MemoryStack(Section, x86_Any, FALSE);
|
|
|
|
//CPU_Message("MemoryStack for Original State = %s",x86Reg > 0?x86_Name(x86Reg):"Not Mapped");
|
|
|
|
|
|
|
|
for (x86Reg = 1; x86Reg < 10; x86Reg ++) {
|
|
|
|
if (Section->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) { continue; }
|
|
|
|
if (SyncTo->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) {
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
for (count = 1; count < 10; count ++) {
|
|
|
|
if (SyncTo->x86Mapped(count) == CRegInfo::Stack_Mapped) {
|
|
|
|
MoveX86RegToX86Reg(count,x86Reg);
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!changed) {
|
2010-05-22 04:47:15 +00:00
|
|
|
_Notify->BreakPoint(__FILE__,__LINE__);
|
|
|
|
#ifdef tofix
|
2008-09-18 03:15:49 +00:00
|
|
|
MoveVariableToX86reg(g_MemoryStack,"MemoryStack",x86Reg);
|
2010-05-22 04:47:15 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (x86Reg = 1; x86Reg < 10; x86Reg ++) {
|
|
|
|
if (SyncTo->x86Mapped(x86Reg) != CRegInfo::Stack_Mapped) { continue; }
|
|
|
|
//CPU_Message("MemoryStack for Sync State = %s",x86Reg > 0?x86_Name(x86Reg):"Not Mapped");
|
|
|
|
if (Section->x86Mapped(x86Reg) == CRegInfo::Stack_Mapped) { break; }
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (count = 1; count < 32; count ++) {
|
|
|
|
if (Section->MipsRegState(count) == SyncTo->MipsRegState(count)) {
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN: continue;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
if (Section->MipsReg(count) == SyncTo->MipsReg(count)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
if (Section->MipsRegLo(count) == SyncTo->MipsRegLo(count)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
if (Section->MipsReg(count) != SyncTo->MipsReg(count)) {
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
|
|
|
DisplayError("Umm.. how ???");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if (Section->MipsRegLo(count) != SyncTo->MipsRegLo(count)) {
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
|
|
|
DisplayError("Umm.. how ???");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
DisplayError("Unhandled Reg state %d\nin SyncRegState",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
changed = TRUE;
|
|
|
|
|
|
|
|
switch (SyncTo->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN: UnMap_GPR(Section,count,TRUE); break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
x86RegHi = SyncTo->MipsRegHi(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
UnMap_X86reg(Section,x86RegHi);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_UNKNOWN:
|
2010-05-23 10:05:41 +00:00
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg);
|
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[1],CRegName::GPR_Hi[count],x86RegHi);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegHi(count),x86RegHi);
|
|
|
|
Section->x86Mapped(Section->MipsRegHi(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86RegHi);
|
|
|
|
ShiftRightSignImmed(x86RegHi,31);
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
XorX86RegToX86Reg(x86RegHi,x86RegHi);
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
MoveConstToX86reg(Section->MipsRegHi(count),x86RegHi);
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo_S(count) >> 31,x86RegHi);
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegHi(count) = x86RegHi;
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_MAPPED_64;
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86Mapped(x86RegHi) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
Section->x86MapOrder(x86RegHi) = 1;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
2010-05-23 10:05:41 +00:00
|
|
|
case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg); break;
|
2008-09-18 03:15:49 +00:00
|
|
|
case CRegInfo::STATE_CONST_32: MoveConstToX86reg(Section->MipsRegLo(count),x86Reg); break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_SIGN:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
if (Section->MipsRegLo(count) != (DWORD)x86Reg) {
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
Section->x86Mapped(Section->MipsRegHi(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
case CRegInfo::STATE_CONST_64:
|
|
|
|
DisplayError("hi %X\nLo %X",Section->MipsRegHi(count),Section->MipsRegLo(count));
|
|
|
|
default:
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegState(count) = CRegInfo::STATE_MAPPED_32_SIGN;
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
x86Reg = SyncTo->MipsRegLo(count);
|
|
|
|
UnMap_X86reg(Section,x86Reg);
|
|
|
|
switch (Section->MipsRegState(count)) {
|
|
|
|
case CRegInfo::STATE_MAPPED_64:
|
|
|
|
case CRegInfo::STATE_UNKNOWN:
|
2010-05-23 10:05:41 +00:00
|
|
|
MoveVariableToX86reg(&_GPR[count].UW[0],CRegName::GPR_Lo[count],x86Reg);
|
2008-09-18 03:15:49 +00:00
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_MAPPED_32_ZERO:
|
|
|
|
MoveX86RegToX86Reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
Section->x86Mapped(Section->MipsRegLo(count)) = CRegInfo::NotMapped;
|
|
|
|
break;
|
|
|
|
case CRegInfo::STATE_CONST_32:
|
|
|
|
if (Section->MipsRegLo_S(count) < 0) {
|
|
|
|
CPU_Message("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO");
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%s: %X",CRegName::GPR[count],Section->MipsRegLo_S(count));
|
2008-09-18 03:15:49 +00:00
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
DisplayError("Sign Problems in SyncRegState\nSTATE_MAPPED_32_ZERO");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
MoveConstToX86reg(Section->MipsRegLo(count),x86Reg);
|
|
|
|
break;
|
|
|
|
#ifndef EXTERNAL_RELEASE
|
|
|
|
default:
|
|
|
|
CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d",Section->MipsRegState(count));
|
|
|
|
DisplayError("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d",Section->MipsRegState(count));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
Section->MipsRegLo(count) = x86Reg;
|
|
|
|
Section->MipsRegState(count) = SyncTo->MipsRegState(count);
|
|
|
|
Section->x86Mapped(x86Reg) = CRegInfo::GPR_Mapped;
|
|
|
|
Section->x86MapOrder(x86Reg) = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if (!defined(EXTERNAL_RELEASE))
|
2010-05-23 10:05:41 +00:00
|
|
|
CPU_Message("%d\n%d\nreg: %s (%d)",SyncTo->MipsRegState(count),Section->MipsRegState(count),CRegName::GPR[count],count);
|
|
|
|
DisplayError("%d\n%d\nreg: %s (%d)",SyncTo->MipsRegState(count),Section->MipsRegState(count),CRegName::GPR[count],count);
|
2008-09-18 03:15:49 +00:00
|
|
|
DisplayError("Do something with states in SyncRegState");
|
|
|
|
#endif
|
|
|
|
changed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|