blob: dafa13766f911cfa23122a8b76362e6af241313e [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 Deacona329b062017-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 Deacon8fdbffb2017-11-14 14:20:21 +000074 .macro kernel_ventry, el, label, regsize = 64
Mark Rutland17d35922017-07-19 17:24:49 +010075 .align 7
Will Deaconc27a22582017-11-14 14:24:29 +000076#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
Will Deaconf79ff2d2017-11-14 14:38:19 +000077alternative_if ARM64_UNMAP_KERNEL_AT_EL0
Will Deaconc27a22582017-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 Deaconf79ff2d2017-11-14 14:38:19 +000086alternative_else_nop_endif
Will Deaconc27a22582017-11-14 14:24:29 +000087#endif
88
Will Deacon63648dd2014-09-29 12:26:41 +010089 sub sp, sp, #S_FRAME_SIZE
Will Deacon8fdbffb2017-11-14 14:20:21 +000090 b el\()\el\()_\label
Mark Rutland17d35922017-07-19 17:24:49 +010091 .endm
92
Will Deaconc27a22582017-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 Rutland17d35922017-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
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000120 mov tsk, sp
121 and tsk, tsk, #~(THREAD_SIZE - 1) // Ensure MDSCR_EL1.SS is clear,
Will Deacon2a283072014-04-29 19:04:06 +0100122 ldr x19, [tsk, #TI_FLAGS] // since we can unmask debug
123 disable_step_tsk x19, x20 // exceptions when scheduling.
James Morse49003a82015-12-10 10:22:41 +0000124
125 mov x29, xzr // fp pointed to user-space
Catalin Marinas60ffc302012-03-05 11:49:27 +0000126 .else
127 add x21, sp, #S_FRAME_SIZE
James Morsee19a6ee2016-06-20 18:28:01 +0100128 get_thread_info tsk
129 /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */
130 ldr x20, [tsk, #TI_ADDR_LIMIT]
131 str x20, [sp, #S_ORIG_ADDR_LIMIT]
132 mov x20, #TASK_SIZE_64
133 str x20, [tsk, #TI_ADDR_LIMIT]
Vladimir Murzin563cada2016-09-01 14:35:59 +0100134 /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */
James Morsee19a6ee2016-06-20 18:28:01 +0100135 .endif /* \el == 0 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000136 mrs x22, elr_el1
137 mrs x23, spsr_el1
138 stp lr, x21, [sp, #S_LR]
Catalin Marinascfa93772016-09-02 14:54:03 +0100139
140#ifdef CONFIG_ARM64_SW_TTBR0_PAN
141 /*
142 * Set the TTBR0 PAN bit in SPSR. When the exception is taken from
143 * EL0, there is no need to check the state of TTBR0_EL1 since
144 * accesses are always enabled.
145 * Note that the meaning of this bit differs from the ARMv8.1 PAN
146 * feature as all TTBR0_EL1 accesses are disabled, not just those to
147 * user mappings.
148 */
149alternative_if ARM64_HAS_PAN
150 b 1f // skip TTBR0 PAN
151alternative_else_nop_endif
152
153 .if \el != 0
Will Deacon599c71f2017-08-10 13:58:16 +0100154 mrs x21, ttbr1_el1
Will Deacond7013ed2017-12-01 17:33:48 +0000155 tst x21, #TTBR_ASID_MASK // Check for the reserved ASID
Catalin Marinascfa93772016-09-02 14:54:03 +0100156 orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR
157 b.eq 1f // TTBR0 access already disabled
158 and x23, x23, #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
159 .endif
160
161 __uaccess_ttbr0_disable x21
1621:
163#endif
164
Catalin Marinas60ffc302012-03-05 11:49:27 +0000165 stp x22, x23, [sp, #S_PC]
166
167 /*
168 * Set syscallno to -1 by default (overridden later if real syscall).
169 */
170 .if \el == 0
171 mvn x21, xzr
172 str x21, [sp, #S_SYSCALLNO]
173 .endif
174
175 /*
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000176 * Set sp_el0 to current thread_info.
177 */
178 .if \el == 0
179 msr sp_el0, tsk
180 .endif
181
182 /*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000183 * Registers that may be useful after this macro is invoked:
184 *
185 * x21 - aborted SP
186 * x22 - aborted PC
187 * x23 - aborted PSTATE
188 */
189 .endm
190
Will Deacon412fcb62015-08-19 15:57:09 +0100191 .macro kernel_exit, el
James Morsee19a6ee2016-06-20 18:28:01 +0100192 .if \el != 0
193 /* Restore the task's original addr_limit. */
194 ldr x20, [sp, #S_ORIG_ADDR_LIMIT]
195 str x20, [tsk, #TI_ADDR_LIMIT]
196
197 /* No need to restore UAO, it will be restored from SPSR_EL1 */
198 .endif
199
Catalin Marinas60ffc302012-03-05 11:49:27 +0000200 ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
201 .if \el == 0
Larry Bassel6c81fe72014-05-30 12:34:15 -0700202 ct_user_enter
Catalin Marinascfa93772016-09-02 14:54:03 +0100203 .endif
204
205#ifdef CONFIG_ARM64_SW_TTBR0_PAN
206 /*
207 * Restore access to TTBR0_EL1. If returning to EL0, no need for SPSR
208 * PAN bit checking.
209 */
210alternative_if ARM64_HAS_PAN
211 b 2f // skip TTBR0 PAN
212alternative_else_nop_endif
213
214 .if \el != 0
215 tbnz x22, #22, 1f // Skip re-enabling TTBR0 access if the PSR_PAN_BIT is set
216 .endif
217
Will Deacon599c71f2017-08-10 13:58:16 +0100218 __uaccess_ttbr0_enable x0, x1
Catalin Marinascfa93772016-09-02 14:54:03 +0100219
220 .if \el == 0
221 /*
222 * Enable errata workarounds only if returning to user. The only
223 * workaround currently required for TTBR0_EL1 changes are for the
224 * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache
225 * corruption).
226 */
Marc Zyngier95bfec62018-01-02 18:19:39 +0000227 bl post_ttbr_update_workaround
Catalin Marinascfa93772016-09-02 14:54:03 +0100228 .endif
2291:
230 .if \el != 0
231 and x22, x22, #~PSR_PAN_BIT // ARMv8.0 CPUs do not understand this bit
232 .endif
2332:
234#endif
235
236 .if \el == 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000237 ldr x23, [sp, #S_SP] // load return stack pointer
Catalin Marinas60ffc302012-03-05 11:49:27 +0000238 msr sp_el0, x23
Will Deaconc27a22582017-11-14 14:24:29 +0000239 tst x22, #PSR_MODE32_BIT // native task?
240 b.eq 3f
241
Will Deacon905e8c52015-03-23 19:07:02 +0000242#ifdef CONFIG_ARM64_ERRATUM_845719
Mark Rutland6ba3b552016-09-07 11:07:09 +0100243alternative_if ARM64_WORKAROUND_845719
Daniel Thompsone28cabf2015-07-22 12:21:03 +0100244#ifdef CONFIG_PID_IN_CONTEXTIDR
245 mrs x29, contextidr_el1
246 msr contextidr_el1, x29
247#else
248 msr contextidr_el1, xzr
249#endif
Mark Rutland6ba3b552016-09-07 11:07:09 +0100250alternative_else_nop_endif
Will Deacon905e8c52015-03-23 19:07:02 +0000251#endif
Will Deaconc27a22582017-11-14 14:24:29 +00002523:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000253 .endif
Catalin Marinascfa93772016-09-02 14:54:03 +0100254
Will Deacon63648dd2014-09-29 12:26:41 +0100255 msr elr_el1, x21 // set up the return data
256 msr spsr_el1, x22
Will Deacon63648dd2014-09-29 12:26:41 +0100257 ldp x0, x1, [sp, #16 * 0]
Will Deacon63648dd2014-09-29 12:26:41 +0100258 ldp x2, x3, [sp, #16 * 1]
259 ldp x4, x5, [sp, #16 * 2]
260 ldp x6, x7, [sp, #16 * 3]
261 ldp x8, x9, [sp, #16 * 4]
262 ldp x10, x11, [sp, #16 * 5]
263 ldp x12, x13, [sp, #16 * 6]
264 ldp x14, x15, [sp, #16 * 7]
265 ldp x16, x17, [sp, #16 * 8]
266 ldp x18, x19, [sp, #16 * 9]
267 ldp x20, x21, [sp, #16 * 10]
268 ldp x22, x23, [sp, #16 * 11]
269 ldp x24, x25, [sp, #16 * 12]
270 ldp x26, x27, [sp, #16 * 13]
271 ldp x28, x29, [sp, #16 * 14]
272 ldr lr, [sp, #S_LR]
273 add sp, sp, #S_FRAME_SIZE // restore sp
Will Deaconc27a22582017-11-14 14:24:29 +0000274
Will Deaconc27a22582017-11-14 14:24:29 +0000275 .if \el == 0
Will Deaconf79ff2d2017-11-14 14:38:19 +0000276alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
277#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
Will Deaconc27a22582017-11-14 14:24:29 +0000278 bne 4f
279 msr far_el1, x30
280 tramp_alias x30, tramp_exit_native
281 br x30
2824:
283 tramp_alias x30, tramp_exit_compat
284 br x30
Will Deaconf79ff2d2017-11-14 14:38:19 +0000285#endif
Will Deaconc27a22582017-11-14 14:24:29 +0000286 .else
287 eret
288 .endif
Catalin Marinas60ffc302012-03-05 11:49:27 +0000289 .endm
290
James Morse971c67c2015-12-15 11:21:25 +0000291 .macro irq_stack_entry
James Morse8e23dac2015-12-04 11:02:27 +0000292 mov x19, sp // preserve the original sp
293
James Morse8e23dac2015-12-04 11:02:27 +0000294 /*
James Morsed224a692015-12-18 16:01:47 +0000295 * Compare sp with the current thread_info, if the top
296 * ~(THREAD_SIZE - 1) bits match, we are on a task stack, and
297 * should switch to the irq stack.
James Morse8e23dac2015-12-04 11:02:27 +0000298 */
James Morsed224a692015-12-18 16:01:47 +0000299 and x25, x19, #~(THREAD_SIZE - 1)
300 cmp x25, tsk
301 b.ne 9998f
James Morse8e23dac2015-12-04 11:02:27 +0000302
James Morsed224a692015-12-18 16:01:47 +0000303 this_cpu_ptr irq_stack, x25, 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 Deacon8fdbffb2017-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 Deacon8fdbffb2017-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 Deacon8fdbffb2017-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 Deacon8fdbffb2017-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 Deacon8fdbffb2017-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
Neil Zhang883c0572014-01-13 08:57:56 +0000531 ldr w24, [tsk, #TI_PREEMPT] // get preempt count
Marc Zyngier717321f2013-11-04 20:14:58 +0000532 cbnz w24, 1f // preempt count != 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000533 ldr x0, [tsk, #TI_FLAGS] // get flags
534 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
Catalin Marinas60ffc302012-03-05 11:49:27 +0000548 ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
549 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
Larry Bassel6c81fe72014-05-30 12:34:15 -0700651 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100652 mov x0, x26
Mark Rutland541ec872016-05-31 12:33:03 +0100653 mov x1, x25
Catalin Marinas60ffc302012-03-05 11:49:27 +0000654 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100655 bl do_mem_abort
656 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000657el0_fpsimd_acc:
658 /*
659 * Floating Point or Advanced SIMD access
660 */
Will Deacon2a283072014-04-29 19:04:06 +0100661 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700662 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000663 mov x0, x25
664 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100665 bl do_fpsimd_acc
666 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000667el0_fpsimd_exc:
668 /*
669 * Floating Point or Advanced SIMD exception
670 */
Will Deacon2a283072014-04-29 19:04:06 +0100671 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700672 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000673 mov x0, x25
674 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100675 bl do_fpsimd_exc
676 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000677el0_sp_pc:
678 /*
679 * Stack or PC alignment exception handling
680 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100681 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000682 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100683 enable_dbg_and_irq
Mark Rutland46b05672015-06-15 16:40:27 +0100684 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100685 mov x0, x26
Catalin Marinas60ffc302012-03-05 11:49:27 +0000686 mov x1, x25
687 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100688 bl do_sp_pc_abort
689 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000690el0_undef:
691 /*
692 * Undefined instruction
693 */
Catalin Marinas2600e132013-08-22 11:47:37 +0100694 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100695 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700696 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100697 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100698 bl do_undefinstr
699 b ret_to_user
Andre Przywara7dd01ae2016-06-28 18:07:32 +0100700el0_sys:
701 /*
702 * System instructions, for trapped cache maintenance instructions
703 */
704 enable_dbg_and_irq
705 ct_user_exit
706 mov x0, x25
707 mov x1, sp
708 bl do_sysinstr
709 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000710el0_dbg:
711 /*
712 * Debug exception handling
713 */
714 tbnz x24, #0, el0_inv // EL0 only
715 mrs x0, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000716 mov x1, x25
717 mov x2, sp
Will Deacon2a283072014-04-29 19:04:06 +0100718 bl do_debug_exception
719 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700720 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100721 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000722el0_inv:
Will Deacon2a283072014-04-29 19:04:06 +0100723 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700724 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000725 mov x0, sp
726 mov x1, #BAD_SYNC
Mark Rutland1b428042015-07-07 18:00:49 +0100727 mov x2, x25
Mark Rutlandde327942017-01-18 17:23:41 +0000728 bl bad_el0_sync
Will Deacond54e81f2014-09-29 11:44:01 +0100729 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000730ENDPROC(el0_sync)
731
732 .align 6
733el0_irq:
734 kernel_entry 0
735el0_irq_naked:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000736 enable_dbg
737#ifdef CONFIG_TRACE_IRQFLAGS
738 bl trace_hardirqs_off
739#endif
Marc Zyngier64681782013-11-12 17:11:53 +0000740
Larry Bassel6c81fe72014-05-30 12:34:15 -0700741 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000742 irq_handler
Marc Zyngier64681782013-11-12 17:11:53 +0000743
Catalin Marinas60ffc302012-03-05 11:49:27 +0000744#ifdef CONFIG_TRACE_IRQFLAGS
745 bl trace_hardirqs_on
746#endif
747 b ret_to_user
748ENDPROC(el0_irq)
749
750/*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000751 * Register switch for AArch64. The callee-saved registers need to be saved
752 * and restored. On entry:
753 * x0 = previous task_struct (must be preserved across the switch)
754 * x1 = next task_struct
755 * Previous and next are guaranteed not to be the same.
756 *
757 */
758ENTRY(cpu_switch_to)
Will Deaconc0d3fce2015-07-20 15:14:53 +0100759 mov x10, #THREAD_CPU_CONTEXT
760 add x8, x0, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000761 mov x9, sp
762 stp x19, x20, [x8], #16 // store callee-saved registers
763 stp x21, x22, [x8], #16
764 stp x23, x24, [x8], #16
765 stp x25, x26, [x8], #16
766 stp x27, x28, [x8], #16
767 stp x29, x9, [x8], #16
768 str lr, [x8]
Will Deaconc0d3fce2015-07-20 15:14:53 +0100769 add x8, x1, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000770 ldp x19, x20, [x8], #16 // restore callee-saved registers
771 ldp x21, x22, [x8], #16
772 ldp x23, x24, [x8], #16
773 ldp x25, x26, [x8], #16
774 ldp x27, x28, [x8], #16
775 ldp x29, x9, [x8], #16
776 ldr lr, [x8]
777 mov sp, x9
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000778 and x9, x9, #~(THREAD_SIZE - 1)
779 msr sp_el0, x9
Catalin Marinas60ffc302012-03-05 11:49:27 +0000780 ret
781ENDPROC(cpu_switch_to)
782
783/*
784 * This is the fast syscall return path. We do as little as possible here,
785 * and this includes saving x0 back into the kernel stack.
786 */
787ret_fast_syscall:
788 disable_irq // disable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100789 str x0, [sp, #S_X0] // returned x0
Josh Stone04d7e092015-06-05 14:28:03 -0700790 ldr x1, [tsk, #TI_FLAGS] // re-check for syscall tracing
791 and x2, x1, #_TIF_SYSCALL_WORK
792 cbnz x2, ret_fast_syscall_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000793 and x2, x1, #_TIF_WORK_MASK
Will Deacon412fcb62015-08-19 15:57:09 +0100794 cbnz x2, work_pending
Will Deacon2a283072014-04-29 19:04:06 +0100795 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100796 kernel_exit 0
Josh Stone04d7e092015-06-05 14:28:03 -0700797ret_fast_syscall_trace:
798 enable_irq // enable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100799 b __sys_trace_return_skipped // we already saved x0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000800
801/*
802 * Ok, we need to do extra processing, enter the slow path.
803 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000804work_pending:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000805 mov x0, sp // 'regs'
Catalin Marinas60ffc302012-03-05 11:49:27 +0000806 bl do_notify_resume
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000807#ifdef CONFIG_TRACE_IRQFLAGS
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400808 bl trace_hardirqs_on // enabled while in userspace
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000809#endif
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400810 ldr x1, [tsk, #TI_FLAGS] // re-check for single-step
811 b finish_ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000812/*
813 * "slow" syscall return path.
814 */
Catalin Marinas59dc67b2012-09-10 16:11:46 +0100815ret_to_user:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000816 disable_irq // disable interrupts
817 ldr x1, [tsk, #TI_FLAGS]
818 and x2, x1, #_TIF_WORK_MASK
819 cbnz x2, work_pending
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400820finish_ret_to_user:
Will Deacon2a283072014-04-29 19:04:06 +0100821 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100822 kernel_exit 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000823ENDPROC(ret_to_user)
824
825/*
826 * This is how we return from a fork.
827 */
828ENTRY(ret_from_fork)
829 bl schedule_tail
Catalin Marinasc34501d2012-10-05 12:31:20 +0100830 cbz x19, 1f // not a kernel thread
831 mov x0, x20
832 blr x19
8331: get_thread_info tsk
Catalin Marinas60ffc302012-03-05 11:49:27 +0000834 b ret_to_user
835ENDPROC(ret_from_fork)
836
837/*
838 * SVC handler.
839 */
840 .align 6
841el0_svc:
842 adrp stbl, sys_call_table // load syscall table pointer
843 uxtw scno, w8 // syscall number in w8
844 mov sc_nr, #__NR_syscalls
845el0_svc_naked: // compat entry point
846 stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number
Will Deacon2a283072014-04-29 19:04:06 +0100847 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700848 ct_user_exit 1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000849
AKASHI Takahiro449f81a2014-04-30 10:51:29 +0100850 ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks
851 tst x16, #_TIF_SYSCALL_WORK
852 b.ne __sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000853 cmp scno, sc_nr // check upper syscall limit
854 b.hs ni_sys
855 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100856 blr x16 // call sys_* routine
857 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000858ni_sys:
859 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100860 bl do_ni_syscall
861 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000862ENDPROC(el0_svc)
863
864 /*
865 * This is the really slow path. We're going to be doing context
866 * switches, and waiting for our parent to respond.
867 */
868__sys_trace:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000869 mov w0, #-1 // set default errno for
870 cmp scno, x0 // user-issued syscall(-1)
871 b.ne 1f
872 mov x0, #-ENOSYS
873 str x0, [sp, #S_X0]
8741: mov x0, sp
AKASHI Takahiro31578582014-04-30 10:51:30 +0100875 bl syscall_trace_enter
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000876 cmp w0, #-1 // skip the syscall?
877 b.eq __sys_trace_return_skipped
Catalin Marinas60ffc302012-03-05 11:49:27 +0000878 uxtw scno, w0 // syscall number (possibly new)
879 mov x1, sp // pointer to regs
880 cmp scno, sc_nr // check upper syscall limit
Will Deacond54e81f2014-09-29 11:44:01 +0100881 b.hs __ni_sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000882 ldp x0, x1, [sp] // restore the syscall args
883 ldp x2, x3, [sp, #S_X2]
884 ldp x4, x5, [sp, #S_X4]
885 ldp x6, x7, [sp, #S_X6]
886 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100887 blr x16 // call sys_* routine
Catalin Marinas60ffc302012-03-05 11:49:27 +0000888
889__sys_trace_return:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000890 str x0, [sp, #S_X0] // save returned x0
891__sys_trace_return_skipped:
AKASHI Takahiro31578582014-04-30 10:51:30 +0100892 mov x0, sp
893 bl syscall_trace_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000894 b ret_to_user
895
Will Deacond54e81f2014-09-29 11:44:01 +0100896__ni_sys_trace:
897 mov x0, sp
898 bl do_ni_syscall
899 b __sys_trace_return
900
Pratyush Anand888b3c82016-07-08 12:35:50 -0400901 .popsection // .entry.text
902
Will Deacona329b062017-11-14 14:07:40 +0000903#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
904/*
905 * Exception vectors trampoline.
906 */
907 .pushsection ".entry.tramp.text", "ax"
908
909 .macro tramp_map_kernel, tmp
910 mrs \tmp, ttbr1_el1
911 sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
912 bic \tmp, \tmp, #USER_ASID_FLAG
913 msr ttbr1_el1, \tmp
Will Deacon04b77fe2017-11-14 14:29:19 +0000914#ifdef CONFIG_ARCH_MSM8996
915 /* ASID already in \tmp[63:48] */
916 movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12)
917 movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12)
918 /* 2MB boundary containing the vectors, so we nobble the walk cache */
919 movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12)
920 isb
921 tlbi vae1, \tmp
922 dsb nsh
923#endif /* CONFIG_ARCH_MSM8996 */
Will Deacona329b062017-11-14 14:07:40 +0000924 .endm
925
926 .macro tramp_unmap_kernel, tmp
927 mrs \tmp, ttbr1_el1
928 add \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
929 orr \tmp, \tmp, #USER_ASID_FLAG
930 msr ttbr1_el1, \tmp
931 /*
932 * We avoid running the post_ttbr_update_workaround here because the
933 * user and kernel ASIDs don't have conflicting mappings, so any
934 * "blessing" as described in:
935 *
936 * http://lkml.kernel.org/r/56BB848A.6060603@caviumnetworks.com
937 *
938 * will not hurt correctness. Whilst this may partially defeat the
939 * point of using split ASIDs in the first place, it avoids
940 * the hit of invalidating the entire I-cache on every return to
941 * userspace.
942 */
943 .endm
944
945 .macro tramp_ventry, regsize = 64
946 .align 7
9471:
948 .if \regsize == 64
949 msr tpidrro_el0, x30 // Restored in kernel_ventry
950 .endif
Will Deacon75359362017-11-14 16:15:59 +0000951 bl 2f
952 b .
9532:
Will Deacona329b062017-11-14 14:07:40 +0000954 tramp_map_kernel x30
Will Deacon06fe41f2017-12-06 11:24:02 +0000955#ifdef CONFIG_RANDOMIZE_BASE
956 adr x30, tramp_vectors + PAGE_SIZE
Todd Poynorb328e522018-01-08 12:22:41 -0800957#ifndef CONFIG_ARCH_MSM8996
958 isb
959#endif
Will Deacon06fe41f2017-12-06 11:24:02 +0000960 ldr x30, [x30]
961#else
Will Deacona329b062017-11-14 14:07:40 +0000962 ldr x30, =vectors
Will Deacon06fe41f2017-12-06 11:24:02 +0000963#endif
Will Deacona329b062017-11-14 14:07:40 +0000964 prfm plil1strm, [x30, #(1b - tramp_vectors)]
965 msr vbar_el1, x30
966 add x30, x30, #(1b - tramp_vectors)
967 isb
Will Deacon75359362017-11-14 16:15:59 +0000968 ret
Will Deacona329b062017-11-14 14:07:40 +0000969 .endm
970
971 .macro tramp_exit, regsize = 64
972 adr x30, tramp_vectors
973 msr vbar_el1, x30
974 tramp_unmap_kernel x30
975 .if \regsize == 64
976 mrs x30, far_el1
977 .endif
978 eret
979 .endm
980
981 .align 11
982ENTRY(tramp_vectors)
983 .space 0x400
984
985 tramp_ventry
986 tramp_ventry
987 tramp_ventry
988 tramp_ventry
989
990 tramp_ventry 32
991 tramp_ventry 32
992 tramp_ventry 32
993 tramp_ventry 32
994END(tramp_vectors)
995
996ENTRY(tramp_exit_native)
997 tramp_exit
998END(tramp_exit_native)
999
1000ENTRY(tramp_exit_compat)
1001 tramp_exit 32
1002END(tramp_exit_compat)
1003
1004 .ltorg
1005 .popsection // .entry.tramp.text
Will Deacon06fe41f2017-12-06 11:24:02 +00001006#ifdef CONFIG_RANDOMIZE_BASE
1007 .pushsection ".rodata", "a"
1008 .align PAGE_SHIFT
1009 .globl __entry_tramp_data_start
1010__entry_tramp_data_start:
1011 .quad vectors
1012 .popsection // .rodata
1013#endif /* CONFIG_RANDOMIZE_BASE */
Will Deacona329b062017-11-14 14:07:40 +00001014#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
1015
Catalin Marinas60ffc302012-03-05 11:49:27 +00001016/*
1017 * Special system call wrappers.
1018 */
Catalin Marinas60ffc302012-03-05 11:49:27 +00001019ENTRY(sys_rt_sigreturn_wrapper)
1020 mov x0, sp
1021 b sys_rt_sigreturn
1022ENDPROC(sys_rt_sigreturn_wrapper)