]> git.saurik.com Git - apple/libplatform.git/blame - src/cachecontrol/arm64/cache.s
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / src / cachecontrol / arm64 / cache.s
CommitLineData
ada7c492 1/*
e45b4692 2 * Copyright (c) 2011-2017 Apple Computer, Inc. All rights reserved.
ada7c492
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#include <mach/arm/syscall_sw.h>
89154bfb
A
25#include <mach/arm64/asm.h>
26#include <machine/cpu_capabilities.h>
ada7c492 27
442fbc9d 28
e45b4692
A
29#define MMU_I_CLINE 6 // cache line size as 1<<MMU_I_CLINE (64)
30
31/* void sys_icache_invalidate(void *start, size_t length) */
ada7c492 32.globl _sys_icache_invalidate
e45b4692 33.p2align 2
ada7c492 34_sys_icache_invalidate:
e45b4692
A
35 // see InvalidatePoU_IcacheRegion() in xnu/osfmk/arm64/caches_asm.s
36 cbz x1, 2f // length > 0 ?
89154bfb
A
37 and x9, x0, #~((1<<MMU_I_CLINE)-1) // cacheline align address
38 and x10, x0, #((1<<MMU_I_CLINE)-1) // extend length by alignment
39 add x10, x1, x10
40 sub x10, x10, #1
41 mov x11, #-1
42 eor x10, x11, x10, lsr #MMU_I_CLINE // compute cacheline counter
43 dsb ish
e45b4692 441:
89154bfb
A
45 ic ivau, x9 // invalidate icache line
46 add x9, x9, #1<<MMU_I_CLINE // next cacheline address
47 adds x10, x10, #1 // decrement cacheline counter
48 b.ne 1b
e45b4692
A
49 dsb ish
50 isb
512:
ada7c492
A
52 ret
53
e45b4692 54/* void sys_dcache_flush(void *start, size_t length) */
ada7c492 55.globl _sys_dcache_flush
e45b4692 56.p2align 2
ada7c492 57_sys_dcache_flush:
e45b4692
A
58 // see FlushPoC_DcacheRegion() in xnu/osfmk/arm64/caches_asm.s
59 dsb ish // noop, we are fully coherent
ada7c492
A
60 ret
61
e45b4692 62#if 0
89154bfb 63// Above based on output generated by clang from:
e45b4692
A
64static void __attribute((used))
65sys_icache_invalidate(uintptr_t start, size_t length)
66{
67 if (!length) return;
89154bfb 68 boolean_t hasICDSB = (*(uint32_t*)(uintptr_t)_COMM_PAGE_CPU_CAPABILITIES) & kHasICDSB;
e45b4692
A
69 uintptr_t addr = start & ~((1 << MMU_I_CLINE) - 1);
70 length += start & ((1 << MMU_I_CLINE) - 1);
71 size_t count = ((length - 1) >> MMU_I_CLINE) + 1;
89154bfb 72 asm volatile("dsb ish" ::: "memory");
e45b4692
A
73 while (count--) {
74 asm("ic ivau, %[addr]" :: [addr] "r" (addr) : "memory");
75 addr += (1 << MMU_I_CLINE);
76 }
89154bfb
A
77 if (hasICDSB) {
78 asm volatile("dsb ish" ::: "memory");
79 } else {
80 asm volatile("dsb ish" ::: "memory");
81 asm volatile("isb" ::: "memory");
82 }
e45b4692 83}
89154bfb
A
84
85cbz x1, 0x44
86mov x8, #0xfffff0000
87movk x8, #0xc020
88ldr w8, [x8]
89and x9, x0, #0xffffffffffffffc0
90and x10, x0, #0x3f
91add x10, x1, x10
92sub x10, x10, #0x1
93mov x11, #-0x1
94eor x10, x11, x10, lsr #6
95ic ivau, x9
96add x9, x9, #0x40
97adds x10, x10, #0x1
98b.ne 0x28
99dsb ish
100tbnz w8, #0x2, 0x44
101isb
102ret
103
e45b4692
A
104#endif
105