2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-04 06:25:07 +00:00
|
|
|
#include "stdafx.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "RecompilerClass.h"
|
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
|
|
|
#include <Project64-core/N64System/Recompiler/x86CodeLog.h>
|
|
|
|
#include <Project64-core/N64System/N64Class.h>
|
|
|
|
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
|
|
|
|
#include <Objbase.h>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
CRecompiler::CRecompiler(CRegisters & Registers, CProfiling & Profile, bool & EndEmulation) :
|
2015-12-13 07:52:22 +00:00
|
|
|
m_Registers(Registers),
|
|
|
|
m_Profile(Profile),
|
|
|
|
m_EndEmulation(EndEmulation),
|
|
|
|
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (g_MMU != NULL)
|
|
|
|
{
|
|
|
|
ResetMemoryStackPos();
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CRecompiler::~CRecompiler()
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
ResetRecompCode(false);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::Run()
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
CoInitialize(NULL);
|
|
|
|
if (bLogX86Code())
|
|
|
|
{
|
|
|
|
Start_x86_Log();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CRecompMemory::AllocateMemory())
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "AllocateMemory failed");
|
2015-11-09 20:19:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!CFunctionMap::AllocateMemory())
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "AllocateMemory failed");
|
2015-11-09 20:19:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_EndEmulation = false;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
*g_MemoryStack = (uint32_t)(RDRAM+(_GPR[29].W[0] & 0x1FFFFFFF));
|
2010-05-25 09:15:19 +00:00
|
|
|
#endif
|
2015-12-13 07:52:22 +00:00
|
|
|
__try
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (g_System->LookUpMode() == FuncFind_VirtualLookup)
|
|
|
|
{
|
|
|
|
if (g_System->bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
RecompilerMain_VirtualTable_validate();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
RecompilerMain_VirtualTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (g_System->LookUpMode() == FuncFind_ChangeMemory)
|
|
|
|
{
|
|
|
|
RecompilerMain_ChangeMemory();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g_System->bUseTlb())
|
|
|
|
{
|
|
|
|
if (g_System->bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
RecompilerMain_Lookup_validate_TLB();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
RecompilerMain_Lookup_TLB();
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (g_System->bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
RecompilerMain_Lookup_validate();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
RecompilerMain_Lookup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except (g_MMU->MemoryFilter(GetExceptionCode(), GetExceptionInformation()))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(MSG_UNKNOWN_MEM_ACTION);
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CRecompiler::RecompilerMain_VirtualTable()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
bool & Done = m_EndEmulation;
|
2015-11-08 20:45:41 +00:00
|
|
|
uint32_t & PC = PROGRAM_COUNTER;
|
2010-10-29 03:20:25 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
while (!Done)
|
|
|
|
{
|
|
|
|
if (!g_TransVaddr->ValidVaddr(PC))
|
|
|
|
{
|
|
|
|
m_Registers.DoTLBReadMiss(false, PC);
|
|
|
|
if (!g_TransVaddr->ValidVaddr(PC))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PC).ToUTF16().c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCCompiledFunc_TABLE & table = FunctionTable()[PC >> 0xC];
|
|
|
|
uint32_t TableEntry = (PC & 0xFFF) >> 2;
|
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = table[TableEntry];
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
(info->Function())();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CCompiledFunc * info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table == NULL)
|
|
|
|
{
|
|
|
|
table = new PCCompiledFunc[(0x1000 >> 2)];
|
|
|
|
if (table == NULL)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "failed to allocate PCCompiledFunc");
|
2015-11-09 20:19:27 +00:00
|
|
|
g_Notify->FatalError(MSG_MEM_ALLOC_ERROR);
|
|
|
|
}
|
|
|
|
memset(table, 0, sizeof(PCCompiledFunc) * (0x1000 >> 2));
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Create Table (%X): Index = %d", table, PC >> 0xC);
|
2015-11-09 20:19:27 +00:00
|
|
|
g_MMU->ProtectMemory(PC & ~0xFFF, PC | 0xFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
table[TableEntry] = info;
|
|
|
|
(info->Function())();
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CRecompiler::RecompilerMain_VirtualTable_validate()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
/* PCCompiledFunc_TABLE * m_FunctionTable = m_Functions.GetFunctionTable();
|
|
|
|
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
|
|
|
/*if (NextInstruction == DELAY_SLOT)
|
|
|
|
{
|
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
if (!g_TLB->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!g_TLB->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//Find Block on hash table
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const uint8_t * 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;
|
|
|
|
}*/
|
|
|
|
/* PCCompiledFunc_TABLE table = m_FunctionTable[PROGRAM_COUNTER >> 0xC];
|
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = table[(PROGRAM_COUNTER & 0xFFF) >> 2];
|
|
|
|
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 uint8_t * Block = info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
if (!g_TLB->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!g_TLB->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
CCompiledFunc * info = CompilerCode();
|
|
|
|
|
|
|
|
if (info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
|
|
|
if (!g_MMU->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!g_MMU->ValidVaddr(PROGRAM_COUNTER))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NextInstruction == DELAY_SLOT)
|
|
|
|
{
|
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
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 uint8_t * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCompiledFunc * Info = m_Functions.FindFunction(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompilerCode();
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
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 uint8_t * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::RecompilerMain_Lookup()
|
|
|
|
{
|
|
|
|
while (!m_EndEmulation)
|
|
|
|
{
|
|
|
|
uint32_t PhysicalAddr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
|
|
|
if (PhysicalAddr < g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2];
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
|
|
|
g_MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF, PROGRAM_COUNTER | 0xFFF);
|
|
|
|
}
|
|
|
|
JumpTable()[PhysicalAddr >> 2] = info;
|
|
|
|
}
|
|
|
|
(info->Function())();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t opsExecuted = 0;
|
|
|
|
|
|
|
|
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CInterpreterCPU::ExecuteOps(g_System->CountPerOp());
|
|
|
|
opsExecuted += g_System->CountPerOp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_SyncSystem)
|
|
|
|
{
|
|
|
|
g_System->UpdateSyncCPU(g_SyncSystem, opsExecuted);
|
|
|
|
g_System->SyncCPU(g_SyncSystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
uint32_t Addr;
|
|
|
|
CCompiledFunc * Info;
|
|
|
|
//const uint8_t * Block;
|
|
|
|
|
|
|
|
while(!m_EndEmulation)
|
|
|
|
{
|
|
|
|
/*if (bUseTlb())
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
if (!g_TLB->TranslateVaddr(PROGRAM_COUNTER, Addr))
|
|
|
|
{
|
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr)) {
|
|
|
|
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
Addr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/* if (NextInstruction == DELAY_SLOT) {
|
|
|
|
CCompiledFunc * Info = m_FunctionsDelaySlot.FindFunction(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
//Find Block on hash table
|
|
|
|
if (Info == NULL)
|
|
|
|
{
|
|
|
|
Info = CompileDelaySlot(PROGRAM_COUNTER);
|
|
|
|
|
|
|
|
if (Info == NULL || EndEmulation())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
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 uint8_t * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
__try {
|
|
|
|
if (Addr > 0x10000000)
|
|
|
|
{
|
|
|
|
if (bRomInMemory())
|
|
|
|
{
|
|
|
|
if (Addr > 0x20000000)
|
|
|
|
{
|
|
|
|
WriteTraceF(TraceDebug,"Executing from non mapped space .1 PC: %X Addr: %X",PROGRAM_COUNTER, Addr);
|
|
|
|
g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Info = (CCompiledFunc *)*(JumpTable + (Addr >> 2));
|
|
|
|
} 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);
|
|
|
|
g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Info = (CCompiledFunc *)*(JumpTable + (Addr >> 2));
|
|
|
|
}
|
|
|
|
} __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);
|
|
|
|
g_Notify->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) {
|
|
|
|
// VirtualProtect(RDRAM + Addr, 4, PAGE_READONLY, &OldProtect);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
if (bSMM_ValidFunc())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
if (Profiling && IndvidualBlock) {
|
|
|
|
static uint32_t 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");
|
|
|
|
/* }
|
|
|
|
#endif
|
|
|
|
const uint8_t * Block = Info->FunctionAddr();
|
|
|
|
_asm {
|
|
|
|
pushad
|
|
|
|
call Block
|
|
|
|
popad
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::RecompilerMain_Lookup_TLB()
|
|
|
|
{
|
|
|
|
uint32_t PhysicalAddr;
|
|
|
|
|
|
|
|
while (!m_EndEmulation)
|
|
|
|
{
|
|
|
|
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
|
|
|
|
{
|
|
|
|
m_Registers.DoTLBReadMiss(false, PROGRAM_COUNTER);
|
|
|
|
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).ToUTF16().c_str());
|
|
|
|
m_EndEmulation = true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (PhysicalAddr < g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2];
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
|
|
|
g_MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF, PROGRAM_COUNTER | 0xFFF);
|
|
|
|
}
|
|
|
|
JumpTable()[PhysicalAddr >> 2] = info;
|
|
|
|
}
|
|
|
|
(info->Function())();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint32_t opsExecuted = 0;
|
|
|
|
|
|
|
|
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CInterpreterCPU::ExecuteOps(g_System->CountPerOp());
|
|
|
|
opsExecuted += g_System->CountPerOp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_SyncSystem)
|
|
|
|
{
|
|
|
|
g_System->UpdateSyncCPU(g_SyncSystem, opsExecuted);
|
|
|
|
g_System->SyncCPU(g_SyncSystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::RecompilerMain_Lookup_validate()
|
|
|
|
{
|
|
|
|
while (!m_EndEmulation)
|
|
|
|
{
|
|
|
|
uint32_t PhysicalAddr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
|
|
|
if (PhysicalAddr < g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2];
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
|
|
|
g_MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF, PROGRAM_COUNTER | 0xFFF);
|
|
|
|
}
|
|
|
|
JumpTable()[PhysicalAddr >> 2] = info;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (*(info->MemLocation(0)) != info->MemContents(0) ||
|
|
|
|
*(info->MemLocation(1)) != info->MemContents(1))
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt((info->EnterPC() - 0x1000) & ~0xFFF, 0x3000, Remove_ValidateFunc);
|
|
|
|
info = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(info->Function())();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t opsExecuted = 0;
|
|
|
|
|
|
|
|
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CInterpreterCPU::ExecuteOps(g_System->CountPerOp());
|
|
|
|
opsExecuted += g_System->CountPerOp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_SyncSystem)
|
|
|
|
{
|
|
|
|
g_System->UpdateSyncCPU(g_SyncSystem, opsExecuted);
|
|
|
|
g_System->SyncCPU(g_SyncSystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::RecompilerMain_Lookup_validate_TLB()
|
|
|
|
{
|
|
|
|
uint32_t PhysicalAddr;
|
|
|
|
|
|
|
|
while (!m_EndEmulation)
|
|
|
|
{
|
|
|
|
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
|
|
|
|
{
|
|
|
|
m_Registers.DoTLBReadMiss(false, PROGRAM_COUNTER);
|
|
|
|
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr))
|
|
|
|
{
|
|
|
|
g_Notify->DisplayError(stdstr_f("Failed to translate PC to a PAddr: %X\n\nEmulation stopped", PROGRAM_COUNTER).ToUTF16().c_str());
|
|
|
|
m_EndEmulation = true;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (PhysicalAddr < g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CCompiledFunc * info = JumpTable()[PhysicalAddr >> 2];
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
info = CompilerCode();
|
|
|
|
if (info == NULL || m_EndEmulation)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
|
|
|
g_MMU->ProtectMemory(PROGRAM_COUNTER & ~0xFFF, PROGRAM_COUNTER | 0xFFF);
|
|
|
|
}
|
|
|
|
JumpTable()[PhysicalAddr >> 2] = info;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (*(info->MemLocation(0)) != info->MemContents(0) ||
|
|
|
|
*(info->MemLocation(1)) != info->MemContents(1))
|
|
|
|
{
|
|
|
|
if (PhysicalAddr > 0x1000)
|
|
|
|
{
|
|
|
|
ClearRecompCode_Phys((PhysicalAddr - 0x1000) & ~0xFFF, 0x3000, Remove_ValidateFunc);
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
ClearRecompCode_Phys(0, 0x2000, Remove_ValidateFunc);
|
|
|
|
}
|
|
|
|
info = JumpTable()[PhysicalAddr >> 2];
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
info = NULL;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(info->Function())();
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t opsExecuted = 0;
|
|
|
|
|
|
|
|
while (g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, PhysicalAddr) && PhysicalAddr >= g_System->RdramSize())
|
|
|
|
{
|
|
|
|
CInterpreterCPU::ExecuteOps(g_System->CountPerOp());
|
|
|
|
opsExecuted += g_System->CountPerOp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_SyncSystem)
|
|
|
|
{
|
|
|
|
g_System->UpdateSyncCPU(g_SyncSystem, opsExecuted);
|
|
|
|
g_System->SyncCPU(g_SyncSystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::Reset()
|
|
|
|
{
|
|
|
|
ResetRecompCode(true);
|
|
|
|
ResetMemoryStackPos();
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::ResetRecompCode(bool bAllocate)
|
|
|
|
{
|
|
|
|
CRecompMemory::Reset();
|
|
|
|
CFunctionMap::Reset(bAllocate);
|
|
|
|
|
|
|
|
for (CCompiledFuncList::iterator iter = m_Functions.begin(); iter != m_Functions.end(); iter++)
|
|
|
|
{
|
|
|
|
CCompiledFunc * Func = iter->second;
|
|
|
|
while (Func != NULL)
|
|
|
|
{
|
|
|
|
CCompiledFunc * CurrentFunc = Func;
|
|
|
|
Func = Func->Next();
|
|
|
|
|
|
|
|
delete CurrentFunc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Functions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRecompiler::RecompilerMain_ChangeMemory()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-12-15 06:01:06 +00:00
|
|
|
#ifdef legacycode
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t Value, Addr;
|
|
|
|
uint8_t * Block;
|
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
while(!EndEmulation())
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (UseTlb)
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr))
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
DoTLBMiss(NextInstruction == DELAY_SLOT,PROGRAM_COUNTER);
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
if (!TranslateVaddr(PROGRAM_COUNTER, &Addr))
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
g_Notify->DisplayError(L"Failed to translate PC to a PAddr: %X\n\nEmulation stopped",PROGRAM_COUNTER);
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Addr = PROGRAM_COUNTER & 0x1FFFFFFF;
|
|
|
|
}
|
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
if (NextInstruction == DELAY_SLOT)
|
|
|
|
{
|
|
|
|
__try
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
Value = (uint32_t)(*(DelaySlotTable + (Addr >> 12)));
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
g_Notify->DisplayError(L"Executing Delay Slot from non maped space\nPROGRAM_COUNTER = 0x%X",PROGRAM_COUNTER);
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
if ( (Value >> 16) == 0x7C7C)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t Index = (Value & 0xFFFF);
|
|
|
|
Block = (uint8_t *)OrigMem[Index].CompiledLocation;
|
|
|
|
if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
|
|
|
|
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
|
|
|
|
if (Index >= TargetIndex) { Block = NULL; }
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
Block = NULL;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
if (Block == NULL)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t MemValue;
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
Block = CompileDelaySlot();
|
|
|
|
Value = 0x7C7C0000;
|
|
|
|
Value += (uint16_t)(TargetIndex);
|
|
|
|
MemValue = *(uint32_t *)(RDRAM + Addr);
|
2015-12-13 07:52:22 +00:00
|
|
|
if ( (MemValue >> 16) == 0x7C7C)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
|
|
|
|
}
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].CompiledLocation = Block;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].PAddr = Addr;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].VAddr = PROGRAM_COUNTER;
|
|
|
|
TargetIndex += 1;
|
|
|
|
*(DelaySlotTable + (Addr >> 12)) = (void *)Value;
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
_asm
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
pushad
|
2015-12-13 07:52:22 +00:00
|
|
|
call Block
|
|
|
|
popad
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
__try
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
Value = *(uint32_t *)(RDRAM + Addr);
|
2015-12-13 07:52:22 +00:00
|
|
|
if ( (Value >> 16) == 0x7C7C)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t Index = (Value & 0xFFFF);
|
|
|
|
Block = (uint8_t *)OrigMem[Index].CompiledLocation;
|
|
|
|
if (OrigMem[Index].PAddr != Addr) { Block = NULL; }
|
|
|
|
if (OrigMem[Index].VAddr != PROGRAM_COUNTER) { Block = NULL; }
|
|
|
|
if (Index >= TargetIndex) { Block = NULL; }
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
Block = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
g_Notify->DisplayError(GS(MSG_NONMAPPED_SPACE));
|
|
|
|
ExitThread(0);
|
|
|
|
}
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
if (Block == NULL)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t MemValue;
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
__try
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
Block = Compiler4300iBlock();
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|
|
|
|
__except(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
ResetRecompCode();
|
|
|
|
Block = Compiler4300iBlock();
|
|
|
|
}
|
|
|
|
if (EndEmulation())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
if (TargetIndex == MaxOrigMem)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
ResetRecompCode();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Value = 0x7C7C0000;
|
|
|
|
Value += (uint16_t)(TargetIndex);
|
|
|
|
MemValue = *(uint32_t *)(RDRAM + Addr);
|
2015-12-13 07:52:22 +00:00
|
|
|
if ( (MemValue >> 16) == 0x7C7C)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
MemValue = OrigMem[(MemValue & 0xFFFF)].OriginalValue;
|
|
|
|
}
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].OriginalValue = MemValue;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].CompiledLocation = Block;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].PAddr = Addr;
|
|
|
|
OrigMem[(uint16_t)(TargetIndex)].VAddr = PROGRAM_COUNTER;
|
|
|
|
TargetIndex += 1;
|
|
|
|
*(uint32_t *)(RDRAM + Addr) = Value;
|
|
|
|
NextInstruction = NORMAL;
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
if (Profiling && IndvidualBlock)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
static uint32_t ProfAddress = 0;
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
/*if ((PROGRAM_COUNTER & ~0xFFF) != ProfAddress)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
char Label[100];
|
2012-09-24 22:07:51 +00:00
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
ProfAddress = PROGRAM_COUNTER & ~0xFFF;
|
|
|
|
sprintf(Label,"PC: %X to %X",ProfAddress,ProfAddress+ 0xFFC);
|
|
|
|
StartTimer(Label);
|
|
|
|
}*/
|
2015-12-13 07:52:22 +00:00
|
|
|
/*if (PROGRAM_COUNTER >= 0x800DD000 && PROGRAM_COUNTER <= 0x800DDFFC)
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
char Label[100];
|
|
|
|
sprintf(Label,"PC: %X Block: %X",PROGRAM_COUNTER,Block);
|
|
|
|
StartTimer(Label);
|
|
|
|
}*/
|
|
|
|
// } else if ((Profiling || ShowCPUPer) && ProfilingLabel[0] == 0) {
|
|
|
|
// StartTimer("r4300i Running");
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
_asm
|
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
pushad
|
2015-12-13 07:52:22 +00:00
|
|
|
call Block
|
|
|
|
popad
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
|
|
|
} // end for(;;)
|
2008-09-18 03:15:49 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
CCompiledFunc * CRecompiler::CompilerCode()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
uint32_t pAddr = 0;
|
|
|
|
if (!g_TransVaddr->TranslateVaddr(PROGRAM_COUNTER, pAddr))
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Failed to translate %X", PROGRAM_COUNTER);
|
2015-11-09 20:19:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCompiledFuncList::iterator iter = m_Functions.find(PROGRAM_COUNTER);
|
|
|
|
if (iter != m_Functions.end())
|
|
|
|
{
|
|
|
|
for (CCompiledFunc * Func = iter->second; Func != NULL; Func = Func->Next())
|
|
|
|
{
|
|
|
|
uint32_t PAddr;
|
|
|
|
if (g_TransVaddr->TranslateVaddr(Func->MinPC(), PAddr))
|
|
|
|
{
|
|
|
|
MD5Digest Hash;
|
|
|
|
MD5(g_MMU->Rdram() + PAddr, (Func->MaxPC() - Func->MinPC()) + 4).get_digest(Hash);
|
|
|
|
if (memcmp(Hash.digest, Func->Hash().digest, sizeof(Hash.digest)) == 0)
|
|
|
|
{
|
|
|
|
return Func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckRecompMem();
|
|
|
|
|
|
|
|
//uint32_t StartTime = timeGetTime();
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, ": Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr);
|
2015-11-09 20:19:27 +00:00
|
|
|
|
|
|
|
CCodeBlock CodeBlock(PROGRAM_COUNTER, RecompPos());
|
|
|
|
if (!CodeBlock.Compile())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bShowRecompMemSize())
|
|
|
|
{
|
|
|
|
ShowMemUsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCompiledFunc * Func = new CCompiledFunc(CodeBlock);
|
|
|
|
CCompiledFuncList::_Pairib ret = m_Functions.insert(CCompiledFuncList::value_type(Func->EnterPC(), Func));
|
|
|
|
if (ret.second == false)
|
|
|
|
{
|
|
|
|
Func->SetNext(ret.first->second->Next());
|
|
|
|
ret.first->second->SetNext(Func);
|
|
|
|
return Func;
|
|
|
|
}
|
|
|
|
return Func;
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::ClearRecompCode_Phys(uint32_t Address, int length, REMOVE_REASON Reason)
|
2012-12-17 00:21:29 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (g_System->LookUpMode() == FuncFind_VirtualLookup)
|
|
|
|
{
|
|
|
|
ClearRecompCode_Virt(Address + 0x80000000, length, Reason);
|
|
|
|
ClearRecompCode_Virt(Address + 0xA0000000, length, Reason);
|
|
|
|
|
|
|
|
if (g_System->bUseTlb())
|
|
|
|
{
|
|
|
|
uint32_t VAddr, Index = 0;
|
|
|
|
while (g_TLB->PAddrToVAddr(Address, VAddr, Index))
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "ClearRecompCode Vaddr %X len: %d", VAddr, length);
|
2015-11-09 20:19:27 +00:00
|
|
|
ClearRecompCode_Virt(VAddr, length, Reason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (g_System->LookUpMode() == FuncFind_PhysicalLookup)
|
|
|
|
{
|
|
|
|
if (Address < g_System->RdramSize())
|
|
|
|
{
|
|
|
|
int ClearLen = ((length + 3) & ~3);
|
|
|
|
if (Address + ClearLen > g_System->RdramSize())
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
ClearLen = g_System->RdramSize() - Address;
|
|
|
|
}
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "Reseting Jump Table, Addr: %X len: %d", Address, ClearLen);
|
2015-11-09 20:19:27 +00:00
|
|
|
memset((uint8_t *)JumpTable() + Address, 0, ClearLen);
|
|
|
|
if (g_System->bSMM_Protect())
|
|
|
|
{
|
|
|
|
g_MMU->UnProtectMemory(Address + 0x80000000, Address + 0x80000004);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceDebug, "Ignoring reset of Jump Table, Addr: %X len: %d", Address, ((length + 3) & ~3));
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 20:19:27 +00:00
|
|
|
void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REASON Reason)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
switch (g_System->LookUpMode())
|
|
|
|
{
|
|
|
|
case FuncFind_VirtualLookup:
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
|
|
|
uint32_t AddressIndex = Address >> 0xC;
|
|
|
|
uint32_t WriteStart = (Address & 0xFFC);
|
|
|
|
length = ((length + 3) & ~0x3);
|
2015-11-09 20:19:27 +00:00
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
int DataInBlock = 0x1000 - WriteStart;
|
|
|
|
int DataToWrite = length < DataInBlock ? length : DataInBlock;
|
|
|
|
int DataLeft = length - DataToWrite;
|
2015-11-09 20:19:27 +00:00
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
PCCompiledFunc_TABLE & table = FunctionTable()[AddressIndex];
|
|
|
|
if (table)
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Delete Table (%X): Index = %d", table, AddressIndex);
|
2015-12-13 07:52:22 +00:00
|
|
|
delete table;
|
|
|
|
table = NULL;
|
|
|
|
g_MMU->UnProtectMemory(Address, Address + length);
|
|
|
|
}
|
2015-11-09 20:19:27 +00:00
|
|
|
|
2015-12-13 07:52:22 +00:00
|
|
|
if (DataLeft > 0)
|
|
|
|
{
|
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-09 20:19:27 +00:00
|
|
|
case FuncFind_PhysicalLookup:
|
2015-12-13 07:52:22 +00:00
|
|
|
{
|
|
|
|
uint32_t pAddr = 0;
|
|
|
|
if (g_TransVaddr->TranslateVaddr(Address, pAddr))
|
2015-11-09 20:19:27 +00:00
|
|
|
{
|
2015-12-13 07:52:22 +00:00
|
|
|
ClearRecompCode_Phys(pAddr, length, Reason);
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-09 20:19:27 +00:00
|
|
|
default:
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
2010-07-23 10:45:35 +00:00
|
|
|
|
2015-04-28 22:19:02 +00:00
|
|
|
void CRecompiler::ResetMemoryStackPos()
|
2010-07-23 10:45:35 +00:00
|
|
|
{
|
2015-11-09 20:19:27 +00:00
|
|
|
if (g_MMU == NULL)
|
|
|
|
{
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_Registers.m_GPR[29].UW[0] == 0)
|
|
|
|
{
|
|
|
|
m_MemoryStack = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t pAddr = 0;
|
|
|
|
if (g_TransVaddr->TranslateVaddr(m_Registers.m_GPR[29].UW[0], pAddr))
|
|
|
|
{
|
|
|
|
m_MemoryStack = (uint32_t)(g_MMU->Rdram() + pAddr);
|
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
else
|
|
|
|
{
|
2015-12-14 10:51:33 +00:00
|
|
|
WriteTrace(TraceRecompiler, TraceError, "Failed to translate SP address (%s)", m_Registers.m_GPR[29].UW[0]);
|
2015-12-09 11:37:58 +00:00
|
|
|
g_Notify->BreakPoint(__FILE__, __LINE__);
|
2015-11-09 20:19:27 +00:00
|
|
|
}
|
2015-12-13 07:52:22 +00:00
|
|
|
}
|