better chances at safe TLB paddr allocation to integers

This commit is contained in:
unknown 2015-08-26 22:30:45 -04:00
parent 3b6d55cc5c
commit da232c590a
2 changed files with 42 additions and 24 deletions

View File

@ -50,24 +50,26 @@ void CMipsMemoryVM::Reset( bool /*EraseMemory*/ )
{ {
if (m_TLB_ReadMap) if (m_TLB_ReadMap)
{ {
memset(m_TLB_ReadMap,0,(0xFFFFF * sizeof(DWORD))); size_t address;
memset(m_TLB_WriteMap,0,(0xFFFFF * sizeof(DWORD)));
for (DWORD address = 0x80000000; address < 0xC0000000; address += 0x1000) memset(m_TLB_ReadMap , 0, 0xFFFFF * sizeof(size_t));
memset(m_TLB_WriteMap, 0, 0xFFFFF * sizeof(size_t));
for (address = 0x80000000; address < 0xC0000000; address += 0x1000)
{ {
m_TLB_ReadMap[address >> 12] = ((DWORD)m_RDRAM + (address & 0x1FFFFFFF)) - address; m_TLB_ReadMap[address >> 12] = ((size_t)m_RDRAM + (address & 0x1FFFFFFF)) - address;
m_TLB_WriteMap[address >> 12] = ((DWORD)m_RDRAM + (address & 0x1FFFFFFF)) - address; m_TLB_WriteMap[address >> 12] = ((size_t)m_RDRAM + (address & 0x1FFFFFFF)) - address;
} }
if (g_Settings->LoadDword(Rdb_TLB_VAddrStart) != 0) if (g_Settings->LoadDword(Rdb_TLB_VAddrStart) != 0)
{ {
DWORD Start = g_Settings->LoadDword(Rdb_TLB_VAddrStart); //0x7F000000; size_t Start = g_Settings->LoadDword(Rdb_TLB_VAddrStart); //0x7F000000;
DWORD Len = g_Settings->LoadDword(Rdb_TLB_VAddrLen); //0x01000000; size_t Len = g_Settings->LoadDword(Rdb_TLB_VAddrLen); //0x01000000;
DWORD PAddr = g_Settings->LoadDword(Rdb_TLB_PAddrStart); //0x10034b30; size_t PAddr = g_Settings->LoadDword(Rdb_TLB_PAddrStart); //0x10034b30;
DWORD End = Start + Len; size_t End = Start + Len;
for (DWORD address = Start; address < End; address += 0x1000) for (address = Start; address < End; address += 0x1000)
{ {
m_TLB_ReadMap[address >> 12] = ((DWORD)m_RDRAM + (address - Start + PAddr)) - address; m_TLB_ReadMap[address >> 12] = ((size_t)m_RDRAM + (address - Start + PAddr)) - address;
m_TLB_WriteMap[address >> 12] = ((DWORD)m_RDRAM + (address - Start + PAddr)) - address; m_TLB_WriteMap[address >> 12] = ((size_t)m_RDRAM + (address - Start + PAddr)) - address;
} }
} }
} }
@ -164,18 +166,28 @@ bool CMipsMemoryVM::Initialize()
} }
CPifRam::Reset(); CPifRam::Reset();
m_TLB_ReadMap = (DWORD *)VirtualAlloc(NULL,0xFFFFF * sizeof(DWORD),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); m_TLB_ReadMap = (size_t *)VirtualAlloc(
NULL,
0xFFFFF * sizeof(size_t),
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE
);
if (m_TLB_ReadMap == NULL) if (m_TLB_ReadMap == NULL)
{ {
WriteTraceF(TraceError,__FUNCTION__": Failed to Allocate m_TLB_ReadMap (Size: 0x%X)",0xFFFFF * sizeof(DWORD)); WriteTraceF(TraceError,__FUNCTION__": Failed to Allocate m_TLB_ReadMap (Size: 0x%X)",0xFFFFF * sizeof(size_t));
FreeMemory(); FreeMemory();
return false; return false;
} }
m_TLB_WriteMap = (DWORD *)VirtualAlloc(NULL,0xFFFFF * sizeof(DWORD),MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); m_TLB_WriteMap = (size_t *)VirtualAlloc(
NULL,
0xFFFFF * sizeof(size_t),
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE
);
if (m_TLB_WriteMap == NULL) if (m_TLB_WriteMap == NULL)
{ {
WriteTraceF(TraceError,__FUNCTION__": Failed to Allocate m_TLB_WriteMap (Size: 0x%X)",0xFFFFF * sizeof(DWORD)); WriteTraceF(TraceError,__FUNCTION__": Failed to Allocate m_TLB_WriteMap (Size: 0x%X)",0xFFFFF * sizeof(size_t));
FreeMemory(); FreeMemory();
return false; return false;
} }
@ -5349,22 +5361,28 @@ LPCTSTR CMipsMemoryVM::LabelName ( DWORD Address ) const
void CMipsMemoryVM::TLB_Mapped( DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly ) void CMipsMemoryVM::TLB_Mapped( DWORD VAddr, DWORD Len, DWORD PAddr, bool bReadOnly )
{ {
for (DWORD count = VAddr, VEnd = VAddr + Len; count < VEnd; count += 0x1000) size_t count, VEnd;
VEnd = VAddr + Len;
for (count = VAddr; count < VEnd; count += 0x1000)
{ {
DWORD Index = count >> 12; size_t Index = count >> 12;
m_TLB_ReadMap[Index] = ((DWORD)m_RDRAM + (count - VAddr + PAddr)) - count; m_TLB_ReadMap[Index] = ((size_t)m_RDRAM + (count - VAddr + PAddr)) - count;
if (!bReadOnly) if (!bReadOnly)
{ {
m_TLB_WriteMap[Index] = ((DWORD)m_RDRAM + (count - VAddr + PAddr)) - count; m_TLB_WriteMap[Index] = ((size_t)m_RDRAM + (count - VAddr + PAddr)) - count;
} }
} }
} }
void CMipsMemoryVM::TLB_Unmaped( DWORD Vaddr, DWORD Len ) void CMipsMemoryVM::TLB_Unmaped( DWORD Vaddr, DWORD Len )
{ {
for (DWORD count = Vaddr, End = Vaddr + Len; count < End; count += 0x1000) size_t count, End;
End = Vaddr + Len;
for (count = Vaddr; count < End; count += 0x1000)
{ {
DWORD Index = count >> 12; size_t Index = count >> 12;
m_TLB_ReadMap[Index] = NULL; m_TLB_ReadMap[Index] = NULL;
m_TLB_WriteMap[Index] = NULL; m_TLB_WriteMap[Index] = NULL;
} }

View File

@ -166,6 +166,6 @@ private:
mutable char m_strLabelName[100]; mutable char m_strLabelName[100];
//BIG look up table to quickly translate the tlb to real mem address //BIG look up table to quickly translate the tlb to real mem address
DWORD * m_TLB_ReadMap; size_t * m_TLB_ReadMap;
DWORD * m_TLB_WriteMap; size_t * m_TLB_WriteMap;
}; };