blob: 79ea90b336829b066dd6bb43d76dfd461feae485 [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
77 .if \el == 0
78 .if \regsize == 64
79 mrs x30, tpidrro_el0
80 msr tpidrro_el0, xzr
81 .else
82 mov x30, xzr
83 .endif
84 .endif
85#endif
86
Will Deacon63648dd2014-09-29 12:26:41 +010087 sub sp, sp, #S_FRAME_SIZE
Will Deacon8fdbffb2017-11-14 14:20:21 +000088 b el\()\el\()_\label
Mark Rutland17d35922017-07-19 17:24:49 +010089 .endm
90
Will Deaconc27a22582017-11-14 14:24:29 +000091 .macro tramp_alias, dst, sym
92 mov_q \dst, TRAMP_VALIAS
93 add \dst, \dst, #(\sym - .entry.tramp.text)
94 .endm
95
Mark Rutland17d35922017-07-19 17:24:49 +010096 .macro kernel_entry, el, regsize = 64
Catalin Marinas60ffc302012-03-05 11:49:27 +000097 .if \regsize == 32
98 mov w0, w0 // zero upper 32 bits of x0
99 .endif
Will Deacon63648dd2014-09-29 12:26:41 +0100100 stp x0, x1, [sp, #16 * 0]
101 stp x2, x3, [sp, #16 * 1]
102 stp x4, x5, [sp, #16 * 2]
103 stp x6, x7, [sp, #16 * 3]
104 stp x8, x9, [sp, #16 * 4]
105 stp x10, x11, [sp, #16 * 5]
106 stp x12, x13, [sp, #16 * 6]
107 stp x14, x15, [sp, #16 * 7]
108 stp x16, x17, [sp, #16 * 8]
109 stp x18, x19, [sp, #16 * 9]
110 stp x20, x21, [sp, #16 * 10]
111 stp x22, x23, [sp, #16 * 11]
112 stp x24, x25, [sp, #16 * 12]
113 stp x26, x27, [sp, #16 * 13]
114 stp x28, x29, [sp, #16 * 14]
115
Catalin Marinas60ffc302012-03-05 11:49:27 +0000116 .if \el == 0
117 mrs x21, sp_el0
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000118 mov tsk, sp
119 and tsk, tsk, #~(THREAD_SIZE - 1) // Ensure MDSCR_EL1.SS is clear,
Will Deacon2a283072014-04-29 19:04:06 +0100120 ldr x19, [tsk, #TI_FLAGS] // since we can unmask debug
121 disable_step_tsk x19, x20 // exceptions when scheduling.
James Morse49003a82015-12-10 10:22:41 +0000122
123 mov x29, xzr // fp pointed to user-space
Catalin Marinas60ffc302012-03-05 11:49:27 +0000124 .else
125 add x21, sp, #S_FRAME_SIZE
James Morsee19a6ee2016-06-20 18:28:01 +0100126 get_thread_info tsk
127 /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */
128 ldr x20, [tsk, #TI_ADDR_LIMIT]
129 str x20, [sp, #S_ORIG_ADDR_LIMIT]
130 mov x20, #TASK_SIZE_64
131 str x20, [tsk, #TI_ADDR_LIMIT]
Vladimir Murzin563cada2016-09-01 14:35:59 +0100132 /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */
James Morsee19a6ee2016-06-20 18:28:01 +0100133 .endif /* \el == 0 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000134 mrs x22, elr_el1
135 mrs x23, spsr_el1
136 stp lr, x21, [sp, #S_LR]
Catalin Marinascfa93772016-09-02 14:54:03 +0100137
138#ifdef CONFIG_ARM64_SW_TTBR0_PAN
139 /*
140 * Set the TTBR0 PAN bit in SPSR. When the exception is taken from
141 * EL0, there is no need to check the state of TTBR0_EL1 since
142 * accesses are always enabled.
143 * Note that the meaning of this bit differs from the ARMv8.1 PAN
144 * feature as all TTBR0_EL1 accesses are disabled, not just those to
145 * user mappings.
146 */
147alternative_if ARM64_HAS_PAN
148 b 1f // skip TTBR0 PAN
149alternative_else_nop_endif
150
151 .if \el != 0
Will Deacon599c71f2017-08-10 13:58:16 +0100152 mrs x21, ttbr1_el1
Catalin Marinascfa93772016-09-02 14:54:03 +0100153 tst x21, #0xffff << 48 // Check for the reserved ASID
154 orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR
155 b.eq 1f // TTBR0 access already disabled
156 and x23, x23, #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
157 .endif
158
159 __uaccess_ttbr0_disable x21
1601:
161#endif
162
Catalin Marinas60ffc302012-03-05 11:49:27 +0000163 stp x22, x23, [sp, #S_PC]
164
165 /*
166 * Set syscallno to -1 by default (overridden later if real syscall).
167 */
168 .if \el == 0
169 mvn x21, xzr
170 str x21, [sp, #S_SYSCALLNO]
171 .endif
172
173 /*
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000174 * Set sp_el0 to current thread_info.
175 */
176 .if \el == 0
177 msr sp_el0, tsk
178 .endif
179
180 /*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000181 * Registers that may be useful after this macro is invoked:
182 *
183 * x21 - aborted SP
184 * x22 - aborted PC
185 * x23 - aborted PSTATE
186 */
187 .endm
188
Will Deacon412fcb62015-08-19 15:57:09 +0100189 .macro kernel_exit, el
James Morsee19a6ee2016-06-20 18:28:01 +0100190 .if \el != 0
191 /* Restore the task's original addr_limit. */
192 ldr x20, [sp, #S_ORIG_ADDR_LIMIT]
193 str x20, [tsk, #TI_ADDR_LIMIT]
194
195 /* No need to restore UAO, it will be restored from SPSR_EL1 */
196 .endif
197
Catalin Marinas60ffc302012-03-05 11:49:27 +0000198 ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
199 .if \el == 0
Larry Bassel6c81fe72014-05-30 12:34:15 -0700200 ct_user_enter
Catalin Marinascfa93772016-09-02 14:54:03 +0100201 .endif
202
203#ifdef CONFIG_ARM64_SW_TTBR0_PAN
204 /*
205 * Restore access to TTBR0_EL1. If returning to EL0, no need for SPSR
206 * PAN bit checking.
207 */
208alternative_if ARM64_HAS_PAN
209 b 2f // skip TTBR0 PAN
210alternative_else_nop_endif
211
212 .if \el != 0
213 tbnz x22, #22, 1f // Skip re-enabling TTBR0 access if the PSR_PAN_BIT is set
214 .endif
215
Will Deacon599c71f2017-08-10 13:58:16 +0100216 __uaccess_ttbr0_enable x0, x1
Catalin Marinascfa93772016-09-02 14:54:03 +0100217
218 .if \el == 0
219 /*
220 * Enable errata workarounds only if returning to user. The only
221 * workaround currently required for TTBR0_EL1 changes are for the
222 * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache
223 * corruption).
224 */
Will Deacon071a49f2017-08-10 13:34:30 +0100225 post_ttbr_update_workaround
Catalin Marinascfa93772016-09-02 14:54:03 +0100226 .endif
2271:
228 .if \el != 0
229 and x22, x22, #~PSR_PAN_BIT // ARMv8.0 CPUs do not understand this bit
230 .endif
2312:
232#endif
233
234 .if \el == 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000235 ldr x23, [sp, #S_SP] // load return stack pointer
Catalin Marinas60ffc302012-03-05 11:49:27 +0000236 msr sp_el0, x23
Will Deaconc27a22582017-11-14 14:24:29 +0000237 tst x22, #PSR_MODE32_BIT // native task?
238 b.eq 3f
239
Will Deacon905e8c52015-03-23 19:07:02 +0000240#ifdef CONFIG_ARM64_ERRATUM_845719
Mark Rutland6ba3b552016-09-07 11:07:09 +0100241alternative_if ARM64_WORKAROUND_845719
Daniel Thompsone28cabf2015-07-22 12:21:03 +0100242#ifdef CONFIG_PID_IN_CONTEXTIDR
243 mrs x29, contextidr_el1
244 msr contextidr_el1, x29
245#else
246 msr contextidr_el1, xzr
247#endif
Mark Rutland6ba3b552016-09-07 11:07:09 +0100248alternative_else_nop_endif
Will Deacon905e8c52015-03-23 19:07:02 +0000249#endif
Will Deaconc27a22582017-11-14 14:24:29 +00002503:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000251 .endif
Catalin Marinascfa93772016-09-02 14:54:03 +0100252
Will Deacon63648dd2014-09-29 12:26:41 +0100253 msr elr_el1, x21 // set up the return data
254 msr spsr_el1, x22
Will Deacon63648dd2014-09-29 12:26:41 +0100255 ldp x0, x1, [sp, #16 * 0]
Will Deacon63648dd2014-09-29 12:26:41 +0100256 ldp x2, x3, [sp, #16 * 1]
257 ldp x4, x5, [sp, #16 * 2]
258 ldp x6, x7, [sp, #16 * 3]
259 ldp x8, x9, [sp, #16 * 4]
260 ldp x10, x11, [sp, #16 * 5]
261 ldp x12, x13, [sp, #16 * 6]
262 ldp x14, x15, [sp, #16 * 7]
263 ldp x16, x17, [sp, #16 * 8]
264 ldp x18, x19, [sp, #16 * 9]
265 ldp x20, x21, [sp, #16 * 10]
266 ldp x22, x23, [sp, #16 * 11]
267 ldp x24, x25, [sp, #16 * 12]
268 ldp x26, x27, [sp, #16 * 13]
269 ldp x28, x29, [sp, #16 * 14]
270 ldr lr, [sp, #S_LR]
271 add sp, sp, #S_FRAME_SIZE // restore sp
Will Deaconc27a22582017-11-14 14:24:29 +0000272
273#ifndef CONFIG_UNMAP_KERNEL_AT_EL0
274 eret
275#else
276 .if \el == 0
277 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
284 .else
285 eret
286 .endif
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 /*
James Morsed224a692015-12-18 16:01:47 +0000294 * Compare sp with the current thread_info, if the top
295 * ~(THREAD_SIZE - 1) bits match, we are on a task stack, and
296 * should switch to the irq stack.
James Morse8e23dac2015-12-04 11:02:27 +0000297 */
James Morsed224a692015-12-18 16:01:47 +0000298 and x25, x19, #~(THREAD_SIZE - 1)
299 cmp x25, tsk
300 b.ne 9998f
James Morse8e23dac2015-12-04 11:02:27 +0000301
James Morsed224a692015-12-18 16:01:47 +0000302 this_cpu_ptr irq_stack, x25, x26
James Morse8e23dac2015-12-04 11:02:27 +0000303 mov x26, #IRQ_STACK_START_SP
304 add x26, x25, x26
James Morsed224a692015-12-18 16:01:47 +0000305
306 /* switch to the irq stack */
James Morse8e23dac2015-12-04 11:02:27 +0000307 mov sp, x26
308
James Morse971c67c2015-12-15 11:21:25 +0000309 /*
310 * Add a dummy stack frame, this non-standard format is fixed up
311 * by unwind_frame()
312 */
313 stp x29, x19, [sp, #-16]!
James Morse8e23dac2015-12-04 11:02:27 +0000314 mov x29, sp
James Morse8e23dac2015-12-04 11:02:27 +0000315
3169998:
317 .endm
318
319 /*
320 * x19 should be preserved between irq_stack_entry and
321 * irq_stack_exit.
322 */
323 .macro irq_stack_exit
324 mov sp, x19
325 .endm
326
Catalin Marinas60ffc302012-03-05 11:49:27 +0000327/*
328 * These are the registers used in the syscall handler, and allow us to
329 * have in theory up to 7 arguments to a function - x0 to x6.
330 *
331 * x7 is reserved for the system call number in 32-bit mode.
332 */
333sc_nr .req x25 // number of system calls
334scno .req x26 // syscall number
335stbl .req x27 // syscall table pointer
336tsk .req x28 // current thread_info
337
338/*
339 * Interrupt handling.
340 */
341 .macro irq_handler
James Morse8e23dac2015-12-04 11:02:27 +0000342 ldr_l x1, handle_arch_irq
Catalin Marinas60ffc302012-03-05 11:49:27 +0000343 mov x0, sp
James Morse971c67c2015-12-15 11:21:25 +0000344 irq_stack_entry
Catalin Marinas60ffc302012-03-05 11:49:27 +0000345 blr x1
James Morse8e23dac2015-12-04 11:02:27 +0000346 irq_stack_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000347 .endm
348
349 .text
350
351/*
352 * Exception vectors.
353 */
Pratyush Anand888b3c82016-07-08 12:35:50 -0400354 .pushsection ".entry.text", "ax"
Catalin Marinas60ffc302012-03-05 11:49:27 +0000355
356 .align 11
357ENTRY(vectors)
Will Deacon8fdbffb2017-11-14 14:20:21 +0000358 kernel_ventry 1, sync_invalid // Synchronous EL1t
359 kernel_ventry 1, irq_invalid // IRQ EL1t
360 kernel_ventry 1, fiq_invalid // FIQ EL1t
361 kernel_ventry 1, error_invalid // Error EL1t
Catalin Marinas60ffc302012-03-05 11:49:27 +0000362
Will Deacon8fdbffb2017-11-14 14:20:21 +0000363 kernel_ventry 1, sync // Synchronous EL1h
364 kernel_ventry 1, irq // IRQ EL1h
365 kernel_ventry 1, fiq_invalid // FIQ EL1h
366 kernel_ventry 1, error_invalid // Error EL1h
Catalin Marinas60ffc302012-03-05 11:49:27 +0000367
Will Deacon8fdbffb2017-11-14 14:20:21 +0000368 kernel_ventry 0, sync // Synchronous 64-bit EL0
369 kernel_ventry 0, irq // IRQ 64-bit EL0
370 kernel_ventry 0, fiq_invalid // FIQ 64-bit EL0
371 kernel_ventry 0, error_invalid // Error 64-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000372
373#ifdef CONFIG_COMPAT
Will Deacon8fdbffb2017-11-14 14:20:21 +0000374 kernel_ventry 0, sync_compat, 32 // Synchronous 32-bit EL0
375 kernel_ventry 0, irq_compat, 32 // IRQ 32-bit EL0
376 kernel_ventry 0, fiq_invalid_compat, 32 // FIQ 32-bit EL0
377 kernel_ventry 0, error_invalid_compat, 32 // Error 32-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000378#else
Will Deacon8fdbffb2017-11-14 14:20:21 +0000379 kernel_ventry 0, sync_invalid, 32 // Synchronous 32-bit EL0
380 kernel_ventry 0, irq_invalid, 32 // IRQ 32-bit EL0
381 kernel_ventry 0, fiq_invalid, 32 // FIQ 32-bit EL0
382 kernel_ventry 0, error_invalid, 32 // Error 32-bit EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000383#endif
384END(vectors)
385
386/*
387 * Invalid mode handlers
388 */
389 .macro inv_entry, el, reason, regsize = 64
Ard Biesheuvelb6609502016-03-18 10:58:09 +0100390 kernel_entry \el, \regsize
Catalin Marinas60ffc302012-03-05 11:49:27 +0000391 mov x0, sp
392 mov x1, #\reason
393 mrs x2, esr_el1
394 b bad_mode
395 .endm
396
397el0_sync_invalid:
398 inv_entry 0, BAD_SYNC
399ENDPROC(el0_sync_invalid)
400
401el0_irq_invalid:
402 inv_entry 0, BAD_IRQ
403ENDPROC(el0_irq_invalid)
404
405el0_fiq_invalid:
406 inv_entry 0, BAD_FIQ
407ENDPROC(el0_fiq_invalid)
408
409el0_error_invalid:
410 inv_entry 0, BAD_ERROR
411ENDPROC(el0_error_invalid)
412
413#ifdef CONFIG_COMPAT
414el0_fiq_invalid_compat:
415 inv_entry 0, BAD_FIQ, 32
416ENDPROC(el0_fiq_invalid_compat)
417
418el0_error_invalid_compat:
419 inv_entry 0, BAD_ERROR, 32
420ENDPROC(el0_error_invalid_compat)
421#endif
422
423el1_sync_invalid:
424 inv_entry 1, BAD_SYNC
425ENDPROC(el1_sync_invalid)
426
427el1_irq_invalid:
428 inv_entry 1, BAD_IRQ
429ENDPROC(el1_irq_invalid)
430
431el1_fiq_invalid:
432 inv_entry 1, BAD_FIQ
433ENDPROC(el1_fiq_invalid)
434
435el1_error_invalid:
436 inv_entry 1, BAD_ERROR
437ENDPROC(el1_error_invalid)
438
439/*
440 * EL1 mode handlers.
441 */
442 .align 6
443el1_sync:
444 kernel_entry 1
445 mrs x1, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000446 lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class
447 cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000448 b.eq el1_da
Laura Abbott9adeb8e2016-08-09 18:25:26 -0700449 cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1
450 b.eq el1_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000451 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
Catalin Marinas60ffc302012-03-05 11:49:27 +0000452 b.eq el1_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000453 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000454 b.eq el1_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000455 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000456 b.eq el1_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000457 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000458 b.eq el1_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000459 cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000460 b.ge el1_dbg
461 b el1_inv
Laura Abbott9adeb8e2016-08-09 18:25:26 -0700462
463el1_ia:
464 /*
465 * Fall through to the Data abort case
466 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000467el1_da:
468 /*
469 * Data abort handling
470 */
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100471 mrs x3, far_el1
Will Deacon2a283072014-04-29 19:04:06 +0100472 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000473 // re-enable interrupts if they were enabled in the aborted context
474 tbnz x23, #7, 1f // PSR_I_BIT
475 enable_irq
4761:
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100477 clear_address_tag x0, x3
Catalin Marinas60ffc302012-03-05 11:49:27 +0000478 mov x2, sp // struct pt_regs
479 bl do_mem_abort
480
481 // disable interrupts before pulling preserved data off the stack
482 disable_irq
483 kernel_exit 1
484el1_sp_pc:
485 /*
486 * Stack or PC alignment exception handling
487 */
488 mrs x0, far_el1
Will Deacon2a283072014-04-29 19:04:06 +0100489 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000490 mov x2, sp
491 b do_sp_pc_abort
492el1_undef:
493 /*
494 * Undefined instruction
495 */
Will Deacon2a283072014-04-29 19:04:06 +0100496 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000497 mov x0, sp
498 b do_undefinstr
499el1_dbg:
500 /*
501 * Debug exception handling
502 */
Mark Rutlandaed40e02014-11-24 12:31:40 +0000503 cmp x24, #ESR_ELx_EC_BRK64 // if BRK64
Sandeepa Prabhuee6214c2013-12-04 05:50:20 +0000504 cinc x24, x24, eq // set bit '0'
Catalin Marinas60ffc302012-03-05 11:49:27 +0000505 tbz x24, #0, el1_inv // EL1 only
506 mrs x0, far_el1
507 mov x2, sp // struct pt_regs
508 bl do_debug_exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000509 kernel_exit 1
510el1_inv:
511 // TODO: add support for undefined instructions in kernel mode
Will Deacon2a283072014-04-29 19:04:06 +0100512 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000513 mov x0, sp
Mark Rutland1b428042015-07-07 18:00:49 +0100514 mov x2, x1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000515 mov x1, #BAD_SYNC
Catalin Marinas60ffc302012-03-05 11:49:27 +0000516 b bad_mode
517ENDPROC(el1_sync)
518
519 .align 6
520el1_irq:
521 kernel_entry 1
Will Deacon2a283072014-04-29 19:04:06 +0100522 enable_dbg
Catalin Marinas60ffc302012-03-05 11:49:27 +0000523#ifdef CONFIG_TRACE_IRQFLAGS
524 bl trace_hardirqs_off
525#endif
Marc Zyngier64681782013-11-12 17:11:53 +0000526
527 irq_handler
528
Catalin Marinas60ffc302012-03-05 11:49:27 +0000529#ifdef CONFIG_PREEMPT
Neil Zhang883c0572014-01-13 08:57:56 +0000530 ldr w24, [tsk, #TI_PREEMPT] // get preempt count
Marc Zyngier717321f2013-11-04 20:14:58 +0000531 cbnz w24, 1f // preempt count != 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000532 ldr x0, [tsk, #TI_FLAGS] // get flags
533 tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
534 bl el1_preempt
5351:
536#endif
537#ifdef CONFIG_TRACE_IRQFLAGS
538 bl trace_hardirqs_on
539#endif
540 kernel_exit 1
541ENDPROC(el1_irq)
542
543#ifdef CONFIG_PREEMPT
544el1_preempt:
545 mov x24, lr
Will Deacon2a283072014-04-29 19:04:06 +01005461: bl preempt_schedule_irq // irq en/disable is done inside
Catalin Marinas60ffc302012-03-05 11:49:27 +0000547 ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
548 tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
549 ret x24
550#endif
551
552/*
553 * EL0 mode handlers.
554 */
555 .align 6
556el0_sync:
557 kernel_entry 0
558 mrs x25, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000559 lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class
560 cmp x24, #ESR_ELx_EC_SVC64 // SVC in 64-bit state
Catalin Marinas60ffc302012-03-05 11:49:27 +0000561 b.eq el0_svc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000562 cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000563 b.eq el0_da
Mark Rutlandaed40e02014-11-24 12:31:40 +0000564 cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000565 b.eq el0_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000566 cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access
Catalin Marinas60ffc302012-03-05 11:49:27 +0000567 b.eq el0_fpsimd_acc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000568 cmp x24, #ESR_ELx_EC_FP_EXC64 // FP/ASIMD exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000569 b.eq el0_fpsimd_exc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000570 cmp x24, #ESR_ELx_EC_SYS64 // configurable trap
Andre Przywara7dd01ae2016-06-28 18:07:32 +0100571 b.eq el0_sys
Mark Rutlandaed40e02014-11-24 12:31:40 +0000572 cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000573 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000574 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000575 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000576 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000577 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000578 cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000579 b.ge el0_dbg
580 b el0_inv
581
582#ifdef CONFIG_COMPAT
583 .align 6
584el0_sync_compat:
585 kernel_entry 0, 32
586 mrs x25, esr_el1 // read the syndrome register
Mark Rutlandaed40e02014-11-24 12:31:40 +0000587 lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class
588 cmp x24, #ESR_ELx_EC_SVC32 // SVC in 32-bit state
Catalin Marinas60ffc302012-03-05 11:49:27 +0000589 b.eq el0_svc_compat
Mark Rutlandaed40e02014-11-24 12:31:40 +0000590 cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000591 b.eq el0_da
Mark Rutlandaed40e02014-11-24 12:31:40 +0000592 cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000593 b.eq el0_ia
Mark Rutlandaed40e02014-11-24 12:31:40 +0000594 cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access
Catalin Marinas60ffc302012-03-05 11:49:27 +0000595 b.eq el0_fpsimd_acc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000596 cmp x24, #ESR_ELx_EC_FP_EXC32 // FP/ASIMD exception
Catalin Marinas60ffc302012-03-05 11:49:27 +0000597 b.eq el0_fpsimd_exc
Mark Salyzyn77f3228f2015-10-13 14:30:51 -0700598 cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception
599 b.eq el0_sp_pc
Mark Rutlandaed40e02014-11-24 12:31:40 +0000600 cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000601 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000602 cmp x24, #ESR_ELx_EC_CP15_32 // CP15 MRC/MCR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100603 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000604 cmp x24, #ESR_ELx_EC_CP15_64 // CP15 MRRC/MCRR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100605 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000606 cmp x24, #ESR_ELx_EC_CP14_MR // CP14 MRC/MCR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100607 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000608 cmp x24, #ESR_ELx_EC_CP14_LS // CP14 LDC/STC trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100609 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000610 cmp x24, #ESR_ELx_EC_CP14_64 // CP14 MRRC/MCRR trap
Mark Rutland381cc2b2013-05-24 12:02:35 +0100611 b.eq el0_undef
Mark Rutlandaed40e02014-11-24 12:31:40 +0000612 cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000613 b.ge el0_dbg
614 b el0_inv
615el0_svc_compat:
616 /*
617 * AArch32 syscall handling
618 */
Catalin Marinas01564112015-01-06 16:42:32 +0000619 adrp stbl, compat_sys_call_table // load compat syscall table pointer
Catalin Marinas60ffc302012-03-05 11:49:27 +0000620 uxtw scno, w7 // syscall number in w7 (r7)
621 mov sc_nr, #__NR_compat_syscalls
622 b el0_svc_naked
623
624 .align 6
625el0_irq_compat:
626 kernel_entry 0, 32
627 b el0_irq_naked
628#endif
629
630el0_da:
631 /*
632 * Data abort handling
633 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100634 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000635 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100636 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700637 ct_user_exit
Kristina Martsenko9e09d902017-06-06 20:14:10 +0100638 clear_address_tag x0, x26
Catalin Marinas60ffc302012-03-05 11:49:27 +0000639 mov x1, x25
640 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100641 bl do_mem_abort
642 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000643el0_ia:
644 /*
645 * Instruction abort handling
646 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100647 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000648 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100649 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700650 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100651 mov x0, x26
Mark Rutland541ec872016-05-31 12:33:03 +0100652 mov x1, x25
Catalin Marinas60ffc302012-03-05 11:49:27 +0000653 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100654 bl do_mem_abort
655 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000656el0_fpsimd_acc:
657 /*
658 * Floating Point or Advanced SIMD access
659 */
Will Deacon2a283072014-04-29 19:04:06 +0100660 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700661 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000662 mov x0, x25
663 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100664 bl do_fpsimd_acc
665 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000666el0_fpsimd_exc:
667 /*
668 * Floating Point or Advanced SIMD exception
669 */
Will Deacon2a283072014-04-29 19:04:06 +0100670 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700671 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000672 mov x0, x25
673 mov x1, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100674 bl do_fpsimd_exc
675 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000676el0_sp_pc:
677 /*
678 * Stack or PC alignment exception handling
679 */
Larry Bassel6ab64632014-05-30 20:34:14 +0100680 mrs x26, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000681 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100682 enable_dbg_and_irq
Mark Rutland46b05672015-06-15 16:40:27 +0100683 ct_user_exit
Larry Bassel6ab64632014-05-30 20:34:14 +0100684 mov x0, x26
Catalin Marinas60ffc302012-03-05 11:49:27 +0000685 mov x1, x25
686 mov x2, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100687 bl do_sp_pc_abort
688 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000689el0_undef:
690 /*
691 * Undefined instruction
692 */
Catalin Marinas2600e132013-08-22 11:47:37 +0100693 // enable interrupts before calling the main handler
Will Deacon2a283072014-04-29 19:04:06 +0100694 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700695 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100696 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100697 bl do_undefinstr
698 b ret_to_user
Andre Przywara7dd01ae2016-06-28 18:07:32 +0100699el0_sys:
700 /*
701 * System instructions, for trapped cache maintenance instructions
702 */
703 enable_dbg_and_irq
704 ct_user_exit
705 mov x0, x25
706 mov x1, sp
707 bl do_sysinstr
708 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000709el0_dbg:
710 /*
711 * Debug exception handling
712 */
713 tbnz x24, #0, el0_inv // EL0 only
714 mrs x0, far_el1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000715 mov x1, x25
716 mov x2, sp
Will Deacon2a283072014-04-29 19:04:06 +0100717 bl do_debug_exception
718 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700719 ct_user_exit
Will Deacon2a283072014-04-29 19:04:06 +0100720 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000721el0_inv:
Will Deacon2a283072014-04-29 19:04:06 +0100722 enable_dbg
Larry Bassel6c81fe72014-05-30 12:34:15 -0700723 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000724 mov x0, sp
725 mov x1, #BAD_SYNC
Mark Rutland1b428042015-07-07 18:00:49 +0100726 mov x2, x25
Mark Rutlandde327942017-01-18 17:23:41 +0000727 bl bad_el0_sync
Will Deacond54e81f2014-09-29 11:44:01 +0100728 b ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000729ENDPROC(el0_sync)
730
731 .align 6
732el0_irq:
733 kernel_entry 0
734el0_irq_naked:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000735 enable_dbg
736#ifdef CONFIG_TRACE_IRQFLAGS
737 bl trace_hardirqs_off
738#endif
Marc Zyngier64681782013-11-12 17:11:53 +0000739
Larry Bassel6c81fe72014-05-30 12:34:15 -0700740 ct_user_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000741 irq_handler
Marc Zyngier64681782013-11-12 17:11:53 +0000742
Catalin Marinas60ffc302012-03-05 11:49:27 +0000743#ifdef CONFIG_TRACE_IRQFLAGS
744 bl trace_hardirqs_on
745#endif
746 b ret_to_user
747ENDPROC(el0_irq)
748
749/*
Catalin Marinas60ffc302012-03-05 11:49:27 +0000750 * Register switch for AArch64. The callee-saved registers need to be saved
751 * and restored. On entry:
752 * x0 = previous task_struct (must be preserved across the switch)
753 * x1 = next task_struct
754 * Previous and next are guaranteed not to be the same.
755 *
756 */
757ENTRY(cpu_switch_to)
Will Deaconc0d3fce2015-07-20 15:14:53 +0100758 mov x10, #THREAD_CPU_CONTEXT
759 add x8, x0, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000760 mov x9, sp
761 stp x19, x20, [x8], #16 // store callee-saved registers
762 stp x21, x22, [x8], #16
763 stp x23, x24, [x8], #16
764 stp x25, x26, [x8], #16
765 stp x27, x28, [x8], #16
766 stp x29, x9, [x8], #16
767 str lr, [x8]
Will Deaconc0d3fce2015-07-20 15:14:53 +0100768 add x8, x1, x10
Catalin Marinas60ffc302012-03-05 11:49:27 +0000769 ldp x19, x20, [x8], #16 // restore callee-saved registers
770 ldp x21, x22, [x8], #16
771 ldp x23, x24, [x8], #16
772 ldp x25, x26, [x8], #16
773 ldp x27, x28, [x8], #16
774 ldp x29, x9, [x8], #16
775 ldr lr, [x8]
776 mov sp, x9
Jungseok Lee6cdf9c72015-12-04 11:02:25 +0000777 and x9, x9, #~(THREAD_SIZE - 1)
778 msr sp_el0, x9
Catalin Marinas60ffc302012-03-05 11:49:27 +0000779 ret
780ENDPROC(cpu_switch_to)
781
782/*
783 * This is the fast syscall return path. We do as little as possible here,
784 * and this includes saving x0 back into the kernel stack.
785 */
786ret_fast_syscall:
787 disable_irq // disable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100788 str x0, [sp, #S_X0] // returned x0
Josh Stone04d7e092015-06-05 14:28:03 -0700789 ldr x1, [tsk, #TI_FLAGS] // re-check for syscall tracing
790 and x2, x1, #_TIF_SYSCALL_WORK
791 cbnz x2, ret_fast_syscall_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000792 and x2, x1, #_TIF_WORK_MASK
Will Deacon412fcb62015-08-19 15:57:09 +0100793 cbnz x2, work_pending
Will Deacon2a283072014-04-29 19:04:06 +0100794 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100795 kernel_exit 0
Josh Stone04d7e092015-06-05 14:28:03 -0700796ret_fast_syscall_trace:
797 enable_irq // enable interrupts
Will Deacon412fcb62015-08-19 15:57:09 +0100798 b __sys_trace_return_skipped // we already saved x0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000799
800/*
801 * Ok, we need to do extra processing, enter the slow path.
802 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000803work_pending:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000804 mov x0, sp // 'regs'
Catalin Marinas60ffc302012-03-05 11:49:27 +0000805 bl do_notify_resume
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000806#ifdef CONFIG_TRACE_IRQFLAGS
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400807 bl trace_hardirqs_on // enabled while in userspace
Catalin Marinasdb3899a2015-12-04 12:42:29 +0000808#endif
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400809 ldr x1, [tsk, #TI_FLAGS] // re-check for single-step
810 b finish_ret_to_user
Catalin Marinas60ffc302012-03-05 11:49:27 +0000811/*
812 * "slow" syscall return path.
813 */
Catalin Marinas59dc67b2012-09-10 16:11:46 +0100814ret_to_user:
Catalin Marinas60ffc302012-03-05 11:49:27 +0000815 disable_irq // disable interrupts
816 ldr x1, [tsk, #TI_FLAGS]
817 and x2, x1, #_TIF_WORK_MASK
818 cbnz x2, work_pending
Chris Metcalf421dd6f2016-07-14 16:48:14 -0400819finish_ret_to_user:
Will Deacon2a283072014-04-29 19:04:06 +0100820 enable_step_tsk x1, x2
Will Deacon412fcb62015-08-19 15:57:09 +0100821 kernel_exit 0
Catalin Marinas60ffc302012-03-05 11:49:27 +0000822ENDPROC(ret_to_user)
823
824/*
825 * This is how we return from a fork.
826 */
827ENTRY(ret_from_fork)
828 bl schedule_tail
Catalin Marinasc34501d2012-10-05 12:31:20 +0100829 cbz x19, 1f // not a kernel thread
830 mov x0, x20
831 blr x19
8321: get_thread_info tsk
Catalin Marinas60ffc302012-03-05 11:49:27 +0000833 b ret_to_user
834ENDPROC(ret_from_fork)
835
836/*
837 * SVC handler.
838 */
839 .align 6
840el0_svc:
841 adrp stbl, sys_call_table // load syscall table pointer
842 uxtw scno, w8 // syscall number in w8
843 mov sc_nr, #__NR_syscalls
844el0_svc_naked: // compat entry point
845 stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number
Will Deacon2a283072014-04-29 19:04:06 +0100846 enable_dbg_and_irq
Larry Bassel6c81fe72014-05-30 12:34:15 -0700847 ct_user_exit 1
Catalin Marinas60ffc302012-03-05 11:49:27 +0000848
AKASHI Takahiro449f81a2014-04-30 10:51:29 +0100849 ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks
850 tst x16, #_TIF_SYSCALL_WORK
851 b.ne __sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000852 cmp scno, sc_nr // check upper syscall limit
853 b.hs ni_sys
854 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100855 blr x16 // call sys_* routine
856 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000857ni_sys:
858 mov x0, sp
Will Deacond54e81f2014-09-29 11:44:01 +0100859 bl do_ni_syscall
860 b ret_fast_syscall
Catalin Marinas60ffc302012-03-05 11:49:27 +0000861ENDPROC(el0_svc)
862
863 /*
864 * This is the really slow path. We're going to be doing context
865 * switches, and waiting for our parent to respond.
866 */
867__sys_trace:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000868 mov w0, #-1 // set default errno for
869 cmp scno, x0 // user-issued syscall(-1)
870 b.ne 1f
871 mov x0, #-ENOSYS
872 str x0, [sp, #S_X0]
8731: mov x0, sp
AKASHI Takahiro31578582014-04-30 10:51:30 +0100874 bl syscall_trace_enter
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000875 cmp w0, #-1 // skip the syscall?
876 b.eq __sys_trace_return_skipped
Catalin Marinas60ffc302012-03-05 11:49:27 +0000877 uxtw scno, w0 // syscall number (possibly new)
878 mov x1, sp // pointer to regs
879 cmp scno, sc_nr // check upper syscall limit
Will Deacond54e81f2014-09-29 11:44:01 +0100880 b.hs __ni_sys_trace
Catalin Marinas60ffc302012-03-05 11:49:27 +0000881 ldp x0, x1, [sp] // restore the syscall args
882 ldp x2, x3, [sp, #S_X2]
883 ldp x4, x5, [sp, #S_X4]
884 ldp x6, x7, [sp, #S_X6]
885 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
Will Deacond54e81f2014-09-29 11:44:01 +0100886 blr x16 // call sys_* routine
Catalin Marinas60ffc302012-03-05 11:49:27 +0000887
888__sys_trace_return:
AKASHI Takahiro1014c812014-11-28 05:26:35 +0000889 str x0, [sp, #S_X0] // save returned x0
890__sys_trace_return_skipped:
AKASHI Takahiro31578582014-04-30 10:51:30 +0100891 mov x0, sp
892 bl syscall_trace_exit
Catalin Marinas60ffc302012-03-05 11:49:27 +0000893 b ret_to_user
894
Will Deacond54e81f2014-09-29 11:44:01 +0100895__ni_sys_trace:
896 mov x0, sp
897 bl do_ni_syscall
898 b __sys_trace_return
899
Pratyush Anand888b3c82016-07-08 12:35:50 -0400900 .popsection // .entry.text
901
Will Deacona329b062017-11-14 14:07:40 +0000902#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
903/*
904 * Exception vectors trampoline.
905 */
906 .pushsection ".entry.tramp.text", "ax"
907
908 .macro tramp_map_kernel, tmp
909 mrs \tmp, ttbr1_el1
910 sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
911 bic \tmp, \tmp, #USER_ASID_FLAG
912 msr ttbr1_el1, \tmp
Will Deacon04b77fe2017-11-14 14:29:19 +0000913#ifdef CONFIG_ARCH_MSM8996
914 /* ASID already in \tmp[63:48] */
915 movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12)
916 movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12)
917 /* 2MB boundary containing the vectors, so we nobble the walk cache */
918 movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12)
919 isb
920 tlbi vae1, \tmp
921 dsb nsh
922#endif /* CONFIG_ARCH_MSM8996 */
Will Deacona329b062017-11-14 14:07:40 +0000923 .endm
924
925 .macro tramp_unmap_kernel, tmp
926 mrs \tmp, ttbr1_el1
927 add \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE)
928 orr \tmp, \tmp, #USER_ASID_FLAG
929 msr ttbr1_el1, \tmp
930 /*
931 * We avoid running the post_ttbr_update_workaround here because the
932 * user and kernel ASIDs don't have conflicting mappings, so any
933 * "blessing" as described in:
934 *
935 * http://lkml.kernel.org/r/56BB848A.6060603@caviumnetworks.com
936 *
937 * will not hurt correctness. Whilst this may partially defeat the
938 * point of using split ASIDs in the first place, it avoids
939 * the hit of invalidating the entire I-cache on every return to
940 * userspace.
941 */
942 .endm
943
944 .macro tramp_ventry, regsize = 64
945 .align 7
9461:
947 .if \regsize == 64
948 msr tpidrro_el0, x30 // Restored in kernel_ventry
949 .endif
950 tramp_map_kernel x30
951 ldr x30, =vectors
952 prfm plil1strm, [x30, #(1b - tramp_vectors)]
953 msr vbar_el1, x30
954 add x30, x30, #(1b - tramp_vectors)
955 isb
956 br x30
957 .endm
958
959 .macro tramp_exit, regsize = 64
960 adr x30, tramp_vectors
961 msr vbar_el1, x30
962 tramp_unmap_kernel x30
963 .if \regsize == 64
964 mrs x30, far_el1
965 .endif
966 eret
967 .endm
968
969 .align 11
970ENTRY(tramp_vectors)
971 .space 0x400
972
973 tramp_ventry
974 tramp_ventry
975 tramp_ventry
976 tramp_ventry
977
978 tramp_ventry 32
979 tramp_ventry 32
980 tramp_ventry 32
981 tramp_ventry 32
982END(tramp_vectors)
983
984ENTRY(tramp_exit_native)
985 tramp_exit
986END(tramp_exit_native)
987
988ENTRY(tramp_exit_compat)
989 tramp_exit 32
990END(tramp_exit_compat)
991
992 .ltorg
993 .popsection // .entry.tramp.text
994#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
995
Catalin Marinas60ffc302012-03-05 11:49:27 +0000996/*
997 * Special system call wrappers.
998 */
Catalin Marinas60ffc302012-03-05 11:49:27 +0000999ENTRY(sys_rt_sigreturn_wrapper)
1000 mov x0, sp
1001 b sys_rt_sigreturn
1002ENDPROC(sys_rt_sigreturn_wrapper)