gem5  v20.1.0.0
memhelpers.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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 
53 template <class XC, class MemT>
54 Fault
56  MemT &mem, Request::Flags flags)
57 {
58  return xc->initiateMemRead(addr, sizeof(MemT), flags);
59 }
60 
62 template <ByteOrder Order, class MemT>
63 void
64 getMem(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
65 {
66  mem = pkt->get<MemT>(Order);
67  if (traceData)
68  traceData->setData(mem);
69 }
70 
71 template <class MemT>
72 void
73 getMemLE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
74 {
75  getMem<ByteOrder::little>(pkt, mem, traceData);
76 }
77 
78 template <class MemT>
79 void
80 getMemBE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
81 {
82  getMem<ByteOrder::big>(pkt, mem, traceData);
83 }
84 
86 template <ByteOrder Order, class XC, class MemT>
87 Fault
88 readMemAtomic(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem,
89  Request::Flags flags)
90 {
91  memset(&mem, 0, sizeof(mem));
92  Fault fault = xc->readMem(addr, (uint8_t *)&mem, sizeof(MemT), flags);
93  if (fault == NoFault) {
94  mem = gtoh(mem, Order);
95  if (traceData)
96  traceData->setData(mem);
97  }
98  return fault;
99 }
100 
101 template <class XC, class MemT>
102 Fault
103 readMemAtomicLE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem,
104  Request::Flags flags)
105 {
106  return readMemAtomic<ByteOrder::little>(
107  xc, traceData, addr, mem, flags);
108 }
109 
110 template <class XC, class MemT>
111 Fault
112 readMemAtomicBE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem,
113  Request::Flags flags)
114 {
115  return readMemAtomic<ByteOrder::big>(xc, traceData, addr, mem, flags);
116 }
117 
119 template <ByteOrder Order, class XC, class MemT>
120 Fault
121 writeMemTiming(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr,
122  Request::Flags flags, uint64_t *res)
123 {
124  if (traceData) {
125  traceData->setData(mem);
126  }
127  mem = htog(mem, Order);
128  return xc->writeMem((uint8_t *)&mem, sizeof(MemT), addr, flags, res);
129 }
130 
131 template <class XC, class MemT>
132 Fault
133 writeMemTimingLE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr,
134  Request::Flags flags, uint64_t *res)
135 {
136  return writeMemTiming<ByteOrder::little>(
137  xc, traceData, mem, addr, flags, res);
138 }
139 
140 template <class XC, class MemT>
141 Fault
142 writeMemTimingBE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr,
143  Request::Flags flags, uint64_t *res)
144 {
145  return writeMemTiming<ByteOrder::big>(
146  xc, traceData, mem, addr, flags, res);
147 }
148 
150 template <ByteOrder Order, class XC, class MemT>
151 Fault
152 writeMemAtomic(XC *xc, Trace::InstRecord *traceData, const MemT &mem,
153  Addr addr, Request::Flags flags, uint64_t *res)
154 {
155  if (traceData) {
156  traceData->setData(mem);
157  }
158  MemT host_mem = htog(mem, Order);
159  Fault fault =
160  xc->writeMem((uint8_t *)&host_mem, sizeof(MemT), addr, flags, res);
161  if (fault == NoFault && res != NULL) {
162  if (flags & Request::MEM_SWAP || flags & Request::MEM_SWAP_COND)
163  *(MemT *)res = gtoh(*(MemT *)res, Order);
164  else
165  *res = gtoh(*res, Order);
166  }
167  return fault;
168 }
169 
170 template <class XC, class MemT>
171 Fault
172 writeMemAtomicLE(XC *xc, Trace::InstRecord *traceData, const MemT &mem,
173  Addr addr, Request::Flags flags, uint64_t *res)
174 {
175  return writeMemAtomic<ByteOrder::little>(
176  xc, traceData, mem, addr, flags, res);
177 }
178 
179 template <class XC, class MemT>
180 Fault
181 writeMemAtomicBE(XC *xc, Trace::InstRecord *traceData, const MemT &mem,
182  Addr addr, Request::Flags flags, uint64_t *res)
183 {
184  return writeMemAtomic<ByteOrder::big>(
185  xc, traceData, mem, addr, flags, res);
186 }
187 
189 template <ByteOrder Order, class XC, class MemT>
190 Fault
191 amoMemAtomic(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr,
192  Request::Flags flags, AtomicOpFunctor *_amo_op)
193 {
194  assert(_amo_op);
195 
196  // mem will hold the previous value at addr after the AMO completes
197  memset(&mem, 0, sizeof(mem));
198 
199  AtomicOpFunctorPtr amo_op = AtomicOpFunctorPtr(_amo_op);
200  Fault fault = xc->amoMem(addr, (uint8_t *)&mem, sizeof(MemT), flags,
201  std::move(amo_op));
202 
203  if (fault == NoFault) {
204  mem = gtoh(mem, Order);
205  if (traceData)
206  traceData->setData(mem);
207  }
208  return fault;
209 }
210 
211 template <class XC, class MemT>
212 Fault
213 amoMemAtomicLE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr,
214  Request::Flags flags, AtomicOpFunctor *_amo_op)
215 {
216  return amoMemAtomic<ByteOrder::little>(
217  xc, traceData, mem, addr, flags, _amo_op);
218 }
219 
220 template <class XC, class MemT>
221 Fault
222 amoMemAtomicBE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr,
223  Request::Flags flags, AtomicOpFunctor *_amo_op)
224 {
225  return amoMemAtomic<ByteOrder::big>(
226  xc, traceData, mem, addr, flags, _amo_op);
227 }
228 
230 template <class XC, class MemT>
231 Fault
232 initiateMemAMO(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT& mem,
233  Request::Flags flags, AtomicOpFunctor *_amo_op)
234 {
235  assert(_amo_op);
236  AtomicOpFunctorPtr amo_op = AtomicOpFunctorPtr(_amo_op);
237  return xc->initiateMemAMO(addr, sizeof(MemT), flags, std::move(amo_op));
238 }
239 
240 #endif
getMem
void getMem(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
Extract the data returned from a timing mode read.
Definition: memhelpers.hh:64
AtomicOpFunctorPtr
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:239
writeMemAtomicBE
Fault writeMemAtomicBE(XC *xc, Trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res)
Definition: memhelpers.hh:181
initiateMemRead
Fault initiateMemRead(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
Initiate a read from memory in timing mode.
Definition: memhelpers.hh:55
amoMemAtomicLE
Fault amoMemAtomicLE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op)
Definition: memhelpers.hh:213
insttracer.hh
Flags< FlagsType >
Trace::InstRecord
Definition: insttracer.hh:55
Request::MEM_SWAP_COND
@ MEM_SWAP_COND
Definition: request.hh:148
request.hh
packet.hh
AtomicOpFunctor
Definition: amo.hh:40
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
htog
T htog(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:155
writeMemAtomic
Fault writeMemAtomic(XC *xc, Trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res)
Write to memory in atomic mode.
Definition: memhelpers.hh:152
amoMemAtomicBE
Fault amoMemAtomicBE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op)
Definition: memhelpers.hh:222
initiateMemAMO
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.
Definition: memhelpers.hh:232
Request::MEM_SWAP
@ MEM_SWAP
This request is for a memory swap.
Definition: request.hh:147
writeMemTimingLE
Fault writeMemTimingLE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res)
Definition: memhelpers.hh:133
Trace::InstRecord::setData
void setData(std::array< T, N > d)
Definition: insttracer.hh:183
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
writeMemTiming
Fault writeMemTiming(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res)
Write to memory in timing mode.
Definition: memhelpers.hh:121
readMemAtomicBE
Fault readMemAtomicBE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
Definition: memhelpers.hh:112
Packet::get
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
Definition: packet_access.hh:82
getMemLE
void getMemLE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
Definition: memhelpers.hh:73
types.hh
getMemBE
void getMemBE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData)
Definition: memhelpers.hh:80
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
writeMemTimingBE
Fault writeMemTimingBE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res)
Definition: memhelpers.hh:142
addr
ip6_addr_t addr
Definition: inet.hh:423
mem
bool_vector8 mem[]
Definition: reset_stim.h:43
gtoh
T gtoh(T value, ByteOrder guest_byte_order)
Definition: byteswap.hh:162
amoMemAtomic
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.
Definition: memhelpers.hh:191
byteswap.hh
readMemAtomicLE
Fault readMemAtomicLE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
Definition: memhelpers.hh:103
writeMemAtomicLE
Fault writeMemAtomicLE(XC *xc, Trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res)
Definition: memhelpers.hh:172
readMemAtomic
Fault readMemAtomic(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags)
Read from memory in atomic mode.
Definition: memhelpers.hh:88

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17