14 * @brief Memory Mapping Unit
16 * Manages address decoding for memory accesses: maps the different
17 * regions to the correct classes.
21 MMU(unsigned int ioSpaceSize
, unsigned int ramSize
, ERam
*eram
= 0);
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
);
41 unsigned int ioregs() const { return regs
.size(); }
42 const std::string
& registerName(byte addr
) const;
46 * Checks whether an offset is associated with a register
48 bool isRegister(unsigned int offset
) const;
51 * Reads a single bytes of raw data from memory at
54 * \exception AccessViolation { When the data requested is
55 * not available, this exception is thrown }
57 byte
readByte(unsigned int offset
) const;
60 * Reads a word of raw data from memory starting at
63 * \exception AccessViolation { When the data requested is
64 * not available, this exception is thrown }
66 word
readWord(unsigned int offset
) const;
69 * Reads a single bytes of raw data from memory at
72 * \exception AccessViolation { When the data requested is
73 * not available, this exception is thrown }
75 void writeByte(unsigned int offset
, byte val
);
78 * Reads a word of raw data from memory starting at
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
);
90 static const unsigned int registerSpaceSize
= 32;
93 Register R
[registerSpaceSize
];
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
)
122 inline bool MMU::isRegister(unsigned int offset
) const {
123 return offset
< registerSpaceSize
+ regs
.size();
128 #endif /*AVR_MMU_H_*/