RubySlicc_Util.hh (10563:755b18321206) RubySlicc_Util.hh (10956:19515f842044)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * These are the functions that exported to slicc from ruby.
31 */
32
33#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
34#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
35
36#include <cassert>
37
38#include "debug/RubySlicc.hh"
39#include "mem/ruby/common/Address.hh"
40#include "mem/ruby/common/DataBlock.hh"
41#include "mem/packet.hh"
42
43inline Cycles zero_time() { return Cycles(0); }
44
45inline NodeID
46intToID(int nodenum)
47{
48 NodeID id = nodenum;
49 return id;
50}
51
52inline int
53IDToInt(NodeID id)
54{
55 int nodenum = id;
56 return nodenum;
57}
58
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/*
30 * These are the functions that exported to slicc from ruby.
31 */
32
33#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
34#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
35
36#include <cassert>
37
38#include "debug/RubySlicc.hh"
39#include "mem/ruby/common/Address.hh"
40#include "mem/ruby/common/DataBlock.hh"
41#include "mem/packet.hh"
42
43inline Cycles zero_time() { return Cycles(0); }
44
45inline NodeID
46intToID(int nodenum)
47{
48 NodeID id = nodenum;
49 return id;
50}
51
52inline int
53IDToInt(NodeID id)
54{
55 int nodenum = id;
56 return nodenum;
57}
58
59inline int
60addressToInt(Address addr)
61{
62 assert(!(addr.getAddress() & 0xffffffff00000000));
63
64 return (int)addr.getAddress();
65}
66
59// Appends an offset to an address
60inline Address
61setOffset(Address addr, int offset)
62{
63 Address result = addr;
64 result.setOffset(offset);
65 return result;
66}
67
68// Makes an address into a line address
69inline Address
70makeLineAddress(Address addr)
71{
72 Address result = addr;
73 result.makeLineAddress();
74 return result;
75}
76
77inline int
78addressOffset(Address addr)
79{
80 return addr.getOffset();
81}
82
83inline int
84mod(int val, int mod)
85{
86 return val % mod;
87}
88
89inline int max_tokens()
90{
91 return 1024;
92}
93
94/**
95 * This function accepts an address, a data block and a packet. If the address
96 * range for the data block contains the address which the packet needs to
97 * read, then the data from the data block is written to the packet. True is
98 * returned if the data block was read, otherwise false is returned.
99 */
100inline bool
101testAndRead(Address addr, DataBlock& blk, Packet *pkt)
102{
103 Address pktLineAddr(pkt->getAddr());
104 pktLineAddr.makeLineAddress();
105
106 Address lineAddr = addr;
107 lineAddr.makeLineAddress();
108
109 if (pktLineAddr == lineAddr) {
110 uint8_t *data = pkt->getPtr<uint8_t>();
111 unsigned int size_in_bytes = pkt->getSize();
112 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
113
114 for (unsigned i = 0; i < size_in_bytes; ++i) {
115 data[i] = blk.getByte(i + startByte);
116 }
117 return true;
118 }
119 return false;
120}
121
122/**
123 * This function accepts an address, a data block and a packet. If the address
124 * range for the data block contains the address which the packet needs to
125 * write, then the data from the packet is written to the data block. True is
126 * returned if the data block was written, otherwise false is returned.
127 */
128inline bool
129testAndWrite(Address addr, DataBlock& blk, Packet *pkt)
130{
131 Address pktLineAddr(pkt->getAddr());
132 pktLineAddr.makeLineAddress();
133
134 Address lineAddr = addr;
135 lineAddr.makeLineAddress();
136
137 if (pktLineAddr == lineAddr) {
138 const uint8_t *data = pkt->getConstPtr<uint8_t>();
139 unsigned int size_in_bytes = pkt->getSize();
140 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
141
142 for (unsigned i = 0; i < size_in_bytes; ++i) {
143 blk.setByte(i + startByte, data[i]);
144 }
145 return true;
146 }
147 return false;
148}
149
150#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
67// Appends an offset to an address
68inline Address
69setOffset(Address addr, int offset)
70{
71 Address result = addr;
72 result.setOffset(offset);
73 return result;
74}
75
76// Makes an address into a line address
77inline Address
78makeLineAddress(Address addr)
79{
80 Address result = addr;
81 result.makeLineAddress();
82 return result;
83}
84
85inline int
86addressOffset(Address addr)
87{
88 return addr.getOffset();
89}
90
91inline int
92mod(int val, int mod)
93{
94 return val % mod;
95}
96
97inline int max_tokens()
98{
99 return 1024;
100}
101
102/**
103 * This function accepts an address, a data block and a packet. If the address
104 * range for the data block contains the address which the packet needs to
105 * read, then the data from the data block is written to the packet. True is
106 * returned if the data block was read, otherwise false is returned.
107 */
108inline bool
109testAndRead(Address addr, DataBlock& blk, Packet *pkt)
110{
111 Address pktLineAddr(pkt->getAddr());
112 pktLineAddr.makeLineAddress();
113
114 Address lineAddr = addr;
115 lineAddr.makeLineAddress();
116
117 if (pktLineAddr == lineAddr) {
118 uint8_t *data = pkt->getPtr<uint8_t>();
119 unsigned int size_in_bytes = pkt->getSize();
120 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
121
122 for (unsigned i = 0; i < size_in_bytes; ++i) {
123 data[i] = blk.getByte(i + startByte);
124 }
125 return true;
126 }
127 return false;
128}
129
130/**
131 * This function accepts an address, a data block and a packet. If the address
132 * range for the data block contains the address which the packet needs to
133 * write, then the data from the packet is written to the data block. True is
134 * returned if the data block was written, otherwise false is returned.
135 */
136inline bool
137testAndWrite(Address addr, DataBlock& blk, Packet *pkt)
138{
139 Address pktLineAddr(pkt->getAddr());
140 pktLineAddr.makeLineAddress();
141
142 Address lineAddr = addr;
143 lineAddr.makeLineAddress();
144
145 if (pktLineAddr == lineAddr) {
146 const uint8_t *data = pkt->getConstPtr<uint8_t>();
147 unsigned int size_in_bytes = pkt->getSize();
148 unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
149
150 for (unsigned i = 0; i < size_in_bytes; ++i) {
151 blk.setByte(i + startByte, data[i]);
152 }
153 return true;
154 }
155 return false;
156}
157
158#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__