gem5 v24.0.0.0
Loading...
Searching...
No Matches
memhelpers.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013, 2019 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2011 Google
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __ARCH_GENERIC_MEMHELPERS_HH__
42#define __ARCH_GENERIC_MEMHELPERS_HH__
43
44#include "base/types.hh"
45#include "mem/packet.hh"
46#include "mem/request.hh"
47#include "sim/byteswap.hh"
48#include "sim/insttracer.hh"
49
50namespace gem5
51{
52
53template <class XC>
55initiateMemRead(XC *xc, Addr addr, std::size_t size,
57 const std::vector<bool> &byte_enable)
58{
59 return xc->initiateMemRead(addr, size, flags, byte_enable);
60}
61
65template <class XC, class MemT>
69{
70 static const std::vector<bool> byte_enable(sizeof(MemT), true);
71 return initiateMemRead(xc, addr, sizeof(MemT),
72 flags, byte_enable);
73}
74
76template <ByteOrder Order, class MemT>
77void
78getMem(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
79{
80 mem = pkt->get<MemT>(Order);
81 if (traceData)
82 traceData->setData(mem);
83}
84
85template <class MemT>
86void
87getMemLE(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
88{
89 getMem<ByteOrder::little>(pkt, mem, traceData);
90}
91
92template <class MemT>
93void
94getMemBE(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
95{
96 getMem<ByteOrder::big>(pkt, mem, traceData);
97}
98
100template <class XC>
101Fault
102readMemAtomic(XC *xc, Addr addr, uint8_t *mem,
103 std::size_t size, Request::Flags flags,
104 const std::vector<bool> &byte_enable)
105{
106 return xc->readMem(addr, mem, size, flags, byte_enable);
107}
108
110template <ByteOrder Order, class XC, class MemT>
111Fault
112readMemAtomic(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem,
114{
115 memset(&mem, 0, sizeof(mem));
116 static const std::vector<bool> byte_enable(sizeof(MemT), true);
117 Fault fault = readMemAtomic(xc, addr, (uint8_t*)&mem,
118 sizeof(MemT), flags, byte_enable);
119 if (fault == NoFault) {
120 mem = gtoh(mem, Order);
121 if (traceData)
122 traceData->setData(mem);
123 }
124 return fault;
125}
126
128template <ByteOrder Order, class XC, class MemT>
129Fault
130readMemAtomic(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem,
131 size_t size, Request::Flags flags)
132{
133 memset(&mem, 0, size);
134 static const std::vector<bool> byte_enable(size, true);
135 Fault fault = readMemAtomic(xc, addr, (uint8_t*)&mem,
136 size, flags, byte_enable);
137 if (fault == NoFault) {
138 mem = gtoh(mem, Order);
139 if (traceData)
140 traceData->setData(mem);
141 }
142 return fault;
143}
144
145template <class XC, class MemT>
146Fault
147readMemAtomicLE(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem,
149{
151 xc, traceData, addr, mem, flags);
152}
153
154template <class XC, class MemT>
155Fault
156readMemAtomicLE(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem,
157 size_t size, Request::Flags flags)
158{
160 xc, traceData, addr, mem, size, flags);
161}
162
163
164template <class XC, class MemT>
165Fault
166readMemAtomicBE(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem,
168{
169 return readMemAtomic<ByteOrder::big>(xc, traceData, addr, mem, flags);
170}
171
173template <class XC>
174Fault
175writeMemTiming(XC *xc, uint8_t *mem, Addr addr,
176 std::size_t size, Request::Flags flags, uint64_t *res,
177 const std::vector<bool> &byte_enable)
178{
179 return xc->writeMem(mem, size, addr, flags, res, byte_enable);
180}
181
182template <ByteOrder Order, class XC, class MemT>
183Fault
184writeMemTiming(XC *xc, trace::InstRecord *traceData, MemT mem, Addr addr,
185 Request::Flags flags, uint64_t *res)
186{
187 if (traceData) {
188 traceData->setData(mem);
189 }
190 mem = htog(mem, Order);
191 static const std::vector<bool> byte_enable(sizeof(MemT), true);
192 return writeMemTiming(xc, (uint8_t*)&mem, addr,
193 sizeof(MemT), flags, res, byte_enable);
194}
195
196template <ByteOrder Order, class XC, class MemT>
197Fault
198writeMemTiming(XC *xc, trace::InstRecord *traceData, MemT mem, Addr addr,
199 size_t size, Request::Flags flags, uint64_t *res)
200{
201 if (traceData) {
202 traceData->setData(mem);
203 }
204 mem = htog(mem, Order);
205 static const std::vector<bool> byte_enable(size, true);
206 return writeMemTiming(xc, (uint8_t*)&mem, addr,
207 size, flags, res, byte_enable);
208}
209
210template <class XC, class MemT>
211Fault
213 Request::Flags flags, uint64_t *res)
214{
216 xc, traceData, mem, addr, flags, res);
217}
218
219template <class XC, class MemT>
220Fault
222 size_t size, Request::Flags flags, uint64_t *res)
223{
225 xc, traceData, mem, addr, size, flags, res);
226}
227
228template <class XC, class MemT>
229Fault
231 Request::Flags flags, uint64_t *res)
232{
234 xc, traceData, mem, addr, flags, res);
235}
236
238template <class XC>
239Fault
240writeMemAtomic(XC *xc, uint8_t *mem, Addr addr,
241 std::size_t size, Request::Flags flags,
242 uint64_t *res, const std::vector<bool> &byte_enable)
243{
244 return xc->writeMem(mem, size, addr, flags, res, byte_enable);
245}
246
247template <ByteOrder Order, class XC, class MemT>
248Fault
249writeMemAtomic(XC *xc, trace::InstRecord *traceData, const MemT &mem,
250 Addr addr, Request::Flags flags, uint64_t *res)
251{
252 if (traceData) {
253 traceData->setData(mem);
254 }
255 MemT host_mem = htog(mem, Order);
256 static const std::vector<bool> byte_enable(sizeof(MemT), true);
257 Fault fault = writeMemAtomic(xc, (uint8_t*)&host_mem,
258 addr, sizeof(MemT), flags, res, byte_enable);
259 if (fault == NoFault && res != NULL) {
261 *(MemT *)res = gtoh(*(MemT *)res, Order);
262 else
263 *res = gtoh(*res, Order);
264 }
265 return fault;
266}
267
268template <ByteOrder Order, class XC, class MemT>
269Fault
270writeMemAtomic(XC *xc, trace::InstRecord *traceData, const MemT &mem,
271 Addr addr, size_t size, Request::Flags flags, uint64_t *res)
272{
273 if (traceData) {
274 traceData->setData(mem);
275 }
276 MemT host_mem = htog(mem, Order);
277 static const std::vector<bool> byte_enable(size, true);
278 Fault fault = writeMemAtomic(xc, (uint8_t*)&host_mem,
279 addr, size, flags, res, byte_enable);
280 if (fault == NoFault && res != NULL) {
282 *(MemT *)res = gtoh(*(MemT *)res, Order);
283 else
284 *res = gtoh(*res, Order);
285 }
286 return fault;
287}
288
289template <class XC, class MemT>
290Fault
291writeMemAtomicLE(XC *xc, trace::InstRecord *traceData, const MemT &mem,
292 Addr addr, Request::Flags flags, uint64_t *res)
293{
295 xc, traceData, mem, addr, flags, res);
296}
297
298template <class XC, class MemT>
299Fault
300writeMemAtomicLE(XC *xc, trace::InstRecord *traceData, const MemT &mem,
301 size_t size, Addr addr, Request::Flags flags, uint64_t *res)
302{
304 xc, traceData, mem, addr, size, flags, res);
305}
306
307template <class XC, class MemT>
308Fault
309writeMemAtomicBE(XC *xc, trace::InstRecord *traceData, const MemT &mem,
310 Addr addr, Request::Flags flags, uint64_t *res)
311{
313 xc, traceData, mem, addr, flags, res);
314}
315
317template <ByteOrder Order, class XC, class MemT>
318Fault
319amoMemAtomic(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr,
321{
322 assert(_amo_op);
323
324 // mem will hold the previous value at addr after the AMO completes
325 memset(&mem, 0, sizeof(mem));
326
327 AtomicOpFunctorPtr amo_op = AtomicOpFunctorPtr(_amo_op);
328 Fault fault = xc->amoMem(addr, (uint8_t *)&mem, sizeof(MemT), flags,
329 std::move(amo_op));
330
331 if (fault == NoFault) {
332 mem = gtoh(mem, Order);
333 if (traceData)
334 traceData->setData(mem);
335 }
336 return fault;
337}
338
339template <class XC, class MemT>
340Fault
341amoMemAtomicLE(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr,
343{
345 xc, traceData, mem, addr, flags, _amo_op);
346}
347
348template <class XC, class MemT>
349Fault
350amoMemAtomicBE(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr,
352{
354 xc, traceData, mem, addr, flags, _amo_op);
355}
356
358template <class XC, class MemT>
359Fault
360initiateMemAMO(XC *xc, trace::InstRecord *traceData, Addr addr, MemT& mem,
362{
363 assert(_amo_op);
364 AtomicOpFunctorPtr amo_op = AtomicOpFunctorPtr(_amo_op);
365 return xc->initiateMemAMO(addr, sizeof(MemT), flags, std::move(amo_op));
366}
367
368} // namespace gem5
369
370#endif
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
@ MEM_SWAP
This request is for a memory swap.
Definition request.hh:158
void setData(std::array< T, N > d)
STL vector class.
Definition stl.hh:37
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition amo.hh:269
uint8_t flags
Definition helpers.cc:87
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Fault readMemAtomicBE(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
void getMemLE(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
Definition memhelpers.hh:87
Fault initiateMemRead(XC *xc, Addr addr, std::size_t size, Request::Flags flags, const std::vector< bool > &byte_enable)
Definition memhelpers.hh:55
Fault amoMemAtomicBE(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op)
Fault writeMemTimingLE(XC *xc, trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
T gtoh(T value, ByteOrder guest_byte_order)
Definition byteswap.hh:194
Fault writeMemAtomicBE(XC *xc, trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res)
void getMemBE(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
Definition memhelpers.hh:94
Fault writeMemAtomic(XC *xc, uint8_t *mem, Addr addr, std::size_t size, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable)
Write to memory in atomic mode.
Fault writeMemTiming(XC *xc, uint8_t *mem, Addr addr, std::size_t size, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable)
Write to memory in timing mode.
Fault amoMemAtomic(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op)
Do atomic read-modify-write (AMO) in atomic mode.
Fault readMemAtomicLE(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
Fault initiateMemAMO(XC *xc, trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags, AtomicOpFunctor *_amo_op)
Do atomic read-modify-wrote (AMO) in timing mode.
Fault writeMemAtomicLE(XC *xc, trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res)
T htog(T value, ByteOrder guest_byte_order)
Definition byteswap.hh:187
Fault writeMemTimingBE(XC *xc, trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res)
void getMem(PacketPtr pkt, MemT &mem, trace::InstRecord *traceData)
Extract the data returned from a timing mode read.
Definition memhelpers.hh:78
Fault amoMemAtomicLE(XC *xc, trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op)
constexpr decltype(nullptr) NoFault
Definition types.hh:253
Fault readMemAtomic(XC *xc, Addr addr, uint8_t *mem, std::size_t size, Request::Flags flags, const std::vector< bool > &byte_enable)
Read from memory in atomic mode.
Declaration of the Packet class.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
bool_vector8 mem[]
Definition reset_stim.h:43

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0