Skip to content

Commit

Permalink
Lots of refactoring of ARM debug stuff, moving it to base class
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Jul 25, 2018
1 parent eed3e38 commit 7669f26
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 146 deletions.
45 changes: 29 additions & 16 deletions ARM7TDMISProcessor.cpp
Expand Up @@ -52,7 +52,8 @@ ARM7TDMISProcessor::ARM7TDMISProcessor(
unsigned int idcode,
JtagInterface* iface,
size_t pos)
: ARMDevice(idcode, iface, pos, 4)
: DebuggableDevice(NULL)
, ARMDevice(idcode, iface, pos, 4)
, m_rev(rev)
{
m_selectedChain = 255;
Expand Down Expand Up @@ -241,17 +242,16 @@ void ARM7TDMISProcessor::PrintIDRegister(ARM7TDMISDebugIDRegister did)
LogVerbose("%d watchpoints\n", did.bits.wpoints_minus_one + 1);
}
*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// System memory access
// Debugging

uint32_t ARM7TDMISProcessor::ReadMemory(uint32_t /*addr*/)
void ARM7TDMISProcessor::PrintRegisters()
{
LogError("ARM7TDMISProcessor::ReadMemory unimplemented\n");
return 0;
//return m_ap->GetDebugPort()->ReadMemory(addr);
throw JtagExceptionWrapper(
"Register printing not implemented for this CPU yet",
"");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Debugging

/**
@brief Checks if the CPU is halted due to a fatal error
Expand Down Expand Up @@ -351,14 +351,21 @@ void ARM7TDMISProcessor::DumpRegisters()
LogNotice("%10s: %08x\n", GetRegisterName(reg), ReadCPURegister(reg));
}*/

uint32_t ARM7TDMISProcessor::ReadMemory(uint32_t addr)
{
throw JtagExceptionWrapper(
"Memory access not implemented for this CPU yet",
"");

return 0;
}

/**
@brief Halts the CPU and enters debug state
See ARMv7-M arch manual C1-6
*/
/*(
void ARM7TDMISProcessor::EnterDebugState()
void ARM7TDMISProcessor::DebugHalt()
{
/*
LogTrace("Halting CPU to enter debug state...\n");
LogIndenter li;
Expand All @@ -375,12 +382,16 @@ void ARM7TDMISProcessor::EnterDebugState()
break;
//LogTrace("DHCSR = %08x\n", dhcsr);
usleep(1000);
}
}*/
throw JtagExceptionWrapper(
"Debug halt/resume not implemented for this CPU yet",
"");
}


void ARM7TDMISProcessor::ExitDebugState()
void ARM7TDMISProcessor::DebugResume()
{
/*
//Request a resume by writing to DBGDRCR.RRQ
LogTrace("Restarting CPU...\n");
LogIndenter li;
Expand All @@ -394,9 +405,11 @@ void ARM7TDMISProcessor::ExitDebugState()
if(v & 2)
break;
usleep(1000);
}
}*/
throw JtagExceptionWrapper(
"Debug halt/resume not implemented for this CPU yet",
"");
}
*/

