diff --git a/Source/Project64-core/MemoryExceptionFilter.cpp b/Source/Project64-core/MemoryExceptionFilter.cpp index 531576ef3..ee6df39b6 100644 --- a/Source/Project64-core/MemoryExceptionFilter.cpp +++ b/Source/Project64-core/MemoryExceptionFilter.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include #include -#include #include #include #ifndef _WIN32 diff --git a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp index 8dc2f2ec8..90879d403 100755 --- a/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp +++ b/Source/Project64-core/N64System/Mips/MemoryVirtualMem.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/Source/Project64-core/N64System/N64System.cpp b/Source/Project64-core/N64System/N64System.cpp index 280d2de05..9d8f462a9 100644 --- a/Source/Project64-core/N64System/N64System.cpp +++ b/Source/Project64-core/N64System/N64System.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "N64System.h" #include -#include #include #include #include @@ -2279,10 +2278,9 @@ bool CN64System::LoadState(const char * FileName) } m_CPU_Usage.ResetTimers(); m_FPS.Reset(true); - if (bRecordRecompilerAsm()) + if (bRecordRecompilerAsm() && m_Recomp) { - Stop_Recompiler_Log(); - Start_Recompiler_Log(); + m_Recomp->ResetLog(); } #ifdef TEST_SP_TRACKING diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp index e754a648a..81d459890 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include #include -#include #include #include #include @@ -31,7 +30,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi } #endif #if defined(__i386__) || defined(_M_IX86) - m_RecompilerOps = new CX86RecompilerOps(MMU); + m_RecompilerOps = new CX86RecompilerOps(MMU, *this); #elif defined(__arm__) || defined(_M_ARM) m_RecompilerOps = new CArmRecompilerOps(MMU); #endif @@ -40,7 +39,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi g_Notify->BreakPoint(__FILE__, __LINE__); return; } - CCodeSection * baseSection = new CCodeSection(this, VAddrEnter, 0, false); + CCodeSection * baseSection = new CCodeSection(*this, VAddrEnter, 0, false); if (baseSection == nullptr) { 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.RegSet = baseSection->m_RegEnter; - m_EnterSection = new CCodeSection(this, VAddrEnter, 1, true); + m_EnterSection = new CCodeSection(*this, VAddrEnter, 1, true); if (m_EnterSection == nullptr) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -127,7 +126,7 @@ bool CCodeBlock::SetSection(CCodeSection * & Section, CCodeSection * CurrentSect 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) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -160,7 +159,7 @@ bool CCodeBlock::SetSection(CCodeSection * & Section, CCodeSection * CurrentSect } 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; BaseSection->m_EndPC = SplitSection->m_EndPC; 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; - 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) { if (TestPC != EndPC) @@ -213,7 +212,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) CurrentSection->m_EndPC = TestPC - 4; CurrentSection = itr->second; - CPU_Message("Section %d", CurrentSection->m_SectionID); + Log("Section %d", CurrentSection->m_SectionID); if (EnterSection != m_EnterSection) { if (CurrentSection->m_JumpSection != nullptr || @@ -258,7 +257,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) if (EndBlock) { - CPU_Message("%s: End Block", __FUNCTION__); + Log("%s: End Block", __FUNCTION__); CurrentSection->m_EndSection = true; // Find other sections that need compiling break; @@ -266,7 +265,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) 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); if (!SetSection(CurrentSection->m_ContinueSection, CurrentSection, ContinuePC, true, TestPC)) { @@ -276,7 +275,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) 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); if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4, false, TestPC)) { @@ -299,7 +298,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) JumpSection->m_EndPC = TestPC + 4; if (BranchEndBlock) { - CPU_Message("%s: Jump End Block", __FUNCTION__); + Log("%s: Jump End Block", __FUNCTION__); JumpSection->m_EndSection = true; TargetPC = (uint32_t)-1; } @@ -317,7 +316,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) } 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); if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC, true, TestPC)) { @@ -359,7 +358,7 @@ bool CCodeBlock::CreateBlockLinkage(CCodeSection * EnterSection) break; } TestPC = CurrentSection->m_EnterPC; - CPU_Message("a. Section %d", CurrentSection->m_SectionID); + Log("a. Section %d", CurrentSection->m_SectionID); TestPC -= 4; } @@ -441,7 +440,7 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & #ifdef _DEBUG 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 switch (Command.op) { @@ -776,11 +775,11 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & bool CCodeBlock::Compile() { - CPU_Message("====== Code block ======"); - CPU_Message("Native entry point: %X", CompiledLocation()); - CPU_Message("Start of block: %X", VAddrEnter()); - CPU_Message("Number of sections: %d", NoOfSections()); - CPU_Message("====== Recompiled code ======"); + Log("====== Code block ======"); + Log("Native entry point: %X", CompiledLocation()); + Log("Start of block: %X", VAddrEnter()); + Log("Number of sections: %d", NoOfSections()); + Log("====== Recompiled code ======"); m_RecompilerOps->EnterCodeBlock(); if (g_System->bLinkBlocks()) @@ -816,4 +815,28 @@ uint32_t CCodeBlock::NextTest() uint32_t next_test = m_Test; m_Test += 1; return next_test; -} \ No newline at end of file +} + +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); +} diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.h b/Source/Project64-core/N64System/Recompiler/CodeBlock.h index eff677d0e..319264cec 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.h +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.h @@ -22,6 +22,8 @@ public: const CCodeSection & EnterSection() const { return *m_EnterSection; } const MD5Digest & Hash() const { return m_Hash; } CRecompilerOps *& RecompilerOps() { return m_RecompilerOps; } + const std::string & CodeLog() const { return m_CodeLog; } + void SetVAddrFirst(uint32_t VAddr) { m_VAddrFirst = VAddr; } void SetVAddrLast(uint32_t VAddr) { m_VAddrLast = VAddr; } @@ -33,6 +35,8 @@ public: uint32_t NextTest(); + void Log(_Printf_format_string_ const char * Text, ...); + private: CCodeBlock(); CCodeBlock(const CCodeBlock&); @@ -64,4 +68,5 @@ private: uint64_t m_MemContents[2]; uint64_t * m_MemLocation[2]; CRecompilerOps * m_RecompilerOps; + std::string m_CodeLog; }; diff --git a/Source/Project64-core/N64System/Recompiler/CodeSection.cpp b/Source/Project64-core/N64System/Recompiler/CodeSection.cpp index 1b4e4c66a..4a5c5ea66 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeSection.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeSection.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -13,8 +12,8 @@ #include #include -CCodeSection::CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) : - m_BlockInfo(CodeBlock), +CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID, bool LinkAllowed) : + m_CodeBlock(CodeBlock), m_SectionID(ID), m_EnterPC(EnterPC), m_EndPC((uint32_t)-1), @@ -27,9 +26,12 @@ CCodeSection::CCodeSection(CCodeBlock * CodeBlock, uint32_t EnterPC, uint32_t ID m_CompiledLocation(nullptr), m_InLoop(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); } @@ -121,13 +123,13 @@ void CCodeSection::GenerateSectionLinkage() { if (JumpInfo[i]->PermLoop) { - CPU_Message("PermLoop *** 1"); + m_CodeBlock.Log("PermLoop *** 1"); m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC); } else { 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); } } @@ -155,7 +157,7 @@ void CCodeSection::GenerateSectionLinkage() if (Parent->m_InLoop) { continue; } if (JumpInfo[i]->PermLoop) { - CPU_Message("PermLoop *** 2"); + m_CodeBlock.Log("PermLoop *** 2"); m_RecompilerOps->CompileInPermLoop(JumpInfo[i]->RegSet, JumpInfo[i]->TargetPC); } if (JumpInfo[i]->FallThrough) @@ -173,30 +175,30 @@ void CCodeSection::GenerateSectionLinkage() if (JumpInfo[i]->TargetPC < m_RecompilerOps->GetCurrentPC()) { 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); } } } - CPU_Message("====== End of Section %d ======", m_SectionID); + m_CodeBlock.Log("====== End of Section %d ======", m_SectionID); 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; m_RecompilerOps->JumpToUnknown(JumpInfo[i]); } } - //CPU_Message("Section %d",m_SectionID); + //CodeLog("Section %d",m_SectionID); for (i = 0; i < 2; i++) { if (JumpInfo[i]->LinkLocation == nullptr) { continue; } 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->CompileExit(JumpInfo[i]->JumpPC, JumpInfo[i]->TargetPC, JumpInfo[i]->RegSet, JumpInfo[i]->ExitReason); continue; @@ -207,13 +209,13 @@ void CCodeSection::GenerateSectionLinkage() } if (TargetSection[i]->m_CompiledLocation == nullptr) { - TargetSection[i]->GenerateNativeCode(m_BlockInfo->NextTest()); + TargetSection[i]->GenerateNativeCode(m_CodeBlock.NextTest()); } else { 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->SetRegWorkingSet(JumpInfo[i]->RegSet); if (JumpInfo[i]->TargetPC <= JumpInfo[i]->JumpPC) @@ -221,12 +223,12 @@ void CCodeSection::GenerateSectionLinkage() m_RecompilerOps->UpdateCounters(m_RecompilerOps->GetRegWorkingSet(), true, true); if (JumpInfo[i]->PermLoop) { - CPU_Message("PermLoop *** 3"); + m_CodeBlock.Log("PermLoop *** 3"); m_RecompilerOps->CompileInPermLoop(m_RecompilerOps->GetRegWorkingSet(), JumpInfo[i]->TargetPC); } else { - CPU_Message("CompileSystemCheck 9"); + m_CodeBlock.Log("CompileSystemCheck 9"); 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.TargetPC = TargetPC; - m_Jump.BranchLabel.Format("0x%08X", TargetPC); + m_Jump.BranchLabel = stdstr_f("0x%08X", TargetPC); m_Jump.PermLoop = PermLoop; } @@ -257,7 +259,7 @@ void CCodeSection::SetContinueAddress(uint32_t JumpPC, uint32_t TargetPC) { m_Cont.JumpPC = JumpPC; m_Cont.TargetPC = TargetPC; - m_Cont.BranchLabel.Format("0x%08X", TargetPC); + m_Cont.BranchLabel = stdstr_f("0x%08X", TargetPC); } bool CCodeSection::ParentContinue() @@ -268,7 +270,7 @@ bool CCodeSection::ParentContinue() { CCodeSection * Parent = *iter; if (Parent->m_CompiledLocation != nullptr) { continue; } - if (IsAllParentLoops(Parent, true, m_BlockInfo->NextTest())) { continue; } + if (IsAllParentLoops(Parent, true, m_CodeBlock.NextTest())) { continue; } return false; } m_RecompilerOps->SetCurrentSection(this); @@ -303,9 +305,9 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test) m_RecompilerOps->SetCurrentPC(m_EnterPC); 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; @@ -313,9 +315,9 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test) R4300iInstruction Instruction(m_RecompilerOps->GetCurrentPC(), Opcode.Value); 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)) @@ -636,7 +638,7 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test) // Do nothing, the block will end break; 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__); break; } @@ -790,11 +792,11 @@ void CCodeSection::DetermineLoop(uint32_t Test, uint32_t Test2, uint32_t TestID) m_Test = Test; 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) { - 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) { - 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) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -889,7 +891,7 @@ void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection) bool bRemove = false; 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++) { @@ -975,13 +977,13 @@ void CCodeSection::DisplaySectionInformation() return; } - CPU_Message("====== Section %d ======", m_SectionID); - CPU_Message("Start PC: 0x%X", m_EnterPC); + m_CodeBlock.Log("====== Section %d ======", m_SectionID); + m_CodeBlock.Log("Start PC: 0x%X", m_EnterPC); 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()) { stdstr ParentList; @@ -994,32 +996,32 @@ void CCodeSection::DisplaySectionInformation() } 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()) { - CPU_Message("Jump address: 0x%08X", m_Jump.JumpPC); - CPU_Message("Jump target address: 0x%08X", m_Jump.TargetPC); + m_CodeBlock.Log("Jump address: 0x%08X", m_Jump.JumpPC); + m_CodeBlock.Log("Jump target address: 0x%08X", m_Jump.TargetPC); if (m_JumpSection != nullptr) { - CPU_Message("Jump section: %d", m_JumpSection->m_SectionID); + m_CodeBlock.Log("Jump section: %d", m_JumpSection->m_SectionID); } else { - CPU_Message("Jump section: None"); + m_CodeBlock.Log("Jump section: None"); } - CPU_Message("Continue address: 0x%08X", m_Cont.JumpPC); - CPU_Message("Continue target address: 0x%08X", m_Cont.TargetPC); + m_CodeBlock.Log("Continue address: 0x%08X", m_Cont.JumpPC); + m_CodeBlock.Log("Continue target address: 0x%08X", m_Cont.TargetPC); if (m_ContinueSection != nullptr) { - CPU_Message("Continue section: %d", m_ContinueSection->m_SectionID); + m_CodeBlock.Log("Continue section: %d", m_ContinueSection->m_SectionID); } 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("======================="); } \ No newline at end of file diff --git a/Source/Project64-core/N64System/Recompiler/CodeSection.h b/Source/Project64-core/N64System/Recompiler/CodeSection.h index 2adcea322..f6cc4f540 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeSection.h +++ b/Source/Project64-core/N64System/Recompiler/CodeSection.h @@ -11,7 +11,7 @@ class CCodeSection : public: typedef std::list 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(); void SetDelaySlot(); @@ -28,28 +28,28 @@ public: void SwitchParent(CCodeSection * OldParent, CCodeSection * NewParent); // Block connection info - SECTION_LIST m_ParentSection; - CCodeBlock * const m_BlockInfo; - const uint32_t m_SectionID; - const uint32_t m_EnterPC; - uint32_t m_EndPC; - CCodeSection * m_ContinueSection; - 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_LinkAllowed; - uint32_t m_Test; - uint32_t m_Test2; - uint8_t * m_CompiledLocation; - bool m_InLoop; - bool m_DelaySlot; + SECTION_LIST m_ParentSection; + CCodeBlock & m_CodeBlock; + const uint32_t m_SectionID; + const uint32_t m_EnterPC; + uint32_t m_EndPC; + CCodeSection * m_ContinueSection; + 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_LinkAllowed; + uint32_t m_Test; + uint32_t m_Test2; + uint8_t * m_CompiledLocation; + bool m_InLoop; + bool m_DelaySlot; CRecompilerOps * & m_RecompilerOps; // Register info - CRegInfo m_RegEnter; + CRegInfo m_RegEnter; // Jump info - CJumpInfo m_Jump; - CJumpInfo m_Cont; + CJumpInfo m_Jump; + CJumpInfo m_Cont; private: CCodeSection(void); diff --git a/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp b/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp new file mode 100644 index 000000000..24f94692c --- /dev/null +++ b/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp @@ -0,0 +1,10 @@ +#include "stdafx.h" +#include + +CExitInfo::CExitInfo(CCodeBlock & CodeBlock) : + ID(0), + TargetPC(0), + JumpLoc(nullptr), + ExitRegSet(CodeBlock) +{ +} diff --git a/Source/Project64-core/N64System/Recompiler/ExitInfo.h b/Source/Project64-core/N64System/Recompiler/ExitInfo.h index 34596e465..74e62b495 100644 --- a/Source/Project64-core/N64System/Recompiler/ExitInfo.h +++ b/Source/Project64-core/N64System/Recompiler/ExitInfo.h @@ -5,6 +5,8 @@ struct CExitInfo { + CExitInfo(CCodeBlock & CodeBlock); + enum EXIT_REASON { Normal = 0, diff --git a/Source/Project64-core/N64System/Recompiler/JumpInfo.h b/Source/Project64-core/N64System/Recompiler/JumpInfo.h index f45a512e0..70cd2c247 100644 --- a/Source/Project64-core/N64System/Recompiler/JumpInfo.h +++ b/Source/Project64-core/N64System/Recompiler/JumpInfo.h @@ -5,16 +5,16 @@ struct CJumpInfo { typedef CExitInfo::EXIT_REASON EXIT_REASON; - CJumpInfo(); + CJumpInfo(CCodeBlock & CodeBlock); - uint32_t TargetPC; - uint32_t JumpPC; - stdstr BranchLabel; - uint32_t * LinkLocation; - uint32_t * LinkLocation2; - bool FallThrough; - bool PermLoop; - bool DoneDelaySlot; - CRegInfo RegSet; + uint32_t TargetPC; + uint32_t JumpPC; + std::string BranchLabel; + uint32_t * LinkLocation; + uint32_t * LinkLocation2; + bool FallThrough; + bool PermLoop; + bool DoneDelaySlot; + CRegInfo RegSet; EXIT_REASON ExitReason; }; diff --git a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp index f90112310..bb3272cf0 100644 --- a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp +++ b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -13,12 +12,13 @@ #define CHECKED_BUILD 1 #endif -LoopAnalysis::LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section) : +LoopAnalysis::LoopAnalysis(CCodeBlock & CodeBlock, CCodeSection * Section) : m_EnterSection(Section), - m_BlockInfo(CodeBlock), + m_CodeBlock(CodeBlock), m_PC((uint32_t)-1), m_PipelineStage(PIPELINE_STAGE_NORMAL), - m_Test(m_BlockInfo->NextTest()) + m_Test(CodeBlock.NextTest()), + m_Reg(CodeBlock) { memset(&m_Command, 0, sizeof(m_Command)); } @@ -50,7 +50,7 @@ bool LoopAnalysis::SetupRegisterForLoop() { 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)) { return false; @@ -71,18 +71,18 @@ bool LoopAnalysis::SetupEnterSection(CCodeSection * Section, bool & bChanged, bo bSkipedSection = false; 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; - CRegInfo RegEnter; + CRegInfo RegEnter(m_CodeBlock); for (CCodeSection::SECTION_LIST::iterator iter = Section->m_ParentSection.begin(); iter != Section->m_ParentSection.end(); 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) { - 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; continue; } @@ -141,7 +141,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section) if (Section == nullptr) { 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; if (Section == m_EnterSection && Section->m_Test == m_Test) @@ -157,7 +157,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section) 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; m_PC = Section->m_EnterPC; @@ -166,7 +166,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section) m_PipelineStage = PIPELINE_STAGE_NORMAL; 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 { @@ -175,7 +175,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section) g_Notify->BreakPoint(__FILE__, __LINE__); 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) { 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()); } - 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) { @@ -722,13 +722,13 @@ bool LoopAnalysis::SyncRegState(CRegInfo & RegSet, const CRegInfo& SyncReg) { 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); bChanged = true; } 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); bChanged = true; } diff --git a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.h b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.h index d55c10f01..1bd5b07d1 100644 --- a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.h +++ b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.h @@ -10,7 +10,7 @@ class CCodeBlock; class LoopAnalysis { public: - LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section); + LoopAnalysis(CCodeBlock & CodeBlock, CCodeSection * Section); ~LoopAnalysis(); bool SetupRegisterForLoop(); @@ -71,7 +71,7 @@ private: RegisterMap m_ContinueRegisters; RegisterMap m_JumpRegisters; CCodeSection * m_EnterSection; - CCodeBlock * m_BlockInfo; + CCodeBlock & m_CodeBlock; uint32_t m_PC; CRegInfo m_Reg; PIPELINE_STAGE m_PipelineStage; diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index 35c2bd3c8..0673e1b32 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include #include -#include #include #include #include @@ -11,7 +10,8 @@ CRecompiler::CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & End m_Registers(Registers), m_EndEmulation(EndEmulation), m_MemoryStack(0), - PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER) + PROGRAM_COUNTER(Registers.m_PROGRAM_COUNTER), + m_LogFile(nullptr) { CFunctionMap::AllocateMemory(); ResetMemoryStackPos(); @@ -20,16 +20,13 @@ CRecompiler::CRecompiler(CMipsMemoryVM & MMU, CRegisters & Registers, bool & End CRecompiler::~CRecompiler() { ResetRecompCode(false); + StopLog(); } void CRecompiler::Run() { WriteTrace(TraceRecompiler, TraceDebug, "Start"); - - if (bRecordRecompilerAsm()) - { - Start_Recompiler_Log(); - } + StartLog(); if (!CRecompMemory::AllocateMemory()) { @@ -387,6 +384,8 @@ CCompiledFunc * CRecompiler::CompileCode() ShowMemUsed(); } + LogCodeBlock(CodeBlock); + CCompiledFunc * Func = new CCompiledFunc(CodeBlock); std::pair ret = m_Functions.insert(CCompiledFuncList::value_type(Func->EnterPC(), Func)); 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() { #if defined(__aarch64__) || defined(__amd64__) @@ -555,4 +560,49 @@ void CRecompiler::DumpFunctionTimes() void CRecompiler::ResetFunctionTimes() { m_BlockProfile.clear(); -} \ No newline at end of file +} + +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(); +} diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.h b/Source/Project64-core/N64System/Recompiler/Recompiler.h index 11a33896a..321b880ae 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.h +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.h @@ -8,6 +8,8 @@ #include #include +class CLog; + class CRecompiler : protected CDebugSettings, public CRecompilerSettings, @@ -44,6 +46,7 @@ public: 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 ResetLog(); void ResetMemoryStackPos(); void ResetFunctionTimes(); void DumpFunctionTimes(); @@ -71,6 +74,10 @@ private: void RecompilerMain_Lookup(); void RecompilerMain_Lookup_validate(); + void StartLog(); + void StopLog(); + void LogCodeBlock(const CCodeBlock & CodeBlock); + CCompiledFuncList m_Functions; CMipsMemoryVM & m_MMU; CRegisters & m_Registers; @@ -78,4 +85,5 @@ private: uint32_t m_MemoryStack; FUNCTION_PROFILE m_BlockProfile; uint32_t & PROGRAM_COUNTER; + CLog * m_LogFile; }; diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp b/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp deleted file mode 100644 index fc02be57e..000000000 --- a/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "stdafx.h" -#include "RecompilerCodeLog.h" -#include -#include - -// vsprintf() -#include -#include - -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(); - } -} diff --git a/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.h b/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.h deleted file mode 100644 index c075aef48..000000000 --- a/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#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); diff --git a/Source/Project64-core/N64System/Recompiler/SectionInfo.cpp b/Source/Project64-core/N64System/Recompiler/SectionInfo.cpp index 25465ac23..2b80d55ae 100644 --- a/Source/Project64-core/N64System/Recompiler/SectionInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/SectionInfo.cpp @@ -2,7 +2,8 @@ #include "SectionInfo.h" #include "JumpInfo.h" -CJumpInfo::CJumpInfo() +CJumpInfo::CJumpInfo(CCodeBlock & CodeBlock) : + RegSet(CodeBlock) { TargetPC = (uint32_t)-1; JumpPC = (uint32_t)-1; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index d5b722598..27ee78aa5 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -20,13 +19,8 @@ #include #include -CCodeSection * CX86RecompilerOps::m_Section = nullptr; -CRegInfo CX86RecompilerOps::m_RegWorkingSet; -PIPELINE_STAGE CX86RecompilerOps::m_PipelineStage; -uint32_t CX86RecompilerOps::m_CompilePC; -R4300iOpcode CX86RecompilerOps::m_Opcode; -uint32_t CX86RecompilerOps::m_BranchCompare = 0; uint32_t CX86RecompilerOps::m_TempValue32 = 0; +uint32_t CX86RecompilerOps::m_BranchCompare = 0; /*int TestValue = 0; void TestFunc() @@ -181,8 +175,15 @@ static void x86TestWriteBreakpoint64() } } -CX86RecompilerOps::CX86RecompilerOps(CMipsMemoryVM & MMU) : - m_MMU(MMU) +CX86RecompilerOps::CX86RecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock) : + CX86Ops(CodeBlock), + m_MMU(MMU), + m_CodeBlock(CodeBlock), + m_RegWorkingSet(CodeBlock), + m_CompilePC(0), + m_Section(nullptr), + m_RegBeforeDelay(CodeBlock), + m_EffectDelaySlot(false) { } @@ -194,7 +195,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) { if (m_PipelineStage != PIPELINE_STAGE_DELAY_SLOT_DONE) { - CPU_Message(" %X %s", m_CompilePC, R4300iInstruction(m_CompilePC, m_Opcode.Value).NameAndParam().c_str()); + m_CodeBlock.Log(" %X %s", m_CompilePC, R4300iInstruction(m_CompilePC, m_Opcode.Value).NameAndParam().c_str()); } /*if (m_CompilePC == 0x803275F4 && m_PipelineStage == PIPELINE_STAGE_NORMAL) { @@ -347,21 +348,21 @@ void CX86RecompilerOps::CompileReadTLBMiss(uint32_t VirtualAddress, x86Reg LookU { MoveConstToVariable(VirtualAddress, g_TLBLoadAddress, "TLBLoadAddress"); CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBReadMiss, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBReadMiss, false, &CX86Ops::JeLabel32); } void CX86RecompilerOps::CompileReadTLBMiss(x86Reg AddressReg, x86Reg LookUpReg) { MoveX86regToVariable(AddressReg, g_TLBLoadAddress, "TLBLoadAddress"); CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBReadMiss, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBReadMiss, false, &CX86Ops::JeLabel32); } void CX86RecompilerOps::CompileWriteTLBMiss(x86Reg AddressReg, x86Reg LookUpReg) { MoveX86regToVariable(AddressReg, &g_TLBStoreAddress, "g_TLBStoreAddress"); CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBWriteMiss, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::TLBWriteMiss, false, &CX86Ops::JeLabel32); } // Trap functions @@ -462,9 +463,6 @@ void CX86RecompilerOps::Compile_BranchCompare(BRANCH_COMPARE CompareType) void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) { - static CRegInfo RegBeforeDelay; - static bool EffectDelaySlot; - if (m_PipelineStage == PIPELINE_STAGE_NORMAL) { if (CompareType == CompareTypeCOP1BCF || CompareType == CompareTypeCOP1BCT) @@ -483,21 +481,21 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) { g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD)); } - EffectDelaySlot = R4300iInstruction(m_CompilePC, m_Opcode.Value).DelaySlotEffectsCompare(DelaySlot.Value); + m_EffectDelaySlot = R4300iInstruction(m_CompilePC, m_Opcode.Value).DelaySlotEffectsCompare(DelaySlot.Value); } else { - EffectDelaySlot = true; + m_EffectDelaySlot = true; } m_Section->m_Jump.JumpPC = m_CompilePC; m_Section->m_Jump.TargetPC = m_CompilePC + ((int16_t)m_Opcode.offset << 2) + 4; if (m_Section->m_JumpSection != nullptr) { - m_Section->m_Jump.BranchLabel.Format("Section_%d", m_Section->m_JumpSection->m_SectionID); + m_Section->m_Jump.BranchLabel = stdstr_f("Section_%d", m_Section->m_JumpSection->m_SectionID); } else { - m_Section->m_Jump.BranchLabel.Format("Exit_%X_jump_%X", m_Section->m_EnterPC, m_Section->m_Jump.TargetPC); + m_Section->m_Jump.BranchLabel = stdstr_f("Exit_%X_jump_%X", m_Section->m_EnterPC, m_Section->m_Jump.TargetPC); } m_Section->m_Jump.LinkLocation = nullptr; m_Section->m_Jump.LinkLocation2 = nullptr; @@ -506,11 +504,11 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) m_Section->m_Cont.TargetPC = m_CompilePC + 8; if (m_Section->m_ContinueSection != nullptr) { - m_Section->m_Cont.BranchLabel.Format("Section_%d", m_Section->m_ContinueSection->m_SectionID); + m_Section->m_Cont.BranchLabel = stdstr_f("Section_%d", m_Section->m_ContinueSection->m_SectionID); } else { - m_Section->m_Cont.BranchLabel.Format("Exit_%X_continue_%X", m_Section->m_EnterPC, m_Section->m_Cont.TargetPC); + m_Section->m_Cont.BranchLabel = stdstr_f("Exit_%X_continue_%X", m_Section->m_EnterPC, m_Section->m_Cont.TargetPC); } m_Section->m_Cont.LinkLocation = nullptr; m_Section->m_Cont.LinkLocation2 = nullptr; @@ -532,12 +530,12 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) m_RegWorkingSet.SetMipsRegLo(31, m_CompilePC + 8); m_RegWorkingSet.SetMipsRegState(31, CRegInfo::STATE_CONST_32_SIGN); } - if (EffectDelaySlot) + if (m_EffectDelaySlot) { if ((m_CompilePC & 0xFFC) != 0xFFC) { - m_Section->m_Cont.BranchLabel = m_Section->m_ContinueSection != nullptr ? "Continue" : "ExitBlock"; - m_Section->m_Jump.BranchLabel = m_Section->m_JumpSection != nullptr ? "Jump" : "ExitBlock"; + m_Section->m_Cont.BranchLabel = m_Section->m_ContinueSection != nullptr ? "Continue" : stdstr_f("ExitBlock_%X_Continue", m_Section->m_EnterPC); + m_Section->m_Jump.BranchLabel = m_Section->m_JumpSection != nullptr ? "Jump" : stdstr_f("ExitBlock_%X_Jump", m_Section->m_EnterPC); } else { @@ -552,15 +550,15 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) { if (m_Section->m_Jump.LinkLocation != nullptr) { - CPU_Message(""); - CPU_Message(" %s:", m_Section->m_Jump.BranchLabel.c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" %s:", m_Section->m_Jump.BranchLabel.c_str()); LinkJump(m_Section->m_Jump); m_Section->m_Jump.FallThrough = true; } else if (m_Section->m_Cont.LinkLocation != nullptr) { - CPU_Message(""); - CPU_Message(" %s:", m_Section->m_Cont.BranchLabel.c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" %s:", m_Section->m_Cont.BranchLabel.c_str()); LinkJump(m_Section->m_Cont); m_Section->m_Cont.FallThrough = true; } @@ -591,8 +589,8 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) if (DelayLinkLocation != nullptr) { g_Notify->BreakPoint(__FILE__, __LINE__); } DelayLinkLocation = (uint8_t *)(*g_RecompPos - 1); - CPU_Message(" "); - CPU_Message(" %s:", m_Section->m_Jump.BranchLabel.c_str()); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" %s:", m_Section->m_Jump.BranchLabel.c_str()); LinkJump(m_Section->m_Jump); MoveConstToVariable(m_Section->m_Jump.TargetPC, &g_System->m_JumpToLocation, "System::m_JumpToLocation"); } @@ -602,28 +600,28 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) if (DelayLinkLocation != nullptr) { g_Notify->BreakPoint(__FILE__, __LINE__); } DelayLinkLocation = (uint8_t *)(*g_RecompPos - 1); - CPU_Message(" "); - CPU_Message(" %s:", m_Section->m_Cont.BranchLabel.c_str()); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" %s:", m_Section->m_Cont.BranchLabel.c_str()); LinkJump(m_Section->m_Cont); MoveConstToVariable(m_Section->m_Cont.TargetPC, &g_System->m_JumpToLocation, "System::m_JumpToLocation"); } if (DelayLinkLocation) { - CPU_Message(""); - CPU_Message(" DoDelaySlot:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" DoDelaySlot:"); SetJump8(DelayLinkLocation, *g_RecompPos); } OverflowDelaySlot(false); return; } ResetX86Protection(); - RegBeforeDelay = m_RegWorkingSet; + m_RegBeforeDelay = m_RegWorkingSet; } m_PipelineStage = PIPELINE_STAGE_DO_DELAY_SLOT; } else if (m_PipelineStage == PIPELINE_STAGE_DELAY_SLOT_DONE) { - if (EffectDelaySlot) + if (m_EffectDelaySlot) { CJumpInfo * FallInfo = m_Section->m_Jump.FallThrough ? &m_Section->m_Jump : &m_Section->m_Cont; CJumpInfo * JumpInfo = m_Section->m_Jump.FallThrough ? &m_Section->m_Cont : &m_Section->m_Jump; @@ -636,7 +634,7 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) { if (m_Section->m_JumpSection != nullptr) { - m_Section->m_Jump.BranchLabel.Format("Section_%d", m_Section->m_JumpSection->m_SectionID); + m_Section->m_Jump.BranchLabel = stdstr_f("Section_%d", m_Section->m_JumpSection->m_SectionID); } else { @@ -645,7 +643,7 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) if (FallInfo->TargetPC <= m_CompilePC) { UpdateCounters(m_Section->m_Jump.RegSet, true, true, true); - CPU_Message("CompileSystemCheck 12"); + m_CodeBlock.Log("CompileSystemCheck 12"); CompileSystemCheck(FallInfo->TargetPC, m_Section->m_Jump.RegSet); ResetX86Protection(); FallInfo->ExitReason = CExitInfo::Normal_NoSysCheck; @@ -656,11 +654,11 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) { if (m_Section->m_ContinueSection != nullptr) { - m_Section->m_Cont.BranchLabel.Format("Section_%d", m_Section->m_ContinueSection->m_SectionID); + m_Section->m_Cont.BranchLabel = stdstr_f("Section_%d", m_Section->m_ContinueSection->m_SectionID); } else { - m_Section->m_Cont.BranchLabel = "ExitBlock"; + m_Section->m_Cont.BranchLabel = stdstr_f("ExitBlock_%X_Continue", m_Section->m_EnterPC); } } FallInfo->DoneDelaySlot = true; @@ -672,11 +670,11 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) if (JumpInfo->LinkLocation != nullptr) { - CPU_Message(" %s:", JumpInfo->BranchLabel.c_str()); + m_CodeBlock.Log(" %s:", JumpInfo->BranchLabel.c_str()); LinkJump(*JumpInfo); JumpInfo->FallThrough = true; m_PipelineStage = PIPELINE_STAGE_DO_DELAY_SLOT; - m_RegWorkingSet = RegBeforeDelay; + m_RegWorkingSet = m_RegBeforeDelay; return; } } @@ -703,7 +701,7 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, bool Link) } if (m_Section->m_ContinueSection != nullptr) { - m_Section->m_Cont.BranchLabel.Format("Section_%d", m_Section->m_ContinueSection->m_SectionID); + m_Section->m_Cont.BranchLabel = stdstr_f("Section_%d", m_Section->m_ContinueSection->m_SectionID); } else { @@ -756,7 +754,7 @@ void CX86RecompilerOps::Compile_BranchLikely(BRANCH_COMPARE CompareType, bool Li if (m_Section->m_JumpSection != nullptr) { - m_Section->m_Jump.BranchLabel.Format("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); + m_Section->m_Jump.BranchLabel = stdstr_f("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); } else { @@ -765,7 +763,7 @@ void CX86RecompilerOps::Compile_BranchLikely(BRANCH_COMPARE CompareType, bool Li if (m_Section->m_ContinueSection != nullptr) { - m_Section->m_Cont.BranchLabel.Format("Section_%d", ((CCodeSection *)m_Section->m_ContinueSection)->m_SectionID); + m_Section->m_Cont.BranchLabel = stdstr_f("Section_%d", ((CCodeSection *)m_Section->m_ContinueSection)->m_SectionID); } else { @@ -807,8 +805,8 @@ void CX86RecompilerOps::Compile_BranchLikely(BRANCH_COMPARE CompareType, bool Li MoveConstToVariable(m_Section->m_Jump.TargetPC, &g_System->m_JumpToLocation, "System::m_JumpToLocation"); OverflowDelaySlot(false); - CPU_Message(" "); - CPU_Message(" %s:", m_Section->m_Cont.BranchLabel.c_str()); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" %s:", m_Section->m_Cont.BranchLabel.c_str()); } else if (!m_Section->m_Cont.FallThrough) { @@ -912,8 +910,8 @@ void CX86RecompilerOps::BNE_Compare() { JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else @@ -989,8 +987,8 @@ void CX86RecompilerOps::BNE_Compare() { JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else @@ -1100,8 +1098,8 @@ void CX86RecompilerOps::BNE_Compare() if (Jump) { - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } @@ -1161,8 +1159,8 @@ void CX86RecompilerOps::BNE_Compare() m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); if (Jump) { - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } } @@ -1232,8 +1230,8 @@ void CX86RecompilerOps::BEQ_Compare() { JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else if (m_Section->m_Jump.FallThrough) @@ -1308,8 +1306,8 @@ void CX86RecompilerOps::BEQ_Compare() { JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else if (m_Section->m_Jump.FallThrough) @@ -1411,8 +1409,8 @@ void CX86RecompilerOps::BEQ_Compare() m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); if (Jump) { - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } } @@ -1461,8 +1459,8 @@ void CX86RecompilerOps::BEQ_Compare() m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); if (Jump) { - CPU_Message(" "); - CPU_Message(" continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } } @@ -1614,14 +1612,14 @@ void CX86RecompilerOps::BGTZ_Compare() { JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else if (m_Section->m_Cont.FallThrough) { JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else @@ -1747,14 +1745,14 @@ void CX86RecompilerOps::BLEZ_Compare() { JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else if (m_Section->m_Cont.FallThrough) { JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } else @@ -1807,7 +1805,7 @@ void CX86RecompilerOps::BLEZ_Compare() } if (Jump) { - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } } @@ -1817,7 +1815,7 @@ void CX86RecompilerOps::BLEZ_Compare() m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); if (Jump) { - CPU_Message(" continue:"); + m_CodeBlock.Log(" continue:"); SetJump8(Jump, *g_RecompPos); } } @@ -2137,7 +2135,7 @@ void CX86RecompilerOps::J() m_Section->m_Jump.JumpPC = m_CompilePC; if (m_Section->m_JumpSection != nullptr) { - m_Section->m_Jump.BranchLabel.Format("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); + m_Section->m_Jump.BranchLabel = stdstr_f("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); } else { @@ -2178,7 +2176,7 @@ void CX86RecompilerOps::JAL() m_Section->m_Jump.JumpPC = m_CompilePC; if (m_Section->m_JumpSection != nullptr) { - m_Section->m_Jump.BranchLabel.Format("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); + m_Section->m_Jump.BranchLabel = stdstr_f("Section_%d", ((CCodeSection *)m_Section->m_JumpSection)->m_SectionID); } else { @@ -2315,13 +2313,13 @@ void CX86RecompilerOps::SLTIU() SetbVariable(&m_BranchCompare, "m_BranchCompare"); JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), (int16_t)m_Opcode.immediate); SetbVariable(&m_BranchCompare, "m_BranchCompare"); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rt, false, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rt)); @@ -2349,8 +2347,8 @@ void CX86RecompilerOps::SLTIU() JneLabel8("CompareSet", 0); Jump = *g_RecompPos - 1; CompConstToVariable((int16_t)m_Opcode.immediate, &_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs]); - CPU_Message(""); - CPU_Message(" CompareSet:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" CompareSet:"); SetJump8(Jump, *g_RecompPos); SetbVariable(&m_BranchCompare, "m_BranchCompare"); Map_GPR_32bit(m_Opcode.rt, false, -1); @@ -2387,13 +2385,13 @@ void CX86RecompilerOps::SLTI() SetlVariable(&m_BranchCompare, "m_BranchCompare"); JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), (int16_t)m_Opcode.immediate); SetbVariable(&m_BranchCompare, "m_BranchCompare"); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rt, false, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rt)); @@ -2446,15 +2444,15 @@ void CX86RecompilerOps::SLTI() SetlVariable(&m_BranchCompare, "m_BranchCompare"); JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompConstToVariable((int16_t)m_Opcode.immediate, &_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs]); SetbVariable(&m_BranchCompare, "m_BranchCompare"); if (Jump[1]) { - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); } Map_GPR_32bit(m_Opcode.rt, false, -1); @@ -2742,7 +2740,7 @@ void CX86RecompilerOps::LB_KnownAddress(x86Reg Reg, uint32_t VAddr, bool SignExt if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { MoveConstToX86reg(0, Reg); - CPU_Message("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -2866,7 +2864,7 @@ void CX86RecompilerOps::LH_KnownAddress(x86Reg Reg, uint32_t VAddr, bool SignExt if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { MoveConstToX86reg(0, Reg); - CPU_Message("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -3466,7 +3464,7 @@ void CX86RecompilerOps::SB() if (IsConst(m_Opcode.rt)) { - SB_Const((uint8_t)(GetMipsRegLo(m_Opcode.rt) & 0xFF), Address); + SB_Const(GetMipsRegLo(m_Opcode.rt), Address); } else if (IsMapped(m_Opcode.rt) && Is8BitReg(GetMipsRegMapLo(m_Opcode.rt))) { @@ -3510,7 +3508,7 @@ void CX86RecompilerOps::SH() if (IsConst(m_Opcode.rt)) { - SH_Const((uint16_t)(GetMipsRegLo(m_Opcode.rt) & 0xFFFF), Address); + SH_Const(GetMipsRegLo(m_Opcode.rt), Address); } else if (IsMapped(m_Opcode.rt)) { @@ -3578,8 +3576,8 @@ void CX86RecompilerOps::SWL() MoveVariableDispToX86Reg(g_MMU->m_TLB_ReadMap, "MMU->TLB_ReadMap", TempReg2, TempReg2, 4); CompileReadTLBMiss(AddressReg, TempReg2); AddConstToX86Reg(TempReg2, (uint32_t)m_MMU.Rdram()); - CPU_Message(""); - CPU_Message(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); SetJump8(JumpFound, *g_RecompPos); MoveX86RegToX86Reg(AddressReg, OffsetReg); AndConstToX86Reg(OffsetReg, 3); @@ -3694,8 +3692,8 @@ void CX86RecompilerOps::SW(bool bCheckLLbit) CompileStoreMemoryValue(x86_Unknown, ValueReg, x86_Unknown, GetMipsRegLo(m_Opcode.rt), 32); if (bCheckLLbit) { - CPU_Message(" "); - CPU_Message(" LLBit_Continue:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" LLBit_Continue:"); SetJump8(JumpLLBit, *g_RecompPos); Map_GPR_32bit(m_Opcode.rt, false, -1); MoveVariableToX86reg(_LLBit, "_LLBit", GetMipsRegMapLo(m_Opcode.rt)); @@ -3742,8 +3740,8 @@ void CX86RecompilerOps::SWR() MoveVariableDispToX86Reg(g_MMU->m_TLB_ReadMap, "MMU->TLB_ReadMap", TempReg2, TempReg2, 4); CompileReadTLBMiss(AddressReg, TempReg2); AddConstToX86Reg(TempReg2, (uint32_t)m_MMU.Rdram()); - CPU_Message(""); - CPU_Message(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); SetJump8(JumpFound, *g_RecompPos); MoveX86RegToX86Reg(AddressReg, OffsetReg); @@ -4601,8 +4599,8 @@ void CX86RecompilerOps::SPECIAL_DSLLV() Jump[1] = *g_RecompPos - 1; // MORE32: - CPU_Message(""); - CPU_Message(" MORE32:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" MORE32:"); SetJump8(Jump[0], *g_RecompPos); MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); @@ -4610,8 +4608,8 @@ void CX86RecompilerOps::SPECIAL_DSLLV() ShiftLeftSign(GetMipsRegMapHi(m_Opcode.rd)); // Continue: - CPU_Message(""); - CPU_Message(" continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" continue:"); SetJump8(Jump[1], *g_RecompPos); } @@ -4686,8 +4684,8 @@ void CX86RecompilerOps::SPECIAL_DSRLV() Jump[1] = *g_RecompPos - 1; // MORE32: - CPU_Message(""); - CPU_Message(" MORE32:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" MORE32:"); SetJump8(Jump[0], *g_RecompPos); MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); XorX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); @@ -4695,8 +4693,8 @@ void CX86RecompilerOps::SPECIAL_DSRLV() ShiftRightUnsign(GetMipsRegMapLo(m_Opcode.rd)); // Continue: - CPU_Message(""); - CPU_Message(" continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" continue:"); SetJump8(Jump[1], *g_RecompPos); } } @@ -4728,8 +4726,8 @@ void CX86RecompilerOps::SPECIAL_DSRAV() Jump[1] = *g_RecompPos - 1; // MORE32: - CPU_Message(""); - CPU_Message(" MORE32:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" MORE32:"); SetJump8(Jump[0], *g_RecompPos); MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); ShiftRightSignImmed(GetMipsRegMapHi(m_Opcode.rd), 0x1F); @@ -4737,8 +4735,8 @@ void CX86RecompilerOps::SPECIAL_DSRAV() ShiftRightSign(GetMipsRegMapLo(m_Opcode.rd)); // Continue: - CPU_Message(""); - CPU_Message(" continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" continue:"); SetJump8(Jump[1], *g_RecompPos); } @@ -4799,7 +4797,7 @@ void CX86RecompilerOps::SPECIAL_DIV() { CompConstToVariable(0, &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); } - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::DivByZero, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::DivByZero, false, &CX86Ops::JeLabel32); } /* lo = (SD)rs / (SD)rt; hi = (SD)rs % (SD)rt; */ @@ -4869,8 +4867,8 @@ void CX86RecompilerOps::SPECIAL_DIVU() JmpLabel8("EndDivu", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" NoExcept:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" NoExcept:"); SetJump8(Jump[0], *g_RecompPos); } @@ -4898,8 +4896,8 @@ void CX86RecompilerOps::SPECIAL_DIVU() if (Jump[1] != nullptr) { - CPU_Message(""); - CPU_Message(" EndDivu:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" EndDivu:"); SetJump8(Jump[1], *g_RecompPos); } } @@ -5947,13 +5945,13 @@ void CX86RecompilerOps::SPECIAL_SLT() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); SetbVariable(&m_BranchCompare, "m_BranchCompare"); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rd, true, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rd)); @@ -6002,8 +6000,8 @@ void CX86RecompilerOps::SPECIAL_SLT() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (MappedReg == m_Opcode.rs) @@ -6014,8 +6012,8 @@ void CX86RecompilerOps::SPECIAL_SLT() { SetaVariable(&m_BranchCompare, "m_BranchCompare"); } - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rd, true, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rd)); @@ -6097,8 +6095,8 @@ void CX86RecompilerOps::SPECIAL_SLT() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); if (IsConst(KnownReg)) { @@ -6115,8 +6113,8 @@ void CX86RecompilerOps::SPECIAL_SLT() { SetbVariable(&m_BranchCompare, "m_BranchCompare"); } - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rd, true, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rd)); @@ -6193,15 +6191,15 @@ void CX86RecompilerOps::SPECIAL_SLT() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompX86regToVariable(Map_TempReg(Reg, m_Opcode.rs, false), &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); SetbVariable(&m_BranchCompare, "m_BranchCompare"); if (Jump[1]) { - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); } Map_GPR_32bit(m_Opcode.rd, true, -1); @@ -6262,13 +6260,13 @@ void CX86RecompilerOps::SPECIAL_SLTU() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); SetbVariable(&m_BranchCompare, "m_BranchCompare"); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rd, true, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rd)); @@ -6319,8 +6317,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompConstToX86reg(MappedRegLo, ConstLo); if (MappedReg == m_Opcode.rs) @@ -6331,8 +6329,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() { SetaVariable(&m_BranchCompare, "m_BranchCompare"); } - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); Map_GPR_32bit(m_Opcode.rd, true, -1); MoveVariableToX86reg(&m_BranchCompare, "m_BranchCompare", GetMipsRegMapLo(m_Opcode.rd)); @@ -6424,8 +6422,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); if (IsConst(KnownReg)) { @@ -6445,8 +6443,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() } if (Jump[1]) { - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); } } @@ -6473,15 +6471,15 @@ void CX86RecompilerOps::SPECIAL_SLTU() JmpLabel8("Continue", 0); Jump[1] = *g_RecompPos - 1; - CPU_Message(""); - CPU_Message(" Low Compare:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Low Compare:"); SetJump8(Jump[0], *g_RecompPos); CompX86regToVariable(Map_TempReg(Reg, m_Opcode.rs, false), &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); SetbVariable(&m_BranchCompare, "m_BranchCompare"); if (Jump[1]) { - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump[1], *g_RecompPos); } Map_GPR_32bit(m_Opcode.rd, true, -1); @@ -6879,7 +6877,7 @@ void CX86RecompilerOps::SPECIAL_DSLL32() } else { - CPU_Message(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); + m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); x86Reg HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); @@ -6921,7 +6919,7 @@ void CX86RecompilerOps::SPECIAL_DSRL32() { if (m_Opcode.rt == m_Opcode.rd) { - CPU_Message(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); + m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); x86Reg HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); @@ -6971,7 +6969,7 @@ void CX86RecompilerOps::SPECIAL_DSRA32() { if (m_Opcode.rt == m_Opcode.rd) { - CPU_Message(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); + m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", x86_Name(GetMipsRegMapHi(m_Opcode.rt)), x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); x86Reg HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); @@ -8261,7 +8259,7 @@ void CX86RecompilerOps::COP1_L_CVT_D() // Other functions void CX86RecompilerOps::UnknownOpcode() { - CPU_Message(" %X Unhandled opcode: %s", m_CompilePC, R4300iInstruction(m_CompilePC, m_Opcode.Value).NameAndParam().c_str()); + m_CodeBlock.Log(" %X Unhandled opcode: %s", m_CompilePC, R4300iInstruction(m_CompilePC, m_Opcode.Value).NameAndParam().c_str()); m_RegWorkingSet.WriteBackRegisters(); UpdateCounters(m_RegWorkingSet, false, true); @@ -8342,8 +8340,8 @@ void CX86RecompilerOps::TestBreakpoint(x86Reg AddressReg, void * FunctAddress, c uint8_t * Jump = *g_RecompPos - 1; MoveConstToVariable(0, &memory_breakpoint_found, "memory_breakpoint_found"); ExitCodeBlock(); - CPU_Message(" "); - CPU_Message(" NoBreakPoint:"); + m_CodeBlock.Log(" "); + m_CodeBlock.Log(" NoBreakPoint:"); SetJump8(Jump, *g_RecompPos); } @@ -8403,8 +8401,8 @@ void CX86RecompilerOps::CompileExitCode() { for (EXIT_LIST::iterator ExitIter = m_ExitInfo.begin(); ExitIter != m_ExitInfo.end(); ExitIter++) { - CPU_Message(""); - CPU_Message(" $%s", ExitIter->Name.c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" $%s", ExitIter->Name.c_str()); SetJump32(ExitIter->JumpLoc, (uint32_t *)*g_RecompPos); m_PipelineStage = ExitIter->PipelineStage; CompileExit((uint32_t)-1, ExitIter->TargetPC, ExitIter->ExitRegSet, ExitIter->reason, true, nullptr); @@ -8421,7 +8419,7 @@ void CX86RecompilerOps::CompileCop1Test() TestVariable(STATUS_CU1, &g_Reg->STATUS_REGISTER, "STATUS_REGISTER"); CRegInfo ExitRegSet = m_RegWorkingSet; ExitRegSet.SetBlockCycleCount(ExitRegSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, ExitRegSet, CExitInfo::COP1_Unuseable, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, ExitRegSet, CExitInfo::COP1_Unuseable, false, &CX86Ops::JeLabel32); m_RegWorkingSet.SetFpuBeenUsed(true); } @@ -8439,7 +8437,7 @@ void CX86RecompilerOps::CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCou Call_Direct(AddressOf(&CSystemTimer::TimerDone), "CSystemTimer::TimerDone"); AddConstToX86Reg(x86_ESP, 4); #endif - CPU_Message("CompileSystemCheck 3"); + m_CodeBlock.Log("CompileSystemCheck 3"); CompileSystemCheck((uint32_t)-1, RegSet); if (g_SyncSystem) { @@ -8454,7 +8452,7 @@ void CX86RecompilerOps::CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCou } } -bool CX86RecompilerOps::SetupRegisterForLoop(CCodeBlock * BlockInfo, const CRegInfo & RegSet) +bool CX86RecompilerOps::SetupRegisterForLoop(CCodeBlock & BlockInfo, const CRegInfo & RegSet) { CRegInfo OriginalReg = m_RegWorkingSet; if (!LoopAnalysis(BlockInfo, m_Section).SetupRegisterForLoop()) @@ -8481,7 +8479,7 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) x86Reg MemStackReg = Get_MemoryStack(); x86Reg TargetStackReg = SyncTo.Get_MemoryStack(); - //CPU_Message("MemoryStack for Original State = %s",MemStackReg > 0?x86_Name(MemStackReg):"Not Mapped"); + //m_CodeBlock.Log("MemoryStack for Original State = %s",MemStackReg > 0?x86_Name(MemStackReg):"Not Mapped"); if (MemStackReg != TargetStackReg) { if (TargetStackReg == x86_Unknown) @@ -8491,14 +8489,14 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) else if (MemStackReg == x86_Unknown) { UnMap_X86reg(TargetStackReg); - CPU_Message(" regcache: allocate %s as memory stack", x86_Name(TargetStackReg)); + m_CodeBlock.Log(" regcache: allocate %s as memory stack", x86_Name(TargetStackReg)); m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", TargetStackReg); } else { UnMap_X86reg(TargetStackReg); - CPU_Message(" regcache: change allocation of memory stack from %s to %s", x86_Name(MemStackReg), x86_Name(TargetStackReg)); + m_CodeBlock.Log(" regcache: change allocation of memory stack from %s to %s", x86_Name(MemStackReg), x86_Name(TargetStackReg)); m_RegWorkingSet.SetX86Mapped(TargetStackReg, CRegInfo::Stack_Mapped); m_RegWorkingSet.SetX86Mapped(MemStackReg, CRegInfo::NotMapped); MoveX86RegToX86Reg(MemStackReg, TargetStackReg); @@ -8511,7 +8509,8 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN) || (g_System->b32BitCore() && GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_SIGN && SyncTo.GetMipsRegState(i) == CRegInfo::STATE_MAPPED_32_ZERO)) { - switch (GetMipsRegState(i)) { + switch (GetMipsRegState(i)) + { case CRegInfo::STATE_UNKNOWN: continue; case CRegInfo::STATE_MAPPED_64: if (GetMipsRegMapHi(i) == SyncTo.GetMipsRegMapHi(i) && @@ -8536,12 +8535,12 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) case CRegInfo::STATE_CONST_32_SIGN: if (GetMipsRegLo(i) != SyncTo.GetMipsRegLo(i)) { - CPU_Message("Value of constant is different register %d (%s) Value: 0x%08X to 0x%08X", i, CRegName::GPR[i], GetMipsRegLo(i), SyncTo.GetMipsRegLo(i)); + m_CodeBlock.Log("Value of constant is different register %d (%s) Value: 0x%08X to 0x%08X", i, CRegName::GPR[i], GetMipsRegLo(i), SyncTo.GetMipsRegLo(i)); g_Notify->BreakPoint(__FILE__, __LINE__); } continue; default: - CPU_Message("Unhandled register state %d\nin SyncRegState", GetMipsRegState(i)); + m_CodeBlock.Log("Unhandled register state %d\nin SyncRegState", GetMipsRegState(i)); g_Notify->BreakPoint(__FILE__, __LINE__); } } @@ -8551,139 +8550,139 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) { case CRegInfo::STATE_UNKNOWN: UnMap_GPR(i, true); break; case CRegInfo::STATE_MAPPED_64: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - x86Reg x86RegHi = SyncTo.GetMipsRegMapHi(i); - UnMap_X86reg(Reg); - UnMap_X86reg(x86RegHi); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_UNKNOWN: - MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); - MoveVariableToX86reg(&_GPR[i].UW[1], CRegName::GPR_Hi[i], x86RegHi); - break; - case CRegInfo::STATE_MAPPED_64: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - MoveX86RegToX86Reg(GetMipsRegMapHi(i), x86RegHi); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), x86RegHi); - ShiftRightSignImmed(x86RegHi, 31); - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - XorX86RegToX86Reg(x86RegHi, x86RegHi); - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_CONST_64: - MoveConstToX86reg(GetMipsRegHi(i), x86RegHi); - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - case CRegInfo::STATE_CONST_32_SIGN: - MoveConstToX86reg(GetMipsRegLo_S(i) >> 31, x86RegHi); - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILE__, __LINE__); - continue; - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegMapHi(i, x86RegHi); - m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_64); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86Mapped(x86RegHi, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - m_RegWorkingSet.SetX86MapOrder(x86RegHi, 1); - } + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + x86Reg x86RegHi = SyncTo.GetMipsRegMapHi(i); + UnMap_X86reg(Reg); + UnMap_X86reg(x86RegHi); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_UNKNOWN: + MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); + MoveVariableToX86reg(&_GPR[i].UW[1], CRegName::GPR_Hi[i], x86RegHi); + break; + case CRegInfo::STATE_MAPPED_64: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + MoveX86RegToX86Reg(GetMipsRegMapHi(i), x86RegHi); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), x86RegHi); + ShiftRightSignImmed(x86RegHi, 31); + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + XorX86RegToX86Reg(x86RegHi, x86RegHi); + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_CONST_64: + MoveConstToX86reg(GetMipsRegHi(i), x86RegHi); + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + case CRegInfo::STATE_CONST_32_SIGN: + MoveConstToX86reg(GetMipsRegLo_S(i) >> 31, x86RegHi); + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + default: + m_CodeBlock.Log("Do something with states in SyncRegState\nSTATE_MAPPED_64\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILE__, __LINE__); + continue; + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegMapHi(i, x86RegHi); + m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_64); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86Mapped(x86RegHi, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + m_RegWorkingSet.SetX86MapOrder(x86RegHi, 1); + } break; case CRegInfo::STATE_MAPPED_32_SIGN: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - UnMap_X86reg(Reg); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); break; - case CRegInfo::STATE_CONST_32_SIGN: MoveConstToX86reg(GetMipsRegLo(i), Reg); break; - case CRegInfo::STATE_MAPPED_32_SIGN: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - if (GetMipsRegMapLo(i) != Reg) - { - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - } - break; - case CRegInfo::STATE_MAPPED_64: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_CONST_64: - CPU_Message("hi %X\nLo %X", GetMipsRegHi(i), GetMipsRegLo(i)); - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILE__, __LINE__); - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_32_SIGN); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - } + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + UnMap_X86reg(Reg); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_UNKNOWN: MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); break; + case CRegInfo::STATE_CONST_32_SIGN: MoveConstToX86reg(GetMipsRegLo(i), Reg); break; + case CRegInfo::STATE_MAPPED_32_SIGN: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + if (GetMipsRegMapLo(i) != Reg) + { + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + } + break; + case CRegInfo::STATE_MAPPED_64: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapHi(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_CONST_64: + m_CodeBlock.Log("hi %X\nLo %X", GetMipsRegHi(i), GetMipsRegLo(i)); + default: + m_CodeBlock.Log("Do something with states in SyncRegState\nSTATE_MAPPED_32_SIGN\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILE__, __LINE__); + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegState(i, CRegInfo::STATE_MAPPED_32_SIGN); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + } break; case CRegInfo::STATE_MAPPED_32_ZERO: - { - x86Reg Reg = SyncTo.GetMipsRegMapLo(i); - UnMap_X86reg(Reg); - switch (GetMipsRegState(i)) - { - case CRegInfo::STATE_MAPPED_64: - case CRegInfo::STATE_UNKNOWN: - MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); - break; - case CRegInfo::STATE_MAPPED_32_ZERO: - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - break; - case CRegInfo::STATE_MAPPED_32_SIGN: - if (g_System->b32BitCore()) - { - MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); - m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); - } - else - { - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILE__, __LINE__); - } - break; - case CRegInfo::STATE_CONST_32_SIGN: - if (!g_System->b32BitCore() && GetMipsRegLo_S(i) < 0) - { - CPU_Message("Sign problems in SyncRegState\nSTATE_MAPPED_32_ZERO"); - CPU_Message("%s: %X", CRegName::GPR[i], GetMipsRegLo_S(i)); - g_Notify->BreakPoint(__FILE__, __LINE__); - } - MoveConstToX86reg(GetMipsRegLo(i), Reg); - break; - default: - CPU_Message("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); - g_Notify->BreakPoint(__FILE__, __LINE__); - } - m_RegWorkingSet.SetMipsRegMapLo(i, Reg); - m_RegWorkingSet.SetMipsRegState(i, SyncTo.GetMipsRegState(i)); - m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); - m_RegWorkingSet.SetX86MapOrder(Reg, 1); - } + { + x86Reg Reg = SyncTo.GetMipsRegMapLo(i); + UnMap_X86reg(Reg); + switch (GetMipsRegState(i)) + { + case CRegInfo::STATE_MAPPED_64: + case CRegInfo::STATE_UNKNOWN: + MoveVariableToX86reg(&_GPR[i].UW[0], CRegName::GPR_Lo[i], Reg); + break; + case CRegInfo::STATE_MAPPED_32_ZERO: + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + break; + case CRegInfo::STATE_MAPPED_32_SIGN: + if (g_System->b32BitCore()) + { + MoveX86RegToX86Reg(GetMipsRegMapLo(i), Reg); + m_RegWorkingSet.SetX86Mapped(GetMipsRegMapLo(i), CRegInfo::NotMapped); + } + else + { + m_CodeBlock.Log("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILE__, __LINE__); + } + break; + case CRegInfo::STATE_CONST_32_SIGN: + if (!g_System->b32BitCore() && GetMipsRegLo_S(i) < 0) + { + m_CodeBlock.Log("Sign problems in SyncRegState\nSTATE_MAPPED_32_ZERO"); + m_CodeBlock.Log("%s: %X", CRegName::GPR[i], GetMipsRegLo_S(i)); + g_Notify->BreakPoint(__FILE__, __LINE__); + } + MoveConstToX86reg(GetMipsRegLo(i), Reg); + break; + default: + m_CodeBlock.Log("Do something with states in SyncRegState\nSTATE_MAPPED_32_ZERO\n%d", GetMipsRegState(i)); + g_Notify->BreakPoint(__FILE__, __LINE__); + } + m_RegWorkingSet.SetMipsRegMapLo(i, Reg); + m_RegWorkingSet.SetMipsRegState(i, SyncTo.GetMipsRegState(i)); + m_RegWorkingSet.SetX86Mapped(Reg, CRegInfo::GPR_Mapped); + m_RegWorkingSet.SetX86MapOrder(Reg, 1); + } break; default: - CPU_Message("%d - %d reg: %s (%d)", SyncTo.GetMipsRegState(i), GetMipsRegState(i), CRegName::GPR[i], i); + m_CodeBlock.Log("%d - %d reg: %s (%d)", SyncTo.GetMipsRegState(i), GetMipsRegState(i), CRegName::GPR[i], i); g_Notify->BreakPoint(__FILE__, __LINE__); changed = false; } @@ -8835,7 +8834,7 @@ bool CX86RecompilerOps::InheritParentInfo() } if (m_Section->m_EnterPC <= JumpInfo->JumpPC) { - CPU_Message("CompileSystemCheck 10"); + m_CodeBlock.Log("CompileSystemCheck 10"); CompileSystemCheck(m_Section->m_EnterPC, GetRegWorkingSet()); } } @@ -8847,7 +8846,7 @@ bool CX86RecompilerOps::InheritParentInfo() // Determine loop registry usage if (m_Section->m_InLoop && ParentList.size() > 1) { - if (!SetupRegisterForLoop(m_Section->m_BlockInfo, m_Section->m_RegEnter)) { return false; } + if (!SetupRegisterForLoop(m_Section->m_CodeBlock, m_Section->m_RegEnter)) { return false; } m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } @@ -8920,7 +8919,7 @@ bool CX86RecompilerOps::InheritParentInfo() } break; default: - CPU_Message("Unknown CPU state(%d) in InheritParentInfo", GetMipsRegState(i2)); + m_CodeBlock.Log("Unknown CPU state(%d) in InheritParentInfo", GetMipsRegState(i2)); g_Notify->BreakPoint(__FILE__, __LINE__); } } @@ -8963,7 +8962,7 @@ bool CX86RecompilerOps::InheritParentInfo() } break; default: - CPU_Message("Unknown CPU state(%d) in InheritParentInfo", RegSet->GetMipsRegState(i2)); + m_CodeBlock.Log("Unknown CPU state(%d) in InheritParentInfo", RegSet->GetMipsRegState(i2)); g_Notify->BreakPoint(__FILE__, __LINE__); break; } @@ -9070,7 +9069,7 @@ bool CX86RecompilerOps::InheritParentInfo() CurrentParent = i; Parent = ParentList[CurrentParent].Parent; JumpInfo = ParentList[CurrentParent].JumpInfo; - CPU_Message(" Section_%d (from %d):", m_Section->m_SectionID, Parent->m_SectionID); + m_CodeBlock.Log(" Section_%d (from %d):", m_Section->m_SectionID, Parent->m_SectionID); if (JumpInfo->LinkLocation != nullptr) { SetJump32(JumpInfo->LinkLocation, (uint32_t *)*g_RecompPos); @@ -9086,7 +9085,7 @@ bool CX86RecompilerOps::InheritParentInfo() if (m_Section->m_EnterPC < JumpInfo->JumpPC) { UpdateCounters(m_RegWorkingSet, true, true); - CPU_Message("CompileSystemCheck 11"); + m_CodeBlock.Log("CompileSystemCheck 11"); CompileSystemCheck(m_Section->m_EnterPC, m_RegWorkingSet); } else @@ -9104,7 +9103,7 @@ bool CX86RecompilerOps::InheritParentInfo() LinkJump(*JumpInfo); } - CPU_Message(" Section_%d:", m_Section->m_SectionID); + m_CodeBlock.Log(" Section_%d:", m_Section->m_SectionID); m_Section->m_RegEnter.SetBlockCycleCount(0); return true; } @@ -9117,11 +9116,11 @@ void CX86RecompilerOps::LinkJump(CJumpInfo & JumpInfo, uint32_t SectionID, uint3 { if (FromSectionID != -1) { - CPU_Message(" Section_%d (from %d):", SectionID, FromSectionID); + m_CodeBlock.Log(" Section_%d (from %d):", SectionID, FromSectionID); } else { - CPU_Message(" Section_%d:", SectionID); + m_CodeBlock.Log(" Section_%d:", SectionID); } } SetJump32(JumpInfo.LinkLocation, (uint32_t *)*g_RecompPos); @@ -9243,8 +9242,8 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool #endif RegSet.AfterCallDirect(); - CPU_Message(""); - CPU_Message(" $Continue_From_Timer_Test:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" $Continue_From_Timer_Test:"); SetJump8(Jump, *g_RecompPos); } @@ -9285,8 +9284,8 @@ void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & R AddConstToX86Reg(x86_ESP, 4); #endif ExitCodeBlock(); - CPU_Message(""); - CPU_Message(" $Continue_From_Interrupt_Test:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" $Continue_From_Interrupt_Test:"); SetJump32(Jump, (uint32_t *)*g_RecompPos); } @@ -9399,7 +9398,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo CompileExit(JumpPC, TargetPC, ExitRegSet, reason, true, nullptr); } -void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(*x86Jmp)(const char * Label, uint32_t Value)) +void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow, void(CX86Ops::*x86Jmp)(const char * Label, uint32_t Value)) { if (!CompileNow) { @@ -9409,8 +9408,8 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo return; } stdstr_f ExitName("Exit_%08X_%d", JumpPC, m_ExitInfo.size()); - x86Jmp(ExitName.c_str(), 0); - CExitInfo ExitInfo; + (this->*x86Jmp)(ExitName.c_str(), 0); + CExitInfo ExitInfo(m_CodeBlock); ExitInfo.ID = m_ExitInfo.size(); ExitInfo.Name = ExitName; ExitInfo.TargetPC = TargetPC; @@ -9422,7 +9421,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo return; } - //CPU_Message("CompileExit: %d",reason); + //m_CodeBlock.Log("CompileExit: %d",reason); ExitRegSet.WriteBackRegisters(); if (TargetPC != (uint32_t)-1) @@ -9444,7 +9443,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo { if (TargetPC <= JumpPC && reason == CExitInfo::Normal) { - CPU_Message("CompileSystemCheck 1"); + m_CodeBlock.Log("CompileSystemCheck 1"); CompileSystemCheck((uint32_t)-1, ExitRegSet); } } @@ -9452,7 +9451,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo { if (reason == CExitInfo::Normal) { - CPU_Message("CompileSystemCheck 2"); + m_CodeBlock.Log("CompileSystemCheck 2"); CompileSystemCheck((uint32_t)-1, ExitRegSet); } } @@ -9498,10 +9497,10 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo // AddConstToX86Reg(x86_EAX,0xC); // MoveVariableDispToX86Reg(OrigMem,"OrigMem",x86_ECX,x86_EAX,1); // JmpDirectReg(x86_ECX); - // CPU_Message(" NoCode:"); + // m_CodeBlock.Log(" NoCode:"); // *((uint8_t *)(Jump))=(uint8_t)(*g_RecompPos - Jump - 1); // if (Jump2 != nullptr) { - // CPU_Message(" NoTlbEntry:"); + // m_CodeBlock.Log(" NoTlbEntry:"); // *((uint8_t *)(Jump2))=(uint8_t)(*g_RecompPos - Jump2 - 1); // } } @@ -9515,7 +9514,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo uint8_t * Jump = *g_RecompPos - 1; MoveX86PointerToX86regDisp(x86_EBX, x86_ECX, 0xC); JmpDirectReg(x86_EBX); - CPU_Message(" NullPointer:"); + m_CodeBlock.Log(" NullPointer:"); *((uint8_t *)(Jump)) = (uint8_t)(*g_RecompPos - Jump - 1); } else if (LookUpMode() == FuncFind_PhysicalLookup) @@ -9546,11 +9545,11 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo uint8_t * Jump = *g_RecompPos - 1; MoveX86PointerToX86regDisp(x86_EAX, x86_ECX, 0xC); JmpDirectReg(x86_EAX); - CPU_Message(" NullPointer:"); + m_CodeBlock.Log(" NullPointer:"); *((uint8_t *)(Jump)) = (uint8_t)(*g_RecompPos - Jump - 1); if (Jump2 != nullptr) { - CPU_Message(" NoTlbEntry:"); + m_CodeBlock.Log(" NoTlbEntry:"); *((uint8_t *)(Jump2)) = (uint8_t)(*g_RecompPos - Jump2 - 1); } } @@ -9732,7 +9731,7 @@ void CX86RecompilerOps::CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86O #endif TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); MoveConstToX86reg((uint32_t)&m_TempValue32, TempReg); SubX86RegToX86Reg(TempReg, AddressReg); } @@ -9751,7 +9750,7 @@ void CX86RecompilerOps::CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86O #endif TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); MoveConstToX86reg((uint32_t)&m_TempValue32, TempReg); SubX86RegToX86Reg(TempReg, AddressReg); XorConstToX86Reg(AddressReg, 2); @@ -9771,7 +9770,7 @@ void CX86RecompilerOps::CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86O #endif TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); MoveConstToX86reg((uint32_t)&m_TempValue32, TempReg); SubX86RegToX86Reg(TempReg, AddressReg); XorConstToX86Reg(AddressReg, 3); @@ -9784,8 +9783,8 @@ void CX86RecompilerOps::CompileLoadMemoryValue(CX86Ops::x86Reg AddressReg, CX86O { AddConstToVariable(OpsExecuted, g_NextTimer, "g_NextTimer"); } - CPU_Message(""); - CPU_Message(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); SetJump8(JumpFound, *g_RecompPos); if (ValueSize == 8) @@ -9905,7 +9904,7 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 m_RegWorkingSet.BeforeCallDirect(); if (ValueReg == x86_Unknown) { - PushImm32((uint32_t)(Value & 0xFF)); + PushImm32((uint32_t)Value); } else { @@ -9926,7 +9925,7 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 } TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); } @@ -9956,7 +9955,7 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 } TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); } @@ -9986,7 +9985,7 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 } TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); } @@ -10018,7 +10017,7 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 } TestX86ByteRegToX86Reg(x86_AL, x86_AL); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, CExitInfo::Normal_NoSysCheck, false, &CX86Ops::JeLabel32); JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); } @@ -10031,8 +10030,8 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 CompileWriteTLBMiss(AddressReg, TempReg); AddConstToX86Reg(TempReg, (uint32_t)m_MMU.Rdram()); } - CPU_Message(""); - CPU_Message(stdstr_f(" MemoryWriteMap_%X_Found:", m_CompilePC).c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(stdstr_f(" MemoryWriteMap_%X_Found:", m_CompilePC).c_str()); SetJump8(JumpFound, *g_RecompPos); if (ValueSize == 8) @@ -10096,13 +10095,13 @@ void CX86RecompilerOps::CompileStoreMemoryValue(CX86Ops::x86Reg AddressReg, CX86 if (MemoryWriteDone != nullptr) { - CPU_Message(""); - CPU_Message(stdstr_f(" MemoryWrite_%X_Done:", m_CompilePC).c_str()); + m_CodeBlock.Log(""); + m_CodeBlock.Log(stdstr_f(" MemoryWrite_%X_Done:", m_CompilePC).c_str()); SetJump8(MemoryWriteDone, *g_RecompPos); } } -void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) +void CX86RecompilerOps::SB_Const(uint32_t Value, uint32_t VAddr) { if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { @@ -10115,7 +10114,7 @@ void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) uint32_t PAddr; if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10141,17 +10140,17 @@ void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) } else if (PAddr < g_MMU->RdramSize()) { - MoveConstByteToVariable(Value, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); + MoveConstByteToVariable((uint8_t)Value, (PAddr ^ 3) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 3)", PAddr).c_str()); } break; case 0x04000000: if (PAddr < 0x04001000) { - MoveConstByteToVariable(Value, ((PAddr - 0x04000000) ^ 3) + g_MMU->Dmem(), stdstr_f("DMem + (%X ^ 3)", (PAddr - 0x04000000)).c_str()); + MoveConstByteToVariable((uint8_t)Value, ((PAddr - 0x04000000) ^ 3) + g_MMU->Dmem(), stdstr_f("DMem + (%X ^ 3)", (PAddr - 0x04000000)).c_str()); } else if (PAddr < 0x04002000) { - MoveConstByteToVariable(Value, ((PAddr - 0x04001000) ^ 3) + g_MMU->Imem(), stdstr_f("Imem + (%X ^ 3)", (PAddr - 0x04001000)).c_str()); + MoveConstByteToVariable((uint8_t)Value, ((PAddr - 0x04001000) ^ 3) + g_MMU->Imem(), stdstr_f("Imem + (%X ^ 3)", (PAddr - 0x04001000)).c_str()); } else { @@ -10162,7 +10161,23 @@ void CX86RecompilerOps::SB_Const(uint8_t Value, uint32_t VAddr) } break; default: - if (BreakOnUnhandledMemory()) + if (PAddr >= 0x10000000 && PAddr < 0x20000000) + { + m_RegWorkingSet.BeforeCallDirect(); + PushImm32(0xFFFFFFFF); + PushImm32(Value << ((3 - (PAddr & 3)) * 8)); + PushImm32(PAddr); +#ifdef _MSC_VER + MoveConstToX86reg((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, x86_ECX); + Call_Direct((void *)((long**)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32"); +#else + PushImm32((uint32_t)&g_MMU->m_RomMemoryHandler); + Call_Direct(AddressOf(&RomMemoryHandler::Write32), "RomMemoryHandler::Write32"); + AddConstToX86Reg(x86_ESP, 16); +#endif + m_RegWorkingSet.AfterCallDirect(); + } + else if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -10183,7 +10198,7 @@ void CX86RecompilerOps::SB_Register(x86Reg Reg, uint32_t VAddr) uint32_t PAddr; if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10220,20 +10235,20 @@ void CX86RecompilerOps::SB_Register(x86Reg Reg, uint32_t VAddr) } } -void CX86RecompilerOps::SH_Const(uint16_t Value, uint32_t VAddr) +void CX86RecompilerOps::SH_Const(uint32_t Value, uint32_t VAddr) { if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); MoveConstToX86reg(VAddr, AddressReg); - CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, Value, 16); + CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, (uint16_t)Value, 16); return; } uint32_t PAddr; if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10255,15 +10270,31 @@ void CX86RecompilerOps::SH_Const(uint16_t Value, uint32_t VAddr) { x86Reg AddressReg = Map_TempReg(x86_Any, -1, false); MoveConstToX86reg(VAddr, AddressReg); - CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, Value, 16); + CompileStoreMemoryValue(AddressReg, x86_Unknown, x86_Unknown, (uint16_t)Value, 16); } else if (PAddr < g_MMU->RdramSize()) { - MoveConstHalfToVariable(Value, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); + MoveConstHalfToVariable((uint16_t)Value, (PAddr ^ 2) + g_MMU->Rdram(), stdstr_f("RDRAM + (%X ^ 2)", PAddr).c_str()); } break; default: - if (BreakOnUnhandledMemory()) + if (PAddr >= 0x10000000 && PAddr < 0x20000000) + { + m_RegWorkingSet.BeforeCallDirect(); + PushImm32(0xFFFFFFFF); + PushImm32(Value << ((2 - (PAddr & 2)) * 8)); + PushImm32(PAddr); +#ifdef _MSC_VER + MoveConstToX86reg((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, x86_ECX); + Call_Direct((void *)((long**)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32"); +#else + PushImm32((uint32_t)&g_MMU->m_RomMemoryHandler); + Call_Direct(AddressOf(&RomMemoryHandler::Write32), "RomMemoryHandler::Write32"); + AddConstToX86Reg(x86_ESP, 16); +#endif + m_RegWorkingSet.AfterCallDirect(); + } + else if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -10315,7 +10346,7 @@ void CX86RecompilerOps::SH_Register(x86Reg Reg, uint32_t VAddr) } else { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10339,7 +10370,7 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) uint32_t PAddr; if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10626,8 +10657,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) m_RegWorkingSet.BeforeCallDirect(); Call_Direct((void *)g_Plugins->Gfx()->ViStatusChanged, "ViStatusChanged"); m_RegWorkingSet.AfterCallDirect(); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump, *g_RecompPos); } break; @@ -10642,8 +10673,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) m_RegWorkingSet.BeforeCallDirect(); Call_Direct((void *)g_Plugins->Gfx()->ViWidthChanged, "ViWidthChanged"); m_RegWorkingSet.AfterCallDirect(); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump, *g_RecompPos); } break; @@ -10841,24 +10872,43 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) } break; default: - if (BreakOnUnhandledMemory()) + if (PAddr >= 0x10000000 && PAddr < 0x20000000) { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - UpdateCounters(m_RegWorkingSet, false, true, true); - - m_RegWorkingSet.BeforeCallDirect(); - PushImm32(Value); - PushImm32(PAddr | 0xA0000000); + m_RegWorkingSet.BeforeCallDirect(); + PushImm32(0xFFFFFFFF); + PushImm32(Value); + PushImm32(PAddr); #ifdef _MSC_VER - MoveConstToX86reg((uint32_t)(g_MMU), x86_ECX); - Call_Direct(AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory"); + MoveConstToX86reg((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, x86_ECX); + Call_Direct((void *)((long**)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32"); #else - PushImm32((uint32_t)(g_MMU)); - Call_Direct(AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory"); - AddConstToX86Reg(x86_ESP, 12); + PushImm32((uint32_t)&g_MMU->m_RomMemoryHandler); + Call_Direct(AddressOf(&RomMemoryHandler::Write32), "RomMemoryHandler::Write32"); + AddConstToX86Reg(x86_ESP, 16); #endif - m_RegWorkingSet.AfterCallDirect(); + m_RegWorkingSet.AfterCallDirect(); + } + else + { + if (BreakOnUnhandledMemory()) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + } + UpdateCounters(m_RegWorkingSet, false, true, true); + + m_RegWorkingSet.BeforeCallDirect(); + PushImm32(Value); + PushImm32(PAddr | 0xA0000000); +#ifdef _MSC_VER + MoveConstToX86reg((uint32_t)(g_MMU), x86_ECX); + Call_Direct(AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory"); +#else + PushImm32((uint32_t)(g_MMU)); + Call_Direct(AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory"); + AddConstToX86Reg(x86_ESP, 12); +#endif + m_RegWorkingSet.AfterCallDirect(); + } } } @@ -10878,7 +10928,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) if (!m_MMU.VAddrToPAddr(VAddr, PAddr)) { - CPU_Message("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); + m_CodeBlock.Log("%s\nFailed to translate address: %08X", __FUNCTION__, VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -10958,7 +11008,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) } else { - CPU_Message(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); + m_CodeBlock.Log(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -11009,7 +11059,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) m_RegWorkingSet.AfterCallDirect(); break; default: - CPU_Message(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); + m_CodeBlock.Log(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -11050,8 +11100,8 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) m_RegWorkingSet.BeforeCallDirect(); Call_Direct((void *)g_Plugins->Gfx()->ViStatusChanged, "ViStatusChanged"); m_RegWorkingSet.AfterCallDirect(); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump, *g_RecompPos); } break; @@ -11070,8 +11120,8 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) m_RegWorkingSet.BeforeCallDirect(); Call_Direct((void *)g_Plugins->Gfx()->ViWidthChanged, "ViWidthChanged"); m_RegWorkingSet.AfterCallDirect(); - CPU_Message(""); - CPU_Message(" Continue:"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" Continue:"); SetJump8(Jump, *g_RecompPos); } break; @@ -11099,7 +11149,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) case 0x04400030: MoveX86regToVariable(Reg, &g_Reg->VI_X_SCALE_REG, "VI_X_SCALE_REG"); break; case 0x04400034: MoveX86regToVariable(Reg, &g_Reg->VI_Y_SCALE_REG, "VI_Y_SCALE_REG"); break; default: - CPU_Message(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); + m_CodeBlock.Log(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -11183,7 +11233,7 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) AndConstToVariable(0xFF, &g_Reg->PI_BSD_DOM2_RLS_REG, "PI_BSD_DOM2_RLS_REG"); break; default: - CPU_Message(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); + m_CodeBlock.Log(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -11293,12 +11343,27 @@ void CX86RecompilerOps::SW_Register(x86Reg Reg, uint32_t VAddr) } break; } + case 0x13F00000: + m_RegWorkingSet.BeforeCallDirect(); + PushImm32(0xFFFFFFFF); + Push(Reg); + PushImm32(PAddr & 0x1FFFFFFF); +#ifdef _MSC_VER + MoveConstToX86reg((uint32_t)(MemoryHandler *)&g_MMU->m_ISViewerHandler, x86_ECX); + Call_Direct((void *)((long**)(MemoryHandler *)&g_MMU->m_ISViewerHandler)[0][1], "ISViewerHandler::Write32"); +#else + PushImm32((uint32_t)&g_MMU->m_ISViewerHandler); + Call_Direct(AddressOf(&ISViewerHandler::Write32), "ISViewerHandler::Write32"); + AddConstToX86Reg(x86_ESP, 16); +#endif + m_RegWorkingSet.AfterCallDirect(); + break; case 0x1FC00000: sprintf(VarName, "RDRAM + %X", PAddr); MoveX86regToVariable(Reg, PAddr + g_MMU->Rdram(), VarName); break; default: - CPU_Message(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); + m_CodeBlock.Log(" should be moving %s in to %08X ?", x86_Name(Reg), VAddr); if (BreakOnUnhandledMemory()) { g_Notify->BreakPoint(__FILE__, __LINE__); @@ -11311,7 +11376,7 @@ void CX86RecompilerOps::ResetMemoryStack() x86Reg Reg, TempReg; int32_t MipsReg = 29; - CPU_Message(" ResetMemoryStack"); + m_CodeBlock.Log(" ResetMemoryStack"); Reg = Get_MemoryStack(); if (Reg == x86_Unknown) { diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h index 6efe85913..fa593f089 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h @@ -25,7 +25,7 @@ class CX86RecompilerOps : private CGameSettings { public: - CX86RecompilerOps(CMipsMemoryVM & MMU); + CX86RecompilerOps(CMipsMemoryVM & MMU, CCodeBlock & CodeBlock); ~CX86RecompilerOps(); // Trap functions @@ -216,7 +216,7 @@ public: void CompileCop1Test(); void CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCounter); void SyncRegState(const CRegInfo & SyncTo); - bool SetupRegisterForLoop(CCodeBlock * BlockInfo, const CRegInfo & RegSet); + bool SetupRegisterForLoop(CCodeBlock & BlockInfo, const CRegInfo & RegSet); CRegInfo & GetRegWorkingSet(void); void SetRegWorkingSet(const CRegInfo & RegInfo); bool InheritParentInfo(); @@ -236,7 +236,7 @@ public: void CompileReadTLBMiss(uint32_t VirtualAddress, x86Reg LookUpReg); void CompileReadTLBMiss(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 CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet); void CompileExecuteBP(void); @@ -247,111 +247,51 @@ public: // Helper functions typedef CRegInfo::REG_STATE REG_STATE; - static REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); } - static 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); } - static 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); } - static 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); } - static CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapLo(Reg); } - static CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapHi(Reg); } + REG_STATE GetMipsRegState(int32_t Reg) { return m_RegWorkingSet.GetMipsRegState(Reg); } + uint64_t GetMipsReg(int32_t Reg) { return m_RegWorkingSet.GetMipsReg(Reg); } + int64_t GetMipsReg_S(int32_t Reg) { return m_RegWorkingSet.GetMipsReg_S(Reg); } + uint32_t GetMipsRegLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo(Reg); } + int32_t GetMipsRegLo_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegLo_S(Reg); } + uint32_t GetMipsRegHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi(Reg); } + int32_t GetMipsRegHi_S(int32_t Reg) { return m_RegWorkingSet.GetMipsRegHi_S(Reg); } + CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapLo(Reg); } + CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) { return m_RegWorkingSet.GetMipsRegMapHi(Reg); } - static bool IsKnown(int32_t Reg) { return m_RegWorkingSet.IsKnown(Reg); } - static bool IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); } - static bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); } - static bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(Reg); } - static bool IsSigned(int32_t Reg) { return m_RegWorkingSet.IsSigned(Reg); } - static bool IsUnsigned(int32_t Reg) { return m_RegWorkingSet.IsUnsigned(Reg); } - static bool Is32Bit(int32_t Reg) { return m_RegWorkingSet.Is32Bit(Reg); } - static bool Is64Bit(int32_t Reg) { return m_RegWorkingSet.Is64Bit(Reg); } - static bool Is32BitMapped(int32_t Reg) { return m_RegWorkingSet.Is32BitMapped(Reg); } - static bool Is64BitMapped(int32_t Reg) { return m_RegWorkingSet.Is64BitMapped(Reg); } + bool IsKnown(int32_t Reg) { return m_RegWorkingSet.IsKnown(Reg); } + bool IsUnknown(int32_t Reg) { return m_RegWorkingSet.IsUnknown(Reg); } + bool IsMapped(int32_t Reg) { return m_RegWorkingSet.IsMapped(Reg); } + bool IsConst(int32_t Reg) { return m_RegWorkingSet.IsConst(Reg); } + bool IsSigned(int32_t Reg) { return m_RegWorkingSet.IsSigned(Reg); } + bool IsUnsigned(int32_t Reg) { return m_RegWorkingSet.IsUnsigned(Reg); } + bool Is32Bit(int32_t Reg) { return m_RegWorkingSet.Is32Bit(Reg); } + bool Is64Bit(int32_t Reg) { return m_RegWorkingSet.Is64Bit(Reg); } + bool Is32BitMapped(int32_t Reg) { return m_RegWorkingSet.Is32BitMapped(Reg); } + bool Is64BitMapped(int32_t Reg) { return m_RegWorkingSet.Is64BitMapped(Reg); } - static void FixRoundModel(CRegInfo::FPU_ROUND RoundMethod) - { - m_RegWorkingSet.FixRoundModel(RoundMethod); - } - static void ChangeFPURegFormat(int32_t Reg, CRegInfo::FPU_STATE OldFormat, CRegInfo::FPU_STATE NewFormat, CRegInfo::FPU_ROUND RoundingModel) - { - m_RegWorkingSet.ChangeFPURegFormat(Reg, OldFormat, NewFormat, RoundingModel); - } - 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); - } + 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); } + 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); } + x86FpuValues StackPosition(int32_t Reg) { return m_RegWorkingSet.StackPosition(Reg); } + void UnMap_AllFPRs() { m_RegWorkingSet.UnMap_AllFPRs(); } + void UnMap_FPR(uint32_t Reg, bool WriteBackValue) { m_RegWorkingSet.UnMap_FPR(Reg, WriteBackValue); } - static x86Reg FreeX86Reg() - { - return m_RegWorkingSet.FreeX86Reg(); - } - static x86Reg Free8BitX86Reg() - { - return m_RegWorkingSet.Free8BitX86Reg(); - } - static void Map_GPR_32bit(int32_t Reg, bool SignValue, int32_t MipsRegToLoad) - { - m_RegWorkingSet.Map_GPR_32bit(Reg, SignValue, MipsRegToLoad); - } - static void Map_GPR_64bit(int32_t Reg, int32_t MipsRegToLoad) - { - 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); - } + x86Reg FreeX86Reg() { return m_RegWorkingSet.FreeX86Reg(); } + x86Reg Free8BitX86Reg() { return m_RegWorkingSet.Free8BitX86Reg(); } + 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); } + 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); } + 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); } + void UnProtectGPR(uint32_t Reg) { m_RegWorkingSet.UnProtectGPR(Reg); } + void ResetX86Protection() { m_RegWorkingSet.ResetX86Protection(); } + x86Reg UnMap_TempReg() { return m_RegWorkingSet.UnMap_TempReg(); } + void UnMap_GPR(uint32_t Reg, bool WriteBackValue) { m_RegWorkingSet.UnMap_GPR(Reg, WriteBackValue); } + bool UnMap_X86reg(x86Reg Reg) { return m_RegWorkingSet.UnMap_X86reg(Reg); } public: - static uint32_t CompilePC() { return m_CompilePC; } + uint32_t CompilePC() { return m_CompilePC; } private: 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 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 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 SW_Const(uint32_t Value, 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(bool ResultSigned, bool bRecordLLBit); 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(); EXIT_LIST m_ExitInfo; CMipsMemoryVM & m_MMU; - static PIPELINE_STAGE m_PipelineStage; - static uint32_t m_CompilePC; - static R4300iOpcode m_Opcode; - static CX86RegInfo m_RegWorkingSet; - static uint32_t m_BranchCompare; - static CCodeSection * m_Section; + CCodeBlock & m_CodeBlock; + PIPELINE_STAGE m_PipelineStage; + uint32_t m_CompilePC; + R4300iOpcode m_Opcode; + CX86RegInfo m_RegWorkingSet; + CCodeSection * m_Section; + CRegInfo m_RegBeforeDelay; + bool m_EffectDelaySlot; static uint32_t m_TempValue32; + static uint32_t m_BranchCompare; }; #endif diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp index eaeb675de..773ea40c6 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -15,7 +14,9 @@ uint32_t CX86RegInfo::m_fpuControl = 0; 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_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; } @@ -140,7 +143,7 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod) { 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; fpuStoreControl(&m_fpuControl, "m_fpuControl"); @@ -205,7 +208,7 @@ void CX86RegInfo::ChangeFPURegFormat(int32_t Reg, FPU_STATE OldFormat, FPU_STATE } 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; 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); } - 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; 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) { 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)); FpuRoundingModel(StackTopPos()) = RoundDefault; 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_State[RegPos] = m_x86fpu_State[StackTopPos()]; m_x86fpu_StateChanged[RegPos] = m_x86fpu_StateChanged[StackTopPos()]; - CPU_Message(" 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(%d) to %s", StackPos, CRegName::FPR[m_x86fpu_MappedTo[RegPos]]); + m_CodeBlock.Log(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); fpuExchange(StackPos); @@ -365,7 +368,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma 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); switch (Format) { @@ -536,7 +539,7 @@ CX86Ops::x86Reg CX86RegInfo::UnMap_8BitTempReg() { 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); return (x86Reg)count; } @@ -585,7 +588,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister, g_Notify->BreakPoint(__FILE__, __LINE__); } 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) { MoveVariableToX86reg(&g_Recompiler->MemoryStackPos(), "MemoryStack", Reg); @@ -597,7 +600,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister, UnMap_X86reg(Reg); 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(CurrentMap, CX86RegInfo::NotMapped); MoveX86RegToX86Reg(CurrentMap, Reg); @@ -605,7 +608,7 @@ CX86RegInfo::x86Reg CX86RegInfo::Map_MemoryStack(x86Reg Reg, bool bMapRegister, else { 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) { 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__); 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 { 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); SetX86Mapped(GetMipsRegMapHi(MipsReg), NotMapped); 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; } SetX86Protected(x86lo, true); - CPU_Message(" 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 hi word of %s", x86_Name(x86Hi), CRegName::GPR[MipsReg]); + m_CodeBlock.Log(" regcache: allocate %s to low word of %s", x86_Name(x86lo), CRegName::GPR[MipsReg]); } else { @@ -729,7 +732,7 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad) } 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 { @@ -784,7 +787,7 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad) } else { - CPU_Message("Map_GPR_64bit 11"); + m_CodeBlock.Log("Map_GPR_64bit 11"); if (Is32Bit(MipsRegToLoad)) { if (IsSigned(MipsRegToLoad)) @@ -883,7 +886,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b UnMap_GPR(count, true); 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); SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); SetMipsRegMapLo(count, NewReg); @@ -901,7 +904,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b UnMap_GPR(count, true); 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); SetX86MapOrder(NewReg, GetX86MapOrder(Reg)); SetMipsRegMapHi(count, NewReg); @@ -918,7 +921,7 @@ CX86Ops::x86Reg CX86RegInfo::Map_TempReg(CX86Ops::x86Reg Reg, int32_t MipsReg, b { 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) { @@ -1066,7 +1069,7 @@ void CX86RegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue) for (i = 0; i < 8; i++) { 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) { int32_t RegPos; @@ -1157,7 +1160,7 @@ void CX86RegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue) } 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 (!WriteBackValue) @@ -1186,11 +1189,11 @@ void CX86RegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue) } 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); 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); SetX86Protected(GetMipsRegMapLo(Reg), false); if (!WriteBackValue) @@ -1241,7 +1244,7 @@ CX86Ops::x86Reg CX86RegInfo::UnMap_TempReg() { 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); } @@ -1292,14 +1295,14 @@ bool CX86RegInfo::UnMap_X86reg(CX86Ops::x86Reg 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); return true; } } 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"); SetX86Mapped(Reg, NotMapped); return true; @@ -1448,7 +1451,7 @@ void CX86RegInfo::WriteBackRegisters() SetMipsRegState(count, CX86RegInfo::STATE_UNKNOWN); break; 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__); } } diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h index 97cc1bafd..0cf7f9e9b 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h @@ -33,7 +33,7 @@ public: }; public: - CX86RegInfo(); + CX86RegInfo(CCodeBlock & CodeBlock); CX86RegInfo(const CX86RegInfo&); ~CX86RegInfo(); @@ -70,19 +70,19 @@ public: bool UnMap_X86reg(x86Reg Reg); void WriteBackRegisters(); - CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; } - CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; } + CX86Ops::x86Reg GetMipsRegMapLo(int32_t Reg) const { return m_RegMapLo[Reg]; } + CX86Ops::x86Reg GetMipsRegMapHi(int32_t Reg) const { return m_RegMapHi[Reg]; } - uint32_t GetX86MapOrder(x86Reg Reg) const { return m_x86reg_MapOrder[Reg]; } - bool GetX86Protected(x86Reg Reg) const { return m_x86reg_Protected[Reg]; } - REG_MAPPED GetX86Mapped(x86Reg Reg) const { return m_x86reg_MappedTo[Reg]; } + uint32_t GetX86MapOrder(x86Reg Reg) const { return m_x86reg_MapOrder[Reg]; } + bool GetX86Protected(x86Reg Reg) const { return m_x86reg_Protected[Reg]; } + REG_MAPPED GetX86Mapped(x86Reg Reg) const { return m_x86reg_MappedTo[Reg]; } - void SetMipsRegMapLo(int32_t GetMipsReg, x86Reg Reg) { m_RegMapLo[GetMipsReg] = Reg; } - void SetMipsRegMapHi(int32_t GetMipsReg, x86Reg Reg) { m_RegMapHi[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 SetX86MapOrder(x86Reg Reg, uint32_t Order) { m_x86reg_MapOrder[Reg] = Order; } - void SetX86Protected(x86Reg Reg, bool Protected) { m_x86reg_Protected[Reg] = Protected; } - void SetX86Mapped(x86Reg Reg, REG_MAPPED Mapping) { m_x86reg_MappedTo[Reg] = Mapping; } + void SetX86MapOrder(x86Reg Reg, uint32_t Order) { m_x86reg_MapOrder[Reg] = Order; } + void SetX86Protected(x86Reg Reg, bool Protected) { m_x86reg_Protected[Reg] = Protected; } + void SetX86Mapped(x86Reg Reg, REG_MAPPED Mapping) { m_x86reg_MappedTo[Reg] = Mapping; } int32_t & StackTopPos() { return m_Stack_TopPos; } 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]; } private: + CX86RegInfo(); + + CCodeBlock & m_CodeBlock; x86Reg UnMap_8BitTempReg(); // r4k - x86Reg m_RegMapHi[32]; - x86Reg m_RegMapLo[32]; + x86Reg m_RegMapHi[32]; + x86Reg m_RegMapLo[32]; - REG_MAPPED m_x86reg_MappedTo[10]; - uint32_t m_x86reg_MapOrder[10]; - bool m_x86reg_Protected[10]; + REG_MAPPED m_x86reg_MappedTo[10]; + uint32_t m_x86reg_MapOrder[10]; + bool m_x86reg_Protected[10]; // FPU - int32_t m_Stack_TopPos; - int32_t m_x86fpu_MappedTo[8]; - FPU_STATE m_x86fpu_State[8]; - bool m_x86fpu_StateChanged[8]; - FPU_ROUND m_x86fpu_RoundingModel[8]; + int32_t m_Stack_TopPos; + int32_t m_x86fpu_MappedTo[8]; + FPU_STATE m_x86fpu_State[8]; + bool m_x86fpu_StateChanged[8]; + FPU_ROUND m_x86fpu_RoundingModel[8]; static uint32_t m_fpuControl; bool m_InBeforeCallDirect; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp index 529ad6402..3549dc80d 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include char CX86Ops::m_fpupop[2][2] = { @@ -23,29 +23,34 @@ CX86Ops::x86Reg CX86Ops::x86_Registers[8] = x86_ESP }; +CX86Ops::CX86Ops(CCodeBlock & CodeBlock) : + m_CodeBlock(CodeBlock) +{ +} + // Logging functions void CX86Ops::WriteX86Comment(const char * Comment) { - CPU_Message(""); - CPU_Message(" // %s", Comment); + CodeLog(""); + CodeLog(" // %s", Comment); } void CX86Ops::WriteX86Label(const char * Label) { - CPU_Message(""); - CPU_Message(" %s:", Label); + CodeLog(""); + CodeLog(" %s:", Label); } void CX86Ops::AdcX86regToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" adc dword ptr [%s], %s", VariableName, x86_Name(reg)); + CodeLog(" adc dword ptr [%s], %s", VariableName, x86_Name(reg)); AddCode16((uint16_t)(0x0511 + (reg * 0x100))); AddCode32((uint32_t)Variable); } void CX86Ops::AdcConstToVariable(void *Variable, const char * VariableName, uint8_t Constant) { - CPU_Message(" adc dword ptr [%s], %Xh", VariableName, Constant); + CodeLog(" adc dword ptr [%s], %Xh", VariableName, Constant); AddCode16(0x1583); AddCode32((uint32_t)Variable); AddCode8(Constant); @@ -53,7 +58,7 @@ void CX86Ops::AdcConstToVariable(void *Variable, const char * VariableName, uint void CX86Ops::AdcConstToX86Reg(x86Reg reg, uint32_t Const) { - CPU_Message(" adc %s, %Xh", x86_Name(reg), Const); + CodeLog(" adc %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { AddCode16((uint16_t)(0xD081 + (reg * 0x100))); @@ -68,20 +73,20 @@ void CX86Ops::AdcConstToX86Reg(x86Reg reg, uint32_t Const) void CX86Ops::AdcVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" adc %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" adc %s, dword ptr [%s]", x86_Name(reg), VariableName); AddCode16((uint16_t)(0x0513 + (reg * 0x800))); AddCode32((uint32_t)Variable); } void CX86Ops::AdcX86RegToX86Reg(x86Reg Destination, x86Reg Source) { - CPU_Message(" adc %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" adc %s, %s", x86_Name(Destination), x86_Name(Source)); AddCode16((uint16_t)(0xC013 + (Source * 0x100) + (Destination * 0x800))); } void CX86Ops::AddConstToVariable(uint32_t Const, void *Variable, const char * VariableName) { - CPU_Message(" add dword ptr [%s], 0x%X", VariableName, Const); + CodeLog(" add dword ptr [%s], 0x%X", VariableName, Const); AddCode16(0x0581); AddCode32((uint32_t)Variable); AddCode32(Const); @@ -102,13 +107,13 @@ void CX86Ops::AddConstToX86Reg(x86Reg reg, uint32_t Const) } else if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - CPU_Message(" add %s, %Xh", x86_Name(reg), Const); + CodeLog(" add %s, %Xh", x86_Name(reg), Const); AddCode16((uint16_t)(0xC081 + (reg * 0x100))); AddCode32(Const); } else { - CPU_Message(" add %s, %Xh", x86_Name(reg), Const); + CodeLog(" add %s, %Xh", x86_Name(reg), Const); AddCode16((uint16_t)(0xC083 + (reg * 0x100))); AddCode8((uint8_t)Const); } @@ -116,27 +121,27 @@ void CX86Ops::AddConstToX86Reg(x86Reg reg, uint32_t Const) void CX86Ops::AddVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" add %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" add %s, dword ptr [%s]", x86_Name(reg), VariableName); AddCode16((uint16_t)(0x0503 + (reg * 0x800))); AddCode32((uint32_t)Variable); } void CX86Ops::AddX86regToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" add dword ptr [%s], %s", VariableName, x86_Name(reg)); + CodeLog(" add dword ptr [%s], %s", VariableName, x86_Name(reg)); AddCode16((uint16_t)(0x0501 + (reg * 0x800))); AddCode32((uint32_t)Variable); } void CX86Ops::AddX86RegToX86Reg(x86Reg Destination, x86Reg Source) { - CPU_Message(" add %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" add %s, %s", x86_Name(Destination), x86_Name(Source)); AddCode16((uint16_t)(0xC003 + (Source * 0x100) + (Destination * 0x800))); } void CX86Ops::AndConstToVariable(uint32_t Const, void *Variable, const char * VariableName) { - CPU_Message(" and dword ptr [%s], 0x%X", VariableName, Const); + CodeLog(" and dword ptr [%s], 0x%X", VariableName, Const); AddCode16(0x2581); AddCode32((uint32_t)Variable); AddCode32(Const); @@ -144,7 +149,7 @@ void CX86Ops::AndConstToVariable(uint32_t Const, void *Variable, const char * Va void CX86Ops::AndConstToX86Reg(x86Reg reg, uint32_t Const) { - CPU_Message(" and %s, %Xh", x86_Name(reg), Const); + CodeLog(" and %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { AddCode16((uint16_t)(0xE081 + (reg * 0x100))); @@ -159,7 +164,7 @@ void CX86Ops::AndConstToX86Reg(x86Reg reg, uint32_t Const) void CX86Ops::AndVariableDispToX86Reg(void *Variable, const char * VariableName, x86Reg reg, x86Reg AddrReg, Multipler Multiply) { - CPU_Message(" and %s, dword ptr [%s+%s*%i]", x86_Name(reg), VariableName, x86_Name(AddrReg), Multiply); + CodeLog(" and %s, dword ptr [%s+%s*%i]", x86_Name(reg), VariableName, x86_Name(AddrReg), Multiply); AddCode16((uint16_t)(0x0423 + (reg * 0x800))); AddCode8((uint8_t)(0x05 + CalcMultiplyCode(Multiply) + (AddrReg * 0x8))); @@ -168,14 +173,14 @@ void CX86Ops::AndVariableDispToX86Reg(void *Variable, const char * VariableName, void CX86Ops::AndVariableToX86Reg(void * Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" and %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" and %s, dword ptr [%s]", x86_Name(reg), VariableName); AddCode16((uint16_t)(0x0523 + (reg * 0x800))); AddCode32((uint32_t)(Variable)); } void CX86Ops::AndX86RegToX86Reg(x86Reg Destination, x86Reg Source) { - CPU_Message(" and %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" and %s, %s", x86_Name(Destination), x86_Name(Source)); AddCode16((uint16_t)(0xC021 + (Destination * 0x100) + (Source * 0x800))); } @@ -186,7 +191,7 @@ void CX86Ops::BreakPointNotification(const char * FileName, int32_t LineNumber) void CX86Ops::X86HardBreakPoint() { - CPU_Message(" int 3"); + CodeLog(" int 3"); AddCode8(0xCC); } @@ -202,21 +207,21 @@ void CX86Ops::X86BreakPoint(const char * FileName, int LineNumber) void CX86Ops::Call_Direct(void * FunctAddress, const char * FunctName) { - CPU_Message(" call offset %s", FunctName); + CodeLog(" call offset %s", FunctName); AddCode8(0xE8); AddCode32((uint32_t)FunctAddress - (uint32_t)*g_RecompPos - 4); } void CX86Ops::Call_Indirect(void * FunctAddress, const char * FunctName) { - CPU_Message(" call [%s]", FunctName); + CodeLog(" call [%s]", FunctName); AddCode16(0x15FF); AddCode32((uint32_t)FunctAddress); } void CX86Ops::CompConstToVariable(uint32_t Const, void * Variable, const char * VariableName) { - CPU_Message(" cmp dword ptr [%s], 0x%X", VariableName, Const); + CodeLog(" cmp dword ptr [%s], 0x%X", VariableName, Const); AddCode16(0x3D81); AddCode32((uint32_t)Variable); AddCode32(Const); @@ -230,7 +235,7 @@ void CX86Ops::CompConstToX86reg(x86Reg reg, uint32_t Const) } else { - CPU_Message(" cmp %s, %Xh", x86_Name(reg), Const); + CodeLog(" cmp %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { AddCode16((uint16_t)(0xF881 + (reg * 0x100))); @@ -248,13 +253,13 @@ void CX86Ops::CompConstToX86regPointer(x86Reg reg, uint32_t Const) { if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { - CPU_Message(" cmp dword ptr [%s], %Xh", x86_Name(reg), Const); + CodeLog(" cmp dword ptr [%s], %Xh", x86_Name(reg), Const); AddCode16((uint16_t)(0x3881 + (reg * 0x100))); AddCode32(Const); } else { - CPU_Message(" cmp byte ptr [%s], %Xh", x86_Name(reg), Const); + CodeLog(" cmp byte ptr [%s], %Xh", x86_Name(reg), Const); AddCode16((uint16_t)(0x3883 + (reg * 0x100))); AddCode8((uint8_t)Const); } @@ -262,14 +267,14 @@ void CX86Ops::CompConstToX86regPointer(x86Reg reg, uint32_t Const) void CX86Ops::CompX86regToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" cmp %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" cmp %s, dword ptr [%s]", x86_Name(reg), VariableName); AddCode16((uint16_t)(0x053B + (reg * 0x800))); AddCode32((uint32_t)Variable); } void CX86Ops::CompVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" cmp dword ptr [%s], %s", VariableName, x86_Name(reg)); + CodeLog(" cmp dword ptr [%s], %s", VariableName, x86_Name(reg)); AddCode16((uint16_t)(0x0539 + (reg * 0x800))); AddCode32((uint32_t)Variable); } @@ -278,7 +283,7 @@ void CX86Ops::CompX86RegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" cmp %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" cmp %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Source) { @@ -309,7 +314,7 @@ void CX86Ops::CompX86RegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::DecX86reg(x86Reg reg) { - CPU_Message(" dec %s", x86_Name(reg)); + CodeLog(" dec %s", x86_Name(reg)); switch (reg) { @@ -328,7 +333,7 @@ void CX86Ops::DecX86reg(x86Reg reg) void CX86Ops::DivX86reg(x86Reg reg) { - CPU_Message(" div %s", x86_Name(reg)); + CodeLog(" div %s", x86_Name(reg)); switch (reg) { case x86_EBX: AddCode16(0xf3F7); break; @@ -345,7 +350,7 @@ void CX86Ops::DivX86reg(x86Reg reg) void CX86Ops::idivX86reg(x86Reg reg) { - CPU_Message(" idiv %s", x86_Name(reg)); + CodeLog(" idiv %s", x86_Name(reg)); switch (reg) { @@ -363,7 +368,7 @@ void CX86Ops::idivX86reg(x86Reg reg) void CX86Ops::imulX86reg(x86Reg reg) { - CPU_Message(" imul %s", x86_Name(reg)); + CodeLog(" imul %s", x86_Name(reg)); switch (reg) { @@ -382,7 +387,7 @@ void CX86Ops::imulX86reg(x86Reg reg) void CX86Ops::IncX86reg(x86Reg reg) { - CPU_Message(" inc %s", x86_Name(reg)); + CodeLog(" inc %s", x86_Name(reg)); switch (reg) { @@ -401,119 +406,119 @@ void CX86Ops::IncX86reg(x86Reg reg) void CX86Ops::JaeLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jae $%s", Label); + CodeLog(" jae $%s", Label); AddCode8(0x73); AddCode8(Value); } void CX86Ops::JaeLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jae $%s", Label); + CodeLog(" jae $%s", Label); AddCode16(0x830F); AddCode32(Value); } void CX86Ops::JaLabel8(const char * Label, uint8_t Value) { - CPU_Message(" ja $%s", Label); + CodeLog(" ja $%s", Label); AddCode8(0x77); AddCode8(Value); } void CX86Ops::JaLabel32(const char * Label, uint32_t Value) { - CPU_Message(" ja $%s", Label); + CodeLog(" ja $%s", Label); AddCode16(0x870F); AddCode32(Value); } void CX86Ops::JbLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jb $%s", Label); + CodeLog(" jb $%s", Label); AddCode8(0x72); AddCode8(Value); } void CX86Ops::JbLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jb $%s", Label); + CodeLog(" jb $%s", Label); AddCode16(0x820F); AddCode32(Value); } void CX86Ops::JecxzLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jecxz $%s", Label); + CodeLog(" jecxz $%s", Label); AddCode8(0xE3); AddCode8(Value); } void CX86Ops::JeLabel8(const char * Label, uint8_t Value) { - CPU_Message(" je $%s", Label); + CodeLog(" je $%s", Label); AddCode8(0x74); AddCode8(Value); } void CX86Ops::JeLabel32(const char * Label, uint32_t Value) { - CPU_Message(" je $%s", Label); + CodeLog(" je $%s", Label); AddCode16(0x840F); AddCode32(Value); } void CX86Ops::JgeLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jge $%s", Label); + CodeLog(" jge $%s", Label); AddCode16(0x8D0F); AddCode32(Value); } void CX86Ops::JgLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jg $%s", Label); + CodeLog(" jg $%s", Label); AddCode8(0x7F); AddCode8(Value); } void CX86Ops::JgLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jg $%s", Label); + CodeLog(" jg $%s", Label); AddCode16(0x8F0F); AddCode32(Value); } void CX86Ops::JleLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jle $%s", Label); + CodeLog(" jle $%s", Label); AddCode8(0x7E); AddCode8(Value); } void CX86Ops::JleLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jle $%s", Label); + CodeLog(" jle $%s", Label); AddCode16(0x8E0F); AddCode32(Value); } void CX86Ops::JlLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jl $%s", Label); + CodeLog(" jl $%s", Label); AddCode8(0x7C); AddCode8(Value); } void CX86Ops::JlLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jl $%s", Label); + CodeLog(" jl $%s", Label); AddCode16(0x8C0F); AddCode32(Value); } void CX86Ops::JmpDirectReg(x86Reg reg) { - CPU_Message(" jmp %s", x86_Name(reg)); + CodeLog(" jmp %s", x86_Name(reg)); switch (reg) { @@ -530,14 +535,14 @@ void CX86Ops::JmpDirectReg(x86Reg reg) void CX86Ops::JmpIndirectLabel32(const char * Label, uint32_t location) { - CPU_Message(" jmp dword ptr [%s]", Label); + CodeLog(" jmp dword ptr [%s]", Label); AddCode16(0x25ff); AddCode32(location); } void CX86Ops::JmpIndirectReg(x86Reg reg) { - CPU_Message(" jmp dword ptr [%s]", x86_Name(reg)); + CodeLog(" jmp dword ptr [%s]", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0x20ff); break; @@ -561,77 +566,77 @@ void CX86Ops::JmpIndirectReg(x86Reg reg) void CX86Ops::JmpLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jmp $%s", Label); + CodeLog(" jmp $%s", Label); AddCode8(0xEB); AddCode8(Value); } void CX86Ops::JmpLabel32(const char * Label, uint32_t Value) { - CPU_Message(" jmp $%s", Label); + CodeLog(" jmp $%s", Label); AddCode8(0xE9); AddCode32(Value); } void CX86Ops::JneLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jne $%s", Label); + CodeLog(" jne $%s", Label); AddCode8(0x75); AddCode8(Value); } void CX86Ops::JneLabel32(const char *Label, uint32_t Value) { - CPU_Message(" jne $%s", Label); + CodeLog(" jne $%s", Label); AddCode16(0x850F); AddCode32(Value); } void CX86Ops::JnsLabel8(const char * Label, uint8_t Value) { - CPU_Message(" jns $%s", Label); + CodeLog(" jns $%s", Label); AddCode8(0x79); AddCode8(Value); } void CX86Ops::JnsLabel32(const char *Label, uint32_t Value) { - CPU_Message(" jns $%s", Label); + CodeLog(" jns $%s", Label); AddCode16(0x890F); AddCode32(Value); } void CX86Ops::JnzLabel8(const char *Label, uint8_t Value) { - CPU_Message(" jnz $%s", Label); + CodeLog(" jnz $%s", Label); AddCode8(0x75); AddCode8(Value); } void CX86Ops::JnzLabel32(const char *Label, uint32_t Value) { - CPU_Message(" jnz $%s", Label); + CodeLog(" jnz $%s", Label); AddCode16(0x850F); AddCode32(Value); } void CX86Ops::JsLabel32(const char *Label, uint32_t Value) { - CPU_Message(" js $%s", Label); + CodeLog(" js $%s", Label); AddCode16(0x880F); AddCode32(Value); } void CX86Ops::JzLabel8(const char *Label, uint8_t Value) { - CPU_Message(" jz $%s", Label); + CodeLog(" jz $%s", Label); AddCode8(0x74); AddCode8(Value); } void CX86Ops::JzLabel32(const char *Label, uint32_t Value) { - CPU_Message(" jz $%s", Label); + CodeLog(" jz $%s", Label); AddCode16(0x840F); AddCode32(Value); } @@ -640,10 +645,10 @@ void CX86Ops::LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler { if (Const != 0) { - CPU_Message(" lea %s, [%s*%i+%X]", x86_Name(RegDest), x86_Name(RegSrc), multiplier, Const); + CodeLog(" lea %s, [%s*%i+%X]", x86_Name(RegDest), x86_Name(RegSrc), multiplier, Const); } else { - CPU_Message(" lea %s, [%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), multiplier); + CodeLog(" lea %s, [%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), multiplier); } AddCode8(0x8D); @@ -654,7 +659,7 @@ void CX86Ops::LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler void CX86Ops::LeaRegReg2(x86Reg RegDest, x86Reg RegSrc, x86Reg RegSrc2, Multipler multiplier) { - CPU_Message(" lea %s, [%s+%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), x86_Name(RegSrc2), multiplier); + CodeLog(" lea %s, [%s+%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), x86_Name(RegSrc2), multiplier); if (RegSrc2 == x86_ESP || RegSrc2 == x86_EBP) { @@ -670,7 +675,7 @@ void CX86Ops::LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int off { uint16_t x86Command = 0; - CPU_Message(" lea %s, [%s + %0Xh]", x86_Name(x86DestReg), x86_Name(x86SourceReg), offset); + CodeLog(" lea %s, [%s + %0Xh]", x86_Name(x86DestReg), x86_Name(x86SourceReg), offset); // if ((offset & 0xFFFFFF80) != 0 && (offset & 0xFFFFFF80) != 0xFFFFFF80) { if (1) @@ -739,7 +744,7 @@ void CX86Ops::LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int off void CX86Ops::MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg) { - CPU_Message(" mov byte ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); + CodeLog(" mov byte ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); switch (AddrReg) { case x86_EAX: AddCode16(0x80C6); break; @@ -759,7 +764,7 @@ void CX86Ops::MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg) void CX86Ops::MoveConstByteToVariable(uint8_t Const, void *Variable, const char * VariableName) { - CPU_Message(" mov byte ptr [%s], %Xh", VariableName, Const); + CodeLog(" mov byte ptr [%s], %Xh", VariableName, Const); AddCode16(0x05C6); AddCode32((uint32_t)Variable); AddCode8(Const); @@ -767,7 +772,7 @@ void CX86Ops::MoveConstByteToVariable(uint8_t Const, void *Variable, const char void CX86Ops::MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg) { - CPU_Message(" mov word ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); + CodeLog(" mov word ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); AddCode8(0x66); switch (AddrReg) { @@ -788,7 +793,7 @@ void CX86Ops::MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg) void CX86Ops::MoveConstHalfToVariable(uint16_t Const, void *Variable, const char * VariableName) { - CPU_Message(" mov word ptr [%s], %Xh", VariableName, Const); + CodeLog(" mov word ptr [%s], %Xh", VariableName, Const); AddCode8(0x66); AddCode16(0x05C7); AddCode32((uint32_t)Variable); @@ -799,7 +804,7 @@ void CX86Ops::MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86R { uint8_t Param = 0; - CPU_Message(" mov word ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); + CodeLog(" mov word ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); AddCode8(0x66); AddCode16(0x04C7); @@ -835,7 +840,7 @@ void CX86Ops::MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86R void CX86Ops::MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Disp) { - CPU_Message(" mov dword ptr [%s+%Xh], %Xh", x86_Name(AddrReg), Disp, Const); + CodeLog(" mov dword ptr [%s+%Xh], %Xh", x86_Name(AddrReg), Disp, Const); switch (AddrReg) { case x86_EAX: AddCode16(0x80C7); break; @@ -855,7 +860,7 @@ void CX86Ops::MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Dis void CX86Ops::MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg) { - CPU_Message(" mov dword ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); + CodeLog(" mov dword ptr [%s+N64mem], %Xh", x86_Name(AddrReg), Const); switch (AddrReg) { case x86_EAX: AddCode16(0x80C7); break; @@ -875,7 +880,7 @@ void CX86Ops::MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg) void CX86Ops::MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp) { - CPU_Message(" mov dword ptr [%s+N64mem+%Xh], %Xh", x86_Name(AddrReg), Const, Disp); + CodeLog(" mov dword ptr [%s+N64mem+%Xh], %Xh", x86_Name(AddrReg), Const, Disp); switch (AddrReg) { case x86_EAX: AddCode16(0x80C7); break; @@ -895,7 +900,7 @@ void CX86Ops::MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp void CX86Ops::MoveConstToVariable(uint32_t Const, void *Variable, const char * VariableName) { - CPU_Message(" mov dword ptr [%s], %Xh", VariableName, Const); + CodeLog(" mov dword ptr [%s], %Xh", VariableName, Const); AddCode16(0x05C7); AddCode32((uint32_t)Variable); AddCode32(Const); @@ -903,7 +908,7 @@ void CX86Ops::MoveConstToVariable(uint32_t Const, void *Variable, const char * V void CX86Ops::MoveConstToX86Pointer(uint32_t Const, x86Reg X86Pointer) { - CPU_Message(" mov dword ptr [%s], %Xh", x86_Name(X86Pointer), Const); + CodeLog(" mov dword ptr [%s], %Xh", x86_Name(X86Pointer), Const); AddCode16((uint16_t)(0x00C7 + (X86Pointer * 0x100))); AddCode32(Const); } @@ -916,7 +921,7 @@ void CX86Ops::MoveConstToX86reg(uint32_t Const, x86Reg reg) } else { - CPU_Message(" mov %s, %Xh", x86_Name(reg), Const); + CodeLog(" mov %s, %Xh", x86_Name(reg), Const); AddCode16((uint16_t)(0xC0C7 + (reg * 0x100))); AddCode32(Const); } @@ -926,7 +931,7 @@ void CX86Ops::MoveConstByteToX86regPointer(uint8_t Const, x86Reg AddrReg1, x86Re { uint8_t Param = 0; - CPU_Message(" mov byte ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); + CodeLog(" mov byte ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); AddCode16(0x04C6); @@ -963,7 +968,7 @@ void CX86Ops::MoveConstToX86regPointer(uint32_t Const, x86Reg AddrReg1, x86Reg A { uint8_t Param = 0; - CPU_Message(" mov dword ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); + CodeLog(" mov dword ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); AddCode16(0x04C7); @@ -998,7 +1003,7 @@ void CX86Ops::MoveN64MemDispToX86reg(x86Reg reg, x86Reg AddrReg, uint8_t Disp) { uint16_t x86Command = 0; - CPU_Message(" mov %s, dword ptr [%s+N64mem+%Xh]", x86_Name(reg), x86_Name(AddrReg), Disp); + CodeLog(" mov %s, dword ptr [%s+N64mem+%Xh]", x86_Name(reg), x86_Name(AddrReg), Disp); switch (AddrReg) { case x86_EAX: x86Command = 0x008B; break; @@ -1031,7 +1036,7 @@ void CX86Ops::MoveN64MemToX86reg(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov %s, dword ptr [%s+N64mem]", x86_Name(reg), x86_Name(AddrReg)); + CodeLog(" mov %s, dword ptr [%s+N64mem]", x86_Name(reg), x86_Name(AddrReg)); switch (AddrReg) { @@ -1065,7 +1070,7 @@ void CX86Ops::MoveN64MemToX86regByte(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov %s, byte ptr [%s+N64mem]", x86_ByteName(reg), x86_Name(AddrReg)); + CodeLog(" mov %s, byte ptr [%s+N64mem]", x86_ByteName(reg), x86_Name(AddrReg)); switch (AddrReg) { case x86_EAX: x86Command = 0x008A; break; @@ -1100,7 +1105,7 @@ void CX86Ops::MoveN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov %s, word ptr [%s+N64mem]", x86_HalfName(reg), x86_Name(AddrReg)); + CodeLog(" mov %s, word ptr [%s+N64mem]", x86_HalfName(reg), x86_Name(AddrReg)); AddCode8(0x66); switch (AddrReg) @@ -1135,7 +1140,7 @@ void CX86Ops::MoveSxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, { uint8_t Param = 0; - CPU_Message(" movsx %s, byte ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" movsx %s, byte ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); AddCode16(0xBE0F); switch (reg) @@ -1184,7 +1189,7 @@ void CX86Ops::MoveSxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, { uint8_t Param = 0; - CPU_Message(" movsx %s, word ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" movsx %s, word ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); AddCode16(0xBF0F); switch (reg) @@ -1233,7 +1238,7 @@ void CX86Ops::MoveSxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" movsx %s, byte ptr [%s+Dmem]", x86_Name(reg), x86_Name(AddrReg)); + CodeLog(" movsx %s, byte ptr [%s+Dmem]", x86_Name(reg), x86_Name(AddrReg)); switch (AddrReg) { case x86_EAX: x86Command = 0x00BE; break; @@ -1270,7 +1275,7 @@ void CX86Ops::MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" movsx %s, word ptr [%s+Dmem]", x86_Name(reg), x86_Name(AddrReg)); + CodeLog(" movsx %s, word ptr [%s+Dmem]", x86_Name(reg), x86_Name(AddrReg)); switch (AddrReg) { @@ -1304,7 +1309,7 @@ void CX86Ops::MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg) void CX86Ops::MoveSxVariableToX86regByte(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" movsx %s, byte ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" movsx %s, byte ptr [%s]", x86_Name(reg), VariableName); AddCode16(0xbe0f); @@ -1326,7 +1331,7 @@ void CX86Ops::MoveSxVariableToX86regByte(void *Variable, const char * VariableNa void CX86Ops::MoveSxVariableToX86regHalf(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" movsx %s, word ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" movsx %s, word ptr [%s]", x86_Name(reg), VariableName); AddCode16(0xbf0f); @@ -1348,7 +1353,7 @@ void CX86Ops::MoveSxVariableToX86regHalf(void *Variable, const char * VariableNa void CX86Ops::MoveVariableToX86reg(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" mov %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" mov %s, dword ptr [%s]", x86_Name(reg), VariableName); switch (reg) { case x86_EAX: AddCode16(0x058B); break; @@ -1368,7 +1373,7 @@ void CX86Ops::MoveVariableToX86reg(void *Variable, const char * VariableName, x8 void CX86Ops::MoveVariableDispToX86Reg(void *Variable, const char * VariableName, x86Reg reg, x86Reg AddrReg, int Multiplier) { int x = 0; - CPU_Message(" mov %s, dword ptr [%s+%s*%i]", x86_Name(reg), VariableName, x86_Name(AddrReg), Multiplier); + CodeLog(" mov %s, dword ptr [%s+%s*%i]", x86_Name(reg), VariableName, x86_Name(AddrReg), Multiplier); AddCode8(0x8B); @@ -1417,7 +1422,7 @@ void CX86Ops::MoveVariableDispToX86Reg(void *Variable, const char * VariableName void CX86Ops::MoveVariableToX86regByte(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" mov %s, byte ptr [%s]", x86_ByteName(reg), VariableName); + CodeLog(" mov %s, byte ptr [%s]", x86_ByteName(reg), VariableName); switch (reg) { @@ -1433,7 +1438,7 @@ void CX86Ops::MoveVariableToX86regByte(void *Variable, const char * VariableName void CX86Ops::MoveVariableToX86regHalf(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" mov %s, word ptr [%s]", x86_HalfName(reg), VariableName); + CodeLog(" mov %s, word ptr [%s]", x86_HalfName(reg), VariableName); AddCode8(0x66); switch (reg) @@ -1456,7 +1461,7 @@ void CX86Ops::MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov byte ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_ByteName(reg)); + CodeLog(" mov byte ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_ByteName(reg)); switch (AddrReg) { @@ -1485,7 +1490,7 @@ void CX86Ops::MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg) void CX86Ops::MoveX86regByteToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" mov byte ptr [%s], %s", VariableName, x86_ByteName(reg)); + CodeLog(" mov byte ptr [%s], %s", VariableName, x86_ByteName(reg)); switch (reg) { @@ -1503,7 +1508,7 @@ void CX86Ops::MoveX86regByteToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg { uint8_t Param = 0; - CPU_Message(" mov byte ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_ByteName(reg)); + CodeLog(" mov byte ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_ByteName(reg)); switch (reg) { @@ -1551,7 +1556,7 @@ void CX86Ops::MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov word ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_HalfName(reg)); + CodeLog(" mov word ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_HalfName(reg)); AddCode8(0x66); switch (AddrReg) @@ -1586,7 +1591,7 @@ void CX86Ops::MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg) void CX86Ops::MoveX86regHalfToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" mov word ptr [%s], %s", VariableName, x86_HalfName(reg)); + CodeLog(" mov word ptr [%s], %s", VariableName, x86_HalfName(reg)); AddCode8(0x66); switch (reg) { @@ -1608,7 +1613,7 @@ void CX86Ops::MoveX86regHalfToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg { uint8_t Param = 0; - CPU_Message(" mov word ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_HalfName(reg)); + CodeLog(" mov word ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_HalfName(reg)); AddCode8(0x66); switch (reg) @@ -1657,7 +1662,7 @@ void CX86Ops::MoveX86PointerToX86reg(x86Reg reg, x86Reg X86Pointer) { uint16_t x86Command = 0; - CPU_Message(" mov %s, dword ptr [%s]", x86_Name(reg), x86_Name(X86Pointer)); + CodeLog(" mov %s, dword ptr [%s]", x86_Name(reg), x86_Name(X86Pointer)); switch (X86Pointer) { @@ -1691,7 +1696,7 @@ void CX86Ops::MoveX86PointerToX86regDisp(x86Reg reg, x86Reg X86Pointer, uint8_t { uint16_t x86Command = 0; - CPU_Message(" mov %s, dword ptr [%s] + %d", x86_Name(reg), x86_Name(X86Pointer), Disp); + CodeLog(" mov %s, dword ptr [%s] + %d", x86_Name(reg), x86_Name(X86Pointer), Disp); switch (X86Pointer) { @@ -1726,7 +1731,7 @@ void CX86Ops::MoveX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg { uint8_t Param = 0; - CPU_Message(" mov %s, dword ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" mov %s, dword ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); switch (reg) { @@ -1774,7 +1779,7 @@ void CX86Ops::MoveX86regPointerToX86regDisp8(x86Reg AddrReg1, x86Reg AddrReg2, x { uint8_t Param = 0; - CPU_Message(" mov %s, dword ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" mov %s, dword ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); switch (reg) { @@ -1823,7 +1828,7 @@ void CX86Ops::MoveX86regToMemory(x86Reg reg, x86Reg AddrReg, uint32_t Disp) { uint16_t x86Command = 0; - CPU_Message(" mov dword ptr [%s+%X], %s", x86_Name(AddrReg), Disp, x86_Name(reg)); + CodeLog(" mov dword ptr [%s+%X], %s", x86_Name(AddrReg), Disp, x86_Name(reg)); switch (AddrReg) { case x86_EAX: x86Command = 0x0089; break; @@ -1858,7 +1863,7 @@ void CX86Ops::MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" mov dword ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_Name(reg)); + CodeLog(" mov dword ptr [%s+N64mem], %s", x86_Name(AddrReg), x86_Name(reg)); switch (AddrReg) { case x86_EAX: x86Command = 0x0089; break; @@ -1891,7 +1896,7 @@ void CX86Ops::MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg) void CX86Ops::MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp) { - CPU_Message(" mov dword ptr [%s+N64mem+%d], %s", x86_Name(AddrReg), Disp, x86_Name(reg)); + CodeLog(" mov dword ptr [%s+N64mem+%d], %s", x86_Name(AddrReg), Disp, x86_Name(reg)); uint16_t x86Command = 0; switch (AddrReg) @@ -1926,7 +1931,7 @@ void CX86Ops::MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp) void CX86Ops::MoveX86regToVariable(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" mov dword ptr [%s], %s", VariableName, x86_Name(reg)); + CodeLog(" mov dword ptr [%s], %s", VariableName, x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0x0589); break; @@ -1951,7 +1956,7 @@ void CX86Ops::MoveX86RegToX86Reg(x86Reg Source, x86Reg Destination) { return; } - CPU_Message(" mov %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" mov %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Destination) { @@ -1987,7 +1992,7 @@ void CX86Ops::MoveX86regToX86Pointer(x86Reg reg, x86Reg X86Pointer) { uint16_t x86Command = 0; - CPU_Message(" mov dword ptr [%s], %s", x86_Name(X86Pointer), x86_Name(reg)); + CodeLog(" mov dword ptr [%s], %s", x86_Name(X86Pointer), x86_Name(reg)); switch (X86Pointer) { @@ -2021,7 +2026,7 @@ void CX86Ops::MoveX86regToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg Addr { uint8_t Param = 0; - CPU_Message(" mov dword ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_Name(reg)); + CodeLog(" mov dword ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_Name(reg)); switch (reg) { @@ -2069,7 +2074,7 @@ void CX86Ops::MoveZxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, { uint8_t Param = 0; - CPU_Message(" movzx %s, byte ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" movzx %s, byte ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); AddCode16(0xB60F); switch (reg) @@ -2118,7 +2123,7 @@ void CX86Ops::MoveZxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, { uint8_t Param = 0; - CPU_Message(" movzx %s, word ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); + CodeLog(" movzx %s, word ptr [%s+%s]", x86_Name(reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); AddCode16(0xB70F); switch (reg) @@ -2167,7 +2172,7 @@ void CX86Ops::MoveZxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" movzx %s, byte ptr [%s+g_MMU->Rdram()]", x86_Name(reg), x86_Name(AddrReg)); + CodeLog(" movzx %s, byte ptr [%s+g_MMU->Rdram()]", x86_Name(reg), x86_Name(AddrReg)); switch (AddrReg) { case x86_EAX: x86Command = 0x00B6; break; @@ -2204,7 +2209,7 @@ void CX86Ops::MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg) { uint16_t x86Command = 0; - CPU_Message(" movzx %s, word ptr [%s+g_MMU->Rdram()]", x86_Name(reg), x86_Name(AddrReg)); + CodeLog(" movzx %s, word ptr [%s+g_MMU->Rdram()]", x86_Name(reg), x86_Name(AddrReg)); switch (AddrReg) { @@ -2240,7 +2245,7 @@ void CX86Ops::MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg) void CX86Ops::MoveZxVariableToX86regByte(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" movzx %s, byte ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" movzx %s, byte ptr [%s]", x86_Name(reg), VariableName); AddCode16(0xb60f); @@ -2262,7 +2267,7 @@ void CX86Ops::MoveZxVariableToX86regByte(void *Variable, const char * VariableNa void CX86Ops::MoveZxVariableToX86regHalf(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" movzx %s, word ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" movzx %s, word ptr [%s]", x86_Name(reg), VariableName); AddCode16(0xb70f); @@ -2284,7 +2289,7 @@ void CX86Ops::MoveZxVariableToX86regHalf(void *Variable, const char * VariableNa void CX86Ops::MulX86reg(x86Reg reg) { - CPU_Message(" mul %s", x86_Name(reg)); + CodeLog(" mul %s", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0xE0F7); break; @@ -2302,7 +2307,7 @@ void CX86Ops::MulX86reg(x86Reg reg) void CX86Ops::NotX86Reg(x86Reg reg) { - CPU_Message(" not %s", x86_Name(reg)); + CodeLog(" not %s", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0xD0F7); break; @@ -2320,7 +2325,7 @@ void CX86Ops::NotX86Reg(x86Reg reg) void CX86Ops::OrConstToVariable(uint32_t Const, void * Variable, const char * VariableName) { - CPU_Message(" or dword ptr [%s], 0x%X", VariableName, Const); + CodeLog(" or dword ptr [%s], 0x%X", VariableName, Const); AddCode16(0x0D81); AddCode32((uint32_t)(Variable)); AddCode32(Const); @@ -2332,7 +2337,7 @@ void CX86Ops::OrConstToX86Reg(uint32_t Const, x86Reg reg) { return; } - CPU_Message(" or %s, %Xh", x86_Name(reg), Const); + CodeLog(" or %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { switch (reg) { @@ -2370,7 +2375,7 @@ void CX86Ops::OrConstToX86Reg(uint32_t Const, x86Reg reg) void CX86Ops::OrVariableToX86Reg(void * Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" or %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" or %s, dword ptr [%s]", x86_Name(reg), VariableName); switch (reg) { case x86_EAX: AddCode16(0x050B); break; @@ -2389,7 +2394,7 @@ void CX86Ops::OrVariableToX86Reg(void * Variable, const char * VariableName, x86 void CX86Ops::OrX86RegToVariable(void * Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" or dword ptr [%s], %s", VariableName, x86_Name(reg)); + CodeLog(" or dword ptr [%s], %s", VariableName, x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0x0509); break; @@ -2410,7 +2415,7 @@ void CX86Ops::OrX86RegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" or %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" or %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Source) { case x86_EAX: x86Command = 0x000B; break; @@ -2442,19 +2447,19 @@ void CX86Ops::OrX86RegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::Popad(void) { - CPU_Message(" popad"); + CodeLog(" popad"); AddCode8(0x61); } void CX86Ops::Pushad(void) { - CPU_Message(" pushad"); + CodeLog(" pushad"); AddCode8(0x60); } void CX86Ops::Push(x86Reg reg) { - CPU_Message(" push %s", x86_Name(reg)); + CodeLog(" push %s", x86_Name(reg)); switch (reg) { @@ -2473,7 +2478,7 @@ void CX86Ops::Push(x86Reg reg) void CX86Ops::Pop(x86Reg reg) { - CPU_Message(" pop %s", x86_Name(reg)); + CodeLog(" pop %s", x86_Name(reg)); switch (reg) { @@ -2504,19 +2509,19 @@ void CX86Ops::PushImm32(uint32_t Value) void CX86Ops::PushImm32(const char * String, uint32_t Value) { - CPU_Message(" push %s", String); + CodeLog(" push %s", String); AddCode8(0x68); AddCode32(Value); } void CX86Ops::Ret(void) { - CPU_Message(" ret"); + CodeLog(" ret"); AddCode8(0xC3); } void CX86Ops::Seta(x86Reg reg) { - CPU_Message(" seta %s", x86_ByteName(reg)); + CodeLog(" seta %s", x86_ByteName(reg)); AddCode16(0x970F); switch (reg) { @@ -2531,7 +2536,7 @@ void CX86Ops::Seta(x86Reg reg) void CX86Ops::SetaVariable(void * Variable, const char * VariableName) { - CPU_Message(" seta byte ptr [%s]", VariableName); + CodeLog(" seta byte ptr [%s]", VariableName); AddCode16(0x970F); AddCode8(0x05); AddCode32((uint32_t)(Variable)); @@ -2539,7 +2544,7 @@ void CX86Ops::SetaVariable(void * Variable, const char * VariableName) void CX86Ops::Setae(x86Reg reg) { - CPU_Message(" setae %s", x86_ByteName(reg)); + CodeLog(" setae %s", x86_ByteName(reg)); AddCode16(0x930F); switch (reg) { @@ -2554,7 +2559,7 @@ void CX86Ops::Setae(x86Reg reg) void CX86Ops::Setb(x86Reg reg) { - CPU_Message(" setb %s", x86_ByteName(reg)); + CodeLog(" setb %s", x86_ByteName(reg)); AddCode16(0x920F); switch (reg) { @@ -2569,7 +2574,7 @@ void CX86Ops::Setb(x86Reg reg) void CX86Ops::SetbVariable(void * Variable, const char * VariableName) { - CPU_Message(" setb byte ptr [%s]", VariableName); + CodeLog(" setb byte ptr [%s]", VariableName); AddCode16(0x920F); AddCode8(0x05); AddCode32((uint32_t)(Variable)); @@ -2577,7 +2582,7 @@ void CX86Ops::SetbVariable(void * Variable, const char * VariableName) void CX86Ops::Setg(x86Reg reg) { - CPU_Message(" setg %s", x86_ByteName(reg)); + CodeLog(" setg %s", x86_ByteName(reg)); AddCode16(0x9F0F); switch (reg) { @@ -2592,7 +2597,7 @@ void CX86Ops::Setg(x86Reg reg) void CX86Ops::SetgVariable(void * Variable, const char * VariableName) { - CPU_Message(" setg byte ptr [%s]", VariableName); + CodeLog(" setg byte ptr [%s]", VariableName); AddCode16(0x9F0F); AddCode8(0x05); AddCode32((uint32_t)Variable); @@ -2600,7 +2605,7 @@ void CX86Ops::SetgVariable(void * Variable, const char * VariableName) void CX86Ops::Setl(x86Reg reg) { - CPU_Message(" setl %s", x86_ByteName(reg)); + CodeLog(" setl %s", x86_ByteName(reg)); AddCode16(0x9C0F); switch (reg) { @@ -2615,7 +2620,7 @@ void CX86Ops::Setl(x86Reg reg) void CX86Ops::SetlVariable(void * Variable, const char * VariableName) { - CPU_Message(" setl byte ptr [%s]", VariableName); + CodeLog(" setl byte ptr [%s]", VariableName); AddCode16(0x9C0F); AddCode8(0x05); AddCode32((uint32_t)Variable); @@ -2623,7 +2628,7 @@ void CX86Ops::SetlVariable(void * Variable, const char * VariableName) void CX86Ops::Setz(x86Reg reg) { - CPU_Message(" setz %s", x86_ByteName(reg)); + CodeLog(" setz %s", x86_ByteName(reg)); AddCode16(0x940F); switch (reg) { @@ -2638,7 +2643,7 @@ void CX86Ops::Setz(x86Reg reg) void CX86Ops::Setnz(x86Reg reg) { - CPU_Message(" setnz %s", x86_ByteName(reg)); + CodeLog(" setnz %s", x86_ByteName(reg)); AddCode16(0x950F); switch (reg) { @@ -2655,7 +2660,7 @@ void CX86Ops::ShiftLeftDouble(x86Reg Destination, x86Reg Source) { uint8_t s = 0xC0; - CPU_Message(" shld %s, %s, cl", x86_Name(Destination), x86_Name(Source)); + CodeLog(" shld %s, %s, cl", x86_Name(Destination), x86_Name(Source)); AddCode16(0xA50F); switch (Destination) @@ -2693,7 +2698,7 @@ void CX86Ops::ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Im { uint8_t s = 0xC0; - CPU_Message(" shld %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); + CodeLog(" shld %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); AddCode16(0xA40F); switch (Destination) @@ -2730,7 +2735,7 @@ void CX86Ops::ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Im void CX86Ops::ShiftLeftSign(x86Reg reg) { - CPU_Message(" shl %s, cl", x86_Name(reg)); + CodeLog(" shl %s, cl", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0xE0D3); break; @@ -2748,7 +2753,7 @@ void CX86Ops::ShiftLeftSign(x86Reg reg) void CX86Ops::ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate) { - CPU_Message(" shl %s, %Xh", x86_Name(reg), Immediate); + CodeLog(" shl %s, %Xh", x86_Name(reg), Immediate); switch (reg) { case x86_EAX: AddCode16(0xE0C1); break; @@ -2767,7 +2772,7 @@ void CX86Ops::ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate) void CX86Ops::ShiftRightSign(x86Reg reg) { - CPU_Message(" sar %s, cl", x86_Name(reg)); + CodeLog(" sar %s, cl", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0xF8D3); break; @@ -2785,7 +2790,7 @@ void CX86Ops::ShiftRightSign(x86Reg reg) void CX86Ops::ShiftRightSignImmed(x86Reg reg, uint8_t Immediate) { - CPU_Message(" sar %s, %Xh", x86_Name(reg), Immediate); + CodeLog(" sar %s, %Xh", x86_Name(reg), Immediate); switch (reg) { case x86_EAX: AddCode16(0xF8C1); break; @@ -2804,7 +2809,7 @@ void CX86Ops::ShiftRightSignImmed(x86Reg reg, uint8_t Immediate) void CX86Ops::ShiftRightUnsign(x86Reg reg) { - CPU_Message(" shr %s, cl", x86_Name(reg)); + CodeLog(" shr %s, cl", x86_Name(reg)); switch (reg) { case x86_EAX: AddCode16(0xE8D3); break; @@ -2824,7 +2829,7 @@ void CX86Ops::ShiftRightDouble(x86Reg Destination, x86Reg Source) { uint8_t s = 0xC0; - CPU_Message(" shrd %s, %s, cl", x86_Name(Destination), x86_Name(Source)); + CodeLog(" shrd %s, %s, cl", x86_Name(Destination), x86_Name(Source)); AddCode16(0xAD0F); switch (Destination) @@ -2862,7 +2867,7 @@ void CX86Ops::ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t I { uint8_t s = 0xC0; - CPU_Message(" shrd %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); + CodeLog(" shrd %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); AddCode16(0xAC0F); switch (Destination) @@ -2899,7 +2904,7 @@ void CX86Ops::ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t I void CX86Ops::ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate) { - CPU_Message(" shr %s, %Xh", x86_Name(reg), Immediate); + CodeLog(" shr %s, %Xh", x86_Name(reg), Immediate); switch (reg) { case x86_EAX: AddCode16(0xE8C1); break; @@ -2918,7 +2923,7 @@ void CX86Ops::ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate) void CX86Ops::SbbConstFromX86Reg(x86Reg reg, uint32_t Const) { - CPU_Message(" sbb %s, %Xh", x86_Name(reg), Const); + CodeLog(" sbb %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { switch (reg) @@ -2957,7 +2962,7 @@ void CX86Ops::SbbConstFromX86Reg(x86Reg reg, uint32_t Const) void CX86Ops::SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" sbb %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" sbb %s, dword ptr [%s]", x86_Name(reg), VariableName); switch (reg) { case x86_EAX: AddCode16(0x051B); break; @@ -2977,7 +2982,7 @@ void CX86Ops::SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * Va void CX86Ops::SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" sbb %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" sbb %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Source) { case x86_EAX: x86Command = 0x001B; break; @@ -3009,7 +3014,7 @@ void CX86Ops::SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::SubConstFromVariable(uint32_t Const, void *Variable, const char * VariableName) { - CPU_Message(" sub dword ptr [%s], 0x%X", VariableName, Const); + CodeLog(" sub dword ptr [%s], 0x%X", VariableName, Const); AddCode16(0x2D81); AddCode32((uint32_t)Variable); @@ -3018,7 +3023,7 @@ void CX86Ops::SubConstFromVariable(uint32_t Const, void *Variable, const char * void CX86Ops::SubConstFromX86Reg(x86Reg reg, uint32_t Const) { - CPU_Message(" sub %s, %Xh", x86_Name(reg), Const); + CodeLog(" sub %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { switch (reg) @@ -3057,7 +3062,7 @@ void CX86Ops::SubConstFromX86Reg(x86Reg reg, uint32_t Const) void CX86Ops::SubVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName) { - CPU_Message(" sub %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" sub %s, dword ptr [%s]", x86_Name(reg), VariableName); switch (reg) { @@ -3078,7 +3083,7 @@ void CX86Ops::SubVariableFromX86reg(x86Reg reg, void * Variable, const char * Va void CX86Ops::SubX86RegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" sub %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" sub %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Source) { @@ -3112,7 +3117,7 @@ void CX86Ops::SubX86RegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::TestConstToX86Reg(uint32_t Const, x86Reg reg) { - CPU_Message(" test %s, 0x%X", x86_Name(reg), Const); + CodeLog(" test %s, 0x%X", x86_Name(reg), Const); switch (reg) { @@ -3132,7 +3137,7 @@ void CX86Ops::TestConstToX86Reg(uint32_t Const, x86Reg reg) void CX86Ops::TestVariable(uint32_t Const, void * Variable, const char * VariableName) { - CPU_Message(" test dword ptr ds:[%s], 0x%X", VariableName, Const); + CodeLog(" test dword ptr ds:[%s], 0x%X", VariableName, Const); AddCode16(0x05F7); AddCode32((uint32_t)Variable); AddCode32(Const); @@ -3141,7 +3146,7 @@ void CX86Ops::TestVariable(uint32_t Const, void * Variable, const char * Variabl void CX86Ops::TestX86RegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" test %s, %s", x86_Name(Destination), x86_Name(Source)); + CodeLog(" test %s, %s", x86_Name(Destination), x86_Name(Source)); switch (Source) { case x86_EAX: x86Command = 0x0085; break; @@ -3174,7 +3179,7 @@ void CX86Ops::TestX86RegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source) { uint16_t x86Command = 0; - CPU_Message(" test %s, %s", x86_ByteName(Destination), x86_ByteName(Source)); + CodeLog(" test %s, %s", x86_ByteName(Destination), x86_ByteName(Source)); switch (Source) { case x86_AL: x86Command = 0x0084; break; @@ -3198,7 +3203,7 @@ void CX86Ops::TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source) void CX86Ops::XorConstToX86Reg(x86Reg reg, uint32_t Const) { - CPU_Message(" xor %s, %Xh", x86_Name(reg), Const); + CodeLog(" xor %s, %Xh", x86_Name(reg), Const); if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) { switch (reg) @@ -3239,7 +3244,7 @@ void CX86Ops::XorX86RegToX86Reg(x86Reg Source, x86Reg Destination) { uint16_t x86Command = 0; - CPU_Message(" xor %s, %s", x86_Name(Source), x86_Name(Destination)); + CodeLog(" xor %s, %s", x86_Name(Source), x86_Name(Destination)); switch (Source) { @@ -3272,7 +3277,7 @@ void CX86Ops::XorX86RegToX86Reg(x86Reg Source, x86Reg Destination) void CX86Ops::XorVariableToX86reg(void *Variable, const char * VariableName, x86Reg reg) { - CPU_Message(" Xor %s, dword ptr [%s]", x86_Name(reg), VariableName); + CodeLog(" Xor %s, dword ptr [%s]", x86_Name(reg), VariableName); switch (reg) { @@ -3292,20 +3297,20 @@ void CX86Ops::XorVariableToX86reg(void *Variable, const char * VariableName, x86 void CX86Ops::fpuAbs(void) { - CPU_Message(" fabs ST(0)"); + CodeLog(" fabs ST(0)"); AddCode16(0xE1D9); } void CX86Ops::fpuAddDword(void *Variable, const char * VariableName) { - CPU_Message(" fadd ST(0), dword ptr [%s]", VariableName); + CodeLog(" fadd ST(0), dword ptr [%s]", VariableName); AddCode16(0x05D8); AddCode32((uint32_t)Variable); } void CX86Ops::fpuAddDwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fadd ST(0), dword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fadd ST(0), dword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x00D8); break; @@ -3322,14 +3327,14 @@ void CX86Ops::fpuAddDwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuAddQword(void *Variable, const char * VariableName) { - CPU_Message(" fadd ST(0), qword ptr [%s]", VariableName); + CodeLog(" fadd ST(0), qword ptr [%s]", VariableName); AddCode16(0x05DC); AddCode32((uint32_t)Variable); } void CX86Ops::fpuAddQwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fadd ST(0), qword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fadd ST(0), qword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x00DC); break; @@ -3346,7 +3351,7 @@ void CX86Ops::fpuAddQwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuAddReg(x86FpuValues x86reg) { - CPU_Message(" fadd ST(0), %s", fpu_Name(x86reg)); + CodeLog(" fadd ST(0), %s", fpu_Name(x86reg)); switch (x86reg) { case x86_ST0: AddCode16(0xC0D8); break; case x86_ST1: AddCode16(0xC1D8); break; @@ -3364,7 +3369,7 @@ void CX86Ops::fpuAddReg(x86FpuValues x86reg) void CX86Ops::fpuAddRegPop(int * StackPos, x86FpuValues reg) { - CPU_Message(" faddp ST(0), %s", fpu_Name(reg)); + CodeLog(" faddp ST(0), %s", fpu_Name(reg)); *StackPos = (*StackPos + 1) & 7; switch (reg) { @@ -3384,7 +3389,7 @@ void CX86Ops::fpuAddRegPop(int * StackPos, x86FpuValues reg) void CX86Ops::fpuComDword(void *Variable, const char * VariableName, bool Pop) { - CPU_Message(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], VariableName); + CodeLog(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], VariableName); AddCode16(Pop ? 0x1DD8 : 0x15D8); AddCode32((uint32_t)Variable); } @@ -3393,7 +3398,7 @@ void CX86Ops::fpuComDwordRegPointer(x86Reg x86Pointer, bool Pop) { uint16_t x86Command; - CPU_Message(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); + CodeLog(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: x86Command = 0x10D8; break; @@ -3416,7 +3421,7 @@ void CX86Ops::fpuComDwordRegPointer(x86Reg x86Pointer, bool Pop) void CX86Ops::fpuComQword(void *Variable, const char * VariableName, bool Pop) { - CPU_Message(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], VariableName); + CodeLog(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], VariableName); AddCode16(Pop ? 0x1DDC : 0x15DC); AddCode32((uint32_t)Variable); } @@ -3425,7 +3430,7 @@ void CX86Ops::fpuComQwordRegPointer(x86Reg x86Pointer, bool Pop) { uint16_t x86Command; - CPU_Message(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); + CodeLog(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: x86Command = 0x10DC; break; @@ -3449,7 +3454,7 @@ void CX86Ops::fpuComQwordRegPointer(x86Reg x86Pointer, bool Pop) void CX86Ops::fpuComReg(x86FpuValues x86reg, bool Pop) { int s = Pop ? 0x0800 : 0x0000; - CPU_Message(" fcom%s ST(0), %s", m_fpupop[Pop], fpu_Name(x86reg)); + CodeLog(" fcom%s ST(0), %s", m_fpupop[Pop], fpu_Name(x86reg)); switch (x86reg) { @@ -3469,14 +3474,14 @@ void CX86Ops::fpuComReg(x86FpuValues x86reg, bool Pop) void CX86Ops::fpuDivDword(void *Variable, const char * VariableName) { - CPU_Message(" fdiv ST(0), dword ptr [%s]", VariableName); + CodeLog(" fdiv ST(0), dword ptr [%s]", VariableName); AddCode16(0x35D8); AddCode32((uint32_t)Variable); } void CX86Ops::fpuDivDwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fdiv ST(0), dword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fdiv ST(0), dword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x30D8); break; @@ -3493,14 +3498,14 @@ void CX86Ops::fpuDivDwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuDivQword(void *Variable, const char * VariableName) { - CPU_Message(" fdiv ST(0), qword ptr [%s]", VariableName); + CodeLog(" fdiv ST(0), qword ptr [%s]", VariableName); AddCode16(0x35DC); AddCode32((uint32_t)Variable); } void CX86Ops::fpuDivQwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fdiv ST(0), qword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fdiv ST(0), qword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x30DC); break; @@ -3517,7 +3522,7 @@ void CX86Ops::fpuDivQwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuDivReg(x86FpuValues Reg) { - CPU_Message(" fdiv ST(0), %s", fpu_Name(Reg)); + CodeLog(" fdiv ST(0), %s", fpu_Name(Reg)); switch (Reg) { case x86_ST0: AddCode16(0xF0D8); break; @@ -3536,7 +3541,7 @@ void CX86Ops::fpuDivReg(x86FpuValues Reg) void CX86Ops::fpuDivRegPop(x86FpuValues reg) { - CPU_Message(" fdivp ST(0), %s", fpu_Name(reg)); + CodeLog(" fdivp ST(0), %s", fpu_Name(reg)); switch (reg) { case x86_ST0: AddCode16(0xF8DE); break; @@ -3555,7 +3560,7 @@ void CX86Ops::fpuDivRegPop(x86FpuValues reg) void CX86Ops::fpuExchange(x86FpuValues Reg) { - CPU_Message(" fxch ST(0), %s", fpu_Name(Reg)); + CodeLog(" fxch ST(0), %s", fpu_Name(Reg)); switch (Reg) { case x86_ST0: AddCode16(0xC8D9); break; @@ -3574,7 +3579,7 @@ void CX86Ops::fpuExchange(x86FpuValues Reg) void CX86Ops::fpuFree(x86FpuValues Reg) { - CPU_Message(" ffree %s", fpu_Name(Reg)); + CodeLog(" ffree %s", fpu_Name(Reg)); switch (Reg) { case x86_ST0: AddCode16(0xC0DD); break; @@ -3593,28 +3598,28 @@ void CX86Ops::fpuFree(x86FpuValues Reg) void CX86Ops::fpuDecStack(int * StackPos) { - CPU_Message(" fdecstp"); + CodeLog(" fdecstp"); *StackPos = (*StackPos - 1) & 7; AddCode16(0xF6D9); } void CX86Ops::fpuIncStack(int * StackPos) { - CPU_Message(" fincstp"); + CodeLog(" fincstp"); *StackPos = (*StackPos + 1) & 7; AddCode16(0xF7D9); } void CX86Ops::fpuLoadControl(void *Variable, const char * VariableName) { - CPU_Message(" fldcw [%s]", VariableName); + CodeLog(" fldcw [%s]", VariableName); AddCode16(0x2DD9); AddCode32((uint32_t)Variable); } void CX86Ops::fpuLoadDword(int * StackPos, void *Variable, const char * VariableName) { - CPU_Message(" fld dword ptr [%s]", VariableName); + CodeLog(" fld dword ptr [%s]", VariableName); *StackPos = (*StackPos - 1) & 7; AddCode16(0x05D9); AddCode32((uint32_t)Variable); @@ -3622,7 +3627,7 @@ void CX86Ops::fpuLoadDword(int * StackPos, void *Variable, const char * Variable void CX86Ops::fpuLoadDwordFromX86Reg(int * StackPos, x86Reg x86reg) { - CPU_Message(" fld dword ptr [%s]", x86_Name(x86reg)); + CodeLog(" fld dword ptr [%s]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; AddCode8(0xD9); switch (x86reg) @@ -3640,7 +3645,7 @@ void CX86Ops::fpuLoadDwordFromX86Reg(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadDwordFromN64Mem(int * StackPos, x86Reg x86reg) { - CPU_Message(" fld dword ptr [%s+N64mem]", x86_Name(x86reg)); + CodeLog(" fld dword ptr [%s+N64mem]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; switch (x86reg) { @@ -3659,7 +3664,7 @@ void CX86Ops::fpuLoadDwordFromN64Mem(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadInt32bFromN64Mem(int * StackPos, x86Reg x86reg) { - CPU_Message(" fild dword ptr [%s+N64mem]", x86_Name(x86reg)); + CodeLog(" fild dword ptr [%s+N64mem]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; switch (x86reg) { @@ -3678,7 +3683,7 @@ void CX86Ops::fpuLoadInt32bFromN64Mem(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadIntegerDword(int * StackPos, void *Variable, const char * VariableName) { - CPU_Message(" fild dword ptr [%s]", VariableName); + CodeLog(" fild dword ptr [%s]", VariableName); *StackPos = (*StackPos - 1) & 7; AddCode16(0x05DB); AddCode32((uint32_t)Variable); @@ -3686,7 +3691,7 @@ void CX86Ops::fpuLoadIntegerDword(int * StackPos, void *Variable, const char * V void CX86Ops::fpuLoadIntegerDwordFromX86Reg(int * StackPos, x86Reg x86reg) { - CPU_Message(" fild dword ptr [%s]", x86_Name(x86reg)); + CodeLog(" fild dword ptr [%s]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; AddCode8(0xDB); switch (x86reg) @@ -3704,7 +3709,7 @@ void CX86Ops::fpuLoadIntegerDwordFromX86Reg(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadIntegerQword(int * StackPos, void *Variable, const char * VariableName) { - CPU_Message(" fild qword ptr [%s]", VariableName); + CodeLog(" fild qword ptr [%s]", VariableName); *StackPos = (*StackPos - 1) & 7; AddCode16(0x2DDF); AddCode32((uint32_t)Variable); @@ -3712,7 +3717,7 @@ void CX86Ops::fpuLoadIntegerQword(int * StackPos, void *Variable, const char * V void CX86Ops::fpuLoadIntegerQwordFromX86Reg(int * StackPos, x86Reg x86reg) { - CPU_Message(" fild qword ptr [%s]", x86_Name(x86reg)); + CodeLog(" fild qword ptr [%s]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; AddCode8(0xDF); switch (x86reg) @@ -3730,7 +3735,7 @@ void CX86Ops::fpuLoadIntegerQwordFromX86Reg(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadQword(int * StackPos, void *Variable, const char * VariableName) { - CPU_Message(" fld qword ptr [%s]", VariableName); + CodeLog(" fld qword ptr [%s]", VariableName); *StackPos = (*StackPos - 1) & 7; AddCode16(0x05DD); AddCode32((uint32_t)Variable); @@ -3738,7 +3743,7 @@ void CX86Ops::fpuLoadQword(int * StackPos, void *Variable, const char * Variable void CX86Ops::fpuLoadQwordFromX86Reg(int * StackPos, x86Reg x86reg) { - CPU_Message(" fld qword ptr [%s]", x86_Name(x86reg)); + CodeLog(" fld qword ptr [%s]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; AddCode8(0xDD); switch (x86reg) @@ -3756,7 +3761,7 @@ void CX86Ops::fpuLoadQwordFromX86Reg(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadQwordFromN64Mem(int * StackPos, x86Reg x86reg) { - CPU_Message(" fld qword ptr [%s+N64mem]", x86_Name(x86reg)); + CodeLog(" fld qword ptr [%s+N64mem]", x86_Name(x86reg)); *StackPos = (*StackPos - 1) & 7; switch (x86reg) { @@ -3775,7 +3780,7 @@ void CX86Ops::fpuLoadQwordFromN64Mem(int * StackPos, x86Reg x86reg) void CX86Ops::fpuLoadReg(int * StackPos, x86FpuValues Reg) { - CPU_Message(" fld ST(0), %s", fpu_Name(Reg)); + CodeLog(" fld ST(0), %s", fpu_Name(Reg)); *StackPos = (*StackPos - 1) & 7; switch (Reg) { @@ -3795,14 +3800,14 @@ void CX86Ops::fpuLoadReg(int * StackPos, x86FpuValues Reg) void CX86Ops::fpuMulDword(void *Variable, const char * VariableName) { - CPU_Message(" fmul ST(0), dword ptr [%s]", VariableName); + CodeLog(" fmul ST(0), dword ptr [%s]", VariableName); AddCode16(0x0DD8); AddCode32((uint32_t)Variable); } void CX86Ops::fpuMulDwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fmul ST(0), dword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fmul ST(0), dword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x08D8); break; @@ -3819,14 +3824,14 @@ void CX86Ops::fpuMulDwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuMulQword(void *Variable, const char * VariableName) { - CPU_Message(" fmul ST(0), qword ptr [%s]", VariableName); + CodeLog(" fmul ST(0), qword ptr [%s]", VariableName); AddCode16(0x0DDC); AddCode32((uint32_t)Variable); } void CX86Ops::fpuMulQwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fmul ST(0), qword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fmul ST(0), qword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x08DC); break; @@ -3843,7 +3848,7 @@ void CX86Ops::fpuMulQwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuMulReg(x86FpuValues x86reg) { - CPU_Message(" fmul ST(0), %s", fpu_Name(x86reg)); + CodeLog(" fmul ST(0), %s", fpu_Name(x86reg)); switch (x86reg) { case x86_ST0: AddCode16(0xC8D8); break; @@ -3862,7 +3867,7 @@ void CX86Ops::fpuMulReg(x86FpuValues x86reg) void CX86Ops::fpuMulRegPop(x86FpuValues x86reg) { - CPU_Message(" fmulp ST(0), %s", fpu_Name(x86reg)); + CodeLog(" fmulp ST(0), %s", fpu_Name(x86reg)); switch (x86reg) { case x86_ST0: AddCode16(0xC8DE); break; @@ -3881,32 +3886,32 @@ void CX86Ops::fpuMulRegPop(x86FpuValues x86reg) void CX86Ops::fpuNeg(void) { - CPU_Message(" fchs ST(0)"); + CodeLog(" fchs ST(0)"); AddCode16(0xE0D9); } void CX86Ops::fpuRound(void) { - CPU_Message(" frndint ST(0)"); + CodeLog(" frndint ST(0)"); AddCode16(0xFCD9); } void CX86Ops::fpuSqrt(void) { - CPU_Message(" fsqrt ST(0)"); + CodeLog(" fsqrt ST(0)"); AddCode16(0xFAD9); } void CX86Ops::fpuStoreControl(void *Variable, const char * VariableName) { - CPU_Message(" fnstcw [%s]", VariableName); + CodeLog(" fnstcw [%s]", VariableName); AddCode16(0x3DD9); AddCode32((uint32_t)Variable); } void CX86Ops::fpuStoreDword(int * StackPos, void *Variable, const char * VariableName, bool pop) { - CPU_Message(" fst%s dword ptr [%s]", m_fpupop[pop], VariableName); + CodeLog(" fst%s dword ptr [%s]", m_fpupop[pop], VariableName); if (pop) { @@ -3921,7 +3926,7 @@ void CX86Ops::fpuStoreDwordFromX86Reg(int * StackPos, x86Reg x86reg, bool pop) { uint8_t Command = 0; - CPU_Message(" fst%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); + CodeLog(" fst%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); if (pop) { @@ -3949,7 +3954,7 @@ void CX86Ops::fpuStoreDwordToN64Mem(int * StackPos, x86Reg x86reg, bool Pop) { int s = Pop ? 0x0800 : 0; - CPU_Message(" fst%s dword ptr [%s+N64mem]", m_fpupop[Pop], x86_Name(x86reg)); + CodeLog(" fst%s dword ptr [%s+N64mem]", m_fpupop[Pop], x86_Name(x86reg)); if (Pop) { @@ -3974,7 +3979,7 @@ void CX86Ops::fpuStoreDwordToN64Mem(int * StackPos, x86Reg x86reg, bool Pop) void CX86Ops::fpuStoreIntegerDword(int * StackPos, void *Variable, const char * VariableName, bool pop) { - CPU_Message(" fist%s dword ptr [%s]", m_fpupop[pop], VariableName); + CodeLog(" fist%s dword ptr [%s]", m_fpupop[pop], VariableName); if (pop) { @@ -3988,7 +3993,7 @@ void CX86Ops::fpuStoreIntegerDwordFromX86Reg(int * StackPos, x86Reg x86reg, bool { uint8_t Command = 0; - CPU_Message(" fist%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); + CodeLog(" fist%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); if (pop) { @@ -4014,7 +4019,7 @@ void CX86Ops::fpuStoreIntegerDwordFromX86Reg(int * StackPos, x86Reg x86reg, bool void CX86Ops::fpuStoreIntegerQword(int * StackPos, void *Variable, const char * VariableName, bool pop) { - CPU_Message(" fist%s qword ptr [%s]", m_fpupop[pop], VariableName); + CodeLog(" fist%s qword ptr [%s]", m_fpupop[pop], VariableName); if (pop) { @@ -4034,7 +4039,7 @@ void CX86Ops::fpuStoreIntegerQwordFromX86Reg(int * StackPos, x86Reg x86reg, bool { uint8_t Command = 0; - CPU_Message(" fist%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); + CodeLog(" fist%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); if (pop) { @@ -4061,7 +4066,7 @@ void CX86Ops::fpuStoreQwordFromX86Reg(int * StackPos, x86Reg x86reg, bool pop) { uint8_t Command = 0; - CPU_Message(" fst%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); + CodeLog(" fst%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); if (pop) { @@ -4087,20 +4092,20 @@ void CX86Ops::fpuStoreQwordFromX86Reg(int * StackPos, x86Reg x86reg, bool pop) void CX86Ops::fpuStoreStatus(void) { - CPU_Message(" fnstsw ax"); + CodeLog(" fnstsw ax"); AddCode16(0xE0DF); } void CX86Ops::fpuSubDword(void *Variable, const char * VariableName) { - CPU_Message(" fsub ST(0), dword ptr [%s]", VariableName); + CodeLog(" fsub ST(0), dword ptr [%s]", VariableName); AddCode16(0x25D8); AddCode32((uint32_t)Variable); } void CX86Ops::fpuSubDwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fsub ST(0), dword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fsub ST(0), dword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x20D8); break; @@ -4117,21 +4122,21 @@ void CX86Ops::fpuSubDwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuSubDwordReverse(void *Variable, const char * VariableName) { - CPU_Message(" fsubr ST(0), dword ptr [%s]", VariableName); + CodeLog(" fsubr ST(0), dword ptr [%s]", VariableName); AddCode16(0x2DD8); AddCode32((uint32_t)Variable); } void CX86Ops::fpuSubQword(void *Variable, const char * VariableName) { - CPU_Message(" fsub ST(0), qword ptr [%s]", VariableName); + CodeLog(" fsub ST(0), qword ptr [%s]", VariableName); AddCode16(0x25DC); AddCode32((uint32_t)Variable); } void CX86Ops::fpuSubQwordRegPointer(x86Reg x86Pointer) { - CPU_Message(" fsub ST(0), qword ptr [%s]", x86_Name(x86Pointer)); + CodeLog(" fsub ST(0), qword ptr [%s]", x86_Name(x86Pointer)); switch (x86Pointer) { case x86_EAX: AddCode16(0x20DC); break; case x86_EBX: AddCode16(0x23DC); break; @@ -4147,14 +4152,14 @@ void CX86Ops::fpuSubQwordRegPointer(x86Reg x86Pointer) void CX86Ops::fpuSubQwordReverse(void *Variable, const char * VariableName) { - CPU_Message(" fsubr ST(0), qword ptr [%s]", VariableName); + CodeLog(" fsubr ST(0), qword ptr [%s]", VariableName); AddCode16(0x2DDC); AddCode32((uint32_t)Variable); } void CX86Ops::fpuSubReg(x86FpuValues x86reg) { - CPU_Message(" fsub ST(0), %s", fpu_Name(x86reg)); + CodeLog(" fsub ST(0), %s", fpu_Name(x86reg)); switch (x86reg) { case x86_ST0: AddCode16(0xE0D8); break; case x86_ST1: AddCode16(0xE1D8); break; @@ -4172,7 +4177,7 @@ void CX86Ops::fpuSubReg(x86FpuValues x86reg) void CX86Ops::fpuSubRegPop(x86FpuValues x86reg) { - CPU_Message(" fsubp ST(0), %s", fpu_Name(x86reg)); + CodeLog(" fsubp ST(0), %s", fpu_Name(x86reg)); switch (x86reg) { case x86_ST0: AddCode16(0xE8DE); break; case x86_ST1: AddCode16(0xE9DE); break; @@ -4345,4 +4350,27 @@ void CX86Ops::AddCode32(uint32_t value) *g_RecompPos += 4; } +void CX86Ops::CodeLog(_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_CodeBlock.Log(buffer); + } +#pragma warning(pop) + va_end(args); +} + #endif diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h index 7bcf65c86..22864c4bc 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h @@ -1,6 +1,8 @@ #pragma once - #if defined(__i386__) || defined(_M_IX86) + +class CCodeBlock; + class CX86Ops { public: @@ -49,250 +51,258 @@ public: static const char * x86_HalfName(x86Reg Reg); static const char * fpu_Name(x86FpuValues Reg); -protected: +public: + CX86Ops(CCodeBlock & CodeBlock); + // Logging functions - static void WriteX86Comment(const char * Comment); - static void WriteX86Label(const char * Label); + void WriteX86Comment(const char * Comment); + void WriteX86Label(const char * Label); - static void AdcX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); - static void AdcConstToVariable(void *Variable, const char * VariableName, uint8_t Constant); - static void AdcConstToX86Reg(x86Reg Reg, uint32_t Const); - static void AdcVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); - static void AdcX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void AddConstToVariable(uint32_t Const, void *Variable, const char * VariableName); - static void AddConstToX86Reg(x86Reg Reg, uint32_t Const); - static void AddVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); - static void AddX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); - static void AddX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void AndConstToVariable(uint32_t Const, void *Variable, const char * VariableName); - static void AndConstToX86Reg(x86Reg Reg, uint32_t Const); - static void AndVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); - static void AndVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, Multipler Multiply); - static void AndX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void X86HardBreakPoint(); - static void X86BreakPoint(const char * FileName, int32_t LineNumber); - static void Call_Direct(void * FunctAddress, const char * FunctName); - static void Call_Indirect(void * FunctAddress, const char * FunctName); - static void CompConstToVariable(uint32_t Const, void * Variable, const char * VariableName); - static void CompConstToX86reg(x86Reg Reg, uint32_t Const); - static void CompConstToX86regPointer(x86Reg Reg, uint32_t Const); - static void CompX86regToVariable(x86Reg Reg, void * Variable, const char * VariableName); - static void CompVariableToX86reg(x86Reg Reg, void * Variable, const char * VariableName); - static void CompX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void DecX86reg(x86Reg Reg); - static void DivX86reg(x86Reg reg); - static void idivX86reg(x86Reg reg); - static void imulX86reg(x86Reg reg); - static void IncX86reg(x86Reg Reg); - static void JaeLabel8(const char * Label, uint8_t Value); - static void JaeLabel32(const char * Label, uint32_t Value); - static void JaLabel8(const char * Label, uint8_t Value); - static void JaLabel32(const char * Label, uint32_t Value); - static void JbLabel8(const char * Label, uint8_t Value); - static void JbLabel32(const char * Label, uint32_t Value); - static void JecxzLabel8(const char * Label, uint8_t Value); - static void JeLabel8(const char * Label, uint8_t Value); - static void JeLabel32(const char * Label, uint32_t Value); - static void JgeLabel32(const char * Label, uint32_t Value); - static void JgLabel8(const char * Label, uint8_t Value); - static void JgLabel32(const char * Label, uint32_t Value); - static void JleLabel8(const char * Label, uint8_t Value); - static void JleLabel32(const char * Label, uint32_t Value); - static void JlLabel8(const char * Label, uint8_t Value); - static void JlLabel32(const char * Label, uint32_t Value); - static void JmpDirectReg(x86Reg reg); - static void JmpIndirectLabel32(const char * Label, uint32_t location); - static void JmpIndirectReg(x86Reg reg); - static void JmpLabel8(const char * Label, uint8_t Value); - static void JmpLabel32(const char * Label, uint32_t Value); - static void JneLabel8(const char * Label, uint8_t Value); - static void JneLabel32(const char * Label, uint32_t Value); - static void JnsLabel8(const char * Label, uint8_t Value); - static void JnsLabel32(const char * Label, uint32_t Value); - static void JnzLabel8(const char * Label, uint8_t Value); - static void JnzLabel32(const char * Label, uint32_t Value); - static void JsLabel32(const char * Label, uint32_t Value); - static void JzLabel8(const char * Label, uint8_t Value); - static void JzLabel32(const char * Label, uint32_t Value); - static void LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler multiplier); - static void LeaRegReg2(x86Reg RegDest, x86Reg RegSrc, x86Reg RegSrc2, Multipler multiplier); - static void LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int32_t offset); - static void MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg); - static void MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg); - static void MoveConstByteToVariable(uint8_t Const, void * Variable, const char * VariableName); - static void MoveConstByteToX86regPointer(uint8_t Const, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveConstHalfToVariable(uint16_t Const, void * Variable, const char * VariableName); - static void MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Disp); - static void MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg); - static void MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp); - static void MoveConstToVariable(uint32_t Const, void * Variable, const char * VariableName); - static void MoveConstToX86Pointer(uint32_t Const, x86Reg X86Pointer); - static void MoveConstToX86reg(uint32_t Const, x86Reg reg); - static void MoveConstToX86regPointer(uint32_t Const, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveN64MemDispToX86reg(x86Reg reg, x86Reg AddrReg, uint8_t Disp); - static void MoveN64MemToX86reg(x86Reg reg, x86Reg AddrReg); - static void MoveN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); - static void MoveN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); - static void MoveSxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); - static void MoveSxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); - static void MoveSxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); - static void MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); - static void MoveSxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); - static void MoveSxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); - static void MoveVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, int32_t Multiplier); - static void MoveVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); - static void MoveVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); - static void MoveVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); - static void MoveX86PointerToX86reg(x86Reg reg, x86Reg X86Pointer); - static void MoveX86PointerToX86regDisp(x86Reg reg, x86Reg X86Pointer, uint8_t Disp); - static void MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg); - static void MoveX86regByteToVariable(x86Reg reg, void * Variable, const char * VariableName); - static void MoveX86regByteToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg); - static void MoveX86regHalfToVariable(x86Reg reg, void * Variable, const char * VariableName); - static void MoveX86regHalfToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); - static void MoveX86regPointerToX86regDisp8(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg, uint8_t offset); - static void MoveX86regToMemory(x86Reg reg, x86Reg AddrReg, uint32_t Disp); - static void MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg); - static void MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp); - static void MoveX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); - static void MoveX86RegToX86Reg(x86Reg Source, x86Reg Destination); - static void MoveX86regToX86Pointer(x86Reg reg, x86Reg X86Pointer); - static void MoveX86regToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); - static void MoveZxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); - static void MoveZxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); - static void MoveZxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); - static void MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); - static void MoveZxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); - static void MoveZxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); - static void MulX86reg(x86Reg reg); - static void NotX86Reg(x86Reg Reg); - static void OrConstToVariable(uint32_t Const, void * Variable, const char * VariableName); - static void OrConstToX86Reg(uint32_t Const, x86Reg reg); - static void OrVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); - static void OrX86RegToVariable(void * Variable, const char * VariableName, x86Reg Reg); - static void OrX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void Push(x86Reg reg); - static void Pushad(); - static void PushImm32(uint32_t Value); - static void PushImm32(const char * String, uint32_t Value); - static void Pop(x86Reg reg); - static void Popad(); - static void Ret(); - static void Seta(x86Reg reg); - static void Setae(x86Reg reg); - static void SetaVariable(void * Variable, const char * VariableName); - static void Setb(x86Reg reg); - static void SetbVariable(void * Variable, const char * VariableName); - static void Setg(x86Reg reg); - static void SetgVariable(void * Variable, const char * VariableName); - static void Setl(x86Reg reg); - static void SetlVariable(void * Variable, const char * VariableName); - static void Setz(x86Reg reg); - static void Setnz(x86Reg reg); - static void ShiftLeftDouble(x86Reg Destination, x86Reg Source); - static void ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); - static void ShiftLeftSign(x86Reg reg); - static void ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate); - static void ShiftRightDouble(x86Reg Destination, x86Reg Source); - static void ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); - static void ShiftRightSign(x86Reg reg); - static void ShiftRightSignImmed(x86Reg reg, uint8_t Immediate); - static void ShiftRightUnsign(x86Reg reg); - static void ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate); - static void SbbConstFromX86Reg(x86Reg Reg, uint32_t Const); - static void SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); - static void SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName); - static void SubConstFromX86Reg(x86Reg Reg, uint32_t Const); - static void SubVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); - static void SubX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void TestConstToX86Reg(uint32_t Const, x86Reg reg); - static void TestVariable(uint32_t Const, void * Variable, const char * VariableName); - static void TestX86RegToX86Reg(x86Reg Destination, x86Reg Source); - static void TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source); - static void XorConstToX86Reg(x86Reg Reg, uint32_t Const); - static void XorX86RegToX86Reg(x86Reg Source, x86Reg Destination); - static void XorVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); + void AdcX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); + void AdcConstToVariable(void *Variable, const char * VariableName, uint8_t Constant); + void AdcConstToX86Reg(x86Reg Reg, uint32_t Const); + void AdcVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); + void AdcX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void AddConstToVariable(uint32_t Const, void *Variable, const char * VariableName); + void AddConstToX86Reg(x86Reg Reg, uint32_t Const); + void AddVariableToX86reg(x86Reg reg, void * Variable, const char * VariableName); + void AddX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); + void AddX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void AndConstToVariable(uint32_t Const, void *Variable, const char * VariableName); + void AndConstToX86Reg(x86Reg Reg, uint32_t Const); + void AndVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); + void AndVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, Multipler Multiply); + void AndX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void X86HardBreakPoint(); + void X86BreakPoint(const char * FileName, int32_t LineNumber); + void Call_Direct(void * FunctAddress, const char * FunctName); + void Call_Indirect(void * FunctAddress, const char * FunctName); + void CompConstToVariable(uint32_t Const, void * Variable, const char * VariableName); + void CompConstToX86reg(x86Reg Reg, uint32_t Const); + void CompConstToX86regPointer(x86Reg Reg, uint32_t Const); + void CompX86regToVariable(x86Reg Reg, void * Variable, const char * VariableName); + void CompVariableToX86reg(x86Reg Reg, void * Variable, const char * VariableName); + void CompX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void DecX86reg(x86Reg Reg); + void DivX86reg(x86Reg reg); + void idivX86reg(x86Reg reg); + void imulX86reg(x86Reg reg); + void IncX86reg(x86Reg Reg); + void JaeLabel8(const char * Label, uint8_t Value); + void JaeLabel32(const char * Label, uint32_t Value); + void JaLabel8(const char * Label, uint8_t Value); + void JaLabel32(const char * Label, uint32_t Value); + void JbLabel8(const char * Label, uint8_t Value); + void JbLabel32(const char * Label, uint32_t Value); + void JecxzLabel8(const char * Label, uint8_t Value); + void JeLabel8(const char * Label, uint8_t Value); + void JeLabel32(const char * Label, uint32_t Value); + void JgeLabel32(const char * Label, uint32_t Value); + void JgLabel8(const char * Label, uint8_t Value); + void JgLabel32(const char * Label, uint32_t Value); + void JleLabel8(const char * Label, uint8_t Value); + void JleLabel32(const char * Label, uint32_t Value); + void JlLabel8(const char * Label, uint8_t Value); + void JlLabel32(const char * Label, uint32_t Value); + void JmpDirectReg(x86Reg reg); + void JmpIndirectLabel32(const char * Label, uint32_t location); + void JmpIndirectReg(x86Reg reg); + void JmpLabel8(const char * Label, uint8_t Value); + void JmpLabel32(const char * Label, uint32_t Value); + void JneLabel8(const char * Label, uint8_t Value); + void JneLabel32(const char * Label, uint32_t Value); + void JnsLabel8(const char * Label, uint8_t Value); + void JnsLabel32(const char * Label, uint32_t Value); + void JnzLabel8(const char * Label, uint8_t Value); + void JnzLabel32(const char * Label, uint32_t Value); + void JsLabel32(const char * Label, uint32_t Value); + void JzLabel8(const char * Label, uint8_t Value); + void JzLabel32(const char * Label, uint32_t Value); + void LeaRegReg(x86Reg RegDest, x86Reg RegSrc, uint32_t Const, Multipler multiplier); + void LeaRegReg2(x86Reg RegDest, x86Reg RegSrc, x86Reg RegSrc2, Multipler multiplier); + void LeaSourceAndOffset(x86Reg x86DestReg, x86Reg x86SourceReg, int32_t offset); + void MoveConstByteToN64Mem(uint8_t Const, x86Reg AddrReg); + void MoveConstHalfToN64Mem(uint16_t Const, x86Reg AddrReg); + void MoveConstByteToVariable(uint8_t Const, void * Variable, const char * VariableName); + void MoveConstByteToX86regPointer(uint8_t Const, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveConstHalfToVariable(uint16_t Const, void * Variable, const char * VariableName); + void MoveConstHalfToX86regPointer(uint16_t Const, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveConstToMemoryDisp(uint32_t Const, x86Reg AddrReg, uint32_t Disp); + void MoveConstToN64Mem(uint32_t Const, x86Reg AddrReg); + void MoveConstToN64MemDisp(uint32_t Const, x86Reg AddrReg, uint8_t Disp); + void MoveConstToVariable(uint32_t Const, void * Variable, const char * VariableName); + void MoveConstToX86Pointer(uint32_t Const, x86Reg X86Pointer); + void MoveConstToX86reg(uint32_t Const, x86Reg reg); + void MoveConstToX86regPointer(uint32_t Const, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveN64MemDispToX86reg(x86Reg reg, x86Reg AddrReg, uint8_t Disp); + void MoveN64MemToX86reg(x86Reg reg, x86Reg AddrReg); + void MoveN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); + void MoveN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); + void MoveSxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); + void MoveSxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); + void MoveSxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); + void MoveSxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); + void MoveSxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); + void MoveSxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); + void MoveVariableDispToX86Reg(void * Variable, const char * VariableName, x86Reg Reg, x86Reg AddrReg, int32_t Multiplier); + void MoveVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); + void MoveVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); + void MoveVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); + void MoveX86PointerToX86reg(x86Reg reg, x86Reg X86Pointer); + void MoveX86PointerToX86regDisp(x86Reg reg, x86Reg X86Pointer, uint8_t Disp); + void MoveX86regByteToN64Mem(x86Reg reg, x86Reg AddrReg); + void MoveX86regByteToVariable(x86Reg reg, void * Variable, const char * VariableName); + void MoveX86regByteToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveX86regHalfToN64Mem(x86Reg reg, x86Reg AddrReg); + void MoveX86regHalfToVariable(x86Reg reg, void * Variable, const char * VariableName); + void MoveX86regHalfToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); + void MoveX86regPointerToX86regDisp8(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg, uint8_t offset); + void MoveX86regToMemory(x86Reg reg, x86Reg AddrReg, uint32_t Disp); + void MoveX86regToN64Mem(x86Reg reg, x86Reg AddrReg); + void MoveX86regToN64MemDisp(x86Reg reg, x86Reg AddrReg, uint8_t Disp); + void MoveX86regToVariable(x86Reg reg, void * Variable, const char * VariableName); + void MoveX86RegToX86Reg(x86Reg Source, x86Reg Destination); + void MoveX86regToX86Pointer(x86Reg reg, x86Reg X86Pointer); + void MoveX86regToX86regPointer(x86Reg reg, x86Reg AddrReg1, x86Reg AddrReg2); + void MoveZxByteX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); + void MoveZxHalfX86regPointerToX86reg(x86Reg AddrReg1, x86Reg AddrReg2, x86Reg reg); + void MoveZxN64MemToX86regByte(x86Reg reg, x86Reg AddrReg); + void MoveZxN64MemToX86regHalf(x86Reg reg, x86Reg AddrReg); + void MoveZxVariableToX86regByte(void * Variable, const char * VariableName, x86Reg reg); + void MoveZxVariableToX86regHalf(void * Variable, const char * VariableName, x86Reg reg); + void MulX86reg(x86Reg reg); + void NotX86Reg(x86Reg Reg); + void OrConstToVariable(uint32_t Const, void * Variable, const char * VariableName); + void OrConstToX86Reg(uint32_t Const, x86Reg reg); + void OrVariableToX86Reg(void * Variable, const char * VariableName, x86Reg Reg); + void OrX86RegToVariable(void * Variable, const char * VariableName, x86Reg Reg); + void OrX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void Push(x86Reg reg); + void Pushad(); + void PushImm32(uint32_t Value); + void PushImm32(const char * String, uint32_t Value); + void Pop(x86Reg reg); + void Popad(); + void Ret(); + void Seta(x86Reg reg); + void Setae(x86Reg reg); + void SetaVariable(void * Variable, const char * VariableName); + void Setb(x86Reg reg); + void SetbVariable(void * Variable, const char * VariableName); + void Setg(x86Reg reg); + void SetgVariable(void * Variable, const char * VariableName); + void Setl(x86Reg reg); + void SetlVariable(void * Variable, const char * VariableName); + void Setz(x86Reg reg); + void Setnz(x86Reg reg); + void ShiftLeftDouble(x86Reg Destination, x86Reg Source); + void ShiftLeftDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); + void ShiftLeftSign(x86Reg reg); + void ShiftLeftSignImmed(x86Reg reg, uint8_t Immediate); + void ShiftRightDouble(x86Reg Destination, x86Reg Source); + void ShiftRightDoubleImmed(x86Reg Destination, x86Reg Source, uint8_t Immediate); + void ShiftRightSign(x86Reg reg); + void ShiftRightSignImmed(x86Reg reg, uint8_t Immediate); + void ShiftRightUnsign(x86Reg reg); + void ShiftRightUnsignImmed(x86Reg reg, uint8_t Immediate); + void SbbConstFromX86Reg(x86Reg Reg, uint32_t Const); + void SbbVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); + void SbbX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName); + void SubConstFromX86Reg(x86Reg Reg, uint32_t Const); + void SubVariableFromX86reg(x86Reg reg, void * Variable, const char * VariableName); + void SubX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void TestConstToX86Reg(uint32_t Const, x86Reg reg); + void TestVariable(uint32_t Const, void * Variable, const char * VariableName); + void TestX86RegToX86Reg(x86Reg Destination, x86Reg Source); + void TestX86ByteRegToX86Reg(x86Reg Destination, x86Reg Source); + void XorConstToX86Reg(x86Reg Reg, uint32_t Const); + void XorX86RegToX86Reg(x86Reg Source, x86Reg Destination); + void XorVariableToX86reg(void * Variable, const char * VariableName, x86Reg reg); - static void fpuAbs(); - static void fpuAddDword(void * Variable, const char * VariableName); - static void fpuAddDwordRegPointer(x86Reg x86Pointer); - static void fpuAddQword(void * Variable, const char * VariableName); - static void fpuAddQwordRegPointer(x86Reg X86Pointer); - static void fpuAddReg(x86FpuValues reg); - static void fpuAddRegPop(int32_t * StackPos, x86FpuValues reg); - static void fpuComDword(void * Variable, const char * VariableName, bool Pop); - static void fpuComDwordRegPointer(x86Reg X86Pointer, bool Pop); - static void fpuComQword(void * Variable, const char * VariableName, bool Pop); - static void fpuComQwordRegPointer(x86Reg X86Pointer, bool Pop); - static void fpuComReg(x86FpuValues reg, bool Pop); - static void fpuDivDword(void * Variable, const char * VariableName); - static void fpuDivDwordRegPointer(x86Reg X86Pointer); - static void fpuDivQword(void * Variable, const char * VariableName); - static void fpuDivQwordRegPointer(x86Reg X86Pointer); - static void fpuDivReg(x86FpuValues Reg); - static void fpuDivRegPop(x86FpuValues reg); - static void fpuExchange(x86FpuValues Reg); - static void fpuFree(x86FpuValues Reg); - static void fpuDecStack(int32_t * StackPos); - static void fpuIncStack(int32_t * StackPos); - static void fpuLoadControl(void * Variable, const char * VariableName); - static void fpuLoadDword(int32_t * StackPos, void * Variable, const char * VariableName); - static void fpuLoadDwordFromX86Reg(int32_t * StackPos, x86Reg reg); - static void fpuLoadDwordFromN64Mem(int32_t * StackPos, x86Reg reg); - static void fpuLoadInt32bFromN64Mem(int32_t * StackPos, x86Reg reg); - static void fpuLoadIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName); - static void fpuLoadIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg); - static void fpuLoadIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName); - static void fpuLoadIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); - static void fpuLoadQword(int32_t * StackPos, void * Variable, const char * VariableName); - static void fpuLoadQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); - static void fpuLoadQwordFromN64Mem(int32_t * StackPos, x86Reg reg); - static void fpuLoadReg(int32_t * StackPos, x86FpuValues Reg); - static void fpuMulDword(void * Variable, const char * VariableName); - static void fpuMulDwordRegPointer(x86Reg X86Pointer); - static void fpuMulQword(void * Variable, const char * VariableName); - static void fpuMulQwordRegPointer(x86Reg X86Pointer); - static void fpuMulReg(x86FpuValues reg); - static void fpuMulRegPop(x86FpuValues reg); - static void fpuNeg(); - static void fpuRound(); - static void fpuSqrt(); - static void fpuStoreControl(void * Variable, const char * VariableName); - static void fpuStoreDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); - static void fpuStoreDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); - static void fpuStoreDwordToN64Mem(int32_t * StackPos, x86Reg reg, bool Pop); - static void fpuStoreIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); - static void fpuStoreIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); - static void fpuStoreIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); - static void fpuStoreIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); - static void fpuStoreQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); - static void fpuStoreStatus(); - static void fpuSubDword(void * Variable, const char * VariableName); - static void fpuSubDwordRegPointer(x86Reg X86Pointer); - static void fpuSubDwordReverse(void * Variable, const char * VariableName); - static void fpuSubQword(void * Variable, const char * VariableName); - static void fpuSubQwordRegPointer(x86Reg X86Pointer); - static void fpuSubQwordReverse(void * Variable, const char * VariableName); - static void fpuSubReg(x86FpuValues reg); - static void fpuSubRegPop(x86FpuValues reg); + void fpuAbs(); + void fpuAddDword(void * Variable, const char * VariableName); + void fpuAddDwordRegPointer(x86Reg x86Pointer); + void fpuAddQword(void * Variable, const char * VariableName); + void fpuAddQwordRegPointer(x86Reg X86Pointer); + void fpuAddReg(x86FpuValues reg); + void fpuAddRegPop(int32_t * StackPos, x86FpuValues reg); + void fpuComDword(void * Variable, const char * VariableName, bool Pop); + void fpuComDwordRegPointer(x86Reg X86Pointer, bool Pop); + void fpuComQword(void * Variable, const char * VariableName, bool Pop); + void fpuComQwordRegPointer(x86Reg X86Pointer, bool Pop); + void fpuComReg(x86FpuValues reg, bool Pop); + void fpuDivDword(void * Variable, const char * VariableName); + void fpuDivDwordRegPointer(x86Reg X86Pointer); + void fpuDivQword(void * Variable, const char * VariableName); + void fpuDivQwordRegPointer(x86Reg X86Pointer); + void fpuDivReg(x86FpuValues Reg); + void fpuDivRegPop(x86FpuValues reg); + void fpuExchange(x86FpuValues Reg); + void fpuFree(x86FpuValues Reg); + void fpuDecStack(int32_t * StackPos); + void fpuIncStack(int32_t * StackPos); + void fpuLoadControl(void * Variable, const char * VariableName); + void fpuLoadDword(int32_t * StackPos, void * Variable, const char * VariableName); + void fpuLoadDwordFromX86Reg(int32_t * StackPos, x86Reg reg); + void fpuLoadDwordFromN64Mem(int32_t * StackPos, x86Reg reg); + void fpuLoadInt32bFromN64Mem(int32_t * StackPos, x86Reg reg); + void fpuLoadIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName); + void fpuLoadIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg); + void fpuLoadIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName); + void fpuLoadIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); + void fpuLoadQword(int32_t * StackPos, void * Variable, const char * VariableName); + void fpuLoadQwordFromX86Reg(int32_t * StackPos, x86Reg Reg); + void fpuLoadQwordFromN64Mem(int32_t * StackPos, x86Reg reg); + void fpuLoadReg(int32_t * StackPos, x86FpuValues Reg); + void fpuMulDword(void * Variable, const char * VariableName); + void fpuMulDwordRegPointer(x86Reg X86Pointer); + void fpuMulQword(void * Variable, const char * VariableName); + void fpuMulQwordRegPointer(x86Reg X86Pointer); + void fpuMulReg(x86FpuValues reg); + void fpuMulRegPop(x86FpuValues reg); + void fpuNeg(); + void fpuRound(); + void fpuSqrt(); + void fpuStoreControl(void * Variable, const char * VariableName); + void fpuStoreDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); + void fpuStoreDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); + void fpuStoreDwordToN64Mem(int32_t * StackPos, x86Reg reg, bool Pop); + void fpuStoreIntegerDword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); + void fpuStoreIntegerDwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); + void fpuStoreIntegerQword(int32_t * StackPos, void * Variable, const char * VariableName, bool pop); + void fpuStoreIntegerQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); + void fpuStoreQwordFromX86Reg(int32_t * StackPos, x86Reg Reg, bool pop); + void fpuStoreStatus(); + void fpuSubDword(void * Variable, const char * VariableName); + void fpuSubDwordRegPointer(x86Reg X86Pointer); + void fpuSubDwordReverse(void * Variable, const char * VariableName); + void fpuSubQword(void * Variable, const char * VariableName); + void fpuSubQwordRegPointer(x86Reg X86Pointer); + void fpuSubQwordReverse(void * Variable, const char * VariableName); + void fpuSubReg(x86FpuValues reg); + void fpuSubRegPop(x86FpuValues reg); static bool Is8BitReg(x86Reg Reg); static uint8_t CalcMultiplyCode(Multipler Multiply); - static void * GetAddressOf(int32_t value, ...); - static void SetJump32(uint32_t * Loc, uint32_t * JumpLoc); - static void SetJump8(uint8_t * Loc, uint8_t * JumpLoc); + void * GetAddressOf(int32_t value, ...); + void SetJump32(uint32_t * Loc, uint32_t * JumpLoc); + void SetJump8(uint8_t * Loc, uint8_t * JumpLoc); private: + CX86Ops(void); + + void CodeLog(_Printf_format_string_ const char * Text, ...); + static void BreakPointNotification(const char * FileName, int32_t LineNumber); static char m_fpupop[2][2]; - static void AddCode8(uint8_t value); - static void AddCode16(uint16_t value); - static void AddCode32(uint32_t value); + void AddCode8(uint8_t value); + void AddCode16(uint16_t value); + void AddCode32(uint32_t value); + + CCodeBlock & m_CodeBlock; }; #define AddressOf(Addr) CX86Ops::GetAddressOf(5,(Addr)) diff --git a/Source/Project64-core/Project64-core.vcxproj b/Source/Project64-core/Project64-core.vcxproj index 10ee99736..4ef0b1300 100644 --- a/Source/Project64-core/Project64-core.vcxproj +++ b/Source/Project64-core/Project64-core.vcxproj @@ -93,11 +93,11 @@ + - @@ -221,7 +221,6 @@ - diff --git a/Source/Project64-core/Project64-core.vcxproj.filters b/Source/Project64-core/Project64-core.vcxproj.filters index ccfcd2f7a..bd9e35d8e 100644 --- a/Source/Project64-core/Project64-core.vcxproj.filters +++ b/Source/Project64-core/Project64-core.vcxproj.filters @@ -303,9 +303,6 @@ Source Files\Rom List - - Source Files\N64 System\Recompiler - Source Files\N64 System\Recompiler\x86 @@ -408,6 +405,9 @@ Source Files\N64 System\MemoryHandler + + Source Files\N64 System\Recompiler + @@ -662,9 +662,6 @@ Header Files\Rom List - - Header Files\N64 System\Recompiler - Header Files\N64 System\Recompiler\x86