3 * Copyright (c) 1999 by Mark Hill and David Wood for the Wisconsin
4 * Multifacet Project. ALL RIGHTS RESERVED.
8 * This software is furnished under a license and may be used and
9 * copied only in accordance with the terms of such license and the
10 * inclusion of the above copyright notice. This software or any
11 * other copies thereof or any derivative works may not be provided or
12 * otherwise made available to any other persons. Title to and
13 * ownership of the software is retained by Mark Hill and David Wood.
14 * Any use of this software must include the above copyright notice.
16 * THIS SOFTWARE IS PROVIDED "AS IS". THE LICENSOR MAKES NO
17 * WARRANTIES ABOUT ITS CORRECTNESS OR PERFORMANCE.
29 #include "RubyConfig.hh"
31 #include "MachineID.hh"
33 const int ADDRESS_WIDTH = 64; // address width in bytes
36 typedef Address PhysAddress;
37 typedef Address VirtAddress;
42 Address() { m_address = 0; }
43 explicit Address(physical_address_t address) { m_address = address; }
45 Address(const Address& obj);
46 Address& operator=(const Address& obj);
53 void setAddress(physical_address_t address) { m_address = address; }
54 physical_address_t getAddress() const {return m_address;}
55 // selects bits inclusive
56 physical_address_t bitSelect(int small, int big) const;
57 physical_address_t maskLowOrderBits(int number) const;
58 physical_address_t maskHighOrderBits(int number) const;
59 physical_address_t shiftLowOrderBits(int number) const;
60 physical_address_t getLineAddress() const
61 { return bitSelect(RubyConfig::dataBlockBits(), ADDRESS_WIDTH); }
62 physical_address_t getOffset() const
63 { return bitSelect(0, RubyConfig::dataBlockBits()-1); }
65 void makeLineAddress() { m_address = maskLowOrderBits(RubyConfig::dataBlockBits()); }
66 // returns the next stride address based on line address
67 void makeNextStrideAddress( int stride) {
68 m_address = maskLowOrderBits(RubyConfig::dataBlockBits())
69 + RubyConfig::dataBlockBytes()*stride;
71 void makePageAddress() { m_address = maskLowOrderBits(RubyConfig::pageSizeBits()); }
72 int getBankSetNum() const;
73 int getBankSetDist() const;
75 Index memoryModuleIndex() const;
77 void print(ostream& out) const;
78 void output(ostream& out) const;
79 void input(istream& in);
81 void setOffset( int offset ){
82 // first, zero out the offset bits
84 m_address |= (physical_address_t) offset;
90 // Private copy constructor and assignment operator
91 // Address(const Address& obj);
92 // Address& operator=(const Address& obj);
94 // Data Members (m_ prefix)
95 physical_address_t m_address;
99 Address line_address(const Address& addr) { Address temp(addr); temp.makeLineAddress(); return temp; }
102 Address next_stride_address(const Address& addr, int stride) {
104 temp.makeNextStrideAddress(stride);
105 temp.setAddress(temp.maskHighOrderBits(ADDRESS_WIDTH-RubyConfig::memorySizeBits())); // surpress wrap-around problem
110 Address page_address(const Address& addr) { Address temp(addr); temp.makePageAddress(); 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(big >= 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(RubyConfig::dataBlockBits()+RubyConfig::memoryBits(), ADDRESS_WIDTH);
202 if (index >= RubyConfig::memoryModuleBlocks()) {
203 cerr << " memoryBits: " << RubyConfig::memoryBits() << " memorySizeBits: " << RubyConfig::memorySizeBits()
204 << " Address: " << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubyConfig::dataBlockBits()) << dec << "]" << flush
205 << "error: limit exceeded. " <<
206 " dataBlockBits: " << RubyConfig::dataBlockBits() <<
207 " memoryModuleBlocks: " << RubyConfig::memoryModuleBlocks() <<
208 " index: " << index << endl;
210 assert (index < RubyConfig::memoryModuleBlocks());
213 // Index indexHighPortion = address.bitSelect(MEMORY_SIZE_BITS-1, PAGE_SIZE_BITS+NUMBER_OF_MEMORY_MODULE_BITS);
214 // Index indexLowPortion = address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS-1);
216 //Index index = indexLowPortion | (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
219 Round-robin mapping of addresses, at page size granularity
221 ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
224 -----------------------------------------------------------------------
225 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
226 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
227 -----------------------------------------------------------------------
228 indexHighPortion indexLowPortion
230 NUMBER_OF_MEMORY_MODULE_BITS
235 void Address::print(ostream& out) const
237 out << "[" << hex << "0x" << m_address << "," << " line 0x" << maskLowOrderBits(RubyConfig::dataBlockBits()) << dec << "]" << flush;
241 namespace __gnu_cxx {
242 template <> struct hash<Address>
244 size_t operator()(const Address &s) const { return (size_t) s.getAddress(); }
248 template <> struct equal_to<Address>
250 bool operator()(const Address& s1, const Address& s2) const { return s1 == s2; }