2 * Copyright (c) 1999 Mark D. Hill and David A. Wood
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.
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.
33 #include "mem/ruby/common/Global.hh"
34 #include "mem/ruby/config/RubyConfig.hh"
35 #include "mem/ruby/system/NodeID.hh"
36 #include "mem/ruby/system/MachineID.hh"
38 const int ADDRESS_WIDTH = 64; // address width in bytes
41 typedef Address PhysAddress;
42 typedef Address VirtAddress;
47 Address() { m_address = 0; }
48 explicit Address(physical_address_t address) { m_address = address; }
50 Address(const Address& obj);
51 Address& operator=(const Address& obj);
58 void setAddress(physical_address_t address) { m_address = address; }
59 physical_address_t getAddress() const {return m_address;}
60 // selects bits inclusive
61 physical_address_t bitSelect(int small, int big) const;
62 physical_address_t maskLowOrderBits(int number) const;
63 physical_address_t maskHighOrderBits(int number) const;
64 physical_address_t shiftLowOrderBits(int number) const;
65 physical_address_t getLineAddress() const
66 { return bitSelect(RubyConfig::dataBlockBits(), ADDRESS_WIDTH); }
67 physical_address_t getOffset() const
68 { return bitSelect(0, RubyConfig::dataBlockBits()-1); }
70 void makeLineAddress() { m_address = maskLowOrderBits(RubyConfig::dataBlockBits()); }
71 // returns the next stride address based on line address
72 void makeNextStrideAddress( int stride) {
73 m_address = maskLowOrderBits(RubyConfig::dataBlockBits())
74 + RubyConfig::dataBlockBytes()*stride;
76 void makePageAddress() { m_address = maskLowOrderBits(RubyConfig::pageSizeBits()); }
77 int getBankSetNum() const;
78 int getBankSetDist() const;
80 Index memoryModuleIndex() const;
82 void print(ostream& out) const;
83 void output(ostream& out) const;
84 void input(istream& in);
86 void setOffset( int offset ){
87 // first, zero out the offset bits
89 m_address |= (physical_address_t) offset;
95 // Private copy constructor and assignment operator
96 // Address(const Address& obj);
97 // Address& operator=(const Address& obj);
99 // Data Members (m_ prefix)
100 physical_address_t m_address;
104 Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
107 Address next_stride_address(const Address& addr, int stride) {
109 temp.makeNextStrideAddress(stride);
110 temp.setAddress(temp.maskHighOrderBits(ADDRESS_WIDTH-RubyConfig::memorySizeBits())); // surpress wrap-around problem
115 Address page_address(const Address& addr) { Address temp(addr); temp.makePageAddress(); return temp; }
117 // Output operator declaration
118 ostream& operator<<(ostream& out, const Address& obj);
119 // comparison operator declaration
120 bool operator==(const Address& obj1, const Address& obj2);
121 bool operator!=(const Address& obj1, const Address& obj2);
122 bool operator<(const Address& obj1, const Address& obj2);
123 /* Address& operator=(const physical_address_t address); */
126 bool operator<(const Address& obj1, const Address& obj2)
128 return obj1.getAddress() < obj2.getAddress();
131 // ******************* Definitions *******************
133 // Output operator definition
135 ostream& operator<<(ostream& out, const Address& obj)
143 bool operator==(const Address& obj1, const Address& obj2)
145 return (obj1.getAddress() == obj2.getAddress());
149 bool operator!=(const Address& obj1, const Address& obj2)
151 return (obj1.getAddress() != obj2.getAddress());
155 physical_address_t Address::bitSelect(int small, int big) const // rips bits inclusive
157 physical_address_t mask;
158 assert(big >= small);
160 if (big >= ADDRESS_WIDTH - 1) {
161 return (m_address >> small);
163 mask = ~((physical_address_t)~0 << (big + 1));
164 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
165 physical_address_t partial = (m_address & mask);
166 return (partial >> small);
171 physical_address_t Address::maskLowOrderBits(int number) const
173 physical_address_t mask;
175 if (number >= ADDRESS_WIDTH - 1) {
178 mask = (physical_address_t)~0 << number;
180 return (m_address & mask);
184 physical_address_t Address::maskHighOrderBits(int number) const
186 physical_address_t mask;
188 if (number >= ADDRESS_WIDTH - 1) {
191 mask = (physical_address_t)~0 >> number;
193 return (m_address & mask);
197 physical_address_t Address::shiftLowOrderBits(int number) const
199 return (m_address >> number);
203 integer_t Address::memoryModuleIndex() const
205 integer_t index = bitSelect(RubyConfig::dataBlockBits()+RubyConfig::memoryBits(), ADDRESS_WIDTH);
207 if (index >= RubyConfig::memoryModuleBlocks()) {
208 cerr << " memoryBits: " << RubyConfig::memoryBits() << " memorySizeBits: " << RubyConfig::memorySizeBits()
209 << " Address: " << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubyConfig::dataBlockBits()) << dec << "]" << flush
210 << "error: limit exceeded. " <<
211 " dataBlockBits: " << RubyConfig::dataBlockBits() <<
212 " memoryModuleBlocks: " << RubyConfig::memoryModuleBlocks() <<
213 " index: " << index << endl;
215 assert (index < RubyConfig::memoryModuleBlocks());
218 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
219 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
221 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
224 Round-robin mapping of addresses, at page size granularity
226 ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
229 -----------------------------------------------------------------------
230 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
231 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
232 -----------------------------------------------------------------------
233 indexHighPortion indexLowPortion
235 NUMBER_OF_MEMORY_MODULE_BITS
240 void Address::print(ostream& out) const
242 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubyConfig::dataBlockBits()) << dec << "]" << flush;
246 namespace __gnu_cxx {
247 template <> struct hash<Address>
249 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); }
253 template <> struct equal_to<Address>
255 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; }