URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [pcu/] [pcu.S] - Rev 556
Compare with Previous | Blame | View Log
/* pcu.S -- Tests the performance counters unitContributor Julius Baxter <julius@opencores.org>This file is part of OpenRISC 1000 Architectural Simulator.This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 3 of the License, or (at your option)any later version.This program is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License formore details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http: www.gnu.org/licenses/>. *//* Currently only checks instruction fetch, TLB miss and cache miss counters. */#include "spr-defs.h".section .except,"ax".org 0x100l.j start_testl.nop.org 0x200l.jal unhandled_exceptl.nop.org 0x300l.jal unhandled_exceptl.nop.org 0x400l.jal unhandled_exceptl.nop.org 0x500l.jal unhandled_exceptl.nop.org 0x600l.jal unhandled_exceptl.nop.org 0x700l.jal unhandled_exceptl.nop.org 0x800l.jal unhandled_exceptl.nop/* DTLB miss - just disable DMMU and return *//* clobber r13 */.org 0x900l.mfspr r13,r0,SPR_ESR_BASEl.xori r13,r13,SPR_SR_DMEl.mtspr r0,r13,SPR_ESR_BASEl.rfe/* ITLB miss - just disable IMMU and return *//* clobber r13 */.org 0xa00l.mfspr r13,r0,SPR_ESR_BASEl.xori r13,r13,SPR_SR_IMEl.mtspr r0,r13,SPR_ESR_BASEl.rfe.org 0xb00l.jal unhandled_exceptl.nop/* System call - switches user/supervisor mode *//* Clobbers r13 */.org 0xc00l.mfspr r13,r0,SPR_ESR_BASEl.xori r13,r13,SPR_SR_SM /* Toggle SM bit */l.mtspr r0,r13,SPR_ESR_BASEl.rfe.org 0xd00l.jal unhandled_exceptl.nop.org 0xe00l.jal unhandled_exceptl.nop.org 0xf00l.jal unhandled_exceptl.nop.section .textstart_test:/* Check PCU is present */l.movhi r0,0l.mfspr r2,r0,SPR_UPRl.andi r2,r2,SPR_UPR_PCUPl.sfnei r2,SPR_UPR_PCUP/* Fail if not present */l.bf faill.nop/* Assumption that we are already in SM *//* Set SUMRA bit in SR */l.movhi r2,hi(SPR_SR_SUMRA)l.mfspr r3,r0,SPR_SRl.or r3,r3,r2l.mtspr r0,r3,SPR_SR/* Check instruction fetch counter - supervisor mode *//* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_IF | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_if_sm:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode */l.mtspr r1,r5,SPR_PCMR(0)/* This next instruction should be counted */l.nop/* Pull PCCR out and check it's != 0 */l.mfspr r3,r1,SPR_PCCR(0)//l.nop NOP_REPORTl.sfnei r3,0l.bnf fail/* Now change to usermode, ensure the counter doesn't increment */l.sys 0/* SM = 0 */l.mfspr r6,r1,SPR_PCCR(0)l.nopl.nopl.nopl.mfspr r7,r1,SPR_PCCR(0)/* r6 and r7 should be equal */l.sfne r6,r7l.bf faill.sys 0/* SM = 1 *//* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_if_sm /* check next set */l.addi r1,r1,1 /* increment set counter *//* Check instruction fetch counter - user mode *//* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CIUM | SPR_PCMR_IF | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_if_um:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode */l.mtspr r1,r5,SPR_PCMR(0)/* Switch to user mode */l.sys 0/* SM = 0 *//* This next instruction should be counted */l.nopl.mfspr r6,r1,SPR_PCCR(0)l.nopl.nopl.mfspr r7,r1,SPR_PCCR(0)/* r6 should be smaller than r7 */l.sfgeu r6,r7l.bf fail/* Now change to supervisor, ensure the counter doesn't increment */l.sys 0/* SM = 1 */l.mfspr r6,r1,SPR_PCCR(0)l.nopl.nopl.nopl.mfspr r7,r1,SPR_PCCR(0)/* r6 and r7 should be equal */l.sfeq r6,r7l.bnf fail/* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_if_um /* check next set */l.addi r1,r1,1 /* increment set counter *//* Check for MMU miss *//* immu *//* Clear MMU match registers, will cause a miss as soon as we turn onthe MMU */l.movhi r1,0 /* Set counter */l.movhi r2,0 /* Way counter */immu_clear_ways:l.slli r3,r2,8 /* way * 0x100 */immu_clear_sets:l.add r4,r1,r3 /* set + way *//* clear immu entry */l.mtspr r4,r0,SPR_ITLBMR_BASE(0)l.mtspr r4,r0,SPR_ITLBTR_BASE(0)/* End of immu sets? */l.sfnei r1,127l.bf immu_clear_setsl.addi r1,r1,1/* Reset set counter */l.movhi r1,0/* end of immu ways? */l.sfnei r2,3l.bf immu_clear_waysl.addi r2,r2,1/* Check itlb miss counter *//* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_ITLBM | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_itlbm:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode */l.mtspr r1,r5,SPR_PCMR(0)/* Switch on IMMU - cause tlb miss*/l.mfspr r4,r0,SPR_SRl.ori r4,r4,SPR_SR_IMEl.mtspr r0,r4,SPR_SR/* Miss should occur here *//* Check PCCR incremented */l.mfspr r6,r1,SPR_PCCR(0)l.sfeq r6,r0l.bf fail/* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_itlbm /* check next set */l.addi r1,r1,1 /* increment set counter *//* Check for MMU miss *//* dmmu *//* Clear MMU match registers, will cause a miss as soon as we turn onthe MMU */l.movhi r1,0 /* Set counter */l.movhi r2,0 /* Way counter */dmmu_clear_ways:l.slli r3,r2,8 /* way * 0x100 */dmmu_clear_sets:l.add r4,r1,r3 /* set + way *//* clear dmmu entry */l.mtspr r4,r0,SPR_DTLBMR_BASE(0)l.mtspr r4,r0,SPR_DTLBTR_BASE(0)/* End of dmmu sets? */l.sfnei r1,127l.bf dmmu_clear_setsl.addi r1,r1,1/* Reset set counter */l.movhi r1,0/* end of dmmu ways? */l.sfnei r2,3l.bf dmmu_clear_waysl.addi r2,r2,1/* Check dtlb miss counter *//* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_DTLBM | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_dtlbm:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode */l.mtspr r1,r5,SPR_PCMR(0)/* Switch on DMMU - cause tlb miss*/l.mfspr r4,r0,SPR_SRl.ori r4,r4,SPR_SR_DMEl.mtspr r0,r4,SPR_SRl.sw 0(r0),r6/* Miss should occur here *//* Check PCCR incremented */l.mfspr r6,r1,SPR_PCCR(0)l.sfeq r6,r0l.bf fail/* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_dtlbm /* check next set */l.addi r1,r1,1 /* increment set counter *//* Check instruction cache miss counter */icache_miss_test:/* Check if IC present and skip enabling otherwise */l.mfspr r3,r0,SPR_UPRl.andi r4,r3,SPR_UPR_ICPl.sfeq r4,r0l.bf dcache_miss_testl.nop/* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_ICM | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_icmiss:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode *//* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_ICM | SPR_PCMR_UMRA)l.mtspr r1,r5,SPR_PCMR(0)/* Disable IC */l.mfspr r6,r0,SPR_SRl.addi r5,r0,-1l.xori r5,r5,SPR_SR_ICEl.and r5,r6,r5l.mtspr r0,r5,SPR_SR/* Establish cache block sizeIf BS=0, 16;If BS=1, 32;r14 contain block size*/l.mfspr r3,r0,SPR_ICCFGRl.andi r4,r3,SPR_ICCFGR_CBSl.srli r5,r4,7l.ori r6,r0,16l.sll r14,r6,r5/* Establish number of cache setsr7 contains number of cache setsr5 contains log(# of cache sets)*/l.andi r4,r3,SPR_ICCFGR_NCSl.srli r5,r4,3l.ori r6,r0,1l.sll r7,r6,r5/* Invalidate IC */l.addi r6,r0,0l.sll r5,r14,r5.L7:l.mtspr r0,r6,SPR_ICBIRl.sfne r6,r5l.bf .L7l.add r6,r6,r14/* Enable IC */l.mfspr r6,r0,SPR_SRl.ori r6,r6,SPR_SR_ICEl.mtspr r0,r6,SPR_SRl.nopl.nopl.nopl.nop/* Should have had at least 1 miss, check this */l.mfspr r6,r1,SPR_PCCR(0)l.sfeq r6,r0l.bf faill.nop/* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_icmiss /* check next set */l.addi r1,r1,1 /* increment set counter */dcache_miss_test:/* Check if DC present and skip enabling otherwise */l.mfspr r3,r0,SPR_UPRl.andi r4,r3,SPR_UPR_DCPl.sfeq r4,r0l.bf dcache_miss_test_donel.nop/* r1 - counter of which counter (0-7) we're using */l.movhi r1,0/* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_DCM | SPR_PCMR_UMRA)/* report pcmr value */l.or r3,r5,r5l.nop NOP_REPORTpcr_dcmiss:/* report which counter we're using */l.or r3,r1,r1l.nop NOP_REPORT/* clear (0) pccr */l.mtspr r1,r0,SPR_PCCR(0)/* Load pcmr with appropriate mode *//* use r5 to hold pcmr value */l.ori r5,r0,(SPR_PCMR_CISM | SPR_PCMR_DCM | SPR_PCMR_UMRA)l.mtspr r1,r5,SPR_PCMR(0)/* Disable DC */l.mfspr r6,r0,SPR_SRl.addi r5,r0,-1l.xori r5,r5,SPR_SR_DCEl.and r5,r6,r5l.mtspr r0,r5,SPR_SR/* Establish cache block sizeIf BS=0, 16;If BS=1, 32;r14 contain block size*/l.mfspr r3,r0,SPR_DCCFGRl.andi r4,r3,SPR_DCCFGR_CBSl.srli r5,r4,7l.ori r6,r0,16l.sll r14,r6,r5/* Establish number of cache setsr7 contains number of cache setsr5 contains log(# of cache sets)*/l.andi r4,r3,SPR_DCCFGR_NCSl.srli r5,r4,3l.ori r6,r0,1l.sll r7,r6,r5/* Invalidate DC */l.addi r6,r0,0l.sll r5,r14,r5.L9:l.mtspr r0,r6,SPR_DCBIRl.sfne r6,r5l.bf .L9l.add r6,r6,r14/* Enable DC */l.mfspr r6,r0,SPR_SRl.ori r6,r6,SPR_SR_DCEl.mtspr r0,r6,SPR_SR/* Should trigger a dcache miss */l.sw 0(r0),r6/* Should trigger another dcache miss */l.lwz r6,0x1000(r0)/* Should have had 2 misses */l.mfspr r6,r1,SPR_PCCR(0)l.sfnei r6,2l.bf faill.nop/* End of loop */l.sfeqi r1,7 /* Finished checking all 8 regs? */l.bnf pcr_dcmiss /* check next set */l.addi r1,r1,1 /* increment set counter */dcache_miss_test_done:finish_ok:l.movhi r3,0xdeadl.ori r3,r3,0xdeadl.nop NOP_REPORTl.ori r3,r0,0l.nop NOP_EXITfail:l.ori r3,r0,0x1234l.nop NOP_EXITunhandled_except:l.addi r3,r9,-8l.nop NOP_REPORTl.nop NOP_EXIT
