Core: Get the recompiler to be use globals less

This commit is contained in:
zilmar 2022-08-08 20:22:51 +09:30
parent 5ea06d958e
commit 51c9867e76
25 changed files with 1278 additions and 1214 deletions

View File

@ -1,7 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h> #include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#ifndef _WIN32 #ifndef _WIN32

View File

@ -4,7 +4,6 @@
#include <Project64-core\N64System\SystemGlobals.h> #include <Project64-core\N64System\SystemGlobals.h>
#include <Project64-core\N64System\N64Rom.h> #include <Project64-core\N64System\N64Rom.h>
#include <Project64-core\N64System\N64System.h> #include <Project64-core\N64System\N64System.h>
#include <Project64-core\N64System\Recompiler\RecompilerCodeLog.h>
#include <Project64-core\N64System\Mips\Disk.h> #include <Project64-core\N64System\Mips\Disk.h>
#include <Project64-core\Debugger.h> #include <Project64-core\Debugger.h>
#include <Project64-core\ExceptionHandler.h> #include <Project64-core\ExceptionHandler.h>

View File

@ -1,7 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "N64System.h" #include "N64System.h"
#include <Project64-core/3rdParty/zip.h> #include <Project64-core/3rdParty/zip.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/Mempak.h> #include <Project64-core/N64System/Mips/Mempak.h>
#include <Project64-core/N64System/Mips/Transferpak.h> #include <Project64-core/N64System/Mips/Transferpak.h>
@ -2279,10 +2278,9 @@ bool CN64System::LoadState(const char * FileName)
} }
m_CPU_Usage.ResetTimers(); m_CPU_Usage.ResetTimers();
m_FPS.Reset(true); m_FPS.Reset(true);
if (bRecordRecompilerAsm()) if (bRecordRecompilerAsm() && m_Recomp)
{ {
Stop_Recompiler_Log(); m_Recomp->ResetLog();
Start_Recompiler_Log();
} }
#ifdef TEST_SP_TRACKING #ifdef TEST_SP_TRACKING

View File

