URL
https://opencores.org/ocsvn/amber/amber/trunk
Subversion Repositories amber
[/] [amber/] [trunk/] [hw/] [tests/] [cache_swap_bug.S] - Rev 15
Compare with Previous | Blame | View Log
/*****************************************************************// //// Amber 2 Core Cache Test //// //// This file is part of the Amber project //// http://www.opencores.org/project,amber //// //// Description //// Tests the interaction between a swap instruction //// and the cache. //// //// Author(s): //// - Conor Santifort, csantifort.amber@gmail.com //// ////////////////////////////////////////////////////////////////////// //// Copyright (C) 2010 Authors and OPENCORES.ORG //// //// This source file may be used and distributed without //// restriction provided that this copyright statement is not //// removed from the file and that any derivative work contains //// the original copyright notice and the associated disclaimer. //// //// This source file is free software; you can redistribute it //// and/or modify it under the terms of the GNU Lesser General //// Public License as published by the Free Software Foundation; //// either version 2.1 of the License, or (at your option) any //// later version. //// //// This source is distributed in the hope that it will be //// useful, but WITHOUT ANY WARRANTY; without even the implied //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// PURPOSE. See the GNU Lesser General Public License for more //// details. //// //// You should have received a copy of the GNU Lesser General //// Public License along with this source; if not, download it //// from http://www.opencores.org/lgpl.shtml //// //*****************************************************************//*Bug is caused by very subtle timing interactions in the CacheIt does not detect a hit, which it should, on the read phase of the swapoperation. It doesnt detect the hit because it is still completinga fill started by the memory request to load an instructuionat swap instruction + 8.This only occurs when the swap target address is in the cachebut the cache instruction address is not, and the instructionaddress the third of a group of 4 instruction words.Test copies sequence to another bit of memory and runs it.Repeats this a few times moving the sequence to slightlydifferent memory locations each time*/#include "amber_registers.h".section .text.globl mainmain:@ ------------------------------------------@ Copy code@ ------------------------------------------@ Copy code sequence to another area in memorymov r13, #4big_loop:ldr r9, Loc1add r9, r9, r13mov r11, r9ldr r8, Adrseqldr r10, Adrseqendcopy:ldmia r8!, {r0-r7}stmia r11!, {r0-r7}cmp r8, r10blt copy@ ------------------------------------------@ Enable and clear cache@ ------------------------------------------@ Enable the cachemov r0, #0xffffffffmcr 15, 0, r0, cr3, cr0, 0 @ cacheable areamov r0, #1mcr 15, 0, r0, cr2, cr0, 0 @ cache enablenopnop@ flush the cachemcr 15, 0, r0, cr1, cr0, 0nopnop@ jump to special sequence@ want to return to the instruction immediately after mov pc, r9mov lr, pcmov pc, r9return:ldr r3, [r5]cmp r3, #0movne r10, #10bne testfailcmp r13, #40beq testpassadd r13, r13, #4mov r0, r13b big_loop@ ------------------------------------------@ ------------------------------------------@ puts swap address into cache@ move 0x7ff32c0 into r5seq: mov r5, #0x000000c0orr r5, r5, #0x00003200orr r5, r5, #0x00ff0000orr r5, r5, #0x07000000ldr r8, [r5]mov ip, #0mov r2, #1str r2, [r5]nopnopnopnop@ ------------------------------------------@ busybox code@ ------------------------------------------str r2, [r5, #4]nopnopnopnopstr ip, [r5, #4]nopnopnopnopnopnopstr ip, [r5, #8]swp r3, ip, [r5]nopnopnopnopldr r3, [r5, #8]nopnopnopnopmov pc, lrnopnopnopseqend: nop@ ------------------------------------------@ ------------------------------------------testfail:ldr r11, AdrTestStatusstr r10, [r11]b testfailtestpass:ldr r11, AdrTestStatusmov r10, #17str r10, [r11]b testpassLoc1: .word 0x200Adrseq: .word seqAdrseqend: .word seqend/* Write 17 to this address to generate a Test Passed message */AdrTestStatus: .word ADR_AMBER_TEST_STATUS/* ========================================================================= *//* ========================================================================= */
