1 // mep-cache.h - Class declaration for the Toshiba Media Engine (MeP) Cache
4 // Copyright (C) 2004, 2005 Red Hat.
5 // This file is part of SID and is licensed under the GPL.
6 // See the file COPYING.SID for conditions for redistribution.
11 #include "sidcpuutil.h"
16 using namespace sidutil;
18 // The mep_cache_line class keeps its data and tags in global memory.
20 class mep_cache_line : public cache_line
23 mep_cache_line (unsigned line_size, unsigned index, unsigned way, mep_cache &c);
26 // Get the line's tag.
27 void set_tag (cache_tag tag);
29 cache_tag tag () const;
31 // Mark the line dirty or clean.
35 // Mark the line valid or invalid.
39 // Lock or unlock the line.
43 // Maintain the R bit.
48 bool dirty_p () const;
51 bool valid_p () const;
53 // Is the line locked?
54 bool locked_p () const;
56 #define DEFN_METHOD(DataType) \
57 /* Insert a datum into the line, starting at byte offset. */ \
58 virtual void insert (unsigned offset, DataType new_data); \
59 /* Extract a datum from the line, starting at byte offset. */ \
60 virtual void extract (unsigned offset, DataType& new_data) const;
62 DEFN_METHOD (sid::big_int_1)
63 DEFN_METHOD (sid::big_int_2)
64 DEFN_METHOD (sid::big_int_4)
65 DEFN_METHOD (sid::big_int_8)
66 DEFN_METHOD (sid::little_int_1)
67 DEFN_METHOD (sid::little_int_2)
68 DEFN_METHOD (sid::little_int_4)
69 DEFN_METHOD (sid::little_int_8)
72 // Dump a line in human readable form to cout.
73 void dump_data () const;
76 void set_raw_tag (cache_tag tag);
77 cache_tag raw_tag () const;
84 cache_tag address_mask;
88 // The cache_line_factory creates and destroys cache lines. This
89 // implementation maps the tags and data to global memory via
90 // the cache's test_area_bus.
92 class mep_cache_line_factory : public cache_line_factory
95 mep_cache_line_factory (mep_cache &c) :
98 ~mep_cache_line_factory () {}
100 cache_line *make_line (unsigned line_size, unsigned index, unsigned way)
102 return new mep_cache_line (line_size, index, way, cache);
108 // Replacement alorithm for MeP associative caches
110 class mep_assoc_replacement_algorithm : public cache_replacement_algorithm
113 virtual ~mep_assoc_replacement_algorithm () {}
115 // Choose a line to replace in a cache set. Return it, if successful
116 virtual cache_line *expell (cache_set &set);
119 // The actual MEP_CACHE component.
120 // Inherit from the generic cache component.
122 class mep_cache: public blocking_cache_component
125 mep_cache (unsigned assoc, unsigned cache_sz, unsigned line_sz,
126 cache_replacement_algorithm& replacer);
127 ~mep_cache () throw() {}
129 unsigned size () const { return cache_size; }
130 unsigned assoc () const { return blocking_cache_component::assoc; }
132 void write_tag (unsigned way, int index, cache_tag atag);
133 cache_tag read_tag (unsigned way, int index);
135 #define DEFN_METHOD(DataType) \
136 /* Insert a datum into the line at the given index, starting at byte offset. */ \
137 void write_data (unsigned way, int index, unsigned offset, DataType new_data); \
138 /* Extract a datum from the line at the given index, starting at byte offset. */ \
139 void read_data (unsigned way, int index, unsigned offset, DataType& new_data) const;
141 DEFN_METHOD (sid::big_int_1)
142 DEFN_METHOD (sid::big_int_2)
143 DEFN_METHOD (sid::big_int_4)
144 DEFN_METHOD (sid::big_int_8)
145 DEFN_METHOD (sid::little_int_1)
146 DEFN_METHOD (sid::little_int_2)
147 DEFN_METHOD (sid::little_int_4)
148 DEFN_METHOD (sid::little_int_8)
151 void dump_data (unsigned way, int index) const;
156 callback_pin<mep_cache> clear_tag_pin;
157 void clear_tag (host_int_4 addr);
158 callback_pin<mep_cache> endian_set_pin;
159 void endian_set_pin_handler(sid::host_int_4 v);
162 virtual void configure (const string &config);