Bug fix: check if vm exists
[avr-sim.git] / Memory.h
blob8bc3f17d30b0418dcae57dfeb439924a96d5b09f
1 #ifndef AVR_MEMORY_H
2 #define AVR_MEMORY_H
4 #include "Types.h"
6 namespace avr {
8 /**
9 * \author Tom Haber
10 * \date 21 April 2008
12 * This class is an abstraction of all types of memory
13 * available on the chip: SRAM, ERAM, Flash.
15 * It allows read and write operations and maintains
16 * the raw data associated with the memory.
18 class Memory {
19 public:
20 Memory(unsigned int size);
21 virtual ~Memory();
23 public:
24 /**
25 * Reads \e size bytes of raw data from memory starting at
26 * offset \e offset. It returns a pointer to this data.
28 * \exception RuntimeException { When the data requested is
29 * not available, this exception is thrown }
31 const unsigned char *read(unsigned int offset, unsigned int size = 1) const;
33 /**
34 * Reads a single bytes of raw data from memory at
35 * offset \e offset.
37 * \exception RuntimeException { When the data requested is
38 * not available, this exception is thrown }
40 byte readByte(unsigned int offset) const;
42 /**
43 * Reads a word of raw data from memory starting at
44 * offset \e offset.
46 * \exception RuntimeException { When the data requested is
47 * not available, this exception is thrown }
49 word readWord(unsigned int offset) const;
51 /**
52 * Write \e size bytes of raw data to memory starting at
53 * offset \e offset. The data to be written is passed via
54 * the \e block variable.
56 * \exception RuntimeException { When the write exceeds
57 * amount of memory, this exception is thrown }
59 virtual void write(unsigned int offset, unsigned char *block, unsigned int size = 1);
61 /**
62 * Fill the entire memory chunk with value \e val.
64 void fill(unsigned char val);
66 /**
67 * \returns the size of the memory chunk.
69 unsigned int size() const;
71 /**
72 * Dump the memory content to disk
74 void dump(const char *fname) const;
76 private:
77 unsigned char *mem;
78 unsigned int siz;
81 inline unsigned int Memory::size() const {
82 return siz;
86 #endif /*AVR_MEMORY_H*/