[Project64] Get x86/x86RecompilerOps.cpp to use an base interface

This commit is contained in:
zilmar 2016-07-04 17:51:11 +10:00
parent cd0f305124
commit 778caf78f0
10 changed files with 785 additions and 553 deletions

View File

@ -11,7 +11,7 @@
#pragma once
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
#include "TranslateVaddr.h"
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Interpreter/InterpreterOps.h>
#include <Project64-core/N64System/Mips/PifRam.h>
#include <Project64-core/N64System/Mips/FlashRam.h>
@ -57,6 +57,7 @@
* 0xAABBCCDD EEFFGGHH --> 0xDDCCBBAA HHGGFFEE
* GPR bits[63..0] b1b2b3b4 b5b6b7b8
*/
class CX86RecompilerOps;
class CMipsMemoryVM :
public CTransVaddr,
@ -130,7 +131,7 @@ private:
CMipsMemoryVM(const CMipsMemoryVM&); // Disable copy constructor
CMipsMemoryVM& operator=(const CMipsMemoryVM&); // Disable assignment
friend CRecompilerOps;
friend CX86RecompilerOps;
void Compile_LW(bool ResultSigned, bool bRecordLLbit);
void Compile_SW(bool bCheckLLbit);

View File

@ -30,7 +30,7 @@
#pragma warning(disable:4355) // Disable 'this' : used in base member initializer list
CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly) :
CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem) :
CSystemEvents(this, Plugins),
m_EndEmulation(false),
m_SaveUsing((SAVE_CHIP_TYPE)g_Settings->LoadDword(Game_SaveChip)),
@ -56,7 +56,8 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly) :
m_SyncCount(0),
m_thread(NULL),
m_hPauseEvent(true),
m_CheatsSlectionChanged(false)
m_CheatsSlectionChanged(false),
m_SyncCpu(SyncSystem)
{
uint32_t gameHertz = g_Settings->LoadDword(Game_ScreenHertz);
if (gameHertz == 0)
@ -66,6 +67,36 @@ CN64System::CN64System(CPlugins * Plugins, bool SavesReadOnly) :
m_Limiter.SetHertz(gameHertz);
g_Settings->SaveDword(GameRunning_ScreenHertz, gameHertz);
m_Cheats.LoadCheats(!g_Settings->LoadDword(Setting_RememberCheats), Plugins);
WriteTrace(TraceN64System, TraceDebug, "Setting up system");
CInterpreterCPU::BuildCPU();
if (!SyncSystem)
{
uint32_t CpuType = g_Settings->LoadDword(Game_CpuType);
WriteTrace(TraceN64System, TraceDebug, "CpuType = %d",CpuType);
if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled))
{
g_Settings->SaveDword(Game_CpuType, CPU_Recompiler);
CpuType = CPU_Recompiler;
}
if (CpuType == CPU_SyncCores)
{
if (g_Plugins->SyncWindow() == NULL)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
g_Notify->DisplayMessage(5, "Copy Plugins");
g_Plugins->CopyPlugins(g_Settings->LoadStringVal(Directory_PluginSync));
m_SyncPlugins = new CPlugins(Directory_PluginSync);
m_SyncPlugins->SetRenderWindows(g_Plugins->SyncWindow(), NULL);
m_SyncCPU = new CN64System(m_SyncPlugins, true, true);
}
if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores)
{
m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation);
}
}
}
CN64System::~CN64System()
@ -88,6 +119,12 @@ CN64System::~CN64System()
delete m_SyncPlugins;
m_SyncPlugins = NULL;
}
if (m_thread != NULL)
{
WriteTrace(TraceN64System, TraceDebug, "Deleting thread object");
delete m_thread;
m_thread = NULL;
}
}
void CN64System::ExternalEvent(SystemEvent action)
@ -257,7 +294,7 @@ bool CN64System::RunFileImage(const char * FileLoc)
WriteTrace(TraceN64System, TraceDebug, "Finished Loading (GoodName: %s)", g_Settings->LoadStringVal(Game_GoodName).c_str());
g_BaseSystem = new CN64System(g_Plugins, false);
g_BaseSystem = new CN64System(g_Plugins, false, false);
if (g_BaseSystem)
{
if (g_Settings->LoadBool(Setting_AutoStart) != 0)
@ -267,7 +304,16 @@ bool CN64System::RunFileImage(const char * FileLoc)
}
else
{
g_BaseSystem->SetActiveSystem(true);
bool bSetActive = true;
if (g_BaseSystem->m_SyncCPU != NULL)
{
bSetActive = g_BaseSystem->m_SyncCPU->SetActiveSystem(true);
}
if (bSetActive)
{
bSetActive = g_BaseSystem->SetActiveSystem(true);
}
}
}
}
@ -446,35 +492,6 @@ void CN64System::StartEmulation2(bool NewThread)
}
g_Settings->SaveDword(Game_CurrentSaveState, g_Settings->LoadDefaultDword(Game_CurrentSaveState));
WriteTrace(TraceN64System, TraceDebug, "Setting up system");
CInterpreterCPU::BuildCPU();
uint32_t CpuType = g_Settings->LoadDword(Game_CpuType);
WriteTrace(TraceN64System, TraceDebug, "CpuType = %d", CpuType);
if (CpuType == CPU_SyncCores && !g_Settings->LoadBool(Debugger_Enabled))
{
g_Settings->SaveDword(Game_CpuType, CPU_Recompiler);
CpuType = CPU_Recompiler;
}
if (CpuType == CPU_SyncCores)
{
if (g_Plugins->SyncWindow() == NULL)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
g_Notify->DisplayMessage(5, "Copy Plugins");
g_Plugins->CopyPlugins(g_Settings->LoadStringVal(Directory_PluginSync));
m_SyncPlugins = new CPlugins(Directory_PluginSync);
m_SyncPlugins->SetRenderWindows(g_Plugins->SyncWindow(), NULL);
m_SyncCPU = new CN64System(m_SyncPlugins, true);
}
if (CpuType == CPU_Recompiler || CpuType == CPU_SyncCores)
{
m_Recomp = new CRecompiler(m_Reg, m_Profile, m_EndEmulation);
}
WriteTrace(TraceN64System, TraceDebug, "Setting system as active");
bool bSetActive = true;
if (m_SyncCPU)
@ -487,11 +504,16 @@ void CN64System::StartEmulation2(bool NewThread)
bSetActive = SetActiveSystem();
}
if (!bSetActive)
if (!m_Plugins->Reset(this) || !m_Plugins->initilized())
{
WriteTrace(TraceN64System, TraceWarning, "can not run, plugins not initlized");
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
}
else if (!bSetActive)
{
WriteTrace(TraceN64System, TraceWarning, "Failed to set system as active");
g_Settings->SaveBool(GameRunning_LoadingInProgress, false);
g_Notify->DisplayError(MSG_PLUGIN_NOT_INIT);
}
else
{
@ -953,7 +975,7 @@ void CN64System::ExecuteCPU()
default: ExecuteInterpret(); break;
}
WriteTrace(TraceN64System, TraceDebug, "CPU finished executing");
g_Settings->SaveBool(GameRunning_CPU_Running, (uint32_t)false);
CpuStopped();
WriteTrace(TraceN64System, TraceDebug, "Notifing plugins rom is done");
m_Plugins->RomClosed();
if (m_SyncCPU)

