Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11480 from Pokechu22/dsp-code-alignment
DSPLLE: Add assertion for bad DMA alignment
  • Loading branch information
delroth committed Jan 26, 2023
2 parents 9c9310b + e391a28 commit f056cec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Source/Core/Core/HW/DSPLLE/DSPHost.cpp
Expand Up @@ -5,6 +5,7 @@

#include <string>

#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Hash.h"
#include "Common/Logging/Log.h"
Expand Down Expand Up @@ -40,13 +41,20 @@ void WriteHostMemory(u8 value, u32 addr)

void DMAToDSP(u16* dst, u32 addr, u32 size)
{
// Hardware testing indicates that a misaligned DMA address does not work properly (it's unclear
// exactly what goes wrong currently). A size that's not a multiple of 32 is allowed, though
// (and occurs with modern libogc homebrew uCode, including the oggpalyer (asnd uCode) and
// modplay (aesnd uCode) examples). It's untested whether extra bytes are copied in that case.
ASSERT_MSG(DSPLLE, (addr & 0x1f) == 0, "DSP DMA addr must be 32-byte aligned (was {:08x})", addr);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyFromEmuSwapped(dst, addr, size);
}

void DMAFromDSP(const u16* src, u32 addr, u32 size)
{
// See comment in DMAToDSP
ASSERT_MSG(DSPLLE, (addr & 0x1f) == 0, "DSP DMA addr must be 32-byte aligned (was {:08x})", addr);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmuSwapped(addr, src, size);
Expand Down
2 changes: 1 addition & 1 deletion Source/DSPTool/DSPTool.cpp
Expand Up @@ -68,7 +68,7 @@ static std::string CodeToHeader(const std::vector<u16>& code, const std::string&
SplitPath(filename, nullptr, &filename_without_extension, nullptr);
header.append(fmt::format("const char* UCODE_NAMES[NUM_UCODES] = {{\"{}\"}};\n\n",
filename_without_extension));
header.append("const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");
header.append("alignas(0x20) const unsigned short dsp_code[NUM_UCODES][0x1000] = {\n");

header.append("\t{\n\t\t");
for (u32 j = 0; j < code_padded.size(); j++)
Expand Down

0 comments on commit f056cec

Please sign in to comment.