2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
13 * A routine for synchronizing the instruction and data caches.
14 * Useful for self-modifying code.
16 * r0 holds the buffer address
17 * r1 holds the size in bytes
20 #include <arch/chip.h>
23 #if defined(__NEWLIB__) || defined(__BME__)
30 /* Share code among Tile family chips but adjust opcodes appropriately. */
36 #if defined(__tilegx__) && __SIZEOF_POINTER__ == 4
37 /* Force 32-bit ops so pointers wrap around appropriately. */
39 #define ADDI_PTR addxi
45 .section .text.__invalidate_icache, "ax"
46 .global __invalidate_icache
47 .type __invalidate_icache,@function
48 .hidden __invalidate_icache
51 FEEDBACK_ENTER(__invalidate_icache)
53 ADD_PTR r1, r0, r1 /* end of buffer */
54 blez r1, .Lexit /* skip out if size <= 0 */
57 ADDI_PTR r1, r1, -1 /* point to last byte to flush */
58 andi r0, r0, -CHIP_L1I_LINE_SIZE() /* align to cache-line size */
61 andi r1, r1, -CHIP_L1I_LINE_SIZE() /* last cache line to flush */
64 #if CHIP_L1I_CACHE_SIZE() > PAGE_SIZE
66 moveli r4, CHIP_L1I_CACHE_SIZE() / PAGE_SIZE /* loop counter */
67 move r2, r0 /* remember starting address */
72 slt r3, r0, r1 /* set up loop invariant */
73 #if CHIP_L1I_CACHE_SIZE() > PAGE_SIZE
80 ADDI_PTR r0, r0, CHIP_L1I_LINE_SIZE() /* advance buffer */
83 slt r3, r0, r1 /* check if buffer < buffer + size */
84 bbst r3, .Lentry /* loop if buffer < buffer + size */
86 #if CHIP_L1I_CACHE_SIZE() > PAGE_SIZE
96 slt r3, r0, r1 /* set up loop invariant */
104 .Lend___invalidate_icache:
105 .size __invalidate_icache, \
106 .Lend___invalidate_icache - __invalidate_icache