View File

@ -47,7 +47,7 @@ class CN64System :
protected CDebugSettings
{
public:
CN64System(CPlugins * Plugins, bool SavesReadOnly);
CN64System(CPlugins * Plugins, bool SavesReadOnly, bool SyncSystem);
virtual ~CN64System(void);
CProfiling m_Profile;
@ -154,6 +154,7 @@ private:
uint32_t m_TLBLoadAddress;
uint32_t m_TLBStoreAddress;
uint32_t m_SyncCount;
bool m_SyncCpu;
bool m_CheatsSlectionChanged;
//When Syncing cores this is the PC where it last Sync'ed correctly

View File

@ -32,13 +32,13 @@ CCodeBlock::CCodeBlock(uint32_t VAddrEnter, uint8_t * CompiledLocation) :
memset(m_MemContents, 0, sizeof(m_MemContents));
memset(m_MemLocation, 0, sizeof(m_MemLocation));
CCodeSection * baseSection = new CCodeSection(this, VAddrEnter, 0, false);
if (baseSection == NULL)
m_RecompilerOps = new CX86RecompilerOps;
if (m_RecompilerOps == NULL)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}
m_RecompilerOps = new CRecompilerOps;
if (m_RecompilerOps == NULL)
CCodeSection * baseSection = new CCodeSection(this, VAddrEnter, 0, false);
if (baseSection == NULL)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
}

