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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [testbench/] [cache.c] - Diff between revs 424 and 484

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 424 Rev 484
Line 1... Line 1...
/* Cache test */
/* Cache test */
#include "support.h"
#include "support.h"
#include "spr_defs.h"
#include "spr_defs.h"
 
 
#define MEM_RAM 0x40000000
#define MEM_RAM 0x40100000
 
 
/* Number of IC sets (power of 2) */
/* Number of IC sets (power of 2) */
#define IC_SETS 512
#define IC_SETS 512
#define DC_SETS 512
#define DC_SETS 512
 
 
Line 26... Line 26...
#define REG32(add) *((volatile unsigned long *)(add))
#define REG32(add) *((volatile unsigned long *)(add))
 
 
extern void (*jalr)(void);
extern void (*jalr)(void);
extern void (*jr)(void);
extern void (*jr)(void);
 
 
 
/* Index on jump table */
 
unsigned long jump_indx;
 
 
 
/* Jump address table */
 
unsigned long jump_add[15*IC_WAYS];
 
 
void dummy();
void dummy();
 
 
void jump_and_link(void)
void jump_and_link(void)
{
{
        asm("_jalr:");
        asm("_jalr:");
Line 37... Line 43...
 
 
void jump(void)
void jump(void)
{
{
        asm("_jr:");
        asm("_jr:");
        /* Read and increment index */
        /* Read and increment index */
        asm("l.lwz\t\tr3,0(r0)");
        asm("l.lwz\t\tr3,0(r11)");
        asm("l.addi\t\tr3,r3,4");
        asm("l.addi\t\tr3,r3,4");
        asm("l.sw\t\t0(r0),r3");
        asm("l.sw\t\t0(r11),r3");
        /* Load next executin address from table */
        /* Load next executin address from table */
        asm("l.lwz\t\tr3,0(r3)");
        asm("l.lwz\t\tr3,0(r3)");
        /* Jump to that address */
        /* Jump to that address */
        asm("l.jr\t\tr3") ;
        asm("l.jr\t\tr3") ;
        /* Report that we succeeded */
        /* Report that we succeeded */
Line 55... Line 61...
        memcpy((void *)add, (void *)&jr, 24);
        memcpy((void *)add, (void *)&jr, 24);
}
}
 
 
void call(unsigned long add)
void call(unsigned long add)
{
{
 
  asm("l.movhi\tr11,hi(_jump_indx)" : :);
 
  asm("l.ori\tr11,r11,lo(_jump_indx)" : :);
        asm("l.jr\t\t%0" : : "r" (add) : "r11");
        asm("l.jr\t\t%0" : : "r" (add) : "r11");
        asm("l.nop" : :);
        asm("l.nop" : :);
}
}
 
 
void icache_enable(void)
void icache_enable(void)
Line 102... Line 110...
int dc_test(void)
int dc_test(void)
{
{
        int i;
        int i;
        unsigned long base, add, ul;
        unsigned long base, add, ul;
 
 
        base = (((unsigned long)&dummy / (IC_SETS*IC_BLOCK_SIZE)) * IC_SETS*IC_BLOCK_SIZE) + IC_SETS*IC_BLOCK_SIZE;
        base = (((unsigned long)MEM_RAM / (IC_SETS*IC_BLOCK_SIZE)) * IC_SETS*IC_BLOCK_SIZE) + IC_SETS*IC_BLOCK_SIZE;
 
 
        dcache_enable();
        dcache_enable();
 
 
        /* Cache miss r */
        /* Cache miss r */
        add = base;
        add = base;
Line 185... Line 193...
int ic_test(void)
int ic_test(void)
{
{
        int i;
        int i;
        unsigned long base, add;
        unsigned long base, add;
 
 
        base = (((unsigned long)&dummy / (IC_SETS*IC_BLOCK_SIZE)) * IC_SETS*IC_BLOCK_SIZE) + IC_SETS*IC_BLOCK_SIZE;
        base = (((unsigned long)MEM_RAM / (IC_SETS*IC_BLOCK_SIZE)) * IC_SETS*IC_BLOCK_SIZE) + IC_SETS*IC_BLOCK_SIZE;
 
 
        /* Copy jr to various location */
        /* Copy jr to various location */
        add = base;
        add = base;
        for(i = 0; i < IC_WAYS; i++) {
        for(i = 0; i < IC_WAYS; i++) {
                copy_jr(add);
                copy_jr(add);
Line 206... Line 214...
 
 
        /* Load execution table which starts at address 4 (at address 0 is table index) */
        /* Load execution table which starts at address 4 (at address 0 is table index) */
        add = base;
        add = base;
        for(i = 0; i < IC_WAYS; i++) {
        for(i = 0; i < IC_WAYS; i++) {
                /* Cache miss */
                /* Cache miss */
                REG32(0x3c*i + 0x04) = add + 2*IC_BLOCK_SIZE + 4;
                jump_add[15*i + 0] = add + 2*IC_BLOCK_SIZE + 4;
                REG32(0x3c*i + 0x08) = add + 4*IC_BLOCK_SIZE + 8;
                jump_add[15*i + 1] = add + 4*IC_BLOCK_SIZE + 8;
                REG32(0x3c*i + 0x0c) = add + 6*IC_BLOCK_SIZE + 12;
                jump_add[15*i + 2] = add + 6*IC_BLOCK_SIZE + 12;
                /* Cache hit/miss */
                /* Cache hit/miss */
                REG32(0x3c*i + 0x10) = add;
                jump_add[15*i + 3] = add;
                REG32(0x3c*i + 0x14) = add + (IC_SETS - 2)*IC_BLOCK_SIZE + 0;
                jump_add[15*i + 4] = add + (IC_SETS - 2)*IC_BLOCK_SIZE + 0;
                REG32(0x3c*i + 0x18) = add + 2*IC_BLOCK_SIZE + 4;
                jump_add[15*i + 5] = add + 2*IC_BLOCK_SIZE + 4;
                REG32(0x3c*i + 0x1c) = add + (IC_SETS - 4)*IC_BLOCK_SIZE + 4;
                jump_add[15*i + 6] = add + (IC_SETS - 4)*IC_BLOCK_SIZE + 4;
                REG32(0x3c*i + 0x20) = add + 4*IC_BLOCK_SIZE + 8;
                jump_add[15*i + 7] = add + 4*IC_BLOCK_SIZE + 8;
                REG32(0x3c*i + 0x24) = add + (IC_SETS - 6)*IC_BLOCK_SIZE + 8;
                jump_add[15*i + 8] = add + (IC_SETS - 6)*IC_BLOCK_SIZE + 8;
                REG32(0x3c*i + 0x28) = add + 6*IC_BLOCK_SIZE + 12;
                jump_add[15*i + 9] = add + 6*IC_BLOCK_SIZE + 12;
                REG32(0x3c*i + 0x2c) = add + (IC_SETS - 8)*IC_BLOCK_SIZE + 12;
                jump_add[15*i + 10] = add + (IC_SETS - 8)*IC_BLOCK_SIZE + 12;
                /* Cache hit */
                /* Cache hit */
                REG32(0x3c*i + 0x30) = add + (IC_SETS - 2)*IC_BLOCK_SIZE + 0;
                jump_add[15*i + 11] = add + (IC_SETS - 2)*IC_BLOCK_SIZE + 0;
                REG32(0x3c*i + 0x34) = add + (IC_SETS - 4)*IC_BLOCK_SIZE + 4;
                jump_add[15*i + 12] = add + (IC_SETS - 4)*IC_BLOCK_SIZE + 4;
                REG32(0x3c*i + 0x38) = add + (IC_SETS - 6)*IC_BLOCK_SIZE + 8;
                jump_add[15*i + 13] = add + (IC_SETS - 6)*IC_BLOCK_SIZE + 8;
                REG32(0x3c*i + 0x3c) = add + (IC_SETS - 8)*IC_BLOCK_SIZE + 12;
                jump_add[15*i + 14] = add + (IC_SETS - 8)*IC_BLOCK_SIZE + 12;
 
 
                add += IC_SETS*IC_BLOCK_SIZE;
                add += IC_SETS*IC_BLOCK_SIZE;
        }
        }
 
 
        /* Go home */
        /* Go home */
        REG32(0x3c*i + 4) = (unsigned long)&jalr;
        jump_add[15*i] = (unsigned long)&jalr;
 
 
        /* Initilalize table index */
        /* Initilalize table index */
        REG32(0) = 0;
        jump_indx = &jump_add[0];
 
 
        icache_enable();
        icache_enable();
 
 
        /* Go */
        /* Go */
        call(base);
        call(base);

powered by: WebSVN 2.1.0

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