OSDN Git Service

Support for Toshiba MeP.
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / cache / mep-cache.h
1 // mep-cache.h - Class declaration for the Toshiba Media Engine (MeP) Cache
2 // -*- C++ -*-
3
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.
7
8 #ifndef MEP_CACHE_H
9 #define MEP_CACHE_H
10
11 #include "sidcpuutil.h"
12 #include "cache.h"
13
14 class mep_cache;
15
16 using namespace sidutil;
17
18 // The mep_cache_line class keeps its data and tags in global memory.
19
20 class mep_cache_line : public cache_line
21 {
22 public:
23   mep_cache_line (unsigned line_size, unsigned index, unsigned way, mep_cache &c);
24  ~mep_cache_line () {}
25
26   // Get the line's tag.
27   void set_tag (cache_tag tag);
28   void clear_tag ();
29   cache_tag tag () const;
30
31   // Mark the line dirty or clean.
32   void dirty ();
33   void clean ();
34
35   // Mark the line valid or invalid.
36   void validate ();
37   void invalidate ();
38
39   // Lock or unlock the line.
40   void lock ();
41   void unlock ();
42
43   // Maintain the R bit.
44   int get_R () const;
45   void set_R (int);
46
47   // Is the line dirty?
48   bool dirty_p () const;
49
50   // Is the line valid?
51   bool valid_p () const;
52
53   // Is the line locked?
54   bool locked_p () const;
55
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;
61
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)
70 #undef DEFN_METHOD
71
72   // Dump a line in human readable form to cout.
73   void dump_data () const;
74
75 private:
76   void set_raw_tag (cache_tag tag);
77   cache_tag raw_tag () const;
78
79   unsigned my_size;
80   unsigned my_way;
81   int my_index;
82   int index_shift;
83   cache_tag index_mask;
84   cache_tag address_mask;
85   mep_cache &my_cache;
86 };
87
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.
91 //
92 class mep_cache_line_factory : public cache_line_factory
93 {
94 public:
95   mep_cache_line_factory (mep_cache &c) :
96     cache (c)
97     {}
98  ~mep_cache_line_factory () {}
99
100   cache_line *make_line (unsigned line_size, unsigned index, unsigned way)
101   {
102     return new mep_cache_line (line_size, index, way, cache);
103   }
104 private:
105   mep_cache &cache;
106 };
107
108 // Replacement alorithm for MeP associative caches
109 //
110 class mep_assoc_replacement_algorithm : public cache_replacement_algorithm
111 {
112 public:
113   virtual ~mep_assoc_replacement_algorithm () {}
114
115   // Choose a line to replace in a cache set. Return it, if successful
116   virtual cache_line *expell (cache_set &set);
117 };
118
119 // The actual MEP_CACHE component.
120 // Inherit from the generic cache component.
121 //
122 class mep_cache: public blocking_cache_component
123 {
124 public:
125   mep_cache (unsigned assoc, unsigned cache_sz, unsigned line_sz,
126              cache_replacement_algorithm& replacer);
127  ~mep_cache () throw() {}
128
129  unsigned size () const { return cache_size; }
130  unsigned assoc () const { return blocking_cache_component::assoc; }
131
132  void write_tag (unsigned way, int index, cache_tag atag);
133  cache_tag read_tag (unsigned way, int index);
134
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;
140
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)
149 #undef DEFN_METHOD
150
151   void dump_data (unsigned way, int index) const;
152
153 private:
154   bus* tag_test_mem;
155   bus* data_test_mem;
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);
160   endian endianness;
161
162   virtual void configure (const string &config);
163 };
164 #endif // CACHE_H