View File

@ -10,7 +10,7 @@
****************************************************************************/
#pragma once
#include <Common/md5.h>
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/CodeSection.h>
class CCodeBlock

View File

@ -10,7 +10,7 @@
****************************************************************************/
#pragma once
#include "JumpInfo.h"
#include <Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
class CCodeBlock;

View File

@ -0,0 +1,225 @@
/****************************************************************************
* *
* Project64 - A Nintendo 64 emulator. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2012 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#pragma once
#include <Project64-core/N64System/Recompiler/RegInfo.h>
#include <Project64-core/N64System/Recompiler/JumpInfo.h>
#include <Project64-core/N64System/Mips/OpCode.h>
class CCodeSection;
class CRecompilerOps
{
public:
enum BRANCH_TYPE
{
BranchTypeCop1,
BranchTypeRs,
BranchTypeRsRt
};
enum BRANCH_COMPARE
{
CompareTypeBEQ,
CompareTypeBNE,
CompareTypeBLTZ,
CompareTypeBLEZ,
CompareTypeBGTZ,
CompareTypeBGEZ,
CompareTypeCOP1BCF,
CompareTypeCOP1BCT,
};
/************************** Branch functions ************************/
virtual void Compile_Branch(BRANCH_COMPARE CompareType, BRANCH_TYPE BranchType, bool Link) = 0;
virtual void Compile_BranchLikely(BRANCH_COMPARE CompareType, bool Link) = 0;
/************************* OpCode functions *************************/
virtual void J() = 0;
virtual void JAL() = 0;
virtual void ADDI() = 0;
virtual void ADDIU() = 0;
virtual void SLTI() = 0;
virtual void SLTIU() = 0;
virtual void ANDI() = 0;
virtual void ORI() = 0;
virtual void XORI() = 0;
virtual void LUI() = 0;
virtual void DADDIU() = 0;
virtual void LDL() = 0;
virtual void LDR() = 0;
virtual void LB() = 0;
virtual void LH() = 0;
virtual void LWL() = 0;
virtual void LW() = 0;
virtual void LBU() = 0;
virtual void LHU() = 0;
virtual void LWR() = 0;
virtual void LWU() = 0;
virtual void SB() = 0;
virtual void SH() = 0;
virtual void SWL() = 0;
virtual void SW() = 0;
virtual void SWR() = 0;
virtual void SDL() = 0;
virtual void SDR() = 0;
virtual void CACHE() = 0;
virtual void LL() = 0;
virtual void LWC1() = 0;
virtual void LDC1() = 0;
virtual void LD() = 0;
virtual void SC() = 0;
virtual void SWC1() = 0;
virtual void SDC1() = 0;
virtual void SD() = 0;
/********************** R4300i OpCodes: Special **********************/
virtual void SPECIAL_SLL() = 0;
virtual void SPECIAL_SRL() = 0;
virtual void SPECIAL_SRA() = 0;
virtual void SPECIAL_SLLV() = 0;
virtual void SPECIAL_SRLV() = 0;
virtual void SPECIAL_SRAV() = 0;
virtual void SPECIAL_JR() = 0;
virtual void SPECIAL_JALR() = 0;
virtual void SPECIAL_SYSCALL() = 0;
virtual void SPECIAL_MFLO() = 0;
virtual void SPECIAL_MTLO() = 0;
virtual void SPECIAL_MFHI() = 0;
virtual void SPECIAL_MTHI() = 0;
virtual void SPECIAL_DSLLV() = 0;
virtual void SPECIAL_DSRLV() = 0;
virtual void SPECIAL_DSRAV() = 0;
virtual void SPECIAL_MULT() = 0;
virtual void SPECIAL_MULTU() = 0;
virtual void SPECIAL_DIV() = 0;
virtual void SPECIAL_DIVU() = 0;
virtual void SPECIAL_DMULT() = 0;
virtual void SPECIAL_DMULTU() = 0;
virtual void SPECIAL_DDIV() = 0;
virtual void SPECIAL_DDIVU() = 0;
virtual void SPECIAL_ADD() = 0;
virtual void SPECIAL_ADDU() = 0;
virtual void SPECIAL_SUB() = 0;
virtual void SPECIAL_SUBU() = 0;
virtual void SPECIAL_AND() = 0;
virtual void SPECIAL_OR() = 0;
virtual void SPECIAL_XOR() = 0;
virtual void SPECIAL_NOR() = 0;
virtual void SPECIAL_SLT() = 0;
virtual void SPECIAL_SLTU() = 0;
virtual void SPECIAL_DADD() = 0;
virtual void SPECIAL_DADDU() = 0;
virtual void SPECIAL_DSUB() = 0;
virtual void SPECIAL_DSUBU() = 0;
virtual void SPECIAL_DSLL() = 0;
virtual void SPECIAL_DSRL() = 0;
virtual void SPECIAL_DSRA() = 0;
virtual void SPECIAL_DSLL32() = 0;
virtual void SPECIAL_DSRL32() = 0;
virtual void SPECIAL_DSRA32() = 0;
/************************** COP0 functions **************************/
virtual void COP0_MF() = 0;
virtual void COP0_MT() = 0;
/************************** COP0 CO functions ***********************/
virtual void COP0_CO_TLBR() = 0;
virtual void COP0_CO_TLBWI() = 0;
virtual void COP0_CO_TLBWR() = 0;
virtual void COP0_CO_TLBP() = 0;
virtual void COP0_CO_ERET() = 0;
/************************** COP1 functions **************************/
virtual void COP1_MF() = 0;
virtual void COP1_DMF() = 0;
virtual void COP1_CF() = 0;
virtual void COP1_MT() = 0;
virtual void COP1_DMT() = 0;
virtual void COP1_CT() = 0;
/************************** COP1: S functions ************************/
virtual void COP1_S_ADD() = 0;
virtual void COP1_S_SUB() = 0;
virtual void COP1_S_MUL() = 0;
virtual void COP1_S_DIV() = 0;
virtual void COP1_S_ABS() = 0;
virtual void COP1_S_NEG() = 0;
virtual void COP1_S_SQRT() = 0;
virtual void COP1_S_MOV() = 0;
virtual void COP1_S_ROUND_L() = 0;
virtual void COP1_S_TRUNC_L() = 0;
virtual void COP1_S_CEIL_L() = 0;
virtual void COP1_S_FLOOR_L() = 0;
virtual void COP1_S_ROUND_W() = 0;
virtual void COP1_S_TRUNC_W() = 0;
virtual void COP1_S_CEIL_W() = 0;
virtual void COP1_S_FLOOR_W() = 0;
virtual void COP1_S_CVT_D() = 0;
virtual void COP1_S_CVT_W() = 0;
virtual void COP1_S_CVT_L() = 0;
virtual void COP1_S_CMP() = 0;
/************************** COP1: D functions ************************/
virtual void COP1_D_ADD() = 0;
virtual void COP1_D_SUB() = 0;
virtual void COP1_D_MUL() = 0;
virtual void COP1_D_DIV() = 0;
virtual void COP1_D_ABS() = 0;
virtual void COP1_D_NEG() = 0;
virtual void COP1_D_SQRT() = 0;
virtual void COP1_D_MOV() = 0;
virtual void COP1_D_ROUND_L() = 0;
virtual void COP1_D_TRUNC_L() = 0;
virtual void COP1_D_CEIL_L() = 0;
virtual void COP1_D_FLOOR_L() = 0;
virtual void COP1_D_ROUND_W() = 0;
virtual void COP1_D_TRUNC_W() = 0;
virtual void COP1_D_CEIL_W() = 0;
virtual void COP1_D_FLOOR_W() = 0;
virtual void COP1_D_CVT_S() = 0;
virtual void COP1_D_CVT_W() = 0;
virtual void COP1_D_CVT_L() = 0;
virtual void COP1_D_CMP() = 0;
/************************** COP1: W functions ************************/
virtual void COP1_W_CVT_S() = 0;
virtual void COP1_W_CVT_D() = 0;
/************************** COP1: L functions ************************/
virtual void COP1_L_CVT_S() = 0;
virtual void COP1_L_CVT_D() = 0;
/************************** Other functions **************************/
virtual void UnknownOpcode() = 0;
virtual void EnterCodeBlock() = 0;
virtual void ExitCodeBlock() = 0;
virtual void CompileExitCode() = 0;
virtual void CompileCop1Test() = 0;
virtual void CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCounter) = 0;
virtual void SyncRegState(const CRegInfo & SyncTo) = 0;
virtual void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo &ExitRegSet, CExitInfo::EXIT_REASON reason, bool CompileNow) = 0;
virtual void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet) = 0;
virtual CRegInfo & GetRegWorkingSet(void) = 0;
virtual void SetRegWorkingSet(const CRegInfo & RegInfo) = 0;
virtual bool InheritParentInfo() = 0;
virtual void LinkJump(CJumpInfo & JumpInfo, uint32_t SectionID = -1, uint32_t FromSectionID = -1) = 0;
virtual void JumpToSection(CCodeSection * Section) = 0;
virtual void JumpToUnknown(CJumpInfo * JumpInfo) = 0;
virtual void SetCurrentPC(uint32_t ProgramCounter) = 0;
virtual uint32_t GetCurrentPC(void) = 0;
virtual void SetCurrentSection(CCodeSection * section) = 0;
virtual void SetNextStepType(STEP_TYPE StepType) = 0;
virtual STEP_TYPE GetNextStepType(void) = 0;
virtual const OPCODE & GetOpcode(void) const = 0;
virtual void PreCompileOpcode(void) = 0;
virtual void PostCompileOpcode(void) = 0;
virtual void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false) = 0;
};

