Fixed a potential cause of random-ish crashes during emulation startup, caused by a small typo in the new SysMmap in System.cpp.

Fixed another potential cause of randomish-crashes during dyna_block_discards, by removing some obsolete debug/troubleshooting hacks from when we had register corruption issues. Also removed if(s_pDispatchBlock == NULL) checks in the Dispatchers, which were added during the same period of register corruption paranoia.

Added a check for null pointers in Deci2Call.  Fixes crashes in some games (Samurai Warriors 2 XL, possibly others?)

Changed over most uses of memset to memzero_obj.

git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@673 a6443dda-0b58-4228-96e9-037be469359c
This commit is contained in:
Jake.Stine 2009-01-31 18:49:20 +00:00 committed by Gregory Hainaut
parent 271eee8dea
commit 46f1df20f4
20 changed files with 82 additions and 82 deletions

View File

@ -59,7 +59,7 @@ void hwReset()
{
hwInit();
memset(PS2MEM_HW, 0, Ps2MemSize::Hardware);
memzero_ptr<Ps2MemSize::Hardware>( PS2MEM_HW );
//memset(PS2MEM_HW+0x2000, 0, 0x0000e000);
psHu32(0xf520) = 0x1201;

View File

@ -134,7 +134,7 @@ void IPUProcessInterrupt()
// Register accesses (run on EE thread)
int ipuInit()
{
memzero_ptr<sizeof(IPUregisters)>(ipuRegs);
memzero_obj(*ipuRegs);
memzero_obj(g_BP);
//other stuff
@ -152,7 +152,7 @@ int ipuInit()
void ipuReset()
{
memzero_ptr<sizeof(IPUregisters)>(ipuRegs);
memzero_obj(*ipuRegs);
g_nDMATransfer = 0;
}

View File

@ -1054,8 +1054,8 @@ void mpeg2sliceIDEC(void* pdone)
decoder->coded_block_pattern = 0x3F;//all 6 blocks
//ipuRegs->ctrl.CBP = 0x3f;
memzero_ptr<sizeof(macroblock_8)>(decoder->mb8);
memzero_ptr<sizeof(rgb32)>(decoder->rgb32);
memzero_obj(*decoder->mb8);
memzero_obj(*decoder->rgb32);
slice_intra_DCT (decoder, 0, (u8*)decoder->mb8->Y, DCT_stride);
slice_intra_DCT (decoder, 0, (u8*)decoder->mb8->Y + 8, DCT_stride);
@ -1194,8 +1194,8 @@ void mpeg2_slice(void* pdone)
*(int*)pdone = 0;
ipuRegs->ctrl.ECD = 0;
memzero_ptr<sizeof(macroblock_8)>(decoder->mb8);
memzero_ptr<sizeof(macroblock_16)>(decoder->mb16);
memzero_obj(*decoder->mb8);
memzero_obj(*decoder->mb16);
bitstream_init (decoder);

View File

@ -93,7 +93,7 @@ static void _rcntSet( int cntidx )
void psxRcntInit() {
int i;
memset(psxCounters, 0, sizeof(psxCounters));
memzero_obj( psxCounters );
for (i=0; i<3; i++) {
psxCounters[i].rate = 1;

View File

@ -29,7 +29,7 @@ void psxHwReset() {
/* if (Config.Sio) psxHu32(0x1070) |= 0x80;
if (Config.SpuIrq) psxHu32(0x1070) |= 0x200;*/
memset(psxH, 0, 0x10000);
memzero_ptr<0x10000>(psxH);
// mdecInit(); //intialize mdec decoder
cdrReset();

View File

@ -429,8 +429,8 @@ void inifile_command( char * cmd )
pEqual = cmd+strlen(cmd);
}
memset( command, 0, sizeof( command ) );
memset( parameter, 0, sizeof( parameter ) );
memzero_obj( command );
memzero_obj( parameter );
strncpy( command, cmd, pEqual - cmd );
strncpy( parameter, pEqual + 1, sizeof( parameter ) );

View File

@ -562,7 +562,16 @@ char deci2buffer[256];
*/
int __Deci2Call(int call, u32 *addr) {
if (call > 0x10) {
if (call > 0x10)
return -1;
// fixme: is this an indication of bad emulation, that addr is sometimes null?
// Games affected include Samurai Warriors 2 XL (and others I don't know offhand)
// (air)
if( addr == NULL )
{
Console::Notice( "Deci2Call > Ignoring Null Pointer." );
return -1;
}

View File

@ -317,7 +317,7 @@ u8 *SysMmap(uptr base, u32 size, uptr bounds, const char *caller)
// memory allocation *must* have the top bit clear, so let's try again
// with NULL (let the OS pick something for us).
SafeSysMunmap( base, size );
SafeSysMunmap( Mem, size );
Mem = (u8*)SysMmap( NULL, size );
if( ((uptr)Mem + size) > bounds )

View File

@ -1334,7 +1334,7 @@ void vif0Write32(u32 mem, u32 value) {
if (value & 0x1) {
/* Reset VIF */
//SysPrintf("Vif0 Reset %x\n", vif0Regs->stat);
memset(&vif0, 0, sizeof(vif0));
memzero_obj(vif0);
vif0ch->qwc = 0; //?
psHu64(0x10004000) = 0;
psHu64(0x10004008) = 0;
@ -1406,8 +1406,8 @@ void vif0Write32(u32 mem, u32 value) {
void vif0Reset() {
/* Reset the whole VIF, meaning the internal pcsx2 vars
and all the registers */
memset(&vif0, 0, sizeof(vif0));
memset(vif0Regs, 0, sizeof(vif0Regs));
memzero_obj(vif0);
memzero_obj(*vif0Regs);
SetNewMask(g_vif0Masks, g_vif0HasMask3, 0, 0xffffffff);
psHu64(0x10004000) = 0;
psHu64(0x10004008) = 0;
@ -2301,7 +2301,7 @@ void vif1Write32(u32 mem, u32 value) {
if (value & 0x1) {
/* Reset VIF */
//SysPrintf("Vif1 Reset %x\n", vif1Regs->stat);
memset(&vif1, 0, sizeof(vif1));
memzero_obj(vif1);
vif1ch->qwc = 0; //?
psHu64(0x10005000) = 0;
psHu64(0x10005008) = 0;
@ -2409,8 +2409,8 @@ void vif1Write32(u32 mem, u32 value) {
void vif1Reset() {
/* Reset the whole VIF, meaning the internal pcsx2 vars
and all the registers */
memset(&vif1, 0, sizeof(vif1));
memset(vif1Regs, 0, sizeof(vif1Regs));
memzero_obj(vif1);
memzero_obj(*vif1Regs);
SetNewMask(g_vif1Masks, g_vif1HasMask3, 0, 0xffffffff);
psHu64(0x10005000) = 0;
psHu64(0x10005008) = 0;

View File

@ -69,7 +69,11 @@ struct ComboInitializer
string tmpStr;
Path::Combine( tmpStr, Config.PluginsDir, FindData.cFileName );
Lib = LoadLibrary(tmpStr.c_str());
if (Lib == NULL) { Console::Error( "%hs: %s", params &tmpStr, SysLibError()); return false; }
if (Lib == NULL)
{
Console::Error( "Plugin load failure: %hs\n\tSysLibError Message: %s", params &tmpStr, SysLibError() );
return false;
}
PS2E_GetLibType = (_PS2EgetLibType) GetProcAddress((HMODULE)Lib,"PS2EgetLibType");
PS2E_GetLibName = (_PS2EgetLibName) GetProcAddress((HMODULE)Lib,"PS2EgetLibName");

View File

@ -70,7 +70,7 @@ void RefreshMemory(void)
for (y = 0; y < 21; y++)
{
memset(text, 0, 32);
memzero_obj(text);
sprintf(buf, "%08X: ", addr);
for (x = 0; x < 16; x++)

View File

@ -406,7 +406,7 @@ BOOL APIENTRY DebuggerProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
debughWnd=hDlg;
DebuggerPC = 0;
// Clear all breakpoints.
memset(bkpt_regv, 0, sizeof(bkpt_regv));
memzero_obj(bkpt_regv);
hWnd_debugdisasm = GetDlgItem(hDlg, IDC_DEBUG_DISASM);
hWnd_debugscroll = GetDlgItem(hDlg, IDC_DEBUG_SCROLL);
@ -599,7 +599,7 @@ BOOL APIENTRY DebuggerProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
return TRUE;
case IDC_DEBUG_BP_CLEAR:
memset(bkpt_regv, 0, sizeof(bkpt_regv));
memzero_obj(bkpt_regv);
return TRUE;
case IDC_DEBUG_DUMP:

View File

@ -35,7 +35,7 @@ u16 SJISTable[0xFFFF];
void IniSJISTable()
{
memset(SJISTable, 0, 0xFFFF);
memzero_obj(SJISTable);
//Blow me sony for using this retarded sjis to store the savegame name
SJISTable[0x20] = 0x0020;
SJISTable[0x21] = 0x0021;
@ -800,7 +800,7 @@ class MemoryCard
{
fclose(fp);
}
memset(FAT, 0, 256*256*4);
memzero_obj(FAT);
Root.Release();
SaveGameList.clear();
@ -1110,7 +1110,7 @@ class MemoryCard
int dircluster = FindEmptyCluster();
char dir[512];
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = Di->Sons.size(); // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1163,7 +1163,7 @@ class MemoryCard
int numfiles = 5;
// ADD FILE ENTRIES TO DIR ., ..
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = numfiles; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1185,7 +1185,7 @@ class MemoryCard
fseek(fp, 0xA920 + (((dircluster) * 0x420) + 0), SEEK_SET);
fwrite(dir, 512, 1, fp);
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = 2; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1221,7 +1221,7 @@ class MemoryCard
dircluster = newcluster;
// Add first file
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_FILE | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = 0; // SIZE OF FILE
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1310,7 +1310,7 @@ class MemoryCard
int dircluster = FindEmptyCluster();
char dir[512];
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = 2; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1363,7 +1363,7 @@ class MemoryCard
int numfiles = 5;
// ADD FILE ENTRIES TO DIR ., ..
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = numfiles; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1385,7 +1385,7 @@ class MemoryCard
fseek(fp, 0xA920 + (((dircluster) * 0x420) + 0), SEEK_SET);
fwrite(dir, 512, 1, fp);
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_DIRECTORY | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = 2; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1421,7 +1421,7 @@ class MemoryCard
dircluster = newcluster;
// Add first file
memset(dir, 0, 512);
memzero_obj(dir);
*(u16 *)&dir[0] = Dir::DF_EXISTS | Dir::DF_FILE | Dir::DF_READ; // mode flag
*(u32 *)&dir[4] = 2; // number of files inside the dir
*(u8 *)&dir[8] = 0; // creation time seconds
@ -1514,9 +1514,9 @@ void Open_Mcd_Proc(HWND hW, int mcd) {
char szFilter[1024];
char *str;
memset(szFileName, 0, sizeof(szFileName));
memset(szFileTitle, 0, sizeof(szFileTitle));
memset(szFilter, 0, sizeof(szFilter));
memzero_obj(szFileName);
memzero_obj(szFileTitle);
memzero_obj(szFilter);
strcpy(szFilter, _("Ps2 Memory Card (*.ps2)"));
@ -1557,9 +1557,9 @@ void SaveFileDialog(HWND hW, int MC, char *dir, char *name) {
char szFilter[1024];
// char *str; (unused for now)
memset(szFileName, 0, sizeof(szFileName));
memset(szFileTitle, 0, sizeof(szFileTitle));
memset(szFilter, 0, sizeof(szFilter));
memzero_obj(szFileName);
memzero_obj(szFileTitle);
memzero_obj(szFilter);
strcpy(szFilter, "All Files (*.*)");
strcpy(szFileName, name);

View File

@ -1065,9 +1065,9 @@ int _allocCheckGPRtoX86(EEINST* pinst, int gprreg, int mode)
void _recClearInst(EEINST* pinst)
{
memset(&pinst->regs[0], EEINST_LIVE0|EEINST_LIVE1|EEINST_LIVE2, sizeof(pinst->regs));
memset(&pinst->fpuregs[0], EEINST_LIVE0, sizeof(pinst->fpuregs));
memset(&pinst->info, 0, sizeof(EEINST)-sizeof(pinst->regs)-sizeof(pinst->fpuregs));
memzero_obj( *pinst );
memset8_obj<EEINST_LIVE0|EEINST_LIVE1|EEINST_LIVE2>( pinst->regs );
memset8_obj<EEINST_LIVE0>( pinst->fpuregs );
}
// returns nonzero value if reg has been written between [startpc, endpc-4]

View File

@ -601,9 +601,9 @@ void recResetIOP()
DbgCon::Status( "iR3000A > Resetting recompiler memory and structures!" );
memset(psxRecLUT, 0, 0x010000 * sizeof(uptr));
memset(recMem, 0xcd, RECMEM_SIZE);
memset(m_recBlockAlloc, 0, m_recBlockAllocSize);
memzero_ptr<0x010000 * sizeof(uptr)>( psxRecLUT );
memset_8<0xcd,RECMEM_SIZE>( recMem );
memzero_ptr<m_recBlockAllocSize>( m_recBlockAlloc );
// We're only mapping 20 pages here in 4 places.
// 0x80 comes from : (Ps2MemSize::IopRam / 0x10000) * 4

View File

@ -22,9 +22,9 @@
#include "iCore.h"
#include "BaseblockEx.h"
// Cycle penalties for particuarly slow instructions.
static const int psxInstCycles_Mult = 8;
static const int psxInstCycles_Div = 60;
// Cycle penalties for particularly slow instructions.
static const int psxInstCycles_Mult = 7;
static const int psxInstCycles_Div = 40;
// Currently unused (iop mod incomplete)
static const int psxInstCycles_Peephole_Store = 0;

View File

@ -441,7 +441,7 @@ void SuperVUAnalyzeOp(VURegs *VU, _vuopinfo *info, _VURegsNum* pCodeRegs)
// check upper flags
if (ptr[1] & 0x80000000) { // I flag
info->cycle = vucycle;
memzero_ptr<sizeof(lregs)>(lregs);
memzero_obj(*lregs);
}
else {

View File

@ -158,7 +158,7 @@ struct VuBlockHeader
class VuInstruction
{
public:
VuInstruction() { memzero_ptr<sizeof(VuInstruction)>(this); nParentPc = -1; vicached = -1; }
VuInstruction() { memzero_obj(*this); nParentPc = -1; vicached = -1; }
int nParentPc; // used for syncing with flag writes, -1 for no parent
@ -329,7 +329,8 @@ void SuperVUAlloc(int vuindex)
if( s_recVUMem == NULL )
{
// upper 4 bits must be zero!
s_recVUMem = SysMmap(0x0c000000, VU_EXESIZE, 0x10000000, "SuperVUAlloc");
// Changed "first try base" to 0xb800000, since 0x0c000000 liked to fail a lot. (air)
s_recVUMem = SysMmap(0x0b800000, VU_EXESIZE, 0x10000000, "SuperVUAlloc");
if( s_recVUMem == NULL )
{
@ -402,7 +403,7 @@ void SuperVUReset(int vuindex)
if( vuindex < 0 )
{
DbgCon::Status( "SuperVU reset > Resetting recompiler memory and structures." );
memset(s_recVUMem, 0xcd, VU_EXESIZE);
memset_8<0xcd, VU_EXESIZE>(s_recVUMem);
memzero_ptr<SUPERVU_STACKSIZE>(recVUStack);
s_recVUPtr = s_recVUMem;

View File

@ -536,11 +536,6 @@ static void recAlloc()
ProfilerRegisterSource( "EERec", recMem, REC_CACHEMEM+0x1000 );
// Clear remMem here but not in Reset. Unfortunately the GUI requires recMem to beintact
// in order to "return" execution even after a reset of the emulator.
memset(recMem, 0xcd, REC_CACHEMEM);
x86FpuState = FPU_STATE;
}
@ -551,8 +546,12 @@ void recResetEE( void )
s_nNextBlock = 0;
maxrecmem = 0;
memset( m_recBlockAlloc, 0, m_recBlockAllocSize );
if( s_pInstCache ) memset( s_pInstCache, 0, sizeof(EEINST)*s_nInstCacheSize );
memset_8<0xcd, REC_CACHEMEM>(recMem);
memzero_ptr<m_recBlockAllocSize>( m_recBlockAlloc );
if( s_pInstCache )
memset( s_pInstCache, 0, sizeof(EEINST)*s_nInstCacheSize );
ResetBaseBlockEx(0);
mmap_ResetBlockTracking();
@ -563,7 +562,7 @@ void recResetEE( void )
__asm__("emms");
#endif
memset( recLUT, 0, 0x010000 * sizeof(uptr) );
memzero_ptr<0x010000 * sizeof(uptr)>( recLUT );
for ( int i = 0x0000; i < 0x0200; i++ )
{
@ -586,11 +585,9 @@ void recResetEE( void )
recLUT[ i + 0xbe00 ] = (uptr)&recROM1[ i << 14 ];
}
memcpy( recLUT + 0x8000, recLUT, 0x2000 * sizeof(uptr) );
memcpy( recLUT + 0xa000, recLUT, 0x2000 * sizeof(uptr) );
memcpy_fast( recLUT + 0x8000, recLUT, 0x2000 * sizeof(uptr) );
memcpy_fast( recLUT + 0xa000, recLUT, 0x2000 * sizeof(uptr) );
//memset(recStack, 0, RECSTACK_SIZE);
// This may or may not be needed anymore...
x86SetPtr(recMem+REC_CACHEMEM);
dyna_block_discard_recmem=(u8*)x86Ptr;
@ -665,7 +662,7 @@ static __naked void Dispatcher()
// calc PC_GETBLOCK
s_pDispatchBlock = PC_GETBLOCK(cpuRegs.pc);
if( s_pDispatchBlock == NULL || s_pDispatchBlock->startpc != cpuRegs.pc )
if( s_pDispatchBlock->startpc != cpuRegs.pc )
recRecompile(cpuRegs.pc);
__asm
@ -702,7 +699,7 @@ static __naked void DispatcherClear()
// calc PC_GETBLOCK
s_pDispatchBlock = PC_GETBLOCK(cpuRegs.pc);
if( s_pDispatchBlock != NULL && s_pDispatchBlock->startpc == cpuRegs.pc )
if( s_pDispatchBlock->startpc == cpuRegs.pc )
{
assert( s_pDispatchBlock->pFnptr != 0 );
@ -741,7 +738,7 @@ static __naked void DispatcherReg()
{
s_pDispatchBlock = PC_GETBLOCK(cpuRegs.pc);
if( s_pDispatchBlock == NULL || s_pDispatchBlock->startpc != cpuRegs.pc )
if( s_pDispatchBlock->startpc != cpuRegs.pc )
recRecompile(cpuRegs.pc);
__asm
@ -1527,19 +1524,8 @@ void badespfn() {
void __fastcall dyna_block_discard(u32 start,u32 sz)
{
#ifdef _MSC_VER
__asm push ebp;
#else
__asm__("push %ebp\n");
#endif
Console::WriteLn("dyna_block_discard %08X , count %d", params start,sz);
Cpu->Clear(start,sz);
#ifdef _MSC_VER
__asm pop ebp;
#else
__asm__("pop %ebp\n");
#endif
return;
}
void recRecompile( const u32 startpc )
@ -1943,8 +1929,7 @@ StartRecomp:
while(stg>0)
{
CMP32ItoM((uptr)PSM(lpc),*(u32*)PSM(lpc));
// fixme: was dyna_block_discard_recmem .. but umm.. why?
JNE32(((u32)&dyna_block_discard)- ( (u32)x86Ptr + 6 ));
JNE32(((u32)&dyna_block_discard_recmem)- ( (u32)x86Ptr + 6 ));
stg-=4;
lpc+=4;

View File

@ -296,9 +296,10 @@ void vtlb_DynGenWrite(u32 sz)
break;
}
u8* cont=JMP8(0);
x86SetJ8(_full);
int szidx=0;
x86SetJ8(_full);
int szidx=0;
switch(sz)
{
case 8: szidx=0; break;