OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [tags/] [gdb/] [gdb-6.8/] [gdb-6.8.openrisc-2.1/] [sim/] [frv/] [cache.h] - Diff between revs 24 and 33

Only display areas with differences | Details | Blame | View Log

Rev 24 Rev 33
/* Cache support for the FRV simulator
/* Cache support for the FRV simulator
   Copyright (C) 1999, 2000, 2003, 2007, 2008 Free Software Foundation, Inc.
   Copyright (C) 1999, 2000, 2003, 2007, 2008 Free Software Foundation, Inc.
   Contributed by Red Hat.
   Contributed by Red Hat.
 
 
This file is part of the GNU Simulators.
This file is part of the GNU Simulators.
 
 
This program is free software; you can redistribute it and/or modify
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
#ifndef CACHE_H
#ifndef CACHE_H
#define CACHE_H
#define CACHE_H
 
 
/* A representation of a set-associative cache with LRU replacement,
/* A representation of a set-associative cache with LRU replacement,
   cache line locking, non-blocking support and multiple read ports.  */
   cache line locking, non-blocking support and multiple read ports.  */
 
 
/* An enumeration of cache pipeline request kinds.  */
/* An enumeration of cache pipeline request kinds.  */
typedef enum
typedef enum
{
{
  req_load,
  req_load,
  req_store,
  req_store,
  req_invalidate,
  req_invalidate,
  req_flush,
  req_flush,
  req_preload,
  req_preload,
  req_unlock,
  req_unlock,
  req_WAR
  req_WAR
} FRV_CACHE_REQUEST_KIND;
} FRV_CACHE_REQUEST_KIND;
 
 
/* The cache pipeline requests.  */
/* The cache pipeline requests.  */
typedef struct {
typedef struct {
  int preload;
  int preload;
  int lock;
  int lock;
} FRV_CACHE_WAR_REQUEST;
} FRV_CACHE_WAR_REQUEST;
 
 
typedef struct {
typedef struct {
  char *data;
  char *data;
  int length;
  int length;
} FRV_CACHE_STORE_REQUEST;
} FRV_CACHE_STORE_REQUEST;
 
 
typedef struct {
typedef struct {
  int flush;
  int flush;
  int all;
  int all;
} FRV_CACHE_INVALIDATE_REQUEST;
} FRV_CACHE_INVALIDATE_REQUEST;
 
 
typedef struct {
typedef struct {
  int lock;
  int lock;
  int length;
  int length;
} FRV_CACHE_PRELOAD_REQUEST;
} FRV_CACHE_PRELOAD_REQUEST;
 
 
/* A cache pipeline request.  */
/* A cache pipeline request.  */
typedef struct frv_cache_request
typedef struct frv_cache_request
{
{
  struct frv_cache_request *next;
  struct frv_cache_request *next;
  struct frv_cache_request *prev;
  struct frv_cache_request *prev;
  FRV_CACHE_REQUEST_KIND kind;
  FRV_CACHE_REQUEST_KIND kind;
  unsigned reqno;
  unsigned reqno;
  unsigned priority;
  unsigned priority;
  SI address;
  SI address;
  union {
  union {
    FRV_CACHE_STORE_REQUEST store;
    FRV_CACHE_STORE_REQUEST store;
    FRV_CACHE_INVALIDATE_REQUEST invalidate;
    FRV_CACHE_INVALIDATE_REQUEST invalidate;
    FRV_CACHE_PRELOAD_REQUEST preload;
    FRV_CACHE_PRELOAD_REQUEST preload;
    FRV_CACHE_WAR_REQUEST WAR;
    FRV_CACHE_WAR_REQUEST WAR;
  } u;
  } u;
} FRV_CACHE_REQUEST;
} FRV_CACHE_REQUEST;
 
 
/* The buffer for returning data to the caller.  */
/* The buffer for returning data to the caller.  */
typedef struct {
typedef struct {
  unsigned reqno;
  unsigned reqno;
  SI address;
  SI address;
  char *data;
  char *data;
  int valid;
  int valid;
} FRV_CACHE_RETURN_BUFFER;
} FRV_CACHE_RETURN_BUFFER;
 
 
/* The status of flush requests.  */
/* The status of flush requests.  */
typedef struct {
typedef struct {
  unsigned reqno;
  unsigned reqno;
  SI address;
  SI address;
  int valid;
  int valid;
} FRV_CACHE_FLUSH_STATUS;
} FRV_CACHE_FLUSH_STATUS;
 
 
/* Communicate status of requests to the caller.  */
/* Communicate status of requests to the caller.  */
typedef struct {
typedef struct {
  FRV_CACHE_FLUSH_STATUS  flush;
  FRV_CACHE_FLUSH_STATUS  flush;
  FRV_CACHE_RETURN_BUFFER return_buffer;
  FRV_CACHE_RETURN_BUFFER return_buffer;
} FRV_CACHE_STATUS;
} FRV_CACHE_STATUS;
 
 
/* A cache pipeline stage.  */
/* A cache pipeline stage.  */
typedef struct {
typedef struct {
  FRV_CACHE_REQUEST *request;
  FRV_CACHE_REQUEST *request;
} FRV_CACHE_STAGE;
} FRV_CACHE_STAGE;
 
 
enum {
enum {
  FIRST_STAGE,
  FIRST_STAGE,
  A_STAGE = FIRST_STAGE, /* Addressing stage */
  A_STAGE = FIRST_STAGE, /* Addressing stage */
  I_STAGE,               /* Interference stage */
  I_STAGE,               /* Interference stage */
  LAST_STAGE = I_STAGE,
  LAST_STAGE = I_STAGE,
  FRV_CACHE_STAGES
  FRV_CACHE_STAGES
};
};
 
 
/* Representation of the WAR register.  */
/* Representation of the WAR register.  */
typedef struct {
typedef struct {
  unsigned reqno;
  unsigned reqno;
  unsigned priority;
  unsigned priority;
  SI address;
  SI address;
  int preload;
  int preload;
  int lock;
  int lock;
  int latency;
  int latency;
  int valid;
  int valid;
} FRV_CACHE_WAR;
} FRV_CACHE_WAR;
 
 
/* A cache pipeline.  */
/* A cache pipeline.  */
#define NUM_WARS 2
#define NUM_WARS 2
typedef struct {
typedef struct {
  FRV_CACHE_REQUEST      *requests;
  FRV_CACHE_REQUEST      *requests;
  FRV_CACHE_STAGE         stages[FRV_CACHE_STAGES];
  FRV_CACHE_STAGE         stages[FRV_CACHE_STAGES];
  FRV_CACHE_WAR           WAR[NUM_WARS];
  FRV_CACHE_WAR           WAR[NUM_WARS];
  FRV_CACHE_STATUS        status;
  FRV_CACHE_STATUS        status;
} FRV_CACHE_PIPELINE;
} FRV_CACHE_PIPELINE;
 
 
enum {LS, LD, FRV_CACHE_PIPELINES};
enum {LS, LD, FRV_CACHE_PIPELINES};
 
 
/* Representation of the xARS registers.  */
/* Representation of the xARS registers.  */
typedef struct {
typedef struct {
  int pipe;
  int pipe;
  unsigned reqno;
  unsigned reqno;
  unsigned priority;
  unsigned priority;
  SI address;
  SI address;
  int preload;
  int preload;
  int lock;
  int lock;
  int valid;
  int valid;
} FRV_CACHE_ARS;
} FRV_CACHE_ARS;
 
 
/* A cache tag.  */
/* A cache tag.  */
typedef struct {
typedef struct {
  USI   tag;    /* Address tag.  */
  USI   tag;    /* Address tag.  */
  int   lru;    /* Lower values indicates less recently used.  */
  int   lru;    /* Lower values indicates less recently used.  */
  char *line;   /* Points to storage for line in data_storage.  */
  char *line;   /* Points to storage for line in data_storage.  */
  char  dirty;  /* line has been written to since last stored?  */
  char  dirty;  /* line has been written to since last stored?  */
  char  locked; /* line is locked?  */
  char  locked; /* line is locked?  */
  char  valid;  /* tag is valid?  */
  char  valid;  /* tag is valid?  */
} FRV_CACHE_TAG;
} FRV_CACHE_TAG;
 
 
/* Cache statistics.  */
/* Cache statistics.  */
typedef struct {
typedef struct {
  unsigned long accesses;   /* number of cache accesses.  */
  unsigned long accesses;   /* number of cache accesses.  */
  unsigned long hits;       /* number of cache hits.  */
  unsigned long hits;       /* number of cache hits.  */
} FRV_CACHE_STATISTICS;
} FRV_CACHE_STATISTICS;
 
 
/* The cache itself.
/* The cache itself.
   Notes:
   Notes:
   - line_size must be a power of 2
   - line_size must be a power of 2
   - sets must be a power of 2
   - sets must be a power of 2
   - ways must be a power of 2
   - ways must be a power of 2
*/
*/
typedef struct {
typedef struct {
  SIM_CPU *cpu;
  SIM_CPU *cpu;
  unsigned configured_ways;   /* Number of ways configured in each set.  */
  unsigned configured_ways;   /* Number of ways configured in each set.  */
  unsigned configured_sets;   /* Number of sets configured in the cache.  */
  unsigned configured_sets;   /* Number of sets configured in the cache.  */
  unsigned ways;              /* Number of ways in each set.  */
  unsigned ways;              /* Number of ways in each set.  */
  unsigned sets;              /* Number of sets in the cache.  */
  unsigned sets;              /* Number of sets in the cache.  */
  unsigned line_size;         /* Size of each cache line.  */
  unsigned line_size;         /* Size of each cache line.  */
  unsigned memory_latency;    /* Latency of main memory in cycles.  */
  unsigned memory_latency;    /* Latency of main memory in cycles.  */
  FRV_CACHE_TAG *tag_storage; /* Storage for tags.  */
  FRV_CACHE_TAG *tag_storage; /* Storage for tags.  */
  char *data_storage;         /* Storage for data (cache lines).  */
  char *data_storage;         /* Storage for data (cache lines).  */
  FRV_CACHE_PIPELINE pipeline[2];  /* Cache pipelines.  */
  FRV_CACHE_PIPELINE pipeline[2];  /* Cache pipelines.  */
  FRV_CACHE_ARS BARS;         /* BARS register.  */
  FRV_CACHE_ARS BARS;         /* BARS register.  */
  FRV_CACHE_ARS NARS;         /* BARS register.  */
  FRV_CACHE_ARS NARS;         /* BARS register.  */
  FRV_CACHE_STATISTICS statistics; /* Operation statistics.  */
  FRV_CACHE_STATISTICS statistics; /* Operation statistics.  */
} FRV_CACHE;
} FRV_CACHE;
 
 
/* The tags are stored by ways within sets in order to make computations
/* The tags are stored by ways within sets in order to make computations
   easier.  */
   easier.  */