@ -1,7 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include <string.h> #include <string.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h> #include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h> #include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h> #include <Project64-core/N64System/Recompiler/Arm/ArmRecompilerOps.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
@ -31,7 +30,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi
} }
#endif #endif
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
m_RecompilerOps = new CX86RecompilerOps(MMU); m_RecompilerOps = new CX86RecompilerOps(MMU, *this);
#elif defined(__arm__) || defined(_M_ARM) #elif defined(__arm__) || defined(_M_ARM)
m_RecompilerOps = new CArmRecompilerOps(MMU); m_RecompilerOps = new CArmRecompilerOps(MMU);
#endif #endif
@ -40,7 +39,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
CCodeSection * baseSection = new CCodeSection(this, VAddrEnter, 0, false); CCodeSection * baseSection = new CCodeSection(*this, VAddrEnter, 0, false);
if (baseSection == nullptr) if (baseSection == nullptr)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -53,7 +52,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi
baseSection->m_Cont.FallThrough = true; baseSection->m_Cont.FallThrough = true;
baseSection->m_Cont.RegSet = baseSection->m_RegEnter; baseSection->m_Cont.RegSet = baseSection->m_RegEnter;
m_EnterSection = new CCodeSection(this, VAddrEnter, 1, true); m_EnterSection = new CCodeSection(*this, VAddrEnter, 1, true);
if (m_EnterSection == nullptr) if (m_EnterSection == nullptr)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -127,7 +126,7 @@ bool CCodeBlock::SetSection(CCodeSection * & Section, CCodeSection * CurrentSect
if (Section == nullptr) if (Section == nullptr)
{ {
Section = new CCodeSection(this, TargetPC, (uint32_t)m_Sections.size(), LinkAllowed); Section = new CCodeSection(*this, TargetPC, (uint32_t)m_Sections.size(), LinkAllowed);
if (Section == nullptr) if (Section == nullptr)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -160,7 +159,7 @@ bool CCodeBlock::SetSection(CCodeSection * & Section, CCodeSection * CurrentSect
} }
if (SplitSection->m_EndPC >= TargetPC) if (SplitSection->m_EndPC >= TargetPC)
{ {
CPU_Message("%s: Split Section: %d with section: %d", __FUNCTION__, SplitSection->m_SectionID, Section->m_SectionID); Log("%s: Split Section: %d with section: %d", __FUNCTION__, SplitSection->m_SectionID, Section->m_SectionID);
CCodeSection * BaseSection = Section; CCodeSection * BaseSection = Section;
BaseSection->m_EndPC = SplitSection->m_EndPC; BaseSection->m_EndPC = SplitSection->m_EndPC;
BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC, SplitSection->m_Jump.PermLoop); BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC, SplitSection->m_Jump.PermLoop);
@ -192,7 +191,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
{ {
CCodeSection * CurrentSection = EnterSection; CCodeSection * CurrentSection = EnterSection;
CPU_Message("Section %d", CurrentSection->m_SectionID); Log("Section %d", CurrentSection->m_SectionID);
for (uint32_t TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4) for (uint32_t TestPC = EnterSection->m_EnterPC, EndPC = ((EnterSection->m_EnterPC + 0x1000) & 0xFFFFF000); TestPC <= EndPC; TestPC += 4)
{ {
if (TestPC != EndPC) if (TestPC != EndPC)
@ -213,7 +212,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
CurrentSection->m_EndPC = TestPC - 4; CurrentSection->m_EndPC = TestPC - 4;
CurrentSection = itr->second; CurrentSection = itr->second;
CPU_Message("Section %d", CurrentSection->m_SectionID); Log("Section %d", CurrentSection->m_SectionID);
if (EnterSection != m_EnterSection) if (EnterSection != m_EnterSection)
{ {
if (CurrentSection->m_JumpSection != nullptr || if (CurrentSection->m_JumpSection != nullptr ||
@ -258,7 +257,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
if (EndBlock) if (EndBlock)
{ {
CPU_Message("%s: End Block", __FUNCTION__); Log("%s: End Block", __FUNCTION__);
CurrentSection->m_EndSection = true; CurrentSection->m_EndSection = true;
// Find other sections that need compiling // Find other sections that need compiling
break; break;
@ -266,7 +265,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
if (ContinuePC != (uint32_t)-1) if (ContinuePC != (uint32_t)-1)
{ {
CPU_Message("%s: SetContinueAddress TestPC = %X ContinuePC = %X", __FUNCTION__, TestPC, ContinuePC); Log("%s: SetContinueAddress TestPC = %X ContinuePC = %X", __FUNCTION__, TestPC, ContinuePC);
CurrentSection->SetContinueAddress(TestPC, ContinuePC); CurrentSection->SetContinueAddress(TestPC, ContinuePC);
if (!SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC, true, TestPC)) if (!SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC, true, TestPC))
{ {
@ -276,7 +275,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
if (LikelyBranch) if (LikelyBranch)
{ {
CPU_Message("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TestPC + 4); Log("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TestPC + 4);
CurrentSection->SetJumpAddress(TestPC, TestPC + 4, false); CurrentSection->SetJumpAddress(TestPC, TestPC + 4, false);
if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4, false, TestPC)) if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4, false, TestPC))
{ {
@ -299,7 +298,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
JumpSection->m_EndPC = TestPC + 4; JumpSection->m_EndPC = TestPC + 4;
if (BranchEndBlock) if (BranchEndBlock)
{ {
CPU_Message("%s: Jump End Block", __FUNCTION__); Log("%s: Jump End Block", __FUNCTION__);
JumpSection->m_EndSection = true; JumpSection->m_EndSection = true;
TargetPC = (uint32_t)-1; TargetPC = (uint32_t)-1;
} }
@ -317,7 +316,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
} }
else if (TargetPC != ((uint32_t)-1)) else if (TargetPC != ((uint32_t)-1))
{ {
CPU_Message("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TargetPC); Log("%s: SetJumpAddress TestPC = %X Target = %X", __FUNCTION__, TestPC, TargetPC);
CurrentSection->SetJumpAddress(TestPC, TargetPC, PermLoop); CurrentSection->SetJumpAddress(TestPC, TargetPC, PermLoop);
if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC, true, TestPC)) if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC, true, TestPC))
{ {
@ -359,7 +358,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection)
break; break;
} }
TestPC = CurrentSection->m_EnterPC; TestPC = CurrentSection->m_EnterPC;
CPU_Message("a. Section %d", CurrentSection->m_SectionID); Log("a. Section %d", CurrentSection->m_SectionID);
TestPC -= 4; TestPC -= 4;
} }
@ -441,7 +440,7 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
#ifdef _DEBUG #ifdef _DEBUG
R4300iInstruction Instruction(PC, Command.Value); R4300iInstruction Instruction(PC, Command.Value);
CPU_Message(" 0x%08X %s %s", PC, Instruction.Name(), Instruction.Param()); Log(" 0x%08X %s %s", PC, Instruction.Name(), Instruction.Param());
#endif #endif
switch (Command.op) switch (Command.op)
{ {
@ -776,11 +775,11 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
bool CCodeBlock::Compile() bool CCodeBlock::Compile()
{ {
CPU_Message("====== Code block ======"); Log("====== Code block ======");
CPU_Message("Native entry point: %X", CompiledLocation()); Log("Native entry point: %X", CompiledLocation());
CPU_Message("Start of block: %X", VAddrEnter()); Log("Start of block: %X", VAddrEnter());
CPU_Message("Number of sections: %d", NoOfSections()); Log("Number of sections: %d", NoOfSections());
CPU_Message("====== Recompiled code ======"); Log("====== Recompiled code ======");
m_RecompilerOps->EnterCodeBlock(); m_RecompilerOps->EnterCodeBlock();
if (g_System->bLinkBlocks()) if (g_System->bLinkBlocks())
@ -816,4 +815,28 @@ uint32_t CCodeBlock::NextTest()
uint32_t next_test = m_Test; uint32_t next_test = m_Test;
m_Test += 1; m_Test += 1;
return next_test; return next_test;
} }
void CCodeBlock::Log(_Printf_format_string_ const char * Text, ...)
{
if (!CDebugSettings::bRecordRecompilerAsm())
{
return;
}
va_list args;
va_start(args, Text);
#pragma warning(push)
#pragma warning(disable : 4996)
size_t nlen = _vscprintf(Text, args) + 1;
char * buffer = (char*)alloca(nlen * sizeof(char));
buffer[nlen - 1] = 0;
if (buffer != nullptr)
{
vsprintf(buffer, Text, args);
m_CodeLog += buffer;
m_CodeLog += "\n";
}
#pragma warning(pop)
va_end(args);
}

View File

@ -22,6 +22,8 @@ public:
const CCodeSection & EnterSection() const { return *m_EnterSection; } const CCodeSection & EnterSection() const { return *m_EnterSection; }
const MD5Digest & Hash() const { return m_Hash; } const MD5Digest & Hash() const { return m_Hash; }
CRecompilerOps *& RecompilerOps() { return m_RecompilerOps; } CRecompilerOps *& RecompilerOps() { return m_RecompilerOps; }
const std::string & CodeLog() const { return m_CodeLog; }
void SetVAddrFirst(uint32_t VAddr) { m_VAddrFirst = VAddr; } void SetVAddrFirst(uint32_t VAddr) { m_VAddrFirst = VAddr; }
void SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; } void SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; }
@ -33,6 +35,8 @@ public:
uint32_t NextTest(); uint32_t NextTest();
void Log(_Printf_format_string_ const char * Text, ...);
private: private:
CCodeBlock(); CCodeBlock();
CCodeBlock(const CCodeBlock&); CCodeBlock(const CCodeBlock&);
@ -64,4 +68,5 @@ private:
uint64_t m_MemContents[2]; uint64_t m_MemContents[2];
uint64_t * m_MemLocation[2]; uint64_t * m_MemLocation[2];
CRecompilerOps * m_RecompilerOps; CRecompilerOps * m_RecompilerOps;
std::string m_CodeLog;
}; };

View File

@ -4,7 +4,6 @@
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h> #include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h> #include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
@ -13,8 +12,8 @@
#include <Project64-core/ExceptionHandler.h> #include <Project64-core/ExceptionHandler.h>
#include <Project64-core/Debugger.h> #include <Project64-core/Debugger.h>
CCodeSection::CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) : CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) :
m_BlockInfo(CodeBlock), m_CodeBlock(CodeBlock),
m_SectionID(ID), m_SectionID(ID),
m_EnterPC(EnterPC), m_EnterPC(EnterPC),
m_EndPC((uint32_t)-1), m_EndPC((uint32_t)-1),
@ -27,9 +26,12 @@ CCodeSection::CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID
m_CompiledLocation(nullptr), m_CompiledLocation(nullptr),
m_InLoop(false), m_InLoop(false),
m_DelaySlot(false), m_DelaySlot(false),
m_RecompilerOps(CodeBlock->RecompilerOps()) m_RecompilerOps(CodeBlock.RecompilerOps()),
m_RegEnter(CodeBlock),
m_Jump(CodeBlock),
m_Cont(CodeBlock)
{ {
CPU_Message("%s: ID %d EnterPC 0x%08X", __FUNCTION__, ID, EnterPC); m_CodeBlock.Log("%s: ID %d EnterPC 0x%08X", __FUNCTION__, ID, EnterPC);
m_RecompilerOps->SetCurrentSection(this); m_RecompilerOps->SetCurrentSection(this);
} }
@ -121,13 +123,13 @@ void CCodeSection::GenerateSectionLinkage()
{ {
if (JumpInfo[i]->PermLoop) if (JumpInfo[i]->PermLoop)
{ {
CPU_Message("PermLoop *** 1"); m_CodeBlock.Log("PermLoop *** 1");
m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC); m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC);
} }
else else
{ {
m_RecompilerOps->UpdateCounters(JumpInfo[i]->RegSet, true, true); m_RecompilerOps->UpdateCounters(JumpInfo[i]->RegSet, true, true);
CPU_Message("CompileSystemCheck 5"); m_CodeBlock.Log("CompileSystemCheck 5");
m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet);
} }
} }
@ -155,7 +157,7 @@ void CCodeSection::GenerateSectionLinkage()
if (Parent->m_InLoop) { continue; } if (Parent->m_InLoop) { continue; }
if (JumpInfo[i]->PermLoop) if (JumpInfo[i]->PermLoop)
{ {
CPU_Message("PermLoop *** 2"); m_CodeBlock.Log("PermLoop *** 2");
m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC); m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC);
} }
if (JumpInfo[i]->FallThrough) if (JumpInfo[i]->FallThrough)
@ -173,30 +175,30 @@ void CCodeSection::GenerateSectionLinkage()
if (JumpInfo[i]->TargetPC < m_RecompilerOps->GetCurrentPC()) if (JumpInfo[i]->TargetPC < m_RecompilerOps->GetCurrentPC())
{ {
m_RecompilerOps->UpdateCounters(JumpInfo[i]->RegSet, true, true); m_RecompilerOps->UpdateCounters(JumpInfo[i]->RegSet, true, true);
CPU_Message("CompileSystemCheck 7"); m_CodeBlock.Log("CompileSystemCheck 7");
m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet); m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet);
} }
} }
} }
CPU_Message("====== End of Section %d ======", m_SectionID); m_CodeBlock.Log("====== End of Section %d ======", m_SectionID);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
if (JumpInfo[i]->FallThrough && (TargetSection[i] == nullptr || !TargetSection[i]->GenerateNativeCode(m_BlockInfo->NextTest()))) if (JumpInfo[i]->FallThrough && (TargetSection[i] == nullptr || !TargetSection[i]->GenerateNativeCode(m_CodeBlock.NextTest())))
{ {
JumpInfo[i]->FallThrough = false; JumpInfo[i]->FallThrough = false;
m_RecompilerOps->JumpToUnknown(JumpInfo[i]); m_RecompilerOps->JumpToUnknown(JumpInfo[i]);
} }
} }
//CPU_Message("Section %d",m_SectionID); //CodeLog("Section %d",m_SectionID);
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
if (JumpInfo[i]->LinkLocation == nullptr) { continue; } if (JumpInfo[i]->LinkLocation == nullptr) { continue; }
if (TargetSection[i] == nullptr) if (TargetSection[i] == nullptr)
{ {
CPU_Message("ExitBlock (from %d):", m_SectionID); m_CodeBlock.Log("ExitBlock (from %d):", m_SectionID);
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1); m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason); m_RecompilerOps->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason);
continue; continue;
@ -207,13 +209,13 @@ void CCodeSection::GenerateSectionLinkage()
} }
if (TargetSection[i]->m_CompiledLocation == nullptr) if (TargetSection[i]->m_CompiledLocation == nullptr)
{ {
TargetSection[i]->GenerateNativeCode(m_BlockInfo->NextTest()); TargetSection[i]->GenerateNativeCode(m_CodeBlock.NextTest());
} }
else else
{ {
stdstr_f Label("Section_%d (from %d):", TargetSection[i]->m_SectionID, m_SectionID); stdstr_f Label("Section_%d (from %d):", TargetSection[i]->m_SectionID, m_SectionID);
CPU_Message(Label.c_str()); m_CodeBlock.Log(Label.c_str());
m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1); m_RecompilerOps->LinkJump(*JumpInfo[i], (uint32_t)-1);
m_RecompilerOps->SetRegWorkingSet(JumpInfo[i]->RegSet); m_RecompilerOps->SetRegWorkingSet(JumpInfo[i]->RegSet);
if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC) if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC)
@ -221,12 +223,12 @@ void CCodeSection::GenerateSectionLinkage()
m_RecompilerOps->UpdateCounters(m_RecompilerOps->GetRegWorkingSet(), true, true); m_RecompilerOps->UpdateCounters(m_RecompilerOps->GetRegWorkingSet(), true, true);
if (JumpInfo[i]->PermLoop) if (JumpInfo[i]->PermLoop)
{ {
CPU_Message("PermLoop *** 3"); m_CodeBlock.Log("PermLoop *** 3");
m_RecompilerOps->CompileInPermLoop(m_RecompilerOps->GetRegWorkingSet(), JumpInfo[i]->TargetPC); m_RecompilerOps->CompileInPermLoop(m_RecompilerOps->GetRegWorkingSet(), JumpInfo[i]->TargetPC);
} }
else else
{ {
CPU_Message("CompileSystemCheck 9"); m_CodeBlock.Log("CompileSystemCheck 9");
m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, m_RecompilerOps->GetRegWorkingSet()); m_RecompilerOps->CompileSystemCheck(JumpInfo[i]->TargetPC, m_RecompilerOps->GetRegWorkingSet());
} }
} }
@ -249,7 +251,7 @@ void CCodeSection::SetJumpAddress(uint32_t JumpPC, uint32_t TargetPC, bool PermL
{ {
m_Jump.JumpPC = JumpPC; m_Jump.JumpPC = JumpPC;
m_Jump.TargetPC = TargetPC; m_Jump.TargetPC = TargetPC;
m_Jump.BranchLabel.Format("0x%08X", TargetPC); m_Jump.BranchLabel = stdstr_f("0x%08X", TargetPC);
m_Jump.PermLoop = PermLoop; m_Jump.PermLoop = PermLoop;
} }
@ -257,7 +259,7 @@ void CCodeSection::SetContinueAddress(uint32_t JumpPC, uint32_t TargetPC)
{ {
m_Cont.JumpPC = JumpPC; m_Cont.JumpPC = JumpPC;
m_Cont.TargetPC = TargetPC; m_Cont.TargetPC = TargetPC;
m_Cont.BranchLabel.Format("0x%08X", TargetPC); m_Cont.BranchLabel = stdstr_f("0x%08X", TargetPC);
} }
bool CCodeSection::ParentContinue() bool CCodeSection::ParentContinue()
@ -268,7 +270,7 @@ bool CCodeSection::ParentContinue()
{ {
CCodeSection * Parent = *iter; CCodeSection * Parent = *iter;
if (Parent->m_CompiledLocation != nullptr) { continue; } if (Parent->m_CompiledLocation != nullptr) { continue; }
if (IsAllParentLoops(Parent, true, m_BlockInfo->NextTest())) { continue; } if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest())) { continue; }
return false; return false;
} }
m_RecompilerOps->SetCurrentSection(this); m_RecompilerOps->SetCurrentSection(this);
@ -303,9 +305,9 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
m_RecompilerOps->SetCurrentPC(m_EnterPC); m_RecompilerOps->SetCurrentPC(m_EnterPC);
m_RecompilerOps->SetNextStepType(m_DelaySlot ? PIPELINE_STAGE_JUMP : PIPELINE_STAGE_NORMAL); m_RecompilerOps->SetNextStepType(m_DelaySlot ? PIPELINE_STAGE_JUMP : PIPELINE_STAGE_NORMAL);
if (m_RecompilerOps->GetCurrentPC() < m_BlockInfo->VAddrFirst()) if (m_RecompilerOps->GetCurrentPC() < m_CodeBlock.VAddrFirst())
{ {
m_BlockInfo->SetVAddrFirst(m_RecompilerOps->GetCurrentPC()); m_CodeBlock.SetVAddrFirst(m_RecompilerOps->GetCurrentPC());
} }
uint32_t ContinueSectionPC = m_ContinueSection ? m_ContinueSection->m_EnterPC : (uint32_t)-1; uint32_t ContinueSectionPC = m_ContinueSection ? m_ContinueSection->m_EnterPC : (uint32_t)-1;
@ -313,9 +315,9 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
R4300iInstruction Instruction(m_RecompilerOps->GetCurrentPC(), Opcode.Value); R4300iInstruction Instruction(m_RecompilerOps->GetCurrentPC(), Opcode.Value);
do do
{ {
if (m_RecompilerOps->GetCurrentPC() > m_BlockInfo->VAddrLast()) if (m_RecompilerOps->GetCurrentPC() > m_CodeBlock.VAddrLast())
{ {
m_BlockInfo->SetVAddrLast(m_RecompilerOps->GetCurrentPC()); m_CodeBlock.SetVAddrLast(m_RecompilerOps->GetCurrentPC());
} }
if (isDebugging() && HaveExecutionBP() && Instruction.HasDelaySlot() && g_Debugger->ExecutionBP(m_RecompilerOps->GetCurrentPC() + 4)) if (isDebugging() && HaveExecutionBP() && Instruction.HasDelaySlot() && g_Debugger->ExecutionBP(m_RecompilerOps->GetCurrentPC() + 4))
@ -636,7 +638,7 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test)
// Do nothing, the block will end // Do nothing, the block will end
break; break;
default: default:
CPU_Message("m_RecompilerOps->GetNextStepType() = %d", m_RecompilerOps->GetNextStepType()); m_CodeBlock.Log("m_RecompilerOps->GetNextStepType() = %d", m_RecompilerOps->GetNextStepType());
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
break; break;
} }
@ -790,11 +792,11 @@ void CCodeSection::DetermineLoop(uint32_t Test, uint32_t Test2, uint32_t TestID)
m_Test = Test; m_Test = Test;
if (m_ContinueSection != nullptr) if (m_ContinueSection != nullptr)
{ {
m_ContinueSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_ContinueSection->m_SectionID); m_ContinueSection->DetermineLoop(Test, m_CodeBlock.NextTest(), m_ContinueSection->m_SectionID);
} }
if (m_JumpSection != nullptr) if (m_JumpSection != nullptr)
{ {
m_JumpSection->DetermineLoop(Test, m_BlockInfo->NextTest(), m_JumpSection->m_SectionID); m_JumpSection->DetermineLoop(Test, m_CodeBlock.NextTest(), m_JumpSection->m_SectionID);
} }
} }
} }
@ -856,7 +858,7 @@ bool CCodeSection::SectionAccessible(uint32_t SectionId, uint32_t Test)
void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection) void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection)
{ {
CPU_Message("%s: Section %d Parent: %d ContinueSection = %s", __FUNCTION__, m_SectionID, Parent->m_SectionID, ContinueSection ? "Yes" : "No"); m_CodeBlock.Log("%s: Section %d Parent: %d ContinueSection = %s", __FUNCTION__, m_SectionID, Parent->m_SectionID, ContinueSection ? "Yes" : "No");
if (Parent->m_ContinueSection == this && Parent->m_JumpSection == this) if (Parent->m_ContinueSection == this && Parent->m_JumpSection == this)
{ {
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
@ -889,7 +891,7 @@ void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection)
bool bRemove = false; bool bRemove = false;
if (m_ParentSection.size() > 0) if (m_ParentSection.size() > 0)
{ {
if (!m_BlockInfo->SectionAccessible(m_SectionID)) if (!m_CodeBlock.SectionAccessible(m_SectionID))
{ {
for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++)
{ {
@ -975,13 +977,13 @@ void CCodeSection::DisplaySectionInformation()
return; return;
} }
CPU_Message("====== Section %d ======", m_SectionID); m_CodeBlock.Log("====== Section %d ======", m_SectionID);
CPU_Message("Start PC: 0x%X", m_EnterPC); m_CodeBlock.Log("Start PC: 0x%X", m_EnterPC);
if (g_System->bLinkBlocks()) if (g_System->bLinkBlocks())
{ {
CPU_Message("End PC: 0x%X", m_EndPC); m_CodeBlock.Log("End PC: 0x%X", m_EndPC);
} }
CPU_Message("CompiledLocation: 0x%X", m_CompiledLocation); m_CodeBlock.Log("CompiledLocation: 0x%X", m_CompiledLocation);
if (g_System->bLinkBlocks() && !m_ParentSection.empty()) if (g_System->bLinkBlocks() && !m_ParentSection.empty())
{ {
stdstr ParentList; stdstr ParentList;
@ -994,32 +996,32 @@ void CCodeSection::DisplaySectionInformation()
} }
ParentList += stdstr_f("%d", Parent->m_SectionID); ParentList += stdstr_f("%d", Parent->m_SectionID);
} }
CPU_Message("Number of parents: %d (%s)", m_ParentSection.size(), ParentList.c_str()); m_CodeBlock.Log("Number of parents: %d (%s)", m_ParentSection.size(), ParentList.c_str());
} }
if (g_System->bLinkBlocks()) if (g_System->bLinkBlocks())
{ {
CPU_Message("Jump address: 0x%08X", m_Jump.JumpPC); m_CodeBlock.Log("Jump address: 0x%08X", m_Jump.JumpPC);
CPU_Message("Jump target address: 0x%08X", m_Jump.TargetPC); m_CodeBlock.Log("Jump target address: 0x%08X", m_Jump.TargetPC);
if (m_JumpSection != nullptr) if (m_JumpSection != nullptr)
{ {
CPU_Message("Jump section: %d", m_JumpSection->m_SectionID); m_CodeBlock.Log("Jump section: %d", m_JumpSection->m_SectionID);
} }
else else
{ {
CPU_Message("Jump section: None"); m_CodeBlock.Log("Jump section: None");
} }
CPU_Message("Continue address: 0x%08X", m_Cont.JumpPC); m_CodeBlock.Log("Continue address: 0x%08X", m_Cont.JumpPC);
CPU_Message("Continue target address: 0x%08X", m_Cont.TargetPC); m_CodeBlock.Log("Continue target address: 0x%08X", m_Cont.TargetPC);
if (m_ContinueSection != nullptr) if (m_ContinueSection != nullptr)
{ {
CPU_Message("Continue section: %d", m_ContinueSection->m_SectionID); m_CodeBlock.Log("Continue section: %d", m_ContinueSection->m_SectionID);
} }
else else
{ {
CPU_Message("Continue section: None"); m_CodeBlock.Log("Continue section: None");
} }
CPU_Message("In loop: %s", m_InLoop ? "Yes" : "No"); m_CodeBlock.Log("In loop: %s", m_InLoop ? "Yes" : "No");
} }
CPU_Message("======================="); m_CodeBlock.Log("=======================");
} }

View File

