1 #include "DebugInterface.h"
5 #include "Instruction.h"
6 #include "AccessViolation.h"
7 #include "ImplementationException.h"
12 DebugInterface::DebugInterface(Device
& dev
, Core
& core
)
13 : dev(dev
), core(core
), breaked(false) {
14 core
.setDebugInterface(this);
17 DebugInterface::~DebugInterface() {
18 core
.setDebugInterface(0);
21 byte
DebugInterface::reg(int reg
) const {
22 return core
.readRegister(reg
);
25 byte
DebugInterface::status() const {
26 return core
.readStatus();
29 word
DebugInterface::stackPointer() const {
30 return core
.stack
.getSP();
33 dword
DebugInterface::programCounter() const {
34 return (core
.PC
<< 1);
37 const unsigned char *DebugInterface::readRam(
38 unsigned int offset
, unsigned int size
) const {
40 if( offset
< core
.registerSpaceSize
+ core
.regs
.size() )
41 throw AccessViolation("readRam: Tried to read to register area");
43 offset
-= core
.registerSpaceSize
+ core
.regs
.size();
44 return core
.sram
.read(offset
, size
);
47 const unsigned char *DebugInterface::readFlash(
48 unsigned int offset
, unsigned int size
) const {
50 return core
.flash
.read( offset
, size
);
53 void DebugInterface::writeRam(unsigned char *data
,
54 unsigned int offset
, unsigned int size
) {
56 if( offset
< core
.registerSpaceSize
+ core
.regs
.size() )
57 throw AccessViolation("writeRam: Tried to write to register area");
59 offset
-= core
.registerSpaceSize
+ core
.regs
.size();
60 core
.sram
.write(offset
, data
, size
);
63 void DebugInterface::writeFlash(unsigned char *data
,
64 unsigned int offset
, unsigned int size
) {
65 core
.loadFlash(data
, offset
, size
);
68 const unsigned char *DebugInterface::readEeprom(
69 unsigned int offset
, unsigned int size
) const {
70 throw util::ImplementationException( "readEeprom: not yet implemented" );
73 void DebugInterface::writeEeprom(unsigned char *data
,
74 unsigned int offset
, unsigned int size
) {
75 throw util::ImplementationException( "writeEeprom: not yet implemented" );
78 void DebugInterface::setReg(int reg
, byte val
) {
79 core
.writeRegister(reg
, val
);
82 void DebugInterface::setStatus(byte val
) {
83 core
.writeStatus( val
);
86 void DebugInterface::setStackPointer(word val
) {
87 core
.stack
.setSP(val
);
90 void DebugInterface::setProgramCounter(dword val
) {
94 void DebugInterface::insertBreak(dword addr
) {
95 breakPoints
.push_back( addr
);
98 void DebugInterface::removeBreak(dword addr
) {
99 std::remove(breakPoints
.begin(), breakPoints
.end(), addr
);
102 void DebugInterface::deleteAllBreakpoints() {
103 breakPoints
.erase(breakPoints
.begin(), breakPoints
.end());
106 bool DebugInterface::checkBreak(dword addr
) {
107 if( breakPoints
.end() != std::find(breakPoints
.begin(), breakPoints
.end(), addr
)) {
109 Trace::instance().breakpoint(addr
);
121 bool DebugInterface::stepDone() const {
122 return (core
.cpuCycles
== 0);
125 const std::string
& DebugInterface::registerName(byte addr
) const {
126 if( addr
< core
.registerSpaceSize
)
127 return core
.getR(addr
).getName();
129 return core
.getIoreg(addr
- core
.registerSpaceSize
).getName();
132 void DebugInterface::trace(std::ostream
& ostr
, dword addr
) {
133 word opcode
= core
.flash
.readWord( addr
);
134 Instruction
& instr
= core
.decoder
.decode(opcode
);
135 instr
.trace(&core
, ostr
);