Skip to content

Commit

Permalink
Merge pull request #3411 from lioncash/dsp
Browse files Browse the repository at this point in the history
DSPCore: Minor changes
  • Loading branch information
delroth committed Dec 29, 2015
2 parents c16c2d9 + 4bc7c0c commit 76250a9
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 52 deletions.
42 changes: 19 additions & 23 deletions Source/Core/Core/DSP/DSPCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <algorithm>
#include <array>
#include <memory>

#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
Expand All @@ -22,11 +23,11 @@
#include "Core/DSP/DSPIntUtil.h"

SDSP g_dsp;
DSPBreakpoints dsp_breakpoints;
DSPBreakpoints g_dsp_breakpoints;
static DSPCoreState core_state = DSPCORE_STOP;
u16 cyclesLeft = 0;
bool init_hax = false;
DSPEmitter *dspjit = nullptr;
u16 g_cycles_left = 0;
bool g_init_hax = false;
std::unique_ptr<DSPEmitter> g_dsp_jit;
std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
static Common::Event step_event;

Expand Down Expand Up @@ -100,9 +101,8 @@ static void DSPCore_FreeMemoryPages()
bool DSPCore_Init(const DSPInitOptions& opts)
{
g_dsp.step_counter = 0;
cyclesLeft = 0;
init_hax = false;
dspjit = nullptr;
g_cycles_left = 0;
g_init_hax = false;

g_dsp.irom = (u16*)AllocateMemoryPages(DSP_IROM_BYTE_SIZE);
g_dsp.iram = (u16*)AllocateMemoryPages(DSP_IRAM_BYTE_SIZE);
Expand Down Expand Up @@ -147,7 +147,7 @@ bool DSPCore_Init(const DSPInitOptions& opts)

// Initialize JIT, if necessary
if (opts.core_type == DSPInitOptions::CORE_JIT)
dspjit = new DSPEmitter();
g_dsp_jit = std::make_unique<DSPEmitter>();

g_dsp_cap.reset(opts.capture_logger);

Expand All @@ -162,11 +162,7 @@ void DSPCore_Shutdown()

core_state = DSPCORE_STOP;

if (dspjit)
{
delete dspjit;
dspjit = nullptr;
}
g_dsp_jit.reset();

DSPCore_FreeMemoryPages();

Expand Down Expand Up @@ -245,7 +241,7 @@ void DSPCore_CheckExceptions()
// Handle state changes and stepping.
int DSPCore_RunCycles(int cycles)
{
if (dspjit)
if (g_dsp_jit)
{
if (g_dsp.external_interrupt_waiting)
{
Expand All @@ -254,14 +250,14 @@ int DSPCore_RunCycles(int cycles)
DSPCore_SetExternalInterrupt(false);
}

cyclesLeft = cycles;
DSPCompiledCode pExecAddr = (DSPCompiledCode)dspjit->enterDispatcher;
g_cycles_left = cycles;
DSPCompiledCode pExecAddr = (DSPCompiledCode)g_dsp_jit->enterDispatcher;
pExecAddr();

if (g_dsp.reset_dspjit_codespace)
dspjit->ClearIRAMandDSPJITCodespaceReset();
g_dsp_jit->ClearIRAMandDSPJITCodespaceReset();

return cyclesLeft;
return g_cycles_left;
}

while (cycles > 0)
Expand Down Expand Up @@ -317,7 +313,7 @@ void DSPCore_Step()

void CompileCurrent()
{
dspjit->Compile(g_dsp.pc);
g_dsp_jit->Compile(g_dsp.pc);

bool retry = true;

Expand All @@ -326,11 +322,11 @@ void CompileCurrent()
retry = false;
for (u16 i = 0x0000; i < 0xffff; ++i)
{
if (!dspjit->unresolvedJumps[i].empty())
if (!g_dsp_jit->unresolvedJumps[i].empty())
{
u16 addrToCompile = dspjit->unresolvedJumps[i].front();
dspjit->Compile(addrToCompile);
if (!dspjit->unresolvedJumps[i].empty())
u16 addrToCompile = g_dsp_jit->unresolvedJumps[i].front();
g_dsp_jit->Compile(addrToCompile);
if (!g_dsp_jit->unresolvedJumps[i].empty())
retry = true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/DSP/DSPCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ struct SDSP
};

extern SDSP g_dsp;
extern DSPBreakpoints dsp_breakpoints;
extern DSPEmitter *dspjit;
extern u16 cyclesLeft;
extern bool init_hax;
extern DSPBreakpoints g_dsp_breakpoints;
extern u16 g_cycles_left;
extern bool g_init_hax;
extern std::unique_ptr<DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap;

struct DSPInitOptions
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void DSPEmitter::CompileDispatcher()
returnDispatcher = GetCodePtr();

// Decrement cyclesLeft
SUB(16, M(&cyclesLeft), R(EAX));
SUB(16, M(&g_cycles_left), R(EAX));

J_CC(CC_A, dispatcherLoop);

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Core/DSP/DSPHWInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void gdsp_mbox_write_l(Mailbox mbx, u16 val)

u16 gdsp_mbox_read_h(Mailbox mbx)
{
if (init_hax && mbx == MAILBOX_DSP)
if (g_init_hax && mbx == MAILBOX_DSP)
{
return 0x8054;
}
Expand All @@ -70,9 +70,9 @@ u16 gdsp_mbox_read_l(Mailbox mbx)
const u32 value = g_dsp.mbox[mbx].load(std::memory_order_acquire);
g_dsp.mbox[mbx].store(value & ~0x80000000, std::memory_order_release);

if (init_hax && mbx == MAILBOX_DSP)
if (g_init_hax && mbx == MAILBOX_DSP)
{
init_hax = false;
g_init_hax = false;
DSPCore_Reset();
return 0x4348;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/DSP/DSPInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void WriteCR(u16 val)
// HAX!
// OSInitAudioSystem ucode should send this mail - not DSP core itself
INFO_LOG(DSPLLE,"DSP_CONTROL INIT");
init_hax = true;
g_init_hax = true;
val |= 0x800;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ int RunCyclesDebug(int cycles)
{
if (g_dsp.cr & CR_HALT)
return 0;
if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
if (g_dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
{
DSPCore_SetState(DSPCORE_STEPPING);
return cycles;
Expand All @@ -128,7 +128,7 @@ int RunCyclesDebug(int cycles)
{
if (g_dsp.cr & CR_HALT)
return 0;
if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
if (g_dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
{
DSPCore_SetState(DSPCORE_STEPPING);
return cycles;
Expand All @@ -145,7 +145,7 @@ int RunCyclesDebug(int cycles)
// Now, lets run some more without idle skipping.
for (int i = 0; i < 200; i++)
{
if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
if (g_dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc))
{
DSPCore_SetState(DSPCORE_STEPPING);
return cycles;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/DSP/Jit/DSPJitBranch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ static void WriteBlockLink(DSPEmitter& emitter, u16 dest)
{
emitter.gpr.FlushRegs();
// Check if we have enough cycles to execute the next block
emitter.MOV(16, R(ECX), M(&cyclesLeft));
emitter.MOV(16, R(ECX), M(&g_cycles_left));
emitter.CMP(16, R(ECX), Imm16(emitter.blockSize[emitter.startAddr] + emitter.blockSize[dest]));
FixupBranch notEnoughCycles = emitter.J_CC(CC_BE);

emitter.SUB(16, R(ECX), Imm16(emitter.blockSize[emitter.startAddr]));
emitter.MOV(16, M(&cyclesLeft), R(ECX));
emitter.MOV(16, M(&g_cycles_left), R(ECX));
emitter.JMP(emitter.blockLinks[dest], true);
emitter.SetJumpTarget(notEnoughCycles);
}
Expand Down
18 changes: 9 additions & 9 deletions Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ bool DSPDebugInterface::IsBreakpoint(unsigned int address)
{
int real_addr = DSPSymbols::Line2Addr(address);
if (real_addr >= 0)
return dsp_breakpoints.IsAddressBreakPoint(real_addr);
else
return false;
return g_dsp_breakpoints.IsAddressBreakPoint(real_addr);

return false;
}

void DSPDebugInterface::SetBreakpoint(unsigned int address)
Expand All @@ -86,7 +86,7 @@ void DSPDebugInterface::SetBreakpoint(unsigned int address)

if (real_addr >= 0)
{
if (dsp_breakpoints.Add(real_addr))
if (g_dsp_breakpoints.Add(real_addr))
{

}
Expand All @@ -99,7 +99,7 @@ void DSPDebugInterface::ClearBreakpoint(unsigned int address)

if (real_addr >= 0)
{
if (dsp_breakpoints.Remove(real_addr))
if (g_dsp_breakpoints.Remove(real_addr))
{

}
Expand All @@ -108,18 +108,18 @@ void DSPDebugInterface::ClearBreakpoint(unsigned int address)

void DSPDebugInterface::ClearAllBreakpoints()
{
dsp_breakpoints.Clear();
g_dsp_breakpoints.Clear();
}

void DSPDebugInterface::ToggleBreakpoint(unsigned int address)
{
int real_addr = DSPSymbols::Line2Addr(address);
if (real_addr >= 0)
{
if (dsp_breakpoints.IsAddressBreakPoint(real_addr))
dsp_breakpoints.Remove(real_addr);
if (g_dsp_breakpoints.IsAddressBreakPoint(real_addr))
g_dsp_breakpoints.Remove(real_addr);
else
dsp_breakpoints.Add(real_addr);
g_dsp_breakpoints.Add(real_addr);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/DSPLLE/DSPHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void CodeLoaded(const u8 *ptr, int size)

UpdateDebugger();

if (dspjit)
dspjit->ClearIRAM();
if (g_dsp_jit)
g_dsp_jit->ClearIRAM();

DSPAnalyzer::Analyze();
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/HW/DSPLLE/DSPLLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void DSPLLE::DoState(PointerWrap &p)
if (p.GetMode() == PointerWrap::MODE_READ)
DSPHost::CodeLoaded((const u8*)g_dsp.iram, DSP_IRAM_BYTE_SIZE);
p.DoArray(g_dsp.dram, DSP_DRAM_SIZE);
p.Do(cyclesLeft);
p.Do(init_hax);
p.Do(g_cycles_left);
p.Do(g_init_hax);
p.Do(m_cycle_count);
}

Expand All @@ -99,7 +99,7 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle)
if (cycles > 0)
{
std::lock_guard<std::mutex> dsp_thread_lock(dsp_lle->m_csDSPThreadActive);
if (dspjit)
if (g_dsp_jit)
{
DSPCore_RunCycles(cycles);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ bool DSPLLE::Initialize(bool bWii, bool bDSPThread)

// needs to be after DSPCore_Init for the dspjit ptr
if (NetPlay::IsNetPlayRunning() || Movie::IsMovieActive() ||
Core::g_want_determinism || !dspjit)
Core::g_want_determinism || !g_dsp_jit)
{
bDSPThread = false;
}
Expand Down

0 comments on commit 76250a9

Please sign in to comment.