2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Erik Hallnor
32 * Definitions of a simple cache block class.
35 #ifndef __CACHE_BLK_HH__
36 #define __CACHE_BLK_HH__
38 #include "sim/root.hh" // for Tick
39 #include "arch/isa_traits.hh" // for Addr
42 * Cache block status bit assignments
44 enum CacheBlkStatusBits {
45 /** valid, readable */
47 /** write permission */
49 /** dirty (modified) */
53 /** block was referenced */
55 /** block was a hardware prefetch yet unaccessed*/
56 BlkHWPrefetched = 0x20
60 * A Basic Cache block.
61 * Contains the tag, status, and a pointer to data.
66 /** The address space ID of this block. */
68 /** Data block tag value. */
71 * Contains a copy of the data in this block for easy access. This is used
72 * for efficient execution when the data could be actually stored in
73 * another format (COW, compressed, sub-blocked, etc). In all cases the
74 * data stored here should be kept consistant with the actual data
75 * referenced by this block.
78 /** the number of bytes stored in this block. */
81 /** block state: OR of CacheBlkStatusBit */
82 typedef unsigned State;
84 /** The current status of this block. @sa CacheBlockStatusBits */
87 /** Which curTick will this block be accessable */
91 * The set this block belongs to.
92 * @todo Move this into subclasses when we fix CacheTags to use them.
96 /** Number of references to this block since it was brought in. */
100 : asid(-1), tag(0), data(0) ,size(0), status(0), whenReady(0), xc(0),
105 * Copy the state of the given block into this one.
106 * @param rhs The block to copy.
107 * @return a const reference to this block.
109 const CacheBlk& operator=(const CacheBlk& rhs)
116 whenReady = rhs.whenReady;
119 refCount = rhs.refCount;
124 * Checks the write permissions of this block.
125 * @return True if the block is writable.
127 bool isWritable() const
129 const int needed_bits = BlkWritable | BlkValid;
130 return (status & needed_bits) == needed_bits;
134 * Checks that a block is valid (readable).
135 * @return True if the block is valid.
139 return (status & BlkValid) != 0;
143 * Check to see if a block has been written.
144 * @return True if the block is dirty.
146 bool isModified() const
148 return (status & BlkDirty) != 0;
152 * Check to see if this block contains compressed data.
153 * @return True iF the block's data is compressed.
155 bool isCompressed() const
157 return (status & BlkCompressed) != 0;
161 * Check if this block has been referenced.
162 * @return True if the block has been referenced.
164 bool isReferenced() const
166 return (status & BlkReferenced) != 0;
170 * Check if this block was the result of a hardware prefetch, yet to
172 * @return True if the block was a hardware prefetch, unaccesed.
174 bool isPrefetch() const
176 return (status & BlkHWPrefetched) != 0;
183 * Output a CacheBlk to the given ostream.
184 * @param out The stream for the output.
185 * @param blk The cache block to print.
187 * @return The output stream.
189 inline std::ostream &
190 operator<<(std::ostream &out, const CacheBlk &blk)
192 out << std::hex << std::endl;
193 out << " Tag: " << blk.tag << std::endl;
194 out << " Status: " << blk.status << std::endl;
196 return(out << std::dec);
199 #endif //__CACHE_BLK_HH__