Line 34... |
Line 34... |
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
|
|
|
extern struct dev_memarea *cur_area;
|
struct ic_set {
|
struct ic_set {
|
struct {
|
struct {
|
|
unsigned long line[MAX_IC_BLOCK_SIZE];
|
unsigned long tagaddr; /* tag address */
|
unsigned long tagaddr; /* tag address */
|
int lru; /* least recently used */
|
int lru; /* least recently used */
|
} way[MAX_IC_WAYS];
|
} way[MAX_IC_WAYS];
|
} ic[MAX_IC_SETS];
|
} ic[MAX_IC_SETS];
|
|
|
Line 56... |
Line 58... |
|
|
/* First check if instruction is already in the cache and if it is:
|
/* First check if instruction is already in the cache and if it is:
|
- increment IC read hit stats,
|
- increment IC read hit stats,
|
- set 'lru' at this way to config.ic.ustates - 1 and
|
- set 'lru' at this way to config.ic.ustates - 1 and
|
decrement 'lru' of other ways unless they have reached 0,
|
decrement 'lru' of other ways unless they have reached 0,
|
|
- read insn from the cache line
|
and if not:
|
and if not:
|
- increment IC read miss stats
|
- increment IC read miss stats
|
- find lru way and entry and replace old tag with tag of the 'fetchaddr'
|
- find lru way and entry and replace old tag with tag of the 'fetchaddr'
|
- set 'lru' with config.ic.ustates - 1 and decrement 'lru' of other
|
- set 'lru' with config.ic.ustates - 1 and decrement 'lru' of other
|
ways unless they have reached 0
|
ways unless they have reached 0
|
|
- refill cache line
|
*/
|
*/
|
|
|
void ic_simulate_fetch(unsigned long fetchaddr)
|
unsigned long ic_simulate_fetch(unsigned long fetchaddr)
|
{
|
{
|
int set, way = -1;
|
int set, way = -1;
|
int i;
|
int i;
|
unsigned long tagaddr;
|
unsigned long tagaddr;
|
extern int mem_cycles;
|
extern int mem_cycles;
|
|
|
/* ICache simulation enabled/disabled. */
|
/* ICache simulation enabled/disabled. */
|
if ((!testsprbits(SPR_UPR, SPR_UPR_ICP)) || (!testsprbits(SPR_SR, SPR_SR_ICE)))
|
if ((!testsprbits(SPR_UPR, SPR_UPR_ICP)) || (!testsprbits(SPR_SR, SPR_SR_ICE)))
|
return;
|
return evalsim_mem32(fetchaddr);
|
|
|
/* Which set to check out? */
|
/* Which set to check out? */
|
set = (fetchaddr / config.ic.blocksize) % config.ic.nsets;
|
set = (fetchaddr / config.ic.blocksize) % config.ic.nsets;
|
tagaddr = (fetchaddr / config.ic.blocksize) / config.ic.nsets;
|
tagaddr = (fetchaddr / config.ic.blocksize) / config.ic.nsets;
|
|
|
Line 88... |
Line 92... |
/* Did we find our cached instruction? */
|
/* Did we find our cached instruction? */
|
if (way >= 0) { /* Yes, we did. */
|
if (way >= 0) { /* Yes, we did. */
|
ic_stats.readhit++;
|
ic_stats.readhit++;
|
|
|
for (i = 0; i < config.ic.nways; i++)
|
for (i = 0; i < config.ic.nways; i++)
|
if (ic[set].way[i].lru)
|
if (ic[set].way[i].lru > ic[set].way[way].lru)
|
ic[set].way[i].lru--;
|
ic[set].way[i].lru--;
|
ic[set].way[way].lru = config.ic.ustates - 1;
|
ic[set].way[way].lru = config.ic.ustates - 1;
|
mem_cycles += config.ic.hitdelay;
|
mem_cycles += config.ic.hitdelay;
|
|
return (ic[set].way[way].line[(fetchaddr & (config.ic.blocksize - 1)) >> 2]);
|
}
|
}
|
else { /* No, we didn't. */
|
else { /* No, we didn't. */
|
int minlru = config.ic.ustates - 1;
|
int minlru = config.ic.ustates - 1;
|
int minway = 0;
|
int minway = 0;
|
|
|
Line 103... |
Line 108... |
|
|
for (i = 0; i < config.ic.nways; i++)
|
for (i = 0; i < config.ic.nways; i++)
|
if (ic[set].way[i].lru < minlru)
|
if (ic[set].way[i].lru < minlru)
|
minway = i;
|
minway = i;
|
|
|
|
for (i = 0; i < (config.ic.blocksize); i += 4) {
|
|
ic[set].way[minway].line[((fetchaddr + i) & (config.ic.blocksize - 1)) >> 2] =
|
|
evalsim_mem32((fetchaddr & ~(config.ic.blocksize - 1)) + ((fetchaddr + i) & (config.ic.blocksize - 1)));
|
|
if(!cur_area)
|
|
return 0;
|
|
}
|
|
|
ic[set].way[minway].tagaddr = tagaddr;
|
ic[set].way[minway].tagaddr = tagaddr;
|
for (i = 0; i < config.ic.nways; i++)
|
for (i = 0; i < config.ic.nways; i++)
|
if ((ic[set].way[i].lru) &&
|
if (ic[set].way[i].lru)
|
(getsprbits(SPR_ICCR, SPR_ICCR_EW) & (1 << i)))
|
|
ic[set].way[i].lru--;
|
ic[set].way[i].lru--;
|
ic[set].way[minway].lru = config.ic.ustates - 1;
|
ic[set].way[minway].lru = config.ic.ustates - 1;
|
mem_cycles += config.ic.missdelay;
|
mem_cycles += config.ic.missdelay;
|
|
return (ic[set].way[minway].line[(fetchaddr & (config.ic.blocksize - 1)) >> 2]);
|
}
|
}
|
}
|
}
|
|
|
/* First check if data is already in the cache and if it is:
|
/* First check if data is already in the cache and if it is:
|
- invalidate block if way isn't locked
|
- invalidate block if way isn't locked
|
Line 131... |
Line 143... |
|
|
/* Which set to check out? */
|
/* Which set to check out? */
|
set = (dataaddr / config.ic.blocksize) % config.ic.nsets;
|
set = (dataaddr / config.ic.blocksize) % config.ic.nsets;
|
tagaddr = (dataaddr / config.ic.blocksize) / config.ic.nsets;
|
tagaddr = (dataaddr / config.ic.blocksize) / config.ic.nsets;
|
|
|
|
if (!testsprbits(SPR_SR, SPR_SR_ICE)) {
|
|
for (i = 0; i < config.ic.nways; i++) {
|
|
ic[set].way[i].tagaddr = -1;
|
|
ic[set].way[i].lru = 0;
|
|
}
|
|
return;
|
|
}
|
|
|
/* Scan all ways and try to find a matching way. */
|
/* Scan all ways and try to find a matching way. */
|
for (i = 0; i < config.ic.nways; i++)
|
for (i = 0; i < config.ic.nways; i++)
|
if (ic[set].way[i].tagaddr == tagaddr)
|
if (ic[set].way[i].tagaddr == tagaddr)
|
way = i;
|
way = i;
|
|
|
/* Did we find our cached data? */
|
/* Did we find our cached data? */
|
if ((way >= 0) && (getsprbits(SPR_ICCR, SPR_ICCR_EW) & (1 << way))) { /* Yes, we did. */
|
if (way >= 0) { /* Yes, we did. */
|
ic[set].way[way].tagaddr = -1;
|
ic[set].way[way].tagaddr = -1;
|
|
ic[set].way[way].lru = 0;
|
}
|
}
|
}
|
}
|
|
|
inline void ic_clock()
|
inline void ic_clock()
|
{
|
{
|