newHostVM branch: (now boots games!)

* EE and IOP recompilers are using the new RecompiledCodeReserve class.
 * PS2 main memory should typically be located at 0x20000000 (code still need some cleanups)

VU0/VU1 recompilers will be implemented soon.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/newHostVM@3959 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2010-10-22 19:47:02 +00:00
parent 01541f2c92
commit bed33749b5
10 changed files with 99 additions and 38 deletions

View File

@ -68,12 +68,6 @@ wxString DiagnosticOrigin::ToString( const wxChar* msg ) const
} }
bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg )
{
wxLogError( L"%s", origin.ToString( msg ).c_str() );
return false;
}
// Because wxTrap isn't available on Linux builds of wxWidgets (non-Debug, typically) // Because wxTrap isn't available on Linux builds of wxWidgets (non-Debug, typically)
void pxTrap() void pxTrap()
{ {
@ -94,6 +88,16 @@ void pxTrap()
#endif // Win/Unix #endif // Win/Unix
} }
bool pxAssertImpl_LogIt( const DiagnosticOrigin& origin, const wxChar *msg )
{
//wxLogError( L"%s", origin.ToString( msg ).c_str() );
wxMessageOutputDebug().Printf( L"%s", origin.ToString( msg ).c_str() );
pxTrap();
return false;
}
DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg ) DEVASSERT_INLINE void pxOnAssert( const DiagnosticOrigin& origin, const wxChar* msg )
{ {
// Recursion guard: Allow at least one recursive call. This is useful because sometimes // Recursion guard: Allow at least one recursive call. This is useful because sometimes

View File

@ -582,7 +582,7 @@ protected:
void OnPageFaultEvent( const PageFaultInfo& info, bool& handled ); void OnPageFaultEvent( const PageFaultInfo& info, bool& handled );
}; };
static mmap_PageFaultHandler mmap_faultHandler; static mmap_PageFaultHandler* mmap_faultHandler = NULL;
EEVM_MemoryAllocMess* eeMem = NULL; EEVM_MemoryAllocMess* eeMem = NULL;
@ -596,12 +596,13 @@ void memAlloc()
if( eeMem == NULL) if( eeMem == NULL)
throw Exception::OutOfMemory( L"memAlloc > failed to allocate PS2's base ram/rom/scratchpad." ); throw Exception::OutOfMemory( L"memAlloc > failed to allocate PS2's base ram/rom/scratchpad." );
Source_PageFault.Add( mmap_faultHandler ); pxAssume(Source_PageFault);
mmap_faultHandler = new mmap_PageFaultHandler();
} }
void memShutdown() void memShutdown()
{ {
Source_PageFault.Remove( mmap_faultHandler ); safe_delete(mmap_faultHandler);
vtlb_free( eeMem, sizeof(*eeMem) ); vtlb_free( eeMem, sizeof(*eeMem) );
eeMem = NULL; eeMem = NULL;

View File

@ -31,16 +31,18 @@ extern void resetNewVif(int idx);
template class EventSource< IEventListener_PageFault >; template class EventSource< IEventListener_PageFault >;
SrcType_PageFault Source_PageFault; SrcType_PageFault* Source_PageFault = NULL;
EventListener_PageFault::EventListener_PageFault() EventListener_PageFault::EventListener_PageFault()
{ {
Source_PageFault.Add( *this ); pxAssume(Source_PageFault);
Source_PageFault->Add( *this );
} }
EventListener_PageFault::~EventListener_PageFault() throw() EventListener_PageFault::~EventListener_PageFault() throw()
{ {
Source_PageFault.Remove( *this ); if (Source_PageFault)
Source_PageFault->Remove( *this );
} }
void SrcType_PageFault::Dispatch( const PageFaultInfo& params ) void SrcType_PageFault::Dispatch( const PageFaultInfo& params )
@ -108,11 +110,19 @@ void* BaseVirtualMemoryReserve::Reserve( uint size, uptr base, uptr upper_bounds
DevCon.WriteLn( Color_Blue, L"%s mapped @ 0x%08X -> 0x%08X [%umb]", Name.c_str(), DevCon.WriteLn( Color_Blue, L"%s mapped @ 0x%08X -> 0x%08X [%umb]", Name.c_str(),
m_baseptr, (uptr)m_baseptr+reserved_bytes, reserved_bytes / _1mb); m_baseptr, (uptr)m_baseptr+reserved_bytes, reserved_bytes / _1mb);
if (m_def_commit) /*if (m_def_commit)
{ {
HostSys::MmapCommit(m_baseptr, m_def_commit*__pagesize); const uint camt = m_def_commit * __pagesize;
HostSys::MemProtect(m_baseptr, m_def_commit*__pagesize, m_prot_mode); HostSys::MmapCommit(m_baseptr, camt);
} HostSys::MemProtect(m_baseptr, camt, m_prot_mode);
u8* init = (u8*)m_baseptr;
u8* endpos = init + camt;
for( ; init<endpos; init += m_block_size*__pagesize )
OnCommittedBlock(init);
m_commited += m_def_commit * __pagesize;
}*/
return m_baseptr; return m_baseptr;
} }
@ -153,9 +163,9 @@ void BaseVirtualMemoryReserve::OnPageFaultEvent(const PageFaultInfo& info, bool&
for( ; init<endpos; init += m_block_size*__pagesize ) for( ; init<endpos; init += m_block_size*__pagesize )
OnCommittedBlock(init); OnCommittedBlock(init);
handled = true;
m_commited += m_def_commit * __pagesize; m_commited += m_def_commit * __pagesize;
handled = true;
return; return;
} }
@ -176,7 +186,7 @@ void BaseVirtualMemoryReserve::OnPageFaultEvent(const PageFaultInfo& info, bool&
OnOutOfMemory( ex, (u8*)m_baseptr + (offset * __pagesize), handled ); OnOutOfMemory( ex, (u8*)m_baseptr + (offset * __pagesize), handled );
} }
#ifndef __WXMSW__ #ifndef __WXMSW__
// In windows we can let exceptions bubble out of the pag fault handler. SEH will more // In windows we can let exceptions bubble out of the page fault handler. SEH will more
// or less handle them in a semi-expected way, and might even avoid a GPF long enough // or less handle them in a semi-expected way, and might even avoid a GPF long enough
// for the system to log the error or something. // for the system to log the error or something.
@ -487,6 +497,31 @@ static wxString GetMemoryErrorVM()
); );
} }
// --------------------------------------------------------------------------------------
// SysReserveVM (implementations)
// --------------------------------------------------------------------------------------
SysReserveVM::SysReserveVM()
{
if (!Source_PageFault) Source_PageFault = new SrcType_PageFault();
// [TODO] : Reserve memory addresses for PS2 virtual machine
//DevCon.WriteLn( "Reserving memory addresses for the PS2 virtual machine..." );
}
void SysReserveVM::CleanupMess() throw()
{
try
{
safe_delete(Source_PageFault);
}
DESTRUCTOR_CATCHALL
}
SysReserveVM::~SysReserveVM() throw()
{
CleanupMess();
}
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// SysAllocVM (implementations) // SysAllocVM (implementations)
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------