@ -11,7 +11,7 @@ class CCodeSection :
public: public:
typedef std::list<CCodeSection *> SECTION_LIST; typedef std::list<CCodeSection *> SECTION_LIST;
CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed); CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed);
~CCodeSection(); ~CCodeSection();
void SetDelaySlot(); void SetDelaySlot();
@ -28,28 +28,28 @@ public:
void SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent); void SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent);
// Block connection info // Block connection info
SECTION_LIST m_ParentSection; SECTION_LIST m_ParentSection;
CCodeBlock * const m_BlockInfo; CCodeBlock & m_CodeBlock;
const uint32_t m_SectionID; const uint32_t m_SectionID;
const uint32_t m_EnterPC; const uint32_t m_EnterPC;
uint32_t m_EndPC; uint32_t m_EndPC;
CCodeSection * m_ContinueSection; CCodeSection * m_ContinueSection;
CCodeSection * m_JumpSection; CCodeSection * m_JumpSection;
bool m_EndSection; // If this section does not link, are other sections allowed to find block to link to it? bool m_EndSection; // If this section does not link, are other sections allowed to find block to link to it?
bool m_LinkAllowed; bool m_LinkAllowed;
uint32_t m_Test; uint32_t m_Test;
uint32_t m_Test2; uint32_t m_Test2;
uint8_t * m_CompiledLocation; uint8_t * m_CompiledLocation;
bool m_InLoop; bool m_InLoop;
bool m_DelaySlot; bool m_DelaySlot;
CRecompilerOps * & m_RecompilerOps; CRecompilerOps * & m_RecompilerOps;
// Register info // Register info
CRegInfo m_RegEnter; CRegInfo m_RegEnter;
// Jump info // Jump info
CJumpInfo m_Jump; CJumpInfo m_Jump;
CJumpInfo m_Cont; CJumpInfo m_Cont;
private: private:
CCodeSection(void); CCodeSection(void);

View File

@ -0,0 +1,10 @@
#include "stdafx.h"
#include <Project64-core\N64System\Recompiler\ExitInfo.h>
CExitInfo::CExitInfo(CCodeBlock & CodeBlock) :
ID(0),
TargetPC(0),
JumpLoc(nullptr),
ExitRegSet(CodeBlock)
{
}

View File

