OpenASIP 2.2
Loading...
Searching...
No Matches
DirectAccessMemory.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file DirectAccessMemory.cc
26 *
27 * Definition of DirectAccessMemory class.
28 *
29 * @author Pekka Jääskeläinen 2007 (pjaaskel-no.spam-cs.tut.fi)
30 * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <string>
35#include <utility>
36#include <limits>
37
38#include "DirectAccessMemory.hh"
39#include "MemoryContents.hh"
40#include "Conversion.hh"
41#include "Application.hh"
42
43using std::string;
44
45
46/**
47 * Constructor. Create a model for a given memory.
48 *
49 * The created memory model is empty. No data is allocated for its contents.
50 *
51 * @param start First address of the memory.
52 * @param end Last address of the memory.
53 * @param MAUSize Bit width of the minimum addressable unit of the memory.
54 */
56 ULongWord start, ULongWord end, Word MAUSize, bool littleEndian) :
57 Memory(start, end, MAUSize, littleEndian),
58 start_(start), end_(end), MAUSize_(MAUSize),
59 MAUSize3_(MAUSize_ * 3), MAUSize2_(MAUSize_ * 2) {
60
61 /// @note In C++, when shifting more bits than there are in integer, the
62 /// result is undefined. Thus, we just set the mask to ~0 in this case.
63 /// We should probably give user a warning if MAUSize is larger than
64 /// the integer size!
65 if (MAUSize_ >= static_cast<Word>(std::numeric_limits<Word>::digits)) {
66 mask_ = ~0u;
67 } else {
68 mask_ = ~(~0u << MAUSize_);
69 }
70
72}
73
74
75/**
76 * Destructor.
77 */
82
83/**
84 * Fills the whole memory with zeros.
85 *
86 * This is needed due to some buggy simulated programs which expect
87 * uninitialized data to be zero.
88 */
89void
93
94/**
95 * Writes a single MAU using the fastest possible method.
96 *
97 * @param address The address.
98 * @param data The data.
99 */
100void
102 fastWriteMAU(address, data);
103}
104
105/**
106 * A convenience method for writing units of data to the memory.
107 *
108 * The data is stored in an UIntWord.
109 *
110 * @param address The address to write.
111 * @param count Number of MAUs to write.
112 * @param data The data to write.
113 * @exception OutOfRange in case the address is out of range of the memory.
114 */
115void
117 Memory::writeBE(address, count, data);
118 // compiled simulator does not call advance clock of
119 // memories at every cycle for efficiency, so we have
120 // to "flush" the writes right away
122}
123
124/**
125 * Reads a single MAU using the fastest possible method.
126 *
127 * @param address The address.
128 * @return Data.
129 */
132 ULongWord data = 0;
133 fastReadMAU(address, data);
134 return data;
135}
136
137/**
138 * Writes 1 MAU to the memory as fast as possible
139 *
140 * @param address address to write
141 * @param data data to be written
142 * @note No bounds checking is made so the address is assumed to be in range.
143 * @note On a cycle with read and write, make sure the read is done *first* !
144 */
145void
147 data_->writeData(address - start_, (int)(data & mask_));
148}
149
150/**
151 * Writes 2 MAUs to the memory as fast as possible
152 *
153 * @param address address to write
154 * @param data data to be written
155 * @note No bounds checking is made so the address is assumed to be in range.
156 * @note On a cycle with read and write, make sure the read is done *first* !
157 */
158void
160 const Word index = address - start_;
161 data_->writeData(index, (int)((data >> MAUSize_) & mask_));
162 data_->writeData(index + 1, (int)(data & mask_));
163}
164
165/**
166 * Writes 2 MAUs to the memory as fast as possible in little Endian
167 *
168 * @param address address to write
169 * @param data data to be written
170 * @note No bounds checking is made so the address is assumed to be in range.
171 * @note On a cycle with read and write, make sure the read is done *first* !
172 */
173void
175 const Word index = address - start_;
176 data_->writeData(index + 1, (int)((data >> MAUSize_) & mask_));
177 data_->writeData(index, (int)(data & mask_));
178}
179
180/**
181 * Writes 4 MAUs to the memory as fast as possible in BE.
182 *
183 * @param address address to write
184 * @param data data to be written
185 * @note No bounds checking is made so the address is assumed to be in range.
186 * @note On a cycle with read and write, make sure the read is done *first* !
187 */
188void
190 const Word index = address - start_;
191 data_->writeData(index, (int)((data >> MAUSize3_) & mask_));
192 data_->writeData(index + 1, (int)((data >> MAUSize2_) & mask_));
193 data_->writeData(index + 2, (int)((data >> MAUSize_) & mask_));
194 data_->writeData(index + 3, (int)(data & mask_));
195}
196
197/**
198 * Writes 4 MAUs to the memory as fast as possible in LE
199 *
200 * @param address address to write
201 * @param data data to be written
202 * @note No bounds checking is made so the address is assumed to be in range.
203 * @note On a cycle with read and write, make sure the read is done *first* !
204 */
205void
207 const Word index = address - start_;
208 data_->writeData(index + 3, (int)((data >> MAUSize3_) & mask_));
209 data_->writeData(index + 2, (int)((data >> MAUSize2_) & mask_));
210 data_->writeData(index + 1, (int)((data >> MAUSize_) & mask_));
211 data_->writeData(index, (int)(data & mask_));
212}
213
214/**
215 * Reads 1 MAU from the memory as fast as possible
216 *
217 * @param address address to read
218 * @param data reference to the read data
219 * @note No bounds checking is made so the address is assumed to be in range.
220 * @note On a cycle with read and write, make sure the read is done *first* !
221 */
222void
224 data = data_->readData(address - start_);
225}
226
227/**
228 * Reads 2 MAUs from the memory as fast as possible in BE
229 *
230 * @param address address to read
231 * @param data reference to the read data
232 * @note No bounds checking is made so the address is assumed to be in range.
233 * @note On a cycle with read and write, make sure the read is done *first* !
234 */
235void
237 const Word index = address - start_;
238 data = data_->readData(index) << MAUSize_;
239 data |= data_->readData(index + 1);
240}
241
242/**
243 * Reads 2 MAUs from the memory as fast as possible in LE
244 *
245 * @param address address to read
246 * @param data reference to the read data
247 * @note No bounds checking is made so the address is assumed to be in range.
248 * @note On a cycle with read and write, make sure the read is done *first* !
249 */
250void
252 const Word index = address - start_;
253 data = data_->readData(index +1) << MAUSize_;
254 data |= data_->readData(index);
255}
256
257/**
258 * Reads 4 MAUs from the memory as fast as possible in BE
259 *
260 * @param address address to read
261 * @param data reference to the read data
262 * @note No bounds checking is made so the address is assumed to be in range.
263 * @note On a cycle with read and write, make sure the read is done *first* !
264 */
265void
267 const Word index = address - start_;
268 data = data_->readData(index) << MAUSize3_;
269 data |= data_->readData(index + 1) << MAUSize2_;
270 data |= data_->readData(index + 2) << MAUSize_;
271 data |= data_->readData(index + 3);
272}
273
274/**
275 * Reads 4 MAUs from the memory as fast as possible in LE
276 *
277 * @param address address to read
278 * @param data reference to the read data
279 * @note No bounds checking is made so the address is assumed to be in range.
280 * @note On a cycle with read and write, make sure the read is done *first* !
281 */
282void
284 const Word index = address - start_;
285 data = data_->readData(index + 3) << MAUSize3_;
286 data |= data_->readData(index + 2) << MAUSize2_;
287 data |= data_->readData(index + 1) << MAUSize_;
288 data |= data_->readData(index);
289}
unsigned long ULongWord
Definition BaseType.hh:51
Memory::MAU read(ULongWord address) override
void fastRead4MAUsBE(ULongWord address, ULongWord &data)
void writeBE(ULongWord address, int count, ULongWord data) override
DirectAccessMemory(ULongWord start, ULongWord end, Word MAUSize, bool littleEndian)
Word MAUSize_
Size of the minimum adressable unit.
void fastWrite2MAUsBE(ULongWord address, ULongWord data)
void fastWrite4MAUsBE(ULongWord address, ULongWord data)
void fastWriteMAU(ULongWord address, ULongWord data)
void fastRead2MAUsLE(ULongWord address, ULongWord &data)
Word start_
Starting point of the address space.
virtual void fillWithZeros()
Word end_
End point of the address space.
Word mask_
Mask bit pattern for unpacking IntWord to MAUs.
Word MAUSize2_
precalculated MAUSize_ * 2
void fastRead2MAUsBE(ULongWord address, ULongWord &data)
void fastWrite4MAUsLE(ULongWord address, ULongWord data)
void fastReadMAU(ULongWord address, ULongWord &data)
void fastRead4MAUsLE(ULongWord address, ULongWord &data)
void write(ULongWord address, Memory::MAU data) override
void fastWrite2MAUsLE(ULongWord address, ULongWord data)
MemoryContents * data_
Contains MAUs of the memory model, that is, the actual data of the memory.
Word MAUSize3_
precalculated MAUSize_ * 3
virtual void advanceClock()
Definition Memory.cc:819
virtual void writeBE(ULongWord address, int size, ULongWord data)
Definition Memory.cc:194
MinimumAddressableUnit MAU
Definition Memory.hh:76
void clear()
ValueType readData(IndexType index)
void writeData(IndexType index, const ValueType &data)