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 "interface.hh"
48 #include "AbstractChip.hh"
51 class PerfectCacheLineState {
53 PerfectCacheLineState() { m_permission = AccessPermission_NUM; }
54 AccessPermission m_permission;
59 class PerfectCacheMemory {
63 PerfectCacheMemory(AbstractChip* chip_ptr);
66 //~PerfectCacheMemory();
70 static void printConfig(ostream& out);
72 // perform a cache access and see if we hit or not. Return true on
74 bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry);
76 // tests to see if an address is present in the cache
77 bool isTagPresent(const Address& address) const;
79 // Returns true if there is:
80 // a) a tag match on this address or there is
81 // b) an Invalid line in the same cache "way"
82 bool cacheAvail(const Address& address) const;
84 // find an Invalid entry and sets the tag appropriate for the address
85 void allocate(const Address& address);
87 void deallocate(const Address& address);
89 // Returns with the physical address of the conflicting cache line
90 Address cacheProbe(const Address& newAddress) const;
92 // looks an address up in the cache
93 ENTRY& lookup(const Address& address);
94 const ENTRY& lookup(const Address& address) const;
96 // Get/Set permission of cache block
97 AccessPermission getPermission(const Address& address) const;
98 void changePermission(const Address& address, AccessPermission new_perm);
100 // Print cache contents
101 void print(ostream& out) const;
105 // Private copy constructor and assignment operator
106 PerfectCacheMemory(const PerfectCacheMemory& obj);
107 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj);
109 // Data Members (m_prefix)
110 Map<Address, PerfectCacheLineState<ENTRY> > m_map;
111 AbstractChip* m_chip_ptr;
114 // Output operator declaration
115 //ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj);
117 // ******************* Definitions *******************
119 // Output operator definition
120 template<class ENTRY>
122 ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj)
130 // ****************************************************************
132 template<class ENTRY>
134 PerfectCacheMemory<ENTRY>::PerfectCacheMemory(AbstractChip* chip_ptr)
136 m_chip_ptr = chip_ptr;
141 template<class ENTRY>
143 void PerfectCacheMemory<ENTRY>::printConfig(ostream& out)
149 template<class ENTRY>
151 bool PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry)
153 ERROR_MSG("not implemented");
156 // tests to see if an address is present in the cache
157 template<class ENTRY>
159 bool PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const
161 return m_map.exist(line_address(address));
164 template<class ENTRY>
166 bool PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const
171 // find an Invalid or already allocated entry and sets the tag
172 // appropriate for the address
173 template<class ENTRY>
175 void PerfectCacheMemory<ENTRY>::allocate(const Address& address)
177 PerfectCacheLineState<ENTRY> line_state;
178 line_state.m_permission = AccessPermission_Busy;
179 line_state.m_entry = ENTRY();
180 m_map.add(line_address(address), line_state);
184 template<class ENTRY>
186 void PerfectCacheMemory<ENTRY>::deallocate(const Address& address)
188 m_map.erase(line_address(address));
191 // Returns with the physical address of the conflicting cache line
192 template<class ENTRY>
194 Address PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const
196 ERROR_MSG("cacheProbe called in perfect cache");
199 // looks an address up in the cache
200 template<class ENTRY>
202 ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address)
204 return m_map.lookup(line_address(address)).m_entry;
207 // looks an address up in the cache
208 template<class ENTRY>
210 const ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) const
212 return m_map.lookup(line_address(address)).m_entry;
215 template<class ENTRY>
217 AccessPermission PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const
219 return m_map.lookup(line_address(address)).m_permission;
222 template<class ENTRY>
224 void PerfectCacheMemory<ENTRY>::changePermission(const Address& address, AccessPermission new_perm)
226 Address line_address = address;
227 line_address.makeLineAddress();
228 PerfectCacheLineState<ENTRY>& line_state = m_map.lookup(line_address);
229 AccessPermission old_perm = line_state.m_permission;
230 line_state.m_permission = new_perm;
233 template<class ENTRY>
235 void PerfectCacheMemory<ENTRY>::print(ostream& out) const
239 #endif //PERFECTCACHEMEMORY_H