Core: Direct tlb method to read and write to memory

This commit is contained in:
zilmar 2022-05-02 20:22:31 +09:30
parent bac3517c86
commit 5a49331c0b
10 changed files with 223 additions and 50 deletions

View File

@ -212,9 +212,9 @@ void CEnhancements::ResetCodes(CMipsMemoryVM * MMU)
for (ORIGINAL_VALUES8::iterator itr = m_OriginalValues8.begin(); itr != m_OriginalValues8.end(); itr++)
{
uint8_t CurrentValue;
if (MMU->LB_VAddr(itr->first, CurrentValue) && itr->second.Changed == CurrentValue)
if (MMU->MemoryValue8(itr->first, CurrentValue) && itr->second.Changed == CurrentValue)
{
MMU->SB_VAddr(itr->first, itr->second.Original);
MMU->UpdateMemoryValue8(itr->first, itr->second.Original);
}
}
}
@ -225,9 +225,9 @@ void CEnhancements::ResetCodes(CMipsMemoryVM * MMU)
for (ORIGINAL_VALUES16::iterator itr = m_OriginalValues16.begin(); itr != m_OriginalValues16.end(); itr++)
{
uint16_t CurrentValue;
if (MMU->LH_VAddr(itr->first, CurrentValue) && itr->second.Changed == CurrentValue)
if (MMU->MemoryValue16(itr->first, CurrentValue) && itr->second.Changed == CurrentValue)
{
MMU->SH_VAddr(itr->first, itr->second.Original);
MMU->UpdateMemoryValue16(itr->first, itr->second.Original);
}
}
}
@ -468,28 +468,28 @@ void CEnhancements::ApplyGameSharkCodes(CMipsMemoryVM & MMU, CODES & CodeEntry,
ModifyMemory16(MMU, 0xA0000000 | (Code.Command() & 0xFFFFFF), Code.Value(), Code.HasDisableValue(), Code.DisableValue());
break;
case 0xD0000000:
MMU.LB_VAddr(0x80000000 | (Code.Command() & 0xFFFFFF), bMemory);
MMU.MemoryValue8(0x80000000 | (Code.Command() & 0xFFFFFF), bMemory);
if (bMemory == Code.Value())
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
}
break;
case 0xD1000000:
MMU.LH_VAddr(0x80000000 | (Code.Command() & 0xFFFFFF), wMemory);
MMU.MemoryValue16(0x80000000 | (Code.Command() & 0xFFFFFF), wMemory);
if (wMemory == Code.Value())
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
}
break;
case 0xD2000000:
MMU.LB_VAddr(0x80000000 | (Code.Command() & 0xFFFFFF), bMemory);
MMU.MemoryValue8(0x80000000 | (Code.Command() & 0xFFFFFF), bMemory);
if (bMemory != Code.Value())
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
}
break;
case 0xD3000000:
MMU.LH_VAddr(0x80000000 | (Code.Command() & 0xFFFFFF), wMemory);
MMU.MemoryValue16(0x80000000 | (Code.Command() & 0xFFFFFF), wMemory);
if (wMemory != Code.Value())
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
@ -514,7 +514,7 @@ void CEnhancements::ApplyGameSharkCodes(CMipsMemoryVM & MMU, CODES & CodeEntry,
break;
case 0xB8000000:
case 0xBA000000:
MMU.LB_VAddr(0x80000000 | (ConvertXP64Address(Code.Command()) & 0xFFFFFF), bMemory);
MMU.MemoryValue8(0x80000000 | (ConvertXP64Address(Code.Command()) & 0xFFFFFF), bMemory);
if (bMemory == ConvertXP64Value(Code.Value()))
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
@ -522,7 +522,7 @@ void CEnhancements::ApplyGameSharkCodes(CMipsMemoryVM & MMU, CODES & CodeEntry,
break;
case 0xB9000000:
case 0xBB000000:
MMU.LH_VAddr(0x80000000 | (ConvertXP64Address(Code.Command()) & 0xFFFFFF), wMemory);
MMU.MemoryValue16(0x80000000 | (ConvertXP64Address(Code.Command()) & 0xFFFFFF), wMemory);
if (wMemory == ConvertXP64Value(Code.Value()))
{
ApplyGameSharkCodes(MMU, CodeEntry, CurrentEntry + 1);
@ -587,7 +587,7 @@ void CEnhancements::ModifyMemory8(CMipsMemoryVM & MMU, uint32_t Address, uint8_t
}
else
{
if (!MMU.LB_VAddr(Address, OriginalValue.Original))
if (!MMU.MemoryValue8(Address, OriginalValue.Original))
{
return;
}
@ -596,7 +596,7 @@ void CEnhancements::ModifyMemory8(CMipsMemoryVM & MMU, uint32_t Address, uint8_t
{
return;
}
MMU.SB_VAddr(Address, Value);
MMU.UpdateMemoryValue8(Address, Value);
if (g_Recompiler)
{
g_Recompiler->ClearRecompCode_Virt(Address & ~0xFFF, 0x1000, CRecompiler::Remove_Cheats);
@ -614,7 +614,7 @@ void CEnhancements::ModifyMemory16(CMipsMemoryVM & MMU, uint32_t Address, uint16
}
else
{
if (!MMU.LH_VAddr(Address, OriginalValue.Original))
if (!MMU.MemoryValue16(Address, OriginalValue.Original))
{
return;
}
@ -625,7 +625,7 @@ void CEnhancements::ModifyMemory16(CMipsMemoryVM & MMU, uint32_t Address, uint16
}
OriginalValue.Changed = Value;
std::pair<ORIGINAL_VALUES16::iterator, bool> itr = m_OriginalValues16.insert(ORIGINAL_VALUES16::value_type(Address, OriginalValue));
MMU.SH_VAddr(Address, OriginalValue.Changed);
MMU.UpdateMemoryValue16(Address, OriginalValue.Changed);
if (g_Recompiler)
{
g_Recompiler->ClearRecompCode_Virt(Address & ~0xFFF, 0x1000, CRecompiler::Remove_Cheats);

View File

@ -22,7 +22,7 @@ bool DelaySlotEffectsCompare(uint32_t PC, uint32_t Reg1, uint32_t Reg2)
{
OPCODE Command;
if (!g_MMU->LW_VAddr(PC + 4, Command.Hex))
if (!g_MMU->MemoryValue32(PC + 4, Command.Hex))
{
//g_Notify->DisplayError("Failed to load word 2");
//ExitThread(0);
@ -273,7 +273,7 @@ void CInterpreterCPU::ExecuteCPU()
{
while (!Done)
{
if (!g_MMU->LW_VAddr(PROGRAM_COUNTER, Opcode.Hex))
if (!g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Hex))
{
g_Reg->DoTLBReadMiss(PipelineStage == PIPELINE_STAGE_JUMP, PROGRAM_COUNTER);
PipelineStage = PIPELINE_STAGE_NORMAL;
@ -390,7 +390,7 @@ void CInterpreterCPU::ExecuteOps(int32_t Cycles)
return;
}
if (g_MMU->LW_VAddr(PROGRAM_COUNTER, Opcode.Hex))
if (g_MMU->MemoryValue32(PROGRAM_COUNTER, Opcode.Hex))
{
/*if (PROGRAM_COUNTER > 0x80000300 && PROGRAM_COUNTER< 0x80380000)
{
@ -411,7 +411,7 @@ void CInterpreterCPU::ExecuteOps(int32_t Cycles)
*g_NextTimer -= CountPerOp;
/*static uint32_t TestAddress = 0x80077B0C, TestValue = 0, CurrentValue = 0;
if (g_MMU->LW_VAddr(TestAddress, TestValue))
if (g_MMU->MemoryValue32(TestAddress, TestValue))
{
if (TestValue != CurrentValue)
{

View File

@ -19,27 +19,30 @@ CDMA::CDMA(CartridgeDomain2Address2Handler & Domain2Address2Handler) :
void CDMA::OnFirstDMA()
{
int16_t offset;
const uint32_t base = 0x80000000;
const uint32_t rt = g_MMU->RdramSize();
switch (g_Rom->CicChipID())
{
case CIC_NUS_6101: offset = 0x0318; break;
case CIC_NUS_5167: offset = 0x0318; break;
case CIC_NUS_8303: offset = 0x0318; break;
case CIC_NUS_DDUS: offset = 0x0318; break;
case CIC_NUS_8401: offset = 0x0318; break;
case CIC_NUS_6101:
case CIC_NUS_5167:
case CIC_NUS_8303:
case CIC_NUS_DDUS:
case CIC_NUS_8401:
case CIC_UNKNOWN:
case CIC_NUS_6102: offset = 0x0318; break;
case CIC_NUS_6103: offset = 0x0318; break;
case CIC_NUS_6105: offset = 0x03F0; break;
case CIC_NUS_6106: offset = 0x0318; break;
case CIC_NUS_5101: offset = 0x0318; break;
case CIC_NUS_6102:
case CIC_NUS_6103:
case CIC_NUS_6106:
case CIC_NUS_5101:
offset = 0x0318;
break;
case CIC_NUS_6105:
offset = 0x03F0;
break;
default:
g_Notify->DisplayError(stdstr_f("Unhandled CicChip(%d) in first DMA", g_Rom->CicChipID()).c_str());
return;
}
g_MMU->SW_VAddr(base + offset, rt);
g_MMU->UpdateMemoryValue32(0x80000000 + offset, rt);
}
void CDMA::PI_DMA_READ()

View File

@ -266,6 +266,168 @@ void CMipsMemoryVM::FreeMemory()
CPifRam::Reset();
}
bool CMipsMemoryVM::MemoryValue8(uint32_t VAddr, uint8_t& Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = (m_TLB_ReadMap[VAddr >> 12] + VAddr) ^ 3;
if (PAddr < m_AllocatedRdramSize)
{
Value = *(uint8_t*)(m_RDRAM + PAddr);
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
Value = *(uint8_t*)(m_DMEM + (PAddr - 0x04000000));
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
Value = *(uint8_t*)(m_IMEM + (PAddr - 0x04001000));
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::MemoryValue16(uint32_t VAddr, uint16_t& Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = (m_TLB_ReadMap[VAddr >> 12] + VAddr) ^ 2;
if (PAddr < m_AllocatedRdramSize)
{
Value = *(uint16_t*)(m_RDRAM + PAddr);
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
Value = *(uint16_t*)(m_DMEM + (PAddr - 0x04000000));
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
Value = *(uint16_t*)(m_IMEM + (PAddr - 0x04001000));
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::MemoryValue32(uint32_t VAddr, uint32_t& Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr;
if (PAddr < m_AllocatedRdramSize)
{
Value = *(uint32_t*)(m_RDRAM + PAddr);
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
Value = *(uint32_t*)(m_DMEM + (PAddr - 0x04000000));
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
Value = *(uint32_t*)(m_IMEM + (PAddr - 0x04001000));
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::UpdateMemoryValue8(uint32_t VAddr, uint8_t Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = (m_TLB_ReadMap[VAddr >> 12] + VAddr) ^ 3;
if (PAddr < m_AllocatedRdramSize)
{
*(uint8_t*)(m_RDRAM + PAddr) = Value;
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
*(uint8_t*)(m_DMEM + (PAddr - 0x04000000)) = Value;
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
*(uint8_t*)(m_IMEM + (PAddr - 0x04001000)) = Value;
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::UpdateMemoryValue16(uint32_t VAddr, uint16_t Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = (m_TLB_ReadMap[VAddr >> 12] + VAddr) ^ 2;
if (PAddr < m_AllocatedRdramSize)
{
*(uint16_t*)(m_RDRAM + PAddr) = Value;
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
*(uint16_t*)(m_DMEM + (PAddr - 0x04000000)) = Value;
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
*(uint16_t*)(m_IMEM + (PAddr - 0x04001000)) = Value;
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::UpdateMemoryValue32(uint32_t VAddr, uint32_t Value)
{
if (m_TLB_ReadMap[VAddr >> 12] == -1)
{
return false;
}
uint32_t PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr;
if (PAddr < m_AllocatedRdramSize)
{
*(uint32_t*)(m_RDRAM + PAddr) = Value;
return true;
}
if (PAddr >= 0x04000000 && PAddr < 0x04001000)
{
*(uint32_t*)(m_DMEM + (PAddr - 0x04000000)) = Value;
return true;
}
if (PAddr >= 0x04001000 && PAddr < 0x04002000)
{
*(uint32_t*)(m_IMEM + (PAddr - 0x04001000)) = Value;
return true;
}
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;
}
bool CMipsMemoryVM::LB_VAddr(uint32_t VAddr, uint8_t& Value)
{
uint8_t * MemoryPtr = (uint8_t*)m_MemoryReadMap[VAddr >> 12];
@ -438,7 +600,7 @@ bool CMipsMemoryVM::VAddrToPAddr(uint32_t VAddr, uint32_t &PAddr) const
{
return false;
}
PAddr = (uint32_t)(uint8_t *)(m_TLB_ReadMap[VAddr >> 12] + VAddr);
PAddr = m_TLB_ReadMap[VAddr >> 12] + VAddr;
return true;
}

View File

@ -73,6 +73,14 @@ public:
CSram & GetSram() { return m_CartridgeDomain2Address2Handler.Sram(); }
CFlashRam & GetFlashRam() { return m_CartridgeDomain2Address2Handler.FlashRam(); }
bool MemoryValue8(uint32_t VAddr, uint8_t & Value);
bool MemoryValue16(uint32_t VAddr, uint16_t & Value);
bool MemoryValue32(uint32_t VAddr, uint32_t & Value);
bool UpdateMemoryValue8(uint32_t VAddr, uint8_t Value);
bool UpdateMemoryValue16(uint32_t VAddr, uint16_t Value);
bool UpdateMemoryValue32(uint32_t VAddr, uint32_t Value);
bool LB_VAddr(uint32_t VAddr, uint8_t & Value);
bool LH_VAddr(uint32_t VAddr, uint16_t & Value);
bool LW_VAddr(uint32_t VAddr, uint32_t & Value);

View File

@ -1087,7 +1087,7 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU)
m_Reg.m_GPR[24].DW = 0x0000000000000000;
break;
case CIC_NUS_6105:
MMU.SW_VAddr(0xA4001004, 0xBDA807FC);
MMU.UpdateMemoryValue32(0xA4001004, 0xBDA807FC);
m_Reg.m_GPR[5].DW = 0xFFFFFFFFDECAAAD1;
m_Reg.m_GPR[14].DW = 0x000000000CF85C13;
m_Reg.m_GPR[24].DW = 0x0000000000000002;
@ -1116,7 +1116,7 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU)
m_Reg.m_GPR[14].DW = 0x000000005BACA1DF;
break;
case CIC_NUS_6105:
MMU.SW_VAddr(0xA4001004, 0x8DA807FC);
MMU.UpdateMemoryValue32(0xA4001004, 0x8DA807FC);
m_Reg.m_GPR[5].DW = 0x000000005493FB9A;
m_Reg.m_GPR[14].DW = 0xFFFFFFFFC2C20384;
case CIC_NUS_6106:
@ -1180,13 +1180,13 @@ void CN64System::InitRegisters(bool bPostPif, CMipsMemoryVM & MMU)
m_Reg.m_GPR[25].DW = 0xFFFFFFFF825B21C9;
break;
case CIC_NUS_6105:
MMU.SW_VAddr(0xA4001000, 0x3C0DBFC0);
MMU.SW_VAddr(0xA4001008, 0x25AD07C0);
MMU.SW_VAddr(0xA400100C, 0x31080080);
MMU.SW_VAddr(0xA4001010, 0x5500FFFC);
MMU.SW_VAddr(0xA4001014, 0x3C0DBFC0);
MMU.SW_VAddr(0xA4001018, 0x8DA80024);
MMU.SW_VAddr(0xA400101C, 0x3C0BB000);
MMU.UpdateMemoryValue32(0xA4001000, 0x3C0DBFC0);
MMU.UpdateMemoryValue32(0xA4001008, 0x25AD07C0);
MMU.UpdateMemoryValue32(0xA400100C, 0x31080080);
MMU.UpdateMemoryValue32(0xA4001010, 0x5500FFFC);
MMU.UpdateMemoryValue32(0xA4001014, 0x3C0DBFC0);
MMU.UpdateMemoryValue32(0xA4001018, 0x8DA80024);
MMU.UpdateMemoryValue32(0xA400101C, 0x3C0BB000);
m_Reg.m_GPR[1].DW = 0x0000000000000000;
m_Reg.m_GPR[2].DW = 0xFFFFFFFFF58B0FBF;
m_Reg.m_GPR[3].DW = 0xFFFFFFFFF58B0FBF;
@ -1733,7 +1733,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
for (count = -10; count < 10; count++)
{
uint32_t OpcodeValue, Addr = m_Reg.m_PROGRAM_COUNTER + (count << 2);
if (g_MMU->LW_VAddr(Addr, OpcodeValue))
if (g_MMU->MemoryValue32(Addr, OpcodeValue))
{
Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr));
}
@ -1743,7 +1743,7 @@ void CN64System::DumpSyncErrors(CN64System * SecondCPU)
for (count = 0; count < 50; count++)
{
uint32_t OpcodeValue, Addr = m_LastSuccessSyncPC[0] + (count << 2);
if (g_MMU->LW_VAddr(Addr, OpcodeValue))
if (g_MMU->MemoryValue32(Addr, OpcodeValue))
{
Error.LogF("%X: %s\r\n", Addr, R4300iOpcodeName(OpcodeValue, Addr));
}
@ -2352,7 +2352,7 @@ void CN64System::RunRSP()
uint32_t Task = 0;
if (m_RspBroke)
{
g_MMU->LW_VAddr(0xA4000FC0, Task);
g_MMU->MemoryValue32(0xA4000FC0, Task);
if (Task == 1 && UseHleGfx() && (m_Reg.DPC_STATUS_REG & DPC_STATUS_FREEZE) != 0)
{
WriteTrace(TraceRSP, TraceDebug, "Dlist that is frozen");

View File

@ -445,7 +445,7 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t &
PermLoop = false;
OPCODE Command;
if (!g_MMU->LW_VAddr(PC, Command.Hex))
if (!g_MMU->MemoryValue32(PC, Command.Hex))
{
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;

View File

@ -64,7 +64,7 @@ static bool DelaySlotEffectsJump(uint32_t JumpPC)
{
OPCODE Command;
if (!g_MMU->LW_VAddr(JumpPC, Command.Hex))
if (!g_MMU->MemoryValue32(JumpPC, Command.Hex))
{
return true;
}
@ -112,7 +112,7 @@ static bool DelaySlotEffectsJump(uint32_t JumpPC)
bool EffectDelaySlot = false;
OPCODE NewCommand;
if (!g_MMU->LW_VAddr(JumpPC + 4, NewCommand.Hex))
if (!g_MMU->MemoryValue32(JumpPC + 4, NewCommand.Hex))
{
return true;
}

View File

@ -172,7 +172,7 @@ bool LoopAnalysis::CheckLoopRegisterUsage(CCodeSection * Section)
do
{
if (!g_MMU->LW_VAddr(m_PC, m_Command.Hex))
if (!g_MMU->MemoryValue32(m_PC, m_Command.Hex))
{
g_Notify->BreakPoint(__FILE__, __LINE__);
return false;

View File

@ -51,7 +51,7 @@ static void x86_compiler_Break_Point()
g_Reg->m_PROGRAM_COUNTER += 4;
uint32_t OpcodeValue;
if (!g_MMU->LW_VAddr(g_Reg->m_PROGRAM_COUNTER, OpcodeValue))
if (!g_MMU->MemoryValue32(g_Reg->m_PROGRAM_COUNTER, OpcodeValue))
{
g_Reg->DoTLBReadMiss(false, g_Reg->m_PROGRAM_COUNTER);
continue;
@ -483,7 +483,7 @@ void CX86RecompilerOps::Compile_Branch(BRANCH_COMPARE CompareType, BRANCH_TYPE B
{
OPCODE Command;
if (!g_MMU->LW_VAddr(m_CompilePC + 4, Command.Hex))
if (!g_MMU->MemoryValue32(m_CompilePC + 4, Command.Hex))
{
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
}
@ -9848,7 +9848,7 @@ void CX86RecompilerOps::SetCurrentPC(uint32_t ProgramCounter)
m_CompilePC = ProgramCounter;
__except_try()
{
if (!g_MMU->LW_VAddr(m_CompilePC, m_Opcode.Hex))
if (!g_MMU->MemoryValue32(m_CompilePC, m_Opcode.Hex))
{
g_Notify->FatalError(GS(MSG_FAIL_LOAD_WORD));
}