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>
41 .macro check_user_access user_arg, limit, bad_addr_func
48 * One of the fu* or su* functions failed, return -1.
51 SET_FAULT_HANDLER(xzr, x1) /* Reset the handler function */
52 EXIT_USER_ACCESS_CHECK(w0, x1)
59 * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
62 check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb
63 adr x6, fsu_fault /* Load the fault handler */
65 SET_FAULT_HANDLER(x6, x4) /* And set it */
66 ENTER_USER_ACCESS(w6, x4)
67 ldxr w4, [x0] /* Load-exclusive the data */
68 cmp w4, w1 /* Compare */
69 b.ne 1f /* Not equal, exit */
70 stxr w5, w3, [x0] /* Store the new data */
71 1: EXIT_USER_ACCESS(w6)
72 SET_FAULT_HANDLER(xzr, x6) /* Reset the fault handler */
73 str w4, [x2] /* Store the read data */
74 mov w0, w5 /* Result same as store status */
79 * int casueword(volatile u_long *, u_long, u_long *, u_long)
82 check_user_access 0, (VM_MAXUSER_ADDRESS-7), fsu_fault_nopcb
83 adr x6, fsu_fault /* Load the fault handler */
85 SET_FAULT_HANDLER(x6, x4) /* And set it */
86 ENTER_USER_ACCESS(w6, x4)
87 ldxr x4, [x0] /* Load-exclusive the data */
88 cmp x4, x1 /* Compare */
89 b.ne 1f /* Not equal, exit */
90 stxr w5, x3, [x0] /* Store the new data */
91 1: EXIT_USER_ACCESS(w6)
92 SET_FAULT_HANDLER(xzr, x6) /* Reset the fault handler */
93 str x4, [x2] /* Store the read data */
94 mov w0, w5 /* Result same as store status */
98 .macro fsudata insn, ret_reg, user_arg
99 adr x7, fsu_fault /* Load the fault handler */
100 SET_FAULT_HANDLER(x7, x6) /* And set it */
101 \insn \ret_reg, [x\user_arg] /* Try accessing the data */
102 SET_FAULT_HANDLER(xzr, x6) /* Reset the fault handler */
106 * int fubyte(volatile const void *)
109 check_user_access 0, (VM_MAXUSER_ADDRESS), fsu_fault_nopcb
115 * int fuword(volatile const void *)
118 check_user_access 0, (VM_MAXUSER_ADDRESS-1), fsu_fault_nopcb
124 * int32_t fueword32(volatile const void *, int32_t *)
127 check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb
129 str w0, [x1] /* Save the data in kernel space */
130 mov w0, #0 /* Success */
135 * long fueword(volatile const void *, int64_t *)
136 * int64_t fueword64(volatile const void *, int64_t *)
140 check_user_access 0, (VM_MAXUSER_ADDRESS-7), fsu_fault_nopcb
142 str x0, [x1] /* Save the data in kernel space */
143 mov x0, #0 /* Success */
149 * int subyte(volatile void *, int)
152 check_user_access 0, (VM_MAXUSER_ADDRESS), fsu_fault_nopcb
154 mov x0, #0 /* Success */
159 * int suword16(volatile void *, int)
162 check_user_access 0, (VM_MAXUSER_ADDRESS-1), fsu_fault_nopcb
164 mov x0, #0 /* Success */
169 * int suword32(volatile void *, int)
172 check_user_access 0, (VM_MAXUSER_ADDRESS-3), fsu_fault_nopcb
174 mov x0, #0 /* Success */
179 * int suword(volatile void *, long)
183 check_user_access 0, (VM_MAXUSER_ADDRESS-7), fsu_fault_nopcb
185 mov x0, #0 /* Success */
191 /* Store the stack pointer */
195 /* Store the general purpose registers and lr */
196 stp x19, x20, [x0], #16
197 stp x21, x22, [x0], #16
198 stp x23, x24, [x0], #16
199 stp x25, x26, [x0], #16
200 stp x27, x28, [x0], #16
201 stp x29, lr, [x0], #16
209 /* Restore the stack pointer */
213 /* Restore the general purpose registers and lr */
214 ldp x19, x20, [x0], #16
215 ldp x21, x22, [x0], #16
216 ldp x23, x24, [x0], #16
217 ldp x25, x26, [x0], #16
218 ldp x27, x28, [x0], #16
219 ldp x29, lr, [x0], #16
221 /* Load the return value */
227 * pagezero, simple implementation
229 ENTRY(pagezero_simple)
230 add x1, x0, #PAGE_SIZE
233 stp xzr, xzr, [x0], #0x10
234 stp xzr, xzr, [x0], #0x10
235 stp xzr, xzr, [x0], #0x10
236 stp xzr, xzr, [x0], #0x10
244 * pagezero, cache assisted
246 ENTRY(pagezero_cache)
247 add x1, x0, #PAGE_SIZE
249 ldr x2, =dczva_line_size