2 * avr-sim: An atmel AVR simulator
3 * Copyright (C) 2008 Tom Haber
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "DebugInterface.h"
22 #include "Instruction.h"
23 #include "AccessViolation.h"
24 #include "ImplementationException.h"
31 DebugInterface::DebugInterface(Device
& dev
, Core
& core
)
32 : dev(dev
), core(core
), breaked(false) {
33 core
.setDebugInterface(this);
36 DebugInterface::~DebugInterface() {
37 core
.setDebugInterface(0);
40 byte
DebugInterface::reg(int reg
) const {
41 return core
.readRegister(reg
);
44 byte
DebugInterface::status() const {
45 return core
.readStatus();
48 word
DebugInterface::stackPointer() const {
49 return core
.stack
.getSP();
52 dword
DebugInterface::programCounter() const {
53 return (core
.PC
<< 1);
56 const unsigned char *DebugInterface::readRam(
57 unsigned int offset
, unsigned int size
) const {
59 return mmu
.readRam(offset
, size
);
62 const unsigned char *DebugInterface::readFlash(
63 unsigned int offset
, unsigned int size
) const {
65 return core
.flash
.read( offset
, size
);
68 void DebugInterface::writeRam(unsigned char *data
,
69 unsigned int offset
, unsigned int size
) {
71 mmu
.writeRam(data
, offset
, size
);
74 void DebugInterface::writeFlash(unsigned char *data
,
75 unsigned int offset
, unsigned int size
) {
76 core
.loadFlash(data
, offset
, size
);
79 const unsigned char *DebugInterface::readEeprom(
80 unsigned int /*offset*/, unsigned int /*size*/) const {
81 throw util::ImplementationException( "readEeprom: not yet implemented" );
84 void DebugInterface::writeEeprom(unsigned char * /*data*/,
85 unsigned int /*offset*/, unsigned int /*size*/) {
86 throw util::ImplementationException( "writeEeprom: not yet implemented" );
89 void DebugInterface::setReg(int reg
, byte val
) {
90 core
.writeRegister(reg
, val
);
93 void DebugInterface::setStatus(byte val
) {
94 core
.writeStatus( val
);
97 void DebugInterface::setStackPointer(word val
) {
98 core
.stack
.setSP(val
);
101 void DebugInterface::setProgramCounter(dword val
) {
105 void DebugInterface::insertBreak(dword addr
) {
106 breakPoints
.push_back( addr
);
109 void DebugInterface::removeBreak(dword addr
) {
110 std::remove(breakPoints
.begin(), breakPoints
.end(), addr
);
113 void DebugInterface::deleteAllBreakpoints() {
114 breakPoints
.erase(breakPoints
.begin(), breakPoints
.end());
117 bool DebugInterface::checkBreak(dword addr
) {
118 if( breakPoints
.end() != std::find(breakPoints
.begin(), breakPoints
.end(), addr
)) {
131 bool DebugInterface::stepDone() const {
132 return (core
.cpuCycles
== 0);
135 const std::string
& DebugInterface::registerName(byte addr
) const {
136 return mmu
.registerName(addr
);
139 void DebugInterface::trace(std::ostream
& ostr
, dword addr
) {
140 word opcode
= core
.flash
.readWord( addr
);
141 Instruction
& instr
= core
.decoder
.decode(opcode
);
142 instr
.trace(&core
, ostr
);