blob: 3b22fa387ad36f33591f61e0bfba236d7615ef7f [file] [log] [blame]
Catalin Marinas60ffc302012-03-05 11:49:27 +00001/*
2 * Low-level exception handling code
3 *
4 * Copyright (C) 2012 ARM Ltd.
5 * Authors: Catalin Marinas <catalin.marinas@arm.com>
6 * Will Deacon <will.deacon@arm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/init.h>
22#include <linux/linkage.h>
23
Marc Zyngier8d883b22015-06-01 10:47:41 +010024#include <asm/alternative.h>
Catalin Marinas60ffc302012-03-05 11:49:27 +000025#include <asm/assembler.h>
26#include <asm/asm-offsets.h>
Will Deacon905e8c52015-03-23 19:07:02 +000027#include <asm/cpufeature.h>
Catalin Marinas60ffc302012-03-05 11:49:27 +000028#include <asm/errno.h>
Marc Zyngier5c1ce6f2013-04-08 17:17:03 +010029#include <asm/esr.h>
James Morse8e23dac2015-12-04 11:02:27 +000030#include <asm/irq.h>
James Morsee19a6ee2016-06-20 18:28:01 +010031#include <asm/memory.h>
Will Deacon39d3d6b2017-11-14 14:07:40 +000032#include <asm/mmu.h>
Catalin Marinascfa93772016-09-02 14:54:03 +010033#include <asm/ptrace.h>
Catalin Marinas60ffc302012-03-05 11:49:27 +000034#include <asm/thread_info.h>
Catalin Marinascfa93772016-09-02 14:54:03 +010035#include <asm/uaccess.h>
Kristina Martsenko9e09d902017-06-06 20:14:10 +010036#include <asm/asm-uaccess.h>
Catalin Marinas60ffc302012-03-05 11:49:27 +000037#include <asm/unistd.h>
38
39/*
Larry Bassel6c81fe72014-05-30 12:34:15 -070040 * Context tracking subsystem. Used to instrument transitions
41 * between user and kernel mode.
42 */
43 .macro ct_user_exit, syscall = 0
44#ifdef CONFIG_CONTEXT_TRACKING
45 bl context_tracking_user_exit
46 .if \syscall == 1
47 /*
48 * Save/restore needed during syscalls. Restore syscall arguments from
49 * the values already saved on stack during kernel_entry.
50 */
51 ldp x0, x1, [sp]
52 ldp x2, x3, [sp, #S_X2]
53 ldp x4, x5, [sp, #S_X4]
54 ldp x6, x7, [sp, #S_X6]
55 .endif
56#endif
57 .endm
58
59 .macro ct_user_enter
60#ifdef CONFIG_CONTEXT_TRACKING
61 bl context_tracking_user_enter
62#endif
63 .endm
64
65/*
Catalin Marinas60ffc302012-03-05 11:49:27 +000066 * Bad Abort numbers
67 *-----------------
68 */
69#define BAD_SYNC 0
70#define BAD_IRQ 1
71#define BAD_FIQ 2
72#define BAD_ERROR 3
73
Will Deacon8f261a62017-11-14 14:20:21 +000074 .macro kernel_ventry, el, label, regsize = 64
Mark Rutlandd96bee92017-07-19 17:24:49 +010075 .align 7
Will Deacon2d341da2017-11-14 14:24:29 +000076#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
Will Deacona7107232017-11-14 14:38:19 +000077alternative_if ARM64_UNMAP_KERNEL_AT_EL0
Will Deacon2d341da2017-11-14 14:24:29 +000078 .if \el == 0
79 .if \regsize == 64
80 mrs x30, tpidrro_el0
81 msr tpidrro_el0, xzr
82 .else
83 mov x30, xzr
84 .endif
85 .endif
Will Deacona7107232017-11-14 14:38:19 +000086alternative_else_nop_endif
Will Deacon2d341da2017-11-14 14:24:29 +000087#endif
88
Will Deacon63648dd2014-09-29 12:26:41 +010089 sub sp, sp, #S_FRAME_SIZE
Will Deacon8f261a62017-11-14 14:20:21 +000090 b el\()\el\()_\label
Mark Rutlandd96bee92017-07-19 17:24:49 +010091 .endm
92
Will Deacon2d341da2017-11-14 14:24:29 +000093 .macro tramp_alias, dst, sym
94 mov_q \dst, TRAMP_VALIAS
95 add \dst, \dst, #(\sym - .entry.tramp.text)
96 .endm
97
Mark Rutlandd96bee92017-07-19 17:24:49 +010098 .macro kernel_entry, el, regsize = 64
Catalin Marinas60ffc302012-03-05 11:49:27 +000099 .if \regsize == 32
100 mov w0, w0 // zero upper 32 bits of x0
101 .endif
Will Deacon63648dd2014-09-29 12:26:41 +0100102 stp x0, x1, [sp, #16 * 0]
103 stp x2, x3, [sp, #16 * 1]
104 stp x4, x5, [sp, #16 * 2]
105 stp x6, x7, [sp, #16 * 3]
106 stp x8, x9, [sp, #16 * 4]
107 stp x10, x11, [sp, #16 * 5]
108 stp x12, x13, [sp, #16 * 6]
109 stp x14, x15, [sp, #16 * 7]
110 stp x16, x17, [sp, #16 * 8]
111 stp x18, x19, [sp, #16 * 9]
112 stp x20, x21, [sp, #16 * 10]
113 stp x22, x23, [sp, #16 * 11]
114 stp x24, x25, [sp, #16 * 12]
115 stp x26, x27, [sp, #16 * 13]
116 stp x28, x29, [sp, #16 * 14]
117
Catalin Marinas60ffc302012-03-05 11:49:27 +0000118 .if \el == 0
119 mrs x21, sp_el0
Mark Rutlandb51386b2016-11-03 20:23:13 +0000120 ldr_this_cpu tsk, __entry_task, x20 // Ensure MDSCR_EL1.SS is clear,
121 ldr x19, [tsk, #TSK_TI_FLAGS] // since we can unmask debug
Will Deacon2a283072014-04-29 19:04:06 +0100122 disable_step_tsk x19, x20 // exceptions when scheduling.
James Morse49003a82015-12-10 10:22:41 +0000123
124 mov x29, xzr // fp pointed to user-space
Catalin Marinas60ffc302012-03-05 11:49:27 +0000125 .else
126 add x21, sp, #S_FRAME_SIZE
James Morsee19a6ee2016-06-20 18:28:01 +0100127 get_thread_info tsk
128 /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */
Mark Rutlandb51386b2016-11-03 20:23:13 +0000129 ldr x20, [tsk, #TSK_TI_ADDR_LIMIT]
James Morsee19a6ee2016-06-20 18:28:01 +0100130 str x20, [sp, #S_ORIG_ADDR_LIMIT]
131 mov x20, #TASK_SIZE_64
Mark Rutlandb51386b2016-11-03 20:23:13 +0000132 str x20, [tsk, #TSK_TI_ADDR_LIMIT]
Vladimir Murzin563cada2016-09-01 14:35:59 +0100133 /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */
James Morsee19a6ee2016-06-20 18:28:01 +0100134 .endif /* \el == 0 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000135 mrs x22, elr_el1
136 mrs x23, spsr_el1
137 stp lr, x21, [sp, #S_LR]
Catalin Marinascfa93772016-09-02 14:54:03 +0100138
139#ifdef CONFIG_ARM64_SW_TTBR0_PAN
140 /*
141 * Set the TTBR0 PAN bit in SPSR. When the exception is taken from
142 * EL0, there is no need to check the state of TTBR0_EL1 since
143 * accesses are always enabled.
144 * Note that the meaning of this bit differs from the ARMv8.1 PAN
145 * feature as all TTBR0_EL1 accesses are disabled, not just those to
146 * user mappings.
147 */
148alternative_if ARM64_HAS_PAN
149 b 1f // skip TTBR0 PAN
150alternative_else_nop_endif
151
152 .if \el != 0
Catalin Marinas874f7782018-01-10 13:18:30 +0000153 mrs x21, ttbr0_el1
Will Deacon4345a532017-12-01 17:33:48 +0000154 tst x21, #TTBR_ASID_MASK // Check for the reserved ASID
Catalin Marinascfa93772016-09-02 14:54:03 +0100155 orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR
156 b.eq 1f // TTBR0 access already disabled
157 and x23, x23, #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
158 .endif
159
160 __uaccess_ttbr0_disable x21
1611:
162#endif
163
Catalin Marinas60ffc302012-03-05 11:49:27 +0000164 stp x22, x23, [sp, #S_PC]
165
166 /*
167 * Set syscallno to -1 by default (overridden later if real syscall).
168 */
169 .if \el == 0
170 mvn x21, xzr
171 str x21, [sp, #S_SYSCALLNO]
172 .endif
173
174 /*
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000175 * Set sp_el0 to current thread_info.
176 */
177 .if \el == 0
178 msr sp_el0, tsk
179 .endif
180
181 /*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000182 * Registers that may be useful after this macro is invoked:
183 *
184 * x21 - aborted SP
185 * x22 - aborted PC
186 * x23 - aborted PSTATE
187 */
188 .endm
189
Will Deacon412fcb62015-08-19 15:57:09 +0100190 .macro kernel_exit, el
James Morsee19a6ee2016-06-20 18:28:01 +0100191 .if \el != 0
192 /* Restore the task's original addr_limit. */
193 ldr x20, [sp, #S_ORIG_ADDR_LIMIT]
Mark Rutlandb51386b2016-11-03 20:23:13 +0000194 str x20, [tsk, #TSK_TI_ADDR_LIMIT]
James Morsee19a6ee2016-06-20 18:28:01 +0100195
196 /* No need to restore UAO, it will be restored from SPSR_EL1 */
197 .endif
198
Catalin Marinas60ffc302012-03-05 11:49:27 +0000199 ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
200 .if \el == 0
Larry Bassel6c81fe72014-05-30 12:34:15 -0700201 ct_user_enter
Catalin Marinascfa93772016-09-02 14:54:03 +0100202 .endif
203
204#ifdef CONFIG_ARM64_SW_TTBR0_PAN
205 /*
206 * Restore access to TTBR0_EL1. If returning to EL0, no need for SPSR
207 * PAN bit checking.
208 */
209alternative_if ARM64_HAS_PAN
210 b 2f // skip TTBR0 PAN
211alternative_else_nop_endif
212
213 .if \el != 0
214 tbnz x22, #22, 1f // Skip re-enabling TTBR0 access if the PSR_PAN_BIT is set
215 .endif
216
Will Deaconf7aa82e2017-08-10 13:58:16 +0100217 __uaccess_ttbr0_enable x0, x1
Catalin Marinascfa93772016-09-02 14:54:03 +0100218
219 .if \el == 0
220 /*
221 * Enable errata workarounds only if returning to user. The only
222 * workaround currently required for TTBR0_EL1 changes are for the
223 * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache
224 * corruption).
225 */
Marc Zyngier18773dc2018-01-02 18:19:39 +0000226 bl post_ttbr_update_workaround
Catalin Marinascfa93772016-09-02 14:54:03 +0100227 .endif
2281:
229 .if \el != 0
230 and x22, x22, #~PSR_PAN_BIT // ARMv8.0 CPUs do not understand this bit
231 .endif
2322:
233#endif
234
235 .if \el == 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000236 ldr x23, [sp, #S_SP] // load return stack pointer
Catalin Marinas60ffc302012-03-05 11:49:27 +0000237 msr sp_el0, x23
Will Deacon2d341da2017-11-14 14:24:29 +0000238 tst x22, #PSR_MODE32_BIT // native task?
239 b.eq 3f
240
Will Deacon905e8c52015-03-23 19:07:02 +0000241#ifdef CONFIG_ARM64_ERRATUM_845719
Mark Rutland6ba3b552016-09-07 11:07:09 +0100242alternative_if ARM64_WORKAROUND_845719
Daniel Thompsone28cabf2015-07-22 12:21:03 +0100243#ifdef CONFIG_PID_IN_CONTEXTIDR
244 mrs x29, contextidr_el1
245 msr contextidr_el1, x29
246#else
247 msr contextidr_el1, xzr
248#endif
Mark Rutland6ba3b552016-09-07 11:07:09 +0100249alternative_else_nop_endif
Will Deacon905e8c52015-03-23 19:07:02 +0000250#endif
Will Deacon2d341da2017-11-14 14:24:29 +00002513:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000252 .endif
Catalin Marinascfa93772016-09-02 14:54:03 +0100253
Will Deacon63648dd2014-09-29 12:26:41 +0100254 msr elr_el1, x21 // set up the return data
255 msr spsr_el1, x22
Will Deacon63648dd2014-09-29 12:26:41 +0100256 ldp x0, x1, [sp, #16 * 0]
Will Deacon63648dd2014-09-29 12:26:41 +0100257 ldp x2, x3, [sp, #16 * 1]
258 ldp x4, x5, [sp, #16 * 2]
259 ldp x6, x7, [sp, #16 * 3]
260 ldp x8, x9, [sp, #16 * 4]
261 ldp x10, x11, [sp, #16 * 5]
262 ldp x12, x13, [sp, #16 * 6]
263 ldp x14, x15, [sp, #16 * 7]
264 ldp x16, x17, [sp, #16 * 8]
265 ldp x18, x19, [sp, #16 * 9]
266 ldp x20, x21, [sp, #16 * 10]
267 ldp x22, x23, [sp, #16 * 11]
268 ldp x24, x25, [sp, #16 * 12]
269 ldp x26, x27, [sp, #16 * 13]
270 ldp x28, x29, [sp, #16 * 14]
271 ldr lr, [sp, #S_LR]
272 add sp, sp, #S_FRAME_SIZE // restore sp
Will Deacon2d341da2017-11-14 14:24:29 +0000273
Will Deacon2d341da2017-11-14 14:24:29 +0000274 .if \el == 0
Will Deacona7107232017-11-14 14:38:19 +0000275alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
276#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
Will Deacon2d341da2017-11-14 14:24:29 +0000277 bne 4f
278 msr far_el1, x30
279 tramp_alias x30, tramp_exit_native
280 br x30
2814:
282 tramp_alias x30, tramp_exit_compat
283 br x30
Will Deacona7107232017-11-14 14:38:19 +0000284#endif
Will Deacon2d341da2017-11-14 14:24:29 +0000285 .else
286 eret
287 .endif
Catalin Marinas60ffc302012-03-05 11:49:27 +0000288 .endm
289
James Morse971c67c2015-12-15 11:21:25 +0000290 .macro irq_stack_entry
James Morse8e23dac2015-12-04 11:02:27 +0000291 mov x19, sp // preserve the original sp
292
James Morse8e23dac2015-12-04 11:02:27 +0000293 /*
Mark Rutlandb51386b2016-11-03 20:23:13 +0000294 * Compare sp with the base of the task stack.
295 * If the top ~(THREAD_SIZE - 1) bits match, we are on a task stack,
296 * and should switch to the irq stack.
James Morse8e23dac2015-12-04 11:02:27 +0000297 */
Mark Rutlandb51386b2016-11-03 20:23:13 +0000298 ldr x25, [tsk, TSK_STACK]
299 eor x25, x25, x19
300 and x25, x25, #~(THREAD_SIZE - 1)
301 cbnz x25, 9998f
James Morse8e23dac2015-12-04 11:02:27 +0000302
Mark Rutland2f604aa2016-11-03 20:23:12 +0000303 adr_this_cpu x25, irq_stack, x26
James Morse8e23dac2015-12-04 11:02:27 +0000304 mov x26, #IRQ_STACK_START_SP
305 add x26, x25, x26
James Morsed224a692015-12-18 16:01:47 +0000306
307 /* switch to the irq stack */
James Morse8e23dac2015-12-04 11:02:27 +0000308 mov sp, x26
309
James Morse971c67c2015-12-15 11:21:25 +0000310 /*
311 * Add a dummy stack frame, this non-standard format is fixed up
312 * by unwind_frame()
313 */
314 stp x29, x19, [sp, #-16]!
James Morse8e23dac2015-12-04 11:02:27 +0000315 mov x29, sp
James Morse8e23dac2015-12-04 11:02:27 +0000316
3179998:
318 .endm
319
320 /*
321 * x19 should be preserved between irq_stack_entry and
322 * irq_stack_exit.
323 */
324 .macro irq_stack_exit
325 mov sp, x19
326 .endm
327
Catalin Marinas60ffc302012-03-05 11:49:27 +0000328/*
329 * These are the registers used in the syscall handler, and allow us to
330 * have in theory up to 7 arguments to a function - x0 to x6.
331 *
332 * x7 is reserved for the system call number in 32-bit mode.
333 */
334sc_nr .req x25 // number of system calls
335scno .req x26 // syscall number
336stbl .req x27 // syscall table pointer
337tsk .req x28 // current thread_info
338
339/*
340 * Interrupt handling.
341 */
342 .macro irq_handler
James Morse8e23dac2015-12-04 11:02:27 +0000343 ldr_l x1, handle_arch_irq
Catalin Marinas60ffc302012-03-05 11:49:27 +0000344 mov x0, sp
James Morse971c67c2015-12-15 11:21:25 +0000345 irq_stack_entry
Catalin Marinas60ffc302012-03-05 11:49:27 +0000346 blr x1
James Morse8e23dac2015-12-04 11:02:27 +0000347 irq_stack_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000348 .endm
349
350 .text
351
352/*
353 * Exception vectors.
354 */
Pratyush Anand888b3c82016-07-08 12:35:50 -0400355 .pushsection ".entry.text", "ax"
Catalin Marinas60ffc302012-03-05 11:49:27 +0000356
357 .align 11
358ENTRY(vectors)
Will Deacon8f261a62017-11-14 14:20:21 +0000359 kernel_ventry 1, sync_invalid // Synchronous EL1t
360 kernel_ventry 1, irq_invalid // IRQ EL1t
361 kernel_ventry 1, fiq_invalid // FIQ EL1t
362 kernel_ventry 1, error_invalid // Error EL1t
Catalin Marinas60ffc302012-03-05 11:49:27 +0000363
Will Deacon8f261a62017-11-14 14:20:21 +0000364 kernel_ventry 1, sync // Synchronous EL1h
365 kernel_ventry 1, irq // IRQ EL1h
366 kernel_ventry 1, fiq_invalid // FIQ EL1h
367 kernel_ventry 1, error_invalid // Error EL1h
Catalin Marinas60ffc302012-03-05 11:49:27 +0000368
Will Deacon8f261a62017-11-14 14:20:21 +0000369 kernel_ventry 0, sync // Synchronous 64-bit EL0
370 kernel_ventry 0, irq // IRQ 64-bit EL0
371 kernel_ventry 0, fiq_invalid // FIQ 64-bit EL0
372 kernel_ventry 0, error_invalid // Error 64-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000373
374#ifdef CONFIG_COMPAT
Will Deacon8f261a62017-11-14 14:20:21 +0000375 kernel_ventry 0, sync_compat, 32 // Synchronous 32-bit EL0
376 kernel_ventry 0, irq_compat, 32 // IRQ 32-bit EL0
377 kernel_ventry 0, fiq_invalid_compat, 32 // FIQ 32-bit EL0
378 kernel_ventry 0, error_invalid_compat, 32 // Error 32-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000379#else
Will Deacon8f261a62017-11-14 14:20:21 +0000380 kernel_ventry 0, sync_invalid, 32 // Synchronous 32-bit EL0
381 kernel_ventry 0, irq_invalid, 32 // IRQ 32-bit EL0
382 kernel_ventry 0, fiq_invalid, 32 // FIQ 32-bit EL0
383 kernel_ventry 0, error_invalid, 32 // Error 32-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000384#endif
385END(vectors)
386
387/*
388 * Invalid mode handlers
389 */
390 .macro inv_entry, el, reason, regsize = 64
Ard Biesheuvelb6609502016-03-18 10:58:09 +0100391 kernel_entry \el, \regsize
Catalin Marinas60ffc302012-03-05 11:49:27 +0000392 mov x0, sp
393 mov x1, #\reason
394 mrs x2, esr_el1
395 b bad_mode
396 .endm
397
398el0_sync_invalid:
399 inv_entry 0, BAD_SYNC
400ENDPROC(el0_sync_invalid)
401
402el0_irq_invalid:
403 inv_entry 0, BAD_IRQ
404ENDPROC(el0_irq_invalid)
405
406el0_fiq_invalid:
407 inv_entry 0, BAD_FIQ
408ENDPROC(el0_fiq_invalid)
409
410el0_error_invalid:
411 inv_entry 0, BAD_ERROR
412ENDPROC(el0_error_invalid)
413
414#ifdef CONFIG_COMPAT
415el0_fiq_invalid_compat:
416 inv_entry 0, BAD_FIQ, 32
417ENDPROC(el0_fiq_invalid_compat)
418
419el0_error_invalid_compat:
420 inv_entry 0, BAD_ERROR, 32
421ENDPROC(el0_error_invalid_compat)
422#endif
423
424el1_sync_invalid:
425 inv_entry 1, BAD_SYNC
426ENDPROC(el1_sync_invalid)
427
428el1_irq_invalid:
429 inv_entry 1, BAD_IRQ
430ENDPROC(el1_irq_invalid)
431
432el1_fiq_invalid:
433 inv_entry 1, BAD_FIQ
434ENDPROC(el1_fiq_invalid)
435
436el1_error_invalid:
437 inv_entry 1, BAD_ERROR
438ENDPROC(el1_error_invalid)
439
440/*
441 * EL1 mode handlers.
442 */
443 .align 6
444el1_sync:
445 kernel_entry 1
446 mrs x1, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000447 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class
448 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000449 b.eq el1_da
Laura Abbott9adeb8e2016-08-09 18:25:26 -0700450 cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1
451 b.eq el1_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000452 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
Catalin Marinas60ffc302012-03-05 11:49:27 +0000453 b.eq el1_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000454 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000455 b.eq el1_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000456 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000457 b.eq el1_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000458 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000459 b.eq el1_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000460 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000461 b.ge el1_dbg
462 b el1_inv
Laura Abbott9adeb8e2016-08-09 18:25:26 -0700463
464el1_ia:
465 /*
466 * Fall through to the Data abort case
467 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000468el1_da:
469 /*
470 * Data abort handling
471 */
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100472 mrs x3, far_el1
Will Deacon2a283072014-04-29 19:04:06 +0100473 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000474 // re-enable interrupts if they were enabled in the aborted context
475 tbnz x23, #7, 1f // PSR_I_BIT
476 enable_irq
4771:
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100478 clear_address_tag x0, x3
Catalin Marinas60ffc302012-03-05 11:49:27 +0000479 mov x2, sp // struct pt_regs
480 bl do_mem_abort
481
482 // disable interrupts before pulling preserved data off the stack
483 disable_irq
484 kernel_exit 1
485el1_sp_pc:
486 /*
487 * Stack or PC alignment exception handling
488 */
489 mrs x0, far_el1
Will Deacon2a283072014-04-29 19:04:06 +0100490 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000491 mov x2, sp
492 b do_sp_pc_abort
493el1_undef:
494 /*
495 * Undefined instruction
496 */
Will Deacon2a283072014-04-29 19:04:06 +0100497 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000498 mov x0, sp
499 b do_undefinstr
500el1_dbg:
501 /*
502 * Debug exception handling
503 */
Mark Rutlandaed40e02014-11-24 12:31:40 +0000504 cmp x24, #ESR_ELx_EC_BRK64 // if BRK64
Sandeepa Prabhuee6214c2013-12-04 05:50:20 +0000505 cinc x24, x24, eq // set bit '0'
Catalin Marinas60ffc302012-03-05 11:49:27 +0000506 tbz x24, #0, el1_inv // EL1 only
507 mrs x0, far_el1
508 mov x2, sp // struct pt_regs
509 bl do_debug_exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000510 kernel_exit 1
511el1_inv:
512 // TODO: add support for undefined instructions in kernel mode
Will Deacon2a283072014-04-29 19:04:06 +0100513 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000514 mov x0, sp
Mark Rutland1b428042015-07-07 18:00:49 +0100515 mov x2, x1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000516 mov x1, #BAD_SYNC
Catalin Marinas60ffc302012-03-05 11:49:27 +0000517 b bad_mode
518ENDPROC(el1_sync)
519
520 .align 6
521el1_irq:
522 kernel_entry 1
Will Deacon2a283072014-04-29 19:04:06 +0100523 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000524#ifdef CONFIG_TRACE_IRQFLAGS
525 bl trace_hardirqs_off
526#endif
Marc Zyngier64681782013-11-12 17:11:53 +0000527
528 irq_handler
529
Catalin Marinas60ffc302012-03-05 11:49:27 +0000530#ifdef CONFIG_PREEMPT
Mark Rutlandb51386b2016-11-03 20:23:13 +0000531 ldr w24, [tsk, #TSK_TI_PREEMPT] // get preempt count
Marc Zyngier717321f2013-11-04 20:14:58 +0000532 cbnz w24, 1f // preempt count != 0
Mark Rutlandb51386b2016-11-03 20:23:13 +0000533 ldr x0, [tsk, #TSK_TI_FLAGS] // get flags
Catalin Marinas60ffc302012-03-05 11:49:27 +0000534 tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
535 bl el1_preempt
5361:
537#endif
538#ifdef CONFIG_TRACE_IRQFLAGS
539 bl trace_hardirqs_on
540#endif
541 kernel_exit 1
542ENDPROC(el1_irq)
543
544#ifdef CONFIG_PREEMPT
545el1_preempt:
546 mov x24, lr
Will Deacon2a283072014-04-29 19:04:06 +01005471: bl preempt_schedule_irq // irq en/disable is done inside
Mark Rutlandb51386b2016-11-03 20:23:13 +0000548 ldr x0, [tsk, #TSK_TI_FLAGS] // get new tasks TI_FLAGS
Catalin Marinas60ffc302012-03-05 11:49:27 +0000549 tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
550 ret x24
551#endif
552
553/*
554 * EL0 mode handlers.
555 */
556 .align 6
557el0_sync:
558 kernel_entry 0
559 mrs x25, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000560 lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class
561 cmp x24, #ESR_ELx_EC_SVC64 // SVC in 64-bit state
Catalin Marinas60ffc302012-03-05 11:49:27 +0000562 b.eq el0_svc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000563 cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000564 b.eq el0_da
Mark Rutlandaed40e02014-11-24 12:31:40 +0000565 cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000566 b.eq el0_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000567 cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access
Catalin Marinas60ffc302012-03-05 11:49:27 +0000568 b.eq el0_fpsimd_acc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000569 cmp x24, #ESR_ELx_EC_FP_EXC64 // FP/ASIMD exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000570 b.eq el0_fpsimd_exc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000571 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
Andre Przywara7dd01ae2016-06-28 18:07:32 +0100572 b.eq el0_sys
Mark Rutlandaed40e02014-11-24 12:31:40 +0000573 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000574 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000575 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000576 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000577 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000578 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000579 cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000580 b.ge el0_dbg
581 b el0_inv
582
583#ifdef CONFIG_COMPAT
584 .align 6
585el0_sync_compat:
586 kernel_entry 0, 32
587 mrs x25, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000588 lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class
589 cmp x24, #ESR_ELx_EC_SVC32 // SVC in 32-bit state
Catalin Marinas60ffc302012-03-05 11:49:27 +0000590 b.eq el0_svc_compat
Mark Rutlandaed40e02014-11-24 12:31:40 +0000591 cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000592 b.eq el0_da
Mark Rutlandaed40e02014-11-24 12:31:40 +0000593 cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000594 b.eq el0_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000595 cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access
Catalin Marinas60ffc302012-03-05 11:49:27 +0000596 b.eq el0_fpsimd_acc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000597 cmp x24, #ESR_ELx_EC_FP_EXC32 // FP/ASIMD exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000598 b.eq el0_fpsimd_exc
Mark Salyzyn77f3228f2015-10-13 14:30:51 -0700599 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
600 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000601 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000602 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000603 cmp x24, #ESR_ELx_EC_CP15_32 // CP15 MRC/MCR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100604 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000605 cmp x24, #ESR_ELx_EC_CP15_64 // CP15 MRRC/MCRR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100606 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000607 cmp x24, #ESR_ELx_EC_CP14_MR // CP14 MRC/MCR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100608 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000609 cmp x24, #ESR_ELx_EC_CP14_LS // CP14 LDC/STC trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100610 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000611 cmp x24, #ESR_ELx_EC_CP14_64 // CP14 MRRC/MCRR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100612 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000613 cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000614 b.ge el0_dbg
615 b el0_inv
616el0_svc_compat:
617 /*
618 * AArch32 syscall handling
619 */
Catalin Marinas01564112015-01-06 16:42:32 +0000620 adrp stbl, compat_sys_call_table // load compat syscall table pointer
Catalin Marinas60ffc302012-03-05 11:49:27 +0000621 uxtw scno, w7 // syscall number in w7 (r7)
622 mov sc_nr, #__NR_compat_syscalls
623 b el0_svc_naked
624
625 .align 6
626el0_irq_compat:
627 kernel_entry 0, 32
628 b el0_irq_naked
629#endif
630
631el0_da:
632 /*
633 * Data abort handling
634 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100635 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000636 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100637 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700638 ct_user_exit
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100639 clear_address_tag x0, x26
Catalin Marinas60ffc302012-03-05 11:49:27 +0000640 mov x1, x25
641 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100642 bl do_mem_abort
643 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000644el0_ia:
645 /*
646 * Instruction abort handling
647 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100648 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000649 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100650 enable_dbg_and_irq
Will Deacon0f5bfbd2018-01-03 11:17:58 +0000651#ifdef CONFIG_TRACE_IRQFLAGS
652 bl trace_hardirqs_off
653#endif
Larry Bassel6c81fe72014-05-30 12:34:15 -0700654 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100655 mov x0, x26
Mark Rutland541ec872016-05-31 12:33:03 +0100656 mov x1, x25
Catalin Marinas60ffc302012-03-05 11:49:27 +0000657 mov x2, sp
Will Deacon0f5bfbd2018-01-03 11:17:58 +0000658 bl do_el0_ia_bp_hardening
Will Deacond54e81f2014-09-29 11:44:01 +0100659 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000660el0_fpsimd_acc:
661 /*
662 * Floating Point or Advanced SIMD access
663 */
Will Deacon2a283072014-04-29 19:04:06 +0100664 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700665 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000666 mov x0, x25
667 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100668 bl do_fpsimd_acc
669 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000670el0_fpsimd_exc:
671 /*
672 * Floating Point or Advanced SIMD exception
673 */
Will Deacon2a283072014-04-29 19:04:06 +0100674 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700675 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000676 mov x0, x25
677 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100678 bl do_fpsimd_exc
679 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000680el0_sp_pc:
681 /*
682 * Stack or PC alignment exception handling
683 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100684 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000685 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100686 enable_dbg_and_irq
Mark Rutland46b05672015-06-15 16:40:27 +0100687 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100688 mov x0, x26
Catalin Marinas60ffc302012-03-05 11:49:27 +0000689 mov x1, x25
690 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100691 bl do_sp_pc_abort
692 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000693el0_undef:
694 /*
695 * Undefined instruction
696 */
Catalin Marinas2600e132013-08-22 11:47:37 +0100697 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100698 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700699 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100700 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100701 bl do_undefinstr
702 b ret_to_user
Andre Przywara7dd01ae2016-06-28 18:07:32 +0100703el0_sys:
704 /*
705 * System instructions, for trapped cache maintenance instructions
706 */
707 enable_dbg_and_irq
708 ct_user_exit
709 mov x0, x25
710 mov x1, sp
711 bl do_sysinstr
712 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000713el0_dbg:
714 /*
715 * Debug exception handling
716 */
717 tbnz x24, #0, el0_inv // EL0 only
718 mrs x0, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000719 mov x1, x25
720 mov x2, sp
Will Deacon2a283072014-04-29 19:04:06 +0100721 bl do_debug_exception
722 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700723 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100724 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000725el0_inv:
Will Deacon2a283072014-04-29 19:04:06 +0100726 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700727 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000728 mov x0, sp
729 mov x1, #BAD_SYNC
Mark Rutland1b428042015-07-07 18:00:49 +0100730 mov x2, x25
Mark Rutlandde327942017-01-18 17:23:41 +0000731 bl bad_el0_sync
Will Deacond54e81f2014-09-29 11:44:01 +0100732 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000733ENDPROC(el0_sync)
734
735 .align 6
736el0_irq:
737 kernel_entry 0
738el0_irq_naked:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000739 enable_dbg
740#ifdef CONFIG_TRACE_IRQFLAGS
741 bl trace_hardirqs_off
742#endif
Marc Zyngier64681782013-11-12 17:11:53 +0000743
Larry Bassel6c81fe72014-05-30 12:34:15 -0700744 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000745 irq_handler
Marc Zyngier64681782013-11-12 17:11:53 +0000746
Catalin Marinas60ffc302012-03-05 11:49:27 +0000747#ifdef CONFIG_TRACE_IRQFLAGS
748 bl trace_hardirqs_on
749#endif
750 b ret_to_user
751ENDPROC(el0_irq)
752
753/*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000754 * Register switch for AArch64. The callee-saved registers need to be saved
755 * and restored. On entry:
756 * x0 = previous task_struct (must be preserved across the switch)
757 * x1 = next task_struct
758 * Previous and next are guaranteed not to be the same.
759 *
760 */
761ENTRY(cpu_switch_to)
Will Deaconc0d3fce2015-07-20 15:14:53 +0100762 mov x10, #THREAD_CPU_CONTEXT
763 add x8, x0, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000764 mov x9, sp
765 stp x19, x20, [x8], #16 // store callee-saved registers
766 stp x21, x22, [x8], #16
767 stp x23, x24, [x8], #16
768 stp x25, x26, [x8], #16
769 stp x27, x28, [x8], #16
770 stp x29, x9, [x8], #16
771 str lr, [x8]
Will Deaconc0d3fce2015-07-20 15:14:53 +0100772 add x8, x1, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000773 ldp x19, x20, [x8], #16 // restore callee-saved registers
774 ldp x21, x22, [x8], #16
775 ldp x23, x24, [x8], #16
776 ldp x25, x26, [x8], #16
777 ldp x27, x28, [x8], #16
778 ldp x29, x9, [x8], #16
779 ldr lr, [x8]
780 mov sp, x9
Mark Rutlandb51386b2016-11-03 20:23:13 +0000781 msr sp_el0, x1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000782 ret
783ENDPROC(cpu_switch_to)
784
785/*
786 * This is the fast syscall return path. We do as little as possible here,
787 * and this includes saving x0 back into the kernel stack.
788 */
789ret_fast_syscall:
790 disable_irq // disable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100791 str x0, [sp, #S_X0] // returned x0
Mark Rutlandb51386b2016-11-03 20:23:13 +0000792 ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for syscall tracing
Josh Stone04d7e092015-06-05 14:28:03 -0700793 and x2, x1, #_TIF_SYSCALL_WORK
794 cbnz x2, ret_fast_syscall_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000795 and x2, x1, #_TIF_WORK_MASK
Will Deacon412fcb62015-08-19 15:57:09 +0100796 cbnz x2, work_pending
Will Deacon2a283072014-04-29 19:04:06 +0100797 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100798 kernel_exit 0
Josh Stone04d7e092015-06-05 14:28:03 -0700799ret_fast_syscall_trace:
800 enable_irq // enable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100801 b __sys_trace_return_skipped // we already saved x0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000802
803/*
804 * Ok, we need to do extra processing, enter the slow path.
805 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000806work_pending:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000807 mov x0, sp // 'regs'
Catalin Marinas60ffc302012-03-05 11:49:27 +0000808 bl do_notify_resume
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000809#ifdef CONFIG_TRACE_IRQFLAGS
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400810 bl trace_hardirqs_on // enabled while in userspace
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000811#endif
Mark Rutlandb51386b2016-11-03 20:23:13 +0000812 ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for single-step
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400813 b finish_ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000814/*
815 * "slow" syscall return path.
816 */
Catalin Marinas59dc67b2012-09-10 16:11:46 +0100817ret_to_user:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000818 disable_irq // disable interrupts
Mark Rutlandb51386b2016-11-03 20:23:13 +0000819 ldr x1, [tsk, #TSK_TI_FLAGS]
Catalin Marinas60ffc302012-03-05 11:49:27 +0000820 and x2, x1, #_TIF_WORK_MASK
821 cbnz x2, work_pending
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400822finish_ret_to_user:
Will Deacon2a283072014-04-29 19:04:06 +0100823 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100824 kernel_exit 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000825ENDPROC(ret_to_user)
826
827/*
828 * This is how we return from a fork.
829 */
830ENTRY(ret_from_fork)
831 bl schedule_tail
Catalin Marinasc34501d2012-10-05 12:31:20 +0100832 cbz x19, 1f // not a kernel thread
833 mov x0, x20
834 blr x19
8351: get_thread_info tsk
Catalin Marinas60ffc302012-03-05 11:49:27 +0000836 b ret_to_user
837ENDPROC(ret_from_fork)
838
839/*
840 * SVC handler.
841 */
842 .align 6
843el0_svc:
844 adrp stbl, sys_call_table // load syscall table pointer
845 uxtw scno, w8 // syscall number in w8
846 mov sc_nr, #__NR_syscalls
847el0_svc_naked: // compat entry point
848 stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number
Will Deacon2a283072014-04-29 19:04:06 +0100849 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700850 ct_user_exit 1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000851
Mark Rutlandb51386b2016-11-03 20:23:13 +0000852 ldr x16, [tsk, #TSK_TI_FLAGS] // check for syscall hooks
AKASHI Takahiro449f81a2014-04-30 10:51:29 +0100853 tst x16, #_TIF_SYSCALL_WORK
854 b.ne __sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000855 cmp scno, sc_nr // check upper syscall limit
856 b.hs ni_sys
857 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100858 blr x16 // call sys_* routine
859 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000860ni_sys:
861 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100862 bl do_ni_syscall
863 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000864ENDPROC(el0_svc)
865
866 /*
867 * This is the really slow path. We're going to be doing context
868 * switches, and waiting for our parent to respond.
869 */
870__sys_trace:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000871 mov w0, #-1 // set default errno for
872 cmp scno, x0 // user-issued syscall(-1)
873 b.ne 1f
874 mov x0, #-ENOSYS
875 str x0, [sp, #S_X0]
8761: mov x0, sp
AKASHI Takahiro31578582014-04-30 10:51:30 +0100877 bl syscall_trace_enter
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000878 cmp w0, #-1 // skip the syscall?
879 b.eq __sys_trace_return_skipped
Catalin Marinas60ffc302012-03-05 11:49:27 +0000880 uxtw scno, w0 // syscall number (possibly new)
881 mov x1, sp // pointer to regs
882 cmp scno, sc_nr // check upper syscall limit
Will Deacond54e81f2014-09-29 11:44:01 +0100883 b.hs __ni_sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000884 ldp x0, x1, [sp] // restore the syscall args
885 ldp x2, x3, [sp, #S_X2]
886 ldp x4, x5, [sp, #S_X4]
887 ldp x6, x7, [sp, #S_X6]
888 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100889 blr x16 // call sys_* routine
Catalin Marinas60ffc302012-03-05 11:49:27 +0000890
891__sys_trace_return:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000892 str x0, [sp, #S_X0] // save returned x0
893__sys_trace_return_skipped:
AKASHI Takahiro31578582014-04-30 10:51:30 +0100894 mov x0, sp
895 bl syscall_trace_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000896 b ret_to_user
897
Will Deacond54e81f2014-09-29 11:44:01 +0100898__ni_sys_trace:
899 mov x0, sp
900 bl do_ni_syscall
901 b __sys_trace_return
902
Pratyush Anand888b3c82016-07-08 12:35:50 -0400903 .popsection // .entry.text
904
Will Deacon39d3d6b2017-11-14 14:07:40 +0000905#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
906/*
907 * Exception vectors trampoline.
908 */
909 .pushsection ".entry.tramp.text", "ax"
910
911 .macro tramp_map_kernel, tmp
912 mrs \tmp, ttbr1_el1
913 sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
914 bic \tmp, \tmp, #USER_ASID_FLAG
915 msr ttbr1_el1, \tmp
Will Deacon1f911ed2017-11-14 14:29:19 +0000916#ifdef CONFIG_ARCH_MSM8996
917 /* ASID already in \tmp[63:48] */
918 movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12)
919 movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12)
920 /* 2MB boundary containing the vectors, so we nobble the walk cache */
921 movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12)
922 isb
923 tlbi vae1, \tmp
924 dsb nsh
925#endif /* CONFIG_ARCH_MSM8996 */
Will Deacon39d3d6b2017-11-14 14:07:40 +0000926 .endm
927
928 .macro tramp_unmap_kernel, tmp
929 mrs \tmp, ttbr1_el1
930 add \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
931 orr \tmp, \tmp, #USER_ASID_FLAG
932 msr ttbr1_el1, \tmp
933 /*
934 * We avoid running the post_ttbr_update_workaround here because the
935 * user and kernel ASIDs don't have conflicting mappings, so any
936 * "blessing" as described in:
937 *
938 * http://lkml.kernel.org/r/56BB848A.6060603@caviumnetworks.com
939 *
940 * will not hurt correctness. Whilst this may partially defeat the
941 * point of using split ASIDs in the first place, it avoids
942 * the hit of invalidating the entire I-cache on every return to
943 * userspace.
944 */
945 .endm
946
947 .macro tramp_ventry, regsize = 64
948 .align 7
9491:
950 .if \regsize == 64
951 msr tpidrro_el0, x30 // Restored in kernel_ventry
952 .endif
Will Deacon509a7a82017-11-14 16:15:59 +0000953 bl 2f
954 b .
9552:
Will Deacon39d3d6b2017-11-14 14:07:40 +0000956 tramp_map_kernel x30
Will Deacon912612c2017-12-06 11:24:02 +0000957#ifdef CONFIG_RANDOMIZE_BASE
958 adr x30, tramp_vectors + PAGE_SIZE
Todd Poynor735703d2018-01-08 12:22:41 -0800959#ifndef CONFIG_ARCH_MSM8996
960 isb
961#endif
Will Deacon912612c2017-12-06 11:24:02 +0000962 ldr x30, [x30]
963#else
Will Deacon39d3d6b2017-11-14 14:07:40 +0000964 ldr x30, =vectors
Will Deacon912612c2017-12-06 11:24:02 +0000965#endif
Will Deacon39d3d6b2017-11-14 14:07:40 +0000966 prfm plil1strm, [x30, #(1b - tramp_vectors)]
967 msr vbar_el1, x30
968 add x30, x30, #(1b - tramp_vectors)
969 isb
Will Deacon509a7a82017-11-14 16:15:59 +0000970 ret
Will Deacon39d3d6b2017-11-14 14:07:40 +0000971 .endm
972
973 .macro tramp_exit, regsize = 64
974 adr x30, tramp_vectors
975 msr vbar_el1, x30
976 tramp_unmap_kernel x30
977 .if \regsize == 64
978 mrs x30, far_el1
979 .endif
980 eret
981 .endm
982
983 .align 11
984ENTRY(tramp_vectors)
985 .space 0x400
986
987 tramp_ventry
988 tramp_ventry
989 tramp_ventry
990 tramp_ventry
991
992 tramp_ventry 32
993 tramp_ventry 32
994 tramp_ventry 32
995 tramp_ventry 32
996END(tramp_vectors)
997
998ENTRY(tramp_exit_native)
999 tramp_exit
1000END(tramp_exit_native)
1001
1002ENTRY(tramp_exit_compat)
1003 tramp_exit 32
1004END(tramp_exit_compat)
1005
1006 .ltorg
1007 .popsection // .entry.tramp.text
Will Deacon912612c2017-12-06 11:24:02 +00001008#ifdef CONFIG_RANDOMIZE_BASE
1009 .pushsection ".rodata", "a"
1010 .align PAGE_SHIFT
1011 .globl __entry_tramp_data_start
1012__entry_tramp_data_start:
1013 .quad vectors
1014 .popsection // .rodata
1015#endif /* CONFIG_RANDOMIZE_BASE */
Will Deacon39d3d6b2017-11-14 14:07:40 +00001016#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
1017
Catalin Marinas60ffc302012-03-05 11:49:27 +00001018/*
1019 * Special system call wrappers.
1020 */
Catalin Marinas60ffc302012-03-05 11:49:27 +00001021ENTRY(sys_rt_sigreturn_wrapper)
1022 mov x0, sp
1023 b sys_rt_sigreturn
1024ENDPROC(sys_rt_sigreturn_wrapper)