Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / DebugInterface.cpp
blobe80b31b22420a70e9bcc99457ee8158ff959f629
1 /*
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"
20 #include "Core.h"
21 #include "Device.h"
22 #include "Instruction.h"
23 #include "AccessViolation.h"
24 #include "ImplementationException.h"
26 #include <algorithm>
28 #define mmu core.mmu
30 namespace avr {
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 bool DebugInterface::isRegister(unsigned int offset) const {
57 return mmu.isRegister(offset);
60 byte DebugInterface::readRegister(unsigned int offset) const {
61 return mmu.readByte(offset);
64 const unsigned char *DebugInterface::readRam(
65 unsigned int offset, unsigned int size) const {
67 return mmu.readRam(offset, size);
70 const unsigned char *DebugInterface::readFlash(
71 unsigned int offset, unsigned int size) const {
73 return core.flash.read( offset, size );
76 void DebugInterface::writeRam(unsigned char *data,
77 unsigned int offset, unsigned int size) {
79 mmu.writeRam(data, offset, size);
82 void DebugInterface::writeFlash(unsigned char *data,
83 unsigned int offset, unsigned int size) {
84 core.loadFlash(data, offset, size);
87 const unsigned char *DebugInterface::readEeprom(
88 unsigned int /*offset*/, unsigned int /*size*/) const {
89 throw util::ImplementationException( "readEeprom: not yet implemented" );
92 void DebugInterface::writeEeprom(unsigned char * /*data*/,
93 unsigned int /*offset*/, unsigned int /*size*/) {
94 throw util::ImplementationException( "writeEeprom: not yet implemented" );
97 void DebugInterface::setReg(int reg, byte val) {
98 core.writeRegister(reg, val);
101 void DebugInterface::setStatus(byte val) {
102 core.writeStatus( val );
105 void DebugInterface::setStackPointer(word val) {
106 core.stack.setSP(val);
109 void DebugInterface::setProgramCounter(dword val) {
110 core.PC = val >> 1;
113 void DebugInterface::insertBreak(dword addr) {
114 breakPoints.push_back( addr );
117 void DebugInterface::removeBreak(dword addr) {
118 std::remove(breakPoints.begin(), breakPoints.end(), addr);
121 void DebugInterface::deleteAllBreakpoints() {
122 breakPoints.erase(breakPoints.begin(), breakPoints.end());
125 bool DebugInterface::checkBreak(dword addr) {
126 if( breakPoints.end() != std::find(breakPoints.begin(), breakPoints.end(), addr)) {
127 if( ! breaked ) {
128 breaked = true;
129 } else {
130 breaked = false;
132 } else {
133 breaked = false;
136 return breaked;
139 bool DebugInterface::stepDone() const {
140 return (core.cpuCycles == 0);
143 const std::string & DebugInterface::registerName(byte addr) const {
144 return mmu.registerName(addr);
147 void DebugInterface::trace(std::ostream & ostr, dword addr) {
148 word opcode = core.flash.readWord( addr );
149 Instruction & instr = core.decoder.decode(opcode);
150 instr.trace(&core, ostr);