Merge pull request #9384 from lioncash/mbox-enum

DSP: Convert Mailbox enum into an enum class
This commit is contained in:
Léo Lam 2020-12-29 19:57:55 +01:00 committed by GitHub
commit 41316daf91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 34 deletions

View File

@ -387,8 +387,8 @@ void SDSP::DoState(PointerWrap& p)
p.Do(step_counter); p.Do(step_counter);
p.DoArray(ifx_regs); p.DoArray(ifx_regs);
accelerator->DoState(p); accelerator->DoState(p);
p.Do(mbox[0]); p.Do(m_mailbox[0]);
p.Do(mbox[1]); p.Do(m_mailbox[1]);
Common::UnWriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false); Common::UnWriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false);
p.DoArray(iram, DSP_IRAM_SIZE); p.DoArray(iram, DSP_IRAM_SIZE);
Common::WriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false); Common::WriteProtectMemory(iram, DSP_IRAM_BYTE_SIZE, false);

View File

@ -228,10 +228,10 @@ enum class ExceptionType
ExternalInterrupt = 7 // 0x000e external int (message from CPU) ExternalInterrupt = 7 // 0x000e external int (message from CPU)
}; };
enum Mailbox : int enum class Mailbox
{ {
MAILBOX_CPU, CPU,
MAILBOX_DSP DSP
}; };
struct DSP_Regs struct DSP_Regs
@ -429,9 +429,6 @@ struct SDSP
u32 iram_crc = 0; u32 iram_crc = 0;
u64 step_counter = 0; u64 step_counter = 0;
// Mailbox.
std::atomic<u32> mbox[2];
// Accelerator / DMA / other hardware registers. Not GPRs. // Accelerator / DMA / other hardware registers. Not GPRs.
std::array<u16, 256> ifx_regs{}; std::array<u16, 256> ifx_regs{};
@ -445,6 +442,9 @@ struct SDSP
u16* coef = nullptr; u16* coef = nullptr;
private: private:
auto& GetMailbox(Mailbox mailbox) { return m_mailbox[static_cast<u32>(mailbox)]; }
const auto& GetMailbox(Mailbox mailbox) const { return m_mailbox[static_cast<u32>(mailbox)]; }
void FreeMemoryPages(); void FreeMemoryPages();
void DoDMA(); void DoDMA();
@ -455,6 +455,7 @@ private:
u16 ReadIFXImpl(u16 address); u16 ReadIFXImpl(u16 address);
std::array<std::atomic<u32>, 2> m_mailbox;
DSPCore& m_dsp_core; DSPCore& m_dsp_core;
Analyzer m_analyzer; Analyzer m_analyzer;
}; };

View File

