/[pcsx2_0.9.7]/trunk/pcsx2/System.cpp
ViewVC logotype

Diff of /trunk/pcsx2/System.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 15  Line 15 
15    
16  #include "PrecompiledHeader.h"  #include "PrecompiledHeader.h"
17  #include "Common.h"  #include "Common.h"
18  #include "HostGui.h"  #include "IopCommon.h"
19    
20  #include "System/PageFaultSource.h"  #include "System/PageFaultSource.h"
21  #include "Utilities/EventSource.inl"  #include "Utilities/EventSource.inl"
# Line 23  Line 23 
23  // Includes needed for cleanup, since we don't have a good system (yet) for  // Includes needed for cleanup, since we don't have a good system (yet) for
24  // cleaning up these things.  // cleaning up these things.
25  #include "sVU_zerorec.h"  #include "sVU_zerorec.h"
26  #include "DataBase_Loader.h"  #include "GameDatabase.h"
27    #include "Elfheader.h"
28    
29  extern void closeNewVif(int idx);  extern void closeNewVif(int idx);
30  extern void resetNewVif(int idx);  extern void resetNewVif(int idx);
# Line 89  Pcsx2Config::GamefixOptions& SetGameFixC Line 90  Pcsx2Config::GamefixOptions& SetGameFixC
90          return const_cast<Pcsx2Config::GamefixOptions&>(EmuConfig.Gamefixes);          return const_cast<Pcsx2Config::GamefixOptions&>(EmuConfig.Gamefixes);
91  }  }
92    
 ConsoleLogFilters& SetConsoleConfig()  
 {  
         //DbgCon.WriteLn( "Direct modification of EmuConfig.Log detected" );  
         AffinityAssert_AllowFrom_MainUI();  
         return const_cast<ConsoleLogFilters&>(EmuConfig.Log);  
 }  
   
