PerfectCacheMemory.hh revision 6145
112312Sgabeblack@google.com 212312Sgabeblack@google.com/* 312312Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 412312Sgabeblack@google.com * All rights reserved. 512312Sgabeblack@google.com * 612312Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 712312Sgabeblack@google.com * modification, are permitted provided that the following conditions are 812312Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 912312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1012312Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1112312Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1212312Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1312312Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1412312Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1512312Sgabeblack@google.com * this software without specific prior written permission. 1612312Sgabeblack@google.com * 1712312Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812312Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912312Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012312Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112312Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212312Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312312Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412312Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512312Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612312Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712312Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812312Sgabeblack@google.com */ 2912312Sgabeblack@google.com 3012312Sgabeblack@google.com/* 3112312Sgabeblack@google.com * PerfectCacheMemory.h 3212312Sgabeblack@google.com * 3312312Sgabeblack@google.com * Description: 3412312Sgabeblack@google.com * 3512312Sgabeblack@google.com * $Id$ 3612312Sgabeblack@google.com * 3712312Sgabeblack@google.com */ 3812312Sgabeblack@google.com 3912312Sgabeblack@google.com#ifndef PERFECTCACHEMEMORY_H 4012312Sgabeblack@google.com#define PERFECTCACHEMEMORY_H 4112312Sgabeblack@google.com 4212312Sgabeblack@google.com#include "Global.hh" 4312312Sgabeblack@google.com#include "Map.hh" 4412312Sgabeblack@google.com#include "AccessPermission.hh" 4512312Sgabeblack@google.com#include "RubyConfig.hh" 4612312Sgabeblack@google.com#include "Address.hh" 4712312Sgabeblack@google.com#include "interface.hh" 4812312Sgabeblack@google.com#include "AbstractChip.hh" 4912312Sgabeblack@google.com 50template<class ENTRY> 51class PerfectCacheLineState { 52public: 53 PerfectCacheLineState() { m_permission = AccessPermission_NUM; } 54 AccessPermission m_permission; 55 ENTRY m_entry; 56}; 57 58template<class ENTRY> 59class PerfectCacheMemory { 60public: 61 62 // Constructors 63 PerfectCacheMemory(AbstractChip* chip_ptr); 64 65 // Destructor 66 //~PerfectCacheMemory(); 67 68 // Public Methods 69 70 static void printConfig(ostream& out); 71 72 // perform a cache access and see if we hit or not. Return true on 73 // a hit. 74 bool tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry); 75 76 // tests to see if an address is present in the cache 77 bool isTagPresent(const Address& address) const; 78 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; 83 84 // find an Invalid entry and sets the tag appropriate for the address 85 void allocate(const Address& address); 86 87 void deallocate(const Address& address); 88 89 // Returns with the physical address of the conflicting cache line 90 Address cacheProbe(const Address& newAddress) const; 91 92 // looks an address up in the cache 93 ENTRY& lookup(const Address& address); 94 const ENTRY& lookup(const Address& address) const; 95 96 // Get/Set permission of cache block 97 AccessPermission getPermission(const Address& address) const; 98 void changePermission(const Address& address, AccessPermission new_perm); 99 100 // Print cache contents 101 void print(ostream& out) const; 102private: 103 // Private Methods 104 105 // Private copy constructor and assignment operator 106 PerfectCacheMemory(const PerfectCacheMemory& obj); 107 PerfectCacheMemory& operator=(const PerfectCacheMemory& obj); 108 109 // Data Members (m_prefix) 110 Map<Address, PerfectCacheLineState<ENTRY> > m_map; 111 AbstractChip* m_chip_ptr; 112}; 113 114// Output operator declaration 115//ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj); 116 117// ******************* Definitions ******************* 118 119// Output operator definition 120template<class ENTRY> 121extern inline 122ostream& operator<<(ostream& out, const PerfectCacheMemory<ENTRY>& obj) 123{ 124 obj.print(out); 125 out << flush; 126 return out; 127} 128 129 130// **************************************************************** 131 132template<class ENTRY> 133extern inline 134PerfectCacheMemory<ENTRY>::PerfectCacheMemory(AbstractChip* chip_ptr) 135{ 136 m_chip_ptr = chip_ptr; 137} 138 139// STATIC METHODS 140 141template<class ENTRY> 142extern inline 143void PerfectCacheMemory<ENTRY>::printConfig(ostream& out) 144{ 145} 146 147// PUBLIC METHODS 148 149template<class ENTRY> 150extern inline 151bool PerfectCacheMemory<ENTRY>::tryCacheAccess(const CacheMsg& msg, bool& block_stc, ENTRY*& entry) 152{ 153 ERROR_MSG("not implemented"); 154} 155 156// tests to see if an address is present in the cache 157template<class ENTRY> 158extern inline 159bool PerfectCacheMemory<ENTRY>::isTagPresent(const Address& address) const 160{ 161 return m_map.exist(line_address(address)); 162} 163 164template<class ENTRY> 165extern inline 166bool PerfectCacheMemory<ENTRY>::cacheAvail(const Address& address) const 167{ 168 return true; 169} 170 171// find an Invalid or already allocated entry and sets the tag 172// appropriate for the address 173template<class ENTRY> 174extern inline 175void PerfectCacheMemory<ENTRY>::allocate(const Address& address) 176{ 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); 181} 182 183// deallocate entry 184template<class ENTRY> 185extern inline 186void PerfectCacheMemory<ENTRY>::deallocate(const Address& address) 187{ 188 m_map.erase(line_address(address)); 189} 190 191// Returns with the physical address of the conflicting cache line 192template<class ENTRY> 193extern inline 194Address PerfectCacheMemory<ENTRY>::cacheProbe(const Address& newAddress) const 195{ 196 ERROR_MSG("cacheProbe called in perfect cache"); 197} 198 199// looks an address up in the cache 200template<class ENTRY> 201extern inline 202ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) 203{ 204 return m_map.lookup(line_address(address)).m_entry; 205} 206 207// looks an address up in the cache 208template<class ENTRY> 209extern inline 210const ENTRY& PerfectCacheMemory<ENTRY>::lookup(const Address& address) const 211{ 212 return m_map.lookup(line_address(address)).m_entry; 213} 214 215template<class ENTRY> 216extern inline 217AccessPermission PerfectCacheMemory<ENTRY>::getPermission(const Address& address) const 218{ 219 return m_map.lookup(line_address(address)).m_permission; 220} 221 222template<class ENTRY> 223extern inline 224void PerfectCacheMemory<ENTRY>::changePermission(const Address& address, AccessPermission new_perm) 225{ 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; 231} 232 233template<class ENTRY> 234extern inline 235void PerfectCacheMemory<ENTRY>::print(ostream& out) const 236{ 237} 238 239#endif //PERFECTCACHEMEMORY_H 240