@ -5,6 +5,8 @@
struct CExitInfo struct CExitInfo
{ {
CExitInfo(CCodeBlock & CodeBlock);
enum EXIT_REASON enum EXIT_REASON
{ {
Normal = 0, Normal = 0,

View File

@ -5,16 +5,16 @@
struct CJumpInfo struct CJumpInfo
{ {
typedef CExitInfo::EXIT_REASON EXIT_REASON; typedef CExitInfo::EXIT_REASON EXIT_REASON;
CJumpInfo(); CJumpInfo(CCodeBlock & CodeBlock);
uint32_t TargetPC; uint32_t TargetPC;
uint32_t JumpPC; uint32_t JumpPC;
stdstr BranchLabel; std::string BranchLabel;
uint32_t * LinkLocation; uint32_t * LinkLocation;
uint32_t * LinkLocation2; uint32_t * LinkLocation2;
bool FallThrough; bool FallThrough;
bool PermLoop; bool PermLoop;
bool DoneDelaySlot; bool DoneDelaySlot;
CRegInfo RegSet; CRegInfo RegSet;
EXIT_REASON ExitReason; EXIT_REASON ExitReason;
}; };

View File

@ -4,7 +4,6 @@
#include <Project64-core/N64System/N64Types.h> #include <Project64-core/N64System/N64Types.h>
#include <Project64-core/N64System/Recompiler/CodeBlock.h> #include <Project64-core/N64System/Recompiler/CodeBlock.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h> #include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
@ -13,12 +12,13 @@
#define CHECKED_BUILD 1 #define CHECKED_BUILD 1
#endif #endif
LoopAnalysis::LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section) : LoopAnalysis::LoopAnalysis(CCodeBlock & CodeBlock, CCodeSection * Section) :
m_EnterSection(Section), m_EnterSection(Section),
m_BlockInfo(CodeBlock), m_CodeBlock(CodeBlock),
m_PC((uint32_t)-1), m_PC((uint32_t)-1),
m_PipelineStage(PIPELINE_STAGE_NORMAL), m_PipelineStage(PIPELINE_STAGE_NORMAL),
m_Test(m_BlockInfo->NextTest()) m_Test(CodeBlock.NextTest()),
m_Reg(CodeBlock)
{ {
memset(&m_Command, 0, sizeof(m_Command)); memset(&m_Command, 0, sizeof(m_Command));
} }
@ -50,7 +50,7 @@ bool LoopAnalysis::SetupRegisterForLoop()
{ {
return false; return false;
} }
CPU_Message("%s: Section ID: %d Test: %X", __FUNCTION__, m_EnterSection->m_SectionID, m_Test); m_CodeBlock.Log("%s: Section ID: %d Test: %X", __FUNCTION__, m_EnterSection->m_SectionID, m_Test);
if (!CheckLoopRegisterUsage(m_EnterSection)) if (!CheckLoopRegisterUsage(m_EnterSection))
{ {
return false; return false;
@ -71,18 +71,18 @@ bool LoopAnalysis::SetupEnterSection(CCodeSection * Section, bool & bChanged, bo
bSkipedSection = false; bSkipedSection = false;
if (Section->m_ParentSection.empty()) { g_Notify->BreakPoint(__FILE__, __LINE__); return true; } if (Section->m_ParentSection.empty()) { g_Notify->BreakPoint(__FILE__, __LINE__); return true; }
CPU_Message("%s: Block EnterPC: %X Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, m_BlockInfo->VAddrEnter(), Section->m_SectionID, m_Test, Section->m_Test, Section->m_CompiledLocation); m_CodeBlock.Log("%s: Block EnterPC: %X Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, m_CodeBlock.VAddrEnter(), Section->m_SectionID, m_Test, Section->m_Test, Section->m_CompiledLocation);
bool bFirstParent = true; bool bFirstParent = true;
CRegInfo RegEnter; CRegInfo RegEnter(m_CodeBlock);
for (CCodeSection::SECTION_LIST::iterator iter = Section->m_ParentSection.begin(); iter != Section->m_ParentSection.end(); iter++) for (CCodeSection::SECTION_LIST::iterator iter = Section->m_ParentSection.begin(); iter != Section->m_ParentSection.end(); iter++)
{ {
CCodeSection * Parent = *iter; CCodeSection * Parent = *iter;
CPU_Message("%s: Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation); m_CodeBlock.Log("%s: Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation);
if (Parent->m_Test != m_Test && (m_EnterSection != Section || Parent->m_CompiledLocation == nullptr) && Parent->m_InLoop) if (Parent->m_Test != m_Test && (m_EnterSection != Section || Parent->m_CompiledLocation == nullptr) && Parent->m_InLoop)
{ {
CPU_Message("%s: Ignore Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation); m_CodeBlock.Log("%s: Ignore Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation);
bSkipedSection = true; bSkipedSection = true;
continue; continue;
} }
@ -141,7 +141,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
if (Section == nullptr) { return true; } if (Section == nullptr) { return true; }
if (!Section->m_InLoop) { return true; } if (!Section->m_InLoop) { return true; }
CPU_Message("%s: Section %d Block PC: 0x%X", __FUNCTION__, Section->m_SectionID, m_BlockInfo->VAddrEnter()); m_CodeBlock.Log("%s: Section %d Block PC: 0x%X", __FUNCTION__, Section->m_SectionID, m_CodeBlock.VAddrEnter());
bool bChanged = false, bSkipedSection = false; bool bChanged = false, bSkipedSection = false;
if (Section == m_EnterSection && Section->m_Test == m_Test) if (Section == m_EnterSection && Section->m_Test == m_Test)
@ -157,7 +157,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
return true; return true;
} }
CPU_Message("%s: Set Section %d test to %X from %X", __FUNCTION__, Section->m_SectionID, m_Test, Section->m_Test); m_CodeBlock.Log("%s: Set Section %d test to %X from %X", __FUNCTION__, Section->m_SectionID, m_Test, Section->m_Test);
Section->m_Test = m_Test; Section->m_Test = m_Test;
m_PC = Section->m_EnterPC; m_PC = Section->m_EnterPC;
@ -166,7 +166,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
m_PipelineStage = PIPELINE_STAGE_NORMAL; m_PipelineStage = PIPELINE_STAGE_NORMAL;
uint32_t ContinueSectionPC = Section->m_ContinueSection ? Section->m_ContinueSection->m_EnterPC : (uint32_t)-1; uint32_t ContinueSectionPC = Section->m_ContinueSection ? Section->m_ContinueSection->m_EnterPC : (uint32_t)-1;
CPU_Message("ContinueSectionPC = %08X", ContinueSectionPC); m_CodeBlock.Log("ContinueSectionPC = %08X", ContinueSectionPC);
do do
{ {
@ -175,7 +175,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return false; return false;
} }
CPU_Message(" %08X: %s", m_PC, R4300iInstruction(m_PC, m_Command.Value).NameAndParam().c_str()); m_CodeBlock.Log(" %08X: %s", m_PC, R4300iInstruction(m_PC, m_Command.Value).NameAndParam().c_str());
switch (m_Command.op) switch (m_Command.op)
{ {
case R4300i_SPECIAL: case R4300i_SPECIAL:
@ -651,7 +651,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
g_Notify->DisplayError(stdstr_f("Unhandled R4300i opcode in FillSectionInfo 1\n%s\n%X", R4300iInstruction(m_PC, m_Command.Value).NameAndParam().c_str(), m_Command.Value).c_str()); g_Notify->DisplayError(stdstr_f("Unhandled R4300i opcode in FillSectionInfo 1\n%s\n%X", R4300iInstruction(m_PC, m_Command.Value).NameAndParam().c_str(), m_Command.Value).c_str());
} }
CPU_Message(" %s state: %X value: %X", CRegName::GPR[5], m_Reg.GetMipsRegState(5), m_Reg.GetMipsRegLo(5)); m_CodeBlock.Log(" %s state: %X value: %X", CRegName::GPR[5], m_Reg.GetMipsRegState(5), m_Reg.GetMipsRegLo(5));
if (Section->m_DelaySlot) if (Section->m_DelaySlot)
{ {
@ -722,13 +722,13 @@ bool LoopAnalysis::SyncRegState(CRegInfo & RegSet, const CRegInfo& SyncReg)
{ {
if (RegSet.GetMipsRegState(x) != SyncReg.GetMipsRegState(x)) if (RegSet.GetMipsRegState(x) != SyncReg.GetMipsRegState(x))
{ {
CPU_Message("%s: Clear state %s RegEnter State: %X Jump Reg State: %X", __FUNCTION__, CRegName::GPR[x], RegSet.GetMipsRegState(x), SyncReg.GetMipsRegState(x)); m_CodeBlock.Log("%s: Clear state %s RegEnter State: %X Jump Reg State: %X", __FUNCTION__, CRegName::GPR[x], RegSet.GetMipsRegState(x), SyncReg.GetMipsRegState(x));
RegSet.SetMipsRegState(x, CRegInfo::STATE_MODIFIED); RegSet.SetMipsRegState(x, CRegInfo::STATE_MODIFIED);
bChanged = true; bChanged = true;
} }
else if (RegSet.IsConst(x) && RegSet.Is32Bit(x) && RegSet.GetMipsRegLo(x) != SyncReg.GetMipsRegLo(x)) else if (RegSet.IsConst(x) && RegSet.Is32Bit(x) && RegSet.GetMipsRegLo(x) != SyncReg.GetMipsRegLo(x))
{ {
CPU_Message("%s: Clear state %s RegEnter State: %X Jump Reg State: %X", __FUNCTION__, CRegName::GPR[x], RegSet.GetMipsRegState(x), SyncReg.GetMipsRegState(x)); m_CodeBlock.Log("%s: Clear state %s RegEnter State: %X Jump Reg State: %X", __FUNCTION__, CRegName::GPR[x], RegSet.GetMipsRegState(x), SyncReg.GetMipsRegState(x));
RegSet.SetMipsRegState(x, CRegInfo::STATE_MODIFIED); RegSet.SetMipsRegState(x, CRegInfo::STATE_MODIFIED);
bChanged = true; bChanged = true;
} }

View File

@ -10,7 +10,7 @@ class CCodeBlock;
class LoopAnalysis class LoopAnalysis
{ {
public: public:
LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section); LoopAnalysis(CCodeBlock & CodeBlock, CCodeSection * Section);
~LoopAnalysis(); ~LoopAnalysis();
bool SetupRegisterForLoop(); bool SetupRegisterForLoop();
@ -71,7 +71,7 @@ private:
RegisterMap m_ContinueRegisters; RegisterMap m_ContinueRegisters;
RegisterMap m_JumpRegisters; RegisterMap m_JumpRegisters;
CCodeSection * m_EnterSection; CCodeSection * m_EnterSection;
CCodeBlock * m_BlockInfo; CCodeBlock & m_CodeBlock;
uint32_t m_PC; uint32_t m_PC;
CRegInfo m_Reg; CRegInfo m_Reg;
PIPELINE_STAGE m_PipelineStage; PIPELINE_STAGE m_PipelineStage;

View File

@ -1,7 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Recompiler/Recompiler.h> #include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Interpreter/InterpreterCPU.h> #include <Project64-core/N64System/Interpreter/InterpreterCPU.h>
#include <Project64-core/ExceptionHandler.h> #include <Project64-core/ExceptionHandler.h>
@ -11,7 +10,8 @@ CRecompiler::CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & End
m_Registers(Registers), m_Registers(Registers),
m_EndEmulation(EndEmulation), m_EndEmulation(EndEmulation),
m_MemoryStack(0), m_MemoryStack(0),
PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER) PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER),
m_LogFile(nullptr)
{ {
CFunctionMap::AllocateMemory(); CFunctionMap::AllocateMemory();
ResetMemoryStackPos(); ResetMemoryStackPos();
@ -20,16 +20,13 @@ CRecompiler::CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & End
CRecompiler::~CRecompiler() CRecompiler::~CRecompiler()
{ {
ResetRecompCode(false); ResetRecompCode(false);
StopLog();
} }
void CRecompiler::Run() void CRecompiler::Run()
{ {
WriteTrace(TraceRecompiler, TraceDebug, "Start"); WriteTrace(TraceRecompiler, TraceDebug, "Start");
StartLog();
if (bRecordRecompilerAsm())
{
Start_Recompiler_Log();
}
if (!CRecompMemory::AllocateMemory()) if (!CRecompMemory::AllocateMemory())
{ {
@ -387,6 +384,8 @@ CCompiledFunc * CRecompiler::CompileCode()
ShowMemUsed(); ShowMemUsed();
} }
LogCodeBlock(CodeBlock);
CCompiledFunc * Func = new CCompiledFunc(CodeBlock); CCompiledFunc * Func = new CCompiledFunc(CodeBlock);
std::pair<CCompiledFuncList::iterator, bool> ret = m_Functions.insert(CCompiledFuncList::value_type(Func->EnterPC(), Func)); std::pair<CCompiledFuncList::iterator, bool> ret = m_Functions.insert(CCompiledFuncList::value_type(Func->EnterPC(), Func));
if (ret.second == false) if (ret.second == false)
@ -511,6 +510,12 @@ void CRecompiler::ClearRecompCode_Virt(uint32_t Address, int length, REMOVE_REAS
} }
} }
void CRecompiler::ResetLog()
{
StopLog();
StartLog();
}
void CRecompiler::ResetMemoryStackPos() void CRecompiler::ResetMemoryStackPos()
{ {
#if defined(__aarch64__) || defined(__amd64__) #if defined(__aarch64__) || defined(__amd64__)
@ -555,4 +560,49 @@ void CRecompiler::DumpFunctionTimes()
void CRecompiler::ResetFunctionTimes() void CRecompiler::ResetFunctionTimes()
{ {
m_BlockProfile.clear(); m_BlockProfile.clear();
} }
void CRecompiler::StartLog()
{
if (!bRecordRecompilerAsm())
{
return;
}
CPath LogFileName(g_Settings->LoadStringVal(Directory_Log).c_str(), "CPUoutput.log");
if (m_LogFile != nullptr)
{
StopLog();
}
m_LogFile = new CLog();
if (m_LogFile)
{
if (m_LogFile->Open(LogFileName))
{
m_LogFile->SetMaxFileSize(300 * CLog::MB);
}
else
{
StopLog();
}
}
}
void CRecompiler::StopLog(void)
{
if (m_LogFile != nullptr)
{
delete m_LogFile;
m_LogFile = nullptr;
}
}
void CRecompiler::LogCodeBlock(const CCodeBlock & CodeBlock)
{
if (!bRecordRecompilerAsm() || m_LogFile == nullptr || CodeBlock.CodeLog().empty())
{
return;
}
m_LogFile->Log(CodeBlock.CodeLog().c_str());
m_LogFile->Log("\r\n");
m_LogFile->Flush();
}

View File

@ -8,6 +8,8 @@
#include <Project64-core/Settings/RecompilerSettings.h> #include <Project64-core/Settings/RecompilerSettings.h>
#include <Project64-core/Settings/DebugSettings.h> #include <Project64-core/Settings/DebugSettings.h>
class CLog;
class CRecompiler : class CRecompiler :
protected CDebugSettings, protected CDebugSettings,
public CRecompilerSettings, public CRecompilerSettings,
@ -44,6 +46,7 @@ public:
void ClearRecompCode_Virt(uint32_t VirtualAddress, int32_t length, REMOVE_REASON Reason); void ClearRecompCode_Virt(uint32_t VirtualAddress, int32_t length, REMOVE_REASON Reason);
void ClearRecompCode_Phys(uint32_t PhysicalAddress, int32_t length, REMOVE_REASON Reason); void ClearRecompCode_Phys(uint32_t PhysicalAddress, int32_t length, REMOVE_REASON Reason);
void ResetLog();
void ResetMemoryStackPos(); void ResetMemoryStackPos();
void ResetFunctionTimes(); void ResetFunctionTimes();
void DumpFunctionTimes(); void DumpFunctionTimes();
@ -71,6 +74,10 @@ private:
void RecompilerMain_Lookup(); void RecompilerMain_Lookup();
void RecompilerMain_Lookup_validate(); void RecompilerMain_Lookup_validate();
void StartLog();
void StopLog();
void LogCodeBlock(const CCodeBlock & CodeBlock);
CCompiledFuncList m_Functions; CCompiledFuncList m_Functions;
CMipsMemoryVM & m_MMU; CMipsMemoryVM & m_MMU;
CRegisters & m_Registers; CRegisters & m_Registers;
@ -78,4 +85,5 @@ private:
uint32_t m_MemoryStack; uint32_t m_MemoryStack;
FUNCTION_PROFILE m_BlockProfile; FUNCTION_PROFILE m_BlockProfile;
uint32_t & PROGRAM_COUNTER; uint32_t & PROGRAM_COUNTER;
CLog * m_LogFile;
}; };

View File

@ -1,72 +0,0 @@
#include "stdafx.h"
#include "RecompilerCodeLog.h"
#include <Common/path.h>
#include <Common/Platform.h>
// vsprintf()
#include <stdio.h>
#include <stdarg.h>
static CLog * g_CPULogFile = nullptr;
void Recompiler_Log_Message(const char * strFormat, ...)
{
va_list args;
va_start(args, strFormat);
size_t nlen = _vscprintf(strFormat, args) + 1;
char * buffer = (char *)alloca((nlen + 3) * sizeof(char));
if (buffer != nullptr)
{
if (nlen > 0)
{
vsnprintf(buffer, nlen, strFormat, args);
buffer[nlen - 1] = '\0';
}
else
{
buffer[0] = '\0';
}
strcat(buffer, "\r\n");
g_CPULogFile->Log(buffer);
}
va_end(args);
}
void Start_Recompiler_Log (void)
{
CPath LogFileName(g_Settings->LoadStringVal(Directory_Log).c_str(), "CPUoutput.log");
if (g_CPULogFile != nullptr)
{
Stop_Recompiler_Log();
}
g_CPULogFile = new CLog();
if (g_CPULogFile)
{
if (g_CPULogFile->Open(LogFileName))
{
g_CPULogFile->SetMaxFileSize(300 * CLog::MB);
}
else
{
delete g_CPULogFile;
g_CPULogFile = nullptr;
}
}
}
void Stop_Recompiler_Log (void)
{
if (g_CPULogFile != nullptr)
{
delete g_CPULogFile;
g_CPULogFile = nullptr;
}
}
void Flush_Recompiler_Log(void)
{
if (g_CPULogFile != nullptr)
{
g_CPULogFile->Flush();
}
}

View File

@ -1,9 +0,0 @@
#pragma once
#include <Project64-core/Settings/DebugSettings.h>
#define CPU_Message(Message,... ) if (CDebugSettings::bRecordRecompilerAsm()) { Recompiler_Log_Message(Message,## __VA_ARGS__); }
void Recompiler_Log_Message (const char * Message, ...);
void Start_Recompiler_Log (void);
void Stop_Recompiler_Log(void);
void Flush_Recompiler_Log(void);

View File

@ -2,7 +2,8 @@
#include "SectionInfo.h" #include "SectionInfo.h"
#include "JumpInfo.h" #include "JumpInfo.h"
CJumpInfo::CJumpInfo() CJumpInfo::CJumpInfo(CCodeBlock & CodeBlock) :
RegSet(CodeBlock)
{ {
TargetPC = (uint32_t)-1; TargetPC = (uint32_t)-1;
JumpPC = (uint32_t)-1; JumpPC = (uint32_t)-1;

View File

@ -25,7 +25,7 @@ class CX86RecompilerOps :
private CGameSettings private CGameSettings
{ {
public: public:
CX86RecompilerOps(CMipsMemoryVM & MMU); CX86RecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock);
~CX86RecompilerOps(); ~CX86RecompilerOps();
// Trap functions // Trap functions
@ -216,7 +216,7 @@ public:
void CompileCop1Test(); void CompileCop1Test();
void CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCounter); void CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCounter);
void SyncRegState(const CRegInfo & SyncTo); void SyncRegState(const CRegInfo & SyncTo);
bool SetupRegisterForLoop(CCodeBlock * BlockInfo, const CRegInfo & RegSet); bool SetupRegisterForLoop(CCodeBlock & BlockInfo, const CRegInfo & RegSet);
CRegInfo & GetRegWorkingSet(void); CRegInfo & GetRegWorkingSet(void);
void SetRegWorkingSet(const CRegInfo & RegInfo); void SetRegWorkingSet(const CRegInfo & RegInfo);
bool InheritParentInfo(); bool InheritParentInfo();
@ -236,7 +236,7 @@ public:
void CompileReadTLBMiss(uint32_t VirtualAddress, x86Reg LookUpReg); void CompileReadTLBMiss(uint32_t VirtualAddress, x86Reg LookUpReg);
void CompileReadTLBMiss(x86Reg AddressReg, x86Reg LookUpReg); void CompileReadTLBMiss(x86Reg AddressReg, x86Reg LookUpReg);
void CompileWriteTLBMiss(x86Reg AddressReg, x86Reg LookUpReg); void CompileWriteTLBMiss(x86Reg AddressReg, x86Reg LookUpReg);
static void UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles); void UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles);
void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true); void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false, bool UpdateTimer = true);
void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet); void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet);
void CompileExecuteBP(void); void CompileExecuteBP(void);
@ -247,111 +247,51 @@ public:
// Helper functions // Helper functions
typedef CRegInfo::REG_STATE REG_STATE; typedef CRegInfo::REG_STATE REG_STATE;
static REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); } REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); }
static uint64_t GetMipsReg(int32_t Reg) { return m_RegWorkingSet.GetMipsReg(Reg); } uint64_t GetMipsReg(int32_t Reg) { return m_RegWorkingSet.GetMipsReg(Reg); }
static int64_t GetMipsReg_S(int32_t Reg) { return m_RegWorkingSet.GetMipsReg_S(Reg); } int64_t GetMipsReg_S(int32_t Reg) { return m_RegWorkingSet.GetMipsReg_S(Reg); }
static uint32_t GetMipsRegLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo(Reg); } uint32_t GetMipsRegLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo(Reg); }
static int32_t GetMipsRegLo_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo_S(Reg); } int32_t GetMipsRegLo_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo_S(Reg); }
static uint32_t GetMipsRegHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi(Reg); } uint32_t GetMipsRegHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi(Reg); }
static int32_t GetMipsRegHi_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi_S(Reg); } int32_t GetMipsRegHi_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi_S(Reg); }
static CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapLo(Reg); } CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapLo(Reg); }
static CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapHi(Reg); } CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapHi(Reg); }
static bool IsKnown(int32_t Reg) { return m_RegWorkingSet.IsKnown(Reg); } bool IsKnown(int32_t Reg) { return m_RegWorkingSet.IsKnown(Reg); }
static bool IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); } bool IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); }
static bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); } bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); }
static bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(Reg); } bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(Reg); }
static bool IsSigned(int32_t Reg) { return m_RegWorkingSet.IsSigned(Reg); } bool IsSigned(int32_t Reg) { return m_RegWorkingSet.IsSigned(Reg); }
static bool IsUnsigned(int32_t Reg) { return m_RegWorkingSet.IsUnsigned(Reg); } bool IsUnsigned(int32_t Reg) { return m_RegWorkingSet.IsUnsigned(Reg); }
static bool Is32Bit(int32_t Reg) { return m_RegWorkingSet.Is32Bit(Reg); } bool Is32Bit(int32_t Reg) { return m_RegWorkingSet.Is32Bit(Reg); }
static bool Is64Bit(int32_t Reg) { return m_RegWorkingSet.Is64Bit(Reg); } bool Is64Bit(int32_t Reg) { return m_RegWorkingSet.Is64Bit(Reg); }
static bool Is32BitMapped(int32_t Reg) { return m_RegWorkingSet.Is32BitMapped(Reg); } bool Is32BitMapped(int32_t Reg) { return m_RegWorkingSet.Is32BitMapped(Reg); }
static bool Is64BitMapped(int32_t Reg) { return m_RegWorkingSet.Is64BitMapped(Reg); } bool Is64BitMapped(int32_t Reg) { return m_RegWorkingSet.Is64BitMapped(Reg); }
static void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod) void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod) { m_RegWorkingSet.FixRoundModel(RoundMethod); }
{ void ChangeFPURegFormat(int32_t Reg, CRegInfo::FPU_STATE OldFormat, CRegInfo::FPU_STATE NewFormat, CRegInfo::FPU_ROUND RoundingModel) { m_RegWorkingSet.ChangeFPURegFormat(Reg, OldFormat, NewFormat, RoundingModel); }
m_RegWorkingSet.FixRoundModel(RoundMethod); void Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, CRegInfo::FPU_STATE Format) { m_RegWorkingSet.Load_FPR_ToTop(Reg, RegToLoad, Format); }
} bool RegInStack(int32_t Reg, CRegInfo::FPU_STATE Format) { return m_RegWorkingSet.RegInStack(Reg, Format); }
static void ChangeFPURegFormat(int32_t Reg, CRegInfo::FPU_STATE OldFormat, CRegInfo::FPU_STATE NewFormat, CRegInfo::FPU_ROUND RoundingModel) x86FpuValues StackPosition(int32_t Reg) { return m_RegWorkingSet.StackPosition(Reg); }
{ void UnMap_AllFPRs() { m_RegWorkingSet.UnMap_AllFPRs(); }
m_RegWorkingSet.ChangeFPURegFormat(Reg, OldFormat, NewFormat, RoundingModel); void UnMap_FPR(uint32_t Reg, bool WriteBackValue) { m_RegWorkingSet.UnMap_FPR(Reg, WriteBackValue); }
}
static void Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, CRegInfo::FPU_STATE Format)
{
m_RegWorkingSet.Load_FPR_ToTop(Reg, RegToLoad, Format);
}
static bool RegInStack(int32_t Reg, CRegInfo::FPU_STATE Format)
{
return m_RegWorkingSet.RegInStack(Reg, Format);
}
static x86FpuValues StackPosition(int32_t Reg)
{
return m_RegWorkingSet.StackPosition(Reg);
}
static void UnMap_AllFPRs()
{
m_RegWorkingSet.UnMap_AllFPRs();
}
static void UnMap_FPR(uint32_t Reg, bool WriteBackValue)
{
m_RegWorkingSet.UnMap_FPR(Reg, WriteBackValue);
}
static x86Reg FreeX86Reg() x86Reg FreeX86Reg() { return m_RegWorkingSet.FreeX86Reg(); }
{ x86Reg Free8BitX86Reg() { return m_RegWorkingSet.Free8BitX86Reg(); }
return m_RegWorkingSet.FreeX86Reg(); void Map_GPR_32bit(int32_t Reg, bool SignValue, int32_t MipsRegToLoad) { m_RegWorkingSet.Map_GPR_32bit(Reg, SignValue, MipsRegToLoad); }
} void Map_GPR_64bit(int32_t Reg, int32_t MipsRegToLoad) { m_RegWorkingSet.Map_GPR_64bit(Reg, MipsRegToLoad); }
static x86Reg Free8BitX86Reg() x86Reg Get_MemoryStack() { return m_RegWorkingSet.Get_MemoryStack(); }
{ x86Reg Map_MemoryStack(x86Reg Reg, bool bMapRegister, bool LoadValue = true) { return m_RegWorkingSet.Map_MemoryStack(Reg, bMapRegister, LoadValue); }
return m_RegWorkingSet.Free8BitX86Reg(); x86Reg Map_TempReg(x86Reg Reg, int32_t MipsReg, bool LoadHiWord) { return m_RegWorkingSet.Map_TempReg(Reg, MipsReg, LoadHiWord); }
} void ProtectGPR(uint32_t Reg) { m_RegWorkingSet.ProtectGPR(Reg); }
static void Map_GPR_32bit(int32_t Reg, bool SignValue, int32_t MipsRegToLoad) void UnProtectGPR(uint32_t Reg) { m_RegWorkingSet.UnProtectGPR(Reg); }
{ void ResetX86Protection() { m_RegWorkingSet.ResetX86Protection(); }
m_RegWorkingSet.Map_GPR_32bit(Reg, SignValue, MipsRegToLoad); x86Reg UnMap_TempReg() { return m_RegWorkingSet.UnMap_TempReg(); }
} void UnMap_GPR(uint32_t Reg, bool WriteBackValue) { m_RegWorkingSet.UnMap_GPR(Reg, WriteBackValue); }
static void Map_GPR_64bit(int32_t Reg, int32_t MipsRegToLoad) bool UnMap_X86reg(x86Reg Reg) { return m_RegWorkingSet.UnMap_X86reg(Reg); }
{
m_RegWorkingSet.Map_GPR_64bit(Reg, MipsRegToLoad);
}
static x86Reg Get_MemoryStack()
{
return m_RegWorkingSet.Get_MemoryStack();
}
static x86Reg Map_MemoryStack(x86Reg Reg, bool bMapRegister, bool LoadValue = true)
{
return m_RegWorkingSet.Map_MemoryStack(Reg, bMapRegister, LoadValue);
}
static x86Reg Map_TempReg(x86Reg Reg, int32_t MipsReg, bool LoadHiWord)
{
return m_RegWorkingSet.Map_TempReg(Reg, MipsReg, LoadHiWord);
}
static void ProtectGPR(uint32_t Reg)
{
m_RegWorkingSet.ProtectGPR(Reg);
}
static void UnProtectGPR(uint32_t Reg)
{
m_RegWorkingSet.UnProtectGPR(Reg);
}
static void ResetX86Protection()
{
m_RegWorkingSet.ResetX86Protection();
}
static x86Reg UnMap_TempReg()
{
return m_RegWorkingSet.UnMap_TempReg();
}
static void UnMap_GPR(uint32_t Reg, bool WriteBackValue)
{
m_RegWorkingSet.UnMap_GPR(Reg, WriteBackValue);
}
static bool UnMap_X86reg(x86Reg Reg)
{
return m_RegWorkingSet.UnMap_X86reg(Reg);
}
public: public:
static uint32_t CompilePC() { return m_CompilePC; } uint32_t CompilePC() { return m_CompilePC; }
private: private:
CX86RecompilerOps(const CX86RecompilerOps&); CX86RecompilerOps(const CX86RecompilerOps&);
@ -361,9 +301,9 @@ private:
void CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86Ops::x86Reg ValueReg, CX86Ops::x86Reg ValueRegHi, uint8_t ValueSize, bool SignExtend); void CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86Ops::x86Reg ValueReg, CX86Ops::x86Reg ValueRegHi, uint8_t ValueSize, bool SignExtend);
void CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86Ops::x86Reg ValueReg, CX86Ops::x86Reg ValueRegHi, uint64_t Value, uint8_t ValueSize); void CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86Ops::x86Reg ValueReg, CX86Ops::x86Reg ValueRegHi, uint64_t Value, uint8_t ValueSize);
void SB_Const(uint8_t Value, uint32_t Addr); void SB_Const(uint32_t Value, uint32_t Addr);
void SB_Register(CX86Ops::x86Reg Reg, uint32_t Addr); void SB_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
void SH_Const(uint16_t Value, uint32_t Addr); void SH_Const(uint32_t Value, uint32_t Addr);
void SH_Register(CX86Ops::x86Reg Reg, uint32_t Addr); void SH_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
void SW_Const(uint32_t Value, uint32_t Addr); void SW_Const(uint32_t Value, uint32_t Addr);
void SW_Register(CX86Ops::x86Reg Reg, uint32_t Addr); void SW_Register(CX86Ops::x86Reg Reg, uint32_t Addr);
@ -372,18 +312,21 @@ private:
void LW_KnownAddress(x86Reg Reg, uint32_t VAddr); void LW_KnownAddress(x86Reg Reg, uint32_t VAddr);
void LW(bool ResultSigned, bool bRecordLLBit); void LW(bool ResultSigned, bool bRecordLLBit);
void SW(bool bCheckLLbit); void SW(bool bCheckLLbit);
void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(*x86Jmp)(const char * Label, uint32_t Value)); void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(CX86Ops::*x86Jmp)(const char * Label, uint32_t Value));
void ResetMemoryStack(); void ResetMemoryStack();
EXIT_LIST m_ExitInfo; EXIT_LIST m_ExitInfo;
CMipsMemoryVM & m_MMU; CMipsMemoryVM & m_MMU;
static PIPELINE_STAGE m_PipelineStage; CCodeBlock & m_CodeBlock;
static uint32_t m_CompilePC; PIPELINE_STAGE m_PipelineStage;
static R4300iOpcode m_Opcode; uint32_t m_CompilePC;
static CX86RegInfo m_RegWorkingSet; R4300iOpcode m_Opcode;
static uint32_t m_BranchCompare; CX86RegInfo m_RegWorkingSet;
static CCodeSection * m_Section; CCodeSection * m_Section;
CRegInfo m_RegBeforeDelay;
bool m_EffectDelaySlot;
static uint32_t m_TempValue32; static uint32_t m_TempValue32;
static uint32_t m_BranchCompare;
}; };
#endif #endif

