]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/support.S
MFC r303760:
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / support.S
1 /*-
2  * Copyright (c) 2014 Andrew Turner
3  * Copyright (c) 2014-2015 The FreeBSD Foundation
4  * All rights reserved.
5  *
6  * Portions of this software were developed by Andrew Turner
7  * under sponsorship from the FreeBSD Foundation
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
17  *
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
28  * SUCH DAMAGE.
29  *
30  */
31
32 #include <machine/asm.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <machine/setjmp.h>
36 #include <machine/param.h>
37 #include <machine/vmparam.h>
38
39 #include "assym.s"
40
41 /*
42  * One of the fu* or su* functions failed, return -1.
43  */
44 ENTRY(fsu_fault)
45         SET_FAULT_HANDLER(xzr, x1)      /* Reset the handler function */
46 fsu_fault_nopcb:
47         mov     x0, #-1
48         ret
49 END(fsu_fault)
50
51 /*
52  * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
53  */
54 ENTRY(casueword32)
55         ldr     x4, =(VM_MAXUSER_ADDRESS-3)
56         cmp     x0, x4
57         b.cs    fsu_fault_nopcb
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 */
68         ret                             /* Return */
69 END(casueword32)
70
71 /*
72  * int casueword(volatile u_long *, u_long, u_long *, u_long)
73  */
74 ENTRY(casueword)
75         ldr     x4, =(VM_MAXUSER_ADDRESS-7)
76         cmp     x0, x4
77         b.cs    fsu_fault_nopcb
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 */
88         ret                             /* Return */
89 END(casueword)
90
91 /*
92  * int fubyte(volatile const void *)
93  */
94 ENTRY(fubyte)
95         ldr     x1, =VM_MAXUSER_ADDRESS
96         cmp     x0, x1
97         b.cs    fsu_fault_nopcb
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 */
102         ret                             /* Return */
103 END(fubyte)
104
105 /*
106  * int fuword(volatile const void *)
107  */
108 ENTRY(fuword16)
109         ldr     x1, =(VM_MAXUSER_ADDRESS-1)
110         cmp     x0, x1
111         b.cs    fsu_fault_nopcb
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 */
116         ret                             /* Return */
117 END(fuword16)
118
119 /*
120  * int32_t fueword32(volatile const void *, int32_t *)
121  */
122 ENTRY(fueword32)
123         ldr     x2, =(VM_MAXUSER_ADDRESS-3)
124         cmp     x0, x2
125         b.cs    fsu_fault_nopcb
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 */
132         ret                             /* Return */
133 END(fueword32)
134
135 /*
136  * long fueword(volatile const void *, int64_t *)
137  * int64_t fueword64(volatile const void *, int64_t *)
138  */
139 ENTRY(fueword)
140 EENTRY(fueword64)
141         ldr     x2, =(VM_MAXUSER_ADDRESS-7)
142         cmp     x0, x2
143         b.cs    fsu_fault_nopcb
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 */
150         ret                             /* Return */
151 EEND(fueword64)
152 END(fueword)
153
154 /*
155  * int subyte(volatile void *, int)
156  */
157 ENTRY(subyte)
158         ldr     x2, =VM_MAXUSER_ADDRESS
159         cmp     x0, x2
160         b.cs    fsu_fault_nopcb
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 */
166         ret                             /* Return */
167 END(subyte)
168
169 /*
170  * int suword16(volatile void *, int)
171  */
172 ENTRY(suword16)
173         ldr     x2, =(VM_MAXUSER_ADDRESS-1)
174         cmp     x0, x2
175         b.cs    fsu_fault_nopcb
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 */
181         ret                             /* Return */
182 END(suword16)
183
184 /*
185  * int suword32(volatile void *, int)
186  */
187 ENTRY(suword32)
188         ldr     x2, =(VM_MAXUSER_ADDRESS-3)
189         cmp     x0, x2
190         b.cs    fsu_fault_nopcb
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 */
196         ret                             /* Return */
197 END(suword32)
198
199 /*
200  * int suword(volatile void *, long)
201  */
202 ENTRY(suword)
203 EENTRY(suword64)
204         ldr     x2, =(VM_MAXUSER_ADDRESS-7)
205         cmp     x0, x2
206         b.cs    fsu_fault_nopcb
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 */
212         ret                             /* Return */
213 EEND(suword64)
214 END(suword)
215
216 /*
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().
220  */
221
222 /*
223  * Special handler so the trap code knows not to sleep.
224  */
225 ENTRY(fsu_intr_fault)
226         SET_FAULT_HANDLER(xzr, x1)      /* Reset the handler function */
227         mov     x0, #-1
228         ret
229 END(fsu_fault)
230
231 /*
232  * int fuswintr(void *)
233  */
234 ENTRY(fuswintr)
235         ldr     x1, =(VM_MAXUSER_ADDRESS-3)
236         cmp     x0, x1
237         b.cs    fsu_fault_nopcb
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 */
242         ret                             /* Return */
243 END(fuswintr)
244
245 /*
246  * int suswintr(void *base, int word)
247  */
248 ENTRY(suswintr)
249         ldr     x2, =(VM_MAXUSER_ADDRESS-3)
250         cmp     x0, x2
251         b.cs    fsu_fault_nopcb
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 */
257         ret                             /* Return */
258 END(suswintr)
259
260 ENTRY(setjmp)
261         /* Store the stack pointer */
262         mov     x8, sp
263         str     x8, [x0], #8
264
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
272
273         /* Return value */
274         mov     x0, #0
275         ret
276 END(setjmp)
277
278 ENTRY(longjmp)
279         /* Restore the stack pointer */
280         ldr     x8, [x0], #8
281         mov     sp, x8
282
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
290
291         /* Load the return value */
292         mov     x0, x1
293         ret
294 END(longjmp)
295
296 /*
297  * pagezero, simple implementation
298  */
299 ENTRY(pagezero_simple)
300         add     x1, x0, #PAGE_SIZE
301
302 1:
303         stp     xzr, xzr, [x0], #0x10
304         stp     xzr, xzr, [x0], #0x10
305         stp     xzr, xzr, [x0], #0x10
306         stp     xzr, xzr, [x0], #0x10
307         cmp     x0, x1
308         b.ne    1b
309         ret
310
311 END(pagezero_simple)
312
313 /*
314  * pagezero, cache assisted
315  */
316 ENTRY(pagezero_cache)
317         add     x1, x0, #PAGE_SIZE
318
319         ldr     x2, =dczva_line_size
320         ldr     x2, [x2]
321
322 1:
323         dc      zva, x0
324         add     x0, x0, x2
325         cmp     x0, x1
326         b.ne    1b
327         ret
328
329 END(pagezero_cache)