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>
40 * One of the fu* or su* functions failed, return -1.
43 SET_FAULT_HANDLER(xzr, x1) /* Reset the handler function */
49 * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
52 adr x6, fsu_fault /* Load the fault handler */
53 SET_FAULT_HANDLER(x6, x4) /* And set it */
54 1: ldxr w4, [x0] /* Load-exclusive the data */
55 cmp w4, w1 /* Compare */
56 b.ne 2f /* Not equal, exit */
57 stxr w5, w3, [x0] /* Store the new data */
58 cbnz w5, 1b /* Retry on failure */
59 ldrb w0, [x0] /* Try loading the data */
60 2: SET_FAULT_HANDLER(xzr, x5) /* Reset the fault handler */
61 str w4, [x2] /* Store the read data */
66 * int casueword(volatile u_long *, u_long, u_long *, u_long)
69 adr x6, fsu_fault /* Load the fault handler */
70 SET_FAULT_HANDLER(x6, x4) /* And set it */
71 1: ldxr x4, [x0] /* Load-exclusive the data */
72 cmp x4, x1 /* Compare */
73 b.ne 2f /* Not equal, exit */
74 stxr w5, x3, [x0] /* Store the new data */
75 cbnz w5, 1b /* Retry on failure */
76 ldrb w0, [x0] /* Try loading the data */
77 2: SET_FAULT_HANDLER(xzr, x5) /* Reset the fault handler */
78 str x4, [x2] /* Store the read data */
83 * int fubyte(volatile const void *)
86 adr x6, fsu_fault /* Load the fault handler */
87 SET_FAULT_HANDLER(x6, x1) /* And set it */
88 ldrb w0, [x0] /* Try loading the data */
89 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
94 * int fuword(volatile const void *)
97 adr x6, fsu_fault /* Load the fault handler */
98 SET_FAULT_HANDLER(x6, x1) /* And set it */
99 ldrh w0, [x0] /* Try loading the data */
100 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
105 * int32_t fueword32(volatile const void *, int32_t *)
108 adr x6, fsu_fault /* Load the fault handler */
109 SET_FAULT_HANDLER(x6, x2) /* And set it */
110 ldr w0, [x0] /* Try loading the data */
111 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
112 str w0, [x1] /* Save the data in kernel space */
113 mov w0, #0 /* Success */
118 * long fueword(volatile const void *, int64_t *)
119 * int64_t fueword64(volatile const void *, int64_t *)
123 adr x6, fsu_fault /* Load the fault handler */
124 SET_FAULT_HANDLER(x6, x2) /* And set it */
125 ldr x0, [x0] /* Try loading the data */
126 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
127 str x0, [x1] /* Save the data in kernel space */
128 mov x0, #0 /* Success */
134 * int subyte(volatile void *, int)
137 adr x6, fsu_fault /* Load the fault handler */
138 SET_FAULT_HANDLER(x6, x2) /* And set it */
139 strb w1, [x0] /* Try storing the data */
140 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
141 mov x0, #0 /* Success */
146 * int suword16(volatile void *, int)
149 adr x6, fsu_fault /* Load the fault handler */
150 SET_FAULT_HANDLER(x6, x2) /* And set it */
151 strh w1, [x0] /* Try storing the data */
152 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
153 mov x0, #0 /* Success */
158 * int suword32(volatile void *, int)
161 adr x6, fsu_fault /* Load the fault handler */
162 SET_FAULT_HANDLER(x6, x2) /* And set it */
163 str w1, [x0] /* Try storing the data */
164 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
165 mov x0, #0 /* Success */
170 * int suword(volatile void *, long)
174 adr x6, fsu_fault /* Load the fault handler */
175 SET_FAULT_HANDLER(x6, x2) /* And set it */
176 str x1, [x0] /* Try storing the data */
177 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
178 mov x0, #0 /* Success */
184 * fuswintr and suswintr are just like fusword and susword except that if
185 * the page is not in memory or would cause a trap, then we return an error.
186 * The important thing is to prevent sleep() and switch().
190 * Special handler so the trap code knows not to sleep.
192 ENTRY(fsu_intr_fault)
193 SET_FAULT_HANDLER(xzr, x1) /* Reset the handler function */
199 * int fuswintr(void *)
202 adr x6, fsu_intr_fault /* Load the fault handler */
203 SET_FAULT_HANDLER(x6, x1) /* And set it */
204 ldr w0, [x0] /* Try loading the data */
205 SET_FAULT_HANDLER(xzr, x1) /* Reset the fault handler */
210 * int suswintr(void *base, int word)
213 adr x6, fsu_intr_fault /* Load the fault handler */
214 SET_FAULT_HANDLER(x6, x2) /* And set it */
215 str w1, [x0] /* Try storing the data */
216 SET_FAULT_HANDLER(xzr, x2) /* Reset the fault handler */
217 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 */