Add ELF state widget.

This commit is contained in:
Christian Speckner 2024-08-26 22:44:31 +02:00
parent f76d70f68e
commit 2cf85c8ab2
9 changed files with 218 additions and 6 deletions

View File

@ -0,0 +1,106 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2024 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include "CartELFStateWidget.hxx"
#include <sstream>
#include "CartELF.hxx"
#include "DataGridWidget.hxx"
#include "ToggleBitWidget.hxx"
namespace {
string registerName(uInt8 reg) {
switch (reg) {
case 11:
return "FP (R11) = ";
case 12:
return "IP (R12) = ";
case 13:
return "SP (R13) = ";
case 14:
return "LR (R14) = ";
case 15:
return "PC (R15) = ";
default: {
ostringstream s;
s << "R" << static_cast<int>(reg) << " = ";
return s.str();
}
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeELFStateWidget::CartridgeELFStateWidget(GuiObject* boss, const GUI::Font& lfont,
const GUI::Font& nfont,
int x, int y, int w, int h,
CartridgeELF& cart)
: CartDebugWidget(boss, lfont, nfont, x, y, w, h), myCart(cart), myFlagValues(4)
{
initialize();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeELFStateWidget::initialize()
{
constexpr int x0 = 2;
const int lineHeight = _font.getLineHeight();
int y = lineHeight / 2;
new StaticTextWidget(_boss, _font, x0, y, "ARM registers:");
const int indent = _font.getMaxCharWidth() * 15;
myArmRegisters = new DataGridWidget(_boss, _font, x0 + indent, y, 4, 4, 8, 8, Common::Base::Fmt::_16_8);
y += myArmRegisters->getHeight() + lineHeight / 2;
myArmRegisters->setEditable(false);
for (uInt8 i = 0; i < 16; i++) myArmRegisters->setToolTip(i % 4, i / 4, registerName(i));
new StaticTextWidget(_boss, _font, x0, y, "ARM flags:");
myFlags = new ToggleBitWidget(_boss, _font, x0 + indent, y + lineHeight, 4, 1, 1);
myFlags->setEditable(false);
new StaticTextWidget(_boss, _font, x0 + indent + 3, y, "N");
new StaticTextWidget(_boss, _font, x0 + indent + 3 + myFlags->colWidth(), y, "Z");
new StaticTextWidget(_boss, _font, x0 + indent + 3 + 2 * myFlags->colWidth(), y, "C");
new StaticTextWidget(_boss, _font, x0 + indent + 3 + 3 * myFlags->colWidth(), y, "V");
}
void CartridgeELFStateWidget::loadConfig()
{
for (uInt8 i = 0; i < 16; i++)
myArmRegisters->setValue(i, myCart.myCortexEmu.getRegister(i));
BoolArray flags(4);
flags[0] = myCart.myCortexEmu.getN();
flags[1] = myCart.myCortexEmu.getZ();
flags[2] = myCart.myCortexEmu.getC();
flags[3] = myCart.myCortexEmu.getV();
BoolArray flagsChanged(4);
for (uInt8 i = 0; i < 4; i++) flagsChanged[i] = flags[i] != myFlagValues[i];
myFlagValues = flags;
myFlags->setState(flags, flagsChanged);
}

View File

@ -0,0 +1,49 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2024 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef CART_ELF_INFO_WIDGET_HXX
#define CART_ELF_INFO_WIDGET_HXX
#include "CartDebugWidget.hxx"
class CartridgeELF;
class DataGridWidget;
class ToggleBitWidget;
class CartridgeELFStateWidget : public CartDebugWidget {
public:
CartridgeELFStateWidget(GuiObject* boss, const GUI::Font& lfont,
const GUI::Font& nfont,
int x, int y, int w, int h,
CartridgeELF& cart);
~CartridgeELFStateWidget() override = default;
private:
void initialize();
void loadConfig() override;
private:
CartridgeELF& myCart;
BoolArray myFlagValues;
DataGridWidget* myArmRegisters{nullptr};
ToggleBitWidget* myFlags{nullptr};
};
#endif // CART_ELF_INFO_WIDGET_HXX

View File

@ -49,6 +49,7 @@ MODULE_OBJS := \
src/debugger/gui/CartFEWidget.o \
src/debugger/gui/CartGLWidget.o \
src/debugger/gui/CartELFWidget.o \
src/debugger/gui/CartELFStateWidget.o \
src/debugger/gui/CartJANEWidget.o \
src/debugger/gui/CartMDMWidget.o \
src/debugger/gui/CartRamWidget.o \

View File

@ -28,6 +28,7 @@
#ifdef DEBUGGER_SUPPORT
#include "CartELFWidget.hxx"
#include "CartELFStateWidget.hxx"
#endif
#include "CartELF.hxx"
@ -90,7 +91,7 @@ namespace {
stream
<< sections[i].name
<< " @ 0x"<< std::setw(8)
<< " @ 0x" << std::setw(8)
<< (relocatedSections[i]->offset + linker.getSegmentBase(relocatedSections[i]->segment))
<< " size 0x" << std::setw(8) << sections[i].size << '\n';
}
@ -379,10 +380,18 @@ uInt8 CartridgeELF::overdrivePoke(uInt16 address, uInt8 value)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartDebugWidget* CartridgeELF::debugWidget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h
) {
return new CartridgeELFStateWidget(boss, lfont, nfont, x, y, w, h, *this);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartDebugWidget* CartridgeELF::infoWidget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h
) {
return new CartridgeELFWidget(boss, lfont, nfont, x, y, w, h, *this);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string CartridgeELF::getDebugLog() const
{
ostringstream s;
@ -390,7 +399,10 @@ string CartridgeELF::getDebugLog() const
s
<< "ARM entrypoint: 0x"
<< std::hex << std::setw(8) << std::setfill('0') << myArmEntrypoint
<< std::dec << '\n';
<< '\n'
<< "vsclib stubs @ 0x" << std::setw(8) << ADDR_STUB_BASE
<< " size 0x" << std::setw(8) << STUB_SIZE << "\n"
<< std::dec;
dumpLinkage(myElfParser, *myLinker, s);

View File

@ -30,11 +30,13 @@ class ElfLinker;
#ifdef DEBUGGER_SUPPORT
class CartridgeELFWidget;
class CartridgeELFStateWidget;
#endif
class CartridgeELF: public Cartridge {
#ifdef DEBUGGER_SUPPORT
friend CartridgeELFWidget;
friend CartridgeELFStateWidget;
#endif
public:
@ -84,6 +86,10 @@ class CartridgeELF: public Cartridge {
CartDebugWidget* debugWidget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h
) override;
CartDebugWidget* infoWidget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, int x, int y, int w, int h
) override;
#endif
public:

View File

@ -773,11 +773,36 @@ CortexM0& CortexM0::setRegister(uInt8 regno, uInt32 value)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 CortexM0::getRegister(uInt32 regno)
uInt32 CortexM0::getRegister(uInt32 regno) const
{
return read_register(regno);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CortexM0::getN() const
{
return znFlags & 0x80000000;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CortexM0::getZ() const
{
return znFlags == 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CortexM0::getC() const
{
return cFlag;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CortexM0::getV() const
{
return vFlag;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 CortexM0::decodeInstructionWord(uInt16 instructionWord)
{

View File

@ -127,7 +127,12 @@ class CortexM0: public Serializable
CortexM0& reset();
CortexM0& setPc(uInt32 pc);
CortexM0& setRegister(uInt8 regno, uInt32 value);
uInt32 getRegister(uInt32 regno);
uInt32 getRegister(uInt32 regno) const;
bool getN() const;
bool getZ() const;
bool getC() const;
bool getV() const;
static uInt8 decodeInstructionWord(uInt16 instructionWord);

View File

@ -548,6 +548,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-NoDebugger|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\debugger\gui\CartELFWidget.cxx" />
<ClCompile Include="..\..\debugger\gui\CartELFStateWidget.cxx" />
<ClCompile Include="..\..\debugger\gui\CartEnhancedWidget.cxx">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-NoDebugger|x64'">true</ExcludedFromBuild>
</ClCompile>
@ -1521,6 +1522,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-NoDebugger|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\..\debugger\gui\CartELFWidget.hxx" />
<ClInclude Include="..\..\debugger\gui\CartELFStateWidget.hxx" />
<ClInclude Include="..\..\debugger\gui\CartEnhancedWidget.hxx">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug-NoDebugger|x64'">true</ExcludedFromBuild>
</ClInclude>

View File

@ -1266,6 +1266,9 @@
<ClCompile Include="..\..\debugger\gui\CartELFWidget.cxx">
<Filter>Source Files\debugger\gui</Filter>
</ClCompile>
<ClCompile Include="..\..\debugger\gui\CartELFStateWidget.cxx">
<Filter>Source Files\debugger\gui</Filter>
</ClCompile>
<ClCompile Include="..\..\emucore\CortexM0.cxx">
<Filter>Source Files\emucore</Filter>
</ClCompile>
@ -2564,6 +2567,9 @@
<ClInclude Include="..\..\debugger\gui\CartELFWidget.hxx">
<Filter>Header Files\debugger\gui</Filter>
</ClInclude>
<ClInclude Include="..\..\debugger\gui\CartELFStateWidget.hxx">
<Filter>Header Files\debugger\gui</Filter>
</ClInclude>
<ClInclude Include="..\..\emucore\elf\BusTransactionQueue.hxx">
<Filter>Header Files\emucore\elf</Filter>
</ClInclude>