Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 1 | /* |
| 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 Zyngier | 8d883b2 | 2015-06-01 10:47:41 +0100 | [diff] [blame] | 24 | #include <asm/alternative.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 25 | #include <asm/assembler.h> |
| 26 | #include <asm/asm-offsets.h> |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 27 | #include <asm/cpufeature.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 28 | #include <asm/errno.h> |
Marc Zyngier | 5c1ce6f | 2013-04-08 17:17:03 +0100 | [diff] [blame] | 29 | #include <asm/esr.h> |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 30 | #include <asm/irq.h> |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 31 | #include <asm/memory.h> |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 32 | #include <asm/mmu.h> |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 33 | #include <asm/ptrace.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 34 | #include <asm/thread_info.h> |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 35 | #include <asm/uaccess.h> |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 36 | #include <asm/asm-uaccess.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 37 | #include <asm/unistd.h> |
| 38 | |
| 39 | /* |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 40 | * 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 66 | * 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 Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 74 | .macro kernel_ventry, el, label, regsize = 64 |
Mark Rutland | d96bee9 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 75 | .align 7 |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
Will Deacon | a710723 | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 77 | alternative_if ARM64_UNMAP_KERNEL_AT_EL0 |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 78 | .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 Deacon | a710723 | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 86 | alternative_else_nop_endif |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 89 | sub sp, sp, #S_FRAME_SIZE |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 90 | b el\()\el\()_\label |
Mark Rutland | d96bee9 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 91 | .endm |
| 92 | |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 93 | .macro tramp_alias, dst, sym |
| 94 | mov_q \dst, TRAMP_VALIAS |
| 95 | add \dst, \dst, #(\sym - .entry.tramp.text) |
| 96 | .endm |
| 97 | |
Mark Rutland | d96bee9 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 98 | .macro kernel_entry, el, regsize = 64 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 99 | .if \regsize == 32 |
| 100 | mov w0, w0 // zero upper 32 bits of x0 |
| 101 | .endif |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 102 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 118 | .if \el == 0 |
| 119 | mrs x21, sp_el0 |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 120 | 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 Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 122 | disable_step_tsk x19, x20 // exceptions when scheduling. |
James Morse | 49003a8 | 2015-12-10 10:22:41 +0000 | [diff] [blame] | 123 | |
| 124 | mov x29, xzr // fp pointed to user-space |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 125 | .else |
| 126 | add x21, sp, #S_FRAME_SIZE |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 127 | get_thread_info tsk |
| 128 | /* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */ |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 129 | ldr x20, [tsk, #TSK_TI_ADDR_LIMIT] |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 130 | str x20, [sp, #S_ORIG_ADDR_LIMIT] |
| 131 | mov x20, #TASK_SIZE_64 |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 132 | str x20, [tsk, #TSK_TI_ADDR_LIMIT] |
Vladimir Murzin | 563cada | 2016-09-01 14:35:59 +0100 | [diff] [blame] | 133 | /* No need to reset PSTATE.UAO, hardware's already set it to 0 for us */ |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 134 | .endif /* \el == 0 */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 135 | mrs x22, elr_el1 |
| 136 | mrs x23, spsr_el1 |
| 137 | stp lr, x21, [sp, #S_LR] |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 138 | |
| 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 | */ |
| 148 | alternative_if ARM64_HAS_PAN |
| 149 | b 1f // skip TTBR0 PAN |
| 150 | alternative_else_nop_endif |
| 151 | |
| 152 | .if \el != 0 |
Catalin Marinas | 874f778 | 2018-01-10 13:18:30 +0000 | [diff] [blame] | 153 | mrs x21, ttbr0_el1 |
Will Deacon | 4345a53 | 2017-12-01 17:33:48 +0000 | [diff] [blame] | 154 | tst x21, #TTBR_ASID_MASK // Check for the reserved ASID |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 155 | 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 |
| 161 | 1: |
| 162 | #endif |
| 163 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 164 | 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 Lee | 6cdf9c7 | 2015-12-04 11:02:25 +0000 | [diff] [blame] | 175 | * Set sp_el0 to current thread_info. |
| 176 | */ |
| 177 | .if \el == 0 |
| 178 | msr sp_el0, tsk |
| 179 | .endif |
| 180 | |
| 181 | /* |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 182 | * 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 Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 190 | .macro kernel_exit, el |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 191 | .if \el != 0 |
| 192 | /* Restore the task's original addr_limit. */ |
| 193 | ldr x20, [sp, #S_ORIG_ADDR_LIMIT] |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 194 | str x20, [tsk, #TSK_TI_ADDR_LIMIT] |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 195 | |
| 196 | /* No need to restore UAO, it will be restored from SPSR_EL1 */ |
| 197 | .endif |
| 198 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 199 | ldp x21, x22, [sp, #S_PC] // load ELR, SPSR |
| 200 | .if \el == 0 |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 201 | ct_user_enter |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 202 | .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 | */ |
| 209 | alternative_if ARM64_HAS_PAN |
| 210 | b 2f // skip TTBR0 PAN |
| 211 | alternative_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 Deacon | f7aa82e | 2017-08-10 13:58:16 +0100 | [diff] [blame] | 217 | __uaccess_ttbr0_enable x0, x1 |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 218 | |
| 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 Zyngier | 18773dc | 2018-01-02 18:19:39 +0000 | [diff] [blame] | 226 | bl post_ttbr_update_workaround |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 227 | .endif |
| 228 | 1: |
| 229 | .if \el != 0 |
| 230 | and x22, x22, #~PSR_PAN_BIT // ARMv8.0 CPUs do not understand this bit |
| 231 | .endif |
| 232 | 2: |
| 233 | #endif |
| 234 | |
| 235 | .if \el == 0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 236 | ldr x23, [sp, #S_SP] // load return stack pointer |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 237 | msr sp_el0, x23 |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 238 | tst x22, #PSR_MODE32_BIT // native task? |
| 239 | b.eq 3f |
| 240 | |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 241 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
Mark Rutland | 6ba3b55 | 2016-09-07 11:07:09 +0100 | [diff] [blame] | 242 | alternative_if ARM64_WORKAROUND_845719 |
Daniel Thompson | e28cabf | 2015-07-22 12:21:03 +0100 | [diff] [blame] | 243 | #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 Rutland | 6ba3b55 | 2016-09-07 11:07:09 +0100 | [diff] [blame] | 249 | alternative_else_nop_endif |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 250 | #endif |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 251 | 3: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 252 | .endif |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 253 | |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 254 | msr elr_el1, x21 // set up the return data |
| 255 | msr spsr_el1, x22 |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 256 | ldp x0, x1, [sp, #16 * 0] |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 257 | 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 Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 273 | |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 274 | .if \el == 0 |
Will Deacon | a710723 | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 275 | alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 |
| 276 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 277 | bne 4f |
| 278 | msr far_el1, x30 |
| 279 | tramp_alias x30, tramp_exit_native |
| 280 | br x30 |
| 281 | 4: |
| 282 | tramp_alias x30, tramp_exit_compat |
| 283 | br x30 |
Will Deacon | a710723 | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 284 | #endif |
Will Deacon | 2d341da | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 285 | .else |
| 286 | eret |
| 287 | .endif |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 288 | .endm |
| 289 | |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 290 | .macro irq_stack_entry |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 291 | mov x19, sp // preserve the original sp |
| 292 | |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 293 | /* |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 294 | * 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 Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 297 | */ |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 298 | ldr x25, [tsk, TSK_STACK] |
| 299 | eor x25, x25, x19 |
| 300 | and x25, x25, #~(THREAD_SIZE - 1) |
| 301 | cbnz x25, 9998f |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 302 | |
Mark Rutland | 2f604aa | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 303 | adr_this_cpu x25, irq_stack, x26 |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 304 | mov x26, #IRQ_STACK_START_SP |
| 305 | add x26, x25, x26 |
James Morse | d224a69 | 2015-12-18 16:01:47 +0000 | [diff] [blame] | 306 | |
| 307 | /* switch to the irq stack */ |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 308 | mov sp, x26 |
| 309 | |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 310 | /* |
| 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 Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 315 | mov x29, sp |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 316 | |
| 317 | 9998: |
| 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 328 | /* |
| 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 | */ |
| 334 | sc_nr .req x25 // number of system calls |
| 335 | scno .req x26 // syscall number |
| 336 | stbl .req x27 // syscall table pointer |
| 337 | tsk .req x28 // current thread_info |
| 338 | |
| 339 | /* |
| 340 | * Interrupt handling. |
| 341 | */ |
| 342 | .macro irq_handler |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 343 | ldr_l x1, handle_arch_irq |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 344 | mov x0, sp |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 345 | irq_stack_entry |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 346 | blr x1 |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 347 | irq_stack_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 348 | .endm |
| 349 | |
| 350 | .text |
| 351 | |
| 352 | /* |
| 353 | * Exception vectors. |
| 354 | */ |
Pratyush Anand | 888b3c8 | 2016-07-08 12:35:50 -0400 | [diff] [blame] | 355 | .pushsection ".entry.text", "ax" |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 356 | |
| 357 | .align 11 |
| 358 | ENTRY(vectors) |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 359 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 363 | |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 364 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 368 | |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 369 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 373 | |
| 374 | #ifdef CONFIG_COMPAT |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 375 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 379 | #else |
Will Deacon | 8f261a6 | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 380 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 384 | #endif |
| 385 | END(vectors) |
| 386 | |
| 387 | /* |
| 388 | * Invalid mode handlers |
| 389 | */ |
| 390 | .macro inv_entry, el, reason, regsize = 64 |
Ard Biesheuvel | b660950 | 2016-03-18 10:58:09 +0100 | [diff] [blame] | 391 | kernel_entry \el, \regsize |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 392 | mov x0, sp |
| 393 | mov x1, #\reason |
| 394 | mrs x2, esr_el1 |
| 395 | b bad_mode |
| 396 | .endm |
| 397 | |
| 398 | el0_sync_invalid: |
| 399 | inv_entry 0, BAD_SYNC |
| 400 | ENDPROC(el0_sync_invalid) |
| 401 | |
| 402 | el0_irq_invalid: |
| 403 | inv_entry 0, BAD_IRQ |
| 404 | ENDPROC(el0_irq_invalid) |
| 405 | |
| 406 | el0_fiq_invalid: |
| 407 | inv_entry 0, BAD_FIQ |
| 408 | ENDPROC(el0_fiq_invalid) |
| 409 | |
| 410 | el0_error_invalid: |
| 411 | inv_entry 0, BAD_ERROR |
| 412 | ENDPROC(el0_error_invalid) |
| 413 | |
| 414 | #ifdef CONFIG_COMPAT |
| 415 | el0_fiq_invalid_compat: |
| 416 | inv_entry 0, BAD_FIQ, 32 |
| 417 | ENDPROC(el0_fiq_invalid_compat) |
| 418 | |
| 419 | el0_error_invalid_compat: |
| 420 | inv_entry 0, BAD_ERROR, 32 |
| 421 | ENDPROC(el0_error_invalid_compat) |
| 422 | #endif |
| 423 | |
| 424 | el1_sync_invalid: |
| 425 | inv_entry 1, BAD_SYNC |
| 426 | ENDPROC(el1_sync_invalid) |
| 427 | |
| 428 | el1_irq_invalid: |
| 429 | inv_entry 1, BAD_IRQ |
| 430 | ENDPROC(el1_irq_invalid) |
| 431 | |
| 432 | el1_fiq_invalid: |
| 433 | inv_entry 1, BAD_FIQ |
| 434 | ENDPROC(el1_fiq_invalid) |
| 435 | |
| 436 | el1_error_invalid: |
| 437 | inv_entry 1, BAD_ERROR |
| 438 | ENDPROC(el1_error_invalid) |
| 439 | |
| 440 | /* |
| 441 | * EL1 mode handlers. |
| 442 | */ |
| 443 | .align 6 |
| 444 | el1_sync: |
| 445 | kernel_entry 1 |
| 446 | mrs x1, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 447 | lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class |
| 448 | cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 449 | b.eq el1_da |
Laura Abbott | 9adeb8e | 2016-08-09 18:25:26 -0700 | [diff] [blame] | 450 | cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1 |
| 451 | b.eq el1_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 452 | cmp x24, #ESR_ELx_EC_SYS64 // configurable trap |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 453 | b.eq el1_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 454 | cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 455 | b.eq el1_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 456 | cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 457 | b.eq el1_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 458 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 459 | b.eq el1_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 460 | cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 461 | b.ge el1_dbg |
| 462 | b el1_inv |
Laura Abbott | 9adeb8e | 2016-08-09 18:25:26 -0700 | [diff] [blame] | 463 | |
| 464 | el1_ia: |
| 465 | /* |
| 466 | * Fall through to the Data abort case |
| 467 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 468 | el1_da: |
| 469 | /* |
| 470 | * Data abort handling |
| 471 | */ |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 472 | mrs x3, far_el1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 473 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 474 | // re-enable interrupts if they were enabled in the aborted context |
| 475 | tbnz x23, #7, 1f // PSR_I_BIT |
| 476 | enable_irq |
| 477 | 1: |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 478 | clear_address_tag x0, x3 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 479 | 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 |
| 485 | el1_sp_pc: |
| 486 | /* |
| 487 | * Stack or PC alignment exception handling |
| 488 | */ |
| 489 | mrs x0, far_el1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 490 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 491 | mov x2, sp |
| 492 | b do_sp_pc_abort |
| 493 | el1_undef: |
| 494 | /* |
| 495 | * Undefined instruction |
| 496 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 497 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 498 | mov x0, sp |
| 499 | b do_undefinstr |
| 500 | el1_dbg: |
| 501 | /* |
| 502 | * Debug exception handling |
| 503 | */ |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 504 | cmp x24, #ESR_ELx_EC_BRK64 // if BRK64 |
Sandeepa Prabhu | ee6214c | 2013-12-04 05:50:20 +0000 | [diff] [blame] | 505 | cinc x24, x24, eq // set bit '0' |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 506 | 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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 510 | kernel_exit 1 |
| 511 | el1_inv: |
| 512 | // TODO: add support for undefined instructions in kernel mode |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 513 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 514 | mov x0, sp |
Mark Rutland | 1b42804 | 2015-07-07 18:00:49 +0100 | [diff] [blame] | 515 | mov x2, x1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 516 | mov x1, #BAD_SYNC |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 517 | b bad_mode |
| 518 | ENDPROC(el1_sync) |
| 519 | |
| 520 | .align 6 |
| 521 | el1_irq: |
| 522 | kernel_entry 1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 523 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 524 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 525 | bl trace_hardirqs_off |
| 526 | #endif |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 527 | |
| 528 | irq_handler |
| 529 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 530 | #ifdef CONFIG_PREEMPT |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 531 | ldr w24, [tsk, #TSK_TI_PREEMPT] // get preempt count |
Marc Zyngier | 717321f | 2013-11-04 20:14:58 +0000 | [diff] [blame] | 532 | cbnz w24, 1f // preempt count != 0 |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 533 | ldr x0, [tsk, #TSK_TI_FLAGS] // get flags |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 534 | tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling? |
| 535 | bl el1_preempt |
| 536 | 1: |
| 537 | #endif |
| 538 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 539 | bl trace_hardirqs_on |
| 540 | #endif |
| 541 | kernel_exit 1 |
| 542 | ENDPROC(el1_irq) |
| 543 | |
| 544 | #ifdef CONFIG_PREEMPT |
| 545 | el1_preempt: |
| 546 | mov x24, lr |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 547 | 1: bl preempt_schedule_irq // irq en/disable is done inside |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 548 | ldr x0, [tsk, #TSK_TI_FLAGS] // get new tasks TI_FLAGS |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 549 | tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling? |
| 550 | ret x24 |
| 551 | #endif |
| 552 | |
| 553 | /* |
| 554 | * EL0 mode handlers. |
| 555 | */ |
| 556 | .align 6 |
| 557 | el0_sync: |
| 558 | kernel_entry 0 |
| 559 | mrs x25, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 560 | lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class |
| 561 | cmp x24, #ESR_ELx_EC_SVC64 // SVC in 64-bit state |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 562 | b.eq el0_svc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 563 | cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 564 | b.eq el0_da |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 565 | cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 566 | b.eq el0_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 567 | cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 568 | b.eq el0_fpsimd_acc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 569 | cmp x24, #ESR_ELx_EC_FP_EXC64 // FP/ASIMD exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 570 | b.eq el0_fpsimd_exc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 571 | cmp x24, #ESR_ELx_EC_SYS64 // configurable trap |
Andre Przywara | 7dd01ae | 2016-06-28 18:07:32 +0100 | [diff] [blame] | 572 | b.eq el0_sys |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 573 | cmp x24, #ESR_ELx_EC_SP_ALIGN // stack alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 574 | b.eq el0_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 575 | cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 576 | b.eq el0_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 577 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 578 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 579 | cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 580 | b.ge el0_dbg |
| 581 | b el0_inv |
| 582 | |
| 583 | #ifdef CONFIG_COMPAT |
| 584 | .align 6 |
| 585 | el0_sync_compat: |
| 586 | kernel_entry 0, 32 |
| 587 | mrs x25, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 588 | lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class |
| 589 | cmp x24, #ESR_ELx_EC_SVC32 // SVC in 32-bit state |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 590 | b.eq el0_svc_compat |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 591 | cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 592 | b.eq el0_da |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 593 | cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 594 | b.eq el0_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 595 | cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 596 | b.eq el0_fpsimd_acc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 597 | cmp x24, #ESR_ELx_EC_FP_EXC32 // FP/ASIMD exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 598 | b.eq el0_fpsimd_exc |
Mark Salyzyn | 77f3228f | 2015-10-13 14:30:51 -0700 | [diff] [blame] | 599 | cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception |
| 600 | b.eq el0_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 601 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 602 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 603 | cmp x24, #ESR_ELx_EC_CP15_32 // CP15 MRC/MCR trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 604 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 605 | cmp x24, #ESR_ELx_EC_CP15_64 // CP15 MRRC/MCRR trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 606 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 607 | cmp x24, #ESR_ELx_EC_CP14_MR // CP14 MRC/MCR trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 608 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 609 | cmp x24, #ESR_ELx_EC_CP14_LS // CP14 LDC/STC trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 610 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 611 | cmp x24, #ESR_ELx_EC_CP14_64 // CP14 MRRC/MCRR trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 612 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 613 | cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 614 | b.ge el0_dbg |
| 615 | b el0_inv |
| 616 | el0_svc_compat: |
| 617 | /* |
| 618 | * AArch32 syscall handling |
| 619 | */ |
Catalin Marinas | 0156411 | 2015-01-06 16:42:32 +0000 | [diff] [blame] | 620 | adrp stbl, compat_sys_call_table // load compat syscall table pointer |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 621 | uxtw scno, w7 // syscall number in w7 (r7) |
| 622 | mov sc_nr, #__NR_compat_syscalls |
| 623 | b el0_svc_naked |
| 624 | |
| 625 | .align 6 |
| 626 | el0_irq_compat: |
| 627 | kernel_entry 0, 32 |
| 628 | b el0_irq_naked |
| 629 | #endif |
| 630 | |
| 631 | el0_da: |
| 632 | /* |
| 633 | * Data abort handling |
| 634 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 635 | mrs x26, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 636 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 637 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 638 | ct_user_exit |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 639 | clear_address_tag x0, x26 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 640 | mov x1, x25 |
| 641 | mov x2, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 642 | bl do_mem_abort |
| 643 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 644 | el0_ia: |
| 645 | /* |
| 646 | * Instruction abort handling |
| 647 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 648 | mrs x26, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 649 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 650 | enable_dbg_and_irq |
Will Deacon | 0f5bfbd | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 651 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 652 | bl trace_hardirqs_off |
| 653 | #endif |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 654 | ct_user_exit |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 655 | mov x0, x26 |
Mark Rutland | 541ec87 | 2016-05-31 12:33:03 +0100 | [diff] [blame] | 656 | mov x1, x25 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 657 | mov x2, sp |
Will Deacon | 0f5bfbd | 2018-01-03 11:17:58 +0000 | [diff] [blame] | 658 | bl do_el0_ia_bp_hardening |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 659 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 660 | el0_fpsimd_acc: |
| 661 | /* |
| 662 | * Floating Point or Advanced SIMD access |
| 663 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 664 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 665 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 666 | mov x0, x25 |
| 667 | mov x1, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 668 | bl do_fpsimd_acc |
| 669 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 670 | el0_fpsimd_exc: |
| 671 | /* |
| 672 | * Floating Point or Advanced SIMD exception |
| 673 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 674 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 675 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 676 | mov x0, x25 |
| 677 | mov x1, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 678 | bl do_fpsimd_exc |
| 679 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 680 | el0_sp_pc: |
| 681 | /* |
| 682 | * Stack or PC alignment exception handling |
| 683 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 684 | mrs x26, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 685 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 686 | enable_dbg_and_irq |
Mark Rutland | 46b0567 | 2015-06-15 16:40:27 +0100 | [diff] [blame] | 687 | ct_user_exit |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 688 | mov x0, x26 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 689 | mov x1, x25 |
| 690 | mov x2, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 691 | bl do_sp_pc_abort |
| 692 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 693 | el0_undef: |
| 694 | /* |
| 695 | * Undefined instruction |
| 696 | */ |
Catalin Marinas | 2600e13 | 2013-08-22 11:47:37 +0100 | [diff] [blame] | 697 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 698 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 699 | ct_user_exit |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 700 | mov x0, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 701 | bl do_undefinstr |
| 702 | b ret_to_user |
Andre Przywara | 7dd01ae | 2016-06-28 18:07:32 +0100 | [diff] [blame] | 703 | el0_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 Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 713 | el0_dbg: |
| 714 | /* |
| 715 | * Debug exception handling |
| 716 | */ |
| 717 | tbnz x24, #0, el0_inv // EL0 only |
| 718 | mrs x0, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 719 | mov x1, x25 |
| 720 | mov x2, sp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 721 | bl do_debug_exception |
| 722 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 723 | ct_user_exit |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 724 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 725 | el0_inv: |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 726 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 727 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 728 | mov x0, sp |
| 729 | mov x1, #BAD_SYNC |
Mark Rutland | 1b42804 | 2015-07-07 18:00:49 +0100 | [diff] [blame] | 730 | mov x2, x25 |
Mark Rutland | de32794 | 2017-01-18 17:23:41 +0000 | [diff] [blame] | 731 | bl bad_el0_sync |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 732 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 733 | ENDPROC(el0_sync) |
| 734 | |
| 735 | .align 6 |
| 736 | el0_irq: |
| 737 | kernel_entry 0 |
| 738 | el0_irq_naked: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 739 | enable_dbg |
| 740 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 741 | bl trace_hardirqs_off |
| 742 | #endif |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 743 | |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 744 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 745 | irq_handler |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 746 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 747 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 748 | bl trace_hardirqs_on |
| 749 | #endif |
| 750 | b ret_to_user |
| 751 | ENDPROC(el0_irq) |
| 752 | |
| 753 | /* |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 754 | * 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 | */ |
| 761 | ENTRY(cpu_switch_to) |
Will Deacon | c0d3fce | 2015-07-20 15:14:53 +0100 | [diff] [blame] | 762 | mov x10, #THREAD_CPU_CONTEXT |
| 763 | add x8, x0, x10 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 764 | 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 Deacon | c0d3fce | 2015-07-20 15:14:53 +0100 | [diff] [blame] | 772 | add x8, x1, x10 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 773 | 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 Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 781 | msr sp_el0, x1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 782 | ret |
| 783 | ENDPROC(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 | */ |
| 789 | ret_fast_syscall: |
| 790 | disable_irq // disable interrupts |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 791 | str x0, [sp, #S_X0] // returned x0 |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 792 | ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for syscall tracing |
Josh Stone | 04d7e09 | 2015-06-05 14:28:03 -0700 | [diff] [blame] | 793 | and x2, x1, #_TIF_SYSCALL_WORK |
| 794 | cbnz x2, ret_fast_syscall_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 795 | and x2, x1, #_TIF_WORK_MASK |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 796 | cbnz x2, work_pending |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 797 | enable_step_tsk x1, x2 |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 798 | kernel_exit 0 |
Josh Stone | 04d7e09 | 2015-06-05 14:28:03 -0700 | [diff] [blame] | 799 | ret_fast_syscall_trace: |
| 800 | enable_irq // enable interrupts |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 801 | b __sys_trace_return_skipped // we already saved x0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 802 | |
| 803 | /* |
| 804 | * Ok, we need to do extra processing, enter the slow path. |
| 805 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 806 | work_pending: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 807 | mov x0, sp // 'regs' |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 808 | bl do_notify_resume |
Catalin Marinas | db3899a | 2015-12-04 12:42:29 +0000 | [diff] [blame] | 809 | #ifdef CONFIG_TRACE_IRQFLAGS |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 810 | bl trace_hardirqs_on // enabled while in userspace |
Catalin Marinas | db3899a | 2015-12-04 12:42:29 +0000 | [diff] [blame] | 811 | #endif |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 812 | ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for single-step |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 813 | b finish_ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 814 | /* |
| 815 | * "slow" syscall return path. |
| 816 | */ |
Catalin Marinas | 59dc67b | 2012-09-10 16:11:46 +0100 | [diff] [blame] | 817 | ret_to_user: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 818 | disable_irq // disable interrupts |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 819 | ldr x1, [tsk, #TSK_TI_FLAGS] |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 820 | and x2, x1, #_TIF_WORK_MASK |
| 821 | cbnz x2, work_pending |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 822 | finish_ret_to_user: |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 823 | enable_step_tsk x1, x2 |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 824 | kernel_exit 0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 825 | ENDPROC(ret_to_user) |
| 826 | |
| 827 | /* |
| 828 | * This is how we return from a fork. |
| 829 | */ |
| 830 | ENTRY(ret_from_fork) |
| 831 | bl schedule_tail |
Catalin Marinas | c34501d | 2012-10-05 12:31:20 +0100 | [diff] [blame] | 832 | cbz x19, 1f // not a kernel thread |
| 833 | mov x0, x20 |
| 834 | blr x19 |
| 835 | 1: get_thread_info tsk |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 836 | b ret_to_user |
| 837 | ENDPROC(ret_from_fork) |
| 838 | |
| 839 | /* |
| 840 | * SVC handler. |
| 841 | */ |
| 842 | .align 6 |
| 843 | el0_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 |
| 847 | el0_svc_naked: // compat entry point |
| 848 | stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 849 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 850 | ct_user_exit 1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 851 | |
Mark Rutland | b51386b | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 852 | ldr x16, [tsk, #TSK_TI_FLAGS] // check for syscall hooks |
AKASHI Takahiro | 449f81a | 2014-04-30 10:51:29 +0100 | [diff] [blame] | 853 | tst x16, #_TIF_SYSCALL_WORK |
| 854 | b.ne __sys_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 855 | 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 Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 858 | blr x16 // call sys_* routine |
| 859 | b ret_fast_syscall |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 860 | ni_sys: |
| 861 | mov x0, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 862 | bl do_ni_syscall |
| 863 | b ret_fast_syscall |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 864 | ENDPROC(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 Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 871 | 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] |
| 876 | 1: mov x0, sp |
AKASHI Takahiro | 3157858 | 2014-04-30 10:51:30 +0100 | [diff] [blame] | 877 | bl syscall_trace_enter |
AKASHI Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 878 | cmp w0, #-1 // skip the syscall? |
| 879 | b.eq __sys_trace_return_skipped |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 880 | uxtw scno, w0 // syscall number (possibly new) |
| 881 | mov x1, sp // pointer to regs |
| 882 | cmp scno, sc_nr // check upper syscall limit |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 883 | b.hs __ni_sys_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 884 | 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 Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 889 | blr x16 // call sys_* routine |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 890 | |
| 891 | __sys_trace_return: |
AKASHI Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 892 | str x0, [sp, #S_X0] // save returned x0 |
| 893 | __sys_trace_return_skipped: |
AKASHI Takahiro | 3157858 | 2014-04-30 10:51:30 +0100 | [diff] [blame] | 894 | mov x0, sp |
| 895 | bl syscall_trace_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 896 | b ret_to_user |
| 897 | |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 898 | __ni_sys_trace: |
| 899 | mov x0, sp |
| 900 | bl do_ni_syscall |
| 901 | b __sys_trace_return |
| 902 | |
Pratyush Anand | 888b3c8 | 2016-07-08 12:35:50 -0400 | [diff] [blame] | 903 | .popsection // .entry.text |
| 904 | |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 905 | #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 Deacon | 1f911ed | 2017-11-14 14:29:19 +0000 | [diff] [blame] | 916 | #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 Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 926 | .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 |
| 949 | 1: |
| 950 | .if \regsize == 64 |
| 951 | msr tpidrro_el0, x30 // Restored in kernel_ventry |
| 952 | .endif |
Will Deacon | 509a7a8 | 2017-11-14 16:15:59 +0000 | [diff] [blame] | 953 | bl 2f |
| 954 | b . |
| 955 | 2: |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 956 | tramp_map_kernel x30 |
Will Deacon | 912612c | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 957 | #ifdef CONFIG_RANDOMIZE_BASE |
| 958 | adr x30, tramp_vectors + PAGE_SIZE |
Todd Poynor | 735703d | 2018-01-08 12:22:41 -0800 | [diff] [blame] | 959 | #ifndef CONFIG_ARCH_MSM8996 |
| 960 | isb |
| 961 | #endif |
Will Deacon | 912612c | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 962 | ldr x30, [x30] |
| 963 | #else |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 964 | ldr x30, =vectors |
Will Deacon | 912612c | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 965 | #endif |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 966 | prfm plil1strm, [x30, #(1b - tramp_vectors)] |
| 967 | msr vbar_el1, x30 |
| 968 | add x30, x30, #(1b - tramp_vectors) |
| 969 | isb |
Will Deacon | 509a7a8 | 2017-11-14 16:15:59 +0000 | [diff] [blame] | 970 | ret |
Will Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 971 | .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 |
| 984 | ENTRY(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 |
| 996 | END(tramp_vectors) |
| 997 | |
| 998 | ENTRY(tramp_exit_native) |
| 999 | tramp_exit |
| 1000 | END(tramp_exit_native) |
| 1001 | |
| 1002 | ENTRY(tramp_exit_compat) |
| 1003 | tramp_exit 32 |
| 1004 | END(tramp_exit_compat) |
| 1005 | |
| 1006 | .ltorg |
| 1007 | .popsection // .entry.tramp.text |
Will Deacon | 912612c | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 1008 | #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 Deacon | 39d3d6b | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 1016 | #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ |
| 1017 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 1018 | /* |
| 1019 | * Special system call wrappers. |
| 1020 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 1021 | ENTRY(sys_rt_sigreturn_wrapper) |
| 1022 | mov x0, sp |
| 1023 | b sys_rt_sigreturn |
| 1024 | ENDPROC(sys_rt_sigreturn_wrapper) |