gem5  v21.0.0.0
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 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/RubySlicc.hh"
53 #include "mem/packet.hh"
59 #include "mem/ruby/protocol/RubyRequestType.hh"
60 
61 inline Cycles zero_time() { return Cycles(0); }
62 
63 inline Cycles intToCycles(int c) { return Cycles(c); }
64 
65 inline Tick intToTick(int c) { return c; }
66 
67 inline NodeID
68 intToID(int nodenum)
69 {
70  NodeID id = nodenum;
71  return id;
72 }
73 
74 inline int
76 {
77  int nodenum = id;
78  return nodenum;
79 }
80 
81 inline int
83 {
84  assert(!(addr & 0xffffffff00000000));
85  return addr;
86 }
87 
88 inline Addr
90 {
91  assert(!(addr & 0xffffffff00000000));
92  return addr;
93 }
94 
95 inline int
96 mod(int val, int mod)
97 {
98  return val % mod;
99 }
100 
101 inline int max_tokens()
102 {
103  return 1024;
104 }
105 
106 inline bool
107 isWriteRequest(RubyRequestType type)
108 {
109  if ((type == RubyRequestType_ST) ||
110  (type == RubyRequestType_ATOMIC) ||
111  (type == RubyRequestType_RMW_Read) ||
112  (type == RubyRequestType_RMW_Write) ||
113  (type == RubyRequestType_Store_Conditional) ||
114  (type == RubyRequestType_Locked_RMW_Read) ||
115  (type == RubyRequestType_Locked_RMW_Write) ||
116  (type == RubyRequestType_FLUSH)) {
117  return true;
118  } else {
119  return false;
120  }
121 }
122 
123 inline bool
124 isDataReadRequest(RubyRequestType type)
125 {
126  if ((type == RubyRequestType_LD) ||
127  (type == RubyRequestType_Load_Linked)) {
128  return true;
129  } else {
130  return false;
131  }
132 }
133 
134 inline bool
135 isReadRequest(RubyRequestType type)
136 {
137  if (isDataReadRequest(type) ||
138  (type == RubyRequestType_IFETCH)) {
139  return true;
140  } else {
141  return false;
142  }
143 }
144 
145 inline bool
146 isHtmCmdRequest(RubyRequestType type)
147 {
148  if ((type == RubyRequestType_HTM_Start) ||
149  (type == RubyRequestType_HTM_Commit) ||
150  (type == RubyRequestType_HTM_Cancel) ||
151  (type == RubyRequestType_HTM_Abort)) {
152  return true;
153  } else {
154  return false;
155  }
156 }
157 
158 inline RubyRequestType
160 {
161  if (pkt->req->isHTMStart()) {
162  return RubyRequestType_HTM_Start;
163  } else if (pkt->req->isHTMCommit()) {
164  return RubyRequestType_HTM_Commit;
165  } else if (pkt->req->isHTMCancel()) {
166  return RubyRequestType_HTM_Cancel;
167  } else if (pkt->req->isHTMAbort()) {
168  return RubyRequestType_HTM_Abort;
169  }
170  else {
171  panic("invalid ruby packet type\n");
172  }
173 }
174 
175 inline int
177 {
178  assert(addr >= base);
179  Addr offset = addr - base;
180  // sanity checks if fits in an int
181  assert(offset < INT_MAX);
182  return offset;
183 }
184 
197 inline bool
199 {
200  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
201  Addr lineAddr = makeLineAddress(addr);
202 
203  if (pktLineAddr == lineAddr) {
204  uint8_t *data = pkt->getPtr<uint8_t>();
205  unsigned int size_in_bytes = pkt->getSize();
206  unsigned startByte = pkt->getAddr() - lineAddr;
207 
208  for (unsigned i = 0; i < size_in_bytes; ++i) {
209  data[i] = blk.getByte(i + startByte);
210  }
211  return true;
212  }
213  return false;
214 }
215 
223 inline bool
225 {
226  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
227  Addr lineAddr = makeLineAddress(addr);
228 
229  if (pktLineAddr == lineAddr) {
230  uint8_t *data = pkt->getPtr<uint8_t>();
231  unsigned int size_in_bytes = pkt->getSize();
232  unsigned startByte = pkt->getAddr() - lineAddr;
233  bool was_read = false;
234 
235  for (unsigned i = 0; i < size_in_bytes; ++i) {
236  if (mask.test(i + startByte)) {
237  was_read = true;
238  data[i] = blk.getByte(i + startByte);
239  }
240  }
241  return was_read;
242  }
243  return false;
244 }
245 
252 inline bool
254 {
255  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
256  Addr lineAddr = makeLineAddress(addr);
257 
258  if (pktLineAddr == lineAddr) {
259  const uint8_t *data = pkt->getConstPtr<uint8_t>();
260  unsigned int size_in_bytes = pkt->getSize();
261  unsigned startByte = pkt->getAddr() - lineAddr;
262 
263  for (unsigned i = 0; i < size_in_bytes; ++i) {
264  blk.setByte(i + startByte, data[i]);
265  }
266  return true;
267  }
268  return false;
269 }
270 
271 inline int
273 {
274  int count = 0;
275  for (const bool e: bVec) {
276  if (e) {
277  count++;
278  }
279  }
280  return count;
281 }
282 
283 #endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
data
const char data[]
Definition: circlebuf.test.cc:47
htmCmdToRubyRequestType
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
Definition: RubySlicc_Util.hh:159
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
addressOffset
int addressOffset(Addr addr, Addr base)
Definition: RubySlicc_Util.hh:176
mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:96
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:138
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:341
std::vector< bool >
BoolVec.hh
intToCycles
Cycles intToCycles(int c)
Definition: RubySlicc_Util.hh:63
Packet::getSize
unsigned getSize() const
Definition: packet.hh:765
X86ISA::count
count
Definition: misc.hh:703
max_tokens
int max_tokens()
Definition: RubySlicc_Util.hh:101
testAndRead
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:198
DataBlock
Definition: DataBlock.hh:54
packet.hh
addressToInt
int addressToInt(Addr addr)
Definition: RubySlicc_Util.hh:82
testAndReadMask
bool testAndReadMask(Addr addr, DataBlock &blk, WriteMask &mask, Packet *pkt)
This function accepts an address, a data block, a write mask and a packet.
Definition: RubySlicc_Util.hh:224
isWriteRequest
bool isWriteRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:107
countBoolVec
int countBoolVec(BoolVec bVec)
Definition: RubySlicc_Util.hh:272
DataBlock::setByte
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:111
testAndWrite
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:253
DataBlock.hh
TypeDefines.hh
WriteMask.hh
intToAddress
Addr intToAddress(int addr)
Definition: RubySlicc_Util.hh:89
isDataReadRequest
bool isDataReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:124
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
isReadRequest
bool isReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:135
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
DataBlock::getByte
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:105
IDToInt
int IDToInt(NodeID id)
Definition: RubySlicc_Util.hh:75
Address.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
zero_time
Cycles zero_time()
Definition: RubySlicc_Util.hh:61
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
intToID
NodeID intToID(int nodenum)
Definition: RubySlicc_Util.hh:68
Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1158
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
X86ISA::type
type
Definition: misc.hh:727
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1167
WriteMask
Definition: WriteMask.hh:53
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
intToTick
Tick intToTick(int c)
Definition: RubySlicc_Util.hh:65
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
isHtmCmdRequest
bool isHtmCmdRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:146
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17