gem5  v21.2.1.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 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 namespace gem5
62 {
63 
64 namespace ruby
65 {
66 
67 inline Cycles zero_time() { return Cycles(0); }
68 
69 inline Cycles intToCycles(int c) { return Cycles(c); }
70 
71 inline Tick intToTick(int c) { return c; }
72 
73 inline NodeID
74 intToID(int nodenum)
75 {
76  NodeID id = nodenum;
77  return id;
78 }
79 
80 inline int
82 {
83  int nodenum = id;
84  return nodenum;
85 }
86 
87 inline int
89 {
90  assert(!(addr & 0xffffffff00000000));
91  return addr;
92 }
93 
94 inline Addr
96 {
97  assert(!(addr & 0xffffffff00000000));
98  return addr;
99 }
100 
101 inline int
102 mod(int val, int mod)
103 {
104  return val % mod;
105 }
106 
107 inline int max_tokens()
108 {
109  return 1024;
110 }
111 
112 inline bool
113 isWriteRequest(RubyRequestType type)
114 {
115  if ((type == RubyRequestType_ST) ||
116  (type == RubyRequestType_ATOMIC) ||
117  (type == RubyRequestType_RMW_Read) ||
118  (type == RubyRequestType_RMW_Write) ||
119  (type == RubyRequestType_Store_Conditional) ||
120  (type == RubyRequestType_Locked_RMW_Read) ||
121  (type == RubyRequestType_Locked_RMW_Write) ||
122  (type == RubyRequestType_FLUSH)) {
123  return true;
124  } else {
125  return false;
126  }
127 }
128 
129 inline bool
130 isDataReadRequest(RubyRequestType type)
131 {
132  if ((type == RubyRequestType_LD) ||
133  (type == RubyRequestType_Load_Linked)) {
134  return true;
135  } else {
136  return false;
137  }
138 }
139 
140 inline bool
141 isReadRequest(RubyRequestType type)
142 {
143  if (isDataReadRequest(type) ||
144  (type == RubyRequestType_IFETCH)) {
145  return true;
146  } else {
147  return false;
148  }
149 }
150 
151 inline bool
152 isHtmCmdRequest(RubyRequestType type)
153 {
154  if ((type == RubyRequestType_HTM_Start) ||
155  (type == RubyRequestType_HTM_Commit) ||
156  (type == RubyRequestType_HTM_Cancel) ||
157  (type == RubyRequestType_HTM_Abort)) {
158  return true;
159  } else {
160  return false;
161  }
162 }
163 
164 inline RubyRequestType
166 {
167  if (pkt->req->isHTMStart()) {
168  return RubyRequestType_HTM_Start;
169  } else if (pkt->req->isHTMCommit()) {
170  return RubyRequestType_HTM_Commit;
171  } else if (pkt->req->isHTMCancel()) {
172  return RubyRequestType_HTM_Cancel;
173  } else if (pkt->req->isHTMAbort()) {
174  return RubyRequestType_HTM_Abort;
175  }
176  else {
177  panic("invalid ruby packet type\n");
178  }
179 }
180 
181 inline int
183 {
184  assert(addr >= base);
185  Addr offset = addr - base;
186  // sanity checks if fits in an int
187  assert(offset < INT_MAX);
188  return offset;
189 }
190 
203 inline bool
205 {
206  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
207  Addr lineAddr = makeLineAddress(addr);
208 
209  if (pktLineAddr == lineAddr) {
210  uint8_t *data = pkt->getPtr<uint8_t>();
211  unsigned int size_in_bytes = pkt->getSize();
212  unsigned startByte = pkt->getAddr() - lineAddr;
213 
214  for (unsigned i = 0; i < size_in_bytes; ++i) {
215  data[i] = blk.getByte(i + startByte);
216  }
217  return true;
218  }
219  return false;
220 }
221 
229 inline bool
231 {
232  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
233  Addr lineAddr = makeLineAddress(addr);
234 
235  if (pktLineAddr == lineAddr) {
236  uint8_t *data = pkt->getPtr<uint8_t>();
237  unsigned int size_in_bytes = pkt->getSize();
238  unsigned startByte = pkt->getAddr() - lineAddr;
239  bool was_read = false;
240 
241  for (unsigned i = 0; i < size_in_bytes; ++i) {
242  if (mask.test(i + startByte)) {
243  was_read = true;
244  data[i] = blk.getByte(i + startByte);
245  }
246  }
247  return was_read;
248  }
249  return false;
250 }
251 
258 inline bool
260 {
261  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
262  Addr lineAddr = makeLineAddress(addr);
263 
264  if (pktLineAddr == lineAddr) {
265  const uint8_t *data = pkt->getConstPtr<uint8_t>();
266  unsigned int size_in_bytes = pkt->getSize();
267  unsigned startByte = pkt->getAddr() - lineAddr;
268 
269  for (unsigned i = 0; i < size_in_bytes; ++i) {
270  blk.setByte(i + startByte, data[i]);
271  }
272  return true;
273  }
274  return false;
275 }
276 
277 inline int
279 {
280  int count = 0;
281  for (const bool e: bVec) {
282  if (e) {
283  count++;
284  }
285  }
286  return count;
287 }
288 
289 } // namespace ruby
290 } // namespace gem5
291 
292 #endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
gem5::ruby::intToID
NodeID intToID(int nodenum)
Definition: RubySlicc_Util.hh:74
gem5::ruby::htmCmdToRubyRequestType
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
Definition: RubySlicc_Util.hh:165
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::ruby::DataBlock::getByte
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:111
gem5::Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:366
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::ruby::zero_time
Cycles zero_time()
Definition: RubySlicc_Util.hh:67
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:775
std::vector< bool >
BoolVec.hh
gem5::X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::ruby::makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:60
gem5::ruby::intToTick
Tick intToTick(int c)
Definition: RubySlicc_Util.hh:71
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
packet.hh
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::ruby::intToAddress
Addr intToAddress(int addr)
Definition: RubySlicc_Util.hh:95
gem5::ruby::isDataReadRequest
bool isDataReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:130
gem5::ruby::isReadRequest
bool isReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:141
gem5::ruby::intToCycles
Cycles intToCycles(int c)
Definition: RubySlicc_Util.hh:69
gem5::X86ISA::count
count
Definition: misc.hh:709
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::ruby::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:230
DataBlock.hh
TypeDefines.hh
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
WriteMask.hh
gem5::X86ISA::type
type
Definition: misc.hh:733
gem5::Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1193
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::ruby::isWriteRequest
bool isWriteRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:113
gem5::ruby::DataBlock::setByte
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:117
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ruby::addressToInt
int addressToInt(Addr addr)
Definition: RubySlicc_Util.hh:88
gem5::ruby::IDToInt
int IDToInt(NodeID id)
Definition: RubySlicc_Util.hh:81
gem5::ruby::testAndRead
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:204
gem5::ruby::isHtmCmdRequest
bool isHtmCmdRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:152
Address.hh
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:251
gem5::ruby::NodeID
unsigned int NodeID
Definition: TypeDefines.hh:40
gem5::ruby::testAndWrite
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:259
gem5::ruby::countBoolVec
int countBoolVec(BoolVec bVec)
Definition: RubySlicc_Util.hh:278
gem5::ruby::addressOffset
int addressOffset(Addr addr, Addr base)
Definition: RubySlicc_Util.hh:182
gem5::ruby::DataBlock
Definition: DataBlock.hh:60
gem5::ruby::max_tokens
int max_tokens()
Definition: RubySlicc_Util.hh:107
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:781
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::ruby::mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:102
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:791
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1184

Generated on Wed May 4 2022 12:14:01 for gem5 by doxygen 1.8.17