From cc38e72dc3679e15248ffe1c0db6931ce87627c1 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 28 Jun 2009 17:18:52 +0000 Subject: [PATCH] DSPLLE: Setting breakpoints and stepping through code now works in the (still rather basic) DSP debugger. Decided not to share the breakpoints code between PPC and DSP because it can be done much more efficiently for the DSP case due to the very limited memory space. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3575 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DSPCore/DSPCore.vcproj | 8 +++ Source/Core/DSPCore/Src/DSPAnalyzer.h | 2 - Source/Core/DSPCore/Src/DSPBreakpoints.cpp | 19 ++++++ Source/Core/DSPCore/Src/DSPBreakpoints.h | 63 +++++++++++++++++++ Source/Core/DSPCore/Src/DSPCore.cpp | 6 +- Source/Core/DSPCore/Src/DSPCore.h | 4 +- Source/Core/DSPCore/Src/DSPInterpreter.cpp | 46 +++++++++++--- Source/Core/DSPCore/Src/SConscript | 1 + .../Src/Debugger/DSPRegisterView.cpp | 4 +- .../Src/Debugger/DSPRegisterView.h | 2 +- .../Plugin_DSP_LLE/Src/Debugger/Debugger.cpp | 4 +- docs/DSP/DSP_UC_Zelda.txt | 2 +- 12 files changed, 137 insertions(+), 24 deletions(-) create mode 100644 Source/Core/DSPCore/Src/DSPBreakpoints.cpp create mode 100644 Source/Core/DSPCore/Src/DSPBreakpoints.h diff --git a/Source/Core/DSPCore/DSPCore.vcproj b/Source/Core/DSPCore/DSPCore.vcproj index fffc872438..34f8e428f4 100644 --- a/Source/Core/DSPCore/DSPCore.vcproj +++ b/Source/Core/DSPCore/DSPCore.vcproj @@ -482,6 +482,14 @@ RelativePath=".\Src\DSPAnalyzer.h" > + + + + diff --git a/Source/Core/DSPCore/Src/DSPAnalyzer.h b/Source/Core/DSPCore/Src/DSPAnalyzer.h index 89e1e6c980..1b29ede4af 100644 --- a/Source/Core/DSPCore/Src/DSPAnalyzer.h +++ b/Source/Core/DSPCore/Src/DSPAnalyzer.h @@ -23,8 +23,6 @@ namespace DSPAnalyzer { #define ISPACE 65536 - - // Useful things to detect: // * Loop endpoints - so that we can avoid checking for loops every cycle. diff --git a/Source/Core/DSPCore/Src/DSPBreakpoints.cpp b/Source/Core/DSPCore/Src/DSPBreakpoints.cpp new file mode 100644 index 0000000000..ec48a249fc --- /dev/null +++ b/Source/Core/DSPCore/Src/DSPBreakpoints.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2003-2009 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "DSPBreakpoints.h" + diff --git a/Source/Core/DSPCore/Src/DSPBreakpoints.h b/Source/Core/DSPCore/Src/DSPBreakpoints.h new file mode 100644 index 0000000000..98ff5f609d --- /dev/null +++ b/Source/Core/DSPCore/Src/DSPBreakpoints.h @@ -0,0 +1,63 @@ +// Copyright (C) 2003-2009 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _DSP_BREAKPOINTS +#define _DSP_BREAKPOINTS + +#include "Common.h" + +// super fast breakpoints for a limited range. +// To be used interchangably with the BreakPoints class. +class DSPBreakpoints +{ +public: + DSPBreakpoints() {Clear();} + // is address breakpoint + bool IsAddressBreakPoint(u32 addr) { + return b[addr] != 0; + } + + // AddBreakPoint + bool Add(u32 addr, bool temp=false) { + bool was_one = b[addr] != 0; + if (!was_one) { + b[addr] = temp ? 2 : 1; + return true; + } else { + return false; + } + } + // Remove Breakpoint + bool Remove(u32 addr) { + bool was_one = b[addr] != 0; + b[addr] = 0; + return was_one; + } + void Clear() { + for (int i = 0; i < 65536; i++) + b[i] = 0; + } + + void DeleteByAddress(u32 addr) { + b[addr] = 0; + } + +private: + u8 b[65536]; +}; + +#endif diff --git a/Source/Core/DSPCore/Src/DSPCore.cpp b/Source/Core/DSPCore/Src/DSPCore.cpp index 8824916db9..565e2e6b1a 100644 --- a/Source/Core/DSPCore/Src/DSPCore.cpp +++ b/Source/Core/DSPCore/Src/DSPCore.cpp @@ -34,7 +34,7 @@ #include "DSPIntUtil.h" SDSP g_dsp; -BreakPoints dsp_breakpoints; +DSPBreakpoints dsp_breakpoints; DSPCoreState core_state = DSPCORE_RUNNING; Common::Event step_event; @@ -200,11 +200,9 @@ int DSPCore_RunCycles(int cycles) switch (core_state) { case DSPCORE_RUNNING: -#if 0 // Set to 1 to enable stepping - // Enable breakpoints +#if 1 // Set to 0 to disable breakpoints, for a speed boost. cycles = DSPInterpreter::RunCyclesDebug(cycles); #else - //1: enter a fast runloop cycles = DSPInterpreter::RunCycles(cycles); #endif break; diff --git a/Source/Core/DSPCore/Src/DSPCore.h b/Source/Core/DSPCore/Src/DSPCore.h index a0c574ca1a..eab5773c03 100644 --- a/Source/Core/DSPCore/Src/DSPCore.h +++ b/Source/Core/DSPCore/Src/DSPCore.h @@ -26,7 +26,7 @@ #ifndef _DSPCORE_H #define _DSPCORE_H -#include "BreakPoints.h" +#include "DSPBreakpoints.h" #define DSP_IRAM_BYTE_SIZE 0x2000 #define DSP_IRAM_SIZE 0x1000 @@ -201,7 +201,7 @@ struct SDSP }; extern SDSP g_dsp; -extern BreakPoints dsp_breakpoints; +extern DSPBreakpoints dsp_breakpoints; bool DSPCore_Init(const char *irom_filename, const char *coef_filename); void DSPCore_Reset(); diff --git a/Source/Core/DSPCore/Src/DSPInterpreter.cpp b/Source/Core/DSPCore/Src/DSPInterpreter.cpp index d1f98995e9..e054c61237 100644 --- a/Source/Core/DSPCore/Src/DSPInterpreter.cpp +++ b/Source/Core/DSPCore/Src/DSPInterpreter.cpp @@ -157,33 +157,59 @@ int RunCyclesDebug(int cycles) { if (g_dsp.cr & CR_HALT) return 0; - Step(); - cycles--; - } - - while (cycles > 0) - { - if (g_dsp.cr & CR_HALT) { - return 0; - } if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc)) { DSPCore_SetState(DSPCORE_STEPPING); return cycles; } - DSPCore_CheckExternalInterrupt(); Step(); cycles--; + if (cycles < 0) + return 0; + } + DSPCore_CheckExternalInterrupt(); + + // Now, let's run a few cycles with idle skipping. + for (int i = 0; i < 8; i++) + { + if (g_dsp.cr & CR_HALT) + return 0; + if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc)) + { + DSPCore_SetState(DSPCORE_STEPPING); + return cycles; + } // Idle skipping. if (DSPAnalyzer::code_flags[g_dsp.pc] & DSPAnalyzer::CODE_IDLE_SKIP) return 0; + + Step(); + cycles--; + if (cycles < 0) + return 0; } + + // Finally, run the rest of the block without. + while (cycles > 0) + { + if (dsp_breakpoints.IsAddressBreakPoint(g_dsp.pc)) + { + DSPCore_SetState(DSPCORE_STEPPING); + return cycles; + } + Step(); + cycles--; + } + + return cycles; } // Used by non-thread mode. Meant to be efficient. int RunCycles(int cycles) { + DSPCore_CheckExternalInterrupt(); + if (cycles < 18) { for (int i = 0; i < cycles; i++) diff --git a/Source/Core/DSPCore/Src/SConscript b/Source/Core/DSPCore/Src/SConscript index 3fcf93f3c2..f79d9e06f1 100644 --- a/Source/Core/DSPCore/Src/SConscript +++ b/Source/Core/DSPCore/Src/SConscript @@ -6,6 +6,7 @@ files = [ "assemble.cpp", "disassemble.cpp", "DSPAccelerator.cpp", + "DSPBreakpoints.cpp", "DSPIntCCUtil.cpp", "DSPIntExtOps.cpp", "DSPHWInterface.cpp", diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.cpp index 3f455e287d..3d3c26d557 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.cpp @@ -21,7 +21,7 @@ wxString CRegTable::GetValue(int row, int col) { - if (row < 36) // 32 "normal" regs + if (row < 32) // 32 "normal" regs { switch (col) { @@ -46,7 +46,7 @@ void CRegTable::UpdateCachedRegs() m_CachedCounter = g_dsp.step_counter; - for (int i = 0; i < 36; ++i) + for (int i = 0; i < 32; ++i) { m_CachedRegHasChanged[i] = (m_CachedRegs[i] != g_dsp.r[i]); m_CachedRegs[i] = g_dsp.r[i]; diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.h b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.h index f369302035..27e5d2f7bf 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.h +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/DSPRegisterView.h @@ -38,7 +38,7 @@ public: } int GetNumberCols(void) {return 2;} - int GetNumberRows(void) {return 36;} + int GetNumberRows(void) {return 32;} bool IsEmptyCell(int row, int col) {return false;} wxString GetValue(int row, int col); void SetValue(int row, int col, const wxString &); diff --git a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp index 9646997ac9..d0c3c6ca18 100644 --- a/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp +++ b/Source/Plugins/Plugin_DSP_LLE/Src/Debugger/Debugger.cpp @@ -50,8 +50,8 @@ DSPDebuggerLLE::~DSPDebuggerLLE() void DSPDebuggerLLE::CreateGUIControls() { // Basic settings - SetSize(700, 500); - this->SetSizeHints(700, 500); + SetSize(700, 800); + this->SetSizeHints(700, 800); this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); m_Toolbar = CreateToolBar(wxTB_NODIVIDER|wxTB_NOICONS|wxTB_HORZ_TEXT|wxTB_DOCKABLE, ID_TOOLBAR); diff --git a/docs/DSP/DSP_UC_Zelda.txt b/docs/DSP/DSP_UC_Zelda.txt index cc03d26483..8ae5d94b09 100644 --- a/docs/DSP/DSP_UC_Zelda.txt +++ b/docs/DSP/DSP_UC_Zelda.txt @@ -865,7 +865,7 @@ void 0233_Increase_32BitAddress_InMem(_MemAddr(AR0), _Bytes(AX0.L)) void 0239_WaitUntilLastFrameGotSynced() { // 0239 8100 clr $ACC0 - // 23a 8900 clr $ACC1 + // 023a 8900 clr $ACC1 // 023b 00df 0354 lr $AC1.M, @0x0354 // 023d 00de 034e lr $AC0.M, @0x034e // 023f 8200 cmp