cache.S revision 1.2.4.2 1 1.2.4.2 christos /* $NetBSD: cache.S,v 1.2.4.2 2019/06/10 22:09:56 christos Exp $ */
2 1.2.4.2 christos
3 1.2.4.2 christos /*-
4 1.2.4.2 christos * Copyright (c) 2014 Robin Randhawa
5 1.2.4.2 christos * Copyright (c) 2015 The FreeBSD Foundation
6 1.2.4.2 christos * All rights reserved.
7 1.2.4.2 christos *
8 1.2.4.2 christos * Portions of this software were developed by Andrew Turner
9 1.2.4.2 christos * under sponsorship from the FreeBSD Foundation
10 1.2.4.2 christos *
11 1.2.4.2 christos * Redistribution and use in source and binary forms, with or without
12 1.2.4.2 christos * modification, are permitted provided that the following conditions
13 1.2.4.2 christos * are met:
14 1.2.4.2 christos * 1. Redistributions of source code must retain the above copyright
15 1.2.4.2 christos * notice, this list of conditions and the following disclaimer.
16 1.2.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
17 1.2.4.2 christos * notice, this list of conditions and the following disclaimer in the
18 1.2.4.2 christos * documentation and/or other materials provided with the distribution.
19 1.2.4.2 christos *
20 1.2.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 1.2.4.2 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.2.4.2 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.2.4.2 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 1.2.4.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.2.4.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.2.4.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.2.4.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.2.4.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.2.4.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.2.4.2 christos * SUCH DAMAGE.
31 1.2.4.2 christos *
32 1.2.4.2 christos * $FreeBSD: head/sys/arm64/arm64/cpufunc_asm.S 313347 2017-02-06 17:50:09Z andrew $
33 1.2.4.2 christos */
34 1.2.4.2 christos
35 1.2.4.2 christos #include <aarch64/asm.h>
36 1.2.4.2 christos
37 1.2.4.2 christos #define SCTLR_M (1<<0)
38 1.2.4.2 christos #define SCTLR_C (1<<2)
39 1.2.4.2 christos
40 1.2.4.2 christos .text
41 1.2.4.2 christos .align 2
42 1.2.4.2 christos
43 1.2.4.2 christos /*
44 1.2.4.2 christos * Macro to handle the cache. This takes the start address in x0, length
45 1.2.4.2 christos * in x1. It will corrupt x0, x1, x2, and x3.
46 1.2.4.2 christos */
47 1.2.4.2 christos .macro cache_handle_range dcop = 0, ic = 0, icop = 0
48 1.2.4.2 christos .if \ic == 0
49 1.2.4.2 christos mrs x3, ctr_el0
50 1.2.4.2 christos ubfx x3, x3, #16, #4 /* x3 = D cache shift */
51 1.2.4.2 christos mov x2, #4 /* size of word */
52 1.2.4.2 christos lsl x3, x2, x3 /* x3 = D cache line size */
53 1.2.4.2 christos .else
54 1.2.4.2 christos mrs x3, ctr_el0
55 1.2.4.2 christos ubfx x2, x3, #16, #4 /* x2 = D cache shift */
56 1.2.4.2 christos and x3, x3, #15 /* x3 = I cache shift */
57 1.2.4.2 christos cmp x3, x2
58 1.2.4.2 christos bcs 1f
59 1.2.4.2 christos mov x3, x2
60 1.2.4.2 christos 1: /* x3 = MAX(IcacheShift,DcacheShift) */
61 1.2.4.2 christos mov x2, #4 /* size of word */
62 1.2.4.2 christos lsl x3, x2, x3 /* x3 = cache line size */
63 1.2.4.2 christos .endif
64 1.2.4.2 christos sub x4, x3, #1 /* Get the address mask */
65 1.2.4.2 christos and x2, x0, x4 /* Get the low bits of the address */
66 1.2.4.2 christos add x1, x1, x2 /* Add these to the size */
67 1.2.4.2 christos bic x0, x0, x4 /* Clear the low bit of the address */
68 1.2.4.2 christos 1:
69 1.2.4.2 christos dc \dcop, x0
70 1.2.4.2 christos dsb ish
71 1.2.4.2 christos .if \ic != 0
72 1.2.4.2 christos ic \icop, x0
73 1.2.4.2 christos dsb ish
74 1.2.4.2 christos .endif
75 1.2.4.2 christos add x0, x0, x3 /* Move to the next line */
76 1.2.4.2 christos subs x1, x1, x3 /* Reduce the size */
77 1.2.4.2 christos b.hi 1b /* Check if we are done */
78 1.2.4.2 christos .if \ic != 0
79 1.2.4.2 christos isb
80 1.2.4.2 christos .endif
81 1.2.4.2 christos ret
82 1.2.4.2 christos .endm
83 1.2.4.2 christos
84 1.2.4.2 christos
85 1.2.4.2 christos /*
86 1.2.4.2 christos * void aarch64_dcache_wbinv_range(vaddr_t, vsize_t)
87 1.2.4.2 christos */
88 1.2.4.2 christos ENTRY(aarch64_dcache_wbinv_range)
89 1.2.4.2 christos cache_handle_range dcop = civac
90 1.2.4.2 christos END(aarch64_dcache_wbinv_range)
91 1.2.4.2 christos
92 1.2.4.2 christos /*
93 1.2.4.2 christos * void aarch64_icache_inv_all(void)
94 1.2.4.2 christos */
95 1.2.4.2 christos ENTRY(aarch64_icache_inv_all)
96 1.2.4.2 christos dsb ish
97 1.2.4.2 christos ic ialluis
98 1.2.4.2 christos dsb ish
99 1.2.4.2 christos isb
100 1.2.4.2 christos ret
101 1.2.4.2 christos END(aarch64_icache_inv_all)
102 1.2.4.2 christos
103 1.2.4.2 christos /*
104 1.2.4.2 christos * void aarch64_exec_kernel(paddr_t entry, paddr_t dtb)
105 1.2.4.2 christos */
106 1.2.4.2 christos ENTRY(aarch64_exec_kernel)
107 1.2.4.2 christos mov x20, x0 /* kernel entry point */
108 1.2.4.2 christos mov x21, x1 /* dtb address */
109 1.2.4.2 christos
110 1.2.4.2 christos mrs x0, CurrentEL
111 1.2.4.2 christos lsr x0, x0, #2
112 1.2.4.2 christos cmp x0, #0x2
113 1.2.4.2 christos b.eq 1f
114 1.2.4.2 christos
115 1.2.4.2 christos /* Disable MMU and dcache, CurrentEL = EL1 */
116 1.2.4.2 christos mrs x0, sctlr_el1
117 1.2.4.2 christos bic x0, x0, #SCTLR_M
118 1.2.4.2 christos bic x0, x0, #SCTLR_C
119 1.2.4.2 christos msr sctlr_el1, x0
120 1.2.4.2 christos isb
121 1.2.4.2 christos b 2f
122 1.2.4.2 christos 1:
123 1.2.4.2 christos /* Disable MMU and dcache, CurrentEL = EL2 */
124 1.2.4.2 christos mrs x0, sctlr_el2
125 1.2.4.2 christos bic x0, x0, #SCTLR_M
126 1.2.4.2 christos bic x0, x0, #SCTLR_C
127 1.2.4.2 christos msr sctlr_el2, x0
128 1.2.4.2 christos isb
129 1.2.4.2 christos 2:
130 1.2.4.2 christos
131 1.2.4.2 christos /* Jump to kernel */
132 1.2.4.2 christos mov x0, x21
133 1.2.4.2 christos mov x1, xzr
134 1.2.4.2 christos mov x2, xzr
135 1.2.4.2 christos mov x3, xzr
136 1.2.4.2 christos br x20
137 1.2.4.2 christos
138 1.2.4.2 christos END(aarch64_exec_kernel)
139