]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm64/arm64/exception.S
Shorten conditional branch code.
[FreeBSD/FreeBSD.git] / sys / arm64 / arm64 / exception.S
1 /*-
2  * Copyright (c) 2014 Andrew Turner
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27
28 #include <machine/asm.h>
29 __FBSDID("$FreeBSD$");
30
31 #include "assym.s"
32
33         .text
34
35 .macro  save_registers el
36 .if \el == 1
37         mov     x18, sp
38         sub     sp, sp, #128
39 .endif
40         stp     x28, x29, [sp, #-16]!
41         stp     x26, x27, [sp, #-16]!
42         stp     x24, x25, [sp, #-16]!
43         stp     x22, x23, [sp, #-16]!
44         stp     x20, x21, [sp, #-16]!
45         stp     x18, x19, [sp, #-16]!
46         stp     x16, x17, [sp, #-16]!
47         stp     x14, x15, [sp, #-16]!
48         stp     x12, x13, [sp, #-16]!
49         stp     x10, x11, [sp, #-16]!
50         stp     x8, x9, [sp, #-16]!
51         stp     x6, x7, [sp, #-16]!
52         stp     x4, x5, [sp, #-16]!
53         stp     x2, x3, [sp, #-16]!
54         stp     x0, x1, [sp, #-16]!
55         mrs     x10, elr_el1
56         mrs     x11, spsr_el1
57 .if \el == 0
58         mrs     x18, sp_el0
59 .endif
60         stp     x10, x11, [sp, #-16]!
61         stp     x18, lr, [sp, #-16]!
62         mrs     x18, tpidr_el1
63 .endm
64
65 .macro  restore_registers el
66 .if \el == 1
67         msr     daifset, #2
68         /*
69          * Disable interrupts, x18 may change in the interrupt exception
70          * handler.  For EL0 exceptions, do_ast already did this.
71          */
72 .endif
73         ldp     x18, lr, [sp], #16
74         ldp     x10, x11, [sp], #16
75 .if \el == 0
76         msr     sp_el0, x18
77 .endif
78         msr     spsr_el1, x11
79         msr     elr_el1, x10
80         ldp     x0, x1, [sp], #16
81         ldp     x2, x3, [sp], #16
82         ldp     x4, x5, [sp], #16
83         ldp     x6, x7, [sp], #16
84         ldp     x8, x9, [sp], #16
85         ldp     x10, x11, [sp], #16
86         ldp     x12, x13, [sp], #16
87         ldp     x14, x15, [sp], #16
88         ldp     x16, x17, [sp], #16
89 .if \el == 0
90         ldp     x18, x19, [sp], #16
91 .else
92         ldp     xzr, x19, [sp], #16
93 .endif
94         ldp     x20, x21, [sp], #16
95         ldp     x22, x23, [sp], #16
96         ldp     x24, x25, [sp], #16
97         ldp     x26, x27, [sp], #16
98         ldp     x28, x29, [sp], #16
99 .if \el == 1
100         mov     sp, x18
101         mrs     x18, tpidr_el1
102 .endif
103 .endm
104
105 .macro  do_ast
106         /* Disable interrupts */
107         mrs     x19, daif
108 1:
109         msr     daifset, #2
110
111         /* Read the current thread flags */
112         ldr     x1, [x18, #PC_CURTHREAD]        /* Load curthread */
113         ldr     x2, [x1, #TD_FLAGS]
114
115         /* Check if we have either bits set */
116         mov     x3, #((TDF_ASTPENDING|TDF_NEEDRESCHED) >> 8)
117         lsl     x3, x3, #8
118         and     x2, x2, x3
119         cbz     x2, 2f
120
121         /* Restore interrupts */
122         msr     daif, x19
123
124         /* handle the ast */
125         mov     x0, sp
126         bl      _C_LABEL(ast)
127
128         /* Re-check for new ast scheduled */
129         b       1b
130 2:
131 .endm
132
133 ENTRY(handle_el1h_sync)
134         save_registers 1
135         mov     x0, sp
136         bl      do_el1h_sync
137         restore_registers 1
138         eret
139 END(handle_el1h_sync)
140
141 ENTRY(handle_el1h_irq)
142         save_registers 1
143         mov     x0, sp
144         bl      arm_cpu_intr
145         restore_registers 1
146         eret
147 END(handle_el1h_irq)
148
149 ENTRY(handle_el1h_error)
150         brk     0xf13
151 END(handle_el1h_error)
152
153 ENTRY(handle_el0_sync)
154         save_registers 0
155         mov     x0, sp
156         bl      do_el0_sync
157         do_ast
158         restore_registers 0
159         eret
160 END(handle_el0_sync)
161
162 ENTRY(handle_el0_irq)
163         save_registers 0
164         mov     x0, sp
165         bl      arm_cpu_intr
166         do_ast
167         restore_registers 0
168         eret
169 END(handle_el0_irq)
170
171 ENTRY(handle_el0_error)
172         save_registers 0
173         mov     x0, sp
174         bl      do_el0_error
175         brk     0xf23
176         1: b 1b
177 END(handle_el0_error)
178
179 .macro  vempty
180         .align 7
181         brk     0xfff
182         1: b    1b
183 .endm
184
185 .macro  vector  name
186         .align 7
187         b       handle_\name
188 .endm
189
190         .align 11
191         .globl exception_vectors
192 exception_vectors:
193         vempty                  /* Synchronous EL1t */
194         vempty                  /* IRQ EL1t */
195         vempty                  /* FIQ EL1t */
196         vempty                  /* Error EL1t */
197
198         vector el1h_sync        /* Synchronous EL1h */
199         vector el1h_irq         /* IRQ EL1h */
200         vempty                  /* FIQ EL1h */
201         vector el1h_error       /* Error EL1h */
202
203         vector el0_sync         /* Synchronous 64-bit EL0 */
204         vector el0_irq          /* IRQ 64-bit EL0 */
205         vempty                  /* FIQ 64-bit EL0 */
206         vector el0_error        /* Error 64-bit EL0 */
207
208         vempty                  /* Synchronous 32-bit EL0 */
209         vempty                  /* IRQ 32-bit EL0 */
210         vempty                  /* FIQ 32-bit EL0 */
211         vempty                  /* Error 32-bit EL0 */
212