Address.cc revision 8091
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 296154Snate@binkert.org#include "mem/ruby/common/Address.hh" 308091Snilay@cs.wisc.edu#include "mem/ruby/system/System.hh" 318091Snilay@cs.wisc.edu 328091Snilay@cs.wisc.eduphysical_address_t 338091Snilay@cs.wisc.eduAddress::getLineAddress() const 348091Snilay@cs.wisc.edu{ 358091Snilay@cs.wisc.edu return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH); 368091Snilay@cs.wisc.edu} 378091Snilay@cs.wisc.edu 388091Snilay@cs.wisc.eduphysical_address_t 398091Snilay@cs.wisc.eduAddress::getOffset() const 408091Snilay@cs.wisc.edu{ 418091Snilay@cs.wisc.edu return bitSelect(0, RubySystem::getBlockSizeBits() - 1); 428091Snilay@cs.wisc.edu} 438091Snilay@cs.wisc.edu 448091Snilay@cs.wisc.eduvoid 458091Snilay@cs.wisc.eduAddress::makeLineAddress() 468091Snilay@cs.wisc.edu{ 478091Snilay@cs.wisc.edu m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()); 488091Snilay@cs.wisc.edu} 498091Snilay@cs.wisc.edu 508091Snilay@cs.wisc.edu// returns the next stride address based on line address 518091Snilay@cs.wisc.eduvoid 528091Snilay@cs.wisc.eduAddress::makeNextStrideAddress(int stride) 538091Snilay@cs.wisc.edu{ 548091Snilay@cs.wisc.edu m_address = maskLowOrderBits(RubySystem::getBlockSizeBits()) 558091Snilay@cs.wisc.edu + RubySystem::getBlockSizeBytes()*stride; 568091Snilay@cs.wisc.edu} 578091Snilay@cs.wisc.edu 588091Snilay@cs.wisc.eduinteger_t 598091Snilay@cs.wisc.eduAddress::memoryModuleIndex() const 608091Snilay@cs.wisc.edu{ 618091Snilay@cs.wisc.edu integer_t index = 628091Snilay@cs.wisc.edu bitSelect(RubySystem::getBlockSizeBits() + 638091Snilay@cs.wisc.edu RubySystem::getMemorySizeBits(), ADDRESS_WIDTH); 648091Snilay@cs.wisc.edu assert (index >= 0); 658091Snilay@cs.wisc.edu return index; 668091Snilay@cs.wisc.edu 678091Snilay@cs.wisc.edu // Index indexHighPortion = 688091Snilay@cs.wisc.edu // address.bitSelect(MEMORY_SIZE_BITS - 1, 698091Snilay@cs.wisc.edu // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS); 708091Snilay@cs.wisc.edu // Index indexLowPortion = 718091Snilay@cs.wisc.edu // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1); 728091Snilay@cs.wisc.edu // 738091Snilay@cs.wisc.edu // Index index = indexLowPortion | 748091Snilay@cs.wisc.edu // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS)); 758091Snilay@cs.wisc.edu 768091Snilay@cs.wisc.edu /* 778091Snilay@cs.wisc.edu Round-robin mapping of addresses, at page size granularity 788091Snilay@cs.wisc.edu 798091Snilay@cs.wisc.eduADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS 808091Snilay@cs.wisc.edu | | | | 818091Snilay@cs.wisc.edu \ / \ / \ / \ / 0 828091Snilay@cs.wisc.edu ----------------------------------------------------------------------- 838091Snilay@cs.wisc.edu | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 848091Snilay@cs.wisc.edu | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| | 858091Snilay@cs.wisc.edu ----------------------------------------------------------------------- 868091Snilay@cs.wisc.edu indexHighPortion indexLowPortion 878091Snilay@cs.wisc.edu <-------> 888091Snilay@cs.wisc.edu NUMBER_OF_MEMORY_MODULE_BITS 898091Snilay@cs.wisc.edu */ 908091Snilay@cs.wisc.edu} 918091Snilay@cs.wisc.edu 928091Snilay@cs.wisc.eduvoid 938091Snilay@cs.wisc.eduAddress::print(std::ostream& out) const 948091Snilay@cs.wisc.edu{ 958091Snilay@cs.wisc.edu using namespace std; 968091Snilay@cs.wisc.edu out << "[" << hex << "0x" << m_address << "," << " line 0x" 978091Snilay@cs.wisc.edu << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]" 988091Snilay@cs.wisc.edu << flush; 998091Snilay@cs.wisc.edu} 1006145Snate@binkert.org 1017039Snate@binkert.orgvoid 1027055Snate@binkert.orgAddress::output(std::ostream& out) const 1036145Snate@binkert.org{ 1047039Snate@binkert.org // Note: this outputs addresses in the form "ffff", not "0xffff". 1057039Snate@binkert.org // This code should always be able to write out addresses in a 1067039Snate@binkert.org // format that can be read in by the below input() method. Please 1077039Snate@binkert.org // don't change this without talking to Milo first. 1087055Snate@binkert.org out << std::hex << m_address << std::dec; 1096145Snate@binkert.org} 1106145Snate@binkert.org 1117039Snate@binkert.orgvoid 1127055Snate@binkert.orgAddress::input(std::istream& in) 1136145Snate@binkert.org{ 1147039Snate@binkert.org // Note: this only works with addresses in the form "ffff", not 1157039Snate@binkert.org // "0xffff". This code should always be able to read in addresses 1167039Snate@binkert.org // written out by the above output() method. Please don't change 1177039Snate@binkert.org // this without talking to Milo first. 1187055Snate@binkert.org in >> std::hex >> m_address >> std::dec; 1196145Snate@binkert.org} 1206145Snate@binkert.org 1216145Snate@binkert.orgAddress::Address(const Address& obj) 1226145Snate@binkert.org{ 1237039Snate@binkert.org m_address = obj.m_address; 1246145Snate@binkert.org} 1256145Snate@binkert.org 1267039Snate@binkert.orgAddress& 1277039Snate@binkert.orgAddress::operator=(const Address& obj) 1286145Snate@binkert.org{ 1297039Snate@binkert.org if (this == &obj) { 1307039Snate@binkert.org // assert(false); 1317039Snate@binkert.org } else { 1327039Snate@binkert.org m_address = obj.m_address; 1337039Snate@binkert.org } 1347039Snate@binkert.org return *this; 1356145Snate@binkert.org} 1366145Snate@binkert.org 137