Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add devtools options to break on data errors with GDB connected + flag to access full 8mb main memory in DS mode #2200

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ ARM::ARM(u32 num, bool jit, std::optional<GDBArgs> gdb, melonDS::NDS& nds) :
)
GdbStub.Init();
IsSingleStep = false;
BreakOnError = gdb->BreakOnError;
#endif
}

Expand Down Expand Up @@ -545,6 +546,16 @@ void ARMv5::PrefetchAbort()
{
Log(LogLevel::Warn, "ARM9: prefetch abort (%08X)\n", R[15]);

#ifdef GDBSTUB_ENABLED
Gdb::StubState s = GdbStub.Poll();
if (BreakOnError && s != Gdb::StubState::NoConn)
{
BreakReq = true;
GdbCheckB();
return;
}
#endif

u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
CPSR |= 0x97;
Expand All @@ -568,6 +579,16 @@ void ARMv5::DataAbort()
{
Log(LogLevel::Warn, "ARM9: data abort (%08X)\n", R[15]);

#ifdef GDBSTUB_ENABLED
Gdb::StubState s = GdbStub.Poll();
if (BreakOnError && s != Gdb::StubState::NoConn)
{
BreakReq = true;
GdbCheckB();
return;
}
#endif

u32 oldcpsr = CPSR;
CPSR &= ~0xBF;
CPSR |= 0x97;
Expand Down
1 change: 1 addition & 0 deletions src/ARM.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class ARM
bool IsSingleStep;
bool BreakReq;
bool BreakOnStartup;
bool BreakOnError;
u16 Port;

public:
Expand Down
1 change: 1 addition & 0 deletions src/Args.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct GDBArgs
u16 PortARM9 = 0;
bool ARM7BreakOnStartup = false;
bool ARM9BreakOnStartup = false;
bool BreakOnError = false;
};

/// Arguments to pass into the NDS constructor.
Expand Down
7 changes: 6 additions & 1 deletion src/NDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void NDS::Reset()
else
{
ARM9ClockShift = 1;
MainRAMMask = 0x3FFFFF;
MainRAMMask = useExtendedMemory ? 0x7FFFFF : 0x3FFFFF;
}
// has to be called before InitTimings
// otherwise some PU settings are completely
Expand Down Expand Up @@ -4345,4 +4345,9 @@ void NDS::ARM7IOWrite32(u32 addr, u32 val)
Log(LogLevel::Debug, "unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7.R[15]);
}

void NDS::SetMemoryExtension(bool enabled)
{
useExtendedMemory = enabled;
}

}
3 changes: 3 additions & 0 deletions src/NDS.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ class NDS
virtual void ARM7IOWrite16(u32 addr, u16 val);
virtual void ARM7IOWrite32(u32 addr, u32 val);

void SetMemoryExtension(bool enabled);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this flag be extended to also work on TWL/DSi? Its debug units have 32MB of RAM as opposed to 16MB of RAM; it's available at 0xC000000 ~ 0xDFFFFFF.


#ifdef JIT_ENABLED
[[nodiscard]] bool IsJITEnabled() const noexcept { return EnableJIT; }
void SetJITArgs(std::optional<JITArgs> args) noexcept;
Expand Down Expand Up @@ -527,6 +529,7 @@ class NDS
void EnterSleepMode();
template <CPUExecuteMode cpuMode>
u32 RunFrame();
bool useExtendedMemory = false;

public:
NDS(NDSArgs&& args, void* userdata = nullptr) noexcept : NDS(std::move(args), 0, userdata) {}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/qt_sdl/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ LegacyEntry LegacyFile[] =

#ifdef GDBSTUB_ENABLED
{"GdbEnabled", 1, "Gdb.Enabled", false},
{"GdbBreakOnError", 1, "Gdb.BreakOnError", true},
{"GdbPortARM7", 0, "Gdb.ARM7.Port", true},
{"GdbPortARM9", 0, "Gdb.ARM9.Port", true},
{"GdbARM7BreakOnStartup", 1, "Gdb.ARM7.BreakOnStartup", true},
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
static_cast<u16>(gdbopt.GetInt("ARM9.Port")),
gdbopt.GetBool("ARM7.BreakOnStartup"),
gdbopt.GetBool("ARM9.BreakOnStartup"),
gdbopt.GetBool("BreakOnError")
};
auto gdbargs = gdbopt.GetBool("Enabled") ? std::make_optional(_gdbargs) : std::nullopt;
#else
Expand Down Expand Up @@ -1352,6 +1353,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
nds = new NDS(std::move(ndsargs), this);

NDS::Current = nds;
nds->SetMemoryExtension(localCfg.GetBool("Debug.ExtendedMemory"));
nds->Reset();
loadRTCData();
//emuThread->updateVideoRenderer(); // not actually needed?
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/qt_sdl/EmuSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new

#ifdef GDBSTUB_ENABLED
ui->cbGdbEnabled->setChecked(instcfg.GetBool("Gdb.Enabled"));
ui->cbGdbBreakOnError->setChecked(instcfg.GetBool("Gdb.BreakOnError"));
ui->intGdbPortA7->setValue(instcfg.GetInt("Gdb.ARM7.Port"));
ui->intGdbPortA9->setValue(instcfg.GetInt("Gdb.ARM9.Port"));
ui->cbGdbBOSA7->setChecked(instcfg.GetBool("Gdb.ARM7.BreakOnStartup"));
Expand All @@ -108,6 +109,8 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new
ui->cbGdbBOSA9->setDisabled(true);
#endif

ui->cbDebugExtendedMem->setChecked(instcfg.GetBool("Debug.ExtendedMemory"));

on_chkEnableJIT_toggled();
on_cbGdbEnabled_toggled();
on_chkExternalBIOS_toggled();
Expand Down Expand Up @@ -294,11 +297,13 @@ void EmuSettingsDialog::done(int r)
#endif
#ifdef GDBSTUB_ENABLED
instcfg.SetBool("Gdb.Enabled", ui->cbGdbEnabled->isChecked());
instcfg.SetBool("Gdb.BreakOnError", ui->cbGdbBreakOnError->isChecked());
instcfg.SetInt("Gdb.ARM7.Port", ui->intGdbPortA7->value());
instcfg.SetInt("Gdb.ARM9.Port", ui->intGdbPortA9->value());
instcfg.SetBool("Gdb.ARM7.BreakOnStartup", ui->cbGdbBOSA7->isChecked());
instcfg.SetBool("Gdb.ARM9.BreakOnStartup", ui->cbGdbBOSA9->isChecked());
#endif
instcfg.SetBool("Debug.ExtendedMemory", ui->cbDebugExtendedMem->isChecked());

cfg.SetInt("Emu.ConsoleType", ui->cbxConsoleType->currentIndex());
cfg.SetBool("Emu.DirectBoot", ui->chkDirectBoot->isChecked());
Expand Down
20 changes: 17 additions & 3 deletions src/frontend/qt_sdl/EmuSettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -607,14 +607,28 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="7">
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="cbGdbBreakOnError">
<property name="text">
<string>Break on data error</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="5">
<widget class="QCheckBox" name="cbDebugExtendedMem">
<property name="text">
<string>Enable extended main RAM (8Mb)</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="7">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Note: melonDS must be restarted in order for these changes to have effect</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<item row="4" column="0" colspan="7">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Note: GDB stub cannot be used together with the JIT recompiler</string>
Expand Down