Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Core.h
blob700d5374f10a4b60b96830455d1330b1e1d982b7
1 #ifndef AVR_CORE_H
2 #define AVR_CORE_H
4 #include "Types.h"
5 #include "Flash.h"
6 #include "MMU.h"
7 #include "Stack.h"
8 #include "Decoder.h"
10 #include <list>
12 namespace avr {
14 class ERam;
15 class Bus;
16 class Analyzer;
17 class DebugInterface;
19 /**
20 * @author Tom Haber
21 * @date Apr 23, 2008
22 * @brief The core of the AVR chip.
24 * This is the interpreter of the instructions and it contains the state.
26 class Core {
27 public:
28 Core(Bus & bus, unsigned int ioSpaceSize, unsigned int ramSize,
29 unsigned int flashSize, unsigned int pageSize,
30 word stackMask, int pcBytes = 2, ERam *eram = 0);
31 ~Core();
33 public:
34 void init();
35 void loadFlash(unsigned char *data, unsigned int offset, unsigned int size);
37 /**
38 * Resets the core
40 void reset(unsigned int type);
42 /**
43 * Executes a single cpu cycle.
45 bool step();
47 void setDebugInterface(DebugInterface *dbgi);
48 bool isStopped() const { return stoppedMode; }
50 public:
51 void addIOReg(unsigned int address,
52 const std::string & name, byte initial = 0);
53 void addAnalyzer(Analyzer *analyzer);
54 const Register & getR(int r) const { return mmu.getR(r); }
55 IORegister & getIoreg(unsigned int offset);
56 IORegister *getIoreg(const std::string & name);
58 public:
59 byte readRegister(unsigned int r) const;
60 void writeRegister(unsigned int r, byte val);
61 byte readStatus();
62 void writeStatus(byte val);
63 byte readIORegister(unsigned int r);
64 void writeIORegister(unsigned int r, byte val);
65 byte readByte(unsigned int addr) const;
66 void writeByte(unsigned int addr, byte val);
67 byte readFlash(unsigned int addr) const;
68 int writeFlash(unsigned int addr, word data);
69 word fetchOperand();
71 public:
72 int pcBytes() const { return pc_bytes; }
73 void push(byte val);
74 byte pop();
75 void jump(sbyte offset, bool push = false);
76 int skip();
77 void call(dword address, bool push = true);
78 void ret(bool interrupt = false);
79 void sleep();
80 void systemBreak();
82 private:
83 bool invokeInterrupt();
85 private:
86 MMU mmu;
87 Flash flash;
88 Stack stack;
89 Decoder decoder;
90 Bus & bus;
92 private:
93 unsigned char SReg;
94 dword PC;
95 int pc_bytes;
96 bool stoppedMode;
98 bool justReturnedFromInterrupt;
100 enum SleepMode {
101 SLEEP_MODE_IDLE = 0,
102 SLEEP_MODE_ADC_REDUX = 1,
103 SLEEP_MODE_PWR_DOWN = 2,
104 SLEEP_MODE_PWR_SAVE = 3,
105 SLEEP_MODE_reserved1 = 4,
106 SLEEP_MODE_reserved2 = 5,
107 SLEEP_MODE_STANDBY = 6,
108 SLEEP_MODE_EXT_STANDBY = 7,
109 SLEEP_MODE_NONE = 8
110 } sleepMode;
112 private:
113 std::list<Analyzer*> analyzers;
115 private:
116 DebugInterface *dbgi;
117 int cpuCycles;
119 friend class DebugInterface;
122 inline void Core::loadFlash(unsigned char *data, unsigned int offset, unsigned int size) {
123 flash.write(offset, data, size);
126 inline void Core::addAnalyzer(Analyzer *analyzer) {
127 analyzers.push_back( analyzer );
130 inline void Core::setDebugInterface(DebugInterface *dbgi) {
131 this->dbgi = dbgi;
134 inline void Core::addIOReg(unsigned int address,
135 const std::string & name, byte initial) {
136 mmu.addIOReg(address, name, initial);
139 inline IORegister & Core::getIoreg(unsigned int offset) {
140 return mmu.getIoreg(offset);
143 inline IORegister *Core::getIoreg(const std::string & name) {
144 return mmu.getIoreg(name);
147 inline byte Core::readStatus() {
148 return readIORegister(SReg);
151 inline void Core::writeStatus(byte val) {
152 writeIORegister(SReg, val);
157 #endif /*AVR_CORE_H*/