View File

@ -4,7 +4,6 @@
#include <Project64-core/N64System/SystemGlobals.h> #include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/Recompiler/Recompiler.h> #include <Project64-core/N64System/Recompiler/Recompiler.h>
#include <Project64-core/N64System/Recompiler/RecompilerCodeLog.h>
#include <Project64-core/N64System/Recompiler/x86/x86RegInfo.h> #include <Project64-core/N64System/Recompiler/x86/x86RegInfo.h>
#include <stdio.h> #include <stdio.h>
@ -15,7 +14,9 @@ uint32_t CX86RegInfo::m_fpuControl = 0;
const char *Format_Name[] = { "Unknown", "dword", "qword", "float", "double" }; const char *Format_Name[] = { "Unknown", "dword", "qword", "float", "double" };
CX86RegInfo::CX86RegInfo() : CX86RegInfo::CX86RegInfo(CCodeBlock & CodeBlock) :
CX86Ops(CodeBlock),
m_CodeBlock(CodeBlock),
m_Stack_TopPos(0), m_Stack_TopPos(0),
m_InBeforeCallDirect(false) m_InBeforeCallDirect(false)
{ {
@ -39,7 +40,9 @@ CX86RegInfo::CX86RegInfo() :
} }
} }
CX86RegInfo::CX86RegInfo(const CX86RegInfo& rhs) CX86RegInfo::CX86RegInfo(const CX86RegInfo& rhs) :
CX86Ops(rhs),
m_CodeBlock(rhs.m_CodeBlock)
{ {
*this = rhs; *this = rhs;
} }
@ -140,7 +143,7 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod)
{ {
return; return;
} }
CPU_Message(" FixRoundModel: CurrentRoundingModel: %s targetRoundModel: %s", RoundingModelName(GetRoundingModel()), RoundingModelName(RoundMethod)); m_CodeBlock.Log(" FixRoundModel: CurrentRoundingModel: %s targetRoundModel: %s", RoundingModelName(GetRoundingModel()), RoundingModelName(RoundMethod));
m_fpuControl = 0; m_fpuControl = 0;
fpuStoreControl(&m_fpuControl, "m_fpuControl"); fpuStoreControl(&m_fpuControl, "m_fpuControl");
@ -205,7 +208,7 @@ void CX86RegInfo::ChangeFPURegFormat(int32_t Reg, FPU_STATE OldFormat, FPU_STATE
} }
else else
{ {
CPU_Message(" regcache: Changed format of ST(%d) from %s to %s", (i - StackTopPos() + 8) & 7, Format_Name[OldFormat], Format_Name[NewFormat]); m_CodeBlock.Log(" regcache: Changed format of ST(%d) from %s to %s", (i - StackTopPos() + 8) & 7, Format_Name[OldFormat], Format_Name[NewFormat]);
} }
FpuRoundingModel(i) = RoundingModel; FpuRoundingModel(i) = RoundingModel;
m_x86fpu_State[i] = NewFormat; m_x86fpu_State[i] = NewFormat;
@ -225,7 +228,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma
{ {
FixRoundModel(RoundDefault); FixRoundModel(RoundDefault);
} }
CPU_Message("CurrentRoundingModel: %s FpuRoundingModel(StackTopPos()): %s", RoundingModelName(GetRoundingModel()), RoundingModelName(FpuRoundingModel(StackTopPos()))); m_CodeBlock.Log("CurrentRoundingModel: %s FpuRoundingModel(StackTopPos()): %s", RoundingModelName(GetRoundingModel()), RoundingModelName(FpuRoundingModel(StackTopPos())));
int32_t i; int32_t i;
if (RegToLoad < 0) { g_Notify->DisplayError("Load_FPR_ToTop\nRegToLoad < 0 ???"); return; } if (RegToLoad < 0) { g_Notify->DisplayError("Load_FPR_ToTop\nRegToLoad < 0 ???"); return; }
@ -305,7 +308,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma
if (m_x86fpu_MappedTo[(StackTopPos() - 1) & 7] != RegToLoad) if (m_x86fpu_MappedTo[(StackTopPos() - 1) & 7] != RegToLoad)
{ {
UnMap_FPR(m_x86fpu_MappedTo[(StackTopPos() - 1) & 7], true); UnMap_FPR(m_x86fpu_MappedTo[(StackTopPos() - 1) & 7], true);
CPU_Message(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); m_CodeBlock.Log(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]);
fpuLoadReg(&StackTopPos(), StackPosition(RegToLoad)); fpuLoadReg(&StackTopPos(), StackPosition(RegToLoad));
FpuRoundingModel(StackTopPos()) = RoundDefault; FpuRoundingModel(StackTopPos()) = RoundDefault;
m_x86fpu_MappedTo[StackTopPos()] = Reg; m_x86fpu_MappedTo[StackTopPos()] = Reg;
@ -340,8 +343,8 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma
m_x86fpu_MappedTo[RegPos] = m_x86fpu_MappedTo[StackTopPos()]; m_x86fpu_MappedTo[RegPos] = m_x86fpu_MappedTo[StackTopPos()];
m_x86fpu_State[RegPos] = m_x86fpu_State[StackTopPos()]; m_x86fpu_State[RegPos] = m_x86fpu_State[StackTopPos()];
m_x86fpu_StateChanged[RegPos] = m_x86fpu_StateChanged[StackTopPos()]; m_x86fpu_StateChanged[RegPos] = m_x86fpu_StateChanged[StackTopPos()];
CPU_Message(" regcache: allocate ST(%d) to %s", StackPos, CRegName::FPR[m_x86fpu_MappedTo[RegPos]]); m_CodeBlock.Log(" regcache: allocate ST(%d) to %s", StackPos, CRegName::FPR[m_x86fpu_MappedTo[RegPos]]);
CPU_Message(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); m_CodeBlock.Log(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]);
fpuExchange(StackPos); fpuExchange(StackPos);
@ -365,7 +368,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma
i = 8; i = 8;
} }
} }
CPU_Message(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); m_CodeBlock.Log(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]);
TempReg = Map_TempReg(x86_Any, -1, false); TempReg = Map_TempReg(x86_Any, -1, false);
switch (Format) switch (Format)
{ {
@ -536,7 +539,7 @@ CX86Ops::x86Reg CX86RegInfo::UnMap_8BitTempReg()
{ {
if (GetX86Protected((x86Reg)count) == false) if (GetX86Protected((x86Reg)count) == false)
{ {
CPU_Message(" regcache: unallocate %s from temp storage", x86_Name((x86Reg)count)); m_CodeBlock.Log(" regcache: unallocate %s from temp storage", x86_Name((x86Reg)count));
SetX86Mapped((x86Reg)count, CX86RegInfo::NotMapped); SetX86Mapped((x86Reg)count, CX86RegInfo::NotMapped);
return (x86Reg)count; return (x86Reg)count;
} }
@ -585,7 +588,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister,
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped); SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped);
CPU_Message(" regcache: allocate %s as Memory Stack", x86_Name(Reg)); m_CodeBlock.Log(" regcache: allocate %s as Memory Stack", x86_Name(Reg));
if (LoadValue) if (LoadValue)
{ {
MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg); MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg);
@ -597,7 +600,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister,
UnMap_X86reg(Reg); UnMap_X86reg(Reg);
if (CurrentMap != x86_Unknown) if (CurrentMap != x86_Unknown)
{ {
CPU_Message(" regcache: change allocation of memory stack from %s to %s", x86_Name(CurrentMap), x86_Name(Reg)); m_CodeBlock.Log(" regcache: change allocation of memory stack from %s to %s", x86_Name(CurrentMap), x86_Name(Reg));
SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped); SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped);
SetX86Mapped(CurrentMap, CX86RegInfo::NotMapped); SetX86Mapped(CurrentMap, CX86RegInfo::NotMapped);
MoveX86RegToX86Reg(CurrentMap, Reg); MoveX86RegToX86Reg(CurrentMap, Reg);
@ -605,7 +608,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister,
else else
{ {
SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped); SetX86Mapped(Reg, CX86RegInfo::Stack_Mapped);
CPU_Message(" regcache: allocate %s as memory stack", x86_Name(Reg)); m_CodeBlock.Log(" regcache: allocate %s as memory stack", x86_Name(Reg));
if (LoadValue) if (LoadValue)
{ {
MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg); MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg);
@ -634,13 +637,13 @@ void CX86RegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
return; return;
} }
CPU_Message(" regcache: allocate %s to %s", x86_Name(Reg), CRegName::GPR[MipsReg]); m_CodeBlock.Log(" regcache: allocate %s to %s", x86_Name(Reg), CRegName::GPR[MipsReg]);
} }
else else
{ {
if (Is64Bit(MipsReg)) if (Is64Bit(MipsReg))
{ {
CPU_Message(" regcache: unallocate %s from high 32-bit of %s", x86_Name(GetMipsRegMapHi(MipsReg)), CRegName::GPR_Hi[MipsReg]); m_CodeBlock.Log(" regcache: unallocate %s from high 32-bit of %s", x86_Name(GetMipsRegMapHi(MipsReg)), CRegName::GPR_Hi[MipsReg]);
SetX86MapOrder(GetMipsRegMapHi(MipsReg), 0); SetX86MapOrder(GetMipsRegMapHi(MipsReg), 0);
SetX86Mapped(GetMipsRegMapHi(MipsReg), NotMapped); SetX86Mapped(GetMipsRegMapHi(MipsReg), NotMapped);
SetX86Protected(GetMipsRegMapHi(MipsReg), false); SetX86Protected(GetMipsRegMapHi(MipsReg), false);
@ -712,8 +715,8 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
if (x86lo < 0) { g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers"); return; } if (x86lo < 0) { g_Notify->DisplayError("Map_GPR_64bit\n\nOut of registers"); return; }
SetX86Protected(x86lo, true); SetX86Protected(x86lo, true);
CPU_Message(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]); m_CodeBlock.Log(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]);
CPU_Message(" regcache: allocate %s to low word of %s", x86_Name(x86lo), CRegName::GPR[MipsReg]); m_CodeBlock.Log(" regcache: allocate %s to low word of %s", x86_Name(x86lo), CRegName::GPR[MipsReg]);
} }
else else
{ {
@ -729,7 +732,7 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
} }
SetX86Protected(x86Hi, true); SetX86Protected(x86Hi, true);
CPU_Message(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]); m_CodeBlock.Log(" regcache: allocate %s to hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]);
} }
else else
{ {
@ -784,7 +787,7 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad)
} }
else else
{ {
CPU_Message("Map_GPR_64bit 11"); m_CodeBlock.Log("Map_GPR_64bit 11");
if (Is32Bit(MipsRegToLoad)) if (Is32Bit(MipsRegToLoad))
{ {
if (IsSigned(MipsRegToLoad)) if (IsSigned(MipsRegToLoad))
@ -883,7 +886,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b
UnMap_GPR(count, true); UnMap_GPR(count, true);
break; break;
} }
CPU_Message(" regcache: change allocation of %s from %s to %s", CRegName::GPR[count], x86_Name(Reg), x86_Name(NewReg)); m_CodeBlock.Log(" regcache: change allocation of %s from %s to %s", CRegName::GPR[count], x86_Name(Reg), x86_Name(NewReg));
SetX86Mapped(NewReg, GPR_Mapped); SetX86Mapped(NewReg, GPR_Mapped);
SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); SetX86MapOrder(NewReg, GetX86MapOrder(Reg));
SetMipsRegMapLo(count, NewReg); SetMipsRegMapLo(count, NewReg);
@ -901,7 +904,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b
UnMap_GPR(count, true); UnMap_GPR(count, true);
break; break;
} }
CPU_Message(" regcache: change allocation of %s from %s to %s", CRegName::GPR_Hi[count], x86_Name(Reg), x86_Name(NewReg)); m_CodeBlock.Log(" regcache: change allocation of %s from %s to %s", CRegName::GPR_Hi[count], x86_Name(Reg), x86_Name(NewReg));
SetX86Mapped(NewReg, GPR_Mapped); SetX86Mapped(NewReg, GPR_Mapped);
SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); SetX86MapOrder(NewReg, GetX86MapOrder(Reg));
SetMipsRegMapHi(count, NewReg); SetMipsRegMapHi(count, NewReg);
@ -918,7 +921,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b
{ {
UnMap_X86reg(Reg); UnMap_X86reg(Reg);
} }
CPU_Message(" regcache: allocate %s as temp storage", x86_Name(Reg)); m_CodeBlock.Log(" regcache: allocate %s as temp storage", x86_Name(Reg));
if (MipsReg >= 0) if (MipsReg >= 0)
{ {
@ -1066,7 +1069,7 @@ void CX86RegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue)
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
if (m_x86fpu_MappedTo[i] != Reg) { continue; } if (m_x86fpu_MappedTo[i] != Reg) { continue; }
CPU_Message(" regcache: unallocate %s from ST(%d)", CRegName::FPR[Reg], (i - StackTopPos() + 8) & 7); m_CodeBlock.Log(" regcache: unallocate %s from ST(%d)", CRegName::FPR[Reg], (i - StackTopPos() + 8) & 7);
if (WriteBackValue) if (WriteBackValue)
{ {
int32_t RegPos; int32_t RegPos;
@ -1157,7 +1160,7 @@ void CX86RegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue)
} }
if (IsUnknown(Reg)) { return; } if (IsUnknown(Reg)) { return; }
//CPU_Message("UnMap_GPR: State: %X\tReg: %s\tWriteBack: %s",State,CRegName::GPR[Reg],WriteBackValue?"true":"false"); //m_CodeBlock.Log("UnMap_GPR: State: %X\tReg: %s\tWriteBack: %s",State,CRegName::GPR[Reg],WriteBackValue?"true":"false");
if (IsConst(Reg)) if (IsConst(Reg))
{ {
if (!WriteBackValue) if (!WriteBackValue)
@ -1186,11 +1189,11 @@ void CX86RegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue)
} }
if (Is64Bit(Reg)) if (Is64Bit(Reg))
{ {
CPU_Message(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapHi(Reg)), CRegName::GPR_Hi[Reg]); m_CodeBlock.Log(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapHi(Reg)), CRegName::GPR_Hi[Reg]);
SetX86Mapped(GetMipsRegMapHi(Reg), NotMapped); SetX86Mapped(GetMipsRegMapHi(Reg), NotMapped);
SetX86Protected(GetMipsRegMapHi(Reg), false); SetX86Protected(GetMipsRegMapHi(Reg), false);
} }
CPU_Message(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapLo(Reg)), CRegName::GPR_Lo[Reg]); m_CodeBlock.Log(" regcache: unallocate %s from %s", x86_Name(GetMipsRegMapLo(Reg)), CRegName::GPR_Lo[Reg]);
SetX86Mapped(GetMipsRegMapLo(Reg), NotMapped); SetX86Mapped(GetMipsRegMapLo(Reg), NotMapped);
SetX86Protected(GetMipsRegMapLo(Reg), false); SetX86Protected(GetMipsRegMapLo(Reg), false);
if (!WriteBackValue) if (!WriteBackValue)
@ -1241,7 +1244,7 @@ CX86Ops::x86Reg CX86RegInfo::UnMap_TempReg()
{ {
if (GetX86Mapped(Reg) == Temp_Mapped) if (GetX86Mapped(Reg) == Temp_Mapped)
{ {
CPU_Message(" regcache: unallocate %s from temp storage", x86_Name(Reg)); m_CodeBlock.Log(" regcache: unallocate %s from temp storage", x86_Name(Reg));
} }
SetX86Mapped(Reg, NotMapped); SetX86Mapped(Reg, NotMapped);
} }
@ -1292,14 +1295,14 @@ bool CX86RegInfo::UnMap_X86reg(CX86Ops::x86Reg Reg)
{ {
if (!GetX86Protected(Reg)) if (!GetX86Protected(Reg))
{ {
CPU_Message(" regcache: unallocate %s from temp storage", x86_Name(Reg)); m_CodeBlock.Log(" regcache: unallocate %s from temp storage", x86_Name(Reg));
SetX86Mapped(Reg, NotMapped); SetX86Mapped(Reg, NotMapped);
return true; return true;
} }
} }
else if (GetX86Mapped(Reg) == CX86RegInfo::Stack_Mapped) else if (GetX86Mapped(Reg) == CX86RegInfo::Stack_Mapped)
{ {
CPU_Message(" regcache: unallocate %s from memory stack", x86_Name(Reg)); m_CodeBlock.Log(" regcache: unallocate %s from memory stack", x86_Name(Reg));
MoveX86regToVariable(Reg, &(g_Recompiler->MemoryStackPos()), "MemoryStack"); MoveX86regToVariable(Reg, &(g_Recompiler->MemoryStackPos()), "MemoryStack");
SetX86Mapped(Reg, NotMapped); SetX86Mapped(Reg, NotMapped);
return true; return true;
@ -1448,7 +1451,7 @@ void CX86RegInfo::WriteBackRegisters()
SetMipsRegState(count, CX86RegInfo::STATE_UNKNOWN); SetMipsRegState(count, CX86RegInfo::STATE_UNKNOWN);
break; break;
default: default:
CPU_Message("%s: Unknown State: %d reg %d (%s)", __FUNCTION__, GetMipsRegState(count), count, CRegName::GPR[count]); m_CodeBlock.Log("%s: Unknown State: %d reg %d (%s)", __FUNCTION__, GetMipsRegState(count), count, CRegName::GPR[count]);
g_Notify->BreakPoint(__FILE__, __LINE__); g_Notify->BreakPoint(__FILE__, __LINE__);
} }
} }

