1 /* Cache support for the FRV simulator
2 Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
3 Contributed by Red Hat.
5 This file is part of the GNU Simulators.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* A representation of a set-associative cache with LRU replacement,
25 cache line locking, non-blocking support and multiple read ports. */
27 /* An enumeration of cache pipeline request kinds. */
37 } FRV_CACHE_REQUEST_KIND
;
39 /* The cache pipeline requests. */
43 } FRV_CACHE_WAR_REQUEST
;
48 } FRV_CACHE_STORE_REQUEST
;
53 } FRV_CACHE_INVALIDATE_REQUEST
;
58 } FRV_CACHE_PRELOAD_REQUEST
;
60 /* A cache pipeline request. */
61 typedef struct frv_cache_request
63 struct frv_cache_request
*next
;
64 struct frv_cache_request
*prev
;
65 FRV_CACHE_REQUEST_KIND kind
;
70 FRV_CACHE_STORE_REQUEST store
;
71 FRV_CACHE_INVALIDATE_REQUEST invalidate
;
72 FRV_CACHE_PRELOAD_REQUEST preload
;
73 FRV_CACHE_WAR_REQUEST WAR
;
77 /* The buffer for returning data to the caller. */
83 } FRV_CACHE_RETURN_BUFFER
;
85 /* The status of flush requests. */
90 } FRV_CACHE_FLUSH_STATUS
;
92 /* Communicate status of requests to the caller. */
94 FRV_CACHE_FLUSH_STATUS flush
;
95 FRV_CACHE_RETURN_BUFFER return_buffer
;
98 /* A cache pipeline stage. */
100 FRV_CACHE_REQUEST
*request
;
105 A_STAGE
= FIRST_STAGE
, /* Addressing stage */
106 I_STAGE
, /* Interference stage */
107 LAST_STAGE
= I_STAGE
,
111 /* Representation of the WAR register. */
122 /* A cache pipeline. */
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
;
131 enum {LS
, LD
, FRV_CACHE_PIPELINES
};
133 /* Representation of the xARS registers. */
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? */
154 /* Cache statistics. */
156 unsigned long accesses
; /* number of cache accesses. */
157 unsigned long hits
; /* number of cache hits. */
158 } FRV_CACHE_STATISTICS
;
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
168 unsigned configured_ways
; /* Number of ways configured in each set. */
169 unsigned configured_sets
; /* Number of sets configured in the cache. */
170 unsigned ways
; /* Number of ways in each set. */
171 unsigned sets
; /* Number of sets in the cache. */
172 unsigned line_size
; /* Size of each cache line. */
173 unsigned memory_latency
; /* Latency of main memory in cycles. */
174 FRV_CACHE_TAG
*tag_storage
; /* Storage for tags. */
175 char *data_storage
; /* Storage for data (cache lines). */
176 FRV_CACHE_PIPELINE pipeline
[2]; /* Cache pipelines. */
177 FRV_CACHE_ARS BARS
; /* BARS register. */
178 FRV_CACHE_ARS NARS
; /* BARS register. */
179 FRV_CACHE_STATISTICS statistics
; /* Operation statistics. */
182 /* The tags are stored by ways within sets in order to make computations
184 #define CACHE_TAG(cache, set, way) ( \
185 & ((cache)->tag_storage[(set) * (cache)->ways + (way)]) \
188 /* Compute the address tag corresponding to the given address. */
189 #define CACHE_ADDRESS_TAG(cache, address) ( \
190 (address) & ~(((cache)->line_size * (cache)->sets) - 1) \
193 /* Determine the index at which the set containing this tag starts. */
194 #define CACHE_TAG_SET_START(cache, tag) ( \
195 ((tag) - (cache)->tag_storage) & ~((cache)->ways - 1) \
198 /* Determine the number of the set which this cache tag is in. */
199 #define CACHE_TAG_SET_NUMBER(cache, tag) ( \
200 CACHE_TAG_SET_START ((cache), (tag)) / (cache)->ways \
203 #define CACHE_RETURN_DATA(cache, slot, address, mode, N) ( \
204 T2H_##N (*(mode *)(& (cache)->pipeline[slot].status.return_buffer.data \
205 [((address) & ((cache)->line_size - 1))])) \
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)]) \
212 #define DATA_CROSSES_CACHE_LINE(cache, address, size) ( \
213 ((address) & ((cache)->line_size - 1)) + (size) > (cache)->line_size \
216 #define CACHE_INITIALIZED(cache) ((cache)->data_storage != NULL)
218 /* These functions are used to initialize and terminate a cache. */
220 frv_cache_init (SIM_CPU
*, FRV_CACHE
*);
222 frv_cache_term (FRV_CACHE
*);
224 frv_cache_reconfigure (SIM_CPU
*, FRV_CACHE
*);
226 frv_cache_enabled (FRV_CACHE
*);
228 /* These functions are used to operate the cache in non-cycle-accurate mode.
229 Each request is handled individually and immediately using the current
230 cache internal state. */
232 frv_cache_read (FRV_CACHE
*, int, SI
);
234 frv_cache_write (FRV_CACHE
*, SI
, char *, unsigned);
236 frv_cache_preload (FRV_CACHE
*, SI
, USI
, int);
238 frv_cache_invalidate (FRV_CACHE
*, SI
, int);
240 frv_cache_invalidate_all (FRV_CACHE
*, int);
242 /* These functions are used to operate the cache in cycle-accurate mode.
243 The internal operation of the cache is simulated down to the cycle level. */
244 #define NO_REQNO 0xffffffff
246 frv_cache_request_load (FRV_CACHE
*, unsigned, SI
, int);
248 frv_cache_request_store (FRV_CACHE
*, SI
, int, char *, unsigned);
250 frv_cache_request_invalidate (FRV_CACHE
*, unsigned, SI
, int, int, int);
252 frv_cache_request_preload (FRV_CACHE
*, SI
, int, int, int);
254 frv_cache_request_unlock (FRV_CACHE
*, SI
, int);
257 frv_cache_run (FRV_CACHE
*, int);
260 frv_cache_data_in_buffer (FRV_CACHE
*, int, SI
, unsigned);
262 frv_cache_data_flushed (FRV_CACHE
*, int, SI
, unsigned);
265 frv_cache_read_passive_SI (FRV_CACHE
*, SI
, SI
*);