#define CACHE_TAG(cache, set, way) ( \
#define CACHE_TAG(cache, set, way) ( \
  & ((cache)->tag_storage[(set) * (cache)->ways + (way)]) \
  & ((cache)->tag_storage[(set) * (cache)->ways + (way)]) \
)
)
 
 
/* Compute the address tag corresponding to the given address.  */
/* Compute the address tag corresponding to the given address.  */
#define CACHE_ADDRESS_TAG(cache, address) ( \
#define CACHE_ADDRESS_TAG(cache, address) ( \
  (address) & ~(((cache)->line_size * (cache)->sets) - 1) \
  (address) & ~(((cache)->line_size * (cache)->sets) - 1) \
)
)
 
 
/* Determine the index at which the set containing this tag starts.  */
/* Determine the index at which the set containing this tag starts.  */
#define CACHE_TAG_SET_START(cache, tag) ( \
#define CACHE_TAG_SET_START(cache, tag) ( \
  ((tag) - (cache)->tag_storage) & ~((cache)->ways - 1) \
  ((tag) - (cache)->tag_storage) & ~((cache)->ways - 1) \
)
)
 
 
/* Determine the number of the set which this cache tag is in.  */
/* Determine the number of the set which this cache tag is in.  */
#define CACHE_TAG_SET_NUMBER(cache, tag) ( \
#define CACHE_TAG_SET_NUMBER(cache, tag) ( \
  CACHE_TAG_SET_START ((cache), (tag)) / (cache)->ways \
  CACHE_TAG_SET_START ((cache), (tag)) / (cache)->ways \
)
)
 
 
#define CACHE_RETURN_DATA(cache, slot, address, mode, N) (               \
#define CACHE_RETURN_DATA(cache, slot, address, mode, N) (               \
  T2H_##N (*(mode *)(& (cache)->pipeline[slot].status.return_buffer.data \
  T2H_##N (*(mode *)(& (cache)->pipeline[slot].status.return_buffer.data \
                     [((address) & ((cache)->line_size - 1))]))          \
                     [((address) & ((cache)->line_size - 1))]))          \
)
)
#define CACHE_RETURN_DATA_ADDRESS(cache, slot, address, N) (              \
#define CACHE_RETURN_DATA_ADDRESS(cache, slot, address, N) (              \
  ((void *)& (cache)->pipeline[slot].status.return_buffer.data[(address)  \
  ((void *)& (cache)->pipeline[slot].status.return_buffer.data[(address)  \
                                               & ((cache)->line_size - 1)]) \
                                               & ((cache)->line_size - 1)]) \
)
)
 
 
#define DATA_CROSSES_CACHE_LINE(cache, address, size) ( \
#define DATA_CROSSES_CACHE_LINE(cache, address, size) ( \
  ((address) & ((cache)->line_size - 1)) + (size) > (cache)->line_size \
  ((address) & ((cache)->line_size - 1)) + (size) > (cache)->line_size \
)
)
 
 
#define CACHE_INITIALIZED(cache) ((cache)->data_storage != NULL)
#define CACHE_INITIALIZED(cache) ((cache)->data_storage != NULL)
 
 
/* These functions are used to initialize and terminate a cache.  */
/* These functions are used to initialize and terminate a cache.  */
void
void
frv_cache_init (SIM_CPU *, FRV_CACHE *);
frv_cache_init (SIM_CPU *, FRV_CACHE *);
void
void
frv_cache_term (FRV_CACHE *);
frv_cache_term (FRV_CACHE *);
void
void
frv_cache_reconfigure (SIM_CPU *, FRV_CACHE *);
frv_cache_reconfigure (SIM_CPU *, FRV_CACHE *);
int
int
frv_cache_enabled (FRV_CACHE *);
frv_cache_enabled (FRV_CACHE *);
 
 
/* These functions are used to operate the cache in non-cycle-accurate mode.
/* These functions are used to operate the cache in non-cycle-accurate mode.
   Each request is handled individually and immediately using the current
   Each request is handled individually and immediately using the current
   cache internal state.  */
   cache internal state.  */
