3 * Copyright (c) 1999-2008 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.
31 * PerfectCacheMemory.h
39 #ifndef PERFECTCACHEMEMORY_H
40 #define PERFECTCACHEMEMORY_H
44 #include "AccessPermission.hh"
45 #include "RubyConfig.hh"
47 #include "AbstractChip.hh"
50 class PerfectCacheLineState {
52 PerfectCacheLineState() { m_permission = AccessPermission_NUM; }
53 AccessPermission m_permission;
58 class PerfectCacheMemory {
62 PerfectCacheMemory(AbstractChip* chip_ptr);
65 //~PerfectCacheMemory();
69 static void printConfig(ostream& out);
71 // perform a cache access and see if we hit or not. Return true on
73 bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry);
75 // tests to see if an address is present in the cache
76 bool isTagPresent(const Address& address) const;
78 // Returns true if there is:
79 // a) a tag match on this address or there is
80 // b) an Invalid line in the same cache "way"
81 bool cacheAvail(const Address& address) const;
83 // find an Invalid entry and sets the tag appropriate for the address
84 void allocate(const Address& address);
86 void deallocate(const Address& address);
88 // Returns with the physical address of the conflicting cache line
89 Address cacheProbe(const Address& newAddress) const;
91 // looks an address up in the cache
92 ENTRY& lookup(const Address& address);
93 const ENTRY& lookup(const Address& address) const;
95 // Get/Set permission of cache block
96 AccessPermission getPermission(const Address& address) const;
97 void changePermission(const Address& address, AccessPermission new_perm);
99 // Print cache contents
100 void print(ostream& out) const;
104 // Private copy constructor and assignment operator
105 PerfectCacheMemory(const PerfectCacheMemory& obj);
106 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj);
108 // Data Members (m_prefix)
109 Map<Address, PerfectCacheLineState<ENTRY> > m_map;
110 AbstractChip* m_chip_ptr;
113 // Output operator declaration
114 //ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj);
116 // ******************* Definitions *******************
118 // Output operator definition
119 template<class ENTRY>
121 ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj)
129 // ****************************************************************
131 template<class ENTRY>
133 PerfectCacheMemory<ENTRY>::PerfectCacheMemory(AbstractChip* chip_ptr)
135 m_chip_ptr = chip_ptr;
140 template<class ENTRY>
142 void PerfectCacheMemory<ENTRY>::printConfig(ostream& out)
148 template<class ENTRY>
150 bool PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry)
152 ERROR_MSG("not implemented");
155 // tests to see if an address is present in the cache
156 template<class ENTRY>
158 bool PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const
160 return m_map.exist(line_address(address));
163 template<class ENTRY>
165 bool PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const
170 // find an Invalid or already allocated entry and sets the tag
171 // appropriate for the address
172 template<class ENTRY>
174 void PerfectCacheMemory<ENTRY>::allocate(const Address& address)
176 PerfectCacheLineState<ENTRY> line_state;
177 line_state.m_permission = AccessPermission_Busy;
178 line_state.m_entry = ENTRY();
179 m_map.add(line_address(address), line_state);
183 template<class ENTRY>
185 void PerfectCacheMemory<ENTRY>::deallocate(const Address& address)
187 m_map.erase(line_address(address));
190 // Returns with the physical address of the conflicting cache line
191 template<class ENTRY>
193 Address PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const
195 ERROR_MSG("cacheProbe called in perfect cache");
198 // looks an address up in the cache
199 template<class ENTRY>
201 ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address)
203 return m_map.lookup(line_address(address)).m_entry;
206 // looks an address up in the cache
207 template<class ENTRY>
209 const ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) const
211 return m_map.lookup(line_address(address)).m_entry;
214 template<class ENTRY>
216 AccessPermission PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const
218 return m_map.lookup(line_address(address)).m_permission;
221 template<class ENTRY>
223 void PerfectCacheMemory<ENTRY>::changePermission(const Address& address, AccessPermission new_perm)
225 Address line_address = address;
226 line_address.makeLineAddress();
227 PerfectCacheLineState<ENTRY>& line_state = m_map.lookup(line_address);
228 AccessPermission old_perm = line_state.m_permission;
229 line_state.m_permission = new_perm;
232 template<class ENTRY>
234 void PerfectCacheMemory<ENTRY>::print(ostream& out) const
238 #endif //PERFECTCACHEMEMORY_H