New simulator for Fujitsu frv contributed by Red Hat.
[deliverable/binutils-gdb.git] / sim / frv / cache.h
CommitLineData
b34f6357
DB
1/* Cache support for the FRV simulator
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Red Hat.
4
5This file is part of the GNU Simulators.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along
18with this program; if not, write to the Free Software Foundation, Inc.,
1959 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21#ifndef CACHE_H
22#define CACHE_H
23
24/* A representation of a set-associative cache with LRU replacement,
25 cache line locking, non-blocking support and multiple read ports. */
26
27/* An enumeration of cache pipeline request kinds. */
28typedef enum
29{
30 req_load,
31 req_store,
32 req_invalidate,
33 req_flush,
34 req_preload,
35 req_unlock,
36 req_WAR
37} FRV_CACHE_REQUEST_KIND;
38
39/* The cache pipeline requests. */
40typedef struct {
41 int preload;
42 int lock;
43} FRV_CACHE_WAR_REQUEST;
44
45typedef struct {
46 char *data;
47 int length;
48} FRV_CACHE_STORE_REQUEST;
49
50typedef struct {
51 int flush;
52 int all;
53} FRV_CACHE_INVALIDATE_REQUEST;
54
55typedef struct {
56 int lock;
57 int length;
58} FRV_CACHE_PRELOAD_REQUEST;
59
60/* A cache pipeline request. */
61typedef struct frv_cache_request
62{
63 struct frv_cache_request *next;
64 struct frv_cache_request *prev;
65 FRV_CACHE_REQUEST_KIND kind;
66 unsigned reqno;
67 unsigned priority;
68 SI address;
69 union {
70 FRV_CACHE_STORE_REQUEST store;
71 FRV_CACHE_INVALIDATE_REQUEST invalidate;
72 FRV_CACHE_PRELOAD_REQUEST preload;
73 FRV_CACHE_WAR_REQUEST WAR;
74 } u;
75} FRV_CACHE_REQUEST;
76
77/* The buffer for returning data to the caller. */
78typedef struct {
79 unsigned reqno;
80 SI address;
81 char *data;
82 int valid;
83} FRV_CACHE_RETURN_BUFFER;
84
85/* The status of flush requests. */
86typedef struct {
87 unsigned reqno;
88 SI address;
89 int valid;
90} FRV_CACHE_FLUSH_STATUS;
91
92/* Communicate status of requests to the caller. */
93typedef struct {
94 FRV_CACHE_FLUSH_STATUS flush;
95 FRV_CACHE_RETURN_BUFFER return_buffer;
96} FRV_CACHE_STATUS;
97
98/* A cache pipeline stage. */
99typedef struct {
100 FRV_CACHE_REQUEST *request;
101} FRV_CACHE_STAGE;
102
103enum {
104 FIRST_STAGE,
105 A_STAGE = FIRST_STAGE, /* Addressing stage */
106 I_STAGE, /* Interference stage */
107 LAST_STAGE = I_STAGE,
108 FRV_CACHE_STAGES
109};
110
111/* Representation of the WAR register. */
112typedef struct {
113 unsigned reqno;
114 unsigned priority;
115 SI address;
116 int preload;
117 int lock;
118 int latency;
119 int valid;
120} FRV_CACHE_WAR;
121
122/* A cache pipeline. */
123#define NUM_WARS 2
124typedef struct {
125 FRV_CACHE_REQUEST *requests;
126 FRV_CACHE_STAGE stages[FRV_CACHE_STAGES];
127 FRV_CACHE_WAR WAR[NUM_WARS];
128 FRV_CACHE_STATUS status;
129} FRV_CACHE_PIPELINE;
130
131enum {LS, LD, FRV_CACHE_PIPELINES};
132
133/* Representation of the xARS registers. */
134typedef struct {
135 int pipe;
136 unsigned reqno;
137 unsigned priority;
138 SI address;
139 int preload;
140 int lock;
141 int valid;
142} FRV_CACHE_ARS;
143
144/* A cache tag. */
145typedef struct {
146 USI tag; /* Address tag. */
147 int lru; /* Lower values indicates less recently used. */
148 char *line; /* Points to storage for line in data_storage. */
149 char dirty; /* line has been written to since last stored? */
150 char locked; /* line is locked? */
151 char valid; /* tag is valid? */
152} FRV_CACHE_TAG;
153
154/* Cache statistics. */
155typedef struct {
156 unsigned long accesses; /* number of cache accesses. */
157 unsigned long hits; /* number of cache hits. */
158} FRV_CACHE_STATISTICS;
159
160/* The cache itself.
161 Notes:
162 - line_size must be a power of 2
163 - sets must be a power of 2
164 - ways must be a power of 2
165*/
166typedef struct {
167 SIM_CPU *cpu;
168 unsigned ways; /* Number of ways in each set. */
169 unsigned sets; /* Number of sets in the cache. */
170 unsigned line_size; /* Size of each cache line. */
171 unsigned memory_latency; /* Latency of main memory in cycles. */
172 FRV_CACHE_TAG *tag_storage; /* Storage for tags. */
173 char *data_storage; /* Storage for data (cache lines). */
174 FRV_CACHE_PIPELINE pipeline[2]; /* Cache pipelines. */
175 FRV_CACHE_ARS BARS; /* BARS register. */
176 FRV_CACHE_ARS NARS; /* BARS register. */
177 FRV_CACHE_STATISTICS statistics; /* Operation statistics. */
178} FRV_CACHE;
179
180/* The tags are stored by ways within sets in order to make computations
181 easier. */
182#define CACHE_TAG(cache, set, way) ( \
183 & ((cache)->tag_storage[(set) * (cache)->ways + (way)]) \
184)
185
186/* Compute the address tag corresponding to the given address. */
187#define CACHE_ADDRESS_TAG(cache, address) ( \
188 (address) & ~(((cache)->line_size * (cache)->sets) - 1) \
189)
190
191/* Determine the index at which the set containing this tag starts. */
192#define CACHE_TAG_SET_START(cache, tag) ( \
193 ((tag) - (cache)->tag_storage) & ~((cache)->ways - 1) \
194)
195
196/* Determine the number of the set which this cache tag is in. */
197#define CACHE_TAG_SET_NUMBER(cache, tag) ( \
198 CACHE_TAG_SET_START ((cache), (tag)) / (cache)->ways \
199)
200
201#define CACHE_RETURN_DATA(cache, slot, address, mode, N) ( \
202 T2H_##N (*(mode *)(& (cache)->pipeline[slot].status.return_buffer.data \
203 [((address) & ((cache)->line_size - 1) \
204 & ~(sizeof (mode) - 1))])) \
205)
206
207#define CACHE_RETURN_DATA_ADDRESS(cache, slot, address, N) ( \
208 ((void *)& (cache)->pipeline[slot].status.return_buffer.data[(address) \
209 & ((cache)->line_size - 1) \
210 & ~((N) - 1)]) \
211)
212
213#define CACHE_INITIALIZED(cache) ((cache)->data_storage != NULL)
214
215/* These functions are used to initialize and terminate a cache. */
216void
217frv_cache_init (SIM_CPU *, FRV_CACHE *);
218void
219frv_cache_term (FRV_CACHE *);
220int
221frv_cache_enabled (FRV_CACHE *);
222
223/* These functions are used to operate the cache in non-cycle-accurate mode.
224 Each request is handled individually and immediately using the current
225 cache internal state. */
226int
227frv_cache_read (FRV_CACHE *, int, SI);
228int
229frv_cache_write (FRV_CACHE *, SI, char *, unsigned);
230int
231frv_cache_preload (FRV_CACHE *, SI, USI, int);
232int
233frv_cache_invalidate (FRV_CACHE *, SI, int);
234int
235frv_cache_invalidate_all (FRV_CACHE *, int);
236
237/* These functions are used to operate the cache in cycle-accurate mode.
238 The internal operation of the cache is simulated down to the cycle level. */
239#define NO_REQNO 0xffffffff
240void
241frv_cache_request_load (FRV_CACHE *, unsigned, SI, int);
242void
243frv_cache_request_store (FRV_CACHE *, SI, int, char *, unsigned);
244void
245frv_cache_request_invalidate (FRV_CACHE *, unsigned, SI, int, int, int);
246void
247frv_cache_request_preload (FRV_CACHE *, SI, int, int, int);
248void
249frv_cache_request_unlock (FRV_CACHE *, SI, int);
250
251void
252frv_cache_run (FRV_CACHE *, int);
253
254int
255frv_cache_data_in_buffer (FRV_CACHE*, int, SI, unsigned);
256int
257frv_cache_data_flushed (FRV_CACHE*, int, SI, unsigned);
258
259int
260frv_cache_read_passive_SI (FRV_CACHE *, SI, SI *);
261
262#endif /* CACHE_H */
This page took 0.046104 seconds and 4 git commands to generate.