bool ARM7TDMISProcessor::IsProgrammed()
{
Expand Down
18 changes: 7 additions & 11 deletions ARM7TDMISProcessor.h
Expand Up @@ -111,9 +111,6 @@ class ARM7TDMISProcessor : public DebuggableDevice

virtual std::string GetDescription();
virtual void PrintInfo();
/*
void DumpRegisters();
*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ProgrammableDevice
Expand All @@ -130,11 +127,6 @@ class ARM7TDMISProcessor : public DebuggableDevice
unsigned int base_address = 0,
std::string prog_image = "");

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Memory access via the default (AHB) MEM-AP

virtual uint32_t ReadMemory(uint32_t addr);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CPU register access
/*
Expand All @@ -144,12 +136,16 @@ class ARM7TDMISProcessor : public DebuggableDevice
protected:
//void PrintIDRegister(ARM7TDMISDebugIDRegister did);
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Debugger control

void EnterDebugState();
void ExitDebugState();
*/
virtual void DebugHalt();
virtual void DebugResume();

virtual void PrintRegisters();

virtual uint32_t ReadMemory(uint32_t addr);

/*
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 6 additions & 2 deletions ARMCortexA57.cpp
Expand Up @@ -46,8 +46,12 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

ARMCortexA57::ARMCortexA57(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg)
: ARMv8Processor(ap, address, idreg)
ARMCortexA57::ARMCortexA57(
DebuggerInterface* iface,
ARMDebugMemAccessPort* ap,
uint32_t address,
ARMDebugPeripheralIDRegisterBits idreg)
: ARMv8Processor(iface, ap, address, idreg)
{

}
Expand Down
2 changes: 1 addition & 1 deletion ARMCortexA57.h
Expand Up @@ -44,7 +44,7 @@
class ARMCortexA57 : public ARMv8Processor
{
public:
ARMCortexA57(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
ARMCortexA57(DebuggerInterface* iface, ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
virtual ~ARMCortexA57();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 15 additions & 4 deletions ARMCortexA9.cpp
Expand Up @@ -46,8 +46,12 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

ARMCortexA9::ARMCortexA9(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg)
: ARMv7Processor(ap, address, idreg)
ARMCortexA9::ARMCortexA9(
DebuggerInterface* iface,
ARMDebugMemAccessPort* ap,
uint32_t address,
ARMDebugPeripheralIDRegisterBits idreg)
: ARMv7Processor(iface, ap, address, idreg)
{

}
Expand Down Expand Up @@ -107,8 +111,15 @@ void ARMCortexA9::PrintInfo()
//Read L0_SEL

//Read the PC and dump the instruction at that address
uint32_t pc = SampleProgramCounter();
LogVerbose("PC = %08x\n", pc);
try
{
uint32_t pc = SampleProgramCounter();
LogVerbose("PC = %08x\n", pc);
}
catch(const JtagException& e)
{
LogVerbose("Error reading PC value\n");
}
//uint32_t value = ReadMemory(0xE0000000);//m_ap->ReadWord(0x80000000); //ReadMemory(0xFC000000);

//LogDebug(" value = %08x\n", value);
Expand Down
2 changes: 1 addition & 1 deletion ARMCortexA9.h
Expand Up @@ -44,7 +44,7 @@
class ARMCortexA9 : public ARMv7Processor
{
public:
ARMCortexA9(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
ARMCortexA9(DebuggerInterface* iface, ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
virtual ~ARMCortexA9();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions ARMCortexM4.cpp
Expand Up @@ -46,8 +46,8 @@ using namespace std;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

ARMCortexM4::ARMCortexM4(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg)
: ARMv7MProcessor(ap, address, idreg)
ARMCortexM4::ARMCortexM4(DebuggerInterface* iface, ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg)
: ARMv7MProcessor(iface, ap, address, idreg)
{
//LogTrace("Found ARM Cortex-M4 at %08x, probing...\n", address);

Expand Down
2 changes: 1 addition & 1 deletion ARMCortexM4.h
Expand Up @@ -44,7 +44,7 @@
class ARMCortexM4 : public ARMv7MProcessor
{
public:
ARMCortexM4(ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
ARMCortexM4(DebuggerInterface* iface, ARMDebugMemAccessPort* ap, uint32_t address, ARMDebugPeripheralIDRegisterBits idreg);
virtual ~ARMCortexM4();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
26 changes: 13 additions & 13 deletions ARMDebugMemAccessPort.cpp
Expand Up @@ -112,19 +112,19 @@ void ARMDebugMemAccessPort::PrintStatusRegister()
{
ARMDebugMemAPControlStatusWord csw = GetStatusRegister();
LogIndenter li;
LogDebug("Status register for AP %u:\n", m_apnum);
LogNotice("Status register for AP %u:\n", m_apnum);
LogIndenter li2;
if(csw.bits.size >= ACCESS_INVALID)
LogDebug("Size : UNDEFINED\n");
LogNotice("Size : UNDEFINED\n");
else
LogDebug("Size : %s\n", g_cswLenNames[csw.bits.size]);
LogDebug("Auto inc : %u\n", csw.bits.auto_increment);
LogDebug("Enable : %u\n", csw.bits.enable);
LogDebug("Busy : %u\n", csw.bits.busy);
LogDebug("Mode : %u\n", csw.bits.mode);
LogDebug("Secure debug : %u\n", csw.bits.secure_priv_debug);
LogDebug("Bus protection : %u\n", csw.bits.bus_protect);
LogDebug("Nonsecure transfer : %u\n", csw.bits.nonsecure_transfer);
LogNotice("Size : %s\n", g_cswLenNames[csw.bits.size]);
LogNotice("Auto inc : %u\n", csw.bits.auto_increment);
LogNotice("Enable : %u\n", csw.bits.enable);
LogNotice("Busy : %u\n", csw.bits.busy);
LogNotice("Mode : %u\n", csw.bits.mode);
LogNotice("Secure debug : %u\n", csw.bits.secure_priv_debug);
LogNotice("Bus protection : %u\n", csw.bits.bus_protect);
LogNotice("Nonsecure transfer : %u\n", csw.bits.nonsecure_transfer);
}

string ARMDebugMemAccessPort::GetDescription()
Expand Down Expand Up @@ -406,7 +406,7 @@ void ARMDebugMemAccessPort::ProcessDebugBlock(uint32_t base_address, uint32_t id
//Cortex-M4 SCS
case 0x00c:
{
ARMCortexM4* cortex = new ARMCortexM4(this, base_address, reg.bits);
ARMCortexM4* cortex = new ARMCortexM4(m_dp, this, base_address, reg.bits);
m_dp->AddTarget(cortex);
m_debugDevices.push_back(cortex);
}
Expand All @@ -415,7 +415,7 @@ void ARMDebugMemAccessPort::ProcessDebugBlock(uint32_t base_address, uint32_t id
//Cortex-A57
case 0xd07:
{
ARMCortexA57* cortex = new ARMCortexA57(this, base_address, reg.bits);
ARMCortexA57* cortex = new ARMCortexA57(m_dp, this, base_address, reg.bits);
m_dp->AddTarget(cortex);
m_debugDevices.push_back(cortex);
}
Expand All @@ -424,7 +424,7 @@ void ARMDebugMemAccessPort::ProcessDebugBlock(uint32_t base_address, uint32_t id
//Cortex-A9
case 0xC09:
{
ARMCortexA9* cortex = new ARMCortexA9(this, base_address, reg.bits);
ARMCortexA9* cortex = new ARMCortexA9(m_dp, this, base_address, reg.bits);
m_dp->AddTarget(cortex);
m_debugDevices.push_back(cortex);
}
Expand Down

0 comments on commit 7669f26

Please sign in to comment.