2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-09-17 02:12:32 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
2009-09-17 02:12:32 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "PrecompiledHeader.h"
|
2009-11-14 12:02:56 +00:00
|
|
|
#include "Common.h"
|
2010-06-22 10:58:34 +00:00
|
|
|
#include "IopCommon.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-11-14 12:02:56 +00:00
|
|
|
#include "System/PageFaultSource.h"
|
2009-10-25 22:33:23 +00:00
|
|
|
#include "Utilities/EventSource.inl"
|
2009-11-14 12:02:56 +00:00
|
|
|
|
2010-05-28 16:54:42 +00:00
|
|
|
// Includes needed for cleanup, since we don't have a good system (yet) for
|
|
|
|
// cleaning up these things.
|
|
|
|
#include "sVU_zerorec.h"
|
2010-06-18 14:27:13 +00:00
|
|
|
#include "GameDatabase.h"
|
2010-06-22 18:57:48 +00:00
|
|
|
#include "Elfheader.h"
|
2010-05-28 16:54:42 +00:00
|
|
|
|
2010-03-11 21:16:35 +00:00
|
|
|
extern void closeNewVif(int idx);
|
|
|
|
extern void resetNewVif(int idx);
|
|
|
|
|
2010-01-22 15:22:01 +00:00
|
|
|
template class EventSource< IEventListener_PageFault >;
|
2009-10-25 22:33:23 +00:00
|
|
|
|
2009-10-23 20:24:59 +00:00
|
|
|
SrcType_PageFault Source_PageFault;
|
2009-07-15 01:17:28 +00:00
|
|
|
|
2010-01-23 17:13:03 +00:00
|
|
|
EventListener_PageFault::EventListener_PageFault()
|
2010-01-22 15:22:01 +00:00
|
|
|
{
|
|
|
|
Source_PageFault.Add( *this );
|
|
|
|
}
|
|
|
|
|
2010-01-23 17:13:03 +00:00
|
|
|
EventListener_PageFault::~EventListener_PageFault() throw()
|
2010-01-22 15:22:01 +00:00
|
|
|
{
|
|
|
|
Source_PageFault.Remove( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SrcType_PageFault::Dispatch( const PageFaultInfo& params )
|
|
|
|
{
|
|
|
|
m_handled = false;
|
|
|
|
_parent::Dispatch( params );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SrcType_PageFault::_DispatchRaw( ListenerIterator iter, const ListenerIterator& iend, const PageFaultInfo& evt )
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
(*iter)->DispatchEvent( evt, m_handled );
|
|
|
|
} while( (++iter != iend) && !m_handled );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-13 17:11:35 +00:00
|
|
|
#if _MSC_VER
|
|
|
|
# include "svnrev.h"
|
2009-09-04 01:56:33 +00:00
|
|
|
#endif
|
2009-07-15 01:17:28 +00:00
|
|
|
|
2009-09-22 11:50:27 +00:00
|
|
|
const Pcsx2Config EmuConfig;
|
2009-08-04 08:21:10 +00:00
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
// Provides an accessor for quick modification of GS options. All GS options are allowed to be
|
|
|
|
// changed "on the fly" by the *main/gui thread only*.
|
|
|
|
Pcsx2Config::GSOptions& SetGSConfig()
|
|
|
|
{
|
|
|
|
//DbgCon.WriteLn( "Direct modification of EmuConfig.GS detected" );
|
2010-04-27 13:12:03 +00:00
|
|
|
AffinityAssert_AllowFrom_MainUI();
|
2009-12-03 15:51:39 +00:00
|
|
|
return const_cast<Pcsx2Config::GSOptions&>(EmuConfig.GS);
|
|
|
|
}
|
|
|
|
|
2010-05-18 23:52:29 +00:00
|
|
|
// Provides an accessor for quick modification of Recompiler options.
|
|
|
|
// Used by loadGameSettings() to set clamp modes via database at game startup.
|
|
|
|
Pcsx2Config::RecompilerOptions& SetRecompilerConfig()
|
|
|
|
{
|
|
|
|
//DbgCon.WriteLn( "Direct modification of EmuConfig.Gamefixes detected" );
|
|
|
|
AffinityAssert_AllowFrom_MainUI();
|
|
|
|
return const_cast<Pcsx2Config::RecompilerOptions&>(EmuConfig.Cpu.Recompiler);
|
|
|
|
}
|
|
|
|
|
2010-05-17 22:38:36 +00:00
|
|
|
// Provides an accessor for quick modification of Gamefix options.
|
|
|
|
// Used by loadGameSettings() to set gamefixes via database at game startup.
|
|
|
|
Pcsx2Config::GamefixOptions& SetGameFixConfig()
|
|
|
|
{
|
|
|
|
//DbgCon.WriteLn( "Direct modification of EmuConfig.Gamefixes detected" );
|
|
|
|
AffinityAssert_AllowFrom_MainUI();
|
|
|
|
return const_cast<Pcsx2Config::GamefixOptions&>(EmuConfig.Gamefixes);
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
TraceLogFilters& SetTraceConfig()
|
|
|
|
{
|
|
|
|
//DbgCon.WriteLn( "Direct modification of EmuConfig.TraceLog detected" );
|
2010-04-27 13:12:03 +00:00
|
|
|
AffinityAssert_AllowFrom_MainUI();
|
2009-12-03 15:51:39 +00:00
|
|
|
return const_cast<TraceLogFilters&>(EmuConfig.Trace);
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
// This function should be called once during program execution.
|
2009-12-14 12:18:55 +00:00
|
|
|
void SysLogMachineCaps()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-06-06 04:17:43 +00:00
|
|
|
Console.WriteLn( Color_StrongGreen, "PCSX2 %u.%u.%u.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo,
|
2009-09-06 05:21:07 +00:00
|
|
|
SVN_REV, SVN_MODS ? "(modded)" : ""
|
|
|
|
);
|
2009-09-16 17:23:02 +00:00
|
|
|
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.WriteLn( "Savestate version: 0x%x", g_SaveVersion);
|
|
|
|
Console.Newline();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.WriteLn( Color_StrongBlack, "x86-32 Init:" );
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-01 03:33:51 +00:00
|
|
|
u32 speed = x86caps.CalculateMHz();
|
|
|
|
|
2009-11-15 06:26:55 +00:00
|
|
|
Console.Indent().WriteLn(
|
|
|
|
L"CPU vendor name = %s\n"
|
|
|
|
L"FamilyID = %x\n"
|
|
|
|
L"x86Family = %s\n"
|
|
|
|
L"CPU speed = %d.%03d ghz\n"
|
|
|
|
L"Cores = %d physical [%d logical]\n"
|
|
|
|
L"x86PType = %s\n"
|
|
|
|
L"x86Flags = %8.8x %8.8x\n"
|
2009-11-16 00:40:09 +00:00
|
|
|
L"x86EFlags = %8.8x",
|
2009-10-29 13:32:40 +00:00
|
|
|
fromUTF8( x86caps.VendorName ).c_str(), x86caps.StepID,
|
|
|
|
fromUTF8( x86caps.FamilyName ).Trim().Trim(false).c_str(),
|
2010-06-01 03:33:51 +00:00
|
|
|
speed / 1000, speed % 1000,
|
2009-07-29 14:00:00 +00:00
|
|
|
x86caps.PhysicalCores, x86caps.LogicalCores,
|
2010-06-01 03:33:51 +00:00
|
|
|
x86caps.GetTypeName().c_str(),
|
2009-07-29 14:00:00 +00:00
|
|
|
x86caps.Flags, x86caps.Flags2,
|
|
|
|
x86caps.EFlags
|
2009-10-29 13:32:40 +00:00
|
|
|
);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-11-16 00:40:09 +00:00
|
|
|
Console.Newline();
|
2009-09-17 02:12:32 +00:00
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
wxArrayString features[2]; // 2 lines, for readability!
|
2009-09-17 02:12:32 +00:00
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
if( x86caps.hasMultimediaExtensions ) features[0].Add( L"MMX" );
|
|
|
|
if( x86caps.hasStreamingSIMDExtensions ) features[0].Add( L"SSE" );
|
|
|
|
if( x86caps.hasStreamingSIMD2Extensions ) features[0].Add( L"SSE2" );
|
|
|
|
if( x86caps.hasStreamingSIMD3Extensions ) features[0].Add( L"SSE3" );
|
|
|
|
if( x86caps.hasSupplementalStreamingSIMD3Extensions ) features[0].Add( L"SSSE3" );
|
|
|
|
if( x86caps.hasStreamingSIMD4Extensions ) features[0].Add( L"SSE4.1" );
|
|
|
|
if( x86caps.hasStreamingSIMD4Extensions2 ) features[0].Add( L"SSE4.2" );
|
|
|
|
|
|
|
|
if( x86caps.hasMultimediaExtensionsExt ) features[1].Add( L"MMX2 " );
|
|
|
|
if( x86caps.has3DNOWInstructionExtensions ) features[1].Add( L"3DNOW " );
|
|
|
|
if( x86caps.has3DNOWInstructionExtensionsExt ) features[1].Add( L"3DNOW2" );
|
|
|
|
if( x86caps.hasStreamingSIMD4ExtensionsA ) features[1].Add( L"SSE4a " );
|
|
|
|
|
2010-06-30 03:21:59 +00:00
|
|
|
const wxString result[2] =
|
|
|
|
{
|
|
|
|
JoinString( features[0], L".. " ),
|
|
|
|
JoinString( features[1], L".. " )
|
|
|
|
};
|
2009-09-16 17:23:02 +00:00
|
|
|
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.WriteLn( Color_StrongBlack, L"x86 Features Detected:" );
|
2009-11-16 00:40:09 +00:00
|
|
|
Console.Indent().WriteLn( result[0] + (result[1].IsEmpty() ? L"" : (L"\n" + result[1])) );
|
2009-11-15 06:26:55 +00:00
|
|
|
Console.Newline();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
template< typename CpuType >
|
|
|
|
class CpuInitializer
|
|
|
|
{
|
|
|
|
public:
|
2010-06-28 18:03:54 +00:00
|
|
|
ScopedPtr<CpuType> MyCpu;
|
|
|
|
ScopedPtr<BaseException> ExThrown;
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
CpuInitializer();
|
|
|
|
virtual ~CpuInitializer() throw();
|
|
|
|
|
|
|
|
bool IsAvailable() const
|
|
|
|
{
|
|
|
|
return !!MyCpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
CpuType* GetPtr() { return MyCpu.GetPtr(); }
|
|
|
|
const CpuType* GetPtr() const { return MyCpu.GetPtr(); }
|
|
|
|
|
|
|
|
operator CpuType*() { return GetPtr(); }
|
|
|
|
operator const CpuType*() const { return GetPtr(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// CpuInitializer Template
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Helper for initializing various PCSX2 CPU providers, and handing errors and cleanup.
|
|
|
|
//
|
|
|
|
template< typename CpuType >
|
|
|
|
CpuInitializer< CpuType >::CpuInitializer()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
MyCpu = new CpuType();
|
|
|
|
MyCpu->Allocate();
|
|
|
|
}
|
|
|
|
catch( Exception::RuntimeError& ex )
|
|
|
|
{
|
2009-12-14 12:18:55 +00:00
|
|
|
Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() );
|
2010-06-28 18:03:54 +00:00
|
|
|
MyCpu = NULL;
|
|
|
|
ExThrown = ex.Clone();
|
2009-12-07 14:00:39 +00:00
|
|
|
}
|
|
|
|
catch( std::runtime_error& ex )
|
|
|
|
{
|
2009-12-14 12:18:55 +00:00
|
|
|
Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) );
|
2010-06-28 18:03:54 +00:00
|
|
|
MyCpu = NULL;
|
|
|
|
ExThrown = new Exception::RuntimeError(ex);
|
2009-12-07 14:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template< typename CpuType >
|
|
|
|
CpuInitializer< CpuType >::~CpuInitializer() throw()
|
|
|
|
{
|
|
|
|
if( MyCpu )
|
|
|
|
MyCpu->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
class CpuInitializerSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Note: Allocate sVU first -- it's the most picky.
|
|
|
|
|
|
|
|
CpuInitializer<recSuperVU0> superVU0;
|
|
|
|
CpuInitializer<recSuperVU1> superVU1;
|
|
|
|
|
|
|
|
CpuInitializer<recMicroVU0> microVU0;
|
|
|
|
CpuInitializer<recMicroVU1> microVU1;
|
|
|
|
|
|
|
|
CpuInitializer<InterpVU0> interpVU0;
|
|
|
|
CpuInitializer<InterpVU1> interpVU1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
public:
|
|
|
|
CpuInitializerSet() {}
|
|
|
|
virtual ~CpuInitializerSet() throw() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
// returns the translated error message for the Virtual Machine failing to allocate!
|
|
|
|
static wxString GetMemoryErrorVM()
|
|
|
|
{
|
2010-05-31 15:18:49 +00:00
|
|
|
return pxE( ".Error:EmuCore::MemoryForVM",
|
2009-09-16 17:23:02 +00:00
|
|
|
L"PCSX2 is unable to allocate memory needed for the PS2 virtual machine. "
|
|
|
|
L"Close out some memory hogging background tasks and try again."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
SysCoreAllocations::SysCoreAllocations()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-10-23 20:24:59 +00:00
|
|
|
InstallSignalHandler();
|
|
|
|
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.WriteLn( "Initializing PS2 virtual machine..." );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2009-04-29 04:24:46 +00:00
|
|
|
vtlb_Core_Alloc();
|
2009-02-09 21:15:56 +00:00
|
|
|
memAlloc();
|
|
|
|
psxMemAlloc();
|
|
|
|
vuMicroMemAlloc();
|
|
|
|
}
|
2009-09-16 17:23:02 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
catch( Exception::OutOfMemory& ex )
|
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
ex.UserMsg() += L"\n\n" + GetMemoryErrorVM();
|
2009-09-16 17:23:02 +00:00
|
|
|
CleanupMess();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch( std::bad_alloc& ex )
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-16 17:23:02 +00:00
|
|
|
CleanupMess();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
// re-throw std::bad_alloc as something more friendly. This is needed since
|
|
|
|
// much of the code uses new/delete internally, which throw std::bad_alloc on fail.
|
2009-08-31 19:47:25 +00:00
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
throw Exception::OutOfMemory()
|
|
|
|
.SetDiagMsg(
|
|
|
|
L"std::bad_alloc caught while trying to allocate memory for the PS2 Virtual Machine.\n"
|
|
|
|
L"Error Details: " + fromUTF8( ex.what() )
|
|
|
|
)
|
|
|
|
.SetUserMsg(GetMemoryErrorVM()); // translated
|
2009-09-16 17:23:02 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.WriteLn( "Allocating memory for recompilers..." );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
CpuProviders = new CpuInitializerSet();
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
try {
|
2009-02-09 21:15:56 +00:00
|
|
|
recCpu.Allocate();
|
|
|
|
}
|
2009-12-03 15:51:39 +00:00
|
|
|
catch( Exception::RuntimeError& ex )
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
m_RecExceptionEE = ex.Clone();
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
|
2009-02-09 21:15:56 +00:00
|
|
|
recCpu.Shutdown();
|
2009-09-16 17:23:02 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
try {
|
2009-09-16 17:23:02 +00:00
|
|
|
psxRec.Allocate();
|
|
|
|
}
|
2009-12-03 15:51:39 +00:00
|
|
|
catch( Exception::RuntimeError& ex )
|
2009-09-16 17:23:02 +00:00
|
|
|
{
|
2010-06-28 18:03:54 +00:00
|
|
|
m_RecExceptionIOP = ex.Clone();
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
Console.Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
|
2009-02-09 21:15:56 +00:00
|
|
|
psxRec.Shutdown();
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
// hmm! : VU0 and VU1 pre-allocations should do sVU and mVU separately? Sounds complicated. :(
|
2009-09-17 02:12:32 +00:00
|
|
|
|
|
|
|
// If both VUrecs failed, then make sure the SuperVU is totally closed out, because it
|
2009-09-16 17:23:02 +00:00
|
|
|
// actually initializes everything once and then shares it between both VU recs.
|
2009-12-07 14:00:39 +00:00
|
|
|
if( !IsRecAvailable_SuperVU0() && !IsRecAvailable_SuperVU1() )
|
2009-02-09 21:15:56 +00:00
|
|
|
SuperVUDestroy( -1 );
|
|
|
|
}
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
bool SysCoreAllocations::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); }
|
|
|
|
bool SysCoreAllocations::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); }
|
2010-06-28 18:03:54 +00:00
|
|
|
BaseException* SysCoreAllocations::GetException_MicroVU0() const { return CpuProviders->microVU0.ExThrown; }
|
|
|
|
BaseException* SysCoreAllocations::GetException_MicroVU1() const { return CpuProviders->microVU1.ExThrown; }
|
2009-12-07 14:00:39 +00:00
|
|
|
|
|
|
|
bool SysCoreAllocations::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); }
|
|
|
|
bool SysCoreAllocations::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); }
|
2010-06-28 18:03:54 +00:00
|
|
|
BaseException* SysCoreAllocations::GetException_SuperVU0() const { return CpuProviders->superVU0.ExThrown; }
|
|
|
|
BaseException* SysCoreAllocations::GetException_SuperVU1() const { return CpuProviders->superVU1.ExThrown; }
|
2009-12-07 14:00:39 +00:00
|
|
|
|
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
void SysCoreAllocations::CleanupMess() throw()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-16 17:23:02 +00:00
|
|
|
try
|
|
|
|
{
|
2010-05-28 16:54:42 +00:00
|
|
|
closeNewVif(0);
|
|
|
|
closeNewVif(1);
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
// Special SuperVU "complete" terminator (stupid hacky recompiler)
|
2009-09-16 17:23:02 +00:00
|
|
|
SuperVUDestroy( -1 );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
psxRec.Shutdown();
|
|
|
|
recCpu.Shutdown();
|
2009-09-09 14:08:15 +00:00
|
|
|
|
2009-09-16 17:23:02 +00:00
|
|
|
vuMicroMemShutdown();
|
|
|
|
psxMemShutdown();
|
|
|
|
memShutdown();
|
|
|
|
vtlb_Core_Shutdown();
|
|
|
|
}
|
|
|
|
DESTRUCTOR_CATCHALL
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
SysCoreAllocations::~SysCoreAllocations() throw()
|
2009-09-09 14:08:15 +00:00
|
|
|
{
|
2009-09-16 17:23:02 +00:00
|
|
|
CleanupMess();
|
|
|
|
}
|
2009-09-09 14:08:15 +00:00
|
|
|
|
2009-09-20 20:54:45 +00:00
|
|
|
bool SysCoreAllocations::HadSomeFailures( const Pcsx2Config::RecompilerOptions& recOpts ) const
|
2009-09-16 17:23:02 +00:00
|
|
|
{
|
2009-12-07 14:00:39 +00:00
|
|
|
return (recOpts.EnableEE && !IsRecAvailable_EE()) ||
|
|
|
|
(recOpts.EnableIOP && !IsRecAvailable_IOP()) ||
|
|
|
|
(recOpts.EnableVU0 && recOpts.UseMicroVU0 && !IsRecAvailable_MicroVU0()) ||
|
|
|
|
(recOpts.EnableVU1 && recOpts.UseMicroVU0 && !IsRecAvailable_MicroVU1()) ||
|
|
|
|
(recOpts.EnableVU0 && !recOpts.UseMicroVU0 && !IsRecAvailable_SuperVU0()) ||
|
|
|
|
(recOpts.EnableVU1 && !recOpts.UseMicroVU1 && !IsRecAvailable_SuperVU1());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseVUmicroCPU* CpuVU0 = NULL;
|
|
|
|
BaseVUmicroCPU* CpuVU1 = NULL;
|
|
|
|
|
|
|
|
void SysCoreAllocations::SelectCpuProviders() const
|
|
|
|
{
|
|
|
|
Cpu = CHECK_EEREC ? &recCpu : &intCpu;
|
|
|
|
psxCpu = CHECK_IOPREC ? &psxRec : &psxInt;
|
|
|
|
|
|
|
|
CpuVU0 = CpuProviders->interpVU0;
|
|
|
|
CpuVU1 = CpuProviders->interpVU1;
|
|
|
|
|
|
|
|
if( EmuConfig.Cpu.Recompiler.EnableVU0 )
|
|
|
|
CpuVU0 = EmuConfig.Cpu.Recompiler.UseMicroVU0 ? (BaseVUmicroCPU*)CpuProviders->microVU0 : (BaseVUmicroCPU*)CpuProviders->superVU0;
|
|
|
|
|
|
|
|
if( EmuConfig.Cpu.Recompiler.EnableVU1 )
|
|
|
|
CpuVU1 = EmuConfig.Cpu.Recompiler.UseMicroVU1 ? (BaseVUmicroCPU*)CpuProviders->microVU1 : (BaseVUmicroCPU*)CpuProviders->superVU1;
|
2009-09-09 14:08:15 +00:00
|
|
|
}
|
2009-03-04 11:33:45 +00:00
|
|
|
|
2010-07-07 05:59:25 +00:00
|
|
|
// This is a semi-hacky function for convenience
|
|
|
|
BaseVUmicroCPU* SysCoreAllocations::getVUprovider(int whichProvider, int vuIndex) const {
|
|
|
|
switch (whichProvider) {
|
|
|
|
case 0: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->interpVU1 : (BaseVUmicroCPU*)CpuProviders->interpVU0;
|
|
|
|
case 1: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->superVU1 : (BaseVUmicroCPU*)CpuProviders->superVU0;
|
|
|
|
case 2: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->microVU1 : (BaseVUmicroCPU*)CpuProviders->microVU0;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-07 14:00:39 +00:00
|
|
|
|
2009-03-04 11:33:45 +00:00
|
|
|
// Resets all PS2 cpu execution caches, which does not affect that actual PS2 state/condition.
|
2009-02-09 21:15:56 +00:00
|
|
|
// This can be called at any time outside the context of a Cpu->Execute() block without
|
|
|
|
// bad things happening (recompilers will slow down for a brief moment since rec code blocks
|
|
|
|
// are dumped).
|
|
|
|
// Use this method to reset the recs when important global pointers like the MTGS are re-assigned.
|
2009-03-04 11:33:45 +00:00
|
|
|
void SysClearExecutionCache()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-12-07 14:00:39 +00:00
|
|
|
GetSysCoreAlloc().SelectCpuProviders();
|
|
|
|
|
|
|
|
// SuperVUreset will do nothing is none of the recs are initialized.
|
|
|
|
// But it's needed if one or the other is initialized.
|
|
|
|
SuperVUReset(-1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
Cpu->Reset();
|
|
|
|
psxCpu->Reset();
|
2010-05-28 16:54:42 +00:00
|
|
|
CpuVU0->Reset();
|
|
|
|
CpuVU1->Reset();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-11 21:16:35 +00:00
|
|
|
resetNewVif(0);
|
|
|
|
resetNewVif(1);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-31 03:47:05 +00:00
|
|
|
// Maps a block of memory for use as a recompiled code buffer, and ensures that the
|
|
|
|
// allocation is below a certain memory address (specified in "bounds" parameter).
|
|
|
|
// The allocated block has code execution privileges.
|
|
|
|
// Returns NULL on allocation failure.
|
2010-06-22 18:57:48 +00:00
|
|
|
u8* SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-06-22 18:57:48 +00:00
|
|
|
u8* Mem = (u8*)HostSys::Mmap( base, size );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if( (Mem == NULL) || (bounds != 0 && (((uptr)Mem + size) > bounds)) )
|
|
|
|
{
|
2009-12-07 14:00:39 +00:00
|
|
|
if( base != NULL )
|
|
|
|
{
|
|
|
|
DbgCon.Warning( "First try failed allocating %s at address 0x%x", caller, base );
|
|
|
|
|
|
|
|
// memory allocation *must* have the top bit clear, so let's try again
|
|
|
|
// with NULL (let the OS pick something for us).
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
SafeSysMunmap( Mem, size );
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
Mem = (u8*)HostSys::Mmap( NULL, size );
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if( bounds != 0 && (((uptr)Mem + size) > bounds) )
|
|
|
|
{
|
2009-12-07 14:00:39 +00:00
|
|
|
DevCon.Warning( "Second try failed allocating %s, block ptr 0x%x does not meet required criteria.", caller, Mem );
|
2009-02-09 21:15:56 +00:00
|
|
|
SafeSysMunmap( Mem, size );
|
|
|
|
|
|
|
|
// returns NULL, caller should throw an exception.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Mem;
|
|
|
|
}
|
2010-06-22 18:57:48 +00:00
|
|
|
|
|
|
|
// This function always returns a valid DiscID -- using the Sony serial when possible, and
|
|
|
|
// falling back on the CRC checksum of the ELF binary if the PS2 software being run is
|
|
|
|
// homebrew or some other serial-less item.
|
|
|
|
wxString SysGetDiscID()
|
|
|
|
{
|
|
|
|
if( !DiscSerial.IsEmpty() ) return DiscSerial;
|
|
|
|
|
|
|
|
if( !ElfCRC )
|
|
|
|
{
|
|
|
|
// FIXME: If the system is currently running the BIOS, it should return a serial based on
|
|
|
|
// the BIOS being run (either a checksum of the BIOS roms, and/or a string based on BIOS
|
|
|
|
// region and revision).
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxsFormat( L"%8.8x", ElfCRC );
|
|
|
|
}
|