View File

@ -33,7 +33,7 @@ public:
}; };
public: public:
CX86RegInfo(); CX86RegInfo(CCodeBlock & CodeBlock);
CX86RegInfo(const CX86RegInfo&); CX86RegInfo(const CX86RegInfo&);
~CX86RegInfo(); ~CX86RegInfo();
@ -70,19 +70,19 @@ public:
bool UnMap_X86reg(x86Reg Reg); bool UnMap_X86reg(x86Reg Reg);
void WriteBackRegisters(); void WriteBackRegisters();
CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; } CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; }
CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; } CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; }
uint32_t GetX86MapOrder(x86Reg Reg) const { return m_x86reg_MapOrder[Reg]; } uint32_t GetX86MapOrder(x86Reg Reg) const { return m_x86reg_MapOrder[Reg]; }
bool GetX86Protected(x86Reg Reg) const { return m_x86reg_Protected[Reg]; } bool GetX86Protected(x86Reg Reg) const { return m_x86reg_Protected[Reg]; }
REG_MAPPED GetX86Mapped(x86Reg Reg) const { return m_x86reg_MappedTo[Reg]; } REG_MAPPED GetX86Mapped(x86Reg Reg) const { return m_x86reg_MappedTo[Reg]; }
void SetMipsRegMapLo(int32_t GetMipsReg, x86Reg Reg) { m_RegMapLo[GetMipsReg] = Reg; } void SetMipsRegMapLo(int32_t GetMipsReg, x86Reg Reg) { m_RegMapLo[GetMipsReg] = Reg; }
void SetMipsRegMapHi(int32_t GetMipsReg, x86Reg Reg) { m_RegMapHi[GetMipsReg] = Reg; } void SetMipsRegMapHi(int32_t GetMipsReg, x86Reg Reg) { m_RegMapHi[GetMipsReg] = Reg; }
void SetX86MapOrder(x86Reg Reg, uint32_t Order) { m_x86reg_MapOrder[Reg] = Order; } void SetX86MapOrder(x86Reg Reg, uint32_t Order) { m_x86reg_MapOrder[Reg] = Order; }
void SetX86Protected(x86Reg Reg, bool Protected) { m_x86reg_Protected[Reg] = Protected; } void SetX86Protected(x86Reg Reg, bool Protected) { m_x86reg_Protected[Reg] = Protected; }
void SetX86Mapped(x86Reg Reg, REG_MAPPED Mapping) { m_x86reg_MappedTo[Reg] = Mapping; } void SetX86Mapped(x86Reg Reg, REG_MAPPED Mapping) { m_x86reg_MappedTo[Reg] = Mapping; }
int32_t & StackTopPos() { return m_Stack_TopPos; } int32_t & StackTopPos() { return m_Stack_TopPos; }
int32_t & FpuMappedTo(int32_t Reg) { return m_x86fpu_MappedTo[Reg]; } int32_t & FpuMappedTo(int32_t Reg) { return m_x86fpu_MappedTo[Reg]; }
@ -90,22 +90,25 @@ public:
FPU_ROUND & FpuRoundingModel(int32_t Reg) { return m_x86fpu_RoundingModel[Reg]; } FPU_ROUND & FpuRoundingModel(int32_t Reg) { return m_x86fpu_RoundingModel[Reg]; }
private: private:
CX86RegInfo();
CCodeBlock & m_CodeBlock;
x86Reg UnMap_8BitTempReg(); x86Reg UnMap_8BitTempReg();
// r4k // r4k
x86Reg m_RegMapHi[32]; x86Reg m_RegMapHi[32];
x86Reg m_RegMapLo[32]; x86Reg m_RegMapLo[32];
REG_MAPPED m_x86reg_MappedTo[10]; REG_MAPPED m_x86reg_MappedTo[10];
uint32_t m_x86reg_MapOrder[10]; uint32_t m_x86reg_MapOrder[10];
bool m_x86reg_Protected[10]; bool m_x86reg_Protected[10];
// FPU // FPU
int32_t m_Stack_TopPos; int32_t m_Stack_TopPos;
int32_t m_x86fpu_MappedTo[8]; int32_t m_x86fpu_MappedTo[8];
FPU_STATE m_x86fpu_State[8]; FPU_STATE m_x86fpu_State[8];
bool m_x86fpu_StateChanged[8]; bool m_x86fpu_StateChanged[8];
FPU_ROUND m_x86fpu_RoundingModel[8]; FPU_ROUND m_x86fpu_RoundingModel[8];
static uint32_t m_fpuControl; static uint32_t m_fpuControl;
bool m_InBeforeCallDirect; bool m_InBeforeCallDirect;

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)
class CCodeBlock;
class CX86Ops class CX86Ops
{ {
public: public:
@ -49,250 +51,258 @@ public:
static const char * x86_HalfName(x86Reg Reg); static const char * x86_HalfName(x86Reg Reg);
static const char * fpu_Name(x86FpuValues Reg); static const char * fpu_Name(x86FpuValues Reg);
protected: public:
CX86Ops(CCodeBlock & CodeBlock);
// Logging functions // Logging functions
static void WriteX86Comment(const char * Comment); void WriteX86Comment(const char * Comment);
static void WriteX86Label(const char * Label); void WriteX86Label(const char * Label);
static void AdcX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); void AdcX86regToVariable(x86Reg reg, void * Variable, const char * VariableName);
static void AdcConstToVariable(void *Variable, const char * VariableName, uint8_t Constant); void AdcConstToVariable(void *Variable, const char * VariableName, uint8_t Constant);
static void AdcConstToX86Reg(x86Reg Reg, uint32_t Const); void AdcConstToX86Reg(x86Reg Reg, uint32_t Const);
static void AdcVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); void AdcVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName);
static void AdcX86RegToX86Reg(x86Reg Destination, x86Reg Source); void AdcX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void AddConstToVariable(uint32_t Const, void *Variable, const char * VariableName); void AddConstToVariable(uint32_t Const, void *Variable, const char * VariableName);
static void AddConstToX86Reg(x86Reg Reg, uint32_t Const); void AddConstToX86Reg(x86Reg Reg, uint32_t Const);
static void AddVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); void AddVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName);
static void AddX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); void AddX86regToVariable(x86Reg reg, void * Variable, const char * VariableName);
static void AddX86RegToX86Reg(x86Reg Destination, x86Reg Source); void AddX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void AndConstToVariable(uint32_t Const, void *Variable, const char * VariableName); void AndConstToVariable(uint32_t Const, void *Variable, const char * VariableName);
static void AndConstToX86Reg(x86Reg Reg, uint32_t Const); void AndConstToX86Reg(x86Reg Reg, uint32_t Const);
static void AndVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); void AndVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg);
static void AndVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, Multipler Multiply); void AndVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, Multipler Multiply);
static void AndX86RegToX86Reg(x86Reg Destination, x86Reg Source); void AndX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void X86HardBreakPoint(); void X86HardBreakPoint();
static void X86BreakPoint(const char * FileName, int32_t LineNumber); void X86BreakPoint(const char * FileName, int32_t LineNumber);
static void Call_Direct(void * FunctAddress, const char * FunctName); void Call_Direct(void * FunctAddress, const char * FunctName);
static void Call_Indirect(void * FunctAddress, const char * FunctName); void Call_Indirect(void * FunctAddress, const char * FunctName);
static void CompConstToVariable(uint32_t Const, void * Variable, const char * VariableName); void CompConstToVariable(uint32_t Const, void * Variable, const char * VariableName);
static void CompConstToX86reg(x86Reg Reg, uint32_t Const); void CompConstToX86reg(x86Reg Reg, uint32_t Const);
static void CompConstToX86regPointer(x86Reg Reg, uint32_t Const); void CompConstToX86regPointer(x86Reg Reg, uint32_t Const);
static void CompX86regToVariable(x86Reg Reg, void * Variable, const char * VariableName); void CompX86regToVariable(x86Reg Reg, void * Variable, const char * VariableName);
static void CompVariableToX86reg(x86Reg Reg, void * Variable, const char * VariableName); void CompVariableToX86reg(x86Reg Reg, void * Variable, const char * VariableName);
static void CompX86RegToX86Reg(x86Reg Destination, x86Reg Source); void CompX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void DecX86reg(x86Reg Reg); void DecX86reg(x86Reg Reg);
static void DivX86reg(x86Reg reg); void DivX86reg(x86Reg reg);
static void idivX86reg(x86Reg reg); void idivX86reg(x86Reg reg);
static void imulX86reg(x86Reg reg); void imulX86reg(x86Reg reg);
static void IncX86reg(x86Reg Reg); void IncX86reg(x86Reg Reg);
static void JaeLabel8(const char * Label, uint8_t Value); void JaeLabel8(const char * Label, uint8_t Value);
static void JaeLabel32(const char * Label, uint32_t Value); void JaeLabel32(const char * Label, uint32_t Value);
static void JaLabel8(const char * Label, uint8_t Value); void JaLabel8(const char * Label, uint8_t Value);
static void JaLabel32(const char * Label, uint32_t Value); void JaLabel32(const char * Label, uint32_t Value);
static void JbLabel8(const char * Label, uint8_t Value); void JbLabel8(const char * Label, uint8_t Value);
static void JbLabel32(const char * Label, uint32_t Value); void JbLabel32(const char * Label, uint32_t Value);
static void JecxzLabel8(const char * Label, uint8_t Value); void JecxzLabel8(const char * Label, uint8_t Value);
static void JeLabel8(const char * Label, uint8_t Value); void JeLabel8(const char * Label, uint8_t Value);
static void JeLabel32(const char * Label, uint32_t Value); void JeLabel32(const char * Label, uint32_t Value);
static void JgeLabel32(const char * Label, uint32_t Value); void JgeLabel32(const char * Label, uint32_t Value);
static void JgLabel8(const char * Label, uint8_t Value); void JgLabel8(const char * Label, uint8_t Value);
static void JgLabel32(const char * Label, uint32_t Value); void JgLabel32(const char * Label, uint32_t Value);
static void JleLabel8(const char * Label, uint8_t Value); void JleLabel8(const char * Label, uint8_t Value);
static void JleLabel32(const char * Label, uint32_t Value); void JleLabel32(const char * Label, uint32_t Value);
static void JlLabel8(const char * Label, uint8_t Value); void JlLabel8(const char * Label, uint8_t Value);
static void JlLabel32(const char * Label, uint32_t Value); void JlLabel32(const char * Label, uint32_t Value);
static void JmpDirectReg(x86Reg reg); void JmpDirectReg(x86Reg reg);
static void JmpIndirectLabel32(const char * Label, uint32_t location); void JmpIndirectLabel32(const char * Label, uint32_t location);
static void JmpIndirectReg(x86Reg reg); void JmpIndirectReg(x86Reg reg);
static void JmpLabel8(const char * Label, uint8_t Value); void JmpLabel8(const char * Label, uint8_t Value);
static void JmpLabel32(const char * Label, uint32_t Value); void JmpLabel32(const char * Label, uint32_t Value);
static void JneLabel8(const char * Label, uint8_t Value); void JneLabel8(const char * Label, uint8_t Value);
static void JneLabel32(const char * Label, uint32_t Value); void JneLabel32(const char * Label, uint32_t Value);
static void JnsLabel8(const char * Label, uint8_t Value); void JnsLabel8(const char * Label, uint8_t Value);
static void JnsLabel32(const char * Label, uint32_t Value); void JnsLabel32(const char * Label, uint32_t Value);
static void JnzLabel8(const char * Label, uint8_t Value); void JnzLabel8(const char * Label, uint8_t Value);
static void JnzLabel32(const char * Label, uint32_t Value); void JnzLabel32(const char * Label, uint32_t Value);
static void JsLabel32(const char * Label, uint32_t Value); void JsLabel32(const char * Label, uint32_t Value);
static void JzLabel8(const char * Label, uint8_t Value); void JzLabel8(const char * Label, uint8_t Value);
static void JzLabel32(const char * Label, uint32_t Value); void JzLabel32(const char * Label, uint32_t Value);
static void LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler multiplier); void LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler multiplier);
static void LeaRegReg2(x86Reg RegDest, x86Reg RegSrc, x86Reg RegSrc2, Multipler multiplier); void LeaRegReg2(x86Reg RegDest, x86Reg RegSrc, x86Reg RegSrc2, Multipler multiplier);
static void LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int32_t offset); void LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int32_t offset);
static void MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg); void MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg);
static void MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg); void MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg);
static void MoveConstByteToVariable(uint8_t Const, void * Variable, const char * VariableName); void MoveConstByteToVariable(uint8_t Const, void * Variable, const char * VariableName);
static void MoveConstByteToX86regPointer(uint8_t Const, x86Reg AddrReg1, x86Reg AddrReg2); void MoveConstByteToX86regPointer(uint8_t Const, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveConstHalfToVariable(uint16_t Const, void * Variable, const char * VariableName); void MoveConstHalfToVariable(uint16_t Const, void * Variable, const char * VariableName);
static void MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86Reg AddrReg2); void MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Disp); void MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Disp);
static void MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg); void MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg);
static void MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp); void MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp);
static void MoveConstToVariable(uint32_t Const, void * Variable, const char * VariableName); void MoveConstToVariable(uint32_t Const, void * Variable, const char * VariableName);
static void MoveConstToX86Pointer(uint32_t Const, x86Reg X86Pointer); void MoveConstToX86Pointer(uint32_t Const, x86Reg X86Pointer);
static void MoveConstToX86reg(uint32_t Const, x86Reg reg); void MoveConstToX86reg(uint32_t Const, x86Reg reg);
static void MoveConstToX86regPointer(uint32_t Const, x86Reg AddrReg1, x86Reg AddrReg2); void MoveConstToX86regPointer(uint32_t Const, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveN64MemDispToX86reg(x86Reg reg, x86Reg AddrReg, uint8_t Disp); void MoveN64MemDispToX86reg(x86Reg reg, x86Reg AddrReg, uint8_t Disp);
static void MoveN64MemToX86reg(x86Reg reg, x86Reg AddrReg); void MoveN64MemToX86reg(x86Reg reg, x86Reg AddrReg);
static void MoveN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); void MoveN64MemToX86regByte(x86Reg reg, x86Reg AddrReg);
static void MoveN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); void MoveN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg);
static void MoveSxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); void MoveSxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg);
static void MoveSxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); void MoveSxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg);
static void MoveSxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); void MoveSxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg);
static void MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); void MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg);
static void MoveSxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); void MoveSxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg);
static void MoveSxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); void MoveSxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg);
static void MoveVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, int32_t Multiplier); void MoveVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, int32_t Multiplier);
static void MoveVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); void MoveVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg);
static void MoveVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); void MoveVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg);
static void MoveVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); void MoveVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg);
static void MoveX86PointerToX86reg(x86Reg reg, x86Reg X86Pointer); void MoveX86PointerToX86reg(x86Reg reg, x86Reg X86Pointer);
static void MoveX86PointerToX86regDisp(x86Reg reg, x86Reg X86Pointer, uint8_t Disp); void MoveX86PointerToX86regDisp(x86Reg reg, x86Reg X86Pointer, uint8_t Disp);
static void MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg); void MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg);
static void MoveX86regByteToVariable(x86Reg reg, void * Variable, const char * VariableName); void MoveX86regByteToVariable(x86Reg reg, void * Variable, const char * VariableName);
static void MoveX86regByteToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); void MoveX86regByteToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg); void MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg);
static void MoveX86regHalfToVariable(x86Reg reg, void * Variable, const char * VariableName); void MoveX86regHalfToVariable(x86Reg reg, void * Variable, const char * VariableName);
static void MoveX86regHalfToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); void MoveX86regHalfToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); void MoveX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg);
static void MoveX86regPointerToX86regDisp8(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg, uint8_t offset); void MoveX86regPointerToX86regDisp8(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg, uint8_t offset);
static void MoveX86regToMemory(x86Reg reg, x86Reg AddrReg, uint32_t Disp); void MoveX86regToMemory(x86Reg reg, x86Reg AddrReg, uint32_t Disp);
static void MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg); void MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg);
static void MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp); void MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp);
static void MoveX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); void MoveX86regToVariable(x86Reg reg, void * Variable, const char * VariableName);
static void MoveX86RegToX86Reg(x86Reg Source, x86Reg Destination); void MoveX86RegToX86Reg(x86Reg Source, x86Reg Destination);
static void MoveX86regToX86Pointer(x86Reg reg, x86Reg X86Pointer); void MoveX86regToX86Pointer(x86Reg reg, x86Reg X86Pointer);
static void MoveX86regToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); void MoveX86regToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2);
static void MoveZxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); void MoveZxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg);
static void MoveZxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); void MoveZxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg);
static void MoveZxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); void MoveZxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg);
static void MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); void MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg);
static void MoveZxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); void MoveZxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg);
static void MoveZxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); void MoveZxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg);
static void MulX86reg(x86Reg reg); void MulX86reg(x86Reg reg);
static void NotX86Reg(x86Reg Reg); void NotX86Reg(x86Reg Reg);
static void OrConstToVariable(uint32_t Const, void * Variable, const char * VariableName); void OrConstToVariable(uint32_t Const, void * Variable, const char * VariableName);
static void OrConstToX86Reg(uint32_t Const, x86Reg reg); void OrConstToX86Reg(uint32_t Const, x86Reg reg);
static void OrVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); void OrVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg);
static void OrX86RegToVariable(void * Variable, const char * VariableName, x86Reg Reg); void OrX86RegToVariable(void * Variable, const char * VariableName, x86Reg Reg);
static void OrX86RegToX86Reg(x86Reg Destination, x86Reg Source); void OrX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void Push(x86Reg reg); void Push(x86Reg reg);
static void Pushad(); void Pushad();
static void PushImm32(uint32_t Value); void PushImm32(uint32_t Value);
static void PushImm32(const char * String, uint32_t Value); void PushImm32(const char * String, uint32_t Value);
static void Pop(x86Reg reg); void Pop(x86Reg reg);
static void Popad(); void Popad();
static void Ret(); void Ret();
static void Seta(x86Reg reg); void Seta(x86Reg reg);
static void Setae(x86Reg reg); void Setae(x86Reg reg);
static void SetaVariable(void * Variable, const char * VariableName); void SetaVariable(void * Variable, const char * VariableName);
static void Setb(x86Reg reg); void Setb(x86Reg reg);
static void SetbVariable(void * Variable, const char * VariableName); void SetbVariable(void * Variable, const char * VariableName);
static void Setg(x86Reg reg); void Setg(x86Reg reg);
static void SetgVariable(void * Variable, const char * VariableName); void SetgVariable(void * Variable, const char * VariableName);
static void Setl(x86Reg reg); void Setl(x86Reg reg);
static void SetlVariable(void * Variable, const char * VariableName); void SetlVariable(void * Variable, const char * VariableName);
static void Setz(x86Reg reg); void Setz(x86Reg reg);
static void Setnz(x86Reg reg); void Setnz(x86Reg reg);
static void ShiftLeftDouble(x86Reg Destination, x86Reg Source); void ShiftLeftDouble(x86Reg Destination, x86Reg Source);
static void ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); void ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate);
static void ShiftLeftSign(x86Reg reg); void ShiftLeftSign(x86Reg reg);
static void ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate); void ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate);
static void ShiftRightDouble(x86Reg Destination, x86Reg Source); void ShiftRightDouble(x86Reg Destination, x86Reg Source);
static void ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); void ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate);
static void ShiftRightSign(x86Reg reg); void ShiftRightSign(x86Reg reg);
static void ShiftRightSignImmed(x86Reg reg, uint8_t Immediate); void ShiftRightSignImmed(x86Reg reg, uint8_t Immediate);
static void ShiftRightUnsign(x86Reg reg); void ShiftRightUnsign(x86Reg reg);
static void ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate); void ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate);
static void SbbConstFromX86Reg(x86Reg Reg, uint32_t Const); void SbbConstFromX86Reg(x86Reg Reg, uint32_t Const);
static void SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); void SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName);
static void SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source); void SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName); void SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName);
static void SubConstFromX86Reg(x86Reg Reg, uint32_t Const); void SubConstFromX86Reg(x86Reg Reg, uint32_t Const);
static void SubVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); void SubVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName);
static void SubX86RegToX86Reg(x86Reg Destination, x86Reg Source); void SubX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void TestConstToX86Reg(uint32_t Const, x86Reg reg); void TestConstToX86Reg(uint32_t Const, x86Reg reg);
static void TestVariable(uint32_t Const, void * Variable, const char * VariableName); void TestVariable(uint32_t Const, void * Variable, const char * VariableName);
static void TestX86RegToX86Reg(x86Reg Destination, x86Reg Source); void TestX86RegToX86Reg(x86Reg Destination, x86Reg Source);
static void TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source); void TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source);
static void XorConstToX86Reg(x86Reg Reg, uint32_t Const); void XorConstToX86Reg(x86Reg Reg, uint32_t Const);
static void XorX86RegToX86Reg(x86Reg Source, x86Reg Destination); void XorX86RegToX86Reg(x86Reg Source, x86Reg Destination);
static void XorVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); void XorVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg);
static void fpuAbs(); void fpuAbs();
static void fpuAddDword(void * Variable, const char * VariableName); void fpuAddDword(void * Variable, const char * VariableName);
static void fpuAddDwordRegPointer(x86Reg x86Pointer); void fpuAddDwordRegPointer(x86Reg x86Pointer);
static void fpuAddQword(void * Variable, const char * VariableName); void fpuAddQword(void * Variable, const char * VariableName);
static void fpuAddQwordRegPointer(x86Reg X86Pointer); void fpuAddQwordRegPointer(x86Reg X86Pointer);
static void fpuAddReg(x86FpuValues reg); void fpuAddReg(x86FpuValues reg);
static void fpuAddRegPop(int32_t * StackPos, x86FpuValues reg); void fpuAddRegPop(int32_t * StackPos, x86FpuValues reg);
static void fpuComDword(void * Variable, const char * VariableName, bool Pop); void fpuComDword(void * Variable, const char * VariableName, bool Pop);
static void fpuComDwordRegPointer(x86Reg X86Pointer, bool Pop); void fpuComDwordRegPointer(x86Reg X86Pointer, bool Pop);
static void fpuComQword(void * Variable, const char * VariableName, bool Pop); void fpuComQword(void * Variable, const char * VariableName, bool Pop);
static void fpuComQwordRegPointer(x86Reg X86Pointer, bool Pop); void fpuComQwordRegPointer(x86Reg X86Pointer, bool Pop);
static void fpuComReg(x86FpuValues reg, bool Pop); void fpuComReg(x86FpuValues reg, bool Pop);
static void fpuDivDword(void * Variable, const char * VariableName); void fpuDivDword(void * Variable, const char * VariableName);
static void fpuDivDwordRegPointer(x86Reg X86Pointer); void fpuDivDwordRegPointer(x86Reg X86Pointer);
static void fpuDivQword(void * Variable, const char * VariableName); void fpuDivQword(void * Variable, const char * VariableName);
static void fpuDivQwordRegPointer(x86Reg X86Pointer); void fpuDivQwordRegPointer(x86Reg X86Pointer);
static void fpuDivReg(x86FpuValues Reg); void fpuDivReg(x86FpuValues Reg);
static void fpuDivRegPop(x86FpuValues reg); void fpuDivRegPop(x86FpuValues reg);
static void fpuExchange(x86FpuValues Reg); void fpuExchange(x86FpuValues Reg);
static void fpuFree(x86FpuValues Reg); void fpuFree(x86FpuValues Reg);
static void fpuDecStack(int32_t * StackPos); void fpuDecStack(int32_t * StackPos);
static void fpuIncStack(int32_t * StackPos); void fpuIncStack(int32_t * StackPos);
static void fpuLoadControl(void * Variable, const char * VariableName); void fpuLoadControl(void * Variable, const char * VariableName);
static void fpuLoadDword(int32_t * StackPos, void * Variable, const char * VariableName); void fpuLoadDword(int32_t * StackPos, void * Variable, const char * VariableName);
static void fpuLoadDwordFromX86Reg(int32_t * StackPos, x86Reg reg); void fpuLoadDwordFromX86Reg(int32_t * StackPos, x86Reg reg);
static void fpuLoadDwordFromN64Mem(int32_t * StackPos, x86Reg reg); void fpuLoadDwordFromN64Mem(int32_t * StackPos, x86Reg reg);
static void fpuLoadInt32bFromN64Mem(int32_t * StackPos, x86Reg reg); void fpuLoadInt32bFromN64Mem(int32_t * StackPos, x86Reg reg);
static void fpuLoadIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName); void fpuLoadIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName);
static void fpuLoadIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg); void fpuLoadIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg);
static void fpuLoadIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName); void fpuLoadIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName);
static void fpuLoadIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); void fpuLoadIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg);
static void fpuLoadQword(int32_t * StackPos, void * Variable, const char * VariableName); void fpuLoadQword(int32_t * StackPos, void * Variable, const char * VariableName);
static void fpuLoadQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); void fpuLoadQwordFromX86Reg(int32_t * StackPos, x86Reg Reg);
static void fpuLoadQwordFromN64Mem(int32_t * StackPos, x86Reg reg); void fpuLoadQwordFromN64Mem(int32_t * StackPos, x86Reg reg);
static void fpuLoadReg(int32_t * StackPos, x86FpuValues Reg); void fpuLoadReg(int32_t * StackPos, x86FpuValues Reg);
static void fpuMulDword(void * Variable, const char * VariableName); void fpuMulDword(void * Variable, const char * VariableName);
static void fpuMulDwordRegPointer(x86Reg X86Pointer); void fpuMulDwordRegPointer(x86Reg X86Pointer);
static void fpuMulQword(void * Variable, const char * VariableName); void fpuMulQword(void * Variable, const char * VariableName);
static void fpuMulQwordRegPointer(x86Reg X86Pointer); void fpuMulQwordRegPointer(x86Reg X86Pointer);
static void fpuMulReg(x86FpuValues reg); void fpuMulReg(x86FpuValues reg);
static void fpuMulRegPop(x86FpuValues reg); void fpuMulRegPop(x86FpuValues reg);
static void fpuNeg(); void fpuNeg();
static void fpuRound(); void fpuRound();
static void fpuSqrt(); void fpuSqrt();
static void fpuStoreControl(void * Variable, const char * VariableName); void fpuStoreControl(void * Variable, const char * VariableName);
static void fpuStoreDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop);
static void fpuStoreDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); void fpuStoreDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop);
static void fpuStoreDwordToN64Mem(int32_t * StackPos, x86Reg reg, bool Pop); void fpuStoreDwordToN64Mem(int32_t * StackPos, x86Reg reg, bool Pop);
static void fpuStoreIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop);
static void fpuStoreIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); void fpuStoreIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop);
static void fpuStoreIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop);
static void fpuStoreIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); void fpuStoreIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop);
static void fpuStoreQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); void fpuStoreQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop);
static void fpuStoreStatus(); void fpuStoreStatus();
static void fpuSubDword(void * Variable, const char * VariableName); void fpuSubDword(void * Variable, const char * VariableName);
static void fpuSubDwordRegPointer(x86Reg X86Pointer); void fpuSubDwordRegPointer(x86Reg X86Pointer);
static void fpuSubDwordReverse(void * Variable, const char * VariableName); void fpuSubDwordReverse(void * Variable, const char * VariableName);
static void fpuSubQword(void * Variable, const char * VariableName); void fpuSubQword(void * Variable, const char * VariableName);
static void fpuSubQwordRegPointer(x86Reg X86Pointer); void fpuSubQwordRegPointer(x86Reg X86Pointer);
static void fpuSubQwordReverse(void * Variable, const char * VariableName); void fpuSubQwordReverse(void * Variable, const char * VariableName);
static void fpuSubReg(x86FpuValues reg); void fpuSubReg(x86FpuValues reg);
static void fpuSubRegPop(x86FpuValues reg); void fpuSubRegPop(x86FpuValues reg);
static bool Is8BitReg(x86Reg Reg); static bool Is8BitReg(x86Reg Reg);
static uint8_t CalcMultiplyCode(Multipler Multiply); static uint8_t CalcMultiplyCode(Multipler Multiply);
static void * GetAddressOf(int32_t value, ...); void * GetAddressOf(int32_t value, ...);
static void SetJump32(uint32_t * Loc, uint32_t * JumpLoc); void SetJump32(uint32_t * Loc, uint32_t * JumpLoc);
static void SetJump8(uint8_t * Loc, uint8_t * JumpLoc); void SetJump8(uint8_t * Loc, uint8_t * JumpLoc);
private: private:
CX86Ops(void);
void CodeLog(_Printf_format_string_ const char * Text, ...);
static void BreakPointNotification(const char * FileName, int32_t LineNumber); static void BreakPointNotification(const char * FileName, int32_t LineNumber);
static char m_fpupop[2][2]; static char m_fpupop[2][2];
static void AddCode8(uint8_t value); void AddCode8(uint8_t value);
static void AddCode16(uint16_t value); void AddCode16(uint16_t value);
static void AddCode32(uint32_t value); void AddCode32(uint32_t value);
CCodeBlock & m_CodeBlock;
}; };
#define AddressOf(Addr) CX86Ops::GetAddressOf(5,(Addr)) #define AddressOf(Addr) CX86Ops::GetAddressOf(5,(Addr))

