Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / MMU.h
blob78c9f87d17e16c685e053ab833af196666235d9c
1 #ifndef AVR_MMU_H
2 #define AVR_MMU_H
4 #include "Memory.h"
5 #include "SRam.h"
6 #include "Registers.h"
8 namespace avr {
9 class ERam;
11 /**
12 * @author Tom Haber
13 * @date Apr 23, 2008
14 * @brief Memory Mapping Unit
16 * Manages address decoding for memory accesses: maps the different
17 * regions to the correct classes.
19 class MMU {
20 public:
21 MMU(unsigned int ioSpaceSize, unsigned int ramSize, ERam *eram = 0);
22 ~MMU();
24 public:
25 void addIOReg(unsigned int address,
26 const std::string & name, byte initial = 0);
27 const Register & getR(int r) const { return R[r]; }
29 Register & reg(int r);
30 const Register & reg(int r) const;
32 byte statusReg() const;
34 IORegister & getIoreg(unsigned int offset);
35 const IORegister & getIoreg(unsigned int offset) const;
36 IORegister *getIoreg(const std::string & name);
38 void reset();
40 public:
41 unsigned int ioregs() const { return regs.size(); }
42 const std::string & registerName(byte addr) const;
44 public:
45 /**
46 * Checks whether an offset is associated with a register
48 bool isRegister(unsigned int offset) const;
50 /**
51 * Reads a single bytes of raw data from memory at
52 * offset \e offset.
54 * \exception AccessViolation { When the data requested is
55 * not available, this exception is thrown }
57 byte readByte(unsigned int offset) const;
59 /**
60 * Reads a word of raw data from memory starting at
61 * offset \e offset.
63 * \exception AccessViolation { When the data requested is
64 * not available, this exception is thrown }
66 word readWord(unsigned int offset) const;
68 /**
69 * Reads a single bytes of raw data from memory at
70 * offset \e offset.
72 * \exception AccessViolation { When the data requested is
73 * not available, this exception is thrown }
75 void writeByte(unsigned int offset, byte val);
77 /**
78 * Reads a word of raw data from memory starting at
79 * offset \e offset.
81 * \exception AccessViolation { When the data requested is
82 * not available, this exception is thrown }
84 void writeWord(unsigned int offset, word val);
86 const unsigned char *readRam(unsigned int offset, unsigned int size) const;
87 void writeRam(unsigned char *data, unsigned int offset, unsigned int size);
89 public:
90 static const unsigned int registerSpaceSize = 32;
92 private:
93 Register R[registerSpaceSize];
95 IORegisters regs;
96 SRam sram;
97 ERam *eram;
100 inline IORegister & MMU::getIoreg(unsigned int offset) {
101 return regs.getIoreg(offset);
104 inline const IORegister & MMU::getIoreg(unsigned int offset) const {
105 return regs.getIoreg(offset);
108 inline IORegister *MMU::getIoreg(const std::string & name) {
109 return regs.getIoreg(name);
112 inline byte MMU::statusReg() const {
113 return regs.getIoreg("SREG")->getAddress() - registerSpaceSize;
116 inline void MMU::reset() {
117 for(unsigned int i = 0; i < registerSpaceSize; ++i)
118 R[i] = 0;
119 regs.reset();
122 inline bool MMU::isRegister(unsigned int offset) const {
123 return offset < registerSpaceSize + regs.size();
128 #endif /*AVR_MMU_H_*/