gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RubySlicc_Util.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * These are the functions that exported to slicc from ruby.
32  */
33 
34 #ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
35 #define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
36 
37 #include <cassert>
38 
39 #include "debug/RubySlicc.hh"
40 #include "mem/packet.hh"
46 
47 inline Cycles zero_time() { return Cycles(0); }
48 
49 inline NodeID
50 intToID(int nodenum)
51 {
52  NodeID id = nodenum;
53  return id;
54 }
55 
56 inline int
58 {
59  int nodenum = id;
60  return nodenum;
61 }
62 
63 inline int
65 {
66  assert(!(addr & 0xffffffff00000000));
67  return addr;
68 }
69 
70 inline Addr
72 {
73  assert(!(addr & 0xffffffff00000000));
74  return addr;
75 }
76 
77 inline int
78 mod(int val, int mod)
79 {
80  return val % mod;
81 }
82 
83 inline int max_tokens()
84 {
85  return 1024;
86 }
87 
100 inline bool
102 {
103  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
104  Addr lineAddr = makeLineAddress(addr);
105 
106  if (pktLineAddr == lineAddr) {
107  uint8_t *data = pkt->getPtr<uint8_t>();
108  unsigned int size_in_bytes = pkt->getSize();
109  unsigned startByte = pkt->getAddr() - lineAddr;
110 
111  for (unsigned i = 0; i < size_in_bytes; ++i) {
112  data[i] = blk.getByte(i + startByte);
113  }
114  return true;
115  }
116  return false;
117 }
118 
126 inline bool
128 {
129  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
130  Addr lineAddr = makeLineAddress(addr);
131 
132  if (pktLineAddr == lineAddr) {
133  uint8_t *data = pkt->getPtr<uint8_t>();
134  unsigned int size_in_bytes = pkt->getSize();
135  unsigned startByte = pkt->getAddr() - lineAddr;
136  bool was_read = false;
137 
138  for (unsigned i = 0; i < size_in_bytes; ++i) {
139  if (mask.test(i + startByte)) {
140  was_read = true;
141  data[i] = blk.getByte(i + startByte);
142  }
143  }
144  return was_read;
145  }
146  return false;
147 }
148 
155 inline bool
157 {
158  Addr pktLineAddr = makeLineAddress(pkt->getAddr());
159  Addr lineAddr = makeLineAddress(addr);
160 
161  if (pktLineAddr == lineAddr) {
162  const uint8_t *data = pkt->getConstPtr<uint8_t>();
163  unsigned int size_in_bytes = pkt->getSize();
164  unsigned startByte = pkt->getAddr() - lineAddr;
165 
166  for (unsigned i = 0; i < size_in_bytes; ++i) {
167  blk.setByte(i + startByte, data[i]);
168  }
169  return true;
170  }
171  return false;
172 }
173 
174 inline int
176 {
177  int count = 0;
178  for (const auto &it: bVec) {
179  if (it) {
180  count++;
181  }
182  }
183  return count;
184 }
185 
186 #endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
count
Definition: misc.hh:704
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Bitfield< 7 > i
Definition: miscregs.hh:1378
int max_tokens()
int addressToInt(Addr addr)
ip6_addr_t addr
Definition: inet.hh:335
uint8_t getByte(int whichByte) const
Definition: DataBlock.hh:90
bool testAndReadMask(Addr addr, DataBlock &blk, WriteMask &mask, Packet *pkt)
This function accepts an address, a data block, a write mask and a packet.
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:959
void setByte(int whichByte, uint8_t data)
Definition: DataBlock.hh:96
Bitfield< 63 > val
Definition: misc.hh:770
const char data[]
Definition: circlebuf.cc:43
unsigned int NodeID
Definition: TypeDefines.hh:34
int mod(int val, int mod)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
NodeID intToID(int nodenum)
int IDToInt(NodeID id)
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
Addr makeLineAddress(Addr addr)
Definition: Address.cc:112
Declaration of the Packet class.
bool testAndWrite(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
bool testAndRead(Addr addr, DataBlock &blk, Packet *pkt)
This function accepts an address, a data block and a packet.
bool test(int offset)
Definition: WriteMask.hh:71
Cycles zero_time()
Bitfield< 3, 0 > mask
Definition: types.hh:64
Addr intToAddress(int addr)
const T * getConstPtr() const
Definition: packet.hh:967
unsigned getSize() const
Definition: packet.hh:649
Bitfield< 11 > id
Definition: miscregs.hh:124
int countBoolVec(BoolVec bVec)
Addr getAddr() const
Definition: packet.hh:639

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6