2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
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.
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.
31 * These are the functions that exported to slicc from ruby.
34 #ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
35 #define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__
39 #include "debug/RubySlicc.hh"
40 #include "mem/packet.hh"
41 #include "mem/ruby/common/Address.hh"
42 #include "mem/ruby/common/BoolVec.hh"
43 #include "mem/ruby/common/DataBlock.hh"
44 #include "mem/ruby/common/TypeDefines.hh"
45 #include "mem/ruby/common/WriteMask.hh"
47 inline Cycles zero_time() { return Cycles(0); }
64 addressToInt(Addr addr)
66 assert(!(addr & 0xffffffff00000000));
71 intToAddress(int addr)
73 assert(!(addr & 0xffffffff00000000));
83 inline int max_tokens()
89 * This function accepts an address, a data block and a packet. If the address
90 * range for the data block contains the address which the packet needs to
91 * read, then the data from the data block is written to the packet. True is
92 * returned if the data block was read, otherwise false is returned.
94 * This is used during a functional access "search the world" operation. The
95 * functional access looks in every place that might hold a valid data block
96 * and, if it finds one, checks to see if it is holding the address the access
97 * is searching for. During the access check, the WriteMask could be in any
98 * state, including empty.
101 testAndRead(Addr addr, DataBlock& blk, Packet *pkt)
103 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
104 Addr lineAddr = makeLineAddress(addr);
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;
111 for (unsigned i = 0; i < size_in_bytes; ++i) {
112 data[i] = blk.getByte(i + startByte);
120 * This function accepts an address, a data block, a write mask and a packet.
121 * If the valid address range for the data block contains the address which
122 * the packet needs to read, then the data from the data block is written to
123 * the packet. True is returned if any part of the data block was read,
124 * otherwise false is returned.
127 testAndReadMask(Addr addr, DataBlock& blk, WriteMask& mask, Packet *pkt)
129 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
130 Addr lineAddr = makeLineAddress(addr);
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;
138 for (unsigned i = 0; i < size_in_bytes; ++i) {
139 if (mask.test(i + startByte)) {
141 data[i] = blk.getByte(i + startByte);
150 * This function accepts an address, a data block and a packet. If the address
151 * range for the data block contains the address which the packet needs to
152 * write, then the data from the packet is written to the data block. True is
153 * returned if the data block was written, otherwise false is returned.
156 testAndWrite(Addr addr, DataBlock& blk, Packet *pkt)
158 Addr pktLineAddr = makeLineAddress(pkt->getAddr());
159 Addr lineAddr = makeLineAddress(addr);
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;
166 for (unsigned i = 0; i < size_in_bytes; ++i) {
167 blk.setByte(i + startByte, data[i]);
175 countBoolVec(BoolVec bVec)
178 for (const auto &it: bVec) {
186 #endif //__MEM_RUBY_SLICC_INTERFACE_RUBYSLICC_UTIL_HH__