View File

@ -93,11 +93,11 @@
<ClCompile Include="N64System\Recompiler\Arm\ArmRegInfo.cpp" /> <ClCompile Include="N64System\Recompiler\Arm\ArmRegInfo.cpp" />
<ClCompile Include="N64System\Recompiler\CodeBlock.cpp" /> <ClCompile Include="N64System\Recompiler\CodeBlock.cpp" />
<ClCompile Include="N64System\Recompiler\CodeSection.cpp" /> <ClCompile Include="N64System\Recompiler\CodeSection.cpp" />
<ClCompile Include="N64System\Recompiler\ExitInfo.cpp" />
<ClCompile Include="N64System\Recompiler\FunctionInfo.cpp" /> <ClCompile Include="N64System\Recompiler\FunctionInfo.cpp" />
<ClCompile Include="N64System\Recompiler\FunctionMap.cpp" /> <ClCompile Include="N64System\Recompiler\FunctionMap.cpp" />
<ClCompile Include="N64System\Recompiler\LoopAnalysis.cpp" /> <ClCompile Include="N64System\Recompiler\LoopAnalysis.cpp" />
<ClCompile Include="N64System\Recompiler\Recompiler.cpp" /> <ClCompile Include="N64System\Recompiler\Recompiler.cpp" />
<ClCompile Include="N64System\Recompiler\RecompilerCodeLog.cpp" />
<ClCompile Include="N64System\Recompiler\RecompilerMemory.cpp" /> <ClCompile Include="N64System\Recompiler\RecompilerMemory.cpp" />
<ClCompile Include="N64System\Recompiler\RegBase.cpp" /> <ClCompile Include="N64System\Recompiler\RegBase.cpp" />
<ClCompile Include="N64System\Recompiler\SectionInfo.cpp" /> <ClCompile Include="N64System\Recompiler\SectionInfo.cpp" />
@ -221,7 +221,6 @@
<ClInclude Include="N64System\Recompiler\JumpInfo.h" /> <ClInclude Include="N64System\Recompiler\JumpInfo.h" />
<ClInclude Include="N64System\Recompiler\LoopAnalysis.h" /> <ClInclude Include="N64System\Recompiler\LoopAnalysis.h" />
<ClInclude Include="N64System\Recompiler\Recompiler.h" /> <ClInclude Include="N64System\Recompiler\Recompiler.h" />
<ClInclude Include="N64System\Recompiler\RecompilerCodeLog.h" />
<ClInclude Include="N64System\Recompiler\RecompilerMemory.h" /> <ClInclude Include="N64System\Recompiler\RecompilerMemory.h" />
<ClInclude Include="N64System\Recompiler\RecompilerOps.h" /> <ClInclude Include="N64System\Recompiler\RecompilerOps.h" />
<ClInclude Include="N64System\Recompiler\RegBase.h" /> <ClInclude Include="N64System\Recompiler\RegBase.h" />

