From d7c0cb64d32f63fbb8954c35b70b66cf5a33453e Mon Sep 17 00:00:00 2001 From: arcum42 Date: Fri, 11 Dec 2009 04:15:50 +0000 Subject: [PATCH] Revised dmaGetAddr. Fixed a thread error message. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2337 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/Dmac.h | 47 ++++++++++++++++++++++------------ pcsx2/Gif.cpp | 12 ++++----- pcsx2/IPU/IPU.cpp | 10 ++++---- pcsx2/SPR.cpp | 14 +++++----- pcsx2/Sif.cpp | 6 ++--- pcsx2/System/SysThreadBase.cpp | 4 +-- pcsx2/Vif.cpp | 4 +-- pcsx2/Vif0Dma.cpp | 2 +- pcsx2/Vif1Dma.cpp | 2 +- 9 files changed, 57 insertions(+), 44 deletions(-) diff --git a/pcsx2/Dmac.h b/pcsx2/Dmac.h index 0bd2e27f39..147752b0d9 100644 --- a/pcsx2/Dmac.h +++ b/pcsx2/Dmac.h @@ -543,26 +543,39 @@ static __forceinline void throwBusError(const char *s) dmacRegs->stat.BEIS = true; } -// Note: Dma addresses are guaranteed to be aligned to 16 bytes (128 bits) -static __forceinline void *dmaGetAddr(u32 addr) { - u8 *ptr; - -// if (addr & 0xf) { DMA_LOG("*PCSX2*: DMA address not 128bit aligned: %8.8x", addr); } - - // Need to check the physical address as well as just the "SPR" flag, as VTLB doesnt seem to handle it - if ((addr & 0x80000000) || (addr & 0x70000000) == 0x70000000) return (void*)&psS[addr & 0x3ff0]; - - ptr = (u8*)vtlb_GetPhyPtr(addr&0x1FFFFFF0); - if (ptr == NULL) { - Console.Error( "*PCSX2*: DMA error: %8.8x", addr); - return NULL; - } - return ptr; +static __forceinline bool inScratchpad(u32 addr) +{ + return ((addr >=0x70000000) && (addr <= 0x70003fff)); } -static __forceinline u32 *_dmaGetAddr(DMACh *dma, u32 addr, u32 num) +// Note: Dma addresses are guaranteed to be aligned to 16 bytes (128 bits) +static __forceinline tDMA_TAG *dmaGetAddr(u32 addr) { - u32 *ptr = (u32*)dmaGetAddr(addr); + tDMA_TAG *ptr; + + // if (addr & 0xf) { DMA_LOG("*PCSX2*: DMA address not 128bit aligned: %8.8x", addr); } + + if (DMA_TAG(addr).SPR) return (tDMA_TAG*)&psS[addr & 0x3ff0]; + + // Need to check the physical address as well as just the "SPR" flag, as VTLB doesn't seem to handle it.--refraction + if (inScratchpad(addr)) + { + //Console.Warning("Writing to the scratchpad without the SPR flag set!"); + return (tDMA_TAG*)&psS[addr & 0x3ff0]; + } + + ptr = (tDMA_TAG*)vtlb_GetPhyPtr(addr & 0x1FFFFFF0); + if (ptr == NULL) + { + Console.Error( "*PCSX2*: DMA error: %8.8x", addr); + return NULL; + } + return ptr; +} + +static __forceinline tDMA_TAG *safeDmaGetAddr(DMACh *dma, u32 addr, u32 num) +{ + tDMA_TAG *ptr = dmaGetAddr(addr); if (ptr == NULL) { // DMA Error diff --git a/pcsx2/Gif.cpp b/pcsx2/Gif.cpp index 6fa4e6241c..06e3d5a77f 100644 --- a/pcsx2/Gif.cpp +++ b/pcsx2/Gif.cpp @@ -116,7 +116,7 @@ int _GIFchain() u32 qwc = min( gifsplit, (int)gif->qwc ); tDMA_TAG *pMem; - pMem = (tDMA_TAG*)dmaGetAddr(gif->madr); + pMem = dmaGetAddr(gif->madr); if (pMem == NULL) { // reset path3, fixes dark cloud 2 @@ -154,7 +154,7 @@ static __forceinline bool checkTieBit(tDMA_TAG* &ptag) static __forceinline tDMA_TAG* ReadTag() { - tDMA_TAG* ptag = (tDMA_TAG*)dmaGetAddr(gif->tadr); //Set memory pointer to TADR + tDMA_TAG* ptag = dmaGetAddr(gif->tadr); //Set memory pointer to TADR if (!(gif->transfer("Gif", ptag))) return NULL; @@ -167,7 +167,7 @@ static __forceinline tDMA_TAG* ReadTag() static __forceinline tDMA_TAG* ReadTag2() { - tDMA_TAG* ptag = (tDMA_TAG*)dmaGetAddr(gif->tadr); //Set memory pointer to TADR + tDMA_TAG* ptag = dmaGetAddr(gif->tadr); //Set memory pointer to TADR gif->unsafeTransfer(ptag); gif->madr = ptag[1]._u32; @@ -294,7 +294,7 @@ void GIFdma() if ((!gspath3done) && (gif->qwc == 0)) { - ptag = (tDMA_TAG*)dmaGetAddr(gif->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(gif->tadr); //Set memory pointer to TADR gif->unsafeTransfer(ptag); gif->madr = ptag[1]._u32; @@ -411,7 +411,7 @@ static __forceinline bool mfifoGIFchain() { int mfifoqwc; - tDMA_TAG *pMem = (tDMA_TAG*)dmaGetAddr(gif->madr); + tDMA_TAG *pMem = dmaGetAddr(gif->madr); if (pMem == NULL) return false; mfifoqwc = WRITERING_DMA(pMem, gif->qwc); @@ -458,7 +458,7 @@ void mfifoGIFtransfer(int qwc) gif->tadr = qwctag(gif->tadr); - ptag = (tDMA_TAG*)dmaGetAddr(gif->tadr); + ptag = dmaGetAddr(gif->tadr); gif->unsafeTransfer(ptag); gif->madr = ptag[1]._u32; diff --git a/pcsx2/IPU/IPU.cpp b/pcsx2/IPU/IPU.cpp index c168ad9998..cee005af74 100644 --- a/pcsx2/IPU/IPU.cpp +++ b/pcsx2/IPU/IPU.cpp @@ -1352,7 +1352,7 @@ static __forceinline bool IPU1chain(int &totalqwc) int qwc = ipu1dma->qwc; tDMA_TAG *pMem; - pMem = (tDMA_TAG*)dmaGetAddr(ipu1dma->madr); + pMem = dmaGetAddr(ipu1dma->madr); if (pMem == NULL) { @@ -1485,7 +1485,7 @@ int IPU1dma() if (ipu1dma->chcr.TIE && tag.IRQ) { - ptag = (tDMA_TAG*)dmaGetAddr(ipu1dma->tadr); + ptag = dmaGetAddr(ipu1dma->tadr); ipuDmacPartialChain(tag); @@ -1528,7 +1528,7 @@ int IPU1dma() else { // Chain Mode & ipu1dma->qwc is 0 - ptag = (tDMA_TAG*)dmaGetAddr(ipu1dma->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(ipu1dma->tadr); //Set memory pointer to TADR // Transfer the tag. if (!ipu1dma->transfer("IPU1", ptag)) return totalqwc; @@ -1553,7 +1553,7 @@ int IPU1dma() if (done) { - ptag = (tDMA_TAG*)dmaGetAddr(ipu1dma->tadr); + ptag = dmaGetAddr(ipu1dma->tadr); ipuDmacPartialChain(ptag[0]); @@ -1665,7 +1665,7 @@ int IPU0dma() pxAssert(ipu0dma->chcr.MOD == NORMAL_MODE); - pMem = (tDMA_TAG*)dmaGetAddr(ipu0dma->madr); + pMem = dmaGetAddr(ipu0dma->madr); readsize = min(ipu0dma->qwc, (u16)ipuRegs->ctrl.OFC); totalsize+=readsize; diff --git a/pcsx2/SPR.cpp b/pcsx2/SPR.cpp index 08d005586a..c1e47ea486 100644 --- a/pcsx2/SPR.cpp +++ b/pcsx2/SPR.cpp @@ -52,7 +52,7 @@ int _SPR0chain() tDMA_TAG *pMem; if (spr0->qwc == 0) return 0; - pMem = (tDMA_TAG*)dmaGetAddr(spr0->madr); + pMem = dmaGetAddr(spr0->madr); if (pMem == NULL) return -1; switch (dmacRegs->ctrl.MFD) @@ -107,7 +107,7 @@ void _SPR0interleave() { spr0->qwc = std::min(tqwc, qwc); qwc -= spr0->qwc; - pMem = (tDMA_TAG*)dmaGetAddr(spr0->madr); + pMem = dmaGetAddr(spr0->madr); switch (dmacRegs->ctrl.MFD) { @@ -287,7 +287,7 @@ int _SPR1chain() if (spr1->qwc == 0) return 0; - pMem = (tDMA_TAG*)dmaGetAddr(spr1->madr); + pMem = dmaGetAddr(spr1->madr); if (pMem == NULL) return -1; SPR1transfer((u32*)pMem, spr1->qwc << 2); @@ -317,7 +317,7 @@ void _SPR1interleave() { spr1->qwc = std::min(tqwc, qwc); qwc -= spr1->qwc; - pMem = (tDMA_TAG*)dmaGetAddr(spr1->madr); + pMem = dmaGetAddr(spr1->madr); memcpy_fast(&psSu8(spr1->sadr), (u8*)pMem, spr1->qwc << 4); spr1->sadr += spr1->qwc * 16; spr1->madr += (sqwc + spr1->qwc) * 16; @@ -353,7 +353,7 @@ void _dmaSPR1() // toSPR work function } // Chain Mode - ptag = (tDMA_TAG*)dmaGetAddr(spr1->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(spr1->tadr); //Set memory pointer to TADR if (!spr1->transfer("SPR1 Tag", ptag)) { @@ -387,7 +387,7 @@ void _dmaSPR1() // toSPR work function spr1finished = done; if (!done) { - ptag = (tDMA_TAG*)dmaGetAddr(spr1->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(spr1->tadr); //Set memory pointer to TADR CPU_INT(9, (ptag[0].QWC / BIAS));// the lower 16 bits of the tag / BIAS); } break; @@ -411,7 +411,7 @@ void dmaSPR1() // toSPR if ((spr1->chcr.MOD == CHAIN_MODE) && (spr1->qwc == 0)) { tDMA_TAG *ptag; - ptag = (tDMA_TAG*)dmaGetAddr(spr1->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(spr1->tadr); //Set memory pointer to TADR CPU_INT(9, ptag[0].QWC / BIAS); return; } diff --git a/pcsx2/Sif.cpp b/pcsx2/Sif.cpp index 870126bf37..79a8fef24e 100644 --- a/pcsx2/Sif.cpp +++ b/pcsx2/Sif.cpp @@ -179,7 +179,7 @@ __forceinline void SIF0Dma() //SIF_LOG(" EE SIF doing transfer %04Xqw to %08X", readSize, sif0dma->madr); SIF_LOG("----------- %lX of %lX", readSize << 2, size << 2); - ptag = (tDMA_TAG*)_dmaGetAddr(sif0dma, sif0dma->madr, DMAC_SIF0); + ptag = safeDmaGetAddr(sif0dma, sif0dma->madr, DMAC_SIF0); if (ptag == NULL) return; SIF0read((u32*)ptag, readSize << 2); @@ -278,7 +278,7 @@ __forceinline void SIF1Dma() { // Process DMA tag at sif1dma->tadr done = false; - ptag = (tDMA_TAG*)_dmaGetAddr(sif1dma, sif1dma->tadr, DMAC_SIF1); + ptag = safeDmaGetAddr(sif1dma, sif1dma->tadr, DMAC_SIF1); if (ptag == NULL) return; sif1dma->unsafeTransfer(ptag); @@ -341,7 +341,7 @@ __forceinline void SIF1Dma() int qwTransfer = sif1dma->qwc; tDMA_TAG *data; - data = (tDMA_TAG*)_dmaGetAddr(sif1dma, sif1dma->madr, DMAC_SIF1); + data = safeDmaGetAddr(sif1dma, sif1dma->madr, DMAC_SIF1); if (data == NULL) return; if (qwTransfer > (FIFO_SIF1_W - sif1.fifoSize) / 4) // Copy part of sif1dma into FIFO diff --git a/pcsx2/System/SysThreadBase.cpp b/pcsx2/System/SysThreadBase.cpp index 62fd9ddfb7..2e3a70db96 100644 --- a/pcsx2/System/SysThreadBase.cpp +++ b/pcsx2/System/SysThreadBase.cpp @@ -130,8 +130,8 @@ bool SysThreadBase::Suspend( bool isBlocking ) // to wait, or issue a cancel to the thread. throw Exception::ThreadTimedOut( *this, - L"Possible deadlock while suspending thread '%s'", - L"'%s' thread is not responding to suspend requests. It may be deadlocked or just running *really* slow." + wxsFormat(L"Possible deadlock while suspending thread '%s'", m_name.c_str()), + wxsFormat(L"'%s' thread is not responding to suspend requests. It may be deadlocked or just running *really* slow.", m_name.c_str()) ); } } diff --git a/pcsx2/Vif.cpp b/pcsx2/Vif.cpp index 9b234b1c22..91e22ab558 100644 --- a/pcsx2/Vif.cpp +++ b/pcsx2/Vif.cpp @@ -483,7 +483,7 @@ static __forceinline bool mfifo_VIF1chain() } else { - tDMA_TAG *pMem = (tDMA_TAG*)dmaGetAddr(vif1ch->madr); + tDMA_TAG *pMem = dmaGetAddr(vif1ch->madr); SPR_LOG("Non-MFIFO Location"); if (pMem == NULL) return false; @@ -527,7 +527,7 @@ void mfifoVIF1transfer(int qwc) if (vif1ch->qwc == 0 && vifqwc > 0) { - ptag = (tDMA_TAG*)dmaGetAddr(vif1ch->tadr); + ptag = dmaGetAddr(vif1ch->tadr); if (vif1ch->chcr.TTE) { diff --git a/pcsx2/Vif0Dma.cpp b/pcsx2/Vif0Dma.cpp index e4af9e5e66..5ff8c6d029 100644 --- a/pcsx2/Vif0Dma.cpp +++ b/pcsx2/Vif0Dma.cpp @@ -499,7 +499,7 @@ bool _chainVIF0() { tDMA_TAG *ptag; - ptag = (tDMA_TAG*)dmaGetAddr(vif0ch->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(vif0ch->tadr); //Set memory pointer to TADR if (!(vif0ch->transfer("Vif0 Tag", ptag))) return false; diff --git a/pcsx2/Vif1Dma.cpp b/pcsx2/Vif1Dma.cpp index 9b83c1a077..fff6ca0405 100644 --- a/pcsx2/Vif1Dma.cpp +++ b/pcsx2/Vif1Dma.cpp @@ -802,7 +802,7 @@ __forceinline void vif1SetupTransfer() break; case VIF_CHAIN_MODE: - ptag = (tDMA_TAG*)dmaGetAddr(vif1ch->tadr); //Set memory pointer to TADR + ptag = dmaGetAddr(vif1ch->tadr); //Set memory pointer to TADR if (!(vif1ch->transfer("Vif1 Tag", ptag))) return;