View File

@ -60,6 +60,19 @@ namespace HostMemoryMap
static const uptr mVU1rec = 0x40000000; static const uptr mVU1rec = 0x40000000;
} }
// --------------------------------------------------------------------------------------
// SysReserveVM
// --------------------------------------------------------------------------------------
class SysReserveVM
{
public:
SysReserveVM();
virtual ~SysReserveVM() throw();
protected:
void CleanupMess() throw();
};
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
// SysAllocVM // SysAllocVM
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------

View File

@ -193,5 +193,5 @@ extern int SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS* eps);
extern void InstallSignalHandler(); extern void InstallSignalHandler();
extern SrcType_PageFault Source_PageFault; extern SrcType_PageFault* Source_PageFault;

View File

@ -476,6 +476,7 @@ public:
// blocked threads stalling the GUI. // blocked threads stalling the GUI.
ExecutorThread SysExecutorThread; ExecutorThread SysExecutorThread;
ScopedPtr<SysCpuProviderPack> m_CpuProviders; ScopedPtr<SysCpuProviderPack> m_CpuProviders;
ScopedPtr<SysReserveVM> m_VmReserve;
ScopedPtr<SysAllocVM> m_VmAllocs; ScopedPtr<SysAllocVM> m_VmAllocs;
protected: protected:

View File

