2 * Copyright (c) 2014 Andrew Turner
3 * Copyright (c) 2014-2015 The FreeBSD Foundation
6 * Portions of this software were developed by Andrew Turner
7 * under sponsorship from the FreeBSD Foundation
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <machine/asm.h>
33 __FBSDID("$FreeBSD$");
35 #include <machine/setjmp.h>
36 #include <machine/param.h>
37 #include <machine/vmparam.h>
42 * One of the fu* or su* functions failed, return -1.
45 SET_FAULT_HANDLER(xzr, x1) /* Reset the handler function */
46 EXIT_USER_ACCESS_CHECK(w0, x1)
53 * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
56 ldr x4, =(VM_MAXUSER_ADDRESS-3)
59 adr x6, fsu_fault /* Load the fault handler */
61 SET_FAULT_HANDLER(x6, x4) /* And set it */
62 ENTER_USER_ACCESS(w6, x4)
63 1: ldxr w4, [x0] /* Load-exclusive the data */
64 cmp w4, w1 /* Compare */
65 b.ne 2f /* Not equal, exit */
66 stxr w5, w3, [x0] /* Store the new data */
67 2: EXIT_USER_ACCESS(w6)
68 SET_FAULT_HANDLER(xzr, x6) /* Reset the fault handler */
69 str w4, [x2] /* Store the read data */
70 mov w0, w5 /* Result same as store status */
75 * int casueword(volatile u_long *, u_long, u_long *, u_long)
78 ldr x4, =(VM_MAXUSER_ADDRESS-7)
81 adr x6, fsu_fault /* Load the fault handler */
83 SET_FAULT_HANDLER(x6, x4) /* And set it */
84 ENTER_USER_ACCESS(w6, x4)
85 1: ldxr x4, [x0] /* Load-exclusive the data */
86 cmp x4, x1 /* Compare */
87 b.ne 2f /* Not equal, exit */
88 stxr w5, x3, [x0] /* Store the new data */
89 2: EXIT_USER_ACCESS(w6)
90 SET_FAULT_HANDLER(xzr, x6) /* Reset the fault handler */
91 str x4, [x2] /* Store the read data */
92 mov w0, w5 /* Result same as store status */
97 * int fubyte(volatile const void *)
100 ldr x1, =VM_MAXUSER_ADDRESS
103 adr x6, fsu_fault /* Load the fault handler */
104 SET_FAULT_HANDLER(x6, x1) /* And set it */
105 ldtrb w0, [x0] /* Try loading the data */
106 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
111 * int fuword(volatile const void *)
114 ldr x1, =(VM_MAXUSER_ADDRESS-1)
117 adr x6, fsu_fault /* Load the fault handler */
118 SET_FAULT_HANDLER(x6, x1) /* And set it */
119 ldtrh w0, [x0] /* Try loading the data */
120 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
125 * int32_t fueword32(volatile const void *, int32_t *)
128 ldr x2, =(VM_MAXUSER_ADDRESS-3)
131 adr x6, fsu_fault /* Load the fault handler */
132 SET_FAULT_HANDLER(x6, x2) /* And set it */
133 ldtr w0, [x0] /* Try loading the data */
134 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
135 str w0, [x1] /* Save the data in kernel space */
136 mov w0, #0 /* Success */
141 * long fueword(volatile const void *, int64_t *)
142 * int64_t fueword64(volatile const void *, int64_t *)
146 ldr x2, =(VM_MAXUSER_ADDRESS-7)
149 adr x6, fsu_fault /* Load the fault handler */
150 SET_FAULT_HANDLER(x6, x2) /* And set it */
151 ldtr x0, [x0] /* Try loading the data */
152 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
153 str x0, [x1] /* Save the data in kernel space */
154 mov x0, #0 /* Success */
160 * int subyte(volatile void *, int)
163 ldr x2, =VM_MAXUSER_ADDRESS
166 adr x6, fsu_fault /* Load the fault handler */
167 SET_FAULT_HANDLER(x6, x2) /* And set it */
168 sttrb w1, [x0] /* Try storing the data */
169 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
170 mov x0, #0 /* Success */
175 * int suword16(volatile void *, int)
178 ldr x2, =(VM_MAXUSER_ADDRESS-1)
181 adr x6, fsu_fault /* Load the fault handler */
182 SET_FAULT_HANDLER(x6, x2) /* And set it */
183 sttrh w1, [x0] /* Try storing the data */
184 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
185 mov x0, #0 /* Success */
190 * int suword32(volatile void *, int)
193 ldr x2, =(VM_MAXUSER_ADDRESS-3)
196 adr x6, fsu_fault /* Load the fault handler */
197 SET_FAULT_HANDLER(x6, x2) /* And set it */
198 sttr w1, [x0] /* Try storing the data */
199 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
200 mov x0, #0 /* Success */
205 * int suword(volatile void *, long)
209 ldr x2, =(VM_MAXUSER_ADDRESS-7)
212 adr x6, fsu_fault /* Load the fault handler */
213 SET_FAULT_HANDLER(x6, x2) /* And set it */
214 sttr x1, [x0] /* Try storing the data */
215 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
216 mov x0, #0 /* Success */
222 /* Store the stack pointer */
226 /* Store the general purpose registers and lr */
227 stp x19, x20, [x0], #16
228 stp x21, x22, [x0], #16
229 stp x23, x24, [x0], #16
230 stp x25, x26, [x0], #16
231 stp x27, x28, [x0], #16
232 stp x29, lr, [x0], #16
240 /* Restore the stack pointer */
244 /* Restore the general purpose registers and lr */
245 ldp x19, x20, [x0], #16
246 ldp x21, x22, [x0], #16
247 ldp x23, x24, [x0], #16
248 ldp x25, x26, [x0], #16
249 ldp x27, x28, [x0], #16
250 ldp x29, lr, [x0], #16
252 /* Load the return value */
258 * pagezero, simple implementation
260 ENTRY(pagezero_simple)
261 add x1, x0, #PAGE_SIZE
264 stp xzr, xzr, [x0], #0x10
265 stp xzr, xzr, [x0], #0x10
266 stp xzr, xzr, [x0], #0x10
267 stp xzr, xzr, [x0], #0x10
275 * pagezero, cache assisted
277 ENTRY(pagezero_cache)
278 add x1, x0, #PAGE_SIZE
280 ldr x2, =dczva_line_size