Address.cc (10314:94b6b28fc968) Address.cc (10318:98771a936b61)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29#include "arch/isa_traits.hh"
30#include "config/the_isa.hh"
31#include "mem/ruby/common/Address.hh"
32#include "mem/ruby/system/System.hh"
33
34physical_address_t
35Address::getLineAddress() const
36{
37 return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH);
38}
39
40physical_address_t
41Address::getOffset() const
42{
43 return bitSelect(0, RubySystem::getBlockSizeBits() - 1);
44}
45
46void
47Address::makeLineAddress()
48{
49 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits());
50}
51
52// returns the next stride address based on line address
53void
54Address::makeNextStrideAddress(int stride)
55{
56 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
57 + RubySystem::getBlockSizeBytes()*stride;
58}
59
60int64
61Address::memoryModuleIndex() const
62{
63 int64 index =
64 bitSelect(RubySystem::getBlockSizeBits() +
65 RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
66 assert (index >= 0);
67 return index;
68
69 // int64 indexHighPortion =
70 // address.bitSelect(MEMORY_SIZE_BITS - 1,
71 // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS);
72 // int64 indexLowPortion =
73 // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1);
74 //
75 // int64 index = indexLowPortion |
76 // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
77
78 /*
79 Round-robin mapping of addresses, at page size granularity
80
81ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
82 | | | |
83 \ / \ / \ / \ / 0
84 -----------------------------------------------------------------------
85 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
86 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
87 -----------------------------------------------------------------------
88 indexHighPortion indexLowPortion
89 <------->
90 NUMBER_OF_MEMORY_MODULE_BITS
91 */
92}
93
94void
95Address::print(std::ostream& out) const
96{
97 using namespace std;
98 out << "[" << hex << "0x" << m_address << "," << " line 0x"
99 << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]"
100 << flush;
101}
102
103void
104Address::output(std::ostream& out) const
105{
106 // Note: this outputs addresses in the form "ffff", not "0xffff".
107 // This code should always be able to write out addresses in a
108 // format that can be read in by the below input() method. Please
109 // don't change this without talking to Milo first.
110 out << std::hex << m_address << std::dec;
111}
112
113void
114Address::input(std::istream& in)
115{
116 // Note: this only works with addresses in the form "ffff", not
117 // "0xffff". This code should always be able to read in addresses
118 // written out by the above output() method. Please don't change
119 // this without talking to Milo first.
120 in >> std::hex >> m_address >> std::dec;
121}
122
123Address::Address(const Address& obj)
124{
125 m_address = obj.m_address;
126}
127
128Address&
129Address::operator=(const Address& obj)
130{
131 if (this == &obj) {
132 // assert(false);
133 } else {
134 m_address = obj.m_address;
135 }
136 return *this;
137}
138
139void
140Address::makePageAddress()
141{
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29#include "arch/isa_traits.hh"
30#include "config/the_isa.hh"
31#include "mem/ruby/common/Address.hh"
32#include "mem/ruby/system/System.hh"
33
34physical_address_t
35Address::getLineAddress() const
36{
37 return bitSelect(RubySystem::getBlockSizeBits(), ADDRESS_WIDTH);
38}
39
40physical_address_t
41Address::getOffset() const
42{
43 return bitSelect(0, RubySystem::getBlockSizeBits() - 1);
44}
45
46void
47Address::makeLineAddress()
48{
49 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits());
50}
51
52// returns the next stride address based on line address
53void
54Address::makeNextStrideAddress(int stride)
55{
56 m_address = maskLowOrderBits(RubySystem::getBlockSizeBits())
57 + RubySystem::getBlockSizeBytes()*stride;
58}
59
60int64
61Address::memoryModuleIndex() const
62{
63 int64 index =
64 bitSelect(RubySystem::getBlockSizeBits() +
65 RubySystem::getMemorySizeBits(), ADDRESS_WIDTH);
66 assert (index >= 0);
67 return index;
68
69 // int64 indexHighPortion =
70 // address.bitSelect(MEMORY_SIZE_BITS - 1,
71 // PAGE_SIZE_BITS + NUMBER_OF_MEMORY_MODULE_BITS);
72 // int64 indexLowPortion =
73 // address.bitSelect(DATA_BLOCK_BITS, PAGE_SIZE_BITS - 1);
74 //
75 // int64 index = indexLowPortion |
76 // (indexHighPortion << (PAGE_SIZE_BITS - DATA_BLOCK_BITS));
77
78 /*
79 Round-robin mapping of addresses, at page size granularity
80
81ADDRESS_WIDTH MEMORY_SIZE_BITS PAGE_SIZE_BITS DATA_BLOCK_BITS
82 | | | |
83 \ / \ / \ / \ / 0
84 -----------------------------------------------------------------------
85 | unused |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
86 | |xxxxxxxxxxxxxxx| |xxxxxxxxxxxxxxx| |
87 -----------------------------------------------------------------------
88 indexHighPortion indexLowPortion
89 <------->
90 NUMBER_OF_MEMORY_MODULE_BITS
91 */
92}
93
94void
95Address::print(std::ostream& out) const
96{
97 using namespace std;
98 out << "[" << hex << "0x" << m_address << "," << " line 0x"
99 << maskLowOrderBits(RubySystem::getBlockSizeBits()) << dec << "]"
100 << flush;
101}
102
103void
104Address::output(std::ostream& out) const
105{
106 // Note: this outputs addresses in the form "ffff", not "0xffff".
107 // This code should always be able to write out addresses in a
108 // format that can be read in by the below input() method. Please
109 // don't change this without talking to Milo first.
110 out << std::hex << m_address << std::dec;
111}
112
113void
114Address::input(std::istream& in)
115{
116 // Note: this only works with addresses in the form "ffff", not
117 // "0xffff". This code should always be able to read in addresses
118 // written out by the above output() method. Please don't change
119 // this without talking to Milo first.
120 in >> std::hex >> m_address >> std::dec;
121}
122
123Address::Address(const Address& obj)
124{
125 m_address = obj.m_address;
126}
127
128Address&
129Address::operator=(const Address& obj)
130{
131 if (this == &obj) {
132 // assert(false);
133 } else {
134 m_address = obj.m_address;
135 }
136 return *this;
137}
138
139void
140Address::makePageAddress()
141{
142 m_address = maskLowOrderBits(TheISA::LogVMPageSize);
142 m_address = maskLowOrderBits(TheISA::PageShift);
143}
144
145Address
146page_address(const Address& addr)
147{
148 Address temp = addr;
149 temp.makePageAddress();
150 return temp;
151}
152
153Address
154next_stride_address(const Address& addr, int stride)
155{
156 Address temp = addr;
157 temp.makeNextStrideAddress(stride);
158 return temp;
159}
143}
144
145Address
146page_address(const Address& addr)
147{
148 Address temp = addr;
149 temp.makePageAddress();
150 return temp;
151}
152
153Address
154next_stride_address(const Address& addr, int stride)
155{
156 Address temp = addr;
157 temp.makeNextStrideAddress(stride);
158 return temp;
159}