sync-cache.c revision 1.1 1 1.1 mrg /* Machine description for AArch64 architecture.
2 1.1 mrg Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 1.1 mrg Contributed by ARM Ltd.
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
8 1.1 mrg the terms of the GNU General Public License as published by the Free
9 1.1 mrg Software Foundation; either version 3, or (at your option) any later
10 1.1 mrg version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 1.1 mrg for more details.
16 1.1 mrg
17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional
18 1.1 mrg permissions described in the GCC Runtime Library Exception, version
19 1.1 mrg 3.1, as published by the Free Software Foundation.
20 1.1 mrg
21 1.1 mrg You should have received a copy of the GNU General Public License and
22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program;
23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 1.1 mrg <http://www.gnu.org/licenses/>. */
25 1.1 mrg
26 1.1 mrg void __aarch64_sync_cache_range (const void *, const void *);
27 1.1 mrg
28 1.1 mrg void
29 1.1 mrg __aarch64_sync_cache_range (const void *base, const void *end)
30 1.1 mrg {
31 1.1 mrg unsigned icache_lsize;
32 1.1 mrg unsigned dcache_lsize;
33 1.1 mrg static unsigned int cache_info = 0;
34 1.1 mrg const char *address;
35 1.1 mrg
36 1.1 mrg if (! cache_info)
37 1.1 mrg /* CTR_EL0 [3:0] contains log2 of icache line size in words.
38 1.1 mrg CTR_EL0 [19:16] contains log2 of dcache line size in words. */
39 1.1 mrg asm volatile ("mrs\t%0, ctr_el0":"=r" (cache_info));
40 1.1 mrg
41 1.1 mrg icache_lsize = 4 << (cache_info & 0xF);
42 1.1 mrg dcache_lsize = 4 << ((cache_info >> 16) & 0xF);
43 1.1 mrg
44 1.1 mrg /* Loop over the address range, clearing one cache line at once.
45 1.1 mrg Data cache must be flushed to unification first to make sure the
46 1.1 mrg instruction cache fetches the updated data. 'end' is exclusive,
47 1.1 mrg as per the GNU definition of __clear_cache. */
48 1.1 mrg
49 1.1 mrg /* Make the start address of the loop cache aligned. */
50 1.1 mrg address = (const char*) ((__UINTPTR_TYPE__) base
51 1.1 mrg & ~ (__UINTPTR_TYPE__) (dcache_lsize - 1));
52 1.1 mrg
53 1.1 mrg for (; address < (const char *) end; address += dcache_lsize)
54 1.1 mrg asm volatile ("dc\tcvau, %0"
55 1.1 mrg :
56 1.1 mrg : "r" (address)
57 1.1 mrg : "memory");
58 1.1 mrg
59 1.1 mrg asm volatile ("dsb\tish" : : : "memory");
60 1.1 mrg
61 1.1 mrg /* Make the start address of the loop cache aligned. */
62 1.1 mrg address = (const char*) ((__UINTPTR_TYPE__) base
63 1.1 mrg & ~ (__UINTPTR_TYPE__) (icache_lsize - 1));
64 1.1 mrg
65 1.1 mrg for (; address < (const char *) end; address += icache_lsize)
66 1.1 mrg asm volatile ("ic\tivau, %0"
67 1.1 mrg :
68 1.1 mrg : "r" (address)
69 1.1 mrg : "memory");
70 1.1 mrg
71 1.1 mrg asm volatile ("dsb\tish; isb" : : : "memory");
72 1.1 mrg }
73