View File

@ -14,6 +14,7 @@
#include <Project64-core/N64System/Mips/OpCode.h>
#include <Project64-core/N64System/Recompiler/ExitInfo.h>
#include <Project64-core/N64System/Recompiler/RegInfo.h>
#include <Project64-core/N64System/Recompiler/RecompilerOps.h>
#include <Project64-core/N64System/Recompiler/x86/x86ops.h>
#include <Project64-core/N64System/Recompiler/JumpInfo.h>
#include <Project64-core/Settings/DebugSettings.h>
@ -23,7 +24,8 @@
class CCodeBlock;
class CCodeSection;
class CRecompilerOps :
class CX86RecompilerOps :
public CRecompilerOps,
protected CDebugSettings,
protected CX86Ops,
protected CSystemRegisters,
@ -31,24 +33,6 @@ class CRecompilerOps :
protected CRecompilerSettings
{
public:
enum BRANCH_TYPE
{
BranchTypeCop1,
BranchTypeRs,
BranchTypeRsRt
};
enum BRANCH_COMPARE
{
CompareTypeBEQ,
CompareTypeBNE,
CompareTypeBLTZ,
CompareTypeBLEZ,
CompareTypeBGTZ,
CompareTypeBGEZ,
CompareTypeCOP1BCF,
CompareTypeCOP1BCT,
};
/************************** Branch functions ************************/
void Compile_BranchCompare(BRANCH_COMPARE CompareType);
void Compile_Branch(BRANCH_COMPARE CompareType, BRANCH_TYPE BranchType, bool Link);
@ -221,8 +205,8 @@ public:
/************************** Other functions **************************/
void UnknownOpcode();
static void EnterCodeBlock();
static void ExitCodeBlock();
void EnterCodeBlock();
void ExitCodeBlock();
void CompileExitCode();
void CompileCop1Test();
void CompileInPermLoop(CRegInfo & RegSet, uint32_t ProgramCounter);
@ -250,11 +234,10 @@ public:
void CompileReadTLBMiss(x86Reg AddressReg, x86Reg LookUpReg);
void CompileWriteTLBMiss(x86Reg AddressReg, x86Reg LookUpReg);
static void UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles);
static void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false);
static void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet);
void UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool ClearValues = false);
void CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet);
static void ChangeDefaultRoundingModel();
static void OverflowDelaySlot(bool TestTimer);
void OverflowDelaySlot(bool TestTimer);
/********* Helper Functions *********/
typedef CRegInfo::REG_STATE REG_STATE;