int
int
frv_cache_read (FRV_CACHE *, int, SI);
frv_cache_read (FRV_CACHE *, int, SI);
int
int
frv_cache_write (FRV_CACHE *, SI, char *, unsigned);
frv_cache_write (FRV_CACHE *, SI, char *, unsigned);
int
int
frv_cache_preload (FRV_CACHE *, SI, USI, int);
frv_cache_preload (FRV_CACHE *, SI, USI, int);
int
int
frv_cache_invalidate (FRV_CACHE *, SI, int);
frv_cache_invalidate (FRV_CACHE *, SI, int);
int
int
frv_cache_invalidate_all (FRV_CACHE *, int);
frv_cache_invalidate_all (FRV_CACHE *, int);
 
 
/* These functions are used to operate the cache in cycle-accurate mode.
/* These functions are used to operate the cache in cycle-accurate mode.
   The internal operation of the cache is simulated down to the cycle level.  */
   The internal operation of the cache is simulated down to the cycle level.  */
#define NO_REQNO 0xffffffff
#define NO_REQNO 0xffffffff
void
void
frv_cache_request_load (FRV_CACHE *, unsigned, SI, int);
frv_cache_request_load (FRV_CACHE *, unsigned, SI, int);
void
void
frv_cache_request_store (FRV_CACHE *, SI, int, char *, unsigned);
frv_cache_request_store (FRV_CACHE *, SI, int, char *, unsigned);
void
void
frv_cache_request_invalidate (FRV_CACHE *, unsigned, SI, int, int, int);
frv_cache_request_invalidate (FRV_CACHE *, unsigned, SI, int, int, int);
void
void
frv_cache_request_preload (FRV_CACHE *, SI, int, int, int);
frv_cache_request_preload (FRV_CACHE *, SI, int, int, int);
void
void
frv_cache_request_unlock (FRV_CACHE *, SI, int);
frv_cache_request_unlock (FRV_CACHE *, SI, int);
 
 
void
void
frv_cache_run (FRV_CACHE *, int);
frv_cache_run (FRV_CACHE *, int);
 
 
int
int
frv_cache_data_in_buffer (FRV_CACHE*, int, SI, unsigned);
frv_cache_data_in_buffer (FRV_CACHE*, int, SI, unsigned);
int
int
frv_cache_data_flushed (FRV_CACHE*, int, SI, unsigned);
frv_cache_data_flushed (FRV_CACHE*, int, SI, unsigned);
 
 
int
int
frv_cache_read_passive_SI (FRV_CACHE *, SI, SI *);
frv_cache_read_passive_SI (FRV_CACHE *, SI, SI *);
 
 
#endif /* CACHE_H */
#endif /* CACHE_H */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.