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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [tests/] [cache_swap_bug.S] - Diff between revs 2 and 15

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 15
/*****************************************************************
/*****************************************************************
//                                                              //
//                                                              //
//  Amber 2 Core Cache Test                                     //
//  Amber 2 Core Cache Test                                     //
//                                                              //
//                                                              //
//  This file is part of the Amber project                      //
//  This file is part of the Amber project                      //
//  http://www.opencores.org/project,amber                      //
//  http://www.opencores.org/project,amber                      //
//                                                              //
//                                                              //
//  Description                                                 //
//  Description                                                 //
//  Tests the interaction between a swap instruction            //
//  Tests the interaction between a swap instruction            //
//  and the cache.                                              //
//  and the cache.                                              //
//                                                              //
//                                                              //
//  Author(s):                                                  //
//  Author(s):                                                  //
//      - Conor Santifort, csantifort.amber@gmail.com           //
//      - Conor Santifort, csantifort.amber@gmail.com           //
//                                                              //
//                                                              //
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
//                                                              //
//                                                              //
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
//                                                              //
//                                                              //
// This source file may be used and distributed without         //
// This source file may be used and distributed without         //
// restriction provided that this copyright statement is not    //
// restriction provided that this copyright statement is not    //
// removed from the file and that any derivative work contains  //
// removed from the file and that any derivative work contains  //
// the original copyright notice and the associated disclaimer. //
// the original copyright notice and the associated disclaimer. //
//                                                              //
//                                                              //
// This source file is free software; you can redistribute it   //
// This source file is free software; you can redistribute it   //
// and/or modify it under the terms of the GNU Lesser General   //
// and/or modify it under the terms of the GNU Lesser General   //
// Public License as published by the Free Software Foundation; //
// Public License as published by the Free Software Foundation; //
// either version 2.1 of the License, or (at your option) any   //
// either version 2.1 of the License, or (at your option) any   //
// later version.                                               //
// later version.                                               //
//                                                              //
//                                                              //
// This source is distributed in the hope that it will be       //
// This source is distributed in the hope that it will be       //
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
// PURPOSE.  See the GNU Lesser General Public License for more //
// PURPOSE.  See the GNU Lesser General Public License for more //
// details.                                                     //
// details.                                                     //
//                                                              //
//                                                              //
// You should have received a copy of the GNU Lesser General    //
// You should have received a copy of the GNU Lesser General    //
// Public License along with this source; if not, download it   //
// Public License along with this source; if not, download it   //
// from http://www.opencores.org/lgpl.shtml                     //
// from http://www.opencores.org/lgpl.shtml                     //
//                                                              //
//                                                              //
*****************************************************************/
*****************************************************************/
/*
/*
Bug is caused by very subtle timing interactions in the Cache
Bug is caused by very subtle timing interactions in the Cache
It does not detect a hit, which it should, on the read phase of the swap
It does not detect a hit, which it should, on the read phase of the swap
operation. It doesnt detect the hit because it is still completing
operation. It doesnt detect the hit because it is still completing
a fill started by the memory request to load an instructuion
a fill started by the memory request to load an instructuion
at swap instruction + 8.
at swap instruction + 8.
This only occurs when the swap target address is in the cache
This only occurs when the swap target address is in the cache
but the cache instruction address is not, and the instruction
but the cache instruction address is not, and the instruction
address the third of a group of 4 instruction words.
address the third of a group of 4 instruction words.
Test copies sequence to another bit of memory and runs it.
Test copies sequence to another bit of memory and runs it.
Repeats this a few times moving the sequence to slightly
Repeats this a few times moving the sequence to slightly
different memory locations each time
different memory locations each time
*/
*/
#include "amber_registers.h"
#include "amber_registers.h"
        .section .text
        .section .text
        .globl  main
        .globl  main
main:
main:
        @ ------------------------------------------
        @ ------------------------------------------
        @ Copy code
        @ Copy code
        @ ------------------------------------------
        @ ------------------------------------------
        @ Copy code sequence to another area in memory
        @ Copy code sequence to another area in memory
        mov     r13, #4
        mov     r13, #4
big_loop:
big_loop:
        ldr     r9,  Loc1
        ldr     r9,  Loc1
        add     r9,  r9, r13
        add     r9,  r9, r13
        mov     r11, r9
        mov     r11, r9
        ldr     r8,  Adrseq
        ldr     r8,  Adrseq
        ldr     r10, Adrseqend
        ldr     r10, Adrseqend