93  TraceLogFilters& SetTraceConfig()  TraceLogFilters& SetTraceConfig()
94  {  {
95          //DbgCon.WriteLn( "Direct modification of EmuConfig.TraceLog detected" );          //DbgCon.WriteLn( "Direct modification of EmuConfig.TraceLog detected" );
# Line 107  TraceLogFilters& SetTraceConfig() Line 101  TraceLogFilters& SetTraceConfig()
101  // This function should be called once during program execution.  // This function should be called once during program execution.
102  void SysLogMachineCaps()  void SysLogMachineCaps()
103  {  {
104          Console.WriteLn( Color_StrongGreen, "PCSX2 %d.%d.%d.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo,          Console.WriteLn( Color_StrongGreen, "PCSX2 %u.%u.%u.r%d %s - compiled on " __DATE__, PCSX2_VersionHi, PCSX2_VersionMid, PCSX2_VersionLo,
105                  SVN_REV, SVN_MODS ? "(modded)" : ""                  SVN_REV, SVN_MODS ? "(modded)" : ""
106          );          );
107    
# Line 116  void SysLogMachineCaps() Line 110  void SysLogMachineCaps()
110    
111          Console.WriteLn( Color_StrongBlack, "x86-32 Init:" );          Console.WriteLn( Color_StrongBlack, "x86-32 Init:" );
112    
113            u32 speed = x86caps.CalculateMHz();
114    
115          Console.Indent().WriteLn(          Console.Indent().WriteLn(
116                  L"CPU vendor name  =  %s\n"                  L"CPU vendor name  =  %s\n"
117                  L"FamilyID         =  %x\n"                  L"FamilyID         =  %x\n"
# Line 127  void SysLogMachineCaps() Line 123  void SysLogMachineCaps()
123                  L"x86EFlags        =  %8.8x",                  L"x86EFlags        =  %8.8x",
124                          fromUTF8( x86caps.VendorName ).c_str(), x86caps.StepID,                          fromUTF8( x86caps.VendorName ).c_str(), x86caps.StepID,
125                          fromUTF8( x86caps.FamilyName ).Trim().Trim(false).c_str(),                          fromUTF8( x86caps.FamilyName ).Trim().Trim(false).c_str(),
126                          x86caps.Speed / 1000, x86caps.Speed % 1000,                          speed / 1000, speed % 1000,
127                          x86caps.PhysicalCores, x86caps.LogicalCores,                          x86caps.PhysicalCores, x86caps.LogicalCores,
128                          fromUTF8( x86caps.TypeName ).c_str(),                          x86caps.GetTypeName().c_str(),
129                          x86caps.Flags, x86caps.Flags2,                          x86caps.Flags, x86caps.Flags2,
130                          x86caps.EFlags                          x86caps.EFlags
131          );          );
# Line 151  void SysLogMachineCaps() Line 147  void SysLogMachineCaps()
147          if( x86caps.has3DNOWInstructionExtensionsExt )  features[1].Add( L"3DNOW2" );          if( x86caps.has3DNOWInstructionExtensionsExt )  features[1].Add( L"3DNOW2" );
148          if( x86caps.hasStreamingSIMD4ExtensionsA )              features[1].Add( L"SSE4a " );          if( x86caps.hasStreamingSIMD4ExtensionsA )              features[1].Add( L"SSE4a " );
149    
150          wxString result[2];          const wxString result[2] =
151          JoinString( result[0], features[0], L".. " );          {
152          JoinString( result[1], features[1], L".. " );                  JoinString( features[0], L".. " ),
153                    JoinString( features[1], L".. " )
154            };
155    
156          Console.WriteLn( Color_StrongBlack,     L"x86 Features Detected:" );          Console.WriteLn( Color_StrongBlack,     L"x86 Features Detected:" );
157          Console.Indent().WriteLn( result[0] + (result[1].IsEmpty() ? L"" : (L"\n" + result[1])) );          Console.Indent().WriteLn( result[0] + (result[1].IsEmpty() ? L"" : (L"\n" + result[1])) );
# Line 164  template< typename CpuType > Line 162  template< typename CpuType >
162  class CpuInitializer  class CpuInitializer
163  {  {
164  public:  public:
165          ScopedPtr<CpuType>      MyCpu;          ScopedPtr<CpuType>                      MyCpu;
166            ScopedPtr<BaseException>        ExThrown;
167            
168          CpuInitializer();          CpuInitializer();
169          virtual ~CpuInitializer() throw();          virtual ~CpuInitializer() throw();
170    
# Line 196  CpuInitializer< CpuType >::CpuInitialize Line 195  CpuInitializer< CpuType >::CpuInitialize
195          catch( Exception::RuntimeError& ex )          catch( Exception::RuntimeError& ex )
196          {          {
197                  Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() );                  Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() );
198                  if( MyCpu )                  MyCpu = NULL;
199                          MyCpu = NULL;                  ExThrown = ex.Clone();
200          }          }
201          catch( std::runtime_error& ex )          catch( std::runtime_error& ex )
202          {          {
203                  Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) );                  Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) );
204                  if( MyCpu )                  MyCpu = NULL;
205                          MyCpu = NULL;                  ExThrown = new Exception::RuntimeError(ex);
206          }          }
207  }  }
208    
# Line 238  public: Line 237  public:
237  // returns the translated error message for the Virtual Machine failing to allocate!  // returns the translated error message for the Virtual Machine failing to allocate!
238  static wxString GetMemoryErrorVM()  static wxString GetMemoryErrorVM()
239  {  {
240          return pxE( ".Popup Error:EmuCore::MemoryForVM",          return pxE( ".Error:EmuCore::MemoryForVM",
241                  L"PCSX2 is unable to allocate memory needed for the PS2 virtual machine. "                  L"PCSX2 is unable to allocate memory needed for the PS2 virtual machine. "
242                  L"Close out some memory hogging background tasks and try again."                  L"Close out some memory hogging background tasks and try again."
243          );          );
244  }  }
245    
246  SysCoreAllocations::SysCoreAllocations()  // --------------------------------------------------------------------------------------
247    //  SysAllocVM  (implementations)
248    // --------------------------------------------------------------------------------------
249    SysAllocVM::SysAllocVM()
250  {  {
251          InstallSignalHandler();          InstallSignalHandler();
252    
253          Console.WriteLn( "Initializing PS2 virtual machine..." );          Console.WriteLn( "Allocating memory for the PS2 virtual machine..." );
   
         m_RecSuccessEE          = false;  
         m_RecSuccessIOP         = false;  
254    
255          try          try
256          {          {
# Line 263  SysCoreAllocations::SysCoreAllocations() Line 262  SysCoreAllocations::SysCoreAllocations()
262          // ----------------------------------------------------------------------------          // ----------------------------------------------------------------------------
263          catch( Exception::OutOfMemory& ex )          catch( Exception::OutOfMemory& ex )
264          {          {
265                  wxString newmsg( ex.UserMsg() + L"\n\n" + GetMemoryErrorVM() );                  ex.UserMsg() += L"\n\n" + GetMemoryErrorVM();
                 ex.UserMsg() = newmsg;  
266                  CleanupMess();                  CleanupMess();
267                  throw;                  throw;
268          }          }
# Line 275  SysCoreAllocations::SysCoreAllocations() Line 273  SysCoreAllocations::SysCoreAllocations()
273                  // re-throw std::bad_alloc as something more friendly.  This is needed since                  // re-throw std::bad_alloc as something more friendly.  This is needed since
274                  // much of the code uses new/delete internally, which throw std::bad_alloc on fail.                  // much of the code uses new/delete internally, which throw std::bad_alloc on fail.
275    
276                  throw Exception::OutOfMemory(                  throw Exception::OutOfMemory()
277                          L"std::bad_alloc caught while trying to allocate memory for the PS2 Virtual Machine.\n"                          .SetDiagMsg(
278                          L"Error Details: " + fromUTF8( ex.what() ),                                  L"std::bad_alloc caught while trying to allocate memory for the PS2 Virtual Machine.\n"
279                                    L"Error Details: " + fromUTF8( ex.what() )
280                            )
281                            .SetUserMsg(GetMemoryErrorVM());        // translated
282            }
283    }
284    
285                          GetMemoryErrorVM()      // translated  void SysAllocVM::CleanupMess() throw()
286                  );  {
287            try
288            {
289                    vuMicroMemShutdown();
290                    psxMemShutdown();
291                    memShutdown();
292                    vtlb_Core_Shutdown();
293          }          }
294            DESTRUCTOR_CATCHALL
295    }
296    
297    SysAllocVM::~SysAllocVM() throw()
298    {
299            CleanupMess();
300    }
301    
302    // --------------------------------------------------------------------------------------
303    //  SysCpuProviderPack  (implementations)
304    // --------------------------------------------------------------------------------------
305    SysCpuProviderPack::SysCpuProviderPack()
306    {
307          Console.WriteLn( "Allocating memory for recompilers..." );          Console.WriteLn( "Allocating memory for recompilers..." );
308    
309          CpuProviders = new CpuInitializerSet();          CpuProviders = new CpuInitializerSet();
310    
311          try {          try {
312                  recCpu.Allocate();                  recCpu.Allocate();
                 m_RecSuccessEE = true;  
313          }          }
314          catch( Exception::RuntimeError& ex )          catch( Exception::RuntimeError& ex )
315          {          {
316                    m_RecExceptionEE = ex.Clone();
317                  Console.Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );                  Console.Error( L"EE Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
318                  recCpu.Shutdown();                  recCpu.Shutdown();
319          }          }
320    
321          try {          try {
322                  psxRec.Allocate();                  psxRec.Allocate();
                 m_RecSuccessIOP = true;  
323          }          }
324          catch( Exception::RuntimeError& ex )          catch( Exception::RuntimeError& ex )
325          {          {
326                    m_RecExceptionIOP = ex.Clone();
327                  Console.Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );                  Console.Error( L"IOP Recompiler Allocation Failed:\n" + ex.FormatDiagnosticMessage() );
328                  psxRec.Shutdown();                  psxRec.Shutdown();
329          }          }
# Line 315  SysCoreAllocations::SysCoreAllocations() Line 336  SysCoreAllocations::SysCoreAllocations()
336                  SuperVUDestroy( -1 );                  SuperVUDestroy( -1 );
337  }  }
338    
339  bool SysCoreAllocations::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); }  bool SysCpuProviderPack::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); }
340  bool SysCoreAllocations::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); }  bool SysCpuProviderPack::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); }
341    BaseException* SysCpuProviderPack::GetException_MicroVU0() const { return CpuProviders->microVU0.ExThrown; }
342  bool SysCoreAllocations::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); }  BaseException* SysCpuProviderPack::GetException_MicroVU1() const { return CpuProviders->microVU1.ExThrown; }
343  bool SysCoreAllocations::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); }  
344    bool SysCpuProviderPack::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); }
345    bool SysCpuProviderPack::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); }
346    BaseException* SysCpuProviderPack::GetException_SuperVU0() const { return CpuProviders->superVU0.ExThrown; }
347    BaseException* SysCpuProviderPack::GetException_SuperVU1() const { return CpuProviders->superVU1.ExThrown; }
348    
349    
350  void SysCoreAllocations::CleanupMess() throw()  void SysCpuProviderPack::CleanupMess() throw()
351  {  {
352          try          try
353          {          {
                 GameDB.Delete();  
354                  closeNewVif(0);                  closeNewVif(0);
355                  closeNewVif(1);                  closeNewVif(1);
356    
# Line 335  void SysCoreAllocations::CleanupMess() t Line 359  void SysCoreAllocations::CleanupMess() t
359    
360                  psxRec.Shutdown();                  psxRec.Shutdown();
361                  recCpu.Shutdown();                  recCpu.Shutdown();
   
                 vuMicroMemShutdown();  
                 psxMemShutdown();  
                 memShutdown();  
                 vtlb_Core_Shutdown();  
362          }          }
363          DESTRUCTOR_CATCHALL          DESTRUCTOR_CATCHALL
364  }  }
365    
366  SysCoreAllocations::~SysCoreAllocations() throw()  SysCpuProviderPack::~SysCpuProviderPack() throw()
367  {  {
368          CleanupMess();          CleanupMess();
369  }  }
370    
371  bool SysCoreAllocations::HadSomeFailures( const Pcsx2Config::RecompilerOptions& recOpts ) const  bool SysCpuProviderPack::HadSomeFailures( const Pcsx2Config::RecompilerOptions& recOpts ) const
372  {  {
373          return  (recOpts.EnableEE && !IsRecAvailable_EE()) ||          return  (recOpts.EnableEE && !IsRecAvailable_EE()) ||
374                          (recOpts.EnableIOP && !IsRecAvailable_IOP()) ||                          (recOpts.EnableIOP && !IsRecAvailable_IOP()) ||
# Line 363  bool SysCoreAllocations::HadSomeFailures Line 382  bool SysCoreAllocations::HadSomeFailures
382  BaseVUmicroCPU* CpuVU0 = NULL;  BaseVUmicroCPU* CpuVU0 = NULL;
383  BaseVUmicroCPU* CpuVU1 = NULL;  BaseVUmicroCPU* CpuVU1 = NULL;
384    
385  void SysCoreAllocations::SelectCpuProviders() const  void SysCpuProviderPack::ApplyConfig() const
386  {  {
387          Cpu             = CHECK_EEREC   ? &recCpu : &intCpu;          Cpu             = CHECK_EEREC   ? &recCpu : &intCpu;
388          psxCpu  = CHECK_IOPREC  ? &psxRec : &psxInt;          psxCpu  = CHECK_IOPREC  ? &psxRec : &psxInt;
# Line 378  void SysCoreAllocations::SelectCpuProvid Line 397  void SysCoreAllocations::SelectCpuProvid
397                  CpuVU1 = EmuConfig.Cpu.Recompiler.UseMicroVU1 ? (BaseVUmicroCPU*)CpuProviders->microVU1 : (BaseVUmicroCPU*)CpuProviders->superVU1;                  CpuVU1 = EmuConfig.Cpu.Recompiler.UseMicroVU1 ? (BaseVUmicroCPU*)CpuProviders->microVU1 : (BaseVUmicroCPU*)CpuProviders->superVU1;
398  }  }
399    
400    // This is a semi-hacky function for convenience
401    BaseVUmicroCPU* SysCpuProviderPack::getVUprovider(int whichProvider, int vuIndex) const {
402            switch (whichProvider) {
403                    case 0: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->interpVU1 : (BaseVUmicroCPU*)CpuProviders->interpVU0;
404                    case 1: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->superVU1  : (BaseVUmicroCPU*)CpuProviders->superVU0;
405                    case 2: return vuIndex ? (BaseVUmicroCPU*)CpuProviders->microVU1  : (BaseVUmicroCPU*)CpuProviders->microVU0;
406            }
407            return NULL;
408    }
409    
410  // Resets all PS2 cpu execution caches, which does not affect that actual PS2 state/condition.  // Resets all PS2 cpu execution caches, which does not affect that actual PS2 state/condition.
411  // This can be called at any time outside the context of a Cpu->Execute() block without  // This can be called at any time outside the context of a Cpu->Execute() block without
# Line 386  void SysCoreAllocations::SelectCpuProvid Line 414  void SysCoreAllocations::SelectCpuProvid
414  // Use this method to reset the recs when important global pointers like the MTGS are re-assigned.  // Use this method to reset the recs when important global pointers like the MTGS are re-assigned.
415  void SysClearExecutionCache()  void SysClearExecutionCache()
416  {  {
417          GetSysCoreAlloc().SelectCpuProviders();          GetCpuProviders().ApplyConfig();
418    
419          // SuperVUreset will do nothing is none of the recs are initialized.          // SuperVUreset will do nothing is none of the recs are initialized.
420          // But it's needed if one or the other is initialized.          // But it's needed if one or the other is initialized.
# Line 394  void SysClearExecutionCache() Line 422  void SysClearExecutionCache()
422    
423          Cpu->Reset();          Cpu->Reset();
424          psxCpu->Reset();          psxCpu->Reset();
425            // mVU's VU0 needs to be properly initialised for macro mode even if it's not used for micro mode!
426            if (CHECK_EEREC)
427                    ((BaseVUmicroCPU*)GetCpuProviders().CpuProviders->microVU0)->Reset();
428          CpuVU0->Reset();          CpuVU0->Reset();
429          CpuVU1->Reset();          CpuVU1->Reset();
430    
# Line 405  void SysClearExecutionCache() Line 436  void SysClearExecutionCache()
436  // allocation is below a certain memory address (specified in "bounds" parameter).  // allocation is below a certain memory address (specified in "bounds" parameter).
437  // The allocated block has code execution privileges.  // The allocated block has code execution privileges.
438  // Returns NULL on allocation failure.  // Returns NULL on allocation failure.
439  u8 *SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller)  u8* SysMmapEx(uptr base, u32 size, uptr bounds, const char *caller)
440  {  {
441          u8 *Mem = (u8*)HostSys::Mmap( base, size );          u8* Mem = (u8*)HostSys::Mmap( base, size );
442    
443          if( (Mem == NULL) || (bounds != 0 && (((uptr)Mem + size) > bounds)) )          if( (Mem == NULL) || (bounds != 0 && (((uptr)Mem + size) > bounds)) )
444          {          {
# Line 433  u8 *SysMmapEx(uptr base, u32 size, uptr Line 464  u8 *SysMmapEx(uptr base, u32 size, uptr
464          }          }
465          return Mem;          return Mem;
466  }  }
467    
468    // This function always returns a valid DiscID -- using the Sony serial when possible, and
469    // falling back on the CRC checksum of the ELF binary if the PS2 software being run is
470    // homebrew or some other serial-less item.
471    wxString SysGetDiscID()
472    {
473            if( !DiscSerial.IsEmpty() ) return DiscSerial;
474            
475            if( !ElfCRC )
476            {
477                    // FIXME: If the system is currently running the BIOS, it should return a serial based on
478                    // the BIOS being run (either a checksum of the BIOS roms, and/or a string based on BIOS
479                    // region and revision).
480            }
481    
482            return wxsFormat( L"%8.8x", ElfCRC );
483    }

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22