mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 /* Copyright (c) 2009 - 2012 ARM LIMITED
dkato 0:f782d9c66c49 2
dkato 0:f782d9c66c49 3 All rights reserved.
dkato 0:f782d9c66c49 4 Redistribution and use in source and binary forms, with or without
dkato 0:f782d9c66c49 5 modification, are permitted provided that the following conditions are met:
dkato 0:f782d9c66c49 6 - Redistributions of source code must retain the above copyright
dkato 0:f782d9c66c49 7 notice, this list of conditions and the following disclaimer.
dkato 0:f782d9c66c49 8 - Redistributions in binary form must reproduce the above copyright
dkato 0:f782d9c66c49 9 notice, this list of conditions and the following disclaimer in the
dkato 0:f782d9c66c49 10 documentation and/or other materials provided with the distribution.
dkato 0:f782d9c66c49 11 - Neither the name of ARM nor the names of its contributors may be used
dkato 0:f782d9c66c49 12 to endorse or promote products derived from this software without
dkato 0:f782d9c66c49 13 specific prior written permission.
dkato 0:f782d9c66c49 14 *
dkato 0:f782d9c66c49 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
dkato 0:f782d9c66c49 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dkato 0:f782d9c66c49 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dkato 0:f782d9c66c49 18 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
dkato 0:f782d9c66c49 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
dkato 0:f782d9c66c49 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
dkato 0:f782d9c66c49 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dkato 0:f782d9c66c49 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dkato 0:f782d9c66c49 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
dkato 0:f782d9c66c49 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
dkato 0:f782d9c66c49 25 POSSIBILITY OF SUCH DAMAGE.
dkato 0:f782d9c66c49 26 ---------------------------------------------------------------------------*/
dkato 0:f782d9c66c49 27
dkato 0:f782d9c66c49 28 /*----------------------------------------------------------------------------
dkato 0:f782d9c66c49 29 * Functions
dkato 0:f782d9c66c49 30 *---------------------------------------------------------------------------*/
dkato 0:f782d9c66c49 31 .text
dkato 0:f782d9c66c49 32 .global __v7_all_cache
dkato 0:f782d9c66c49 33 /*
dkato 0:f782d9c66c49 34 * __STATIC_ASM void __v7_all_cache(uint32_t op) {
dkato 0:f782d9c66c49 35 */
dkato 0:f782d9c66c49 36 __v7_all_cache:
dkato 0:f782d9c66c49 37 .arm
dkato 0:f782d9c66c49 38
dkato 0:f782d9c66c49 39 PUSH {R4-R11}
dkato 0:f782d9c66c49 40
dkato 0:f782d9c66c49 41 MRC p15, 1, R6, c0, c0, 1 /* Read CLIDR */
dkato 0:f782d9c66c49 42 ANDS R3, R6, #0x07000000 /* Extract coherency level */
dkato 0:f782d9c66c49 43 MOV R3, R3, LSR #23 /* Total cache levels << 1 */
dkato 0:f782d9c66c49 44 BEQ Finished /* If 0, no need to clean */
dkato 0:f782d9c66c49 45
dkato 0:f782d9c66c49 46 MOV R10, #0 /* R10 holds current cache level << 1 */
dkato 0:f782d9c66c49 47 Loop1: ADD R2, R10, R10, LSR #1 /* R2 holds cache "Set" position */
dkato 0:f782d9c66c49 48 MOV R1, R6, LSR R2 /* Bottom 3 bits are the Cache-type for this level */
dkato 0:f782d9c66c49 49 AND R1, R1, #7 /* Isolate those lower 3 bits */
dkato 0:f782d9c66c49 50 CMP R1, #2
dkato 0:f782d9c66c49 51 BLT Skip /* No cache or only instruction cache at this level */
dkato 0:f782d9c66c49 52
dkato 0:f782d9c66c49 53 MCR p15, 2, R10, c0, c0, 0 /* Write the Cache Size selection register */
dkato 0:f782d9c66c49 54 ISB /* ISB to sync the change to the CacheSizeID reg */
dkato 0:f782d9c66c49 55 MRC p15, 1, R1, c0, c0, 0 /* Reads current Cache Size ID register */
dkato 0:f782d9c66c49 56 AND R2, R1, #7 /* Extract the line length field */
dkato 0:f782d9c66c49 57 ADD R2, R2, #4 /* Add 4 for the line length offset (log2 16 bytes) */
dkato 0:f782d9c66c49 58 LDR R4, =0x3FF
dkato 0:f782d9c66c49 59 ANDS R4, R4, R1, LSR #3 /* R4 is the max number on the way size (right aligned) */
dkato 0:f782d9c66c49 60 CLZ R5, R4 /* R5 is the bit position of the way size increment */
dkato 0:f782d9c66c49 61 LDR R7, =0x7FFF
dkato 0:f782d9c66c49 62 ANDS R7, R7, R1, LSR #13 /* R7 is the max number of the index size (right aligned) */
dkato 0:f782d9c66c49 63
dkato 0:f782d9c66c49 64 Loop2: MOV R9, R4 /* R9 working copy of the max way size (right aligned) */
dkato 0:f782d9c66c49 65
dkato 0:f782d9c66c49 66 Loop3: ORR R11, R10, R9, LSL R5 /* Factor in the Way number and cache number into R11 */
dkato 0:f782d9c66c49 67 ORR R11, R11, R7, LSL R2 /* Factor in the Set number */
dkato 0:f782d9c66c49 68 CMP R0, #0
dkato 0:f782d9c66c49 69 BNE Dccsw
dkato 0:f782d9c66c49 70 MCR p15, 0, R11, c7, c6, 2 /* DCISW. Invalidate by Set/Way */
dkato 0:f782d9c66c49 71 B cont
dkato 0:f782d9c66c49 72 Dccsw: CMP R0, #1
dkato 0:f782d9c66c49 73 BNE Dccisw
dkato 0:f782d9c66c49 74 MCR p15, 0, R11, c7, c10, 2 /* DCCSW. Clean by Set/Way */
dkato 0:f782d9c66c49 75 B cont
dkato 0:f782d9c66c49 76 Dccisw: MCR p15, 0, R11, c7, c14, 2 /* DCCISW, Clean and Invalidate by Set/Way */
dkato 0:f782d9c66c49 77 cont: SUBS R9, R9, #1 /* Decrement the Way number */
dkato 0:f782d9c66c49 78 BGE Loop3
dkato 0:f782d9c66c49 79 SUBS R7, R7, #1 /* Decrement the Set number */
dkato 0:f782d9c66c49 80 BGE Loop2
dkato 0:f782d9c66c49 81 Skip: ADD R10, R10, #2 /* increment the cache number */
dkato 0:f782d9c66c49 82 CMP R3, R10
dkato 0:f782d9c66c49 83 BGT Loop1
dkato 0:f782d9c66c49 84
dkato 0:f782d9c66c49 85 Finished:
dkato 0:f782d9c66c49 86 DSB
dkato 0:f782d9c66c49 87 POP {R4-R11}
dkato 0:f782d9c66c49 88 BX lr
dkato 0:f782d9c66c49 89
dkato 0:f782d9c66c49 90
dkato 0:f782d9c66c49 91 .END
dkato 0:f782d9c66c49 92 /*----------------------------------------------------------------------------
dkato 0:f782d9c66c49 93 * end of file
dkato 0:f782d9c66c49 94 *---------------------------------------------------------------------------*/