/* dcache_model.c -- data cache simulation
|
/* dcache_model.c -- data cache simulation
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
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 2 of the License, or
|
the Free Software Foundation; either version 2 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, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
/* Cache functions.
|
/* Cache functions.
|
At the moment this functions only simulate functionality of data
|
At the moment this functions only simulate functionality of data
|
caches and do not influence on fetche/decode/execute stages and timings.
|
caches and do not influence on fetche/decode/execute stages and timings.
|
They are here only to verify performance of various cache configurations.
|
They are here only to verify performance of various cache configurations.
|
*/
|
*/
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <string.h>
|
#include <string.h>
|
#include <errno.h>
|
#include <errno.h>
|
#include <stdarg.h>
|
#include <stdarg.h>
|
|
|
#include "config.h"
|
#include "config.h"
|
|
|
#ifdef HAVE_INTTYPES_H
|
#ifdef HAVE_INTTYPES_H
|
#include <inttypes.h>
|
#include <inttypes.h>
|
#endif
|
#endif
|
|
|
#include "port.h"
|
#include "port.h"
|
#include "arch.h"
|
#include "arch.h"
|
#include "dcache_model.h"
|
#include "dcache_model.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "except.h"
|
#include "except.h"
|
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "execute.h"
|
#include "execute.h"
|
#include "stats.h"
|
#include "stats.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
|
#include "misc.h"
|
|
|
/* Data cache */
|
/* Data cache */
|
|
|
struct dc_set {
|
struct dc_set {
|
struct {
|
struct {
|
uint32_t line[MAX_DC_BLOCK_SIZE];
|
uint32_t line[MAX_DC_BLOCK_SIZE];
|
oraddr_t tagaddr; /* tag address */
|
oraddr_t tagaddr; /* tag address */
|
int lru; /* least recently used */
|
int lru; /* least recently used */
|
} way[MAX_DC_WAYS];
|
} way[MAX_DC_WAYS];
|
} dc[MAX_DC_SETS];
|
} dc[MAX_DC_SETS];
|
|
|
void dc_info(void)
|
void dc_info(void)
|
{
|
{
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP)) {
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP)) {
|
PRINTF("DCache not implemented. Set UPR[DCP].\n");
|
PRINTF("DCache not implemented. Set UPR[DCP].\n");
|
return;
|
return;
|
}
|
}
|
|
|
PRINTF("Data cache %dKB: ", config.dc.nsets * config.dc.blocksize * config.dc.nways / 1024);
|
PRINTF("Data cache %dKB: ", config.dc.nsets * config.dc.blocksize * config.dc.nways / 1024);
|
PRINTF("%d ways, %d sets, block size %d bytes\n", config.dc.nways, config.dc.nsets, config.dc.blocksize);
|
PRINTF("%d ways, %d sets, block size %d bytes\n", config.dc.nways, config.dc.nsets, config.dc.blocksize);
|
}
|
}
|
|
|
/* 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:
|
- increment DC read hit stats,
|
- increment DC read hit stats,
|
- set 'lru' at this way to config.dc.ustates - 1 and
|
- set 'lru' at this way to config.dc.ustates - 1 and
|
decrement 'lru' of other ways unless they have reached 0,
|
decrement 'lru' of other ways unless they have reached 0,
|
and if not:
|
and if not:
|
- increment DC read miss stats
|
- increment DC read miss stats
|
- find lru way and entry and replace old tag with tag of the 'dataaddr'
|
- find lru way and entry and replace old tag with tag of the 'dataaddr'
|
- set 'lru' with config.dc.ustates - 1 and decrement 'lru' of other
|
- set 'lru' with config.dc.ustates - 1 and decrement 'lru' of other
|
ways unless they have reached 0
|
ways unless they have reached 0
|
- refill cache line
|
- refill cache line
|
*/
|
*/
|
|
|
uint32_t dc_simulate_read(oraddr_t dataaddr, oraddr_t virt_addr, int width)
|
uint32_t dc_simulate_read(oraddr_t dataaddr, oraddr_t virt_addr, int width)
|
{
|
{
|
int set, way = -1;
|
int set, way = -1;
|
int i;
|
int i;
|
oraddr_t tagaddr;
|
oraddr_t tagaddr;
|
uint32_t tmp;
|
uint32_t tmp;
|
|
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP) ||
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP) ||
|
!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE) ||
|
!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE) ||
|
data_ci) {
|
data_ci) {
|
if (width == 4)
|
if (width == 4)
|
tmp = evalsim_mem32(dataaddr, virt_addr);
|
tmp = evalsim_mem32(dataaddr, virt_addr);
|
else if (width == 2)
|
else if (width == 2)
|
tmp = evalsim_mem16(dataaddr, virt_addr);
|
tmp = evalsim_mem16(dataaddr, virt_addr);
|
else if (width == 1)
|
else if (width == 1)
|
tmp = evalsim_mem8(dataaddr, virt_addr);
|
tmp = evalsim_mem8(dataaddr, virt_addr);
|
|
|
if (cur_area && cur_area->log)
|
if (cur_area && cur_area->log)
|
fprintf (cur_area->log, "[%"PRIxADDR"] -> read %08"PRIx32"\n", dataaddr,
|
fprintf (cur_area->log, "[%"PRIxADDR"] -> read %08"PRIx32"\n", dataaddr,
|
tmp);
|
tmp);
|
|
|
return tmp;
|
return tmp;
|
}
|
}
|
|
|
/* Which set to check out? */
|
/* Which set to check out? */
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
|
|
/* 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.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
way = i;
|
way = i;
|
|
|
/* Did we find our cached data? */
|
/* Did we find our cached data? */
|
if (way >= 0) { /* Yes, we did. */
|
if (way >= 0) { /* Yes, we did. */
|
dc_stats.readhit++;
|
dc_stats.readhit++;
|
|
|
for (i = 0; i < config.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].lru > dc[set].way[way].lru)
|
if (dc[set].way[i].lru > dc[set].way[way].lru)
|
dc[set].way[i].lru--;
|
dc[set].way[i].lru--;
|
dc[set].way[way].lru = config.dc.ustates - 1;
|
dc[set].way[way].lru = config.dc.ustates - 1;
|
runtime.sim.mem_cycles += config.dc.load_hitdelay;
|
runtime.sim.mem_cycles += config.dc.load_hitdelay;
|
|
|
tmp = dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
tmp = dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
if (width == 4)
|
if (width == 4)
|
return tmp;
|
return tmp;
|
else if (width == 2) {
|
else if (width == 2) {
|
tmp = ((tmp >> ((dataaddr & 2) ? 0 : 16)) & 0xffff);
|
tmp = ((tmp >> ((dataaddr & 2) ? 0 : 16)) & 0xffff);
|
return tmp;
|
return tmp;
|
}
|
}
|
else if (width == 1) {
|
else if (width == 1) {
|
tmp = ((tmp >> (8 * (3 - (dataaddr & 3)))) & 0xff);
|
tmp = ((tmp >> (8 * (3 - (dataaddr & 3)))) & 0xff);
|
return tmp;
|
return tmp;
|
}
|
}
|
} else { /* No, we didn't. */
|
} else { /* No, we didn't. */
|
int minlru = config.dc.ustates - 1;
|
int minlru = config.dc.ustates - 1;
|
int minway = 0;
|
int minway = 0;
|
|
|
dc_stats.readmiss++;
|
dc_stats.readmiss++;
|
|
|
for (i = 0; i < config.dc.nways; i++) {
|
for (i = 0; i < config.dc.nways; i++) {
|
if (dc[set].way[i].lru < minlru) {
|
if (dc[set].way[i].lru < minlru) {
|
minway = i;
|
minway = i;
|
minlru = dc[set].way[i].lru;
|
minlru = dc[set].way[i].lru;
|
}
|
}
|
}
|
}
|
|
|
for (i = 0; i < (config.dc.blocksize); i += 4) {
|
for (i = 0; i < (config.dc.blocksize); i += 4) {
|
dc[set].way[minway].line[((dataaddr + i) & (config.dc.blocksize - 1)) >> 2] =
|
dc[set].way[minway].line[((dataaddr + i) & (config.dc.blocksize - 1)) >> 2] =
|
/* FIXME: What is the virtual address meant to be? (ie. What happens if
|
/* FIXME: What is the virtual address meant to be? (ie. What happens if
|
* we read out of memory while refilling a cache line?) */
|
* we read out of memory while refilling a cache line?) */
|
evalsim_mem32((dataaddr & ~(config.dc.blocksize - 1)) + (((dataaddr & ~ADDR_C(3)) + i) & (config.dc.blocksize - 1)), 0);
|
evalsim_mem32((dataaddr & ~(config.dc.blocksize - 1)) + (((dataaddr & ~ADDR_C(3)) + i) & (config.dc.blocksize - 1)), 0);
|
if(!cur_area) {
|
if(!cur_area) {
|
dc[set].way[minway].tagaddr = -1;
|
dc[set].way[minway].tagaddr = -1;
|
dc[set].way[minway].lru = 0;
|
dc[set].way[minway].lru = 0;
|
return 0;
|
return 0;
|
} else if (cur_area->log)
|
} else if (cur_area->log)
|
fprintf (cur_area->log, "[%"PRIxADDR"] -> read %08"PRIx32"\n", dataaddr,
|
fprintf (cur_area->log, "[%"PRIxADDR"] -> read %08"PRIx32"\n", dataaddr,
|
tmp);
|
tmp);
|
}
|
}
|
|
|
dc[set].way[minway].tagaddr = tagaddr;
|
dc[set].way[minway].tagaddr = tagaddr;
|
for (i = 0; i < config.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].lru)
|
if (dc[set].way[i].lru)
|
dc[set].way[i].lru--;
|
dc[set].way[i].lru--;
|
dc[set].way[minway].lru = config.dc.ustates - 1;
|
dc[set].way[minway].lru = config.dc.ustates - 1;
|
runtime.sim.mem_cycles += config.dc.load_missdelay;
|
runtime.sim.mem_cycles += config.dc.load_missdelay;
|
|
|
tmp = dc[set].way[minway].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
tmp = dc[set].way[minway].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
if (width == 4)
|
if (width == 4)
|
return tmp;
|
return tmp;
|
else if (width == 2) {
|
else if (width == 2) {
|
tmp = (tmp >> ((dataaddr & 2) ? 0 : 16)) & 0xffff;
|
tmp = (tmp >> ((dataaddr & 2) ? 0 : 16)) & 0xffff;
|
return tmp;
|
return tmp;
|
}
|
}
|
else if (width == 1) {
|
else if (width == 1) {
|
tmp = (tmp >> (8 * (3 - (dataaddr & 3)))) & 0xff;
|
tmp = (tmp >> (8 * (3 - (dataaddr & 3)))) & 0xff;
|
return tmp;
|
return tmp;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/* 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:
|
- increment DC write hit stats,
|
- increment DC write hit stats,
|
- set 'lru' at this way to config.dc.ustates - 1 and
|
- set 'lru' at this way to config.dc.ustates - 1 and
|
decrement 'lru' of other ways unless they have reached 0,
|
decrement 'lru' of other ways unless they have reached 0,
|
and if not:
|
and if not:
|
- increment DC write miss stats
|
- increment DC write miss stats
|
- find lru way and entry and replace old tag with tag of the 'dataaddr'
|
- find lru way and entry and replace old tag with tag of the 'dataaddr'
|
- set 'lru' with config.dc.ustates - 1 and decrement 'lru' of other
|
- set 'lru' with config.dc.ustates - 1 and decrement 'lru' of other
|
ways unless they have reached 0
|
ways unless they have reached 0
|
*/
|
*/
|
|
|
void dc_simulate_write(oraddr_t dataaddr, oraddr_t virt_addr, uint32_t data,
|
void dc_simulate_write(oraddr_t dataaddr, oraddr_t virt_addr, uint32_t data,
|
int width)
|
int width)
|
{
|
{
|
int set, way = -1;
|
int set, way = -1;
|
int i;
|
int i;
|
oraddr_t tagaddr;
|
oraddr_t tagaddr;
|
uint32_t tmp;
|
uint32_t tmp;
|
|
|
if (width == 4)
|
if (width == 4)
|
setsim_mem32(dataaddr, virt_addr, data);
|
setsim_mem32(dataaddr, virt_addr, data);
|
else if (width == 2)
|
else if (width == 2)
|
setsim_mem16(dataaddr, virt_addr, data);
|
setsim_mem16(dataaddr, virt_addr, data);
|
else if (width == 1)
|
else if (width == 1)
|
setsim_mem8(dataaddr, virt_addr, data);
|
setsim_mem8(dataaddr, virt_addr, data);
|
|
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP) ||
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP) ||
|
!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE) ||
|
!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE) ||
|
data_ci || !cur_area)
|
data_ci || !cur_area)
|
return;
|
return;
|
|
|
/* Which set to check out? */
|
/* Which set to check out? */
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
|
|
/* 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.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
way = i;
|
way = i;
|
|
|
/* Did we find our cached data? */
|
/* Did we find our cached data? */
|
if (way >= 0) { /* Yes, we did. */
|
if (way >= 0) { /* Yes, we did. */
|
dc_stats.writehit++;
|
dc_stats.writehit++;
|
|
|
for (i = 0; i < config.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].lru > dc[set].way[way].lru)
|
if (dc[set].way[i].lru > dc[set].way[way].lru)
|
dc[set].way[i].lru--;
|
dc[set].way[i].lru--;
|
dc[set].way[way].lru = config.dc.ustates - 1;
|
dc[set].way[way].lru = config.dc.ustates - 1;
|
runtime.sim.mem_cycles += config.dc.store_hitdelay;
|
runtime.sim.mem_cycles += config.dc.store_hitdelay;
|
|
|
tmp = dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
tmp = dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2];
|
if (width == 4)
|
if (width == 4)
|
tmp = data;
|
tmp = data;
|
else if (width == 2) {
|
else if (width == 2) {
|
tmp &= 0xffff << ((dataaddr & 2) ? 16 : 0);
|
tmp &= 0xffff << ((dataaddr & 2) ? 16 : 0);
|
tmp |= (data & 0xffff) << ((dataaddr & 2) ? 0 : 16);
|
tmp |= (data & 0xffff) << ((dataaddr & 2) ? 0 : 16);
|
}
|
}
|
else if (width == 1) {
|
else if (width == 1) {
|
tmp &= ~(0xff << (8 * (3 - (dataaddr & 3))));
|
tmp &= ~(0xff << (8 * (3 - (dataaddr & 3))));
|
tmp |= (data & 0xff) << (8 * (3 - (dataaddr & 3)));
|
tmp |= (data & 0xff) << (8 * (3 - (dataaddr & 3)));
|
}
|
}
|
dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2] = tmp;
|
dc[set].way[way].line[(dataaddr & (config.dc.blocksize - 1)) >> 2] = tmp;
|
}
|
}
|
else { /* No, we didn't. */
|
else { /* No, we didn't. */
|
int minlru = config.dc.ustates - 1;
|
int minlru = config.dc.ustates - 1;
|
int minway = 0;
|
int minway = 0;
|
|
|
dc_stats.writemiss++;
|
dc_stats.writemiss++;
|
|
|
for (i = 0; i < config.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].lru < minlru)
|
if (dc[set].way[i].lru < minlru)
|
minway = i;
|
minway = i;
|
|
|
for (i = 0; i < (config.dc.blocksize); i += 4) {
|
for (i = 0; i < (config.dc.blocksize); i += 4) {
|
dc[set].way[minway].line[((dataaddr + i) & (config.dc.blocksize - 1)) >> 2] =
|
dc[set].way[minway].line[((dataaddr + i) & (config.dc.blocksize - 1)) >> 2] =
|
/* FIXME: Same comment as in dc_simulate_read */
|
/* FIXME: Same comment as in dc_simulate_read */
|
evalsim_mem32((dataaddr & ~(config.dc.blocksize - 1)) + (((dataaddr & ~3ul)+ i) & (config.dc.blocksize - 1)), 0);
|
evalsim_mem32((dataaddr & ~(config.dc.blocksize - 1)) + (((dataaddr & ~3ul)+ i) & (config.dc.blocksize - 1)), 0);
|
if(!cur_area) {
|
if(!cur_area) {
|
dc[set].way[minway].tagaddr = -1;
|
dc[set].way[minway].tagaddr = -1;
|
dc[set].way[minway].lru = 0;
|
dc[set].way[minway].lru = 0;
|
return;
|
return;
|
}
|
}
|
}
|
}
|
|
|
dc[set].way[minway].tagaddr = tagaddr;
|
dc[set].way[minway].tagaddr = tagaddr;
|
for (i = 0; i < config.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].lru)
|
if (dc[set].way[i].lru)
|
dc[set].way[i].lru--;
|
dc[set].way[i].lru--;
|
dc[set].way[minway].lru = config.dc.ustates - 1;
|
dc[set].way[minway].lru = config.dc.ustates - 1;
|
runtime.sim.mem_cycles += config.dc.store_missdelay;
|
runtime.sim.mem_cycles += config.dc.store_missdelay;
|
}
|
}
|
}
|
}
|
|
|
/* 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
|
otherwise don't do anything.
|
otherwise don't do anything.
|
*/
|
*/
|
|
|
void dc_inv(oraddr_t dataaddr)
|
void dc_inv(oraddr_t dataaddr)
|
{
|
{
|
int set, way = -1;
|
int set, way = -1;
|
int i;
|
int i;
|
oraddr_t tagaddr;
|
oraddr_t tagaddr;
|
|
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP))
|
if (!(cpu_state.sprs[SPR_UPR] & SPR_UPR_DCP))
|
return;
|
return;
|
|
|
/* Which set to check out? */
|
/* Which set to check out? */
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
set = (dataaddr / config.dc.blocksize) % config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
tagaddr = (dataaddr / config.dc.blocksize) / config.dc.nsets;
|
|
|
if (!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE)) {
|
if (!(cpu_state.sprs[SPR_SR] & SPR_SR_DCE)) {
|
for (i = 0; i < config.dc.nways; i++) {
|
for (i = 0; i < config.dc.nways; i++) {
|
dc[set].way[i].tagaddr = -1;
|
dc[set].way[i].tagaddr = -1;
|
dc[set].way[i].lru = 0;
|
dc[set].way[i].lru = 0;
|
}
|
}
|
return;
|
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.dc.nways; i++)
|
for (i = 0; i < config.dc.nways; i++)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
if (dc[set].way[i].tagaddr == tagaddr)
|
way = i;
|
way = i;
|
|
|
/* Did we find our cached data? */
|
/* Did we find our cached data? */
|
if (way >= 0) { /* Yes, we did. */
|
if (way >= 0) { /* Yes, we did. */
|
dc[set].way[way].tagaddr = -1;
|
dc[set].way[way].tagaddr = -1;
|
dc[set].way[way].lru = 0;
|
dc[set].way[way].lru = 0;
|
}
|
}
|
}
|
}
|
|
|
/*-----------------------------------------------------[ DC configuration ]---*/
|
/*-----------------------------------------------------[ DC configuration ]---*/
|
void dc_enabled(union param_val val, void *dat)
|
void dc_enabled(union param_val val, void *dat)
|
{
|
{
|
config.dc.enabled = val.int_val;
|
config.dc.enabled = val.int_val;
|
if(val.int_val)
|
if(val.int_val)
|
cpu_state.sprs[SPR_UPR] |= SPR_UPR_DCP;
|
cpu_state.sprs[SPR_UPR] |= SPR_UPR_DCP;
|
else
|
else
|
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_DCP;
|
cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_DCP;
|
}
|
}
|
|
|
void dc_nsets(union param_val val, void *dat)
|
void dc_nsets(union param_val val, void *dat)
|
{
|
{
|
if (is_power2(val.int_val) && val.int_val <= MAX_DC_SETS){
|
if (is_power2(val.int_val) && val.int_val <= MAX_DC_SETS){
|
config.dc.nsets = val.int_val;
|
config.dc.nsets = val.int_val;
|
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCS;
|
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCS;
|
cpu_state.sprs[SPR_DCCFGR] |= log2(val.int_val) << 3;
|
cpu_state.sprs[SPR_DCCFGR] |= log2_int(val.int_val) << 3;
|
}
|
}
|
else {
|
else {
|
char tmp[200];
|
char tmp[200];
|
sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
|
sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS);
|
CONFIG_ERROR(tmp);
|
CONFIG_ERROR(tmp);
|
}
|
}
|
}
|
}
|
|
|
void dc_nways(union param_val val, void *dat)
|
void dc_nways(union param_val val, void *dat)
|
{
|
{
|
if (is_power2(val.int_val) && val.int_val <= MAX_DC_WAYS){
|
if (is_power2(val.int_val) && val.int_val <= MAX_DC_WAYS){
|
config.dc.nways = val.int_val;
|
config.dc.nways = val.int_val;
|
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCW;
|
cpu_state.sprs[SPR_DCCFGR] &= ~SPR_DCCFGR_NCW;
|
cpu_state.sprs[SPR_DCCFGR] |= log2(val.int_val);
|
cpu_state.sprs[SPR_DCCFGR] |= log2_int(val.int_val);
|
}
|
}
|
else{
|
else{
|
char tmp[200];
|
char tmp[200];
|
sprintf (tmp, "value of power of two and lower or equal than %i expected.",
|
sprintf (tmp, "value of power of two and lower or equal than %i expected.",
|
MAX_DC_WAYS);
|
MAX_DC_WAYS);
|
CONFIG_ERROR(tmp);
|
CONFIG_ERROR(tmp);
|
}
|
}
|
}
|
}
|
|
|
void dc_blocksize(union param_val val, void *dat)
|
void dc_blocksize(union param_val val, void *dat)
|
{
|
{
|
if (is_power2(val.int_val)) {
|
if (is_power2(val.int_val)) {
|
config.dc.blocksize = val.int_val;
|
config.dc.blocksize = val.int_val;
|
cpu_state.sprs[SPR_ICCFGR] &= ~SPR_ICCFGR_CBS;
|
cpu_state.sprs[SPR_ICCFGR] &= ~SPR_ICCFGR_CBS;
|
cpu_state.sprs[SPR_ICCFGR] |= log2(val.int_val) << 7;
|
cpu_state.sprs[SPR_ICCFGR] |= log2_int(val.int_val) << 7;
|
} else
|
} else
|
CONFIG_ERROR("value of power of two expected.");
|
CONFIG_ERROR("value of power of two expected.");
|
}
|
}
|
|
|
void dc_ustates(union param_val val, void *dat)
|
void dc_ustates(union param_val val, void *dat)
|
{
|
{
|
if (val.int_val >= 2 && val.int_val <= 4)
|
if (val.int_val >= 2 && val.int_val <= 4)
|
config.dc.ustates = val.int_val;
|
config.dc.ustates = val.int_val;
|
else
|
else
|
CONFIG_ERROR("invalid USTATE.");
|
CONFIG_ERROR("invalid USTATE.");
|
}
|
}
|
|
|
void dc_load_missdelay(union param_val val, void *dat)
|
void dc_load_missdelay(union param_val val, void *dat)
|
{
|
{
|
config.dc.load_missdelay = val.int_val;
|
config.dc.load_missdelay = val.int_val;
|
}
|
}
|
|
|
void dc_load_hitdelay(union param_val val, void *dat)
|
void dc_load_hitdelay(union param_val val, void *dat)
|
{
|
{
|
config.dc.load_hitdelay = val.int_val;
|
config.dc.load_hitdelay = val.int_val;
|
}
|
}
|
|
|
void dc_store_missdelay(union param_val val, void *dat)
|
void dc_store_missdelay(union param_val val, void *dat)
|
{
|
{
|
config.dc.store_missdelay = val.int_val;
|
config.dc.store_missdelay = val.int_val;
|
}
|
}
|
|
|
void dc_store_hitdelay(union param_val val, void *dat)
|
void dc_store_hitdelay(union param_val val, void *dat)
|
{
|
{
|
config.dc.store_hitdelay = val.int_val;
|
config.dc.store_hitdelay = val.int_val;
|
}
|
}
|
|
|
void reg_dc_sec(void)
|
void reg_dc_sec(void)
|
{
|
{
|
struct config_section *sec = reg_config_sec("dc", NULL, NULL);
|
struct config_section *sec = reg_config_sec("dc", NULL, NULL);
|
|
|
reg_config_param(sec, "enabled", paramt_int, dc_enabled);
|
reg_config_param(sec, "enabled", paramt_int, dc_enabled);
|
reg_config_param(sec, "nsets", paramt_int, dc_nsets);
|
reg_config_param(sec, "nsets", paramt_int, dc_nsets);
|
reg_config_param(sec, "nways", paramt_int, dc_nways);
|
reg_config_param(sec, "nways", paramt_int, dc_nways);
|
reg_config_param(sec, "blocksize", paramt_int, dc_blocksize);
|
reg_config_param(sec, "blocksize", paramt_int, dc_blocksize);
|
reg_config_param(sec, "ustates", paramt_int, dc_ustates);
|
reg_config_param(sec, "ustates", paramt_int, dc_ustates);
|
reg_config_param(sec, "load_missdelay", paramt_int, dc_load_missdelay);
|
reg_config_param(sec, "load_missdelay", paramt_int, dc_load_missdelay);
|
reg_config_param(sec, "load_hitdelay", paramt_int, dc_load_hitdelay);
|
reg_config_param(sec, "load_hitdelay", paramt_int, dc_load_hitdelay);
|
reg_config_param(sec, "store_missdelay", paramt_int, dc_store_missdelay);
|
reg_config_param(sec, "store_missdelay", paramt_int, dc_store_missdelay);
|
reg_config_param(sec, "store_hitdelay", paramt_int, dc_store_hitdelay);
|
reg_config_param(sec, "store_hitdelay", paramt_int, dc_store_hitdelay);
|
}
|
}
|
|
|