@ -252,6 +252,8 @@ void Pcsx2App::AllocateCoreStuffs()
SysLogMachineCaps(); SysLogMachineCaps();
AppApplySettings(); AppApplySettings();
if (!m_VmReserve) m_VmReserve = new SysReserveVM();
if( !m_CpuProviders ) if( !m_CpuProviders )
{ {
// FIXME : Some or all of SysCpuProviderPack should be run from the SysExecutor thread, // FIXME : Some or all of SysCpuProviderPack should be run from the SysExecutor thread,

View File

@ -25,8 +25,8 @@ int SysPageFaultExceptionFilter( EXCEPTION_POINTERS* eps )
if( eps->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION ) if( eps->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION )
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
Source_PageFault.Dispatch( PageFaultInfo( (uptr)eps->ExceptionRecord->ExceptionInformation[1] ) ); Source_PageFault->Dispatch( PageFaultInfo( (uptr)eps->ExceptionRecord->ExceptionInformation[1] ) );
return Source_PageFault.WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH; return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH;
} }
void InstallSignalHandler() void InstallSignalHandler()

View File

@ -51,7 +51,7 @@ uptr psxhwLUT[0x10000];
#define HWADDR(mem) (psxhwLUT[mem >> 16] + (mem)) #define HWADDR(mem) (psxhwLUT[mem >> 16] + (mem))
static RecompiledCodeReserve recMem(L"R3000A recompiled code cache", _1mb * 2); static RecompiledCodeReserve* recMem = NULL;
static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here
static BASEBLOCK *recROM = NULL; // and here static BASEBLOCK *recROM = NULL; // and here
@ -757,7 +757,11 @@ static const uint m_recBlockAllocSize =
static void recReserve() static void recReserve()
{ {
recMem.Reserve( _16mb, HostMemoryMap::IOPrec ); if (!recMem)
{
recMem = new RecompiledCodeReserve(L"R3000A recompiled code cache", _1mb * 2);
recMem->Reserve( _16mb, HostMemoryMap::IOPrec );
}
} }
static void recAlloc() static void recAlloc()
@ -786,14 +790,14 @@ static void recAlloc()
if( s_pInstCache == NULL ) if( s_pInstCache == NULL )
throw Exception::OutOfMemory( L"R3000 InstCache." ); throw Exception::OutOfMemory( L"R3000 InstCache." );
ProfilerRegisterSource( "IOP Rec", recMem, recMem.GetReserveSizeInBytes() ); ProfilerRegisterSource( "IOP Rec", *recMem, recMem->GetReserveSizeInBytes() );
_DynGen_Dispatchers(); _DynGen_Dispatchers();
} }
void recResetIOP() void recResetIOP()
{ {
recAlloc(); recAlloc();
recMem.Reset(); recMem->Reset();
DevCon.WriteLn( "iR3000A Recompiler reset." ); DevCon.WriteLn( "iR3000A Recompiler reset." );
@ -836,14 +840,14 @@ void recResetIOP()
recBlocks.Reset(); recBlocks.Reset();
g_psxMaxRecMem = 0; g_psxMaxRecMem = 0;
recPtr = recMem; recPtr = *recMem;
psxbranch = 0; psxbranch = 0;
} }
static void recShutdown() static void recShutdown()
{ {
ProfilerTerminateSource( "IOPRec" ); ProfilerTerminateSource( "IOPRec" );
recMem.Free(); safe_delete( recMem );
safe_aligned_free( m_recBlockAlloc ); safe_aligned_free( m_recBlockAlloc );
@ -1191,7 +1195,7 @@ static void __fastcall iopRecRecompile( const u32 startpc )
pxAssert( startpc ); pxAssert( startpc );
// if recPtr reached the mem limit reset whole mem // if recPtr reached the mem limit reset whole mem
if (recPtr >= (recMem.GetPtrEnd() - _64kb)) { if (recPtr >= (recMem->GetPtrEnd() - _64kb)) {
recResetIOP(); recResetIOP();
} }
@ -1380,7 +1384,7 @@ StartRecomp:
} }
} }
pxAssert( xGetPtr() < recMem.GetPtrEnd() ); pxAssert( xGetPtr() < recMem->GetPtrEnd() );
pxAssert(xGetPtr() - recPtr < _64kb); pxAssert(xGetPtr() - recPtr < _64kb);
s_pCurBlockEx->x86size = xGetPtr() - recPtr; s_pCurBlockEx->x86size = xGetPtr() - recPtr;

View File

