3 * Copyright (c) 1999 Mark D. Hill and David A. Wood
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.
39 #include "base/hashmap.hh"
40 #include "mem/ruby/common/Global.hh"
41 #include "mem/ruby/system/System.hh"
42 #include "mem/ruby/system/NodeID.hh"
43 #include "mem/ruby/system/MachineID.hh"
45 const int ADDRESS_WIDTH = 64; // address width in bytes
48 typedef Address PhysAddress;
49 typedef Address VirtAddress;
54 Address() { m_address = 0; }
55 explicit Address(physical_address_t address) { m_address = address; }
57 Address(const Address& obj);
58 Address& operator=(const Address& obj);
65 void setAddress(physical_address_t address) { m_address = address; }
66 physical_address_t getAddress() const {return m_address;}
67 // selects bits inclusive
68 physical_address_t bitSelect(int small, int big) const;
69 physical_address_t maskLowOrderBits(int number) const;
70 physical_address_t maskHighOrderBits(int number) const;
71 physical_address_t shiftLowOrderBits(int number) const;
72 physical_address_t getLineAddress() const
73 { return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); }
74 physical_address_t getOffset() const
75 { return bitSelect(0, RubySystem::getBlockSizeBits()-1); }
77 void makeLineAddress() { m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); }
78 // returns the next stride address based on line address
79 void makeNextStrideAddress( int stride) {
80 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
81 + RubySystem::getBlockSizeBytes()*stride;
83 int getBankSetNum() const;
84 int getBankSetDist() const;
86 Index memoryModuleIndex() const;
88 void print(ostream& out) const;
89 void output(ostream& out) const;
90 void input(istream& in);
92 void setOffset( int offset ){
93 // first, zero out the offset bits
95 m_address |= (physical_address_t) offset;
101 // Private copy constructor and assignment operator
102 // Address(const Address& obj);
103 // Address& operator=(const Address& obj);
105 // Data Members (m_ prefix)
106 physical_address_t m_address;
110 Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
112 // Output operator declaration
113 ostream& operator<<(ostream& out, const Address& obj);
114 // comparison operator declaration
115 bool operator==(const Address& obj1, const Address& obj2);
116 bool operator!=(const Address& obj1, const Address& obj2);
117 bool operator<(const Address& obj1, const Address& obj2);
118 /* Address& operator=(const physical_address_t address); */
121 bool operator<(const Address& obj1, const Address& obj2)
123 return obj1.getAddress() < obj2.getAddress();
126 // ******************* Definitions *******************
128 // Output operator definition
130 ostream& operator<<(ostream& out, const Address& obj)
138 bool operator==(const Address& obj1, const Address& obj2)
140 return (obj1.getAddress() == obj2.getAddress());
144 bool operator!=(const Address& obj1, const Address& obj2)
146 return (obj1.getAddress() != obj2.getAddress());
150 physical_address_t Address::bitSelect(int small, int big) const // rips bits inclusive
152 physical_address_t mask;
153 assert((unsigned)big >= (unsigned)small);
155 if (big >= ADDRESS_WIDTH - 1) {
156 return (m_address >> small);
158 mask = ~((physical_address_t)~0 << (big + 1));
159 // FIXME - this is slow to manipulate a 64-bit number using 32-bits
160 physical_address_t partial = (m_address & mask);
161 return (partial >> small);
166 physical_address_t Address::maskLowOrderBits(int number) const
168 physical_address_t mask;
170 if (number >= ADDRESS_WIDTH - 1) {
173 mask = (physical_address_t)~0 << number;
175 return (m_address & mask);
179 physical_address_t Address::maskHighOrderBits(int number) const
181 physical_address_t mask;
183 if (number >= ADDRESS_WIDTH - 1) {
186 mask = (physical_address_t)~0 >> number;
188 return (m_address & mask);
192 physical_address_t Address::shiftLowOrderBits(int number) const
194 return (m_address >> number);
198 integer_t Address::memoryModuleIndex() const
200 integer_t index = bitSelect(RubySystem::getBlockSizeBits()+RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
204 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
205 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
207 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
210 Round-robin mapping of addresses, at page size granularity
212 ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
215 -----------------------------------------------------------------------
216 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
217 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
218 -----------------------------------------------------------------------
219 indexHighPortion indexLowPortion
221 NUMBER_OF_MEMORY_MODULE_BITS
226 void Address::print(ostream& out) const
229 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" << flush;
233 namespace __hash_namespace {
234 template <> struct hash<Address>
236 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); }
240 template <> struct equal_to<Address>
242 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; }