Address.cc revision 10318:98771a936b61
113759Sgiacomo.gabrielli@arm.com/*
213759Sgiacomo.gabrielli@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
313759Sgiacomo.gabrielli@arm.com * All rights reserved.
413759Sgiacomo.gabrielli@arm.com *
513759Sgiacomo.gabrielli@arm.com * Redistribution and use in source and binary forms, with or without
613759Sgiacomo.gabrielli@arm.com * modification, are permitted provided that the following conditions are
713759Sgiacomo.gabrielli@arm.com * met: redistributions of source code must retain the above copyright
813759Sgiacomo.gabrielli@arm.com * notice, this list of conditions and the following disclaimer;
913759Sgiacomo.gabrielli@arm.com * redistributions in binary form must reproduce the above copyright
1013759Sgiacomo.gabrielli@arm.com * notice, this list of conditions and the following disclaimer in the
1113759Sgiacomo.gabrielli@arm.com * documentation and/or other materials provided with the distribution;
1213759Sgiacomo.gabrielli@arm.com * neither the name of the copyright holders nor the names of its
1313759Sgiacomo.gabrielli@arm.com * contributors may be used to endorse or promote products derived from
1413759Sgiacomo.gabrielli@arm.com * this software without specific prior written permission.
1513759Sgiacomo.gabrielli@arm.com *
1613759Sgiacomo.gabrielli@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713759Sgiacomo.gabrielli@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813759Sgiacomo.gabrielli@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913759Sgiacomo.gabrielli@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013759Sgiacomo.gabrielli@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113759Sgiacomo.gabrielli@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213759Sgiacomo.gabrielli@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313759Sgiacomo.gabrielli@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413759Sgiacomo.gabrielli@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513759Sgiacomo.gabrielli@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613759Sgiacomo.gabrielli@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713759Sgiacomo.gabrielli@arm.com */
2813759Sgiacomo.gabrielli@arm.com
2913759Sgiacomo.gabrielli@arm.com#include "arch/isa_traits.hh"
3013759Sgiacomo.gabrielli@arm.com#include "config/the_isa.hh"
3113759Sgiacomo.gabrielli@arm.com#include "mem/ruby/common/Address.hh"
3213759Sgiacomo.gabrielli@arm.com#include "mem/ruby/system/System.hh"
3313759Sgiacomo.gabrielli@arm.com
3413759Sgiacomo.gabrielli@arm.comphysical_address_t
3513759Sgiacomo.gabrielli@arm.comAddress::getLineAddress() const
3613759Sgiacomo.gabrielli@arm.com{
3713759Sgiacomo.gabrielli@arm.com    return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH);
3813759Sgiacomo.gabrielli@arm.com}
3913759Sgiacomo.gabrielli@arm.com
4013759Sgiacomo.gabrielli@arm.comphysical_address_t
4113955Sgiacomo.gabrielli@arm.comAddress::getOffset() const
4213759Sgiacomo.gabrielli@arm.com{
4313759Sgiacomo.gabrielli@arm.com    return bitSelect(0, RubySystem::getBlockSizeBits() - 1);
4413759Sgiacomo.gabrielli@arm.com}
4513759Sgiacomo.gabrielli@arm.com
4613759Sgiacomo.gabrielli@arm.comvoid
4713759Sgiacomo.gabrielli@arm.comAddress::makeLineAddress()
4813759Sgiacomo.gabrielli@arm.com{
4913759Sgiacomo.gabrielli@arm.com    m_address = maskLowOrderBits(RubySystem::getBlockSizeBits());
5013759Sgiacomo.gabrielli@arm.com}
5113759Sgiacomo.gabrielli@arm.com
5213759Sgiacomo.gabrielli@arm.com// returns the next stride address based on line address
5313759Sgiacomo.gabrielli@arm.comvoid
5413759Sgiacomo.gabrielli@arm.comAddress::makeNextStrideAddress(int stride)
5513759Sgiacomo.gabrielli@arm.com{
5613759Sgiacomo.gabrielli@arm.com    m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
5713759Sgiacomo.gabrielli@arm.com        + RubySystem::getBlockSizeBytes()*stride;
5813759Sgiacomo.gabrielli@arm.com}
5913759Sgiacomo.gabrielli@arm.com
6013759Sgiacomo.gabrielli@arm.comint64
6113759Sgiacomo.gabrielli@arm.comAddress::memoryModuleIndex() const
6213759Sgiacomo.gabrielli@arm.com{
6313759Sgiacomo.gabrielli@arm.com    int64 index =
6413759Sgiacomo.gabrielli@arm.com        bitSelect(RubySystem::getBlockSizeBits() +
6513759Sgiacomo.gabrielli@arm.com                  RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
6613759Sgiacomo.gabrielli@arm.com    assert (index >= 0);
6713759Sgiacomo.gabrielli@arm.com    return index;
6813759Sgiacomo.gabrielli@arm.com
6913759Sgiacomo.gabrielli@arm.com    // int64 indexHighPortion =
7013759Sgiacomo.gabrielli@arm.com    //     address.bitSelect(MEMORY_SIZE_BITS - 1,
7113759Sgiacomo.gabrielli@arm.com    //                       PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS);
7213759Sgiacomo.gabrielli@arm.com    // int64 indexLowPortion =
7313759Sgiacomo.gabrielli@arm.com    //     address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1);
7413759Sgiacomo.gabrielli@arm.com    //
7513759Sgiacomo.gabrielli@arm.com    // int64 index = indexLowPortion |
7613759Sgiacomo.gabrielli@arm.com    //     (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
7713759Sgiacomo.gabrielli@arm.com
7813759Sgiacomo.gabrielli@arm.com    /*
7913759Sgiacomo.gabrielli@arm.com      Round-robin mapping of addresses, at page size granularity
8013759Sgiacomo.gabrielli@arm.com
8113759Sgiacomo.gabrielli@arm.comADDRESS_WIDTH    MEMORY_SIZE_BITS        PAGE_SIZE_BITS  DATA_BLOCK_BITS
8213759Sgiacomo.gabrielli@arm.com  |                    |                       |               |
8313759Sgiacomo.gabrielli@arm.com \ /                  \ /                     \ /             \ /       0
8413759Sgiacomo.gabrielli@arm.com  -----------------------------------------------------------------------
8513759Sgiacomo.gabrielli@arm.com  |       unused        |xxxxxxxxxxxxxxx|       |xxxxxxxxxxxxxxx|       |
8613759Sgiacomo.gabrielli@arm.com  |                     |xxxxxxxxxxxxxxx|       |xxxxxxxxxxxxxxx|       |
8713759Sgiacomo.gabrielli@arm.com  -----------------------------------------------------------------------
8813759Sgiacomo.gabrielli@arm.com                        indexHighPortion         indexLowPortion
8913759Sgiacomo.gabrielli@arm.com                                        <------->
9013759Sgiacomo.gabrielli@arm.com                               NUMBER_OF_MEMORY_MODULE_BITS
9113759Sgiacomo.gabrielli@arm.com    */
9213759Sgiacomo.gabrielli@arm.com}
9313759Sgiacomo.gabrielli@arm.com
9413759Sgiacomo.gabrielli@arm.comvoid
9513759Sgiacomo.gabrielli@arm.comAddress::print(std::ostream& out) const
9613759Sgiacomo.gabrielli@arm.com{
9713759Sgiacomo.gabrielli@arm.com    using namespace std;
9813759Sgiacomo.gabrielli@arm.com    out << "[" << hex << "0x" << m_address << "," << " line 0x"
9913759Sgiacomo.gabrielli@arm.com        << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]"
10013759Sgiacomo.gabrielli@arm.com        << flush;
10113759Sgiacomo.gabrielli@arm.com}
10213759Sgiacomo.gabrielli@arm.com
10313759Sgiacomo.gabrielli@arm.comvoid
10413759Sgiacomo.gabrielli@arm.comAddress::output(std::ostream& out) const
10513759Sgiacomo.gabrielli@arm.com{
10613759Sgiacomo.gabrielli@arm.com    // Note: this outputs addresses in the form "ffff", not "0xffff".
10713759Sgiacomo.gabrielli@arm.com    // This code should always be able to write out addresses in a
10813759Sgiacomo.gabrielli@arm.com    // format that can be read in by the below input() method.  Please
10913759Sgiacomo.gabrielli@arm.com    // don't change this without talking to Milo first.
11013759Sgiacomo.gabrielli@arm.com    out << std::hex << m_address << std::dec;
11113759Sgiacomo.gabrielli@arm.com}
11213759Sgiacomo.gabrielli@arm.com
11313759Sgiacomo.gabrielli@arm.comvoid
11413759Sgiacomo.gabrielli@arm.comAddress::input(std::istream& in)
11513759Sgiacomo.gabrielli@arm.com{
11613759Sgiacomo.gabrielli@arm.com    // Note: this only works with addresses in the form "ffff", not
11713759Sgiacomo.gabrielli@arm.com    // "0xffff".  This code should always be able to read in addresses
11813759Sgiacomo.gabrielli@arm.com    // written out by the above output() method.  Please don't change
11913759Sgiacomo.gabrielli@arm.com    // this without talking to Milo first.
12013759Sgiacomo.gabrielli@arm.com    in >> std::hex >> m_address >> std::dec;
12113759Sgiacomo.gabrielli@arm.com}
12213759Sgiacomo.gabrielli@arm.com
12313759Sgiacomo.gabrielli@arm.comAddress::Address(const Address& obj)
12413759Sgiacomo.gabrielli@arm.com{
12513759Sgiacomo.gabrielli@arm.com    m_address = obj.m_address;
12613759Sgiacomo.gabrielli@arm.com}
12713759Sgiacomo.gabrielli@arm.com
12813759Sgiacomo.gabrielli@arm.comAddress&
12913759Sgiacomo.gabrielli@arm.comAddress::operator=(const Address& obj)
13013759Sgiacomo.gabrielli@arm.com{
13113759Sgiacomo.gabrielli@arm.com    if (this == &obj) {
13213759Sgiacomo.gabrielli@arm.com        // assert(false);
13313759Sgiacomo.gabrielli@arm.com    } else {
13413759Sgiacomo.gabrielli@arm.com        m_address = obj.m_address;
13513759Sgiacomo.gabrielli@arm.com    }
13613759Sgiacomo.gabrielli@arm.com    return *this;
13713759Sgiacomo.gabrielli@arm.com}
13813759Sgiacomo.gabrielli@arm.com
13913759Sgiacomo.gabrielli@arm.comvoid
14013759Sgiacomo.gabrielli@arm.comAddress::makePageAddress()
14113759Sgiacomo.gabrielli@arm.com{
14213759Sgiacomo.gabrielli@arm.com    m_address = maskLowOrderBits(TheISA::PageShift);
14313759Sgiacomo.gabrielli@arm.com}
14413759Sgiacomo.gabrielli@arm.com
14513759Sgiacomo.gabrielli@arm.comAddress
14613759Sgiacomo.gabrielli@arm.compage_address(const Address& addr)
14713759Sgiacomo.gabrielli@arm.com{
14813759Sgiacomo.gabrielli@arm.com    Address temp = addr;
14913759Sgiacomo.gabrielli@arm.com    temp.makePageAddress();
15013759Sgiacomo.gabrielli@arm.com    return temp;
15113759Sgiacomo.gabrielli@arm.com}
15213759Sgiacomo.gabrielli@arm.com
15313759Sgiacomo.gabrielli@arm.comAddress
15413759Sgiacomo.gabrielli@arm.comnext_stride_address(const Address& addr, int stride)
15513759Sgiacomo.gabrielli@arm.com{
15613759Sgiacomo.gabrielli@arm.com    Address temp = addr;
15713759Sgiacomo.gabrielli@arm.com    temp.makeNextStrideAddress(stride);
15813759Sgiacomo.gabrielli@arm.com    return temp;
15913759Sgiacomo.gabrielli@arm.com}
16013759Sgiacomo.gabrielli@arm.com