gem5  v20.1.0.0
RubySlicc_Util.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 
51 #include "debug/RubySlicc.hh"
52 #include "mem/packet.hh"
58 
59 inline Cycles zero_time() { return Cycles(0); }
60 
61 inline NodeID
62 intToID(int nodenum)
63 {
64  NodeID id = nodenum;
65  return id;
66 }
67 
68 inline int
70 {
71  int nodenum = id;
72  return nodenum;
73 }
74 
75 inline int
77 {
78  assert(!(addr & 0xffffffff00000000));
79  return addr;
80 }
81 
82 inline Addr
84 {
85  assert(!(addr & 0xffffffff00000000));
86  return addr;
87 }
88 
89 inline int
90 mod(int val, int mod)
91 {
92  return val % mod;
93 }
94 
95 inline int max_tokens()
96 {
97  return 1024;
98 }
99 
100 inline bool
101 isWriteRequest(RubyRequestType type)
102 {
103  if ((type == RubyRequestType_ST) ||
104  (type == RubyRequestType_ATOMIC) ||
105  (type == RubyRequestType_RMW_Read) ||
106  (type == RubyRequestType_RMW_Write) ||
107  (type == RubyRequestType_Store_Conditional) ||
108  (type == RubyRequestType_Locked_RMW_Read) ||
109  (type == RubyRequestType_Locked_RMW_Write) ||
110  (type == RubyRequestType_FLUSH)) {
111  return true;
112  } else {
113  return false;
114  }
115 }
116 
117 inline bool
118 isDataReadRequest(RubyRequestType type)
119 {
120  if ((type == RubyRequestType_LD) ||
121  (type == RubyRequestType_Load_Linked)) {
122  return true;
123  } else {
124  return false;
125  }
126 }
127 
128 inline bool
129 isReadRequest(RubyRequestType type)
130 {
131  if (isDataReadRequest(type) ||
132  (type == RubyRequestType_IFETCH)) {
133  return true;
134  } else {
135  return false;
136  }
137 }
138 
139 inline bool
140 isHtmCmdRequest(RubyRequestType type)
141 {
142  if ((type == RubyRequestType_HTM_Start) ||
143  (type == RubyRequestType_HTM_Commit) ||
144  (type == RubyRequestType_HTM_Cancel) ||
145  (type == RubyRequestType_HTM_Abort)) {
146  return true;
147  } else {
148  return false;
149  }
150 }
151 
152 inline RubyRequestType
154 {
155  if (pkt->req->isHTMStart()) {
156  return RubyRequestType_HTM_Start;
157  } else if (pkt->req->isHTMCommit()) {
158  return RubyRequestType_HTM_Commit;
159  } else if (pkt->req->isHTMCancel()) {
160  return RubyRequestType_HTM_Cancel;
161  } else if (pkt->req->isHTMAbort()) {
162  return RubyRequestType_HTM_Abort;
163  }
164  else {
165  panic("invalid ruby packet type\n");
166  }
167 }
168 
181 inline bool
183 {
184  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
185  Addr lineAddr = makeLineAddress(addr);
186 
187  if (pktLineAddr == lineAddr) {
188  uint8_t *data = pkt->getPtr<uint8_t>();
189  unsigned int size_in_bytes = pkt->getSize();
190  unsigned startByte = pkt->getAddr() - lineAddr;
191 
192  for (unsigned i = 0; i < size_in_bytes; ++i) {
193  data[i] = blk.getByte(i + startByte);
194  }
195  return true;
196  }
197  return false;
198 }
199 
207 inline bool
209 {
210  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
211  Addr lineAddr = makeLineAddress(addr);
212 
213  if (pktLineAddr == lineAddr) {
214  uint8_t *data = pkt->getPtr<uint8_t>();
215  unsigned int size_in_bytes = pkt->getSize();
216  unsigned startByte = pkt->getAddr() - lineAddr;
217  bool was_read = false;
218 
219  for (unsigned i = 0; i < size_in_bytes; ++i) {
220  if (mask.test(i + startByte)) {
221  was_read = true;
222  data[i] = blk.getByte(i + startByte);
223  }
224  }
225  return was_read;
226  }
227  return false;
228 }
229 
236 inline bool
238 {
239  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
240  Addr lineAddr = makeLineAddress(addr);
241 
242  if (pktLineAddr == lineAddr) {
243  const uint8_t *data = pkt->getConstPtr<uint8_t>();
244  unsigned int size_in_bytes = pkt->getSize();
245  unsigned startByte = pkt->getAddr() - lineAddr;
246 
247  for (unsigned i = 0; i < size_in_bytes; ++i) {
248  blk.setByte(i + startByte, data[i]);
249  }
250  return true;
251  }
252  return false;
253 }
254 
255 inline int
257 {
258  int count = 0;
259  for (const bool e: bVec) {
260  if (e) {
261  count++;
262  }
263  }
264  return count;
265 }
266 
267 #endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
data
const char data[]
Definition: circlebuf.test.cc:42
htmCmdToRubyRequestType
RubyRequestType htmCmdToRubyRequestType(const Packet *pkt)
Definition: RubySlicc_Util.hh:153
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
mod
int mod(int val, int mod)
Definition: RubySlicc_Util.hh:90
type
uint8_t type
Definition: inet.hh:421
Packet::req
RequestPtr req
A pointer to the original request.
Definition: packet.hh:340
std::vector< bool >
BoolVec.hh
Packet::getSize
unsigned getSize() const
Definition: packet.hh:764
X86ISA::count
count
Definition: misc.hh:703
max_tokens
int max_tokens()
Definition: RubySlicc_Util.hh:95
testAndRead
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:182
DataBlock
Definition: DataBlock.hh:40
packet.hh
addressToInt
int addressToInt(Addr addr)
Definition: RubySlicc_Util.hh:76
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:208
isWriteRequest
bool isWriteRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:101
countBoolVec
int countBoolVec(BoolVec bVec)
Definition: RubySlicc_Util.hh:256
DataBlock::setByte
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:96
testAndWrite
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
Definition: RubySlicc_Util.hh:237
DataBlock.hh
TypeDefines.hh
WriteMask.hh
intToAddress
Addr intToAddress(int addr)
Definition: RubySlicc_Util.hh:83
isDataReadRequest
bool isDataReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:118
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:142
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
isReadRequest
bool isReadRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:129
DataBlock::getByte
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:90
IDToInt
int IDToInt(NodeID id)
Definition: RubySlicc_Util.hh:69
Address.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
zero_time
Cycles zero_time()
Definition: RubySlicc_Util.hh:59
addr
ip6_addr_t addr
Definition: inet.hh:423
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
intToID
NodeID intToID(int nodenum)
Definition: RubySlicc_Util.hh:62
Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1157
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1166
WriteMask
Definition: WriteMask.hh:40
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
isHtmCmdRequest
bool isHtmCmdRequest(RubyRequestType type)
Definition: RubySlicc_Util.hh:140

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