@ -64,7 +64,7 @@ bool g_cpuFlushedPC, g_cpuFlushedCode, g_recompilingDelaySlot, g_maySignalExcept
#define X86 #define X86
static const int RECCONSTBUF_SIZE = 16384 * 2; // 64 bit consts in 32 bit units static const int RECCONSTBUF_SIZE = 16384 * 2; // 64 bit consts in 32 bit units
static RecompiledCodeReserve recMem(L"R5900-32 recompiled code cache", _1mb * 4); static RecompiledCodeReserve* recMem = NULL;
static u32* recConstBuf = NULL; // 64-bit pseudo-immediates static u32* recConstBuf = NULL; // 64-bit pseudo-immediates
static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here
@ -562,7 +562,8 @@ static void recReserve()
if ( !x86caps.hasStreamingSIMD2Extensions ) if ( !x86caps.hasStreamingSIMD2Extensions )
recThrowHardwareDeficiency( L"SSE2" ); recThrowHardwareDeficiency( L"SSE2" );
recMem.Reserve( _64mb, HostMemoryMap::EErec ); recMem = new RecompiledCodeReserve(L"R5900-32 recompiled code cache", _1mb * 4);
recMem->Reserve( _64mb, HostMemoryMap::EErec );
} }
static void recAlloc() static void recAlloc()
@ -595,7 +596,7 @@ static void recAlloc()
// No errors.. Proceed with initialization: // No errors.. Proceed with initialization:
ProfilerRegisterSource( "EE Rec", recMem, recMem.GetReserveSizeInBytes() ); ProfilerRegisterSource( "EE Rec", *recMem, recMem->GetReserveSizeInBytes() );
_DynGen_Dispatchers(); _DynGen_Dispatchers();
x86FpuState = FPU_STATE; x86FpuState = FPU_STATE;
@ -624,7 +625,7 @@ static void recResetRaw()
Console.WriteLn( Color_StrongBlack, "EE/iR5900-32 Recompiler Reset" ); Console.WriteLn( Color_StrongBlack, "EE/iR5900-32 Recompiler Reset" );
recMem.Reset(); recMem->Reset();
maxrecmem = 0; maxrecmem = 0;
@ -674,9 +675,9 @@ static void recResetRaw()
recLUT_SetPage(recLUT, hwLUT, recROM1, 0xa000, i, i - 0x1e00); recLUT_SetPage(recLUT, hwLUT, recROM1, 0xa000, i, i - 0x1e00);
} }
x86SetPtr(recMem); x86SetPtr(*recMem);
recPtr = recMem; recPtr = *recMem;
recConstBufPtr = recConstBuf; recConstBufPtr = recConstBuf;
x86FpuState = FPU_STATE; x86FpuState = FPU_STATE;
@ -686,7 +687,7 @@ static void recResetRaw()
static void recShutdown() static void recShutdown()
{ {
ProfilerTerminateSource( "EERec" ); ProfilerTerminateSource( "EERec" );
recMem.Free(); safe_delete( recMem );
recBlocks.Reset(); recBlocks.Reset();
safe_aligned_free( m_recBlockAlloc ); safe_aligned_free( m_recBlockAlloc );
@ -1355,7 +1356,7 @@ static void __fastcall recRecompile( const u32 startpc )
pxAssume( startpc ); pxAssume( startpc );
// if recPtr reached the mem limit reset whole mem // if recPtr reached the mem limit reset whole mem
if (recPtr >= (recMem.GetPtrEnd() - _64kb)) { if (recPtr >= (recMem->GetPtrEnd() - _64kb)) {
AtomicExchange( eeRecNeedsReset, true ); AtomicExchange( eeRecNeedsReset, true );
} }
else if ((recConstBufPtr - recConstBuf) >= RECCONSTBUF_SIZE - 64) { else if ((recConstBufPtr - recConstBuf) >= RECCONSTBUF_SIZE - 64) {
@ -1844,7 +1845,7 @@ StartRecomp:
} }
} }
pxAssert( xGetPtr() < recMem.GetPtrEnd() ); pxAssert( xGetPtr() < recMem->GetPtrEnd() );
pxAssert( recConstBufPtr < recConstBuf + RECCONSTBUF_SIZE ); pxAssert( recConstBufPtr < recConstBuf + RECCONSTBUF_SIZE );
pxAssert( x86FpuState == 0 ); pxAssert( x86FpuState == 0 );