diff --git a/build.sh b/build.sh index b90c6a607f..2924b34cbe 100644 --- a/build.sh +++ b/build.sh @@ -6,14 +6,14 @@ # Uncomment if building by itself, rather then with all the plugins #Normal -export PCSX2OPTIONS="--enable-sse3 --enable-sse4 --prefix `pwd`" +#export PCSX2OPTIONS="--enable-sse3 --enable-sse4 --prefix `pwd`" #Optimized, but a devbuild #export PCSX2OPTIONS="--enable-sse3 --enable-sse4 --enable-devbuild --prefix `pwd`" #Debug / Devbuild version -#export PCSX2OPTIONS="--enable-debug --enable-devbuild --enable-sse3 --prefix `pwd`" +export PCSX2OPTIONS="--enable-debug --enable-devbuild --enable-sse3 --prefix `pwd`" # Make sure we have plugins, and bring the normal plugins in. sh fetch.sh diff --git a/pcsx2/GS.cpp b/pcsx2/GS.cpp index c290b3181f..5e52ffa1dc 100644 --- a/pcsx2/GS.cpp +++ b/pcsx2/GS.cpp @@ -25,7 +25,7 @@ #include "iR5900.h" #include "Counters.h" -#include "Vifdma.h" +#include "VifDma.h" using namespace Threading; using namespace std; diff --git a/pcsx2/Linux/ConfigDlg.cpp b/pcsx2/Linux/ConfigDlg.cpp index 4e8b0b9b40..0372616c18 100644 --- a/pcsx2/Linux/ConfigDlg.cpp +++ b/pcsx2/Linux/ConfigDlg.cpp @@ -19,12 +19,7 @@ #include "ConfigDlg.h" using namespace std; - -// these namespace directives globalize the new namespaces and make the code behave basically -// like it used to (with cpuReset() and other cpu* vars and functions global). using namespace R5900; -//using namespace Dynarec; -//using namespace Dynarec::R5900; static void FindComboText(GtkWidget *combo, char plist[255][255], GList *list, char *conf) { diff --git a/pcsx2/Linux/GtkGui.cpp b/pcsx2/Linux/GtkGui.cpp index 6add212a17..51c415a759 100644 --- a/pcsx2/Linux/GtkGui.cpp +++ b/pcsx2/Linux/GtkGui.cpp @@ -171,9 +171,11 @@ void RunExecute( const char* elf_file, bool use_bios ) return; } - if( elf_file == 0 ) + SysResetExecutionState() ; + + if (elf_file == 0 ) { - if(g_RecoveryState != NULL) + if (g_RecoveryState != NULL) { try { @@ -950,4 +952,4 @@ void on_Advanced_OK(GtkButton *button, gpointer user_data) gtk_widget_destroy(AdvDlg); gtk_widget_set_sensitive(MainWindow, TRUE); gtk_main_quit(); -} \ No newline at end of file +} diff --git a/pcsx2/Linux/LnxMain.cpp b/pcsx2/Linux/LnxMain.cpp index f4206de7ac..3f2e80c27f 100644 --- a/pcsx2/Linux/LnxMain.cpp +++ b/pcsx2/Linux/LnxMain.cpp @@ -21,15 +21,7 @@ #include "LnxMain.h" -// these namespace directives globalize the new namespaces and make the code behave basically -// like it used to (with cpuReset() and other cpu* vars and functions global). -// Not sure if the Dynarec ones are needed, so uncomment them if you get unresolved external -// link errors. Should solve some of them (maybe not all...) - (air) - -// Definitely not all. Most of them are coming from assembly files. :( - using namespace R5900; -//using namespace Dynarec; DIR *dir; @@ -475,10 +467,16 @@ void SysRunGui() { RunGui(); } -void *SysMmap(uptr base, u32 size) { - return mmap((uptr*)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); +void *SysMmap(uptr base, u32 size) +{ + u8 *Mem; + Mem = mmap((uptr*)base, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + if (Mem == MAP_FAILED) Console::Notice("Mmap Failed!"); + + return Mem; } -void SysMunmap(uptr base, u32 size) { +void SysMunmap(uptr base, u32 size) +{ munmap((uptr*)base, size); } diff --git a/pcsx2/Makefile.am b/pcsx2/Makefile.am index 997593a644..f6db84f7a6 100644 --- a/pcsx2/Makefile.am +++ b/pcsx2/Makefile.am @@ -4,19 +4,20 @@ noinst_LIBRARIES = libpcsx2.a libpcsx2_a_SOURCES = \ CDVD.cpp CDVDiso.cpp CDVDisodrv.cpp COP0.cpp COP2.cpp Cache.cpp CdRom.cpp Console.cpp \ -Counters.cpp Decode_XA.cpp Elfheader.cpp FPU.cpp FPU2.cpp FiFo.cpp GS.cpp Hw.cpp Interpreter.cpp \ +Counters.cpp Decode_XA.cpp Elfheader.cpp FPU.cpp FPU2.cpp FiFo.cpp Gif.cpp GS.cpp Hw.cpp Interpreter.cpp \ IopBios.cpp IopCounters.cpp IopDma.cpp IopHw.cpp IopMem.cpp IopSio2.cpp MMI.cpp MTGS.cpp \ Memory.cpp Misc.cpp Patch.cpp PathUtils.cpp Plugins.cpp PrecompiledHeader.cpp R3000A.cpp \ R3000AInterpreter.cpp R3000AOpcodeTables.cpp R5900.cpp R5900OpcodeImpl.cpp R5900OpcodeTables.cpp \ SPR.cpp SaveState.cpp Sif.cpp Sio.cpp SourceLog.cpp Stats.cpp System.cpp ThreadTools.cpp \ VU0.cpp VU0micro.cpp VU0microInterp.cpp VU1micro.cpp VU1microInterp.cpp VUflags.cpp VUmicroMem.cpp VUops.cpp \ -Vif.cpp VifDma.cpp vssprintf.cpp vtlb.cpp xmlpatchloader.cpp +Vif.cpp VifDma.cpp vssprintf.cpp vtlb.cpp xmlpatchloader.cpp AlignedMalloc.cpp + libpcsx2_a_SOURCES += \ CDVD.h CDVDiso.h CDVDisodrv.h CDVDlib.h COP0.h Cache.h CdRom.h Common.h Counters.h Decode_XA.h EEregs.h \ -Elfheader.h Exceptions.h GS.h Hw.h IopBios.h IopBios2.h IopCounters.h IopDma.h IopHw.h IopMem.h IopSio2.h \ +Elfheader.h Exceptions.h GS.h Hw.h IopBios.h IopBios2.h IopCounters.h IopDma.h IopHw.h IopMem.h IopSio2.h Memcpyfast.h \ Memory.h Misc.h Patch.h Paths.h Plugins.h PrecompiledHeader.h PsxCommon.h R3000A.h R5900.h R5900OpcodeTables.h \ -SPR.h SamplProf.h SaveState.h Sif.h Sifcmd.h Sio.h Stats.h StringUtils.h System.h Threading.h \ +SPR.h SamplProf.h SaveState.h Sif.h Sifcmd.h Sio.h SafeArray.h Stats.h StringUtils.h System.h Threading.h \ VU.h VUflags.h VUmicro.h VUops.h Vif.h VifDma.h cheatscpp.h vtlb.h -SUBDIRS = x86 . DebugTools IPU RDebug tinyxml Linux +SUBDIRS = x86 . DebugTools IPU RDebug tinyxml Linux \ No newline at end of file diff --git a/pcsx2/MemcpyFast.h b/pcsx2/MemcpyFast.h index a80192a3da..6fda7b772e 100644 --- a/pcsx2/MemcpyFast.h +++ b/pcsx2/MemcpyFast.h @@ -19,6 +19,8 @@ #ifndef __MEMCPY_FAST_H__ #define __MEMCPY_FAST_H__ +//#include "Misc.h" + void _memset16_unaligned( void* dest, u16 data, size_t size ); #if defined(_WIN32) && !defined(__x86_64__) diff --git a/pcsx2/SafeArray.h b/pcsx2/SafeArray.h index 60e8ee98c2..745c391cff 100644 --- a/pcsx2/SafeArray.h +++ b/pcsx2/SafeArray.h @@ -29,6 +29,7 @@ extern void pcsx2_aligned_free(void* pmem); #if !defined(_MSC_VER) && !defined(HAVE_ALIGNED_MALLOC) # define _aligned_malloc pcsx2_aligned_malloc # define _aligned_free pcsx2_aligned_free +# define _aligned_realloc pcsx2_aligned_realloc #endif ////////////////////////////////////////////////////////////// @@ -208,8 +209,7 @@ class SafeAlignedArray : public MemoryAlloc protected: T* _virtual_realloc( int newsize ) { - // TODO : aligned_realloc will need a linux implementation now. -_- - return (T*)_aligned_realloc( m_ptr, newsize * sizeof(T), Alignment ); + return (T*)_aligned_realloc( this->m_ptr, newsize * sizeof(T), Alignment ); } // Appends "(align: xx)" to the name of the allocation in devel builds. @@ -225,17 +225,17 @@ protected: public: virtual ~SafeAlignedArray() { - safe_aligned_free( m_ptr ); + safe_aligned_free( this->m_ptr ); // mptr is set to null, so the parent class's destructor won't re-free it. } explicit SafeAlignedArray( const std::string& name="Unnamed" ) : - MemoryAlloc( name ) + MemoryAlloc::MemoryAlloc( name ) { } explicit SafeAlignedArray( int initialSize, const std::string& name="Unnamed" ) : - MemoryAlloc( + MemoryAlloc::MemoryAlloc( _getName(name), (T*)_aligned_malloc( initialSize * sizeof(T), Alignment ), initialSize @@ -245,8 +245,8 @@ public: virtual SafeAlignedArray* Clone() const { - SafeAlignedArray* retval = new SafeAlignedArray( m_size ); - memcpy_fast( retval->GetPtr(), m_ptr, sizeof(T) * m_size ); + SafeAlignedArray* retval = new SafeAlignedArray( this->m_size ); + memcpy_fast( retval->GetPtr(), this->m_ptr, sizeof(T) * this->m_size ); return retval; } }; diff --git a/pcsx2/SourceLog.cpp b/pcsx2/SourceLog.cpp index 256a293efe..0d6d06db1d 100644 --- a/pcsx2/SourceLog.cpp +++ b/pcsx2/SourceLog.cpp @@ -35,13 +35,13 @@ using namespace R5900; FILE *emuLog; -#ifdef PCSX2_DEVBUILD +//#ifdef PCSX2_DEVBUILD u32 varLog; // these used by the depreciated _old_Log only u16 logProtocol; u8 logSource; -#endif +//#endif int connected=0; @@ -70,7 +70,8 @@ void __Log( const char* fmt, ... ) { Console::Write(tmp); - } else if( emuLog != NULL ) // manually write to the logfile. + } + else if( emuLog != NULL ) // manually write to the logfile. { fputs( tmp, emuLog ); //fputs( "\r\n", emuLog ); diff --git a/pcsx2/System.h b/pcsx2/System.h index c98ac20922..b9df91230f 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -233,4 +233,33 @@ int SysMapUserPhysicalPages(void* Addr, uptr NumPages, uptr* pblock, int pageoff #endif +static __forceinline u8 *SysBoundedMmap(uptr base, u32 size, u32 bounds, char *caller) +{ + u8 *Mem = NULL; + // For Linux we need to use the system virtual memory mapper so that we + // can coerce an allocation below the 2GB line. + + // just try an arbitrary address first... + // maybe there's a better one to pick? + Mem = (u8*)SysMmap( base, size ); + + if( (Mem == NULL) || ((uptr)Mem + size) > bounds ) + { + DevCon::Error("Problem allocating in %s.", params caller); + // memory allocation *must* have the top bit clear, so let's try again + // with NULL (let the OS pick something for us). + + if( Mem != NULL ) SysMunmap( base, size ); + + Mem = (u8*)SysMmap( NULL, size ); + if( (uptr)Mem > bounds ) + { + DevCon::Error("Continuing problems allocating in %s.", params caller); + SysMunmap( Mem, size ); + Mem = NULL; // let the os-independent code below handle the error + } + } + return Mem; +} + #endif /* __SYSTEM_H__ */ diff --git a/pcsx2/ThreadTools.cpp b/pcsx2/ThreadTools.cpp index a82bf8db9e..12abe92026 100644 --- a/pcsx2/ThreadTools.cpp +++ b/pcsx2/ThreadTools.cpp @@ -99,7 +99,9 @@ namespace Threading void Semaphore::Post( int multiple ) { +#if defined(_MSC_VER) sem_post_multiple( &sema, multiple ); +#endif } void Semaphore::Wait() diff --git a/pcsx2/build.sh b/pcsx2/build.sh index f1fbe2de8c..bbe7df2b04 100644 --- a/pcsx2/build.sh +++ b/pcsx2/build.sh @@ -18,7 +18,7 @@ # #Normal -export PCSX2OPTIONS="--enable-debug --enable-devbuild --enable-sse3 --enable-sse4 --prefix `pwd`" +#export PCSX2OPTIONS="--enable-debug --enable-devbuild --enable-sse3 --enable-sse4 --prefix `pwd`" echo --------------- echo Building Pcsx2 diff --git a/pcsx2/x86/Makefile.am b/pcsx2/x86/Makefile.am index c37ffa0a0e..63e6516f83 100644 --- a/pcsx2/x86/Makefile.am +++ b/pcsx2/x86/Makefile.am @@ -6,12 +6,12 @@ noinst_LIBRARIES = libx86recomp.a archfiles = ix86-32/iR5900-32.cpp ix86-32/iR5900AritImm.cpp ix86-32/iR5900Jump.cpp \ ix86-32/iR5900Move.cpp ix86-32/iR5900Shift.cpp ix86-32/iR5900Arit.cpp ix86-32/iR5900Branch.cpp \ ix86-32/iR5900LoadStore.cpp ix86-32/iR5900MultDiv.cpp ix86-32/iCore-32.cpp ix86-32/aR5900-32.S \ -ix86-32/iR5900Templates.cpp +ix86-32/iR5900Templates.cpp ix86-32/recVTLB.cpp libx86recomp_a_SOURCES = \ BaseblockEx.cpp iCOP0.cpp iCOP2.cpp iCore.cpp iFPU.cpp iGS.cpp iHw.cpp iIPU.cpp iMMI.cpp iPsxHw.cpp iPsxMem.cpp \ -iR3000A.cpp iR3000Atables.cpp iR5900Misc.cpp iVU0micro.cpp iVU1micro.cpp iVUmicro.cpp iVUmicroLower.cpp iVUmicroUpper.cpp \ -iVUzerorec.cpp iVif.cpp ir5900tables.cpp fast_routines.S aR3000A.S aVUzerorec.S aVif.S $(archfiles) +iR3000A.cpp iR3000Atables.cpp iR5900CoissuedLoadStore.cpp iR5900Misc.cpp iVU0micro.cpp iVU1micro.cpp iVUmicro.cpp \ +iVUmicroLower.cpp iVUmicroUpper.cpp iVUzerorec.cpp iVif.cpp ir5900tables.cpp fast_routines.S aR3000A.S aVUzerorec.S aVif.S $(archfiles) libx86recomp_a_SOURCES += \ BaseblockEx.h iCOP0.h iCore.h iFPU.h iMMI.h iR3000A.h iR5900.h iR5900Arit.h iR5900AritImm.h iR5900Branch.h iR5900Jump.h \ diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 45a6ecb07f..24b7ea0267 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -556,23 +556,7 @@ static void recAlloc() // ... we can't? (air) if( recMem == NULL ) - { - recMem = (u8*)SysMmap(0x0f000000, RECMEM_SIZE); - if( recMem == NULL || (uptr)recMem > 0xf0000000 ) - { - // Allocation failed, so let's try a generic address... - if( recMem != NULL ) - SysMunmap(recMem, RECMEM_SIZE); - - recMem = (u8*)SysMmap(NULL, RECMEM_SIZE); - - if( (uptr)recMem > 0xf0000000 ) - { - SysMunmap(recMem, RECMEM_SIZE); // failed... - recMem = NULL; - } - } - } + recMem = (u8*)SysBoundedMmap(0x0f000000, RECMEM_SIZE, 0xf0000000, "recAlloc(3000)"); if( recMem == NULL ) throw Exception::OutOfMemory( "R3000a Init > failed to allocate memory for the recompiler." ); diff --git a/pcsx2/x86/iVUzerorec.cpp b/pcsx2/x86/iVUzerorec.cpp index a86e5f465a..f90ee52e3e 100644 --- a/pcsx2/x86/iVUzerorec.cpp +++ b/pcsx2/x86/iVUzerorec.cpp @@ -324,27 +324,12 @@ void SuperVUAlloc(int vuindex) // The old -1 crap has been depreciated on this function. Please // specify either 0 or 1, thanks. jASSUME( vuindex >= 0 ); - + + // upper 4 bits must be zero! if( s_recVUMem == NULL ) { // upper 4 bits must be zero! - s_recVUMem = (u8*)SysMmap( 0x0c000000, VU_EXESIZE); - - if( s_recVUMem == NULL || ((uptr)s_recVUMem > 0x80000000) ) - { - // Allocation failed? Well then let's just try an operating-system-assigned - // location, by specifying NULL as the address "hint." - - if( s_recVUMem != NULL ) - SysMunmap( s_recVUMem, VU_EXESIZE ); - - s_recVUMem = (u8*)SysMmap( NULL, VU_EXESIZE); - if( (uptr)s_recVUMem > 0x80000000 ) - { - SysMunmap( s_recVUMem, VU_EXESIZE ); // failed... - s_recVUMem = NULL; - } - } + s_recVUMem = SysBoundedMmap(0x0c000000, VU_EXESIZE, 0x80000000, "SuperVUAlloc"); if( s_recVUMem == NULL ) { @@ -355,8 +340,7 @@ void SuperVUAlloc(int vuindex) ProfilerRegisterSource( "VURec", s_recVUMem, VU_EXESIZE); - if( recVUStack == NULL ) - recVUStack = new u8[SUPERVU_STACKSIZE * 4]; + if( recVUStack == NULL ) recVUStack = new u8[SUPERVU_STACKSIZE * 4]; } if( vuindex >= 0 ) diff --git a/pcsx2/x86/ix86-32/aR5900-32.S b/pcsx2/x86/ix86-32/aR5900-32.S index af6c10c582..23b60d73a1 100644 --- a/pcsx2/x86/ix86-32/aR5900-32.S +++ b/pcsx2/x86/ix86-32/aR5900-32.S @@ -33,11 +33,11 @@ Dispatcher: mov %eax,dword ptr [cpuRegs+PCOFFSET] mov %ecx,%eax mov REG_PC,%eax - shr %eax,10h - and %ecx,0FFFFh + shr %eax,0x10 + and %ecx,0xFFFF mov %edx,dword ptr [recLUT] - mov %eax,dword ptr [edx+eax*4] - lea %ecx,[eax+ecx*2] + mov %eax,dword ptr [%edx+%eax*4] + lea %ecx,[%eax+%ecx*2] // check if startpc == cpuRegs.pc //and %ecx, 0x5fffffff // remove higher bits @@ -137,16 +137,16 @@ DispatcherReg: mov %eax,dword ptr [cpuRegs+PCOFFSET] mov %ecx,%eax mov REG_PC,%eax - shr %eax,10h - and %ecx,0FFFFh + shr %eax,0x10 + and %ecx,0xFFFF mov %edx,dword ptr [recLUT] - mov %eax,dword ptr [edx+eax*4] - lea %ecx,[eax+ecx*2] + mov %eax,dword ptr [%edx+%eax*4] + lea %ecx,[%eax+%ecx*2] // check if startpc == cpuRegs.pc //and %ecx, 0x5fffffff // remove higher bits cmp REG_PC, dword ptr [%ecx+BLOCKTYPE_STARTPC] - je Dispatcher_CheckPtr + je DispatcherReg_CheckPtr // recompile push %ecx @@ -154,16 +154,16 @@ DispatcherReg: call recRecompile add %esp, 4 pop %ecx -Dispatcher_CheckPtr: +DispatcherReg_CheckPtr: mov %eax, dword ptr [%ecx] #ifdef _DEBUG test %eax, %eax - jnz Dispatcher_CallFn + jnz DispatcherReg_CallFn // throw an exception int 10 -Dispatcher_CallFn: +DispatcherReg_CallFn: #endif and %eax, 0x0fffffff jmp %eax diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index c34540f009..7082ff2f7d 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -92,7 +92,7 @@ static u32 s_nInstCacheSize = 0; static BASEBLOCK* s_pCurBlock = NULL; static BASEBLOCKEX* s_pCurBlockEx = NULL; -static const BASEBLOCK* s_pDispatchBlock = NULL; +const BASEBLOCK* s_pDispatchBlock = NULL; static u32 s_nEndBlock = 0; // what pc the current block ends static u32 s_nHasDelay = 0; @@ -502,26 +502,14 @@ static void recAlloc() const uint cachememsize = REC_CACHEMEM+0x1000; // try an arbitrary address first, and if it doesn't work, try NULL. - recMem = (u8*)SysMmap(0x0d000000, cachememsize ); - if( recMem == NULL || ((uptr)recMem > 0x80000000) ) - { - SysMunmap( recMem, cachememsize ); - recMem = (u8*)SysMmap( NULL, REC_CACHEMEM+0x1000 ); - - if( recMem == NULL || ((uptr)recMem > 0x80000000) ) - { - SysMunmap( recMem, cachememsize ); - throw Exception::OutOfMemory( "R5900-32 > failed to allocate recompiler memory." ); - } - } + recMem = (u8*)SysBoundedMmap(0x0d000000, cachememsize, 0x80000000, "recAlloc(5900)"); } - // Goal: Allocate BASEBLOCKs for every possible branch target in PS2 memory. // Any 4-byte aligned address makes a valid branch target as per MIPS design (all instructions are // always 4 bytes long). - if( m_recBlockAlloc == NULL ) - m_recBlockAlloc = (u8*) _aligned_malloc( m_recBlockAllocSize, 4096 ); + if( m_recBlockAlloc == NULL ) + m_recBlockAlloc = (u8*) _aligned_malloc( m_recBlockAllocSize, 4096 ); if( m_recBlockAlloc == NULL ) throw Exception::OutOfMemory( "R5900-32 Init > Failed to allocate memory for BASEBLOCK tables." ); @@ -664,7 +652,7 @@ static __forceinline bool recEventTest() //////////////////////////////////////////////////// static u32 g_lastpc = 0; -static u32 g_EEDispatchTemp; +u32 g_EEDispatchTemp; #ifdef _MSC_VER @@ -840,7 +828,7 @@ __forceinline void recExecute() // Manually pushing is faster, especially on Core2's and such. :) do { g_EEFreezeRegs = true; - __asm + __asm__ ( ".intel_syntax\n" "push %ebx\n" @@ -864,7 +852,7 @@ __forceinline void recExecute() static void recExecuteBlock() { g_EEFreezeRegs = true; - __asm + __asm__ ( ".intel_syntax\n" "push %ebx\n" diff --git a/plugins/zerospu2/build.sh b/plugins/zerospu2/build.sh index 08f40d2922..39a9ef1384 100644 --- a/plugins/zerospu2/build.sh +++ b/plugins/zerospu2/build.sh @@ -12,7 +12,7 @@ then aclocal automake -a autoconf -./configure --enable-debug-build --prefix=${PCSX2PLUGINS} +./configure --prefix=${PCSX2PLUGINS} make clean make install