gem5 v24.0.0.0
Loading...
Searching...
No Matches
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 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
237 Addr lineAddr = makeLineAddress(addr);
238
239 if (pktLineAddr == lineAddr) {
240 uint8_t *data = pkt->getPtr<uint8_t>();
241 unsigned int size_in_bytes = pkt->getSize();
242 unsigned startByte = pkt->getAddr() - lineAddr;
243
244 for (unsigned i = 0; i < size_in_bytes; ++i) {
245 data[i] = blk.getByte(i + startByte);
246 }
247 return true;
248 }
249 return false;
250}
251
259inline bool
261{
262 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
263 Addr lineAddr = makeLineAddress(addr);
264
265 if (pktLineAddr == lineAddr) {
266 uint8_t *data = pkt->getPtr<uint8_t>();
267 unsigned int size_in_bytes = pkt->getSize();
268 unsigned startByte = pkt->getAddr() - lineAddr;
269 bool was_read = false;
270
271 for (unsigned i = 0; i < size_in_bytes; ++i) {
272 if (mask.test(i + startByte)) {
273 was_read = true;
274 data[i] = blk.getByte(i + startByte);
275 }
276 }
277 return was_read;
278 }
279 return false;
280}
281
288inline bool
290{
291 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
292 Addr lineAddr = makeLineAddress(addr);
293
294 if (pktLineAddr == lineAddr) {
295 const uint8_t *data = pkt->getConstPtr<uint8_t>();
296 unsigned int size_in_bytes = pkt->getSize();
297 unsigned startByte = pkt->getAddr() - lineAddr;
298
299 for (unsigned i = 0; i < size_in_bytes; ++i) {
300 blk.setByte(i + startByte, data[i]);
301 }
302 return true;
303 }
304 return false;
305}
306
307inline int
309{
310 int count = 0;
311 for (const bool e: bVec) {
312 if (e) {
313 count++;
314 }
315 }
316 return count;
317}
318
319inline RequestorID
321{
322 return req->requestorId();
323}
324
325} // namespace ruby
326} // namespace gem5
327
328#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:125
void setByte(int whichByte, uint8_t data)
Definition DataBlock.hh:131
#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.
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
Addr makeLineAddress(Addr addr)
Definition Address.cc:60
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 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0