@ -25,21 +25,21 @@ void SDSP::InitializeIFX()
{ {
ifx_regs.fill(0); ifx_regs.fill(0);
mbox[MAILBOX_CPU].store(0); GetMailbox(Mailbox::CPU).store(0);
mbox[MAILBOX_DSP].store(0); GetMailbox(Mailbox::DSP).store(0);
} }
u32 SDSP::PeekMailbox(Mailbox mailbox) const u32 SDSP::PeekMailbox(Mailbox mailbox) const
{ {
return mbox[mailbox].load(); return GetMailbox(mailbox).load();
} }
u16 SDSP::ReadMailboxLow(Mailbox mailbox) u16 SDSP::ReadMailboxLow(Mailbox mailbox)
{ {
const u32 value = mbox[mailbox].load(std::memory_order_acquire); const u32 value = GetMailbox(mailbox).load(std::memory_order_acquire);
mbox[mailbox].store(value & ~0x80000000, std::memory_order_release); GetMailbox(mailbox).store(value & ~0x80000000, std::memory_order_release);
if (m_dsp_core.GetInitHax() && mailbox == MAILBOX_DSP) if (m_dsp_core.GetInitHax() && mailbox == Mailbox::DSP)
{ {
m_dsp_core.SetInitHax(false); m_dsp_core.SetInitHax(false);
m_dsp_core.Reset(); m_dsp_core.Reset();
@ -47,7 +47,7 @@ u16 SDSP::ReadMailboxLow(Mailbox mailbox)
} }
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
const char* const type = mailbox == MAILBOX_DSP ? "DSP" : "CPU"; const char* const type = mailbox == Mailbox::DSP ? "DSP" : "CPU";
DEBUG_LOG_FMT(DSP_MAIL, "{}(RM) B:{} M:0x{:#010x} (pc={:#06x})", type, mailbox, DEBUG_LOG_FMT(DSP_MAIL, "{}(RM) B:{} M:0x{:#010x} (pc={:#06x})", type, mailbox,
PeekMailbox(mailbox), pc); PeekMailbox(mailbox), pc);
#endif #endif
@ -57,7 +57,7 @@ u16 SDSP::ReadMailboxLow(Mailbox mailbox)
u16 SDSP::ReadMailboxHigh(Mailbox mailbox) u16 SDSP::ReadMailboxHigh(Mailbox mailbox)
{ {
if (m_dsp_core.GetInitHax() && mailbox == MAILBOX_DSP) if (m_dsp_core.GetInitHax() && mailbox == Mailbox::DSP)
{ {
return 0x8054; return 0x8054;
} }
@ -68,13 +68,13 @@ u16 SDSP::ReadMailboxHigh(Mailbox mailbox)
void SDSP::WriteMailboxLow(Mailbox mailbox, u16 value) void SDSP::WriteMailboxLow(Mailbox mailbox, u16 value)
{ {
const u32 old_value = mbox[mailbox].load(std::memory_order_acquire); const u32 old_value = GetMailbox(mailbox).load(std::memory_order_acquire);
const u32 new_value = (old_value & ~0xffff) | value; const u32 new_value = (old_value & ~0xffff) | value;
mbox[mailbox].store(new_value | 0x80000000, std::memory_order_release); GetMailbox(mailbox).store(new_value | 0x80000000, std::memory_order_release);
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
const char* const type = mailbox == MAILBOX_DSP ? "DSP" : "CPU"; const char* const type = mailbox == Mailbox::DSP ? "DSP" : "CPU";
DEBUG_LOG_FMT(DSP_MAIL, "{}(WM) B:{} M:{:#010x} (pc={:#06x})", type, mailbox, DEBUG_LOG_FMT(DSP_MAIL, "{}(WM) B:{} M:{:#010x} (pc={:#06x})", type, mailbox,
PeekMailbox(mailbox), pc); PeekMailbox(mailbox), pc);
#endif #endif
@ -82,10 +82,10 @@ void SDSP::WriteMailboxLow(Mailbox mailbox, u16 value)
void SDSP::WriteMailboxHigh(Mailbox mailbox, u16 value) void SDSP::WriteMailboxHigh(Mailbox mailbox, u16 value)
{ {
const u32 old_value = mbox[mailbox].load(std::memory_order_acquire); const u32 old_value = GetMailbox(mailbox).load(std::memory_order_acquire);
const u32 new_value = (old_value & 0xffff) | (value << 16); const u32 new_value = (old_value & 0xffff) | (value << 16);
mbox[mailbox].store(new_value & ~0x80000000, std::memory_order_release); GetMailbox(mailbox).store(new_value & ~0x80000000, std::memory_order_release);
} }
void SDSP::WriteIFX(u32 address, u16 value) void SDSP::WriteIFX(u32 address, u16 value)
@ -102,19 +102,19 @@ void SDSP::WriteIFX(u32 address, u16 value)
break; break;
case DSP_DMBH: case DSP_DMBH:
WriteMailboxHigh(MAILBOX_DSP, value); WriteMailboxHigh(Mailbox::DSP, value);
break; break;
case DSP_DMBL: case DSP_DMBL:
WriteMailboxLow(MAILBOX_DSP, value); WriteMailboxLow(Mailbox::DSP, value);
break; break;
case DSP_CMBH: case DSP_CMBH:
WriteMailboxHigh(MAILBOX_CPU, value); WriteMailboxHigh(Mailbox::CPU, value);
break; break;
case DSP_CMBL: case DSP_CMBL:
WriteMailboxLow(MAILBOX_CPU, value); WriteMailboxLow(Mailbox::CPU, value);
break; break;
case DSP_DSBL: case DSP_DSBL:
@ -207,16 +207,16 @@ u16 SDSP::ReadIFXImpl(u16 address)
switch (address & 0xff) switch (address & 0xff)
{ {
case DSP_DMBH: case DSP_DMBH:
return ReadMailboxHigh(MAILBOX_DSP); return ReadMailboxHigh(Mailbox::DSP);
case DSP_DMBL: case DSP_DMBL:
return ReadMailboxLow(MAILBOX_DSP); return ReadMailboxLow(Mailbox::DSP);
case DSP_CMBH: case DSP_CMBH:
return ReadMailboxHigh(MAILBOX_CPU); return ReadMailboxHigh(Mailbox::CPU);
case DSP_CMBL: case DSP_CMBL:
return ReadMailboxLow(MAILBOX_CPU); return ReadMailboxLow(Mailbox::CPU);
case DSP_DSCR: case DSP_DSCR:
return ifx_regs[address & 0xFF]; return ifx_regs[address & 0xFF];

View File

@ -213,25 +213,25 @@ u16 DSPLLE::DSP_ReadControlRegister()
u16 DSPLLE::DSP_ReadMailBoxHigh(bool cpu_mailbox) u16 DSPLLE::DSP_ReadMailBoxHigh(bool cpu_mailbox)
{ {
return m_dsp_core.ReadMailboxHigh(cpu_mailbox ? MAILBOX_CPU : MAILBOX_DSP); return m_dsp_core.ReadMailboxHigh(cpu_mailbox ? Mailbox::CPU : Mailbox::DSP);
} }
u16 DSPLLE::DSP_ReadMailBoxLow(bool cpu_mailbox) u16 DSPLLE::DSP_ReadMailBoxLow(bool cpu_mailbox)
{ {
return m_dsp_core.ReadMailboxLow(cpu_mailbox ? MAILBOX_CPU : MAILBOX_DSP); return m_dsp_core.ReadMailboxLow(cpu_mailbox ? Mailbox::CPU : Mailbox::DSP);
} }
void DSPLLE::DSP_WriteMailBoxHigh(bool cpu_mailbox, u16 value) void DSPLLE::DSP_WriteMailBoxHigh(bool cpu_mailbox, u16 value)
{ {
if (cpu_mailbox) if (cpu_mailbox)
{ {
if ((m_dsp_core.PeekMailbox(MAILBOX_CPU) & 0x80000000) != 0) if ((m_dsp_core.PeekMailbox(Mailbox::CPU) & 0x80000000) != 0)
{ {
// the DSP didn't read the previous value // the DSP didn't read the previous value
WARN_LOG_FMT(DSPLLE, "Mailbox isn't empty ... strange"); WARN_LOG_FMT(DSPLLE, "Mailbox isn't empty ... strange");
} }
m_dsp_core.WriteMailboxHigh(MAILBOX_CPU, value); m_dsp_core.WriteMailboxHigh(Mailbox::CPU, value);
} }
else else
{ {
@ -243,7 +243,7 @@ void DSPLLE::DSP_WriteMailBoxLow(bool cpu_mailbox, u16 value)
{ {
if (cpu_mailbox) if (cpu_mailbox)
{ {
m_dsp_core.WriteMailboxLow(MAILBOX_CPU, value); m_dsp_core.WriteMailboxLow(Mailbox::CPU, value);
} }
else else
{ {