copy:
copy:
        ldmia   r8!,  {r0-r7}
        ldmia   r8!,  {r0-r7}
        stmia   r11!, {r0-r7}
        stmia   r11!, {r0-r7}
        cmp     r8, r10
        cmp     r8, r10
        blt     copy
        blt     copy
        @ ------------------------------------------
        @ ------------------------------------------
        @ Enable and clear cache
        @ Enable and clear cache
        @ ------------------------------------------
        @ ------------------------------------------
        @ ---------------------
 
        @ Enable the cache
        @ Enable the cache
        @ ---------------------
 
        mov     r0,  #0xffffffff
        mov     r0,  #0xffffffff
        mcr     p15, 0, r0, c3, c0, 0   @ cacheable area
        mcr     15, 0, r0, cr3, cr0, 0   @ cacheable area
        mov     r0,  #1
        mov     r0,  #1
        mcr     p15, 0, r0, c2, c0, 0   @ cache enable
        mcr     15, 0, r0, cr2, cr0, 0   @ cache enable
        nop
        nop
        nop
        nop
        @ flush the cache
        @ flush the cache
        mcr     p15, 0, r0, c1,  c0,  0
        mcr     15, 0, r0, cr1,  cr0,  0
        nop
        nop
        nop
        nop
        @ jump to special sequence
        @ jump to special sequence
        @ want to return to the instruction immediately after mov pc, r9
        @ want to return to the instruction immediately after mov pc, r9
        mov     lr, pc
        mov     lr, pc
        mov     pc, r9
        mov     pc, r9
return:
return:
        ldr     r3, [r5]
        ldr     r3, [r5]
        cmp     r3, #0
        cmp     r3, #0
        movne   r10, #10
        movne   r10, #10
        bne     testfail
        bne     testfail
        cmp     r13, #40
        cmp     r13, #40
        beq     testpass
        beq     testpass
        add     r13, r13, #4
        add     r13, r13, #4
        mov     r0, r13
        mov     r0, r13
        b       big_loop
        b       big_loop
        @ ------------------------------------------
        @ ------------------------------------------
        @ ------------------------------------------
        @ ------------------------------------------
        @ puts swap address into cache
        @ puts swap address into cache
        @ move 0x7ff32c0 into r5
        @ move 0x7ff32c0 into r5
seq:    mov     r5,     #0x000000c0
seq:    mov     r5,     #0x000000c0
        orr     r5, r5, #0x00003200
        orr     r5, r5, #0x00003200
        orr     r5, r5, #0x00ff0000
        orr     r5, r5, #0x00ff0000
        orr     r5, r5, #0x07000000
        orr     r5, r5, #0x07000000
        ldr     r8, [r5]
        ldr     r8, [r5]
        mov     ip, #0
        mov     ip, #0
        mov     r2, #1
        mov     r2, #1
        str     r2, [r5]
        str     r2, [r5]
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        @ ------------------------------------------
        @ ------------------------------------------
        @ busybox code
        @ busybox code
        @ ------------------------------------------
        @ ------------------------------------------
        str     r2, [r5, #4]
        str     r2, [r5, #4]
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        str     ip, [r5, #4]
        str     ip, [r5, #4]
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        str     ip, [r5, #8]
        str     ip, [r5, #8]
        swp     r3, ip, [r5]
        swp     r3, ip, [r5]
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        ldr     r3, [r5, #8]
        ldr     r3, [r5, #8]
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        nop
        mov     pc, lr
        mov     pc, lr
        nop
        nop
        nop
        nop
        nop
        nop
seqend: nop
seqend: nop
        @ ------------------------------------------
        @ ------------------------------------------
        @ ------------------------------------------
        @ ------------------------------------------
testfail:
testfail:
        ldr     r11, AdrTestStatus
        ldr     r11, AdrTestStatus
        str     r10, [r11]
        str     r10, [r11]
        b       testfail
        b       testfail
testpass:
testpass:
        ldr     r11, AdrTestStatus
        ldr     r11, AdrTestStatus
        mov     r10, #17
        mov     r10, #17
        str     r10, [r11]
        str     r10, [r11]
        b       testpass
        b       testpass
Loc1:           .word  0x200
Loc1:           .word  0x200
Adrseq:         .word  seq
Adrseq:         .word  seq
Adrseqend:      .word  seqend
Adrseqend:      .word  seqend
/* Write 17 to this address to generate a Test Passed message */
/* Write 17 to this address to generate a Test Passed message */
AdrTestStatus:  .word  ADR_AMBER_TEST_STATUS
AdrTestStatus:  .word  ADR_AMBER_TEST_STATUS
/* ========================================================================= */
/* ========================================================================= */
/* ========================================================================= */
/* ========================================================================= */
 
 

powered by: WebSVN 2.1.0

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