View File

@ -303,9 +303,6 @@
<ClCompile Include="RomList\RomList.cpp"> <ClCompile Include="RomList\RomList.cpp">
<Filter>Source Files\Rom List</Filter> <Filter>Source Files\Rom List</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="N64System\Recompiler\RecompilerCodeLog.cpp">
<Filter>Source Files\N64 System\Recompiler</Filter>
</ClCompile>
<ClCompile Include="N64System\Recompiler\x86\x86RecompilerOps.cpp"> <ClCompile Include="N64System\Recompiler\x86\x86RecompilerOps.cpp">
<Filter>Source Files\N64 System\Recompiler\x86</Filter> <Filter>Source Files\N64 System\Recompiler\x86</Filter>
</ClCompile> </ClCompile>
@ -408,6 +405,9 @@
<ClCompile Include="N64System\MemoryHandler\ISViewerHandler.cpp"> <ClCompile Include="N64System\MemoryHandler\ISViewerHandler.cpp">
<Filter>Source Files\N64 System\MemoryHandler</Filter> <Filter>Source Files\N64 System\MemoryHandler</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="N64System\Recompiler\ExitInfo.cpp">
<Filter>Source Files\N64 System\Recompiler</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="stdafx.h"> <ClInclude Include="stdafx.h">
@ -662,9 +662,6 @@
<ClInclude Include="RomList\RomList.h"> <ClInclude Include="RomList\RomList.h">
<Filter>Header Files\Rom List</Filter> <Filter>Header Files\Rom List</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="N64System\Recompiler\RecompilerCodeLog.h">
<Filter>Header Files\N64 System\Recompiler</Filter>
</ClInclude>
<ClInclude Include="N64System\Recompiler\x86\x86RecompilerOps.h"> <ClInclude Include="N64System\Recompiler\x86\x86RecompilerOps.h">
<Filter>Header Files\N64 System\Recompiler\x86</Filter> <Filter>Header Files\N64 System\Recompiler\x86</Filter>
</ClInclude> </ClInclude>