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 */
52 * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
55 ldr x4, =(VM_MAXUSER_ADDRESS-3)
58 adr x6, fsu_fault /* Load the fault handler */
59 SET_FAULT_HANDLER(x6, x4) /* And set it */
60 1: ldxr w4, [x0] /* Load-exclusive the data */
61 cmp w4, w1 /* Compare */
62 b.ne 2f /* Not equal, exit */
63 stxr w5, w3, [x0] /* Store the new data */
64 cbnz w5, 1b /* Retry on failure */
65 2: SET_FAULT_HANDLER(xzr, x5) /* Reset the fault handler */
66 str w4, [x2] /* Store the read data */
67 mov x0, #0 /* Success */
72 * int casueword(volatile u_long *, u_long, u_long *, u_long)
75 ldr x4, =(VM_MAXUSER_ADDRESS-7)
78 adr x6, fsu_fault /* Load the fault handler */
79 SET_FAULT_HANDLER(x6, x4) /* And set it */
80 1: ldxr x4, [x0] /* Load-exclusive the data */
81 cmp x4, x1 /* Compare */
82 b.ne 2f /* Not equal, exit */
83 stxr w5, x3, [x0] /* Store the new data */
84 cbnz w5, 1b /* Retry on failure */
85 2: SET_FAULT_HANDLER(xzr, x5) /* Reset the fault handler */
86 str x4, [x2] /* Store the read data */
87 mov x0, #0 /* Success */
92 * int fubyte(volatile const void *)
95 ldr x1, =VM_MAXUSER_ADDRESS
98 adr x6, fsu_fault /* Load the fault handler */
99 SET_FAULT_HANDLER(x6, x1) /* And set it */
100 ldrb w0, [x0] /* Try loading the data */
101 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
106 * int fuword(volatile const void *)
109 ldr x1, =(VM_MAXUSER_ADDRESS-1)
112 adr x6, fsu_fault /* Load the fault handler */
113 SET_FAULT_HANDLER(x6, x1) /* And set it */
114 ldrh w0, [x0] /* Try loading the data */
115 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
120 * int32_t fueword32(volatile const void *, int32_t *)
123 ldr x2, =(VM_MAXUSER_ADDRESS-3)
126 adr x6, fsu_fault /* Load the fault handler */
127 SET_FAULT_HANDLER(x6, x2) /* And set it */
128 ldr w0, [x0] /* Try loading the data */
129 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
130 str w0, [x1] /* Save the data in kernel space */
131 mov w0, #0 /* Success */
136 * long fueword(volatile const void *, int64_t *)
137 * int64_t fueword64(volatile const void *, int64_t *)
141 ldr x2, =(VM_MAXUSER_ADDRESS-7)
144 adr x6, fsu_fault /* Load the fault handler */
145 SET_FAULT_HANDLER(x6, x2) /* And set it */
146 ldr x0, [x0] /* Try loading the data */
147 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
148 str x0, [x1] /* Save the data in kernel space */
149 mov x0, #0 /* Success */
155 * int subyte(volatile void *, int)
158 ldr x2, =VM_MAXUSER_ADDRESS
161 adr x6, fsu_fault /* Load the fault handler */
162 SET_FAULT_HANDLER(x6, x2) /* And set it */
163 strb w1, [x0] /* Try storing the data */
164 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
165 mov x0, #0 /* Success */
170 * int suword16(volatile void *, int)
173 ldr x2, =(VM_MAXUSER_ADDRESS-1)
176 adr x6, fsu_fault /* Load the fault handler */
177 SET_FAULT_HANDLER(x6, x2) /* And set it */
178 strh w1, [x0] /* Try storing the data */
179 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
180 mov x0, #0 /* Success */
185 * int suword32(volatile void *, int)
188 ldr x2, =(VM_MAXUSER_ADDRESS-3)
191 adr x6, fsu_fault /* Load the fault handler */
192 SET_FAULT_HANDLER(x6, x2) /* And set it */
193 str w1, [x0] /* Try storing the data */
194 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
195 mov x0, #0 /* Success */
200 * int suword(volatile void *, long)
204 ldr x2, =(VM_MAXUSER_ADDRESS-7)
207 adr x6, fsu_fault /* Load the fault handler */
208 SET_FAULT_HANDLER(x6, x2) /* And set it */
209 str x1, [x0] /* Try storing the data */
210 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
211 mov x0, #0 /* Success */
217 * fuswintr and suswintr are just like fusword and susword except that if
218 * the page is not in memory or would cause a trap, then we return an error.
219 * The important thing is to prevent sleep() and switch().
223 * Special handler so the trap code knows not to sleep.
225 ENTRY(fsu_intr_fault)
226 SET_FAULT_HANDLER(xzr, x1) /* Reset the handler function */
232 * int fuswintr(void *)
235 ldr x1, =(VM_MAXUSER_ADDRESS-3)
238 adr x6, fsu_intr_fault /* Load the fault handler */
239 SET_FAULT_HANDLER(x6, x1) /* And set it */
240 ldr w0, [x0] /* Try loading the data */
241 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
246 * int suswintr(void *base, int word)
249 ldr x2, =(VM_MAXUSER_ADDRESS-3)
252 adr x6, fsu_intr_fault /* Load the fault handler */
253 SET_FAULT_HANDLER(x6, x2) /* And set it */
254 str w1, [x0] /* Try storing the data */
255 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
256 mov x0, #0 /* Success */
261 /* Store the stack pointer */
265 /* Store the general purpose registers and lr */
266 stp x19, x20, [x0], #16
267 stp x21, x22, [x0], #16
268 stp x23, x24, [x0], #16
269 stp x25, x26, [x0], #16
270 stp x27, x28, [x0], #16
271 stp x29, lr, [x0], #16
279 /* Restore the stack pointer */
283 /* Restore the general purpose registers and lr */
284 ldp x19, x20, [x0], #16
285 ldp x21, x22, [x0], #16
286 ldp x23, x24, [x0], #16
287 ldp x25, x26, [x0], #16
288 ldp x27, x28, [x0], #16
289 ldp x29, lr, [x0], #16
291 /* Load the return value */
297 * pagezero, simple implementation
299 ENTRY(pagezero_simple)
300 add x1, x0, #PAGE_SIZE
303 stp xzr, xzr, [x0], #0x10
304 stp xzr, xzr, [x0], #0x10
305 stp xzr, xzr, [x0], #0x10
306 stp xzr, xzr, [x0], #0x10
314 * pagezero, cache assisted
316 ENTRY(pagezero_cache)
317 add x1, x0, #PAGE_SIZE
319 ldr x2, =dczva_line_size