]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/support.S
Merge from head
[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
37 #include "assym.s"
38
39 /*
40  * One of the fu* or su* functions failed, return -1.
41  */
42 ENTRY(fsu_fault)
43         SET_FAULT_HANDLER(xzr, x1)      /* Reset the handler function */
44         mov     x0, #-1
45         ret
46 END(fsu_fault)
47
48 /*
49  * int casueword32(volatile uint32_t *, uint32_t, uint32_t *, uint32_t)
50  */
51 ENTRY(casueword32)
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 */
62         ret                             /* Return */
63 END(casueword32)
64
65 /*
66  * int casueword(volatile u_long *, u_long, u_long *, u_long)
67  */
68 ENTRY(casueword)
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 */
79         ret                             /* Return */
80 END(casueword)
81
82 /*
83  * int fubyte(volatile const void *)
84  */
85 ENTRY(fubyte)
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 */
90         ret                             /* Return */
91 END(fubyte)
92
93 /*
94  * int fuword(volatile const void *)
95  */
96 ENTRY(fuword16)
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 */
101         ret                             /* Return */
102 END(fuword16)
103
104 /*
105  * int32_t fueword32(volatile const void *, int32_t *)
106  */
107 ENTRY(fueword32)
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 */
114         ret                             /* Return */
115 END(fueword32)
116
117 /*
118  * long fueword(volatile const void *, int64_t *)
119  * int64_t fueword64(volatile const void *, int64_t *)
120  */
121 ENTRY(fueword)
122 EENTRY(fueword64)
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 */
129         ret                             /* Return */
130 EEND(fueword64)
131 END(fueword)
132
133 /*
134  * int subyte(volatile void *, int)
135  */
136 ENTRY(subyte)
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 */
142         ret                             /* Return */
143 END(subyte)
144
145 /*
146  * int suword16(volatile void *, int)
147  */
148 ENTRY(suword16)
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 */
154         ret                             /* Return */
155 END(suword16)
156
157 /*
158  * int suword32(volatile void *, int)
159  */
160 ENTRY(suword32)
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 */
166         ret                             /* Return */
167 END(suword32)
168
169 /*
170  * int suword(volatile void *, long)
171  */
172 ENTRY(suword)
173 EENTRY(suword64)
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 */
179         ret                             /* Return */
180 EEND(suword64)
181 END(suword)
182
183 /*
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().
187  */
188
189 /*
190  * Special handler so the trap code knows not to sleep.
191  */
192 ENTRY(fsu_intr_fault)
193         SET_FAULT_HANDLER(xzr, x1)      /* Reset the handler function */
194         mov     x0, #-1
195         ret
196 END(fsu_fault)
197
198 /*
199  * int fuswintr(void *)
200  */
201 ENTRY(fuswintr)
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 */
206         ret                             /* Return */
207 END(fuswintr)
208
209 /*
210  * int suswintr(void *base, int word)
211  */
212 ENTRY(suswintr)
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 */
218         ret                             /* Return */
219 END(suswintr)
220
221 ENTRY(setjmp)
222         /* Store the stack pointer */
223         mov     x8, sp
224         str     x8, [x0]
225
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
233
234         /* Return value */
235         mov     x0, #0
236         ret
237 END(setjmp)
238
239 ENTRY(longjmp)
240         /* Restore the stack pointer */
241         ldr     x8, [x0], #8
242         mov     sp, x8
243
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
251
252         /* Load the return value */
253         mov     x0, x1
254         ret
255 END(longjmp)