www.pudn.com > leon3.rar > cache.c
#include "testmod.h" #include "leon3.h" #define CCTRL_IFP (1<<15) #define CCTRL_DFP (1<<14) #define DDIAGMSK ((1<> 16) & 7; DLINEBITS = ((dcconf >> 16) & 7); ITAG_BITS = ((icconf >> 20) & 15) + 8 - ILINEBITS; DTAG_BITS = ((dcconf >> 20) & 15) + 8 - DLINEBITS; isetsize = (1<<((icconf >> 20) & 15)) * 1024; dsetsize = (1<<((dcconf >> 20) & 15)) * 1024; isetbits = ((icconf >> 20) & 15) + 10; dsetbits = ((dcconf >> 20) & 15) + 10; ITAGS = (1 << ITAG_BITS); ILINESZ = (1 << ILINEBITS); DTAGS = (1 << DTAG_BITS); DLINESZ = (1 << DLINEBITS); IVALMSK = (1 << ILINESZ)-1; ITAGAMSK = 0x7fffffff - (1 << (ITAG_BITS + ILINEBITS +2)) + 1; DTAGAMSK = 0x7fffffff - (1 << (DTAG_BITS + DLINEBITS +2)) + 1; ISETS = ((icconf >> 24) & 3) + 1; DSETS = ((dcconf >> 24) & 3) + 1; ITAGLOW = 10 + ((icconf >> 20) & 15); DTAGLOW = 10 + ((dcconf >> 20) & 15); /**** INSTRUCTION CACHE TESTS ****/ for (i=0;i > CPP_CONF_BIT) & CPP_CONF_MASK) { cachectrl = rsysreg(0); wsysreg(0, cachectrl & ~0x3fc0); line2(); wsysreg(0, cachectrl | CPTB_MASK); for (i=0;i > IDE_BIT) & 3) != 1) fail(2); setitag((int) line2, 0, 0); cachectrl = rsysreg(0); wsysreg(0, cachectrl & ~CPTB_MASK); //setidata((int) line2, 0, 0); line2(); cachectrl = rsysreg(0); if (((cachectrl >> ITE_BIT) & 3) != 1) fail(3); } /**** DATA CACHE TESTS ****/ flush(); do cachectrl = rsysreg(0); while(cachectrl & (CCTRL_IFP | CCTRL_DFP)); for (i=0;i > CPP_CONF_BIT) & CPP_CONF_MASK) { cachectrl = rsysreg(0); wsysreg(0, cachectrl & ~CE_CLEAR); setddata(&mrx[0],0,0); cachectrl = rsysreg(0); wsysreg(0, cachectrl | CPTB_MASK); for (i=0;i > DDE_BIT) & 3) != 1) fail(12); cachectrl = rsysreg(0); wsysreg(0, cachectrl & ~CPTB_MASK); setddata(&mrx[0],0,0); cachectrl = rsysreg(0); wsysreg(0, cachectrl | CPTB_MASK); do cachectrl = rsysreg(0); while (!(cachectrl & CPTB_MASK)); for (i=0;i > DTE_BIT) & 3) != 1) fail(15); // if ((getdtag(mrx,1) & DTAGMASK) != (1 <<((((int) mrx)>>2)&(DLINESZ-1)))) fail(16); *((volatile long long int *) &dw) = 0x0000001100000055LL; cachectrl = rsysreg(0); wsysreg(0, (cachectrl | CPTB_MASK) & ~DDE_MASK); getdw(&dw); for (i=0;i > DDE_BIT) & 3) != 1) fail(16); wsysreg(0, cachectrl & (~CE_CLEAR & ~CPTB_MASK)); } /* check that tag is properly replaced */ mr[0] = 5; mr[1] = 1; mr[2] = 2; mr[3] = 3; mr[DTAGS*DLINESZ] = 0xbbbbbbbb; /* check that tag is not evicted on write miss */ if (chkdtag((int) mr) != 0) fail(17); /* check that write update memory ok */ if (mr[DTAGS*DLINESZ] != 0xbbbbbbbb) fail(18); /* check that valid bits have been reset */ /* if ((getdtag(mr) & DTAGMASK) != (1 <<((((int) mr)>>2)&(DLINESZ-1)))) */ /* fail(19); */ /* tmp = 0; */ /* if ((getdtag((int) mr & DIAGADDRMASK + i*dsetsize) & DTAGMASK) != (1 <<((((int) mr)>>2)&(DLINESZ-1)))) */ /* tmp = 1; */ /* if (tmp == 1) fail(19); */ /* check partial word access */ mr[8] = 0x01234567; mr[9] = 0x89abcdef; if (mrc[32] != 0x01) fail(26); if (mrc[33] != 0x23) fail(27); if (mrc[34] != 0x45) fail(28); if (mrc[35] != 0x67) fail(29); if (mrc[36] != 0x89) fail(30); if (mrc[37] != 0xab) fail(31); if (mrc[38] != 0xcd) fail(32); if (mrc[39] != 0xef) fail(33); if (mrh[16] != 0x0123) fail(34); if (mrh[17] != 0x4567) fail(35); if (mrh[18] != 0x89ab) fail(36); if (mrh[19] != 0xcdef) fail(37); mrc[32] = 0x30; if (mr[8] != 0x30234567) fail(39); mrc[33] = 0x31; if (mr[8] != 0x30314567) fail(40); mrc[34] = 0x32; if (mr[8] != 0x30313267) fail(41); mrc[35] = 0x33; if (mr[8] != 0x30313233) fail(42); mrc[36] = 0x34; if (mr[9] != 0x34abcdef) fail(43); mrc[37] = 0x35; if (mr[9] != 0x3435cdef) fail(44); mrc[38] = 0x36; if (mr[9] != 0x343536ef) fail(45); mrc[39] = 0x37; if (mr[9] != 0x34353637) fail(46); mrh[16] = 0x4041; if (mr[8] != 0x40413233) fail(47); mrh[17] = 0x4243; if (mr[8] != 0x40414243) fail(48); mrh[18] = 0x4445; if (mr[9] != 0x44453637) fail(49); mrh[19] = 0x4647; if (mr[9] != 0x44454647) fail(50); /* if (((lr->leonconf >> 2) & 3) == 3) { dma((int)&mr[0], 9, 1); } if (((lr->leonconf >> 2) & 3) == 3) { dma((int)&mr[0], 9, 1); } */ /* write data to the memory */ flush(); for (i=0;i cachectrl |= 0x03; flushd(); while(lr->cachectrl & CCTRL_DFP) {} if (chkdtags(DTAG_MAX_ADDRESS,(1<<(DLINEBITS + 2)),0,0) & ((1<