gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RubySlicc_Util.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020-2021,2023 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) 1999-2008 Mark D. Hill and David A. Wood
15 * Copyright (c) 2013 Advanced Micro Devices, Inc.
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42/*
43 * These are the functions that exported to slicc from ruby.
44 */
45
46#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
47#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
48
49#include <cassert>
50#include <climits>
51
52#include "debug/RubyProtocol.hh"
53#include "debug/RubySlicc.hh"
54#include "mem/packet.hh"
60#include "mem/ruby/protocol/RubyRequestType.hh"
61
62namespace gem5
63{
64
65namespace ruby
66{
67
68inline Cycles zero_time() { return Cycles(0); }
69
70inline Cycles intToCycles(int c) { return Cycles(c); }
71
72inline Tick intToTick(int c) { return c; }
73
74inline NodeID
75intToID(int nodenum)
76{
77 NodeID id = nodenum;
78 return id;
79}
80
81inline int
83{
84 int nodenum = id;
85 return nodenum;
86}
87
88inline int
90{
91 assert(!(addr & 0xffffffff00000000));
92 return addr;
93}
94
95inline Addr
97{
98 assert(!(addr & 0xffffffff00000000));
99 return addr;
100}
101
102inline int
103mod(int val, int mod)
104{
105 return val % mod;
106}
107
108inline int max_tokens()
109{
110 return 1024;
111}
112
113inline bool
114isWriteRequest(RubyRequestType type)
115{
116 if ((type == RubyRequestType_ST) ||
117 (type == RubyRequestType_ATOMIC) ||
118 (type == RubyRequestType_RMW_Read) ||
119 (type == RubyRequestType_RMW_Write) ||
120 (type == RubyRequestType_Store_Conditional) ||
121 (type == RubyRequestType_Locked_RMW_Read) ||
122 (type == RubyRequestType_Locked_RMW_Write) ||
123 (type == RubyRequestType_FLUSH)) {
124 return true;
125 } else {
126 return false;
127 }
128}
129
130inline bool
131isDataReadRequest(RubyRequestType type)
132{
133 if ((type == RubyRequestType_LD) ||
134 (type == RubyRequestType_Load_Linked)) {
135 return true;
136 } else {
137 return false;
138 }
139}
140
141inline bool
142isReadRequest(RubyRequestType type)
143{
144 if (isDataReadRequest(type) ||
145 (type == RubyRequestType_IFETCH)) {
146 return true;
147 } else {
148 return false;
149 }
150}
151
152inline bool
153isHtmCmdRequest(RubyRequestType type)
154{
155 if ((type == RubyRequestType_HTM_Start) ||
156 (type == RubyRequestType_HTM_Commit) ||
157 (type == RubyRequestType_HTM_Cancel) ||
158 (type == RubyRequestType_HTM_Abort)) {
159 return true;
160 } else {
161 return false;
162 }
163}
164
165inline bool
166isTlbiCmdRequest(RubyRequestType type)
167{
168 if ((type == RubyRequestType_TLBI) ||
169 (type == RubyRequestType_TLBI_SYNC) ||
170 (type == RubyRequestType_TLBI_EXT_SYNC) ||
171 (type == RubyRequestType_TLBI_EXT_SYNC_COMP)) {
172 return true;
173 } else {
174 return false;
175 }
176}
177
178inline RubyRequestType
180{
181 if (pkt->req->isHTMStart()) {
182 return RubyRequestType_HTM_Start;
183 } else if (pkt->req->isHTMCommit()) {
184 return RubyRequestType_HTM_Commit;
185 } else if (pkt->req->isHTMCancel()) {
186 return RubyRequestType_HTM_Cancel;
187 } else if (pkt->req->isHTMAbort()) {
188 return RubyRequestType_HTM_Abort;
189 }
190 else {
191 panic("invalid ruby packet type\n");
192 }
193}
194
195inline RubyRequestType
197{
198 if (pkt->req->isTlbi()) {
199 return RubyRequestType_TLBI;
200 } else if (pkt->req->isTlbiSync()) {
201 return RubyRequestType_TLBI_SYNC;
202 } else if (pkt->req->isTlbiExtSync()) {
203 return RubyRequestType_TLBI_EXT_SYNC;
204 } else if (pkt->req->isTlbiExtSyncComp()) {
205 return RubyRequestType_TLBI_EXT_SYNC_COMP;
206 } else {
207 panic("invalid ruby packet type\n");
208 }
209}
210
211inline int
213{
214 assert(addr >= base);
215 Addr offset = addr - base;
216 // sanity checks if fits in an int
217 assert(offset < INT_MAX);
218 return offset;
219}
220
233inline bool
235{
236 int block_size_bits = floorLog2(blk.getBlockSize());
237 Addr pktLineAddr = makeLineAddress(pkt->getAddr(), block_size_bits);
238 Addr lineAddr = makeLineAddress(addr, block_size_bits);
239
240 if (pktLineAddr == lineAddr) {
241 uint8_t *data = pkt->getPtr<uint8_t>();
242 unsigned int size_in_bytes = pkt->getSize();
243 unsigned startByte = pkt->getAddr() - lineAddr;
244
245 for (unsigned i = 0; i < size_in_bytes; ++i) {
246 data[i] = blk.getByte(i + startByte);
247 }
248 return true;
249 }
250 return false;
251}
252
260inline bool
262{
263 assert(blk.getBlockSize() == mask.getBlockSize());
264 int block_size_bits = floorLog2(blk.getBlockSize());
265 Addr pktLineAddr = makeLineAddress(pkt->getAddr(), block_size_bits);
266 Addr lineAddr = makeLineAddress(addr, block_size_bits);
267
268 if (pktLineAddr == lineAddr) {
269 uint8_t *data = pkt->getPtr<uint8_t>();
270 unsigned int size_in_bytes = pkt->getSize();
271 unsigned startByte = pkt->getAddr() - lineAddr;
272 bool was_read = false;
273
274 for (unsigned i = 0; i < size_in_bytes; ++i) {
275 if (mask.test(i + startByte)) {
276 was_read = true;
277 data[i] = blk.getByte(i + startByte);
278 }
279 }
280 return was_read;
281 }
282 return false;
283}
284
291inline bool
293{
294 int block_size_bits = floorLog2(blk.getBlockSize());
295 Addr pktLineAddr = makeLineAddress(pkt->getAddr(), block_size_bits);
296 Addr lineAddr = makeLineAddress(addr, block_size_bits);
297
298 if (pktLineAddr == lineAddr) {
299 const uint8_t *data = pkt->getConstPtr<uint8_t>();
300 unsigned int size_in_bytes = pkt->getSize();
301 unsigned startByte = pkt->getAddr() - lineAddr;
302
303 for (unsigned i = 0; i < size_in_bytes; ++i) {
304 blk.setByte(i + startByte, data[i]);
305 }
306 return true;
307 }
308 return false;
309}
310
311inline int
313{
314 int count = 0;
315 for (const bool e: bVec) {
316 if (e) {
317 count++;
318 }
319 }
320 return count;
321}
322
323inline RequestorID
325{
326 return req->requestorId();
327}
328
329} // namespace ruby
330} // namespace gem5
331
332#endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
const char data[]
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
T * getPtr()
get a pointer to the data ptr.
Definition packet.hh:1225
RequestPtr req
A pointer to the original request.
Definition packet.hh:377
unsigned getSize() const
Definition packet.hh:817
const T * getConstPtr() const
Definition packet.hh:1234
uint8_t getByte(int whichByte) const
Definition DataBlock.hh:137
int getBlockSize() const
Definition DataBlock.hh:110
void setByte(int whichByte, uint8_t data)
Definition DataBlock.hh:144
static constexpr std::enable_if_t< std::is_integral_v< T >, int > floorLog2(T x)
Definition intmath.hh:59
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 33 > id
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 51, 12 > base
Definition pagetable.hh:141
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
NodeID intToID(int nodenum)
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Addr makeLineAddress(Addr addr, int cacheLineBits)
Definition Address.cc:61
Cycles intToCycles(int c)
int countBoolVec(BoolVec bVec)
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
bool isWriteRequest(RubyRequestType type)
bool isReadRequest(RubyRequestType type)
RubyRequestType tlbiCmdToRubyRequestType(const Packet *pkt)
Addr intToAddress(int addr)
bool isTlbiCmdRequest(RubyRequestType type)
Cycles zero_time()
Tick intToTick(int c)
RequestorID getRequestorID(RequestPtr req)
unsigned int NodeID
int addressToInt(Addr addr)
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
int IDToInt(NodeID id)
bool testAndReadMask(Addr addr, DataBlock &blk, WriteMask &mask, Packet *pkt)
This function accepts an address, a data block, a write mask and a packet.
bool isDataReadRequest(RubyRequestType type)
int addressOffset(Addr addr, Addr base)
bool isHtmCmdRequest(RubyRequestType type)
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
uint16_t RequestorID
Definition request.hh:95
Declaration of the Packet class.

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8