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 | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 32 | #include <asm/mmu.h> |
Mark Rutland | 27eeced | 2018-04-12 12:10:59 +0100 | [diff] [blame] | 33 | #include <asm/processor.h> |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 34 | #include <asm/ptrace.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 35 | #include <asm/thread_info.h> |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 36 | #include <asm/uaccess.h> |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 37 | #include <asm/asm-uaccess.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 38 | #include <asm/unistd.h> |
Will Deacon | 78a0cec | 2018-04-03 12:09:04 +0100 | [diff] [blame] | 39 | #include <asm/kernel-pgtable.h> |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 40 | |
| 41 | /* |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 42 | * Context tracking subsystem. Used to instrument transitions |
| 43 | * between user and kernel mode. |
| 44 | */ |
| 45 | .macro ct_user_exit, syscall = 0 |
| 46 | #ifdef CONFIG_CONTEXT_TRACKING |
| 47 | bl context_tracking_user_exit |
| 48 | .if \syscall == 1 |
| 49 | /* |
| 50 | * Save/restore needed during syscalls. Restore syscall arguments from |
| 51 | * the values already saved on stack during kernel_entry. |
| 52 | */ |
| 53 | ldp x0, x1, [sp] |
| 54 | ldp x2, x3, [sp, #S_X2] |
| 55 | ldp x4, x5, [sp, #S_X4] |
| 56 | ldp x6, x7, [sp, #S_X6] |
| 57 | .endif |
| 58 | #endif |
| 59 | .endm |
| 60 | |
| 61 | .macro ct_user_enter |
| 62 | #ifdef CONFIG_CONTEXT_TRACKING |
| 63 | bl context_tracking_user_enter |
| 64 | #endif |
| 65 | .endm |
| 66 | |
| 67 | /* |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 68 | * Bad Abort numbers |
| 69 | *----------------- |
| 70 | */ |
| 71 | #define BAD_SYNC 0 |
| 72 | #define BAD_IRQ 1 |
| 73 | #define BAD_FIQ 2 |
| 74 | #define BAD_ERROR 3 |
| 75 | |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 76 | .macro kernel_ventry, el, label, regsize = 64 |
Mark Rutland | 17d3592 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 77 | .align 7 |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 78 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 79 | alternative_if ARM64_UNMAP_KERNEL_AT_EL0 |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 80 | .if \el == 0 |
| 81 | .if \regsize == 64 |
| 82 | mrs x30, tpidrro_el0 |
| 83 | msr tpidrro_el0, xzr |
| 84 | .else |
| 85 | mov x30, xzr |
| 86 | .endif |
| 87 | .endif |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 88 | alternative_else_nop_endif |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 89 | #endif |
| 90 | |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 91 | sub sp, sp, #S_FRAME_SIZE |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 92 | b el\()\el\()_\label |
Mark Rutland | 17d3592 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 93 | .endm |
| 94 | |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 95 | .macro tramp_alias, dst, sym |
| 96 | mov_q \dst, TRAMP_VALIAS |
| 97 | add \dst, \dst, #(\sym - .entry.tramp.text) |
| 98 | .endm |
| 99 | |
Mark Rutland | 17d3592 | 2017-07-19 17:24:49 +0100 | [diff] [blame] | 100 | .macro kernel_entry, el, regsize = 64 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 101 | .if \regsize == 32 |
| 102 | mov w0, w0 // zero upper 32 bits of x0 |
| 103 | .endif |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 104 | stp x0, x1, [sp, #16 * 0] |
| 105 | stp x2, x3, [sp, #16 * 1] |
| 106 | stp x4, x5, [sp, #16 * 2] |
| 107 | stp x6, x7, [sp, #16 * 3] |
| 108 | stp x8, x9, [sp, #16 * 4] |
| 109 | stp x10, x11, [sp, #16 * 5] |
| 110 | stp x12, x13, [sp, #16 * 6] |
| 111 | stp x14, x15, [sp, #16 * 7] |
| 112 | stp x16, x17, [sp, #16 * 8] |
| 113 | stp x18, x19, [sp, #16 * 9] |
| 114 | stp x20, x21, [sp, #16 * 10] |
| 115 | stp x22, x23, [sp, #16 * 11] |
| 116 | stp x24, x25, [sp, #16 * 12] |
| 117 | stp x26, x27, [sp, #16 * 13] |
| 118 | stp x28, x29, [sp, #16 * 14] |
| 119 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 120 | .if \el == 0 |
| 121 | mrs x21, sp_el0 |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 122 | ldr_this_cpu tsk, __entry_task, x20 // Ensure MDSCR_EL1.SS is clear, |
| 123 | ldr x19, [tsk, #TSK_TI_FLAGS] // since we can unmask debug |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 124 | disable_step_tsk x19, x20 // exceptions when scheduling. |
James Morse | 49003a8 | 2015-12-10 10:22:41 +0000 | [diff] [blame] | 125 | |
| 126 | mov x29, xzr // fp pointed to user-space |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 127 | .else |
| 128 | add x21, sp, #S_FRAME_SIZE |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 129 | get_thread_info tsk |
Mark Rutland | c910086 | 2018-04-12 12:11:00 +0100 | [diff] [blame] | 130 | /* Save the task's original addr_limit and set USER_DS */ |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 131 | ldr x20, [tsk, #TSK_TI_ADDR_LIMIT] |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 132 | str x20, [sp, #S_ORIG_ADDR_LIMIT] |
Mark Rutland | c910086 | 2018-04-12 12:11:00 +0100 | [diff] [blame] | 133 | mov x20, #USER_DS |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 134 | str x20, [tsk, #TSK_TI_ADDR_LIMIT] |
Vladimir Murzin | 563cada | 2016-09-01 14:35:59 +0100 | [diff] [blame] | 135 | /* 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] | 136 | .endif /* \el == 0 */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 137 | mrs x22, elr_el1 |
| 138 | mrs x23, spsr_el1 |
| 139 | stp lr, x21, [sp, #S_LR] |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 140 | |
| 141 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN |
| 142 | /* |
| 143 | * Set the TTBR0 PAN bit in SPSR. When the exception is taken from |
| 144 | * EL0, there is no need to check the state of TTBR0_EL1 since |
| 145 | * accesses are always enabled. |
| 146 | * Note that the meaning of this bit differs from the ARMv8.1 PAN |
| 147 | * feature as all TTBR0_EL1 accesses are disabled, not just those to |
| 148 | * user mappings. |
| 149 | */ |
| 150 | alternative_if ARM64_HAS_PAN |
| 151 | b 1f // skip TTBR0 PAN |
| 152 | alternative_else_nop_endif |
| 153 | |
| 154 | .if \el != 0 |
Catalin Marinas | 8788313 | 2018-01-10 13:18:30 +0000 | [diff] [blame] | 155 | mrs x21, ttbr0_el1 |
Will Deacon | d7013ed | 2017-12-01 17:33:48 +0000 | [diff] [blame] | 156 | tst x21, #TTBR_ASID_MASK // Check for the reserved ASID |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 157 | orr x23, x23, #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR |
| 158 | b.eq 1f // TTBR0 access already disabled |
| 159 | and x23, x23, #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR |
| 160 | .endif |
| 161 | |
| 162 | __uaccess_ttbr0_disable x21 |
| 163 | 1: |
| 164 | #endif |
| 165 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 166 | stp x22, x23, [sp, #S_PC] |
| 167 | |
| 168 | /* |
| 169 | * Set syscallno to -1 by default (overridden later if real syscall). |
| 170 | */ |
| 171 | .if \el == 0 |
| 172 | mvn x21, xzr |
| 173 | str x21, [sp, #S_SYSCALLNO] |
| 174 | .endif |
| 175 | |
| 176 | /* |
Jungseok Lee | 6cdf9c7 | 2015-12-04 11:02:25 +0000 | [diff] [blame] | 177 | * Set sp_el0 to current thread_info. |
| 178 | */ |
| 179 | .if \el == 0 |
| 180 | msr sp_el0, tsk |
| 181 | .endif |
| 182 | |
| 183 | /* |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 184 | * Registers that may be useful after this macro is invoked: |
| 185 | * |
| 186 | * x21 - aborted SP |
| 187 | * x22 - aborted PC |
| 188 | * x23 - aborted PSTATE |
| 189 | */ |
| 190 | .endm |
| 191 | |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 192 | .macro kernel_exit, el |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 193 | .if \el != 0 |
| 194 | /* Restore the task's original addr_limit. */ |
| 195 | ldr x20, [sp, #S_ORIG_ADDR_LIMIT] |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 196 | str x20, [tsk, #TSK_TI_ADDR_LIMIT] |
James Morse | e19a6ee | 2016-06-20 18:28:01 +0100 | [diff] [blame] | 197 | |
| 198 | /* No need to restore UAO, it will be restored from SPSR_EL1 */ |
| 199 | .endif |
| 200 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 201 | ldp x21, x22, [sp, #S_PC] // load ELR, SPSR |
| 202 | .if \el == 0 |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 203 | ct_user_enter |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 204 | .endif |
| 205 | |
| 206 | #ifdef CONFIG_ARM64_SW_TTBR0_PAN |
| 207 | /* |
| 208 | * Restore access to TTBR0_EL1. If returning to EL0, no need for SPSR |
| 209 | * PAN bit checking. |
| 210 | */ |
| 211 | alternative_if ARM64_HAS_PAN |
| 212 | b 2f // skip TTBR0 PAN |
| 213 | alternative_else_nop_endif |
| 214 | |
| 215 | .if \el != 0 |
| 216 | tbnz x22, #22, 1f // Skip re-enabling TTBR0 access if the PSR_PAN_BIT is set |
| 217 | .endif |
| 218 | |
Will Deacon | 599c71f | 2017-08-10 13:58:16 +0100 | [diff] [blame] | 219 | __uaccess_ttbr0_enable x0, x1 |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 220 | |
| 221 | .if \el == 0 |
| 222 | /* |
| 223 | * Enable errata workarounds only if returning to user. The only |
| 224 | * workaround currently required for TTBR0_EL1 changes are for the |
| 225 | * Cavium erratum 27456 (broadcast TLBI instructions may cause I-cache |
| 226 | * corruption). |
| 227 | */ |
Marc Zyngier | 95bfec6 | 2018-01-02 18:19:39 +0000 | [diff] [blame] | 228 | bl post_ttbr_update_workaround |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 229 | .endif |
| 230 | 1: |
| 231 | .if \el != 0 |
| 232 | and x22, x22, #~PSR_PAN_BIT // ARMv8.0 CPUs do not understand this bit |
| 233 | .endif |
| 234 | 2: |
| 235 | #endif |
| 236 | |
| 237 | .if \el == 0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 238 | ldr x23, [sp, #S_SP] // load return stack pointer |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 239 | msr sp_el0, x23 |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 240 | tst x22, #PSR_MODE32_BIT // native task? |
| 241 | b.eq 3f |
| 242 | |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 243 | #ifdef CONFIG_ARM64_ERRATUM_845719 |
Mark Rutland | 6ba3b55 | 2016-09-07 11:07:09 +0100 | [diff] [blame] | 244 | alternative_if ARM64_WORKAROUND_845719 |
Daniel Thompson | e28cabf | 2015-07-22 12:21:03 +0100 | [diff] [blame] | 245 | #ifdef CONFIG_PID_IN_CONTEXTIDR |
| 246 | mrs x29, contextidr_el1 |
| 247 | msr contextidr_el1, x29 |
| 248 | #else |
| 249 | msr contextidr_el1, xzr |
| 250 | #endif |
Mark Rutland | 6ba3b55 | 2016-09-07 11:07:09 +0100 | [diff] [blame] | 251 | alternative_else_nop_endif |
Will Deacon | 905e8c5 | 2015-03-23 19:07:02 +0000 | [diff] [blame] | 252 | #endif |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 253 | 3: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 254 | .endif |
Catalin Marinas | cfa9377 | 2016-09-02 14:54:03 +0100 | [diff] [blame] | 255 | |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 256 | msr elr_el1, x21 // set up the return data |
| 257 | msr spsr_el1, x22 |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 258 | ldp x0, x1, [sp, #16 * 0] |
Will Deacon | 63648dd | 2014-09-29 12:26:41 +0100 | [diff] [blame] | 259 | ldp x2, x3, [sp, #16 * 1] |
| 260 | ldp x4, x5, [sp, #16 * 2] |
| 261 | ldp x6, x7, [sp, #16 * 3] |
| 262 | ldp x8, x9, [sp, #16 * 4] |
| 263 | ldp x10, x11, [sp, #16 * 5] |
| 264 | ldp x12, x13, [sp, #16 * 6] |
| 265 | ldp x14, x15, [sp, #16 * 7] |
| 266 | ldp x16, x17, [sp, #16 * 8] |
| 267 | ldp x18, x19, [sp, #16 * 9] |
| 268 | ldp x20, x21, [sp, #16 * 10] |
| 269 | ldp x22, x23, [sp, #16 * 11] |
| 270 | ldp x24, x25, [sp, #16 * 12] |
| 271 | ldp x26, x27, [sp, #16 * 13] |
| 272 | ldp x28, x29, [sp, #16 * 14] |
| 273 | ldr lr, [sp, #S_LR] |
| 274 | add sp, sp, #S_FRAME_SIZE // restore sp |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 275 | |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 276 | .if \el == 0 |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 277 | alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0 |
| 278 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 279 | bne 4f |
| 280 | msr far_el1, x30 |
| 281 | tramp_alias x30, tramp_exit_native |
| 282 | br x30 |
| 283 | 4: |
| 284 | tramp_alias x30, tramp_exit_compat |
| 285 | br x30 |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 286 | #endif |
Will Deacon | c27a2258 | 2017-11-14 14:24:29 +0000 | [diff] [blame] | 287 | .else |
| 288 | eret |
| 289 | .endif |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 290 | .endm |
| 291 | |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 292 | .macro irq_stack_entry |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 293 | mov x19, sp // preserve the original sp |
| 294 | |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 295 | /* |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 296 | * Compare sp with the base of the task stack. |
| 297 | * If the top ~(THREAD_SIZE - 1) bits match, we are on a task stack, |
| 298 | * and should switch to the irq stack. |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 299 | */ |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 300 | ldr x25, [tsk, TSK_STACK] |
| 301 | eor x25, x25, x19 |
| 302 | and x25, x25, #~(THREAD_SIZE - 1) |
| 303 | cbnz x25, 9998f |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 304 | |
Mark Rutland | 8b6c9c9 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 305 | adr_this_cpu x25, irq_stack, x26 |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 306 | mov x26, #IRQ_STACK_START_SP |
| 307 | add x26, x25, x26 |
James Morse | d224a69 | 2015-12-18 16:01:47 +0000 | [diff] [blame] | 308 | |
| 309 | /* switch to the irq stack */ |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 310 | mov sp, x26 |
| 311 | |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 312 | /* |
| 313 | * Add a dummy stack frame, this non-standard format is fixed up |
| 314 | * by unwind_frame() |
| 315 | */ |
| 316 | stp x29, x19, [sp, #-16]! |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 317 | mov x29, sp |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 318 | |
| 319 | 9998: |
| 320 | .endm |
| 321 | |
| 322 | /* |
| 323 | * x19 should be preserved between irq_stack_entry and |
| 324 | * irq_stack_exit. |
| 325 | */ |
| 326 | .macro irq_stack_exit |
| 327 | mov sp, x19 |
| 328 | .endm |
| 329 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 330 | /* |
| 331 | * These are the registers used in the syscall handler, and allow us to |
| 332 | * have in theory up to 7 arguments to a function - x0 to x6. |
| 333 | * |
| 334 | * x7 is reserved for the system call number in 32-bit mode. |
| 335 | */ |
| 336 | sc_nr .req x25 // number of system calls |
| 337 | scno .req x26 // syscall number |
| 338 | stbl .req x27 // syscall table pointer |
| 339 | tsk .req x28 // current thread_info |
| 340 | |
| 341 | /* |
| 342 | * Interrupt handling. |
| 343 | */ |
| 344 | .macro irq_handler |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 345 | ldr_l x1, handle_arch_irq |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 346 | mov x0, sp |
James Morse | 971c67c | 2015-12-15 11:21:25 +0000 | [diff] [blame] | 347 | irq_stack_entry |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 348 | blr x1 |
James Morse | 8e23dac | 2015-12-04 11:02:27 +0000 | [diff] [blame] | 349 | irq_stack_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 350 | .endm |
| 351 | |
| 352 | .text |
| 353 | |
| 354 | /* |
| 355 | * Exception vectors. |
| 356 | */ |
Pratyush Anand | 888b3c8 | 2016-07-08 12:35:50 -0400 | [diff] [blame] | 357 | .pushsection ".entry.text", "ax" |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 358 | |
| 359 | .align 11 |
| 360 | ENTRY(vectors) |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 361 | kernel_ventry 1, sync_invalid // Synchronous EL1t |
| 362 | kernel_ventry 1, irq_invalid // IRQ EL1t |
| 363 | kernel_ventry 1, fiq_invalid // FIQ EL1t |
| 364 | kernel_ventry 1, error_invalid // Error EL1t |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 365 | |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 366 | kernel_ventry 1, sync // Synchronous EL1h |
| 367 | kernel_ventry 1, irq // IRQ EL1h |
| 368 | kernel_ventry 1, fiq_invalid // FIQ EL1h |
| 369 | kernel_ventry 1, error_invalid // Error EL1h |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 370 | |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 371 | kernel_ventry 0, sync // Synchronous 64-bit EL0 |
| 372 | kernel_ventry 0, irq // IRQ 64-bit EL0 |
| 373 | kernel_ventry 0, fiq_invalid // FIQ 64-bit EL0 |
| 374 | kernel_ventry 0, error_invalid // Error 64-bit EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 375 | |
| 376 | #ifdef CONFIG_COMPAT |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 377 | kernel_ventry 0, sync_compat, 32 // Synchronous 32-bit EL0 |
| 378 | kernel_ventry 0, irq_compat, 32 // IRQ 32-bit EL0 |
| 379 | kernel_ventry 0, fiq_invalid_compat, 32 // FIQ 32-bit EL0 |
| 380 | kernel_ventry 0, error_invalid_compat, 32 // Error 32-bit EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 381 | #else |
Will Deacon | 8fdbffb | 2017-11-14 14:20:21 +0000 | [diff] [blame] | 382 | kernel_ventry 0, sync_invalid, 32 // Synchronous 32-bit EL0 |
| 383 | kernel_ventry 0, irq_invalid, 32 // IRQ 32-bit EL0 |
| 384 | kernel_ventry 0, fiq_invalid, 32 // FIQ 32-bit EL0 |
| 385 | kernel_ventry 0, error_invalid, 32 // Error 32-bit EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 386 | #endif |
| 387 | END(vectors) |
| 388 | |
| 389 | /* |
| 390 | * Invalid mode handlers |
| 391 | */ |
| 392 | .macro inv_entry, el, reason, regsize = 64 |
Ard Biesheuvel | b660950 | 2016-03-18 10:58:09 +0100 | [diff] [blame] | 393 | kernel_entry \el, \regsize |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 394 | mov x0, sp |
| 395 | mov x1, #\reason |
| 396 | mrs x2, esr_el1 |
| 397 | b bad_mode |
| 398 | .endm |
| 399 | |
| 400 | el0_sync_invalid: |
| 401 | inv_entry 0, BAD_SYNC |
| 402 | ENDPROC(el0_sync_invalid) |
| 403 | |
| 404 | el0_irq_invalid: |
| 405 | inv_entry 0, BAD_IRQ |
| 406 | ENDPROC(el0_irq_invalid) |
| 407 | |
| 408 | el0_fiq_invalid: |
| 409 | inv_entry 0, BAD_FIQ |
| 410 | ENDPROC(el0_fiq_invalid) |
| 411 | |
| 412 | el0_error_invalid: |
| 413 | inv_entry 0, BAD_ERROR |
| 414 | ENDPROC(el0_error_invalid) |
| 415 | |
| 416 | #ifdef CONFIG_COMPAT |
| 417 | el0_fiq_invalid_compat: |
| 418 | inv_entry 0, BAD_FIQ, 32 |
| 419 | ENDPROC(el0_fiq_invalid_compat) |
| 420 | |
| 421 | el0_error_invalid_compat: |
| 422 | inv_entry 0, BAD_ERROR, 32 |
| 423 | ENDPROC(el0_error_invalid_compat) |
| 424 | #endif |
| 425 | |
| 426 | el1_sync_invalid: |
| 427 | inv_entry 1, BAD_SYNC |
| 428 | ENDPROC(el1_sync_invalid) |
| 429 | |
| 430 | el1_irq_invalid: |
| 431 | inv_entry 1, BAD_IRQ |
| 432 | ENDPROC(el1_irq_invalid) |
| 433 | |
| 434 | el1_fiq_invalid: |
| 435 | inv_entry 1, BAD_FIQ |
| 436 | ENDPROC(el1_fiq_invalid) |
| 437 | |
| 438 | el1_error_invalid: |
| 439 | inv_entry 1, BAD_ERROR |
| 440 | ENDPROC(el1_error_invalid) |
| 441 | |
| 442 | /* |
| 443 | * EL1 mode handlers. |
| 444 | */ |
| 445 | .align 6 |
| 446 | el1_sync: |
| 447 | kernel_entry 1 |
| 448 | mrs x1, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 449 | lsr x24, x1, #ESR_ELx_EC_SHIFT // exception class |
| 450 | cmp x24, #ESR_ELx_EC_DABT_CUR // data abort in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 451 | b.eq el1_da |
Laura Abbott | 9adeb8e | 2016-08-09 18:25:26 -0700 | [diff] [blame] | 452 | cmp x24, #ESR_ELx_EC_IABT_CUR // instruction abort in EL1 |
| 453 | b.eq el1_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 454 | cmp x24, #ESR_ELx_EC_SYS64 // configurable trap |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 455 | b.eq el1_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 456 | cmp x24, #ESR_ELx_EC_SP_ALIGN // stack 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_PC_ALIGN // pc alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 459 | b.eq el1_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 460 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 461 | b.eq el1_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 462 | cmp x24, #ESR_ELx_EC_BREAKPT_CUR // debug exception in EL1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 463 | b.ge el1_dbg |
| 464 | b el1_inv |
Laura Abbott | 9adeb8e | 2016-08-09 18:25:26 -0700 | [diff] [blame] | 465 | |
| 466 | el1_ia: |
| 467 | /* |
| 468 | * Fall through to the Data abort case |
| 469 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 470 | el1_da: |
| 471 | /* |
| 472 | * Data abort handling |
| 473 | */ |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 474 | mrs x3, far_el1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 475 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 476 | // re-enable interrupts if they were enabled in the aborted context |
| 477 | tbnz x23, #7, 1f // PSR_I_BIT |
| 478 | enable_irq |
| 479 | 1: |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 480 | clear_address_tag x0, x3 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 481 | mov x2, sp // struct pt_regs |
| 482 | bl do_mem_abort |
| 483 | |
| 484 | // disable interrupts before pulling preserved data off the stack |
| 485 | disable_irq |
| 486 | kernel_exit 1 |
| 487 | el1_sp_pc: |
| 488 | /* |
| 489 | * Stack or PC alignment exception handling |
| 490 | */ |
| 491 | mrs x0, far_el1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 492 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 493 | mov x2, sp |
| 494 | b do_sp_pc_abort |
| 495 | el1_undef: |
| 496 | /* |
| 497 | * Undefined instruction |
| 498 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 499 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 500 | mov x0, sp |
| 501 | b do_undefinstr |
| 502 | el1_dbg: |
| 503 | /* |
| 504 | * Debug exception handling |
| 505 | */ |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 506 | cmp x24, #ESR_ELx_EC_BRK64 // if BRK64 |
Sandeepa Prabhu | ee6214c | 2013-12-04 05:50:20 +0000 | [diff] [blame] | 507 | cinc x24, x24, eq // set bit '0' |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 508 | tbz x24, #0, el1_inv // EL1 only |
| 509 | mrs x0, far_el1 |
| 510 | mov x2, sp // struct pt_regs |
| 511 | bl do_debug_exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 512 | kernel_exit 1 |
| 513 | el1_inv: |
| 514 | // TODO: add support for undefined instructions in kernel mode |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 515 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 516 | mov x0, sp |
Mark Rutland | 1b42804 | 2015-07-07 18:00:49 +0100 | [diff] [blame] | 517 | mov x2, x1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 518 | mov x1, #BAD_SYNC |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 519 | b bad_mode |
| 520 | ENDPROC(el1_sync) |
| 521 | |
| 522 | .align 6 |
| 523 | el1_irq: |
| 524 | kernel_entry 1 |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 525 | enable_dbg |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 526 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 527 | bl trace_hardirqs_off |
| 528 | #endif |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 529 | |
| 530 | irq_handler |
| 531 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 532 | #ifdef CONFIG_PREEMPT |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 533 | ldr w24, [tsk, #TSK_TI_PREEMPT] // get preempt count |
Marc Zyngier | 717321f | 2013-11-04 20:14:58 +0000 | [diff] [blame] | 534 | cbnz w24, 1f // preempt count != 0 |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 535 | ldr x0, [tsk, #TSK_TI_FLAGS] // get flags |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 536 | tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling? |
| 537 | bl el1_preempt |
| 538 | 1: |
| 539 | #endif |
| 540 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 541 | bl trace_hardirqs_on |
| 542 | #endif |
| 543 | kernel_exit 1 |
| 544 | ENDPROC(el1_irq) |
| 545 | |
| 546 | #ifdef CONFIG_PREEMPT |
| 547 | el1_preempt: |
| 548 | mov x24, lr |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 549 | 1: bl preempt_schedule_irq // irq en/disable is done inside |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 550 | ldr x0, [tsk, #TSK_TI_FLAGS] // get new tasks TI_FLAGS |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 551 | tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling? |
| 552 | ret x24 |
| 553 | #endif |
| 554 | |
| 555 | /* |
| 556 | * EL0 mode handlers. |
| 557 | */ |
| 558 | .align 6 |
| 559 | el0_sync: |
| 560 | kernel_entry 0 |
| 561 | mrs x25, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 562 | lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class |
| 563 | cmp x24, #ESR_ELx_EC_SVC64 // SVC in 64-bit state |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 564 | b.eq el0_svc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 565 | cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 566 | b.eq el0_da |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 567 | cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 568 | b.eq el0_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 569 | cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 570 | b.eq el0_fpsimd_acc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 571 | cmp x24, #ESR_ELx_EC_FP_EXC64 // FP/ASIMD exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 572 | b.eq el0_fpsimd_exc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 573 | cmp x24, #ESR_ELx_EC_SYS64 // configurable trap |
Andre Przywara | 7dd01ae | 2016-06-28 18:07:32 +0100 | [diff] [blame] | 574 | b.eq el0_sys |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 575 | cmp x24, #ESR_ELx_EC_SP_ALIGN // stack 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_PC_ALIGN // pc alignment exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 578 | b.eq el0_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 579 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 580 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 581 | cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 582 | b.ge el0_dbg |
| 583 | b el0_inv |
| 584 | |
| 585 | #ifdef CONFIG_COMPAT |
| 586 | .align 6 |
| 587 | el0_sync_compat: |
| 588 | kernel_entry 0, 32 |
| 589 | mrs x25, esr_el1 // read the syndrome register |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 590 | lsr x24, x25, #ESR_ELx_EC_SHIFT // exception class |
| 591 | cmp x24, #ESR_ELx_EC_SVC32 // SVC in 32-bit state |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 592 | b.eq el0_svc_compat |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 593 | cmp x24, #ESR_ELx_EC_DABT_LOW // data abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 594 | b.eq el0_da |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 595 | cmp x24, #ESR_ELx_EC_IABT_LOW // instruction abort in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 596 | b.eq el0_ia |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 597 | cmp x24, #ESR_ELx_EC_FP_ASIMD // FP/ASIMD access |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 598 | b.eq el0_fpsimd_acc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 599 | cmp x24, #ESR_ELx_EC_FP_EXC32 // FP/ASIMD exception |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 600 | b.eq el0_fpsimd_exc |
Mark Salyzyn | 77f3228f | 2015-10-13 14:30:51 -0700 | [diff] [blame] | 601 | cmp x24, #ESR_ELx_EC_PC_ALIGN // pc alignment exception |
| 602 | b.eq el0_sp_pc |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 603 | cmp x24, #ESR_ELx_EC_UNKNOWN // unknown exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [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_32 // CP15 MRC/MCR 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_CP15_64 // CP15 MRRC/MCRR 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_MR // CP14 MRC/MCR 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_LS // CP14 LDC/STC 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_CP14_64 // CP14 MRRC/MCRR trap |
Mark Rutland | 381cc2b | 2013-05-24 12:02:35 +0100 | [diff] [blame] | 614 | b.eq el0_undef |
Mark Rutland | aed40e0 | 2014-11-24 12:31:40 +0000 | [diff] [blame] | 615 | cmp x24, #ESR_ELx_EC_BREAKPT_LOW // debug exception in EL0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 616 | b.ge el0_dbg |
| 617 | b el0_inv |
| 618 | el0_svc_compat: |
| 619 | /* |
| 620 | * AArch32 syscall handling |
| 621 | */ |
Catalin Marinas | 0156411 | 2015-01-06 16:42:32 +0000 | [diff] [blame] | 622 | adrp stbl, compat_sys_call_table // load compat syscall table pointer |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 623 | uxtw scno, w7 // syscall number in w7 (r7) |
| 624 | mov sc_nr, #__NR_compat_syscalls |
| 625 | b el0_svc_naked |
| 626 | |
| 627 | .align 6 |
| 628 | el0_irq_compat: |
| 629 | kernel_entry 0, 32 |
| 630 | b el0_irq_naked |
| 631 | #endif |
| 632 | |
| 633 | el0_da: |
| 634 | /* |
| 635 | * Data abort handling |
| 636 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 637 | mrs x26, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 638 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 639 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 640 | ct_user_exit |
Kristina Martsenko | 9e09d90 | 2017-06-06 20:14:10 +0100 | [diff] [blame] | 641 | clear_address_tag x0, x26 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 642 | mov x1, x25 |
| 643 | mov x2, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 644 | bl do_mem_abort |
| 645 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 646 | el0_ia: |
| 647 | /* |
| 648 | * Instruction abort handling |
| 649 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 650 | mrs x26, far_el1 |
Mark Rutland | 4732001 | 2018-04-12 12:11:13 +0100 | [diff] [blame] | 651 | msr daifclr, #(8 | 4 | 1) |
| 652 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 653 | bl trace_hardirqs_off |
| 654 | #endif |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 655 | ct_user_exit |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 656 | mov x0, x26 |
Mark Rutland | 541ec87 | 2016-05-31 12:33:03 +0100 | [diff] [blame] | 657 | mov x1, x25 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 658 | mov x2, sp |
Mark Rutland | 4732001 | 2018-04-12 12:11:13 +0100 | [diff] [blame] | 659 | bl do_el0_ia_bp_hardening |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 660 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 661 | el0_fpsimd_acc: |
| 662 | /* |
| 663 | * Floating Point or Advanced SIMD access |
| 664 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 665 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 666 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 667 | mov x0, x25 |
| 668 | mov x1, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 669 | bl do_fpsimd_acc |
| 670 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 671 | el0_fpsimd_exc: |
| 672 | /* |
| 673 | * Floating Point or Advanced SIMD exception |
| 674 | */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 675 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 676 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 677 | mov x0, x25 |
| 678 | mov x1, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 679 | bl do_fpsimd_exc |
| 680 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 681 | el0_sp_pc: |
| 682 | /* |
| 683 | * Stack or PC alignment exception handling |
| 684 | */ |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 685 | mrs x26, far_el1 |
Mark Rutland | e7c3b24 | 2018-04-12 12:11:17 +0100 | [diff] [blame] | 686 | enable_dbg |
| 687 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 688 | bl trace_hardirqs_off |
| 689 | #endif |
Mark Rutland | 46b0567 | 2015-06-15 16:40:27 +0100 | [diff] [blame] | 690 | ct_user_exit |
Larry Bassel | 6ab6463 | 2014-05-30 20:34:14 +0100 | [diff] [blame] | 691 | mov x0, x26 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 692 | mov x1, x25 |
| 693 | mov x2, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 694 | bl do_sp_pc_abort |
| 695 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 696 | el0_undef: |
| 697 | /* |
| 698 | * Undefined instruction |
| 699 | */ |
Catalin Marinas | 2600e13 | 2013-08-22 11:47:37 +0100 | [diff] [blame] | 700 | // enable interrupts before calling the main handler |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 701 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 702 | ct_user_exit |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 703 | mov x0, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 704 | bl do_undefinstr |
| 705 | b ret_to_user |
Andre Przywara | 7dd01ae | 2016-06-28 18:07:32 +0100 | [diff] [blame] | 706 | el0_sys: |
| 707 | /* |
| 708 | * System instructions, for trapped cache maintenance instructions |
| 709 | */ |
| 710 | enable_dbg_and_irq |
| 711 | ct_user_exit |
| 712 | mov x0, x25 |
| 713 | mov x1, sp |
| 714 | bl do_sysinstr |
| 715 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 716 | el0_dbg: |
| 717 | /* |
| 718 | * Debug exception handling |
| 719 | */ |
| 720 | tbnz x24, #0, el0_inv // EL0 only |
| 721 | mrs x0, far_el1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 722 | mov x1, x25 |
| 723 | mov x2, sp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 724 | bl do_debug_exception |
| 725 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 726 | ct_user_exit |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 727 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 728 | el0_inv: |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 729 | enable_dbg |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 730 | ct_user_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 731 | mov x0, sp |
| 732 | mov x1, #BAD_SYNC |
Mark Rutland | 1b42804 | 2015-07-07 18:00:49 +0100 | [diff] [blame] | 733 | mov x2, x25 |
Mark Rutland | de32794 | 2017-01-18 17:23:41 +0000 | [diff] [blame] | 734 | bl bad_el0_sync |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 735 | b ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 736 | ENDPROC(el0_sync) |
| 737 | |
| 738 | .align 6 |
| 739 | el0_irq: |
| 740 | kernel_entry 0 |
| 741 | el0_irq_naked: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 742 | enable_dbg |
| 743 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 744 | bl trace_hardirqs_off |
| 745 | #endif |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 746 | |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 747 | ct_user_exit |
Mark Rutland | 34dc20b | 2018-04-12 12:11:18 +0100 | [diff] [blame] | 748 | #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR |
| 749 | tbz x22, #55, 1f |
| 750 | bl do_el0_irq_bp_hardening |
| 751 | 1: |
| 752 | #endif |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 753 | irq_handler |
Marc Zyngier | 6468178 | 2013-11-12 17:11:53 +0000 | [diff] [blame] | 754 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 755 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 756 | bl trace_hardirqs_on |
| 757 | #endif |
| 758 | b ret_to_user |
| 759 | ENDPROC(el0_irq) |
| 760 | |
| 761 | /* |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 762 | * Register switch for AArch64. The callee-saved registers need to be saved |
| 763 | * and restored. On entry: |
| 764 | * x0 = previous task_struct (must be preserved across the switch) |
| 765 | * x1 = next task_struct |
| 766 | * Previous and next are guaranteed not to be the same. |
| 767 | * |
| 768 | */ |
| 769 | ENTRY(cpu_switch_to) |
Will Deacon | c0d3fce | 2015-07-20 15:14:53 +0100 | [diff] [blame] | 770 | mov x10, #THREAD_CPU_CONTEXT |
| 771 | add x8, x0, x10 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 772 | mov x9, sp |
| 773 | stp x19, x20, [x8], #16 // store callee-saved registers |
| 774 | stp x21, x22, [x8], #16 |
| 775 | stp x23, x24, [x8], #16 |
| 776 | stp x25, x26, [x8], #16 |
| 777 | stp x27, x28, [x8], #16 |
| 778 | stp x29, x9, [x8], #16 |
| 779 | str lr, [x8] |
Will Deacon | c0d3fce | 2015-07-20 15:14:53 +0100 | [diff] [blame] | 780 | add x8, x1, x10 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 781 | ldp x19, x20, [x8], #16 // restore callee-saved registers |
| 782 | ldp x21, x22, [x8], #16 |
| 783 | ldp x23, x24, [x8], #16 |
| 784 | ldp x25, x26, [x8], #16 |
| 785 | ldp x27, x28, [x8], #16 |
| 786 | ldp x29, x9, [x8], #16 |
| 787 | ldr lr, [x8] |
| 788 | mov sp, x9 |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 789 | msr sp_el0, x1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 790 | ret |
| 791 | ENDPROC(cpu_switch_to) |
| 792 | |
| 793 | /* |
| 794 | * This is the fast syscall return path. We do as little as possible here, |
| 795 | * and this includes saving x0 back into the kernel stack. |
| 796 | */ |
| 797 | ret_fast_syscall: |
| 798 | disable_irq // disable interrupts |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 799 | str x0, [sp, #S_X0] // returned x0 |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 800 | ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for syscall tracing |
Josh Stone | 04d7e09 | 2015-06-05 14:28:03 -0700 | [diff] [blame] | 801 | and x2, x1, #_TIF_SYSCALL_WORK |
| 802 | cbnz x2, ret_fast_syscall_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 803 | and x2, x1, #_TIF_WORK_MASK |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 804 | cbnz x2, work_pending |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 805 | enable_step_tsk x1, x2 |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 806 | kernel_exit 0 |
Josh Stone | 04d7e09 | 2015-06-05 14:28:03 -0700 | [diff] [blame] | 807 | ret_fast_syscall_trace: |
| 808 | enable_irq // enable interrupts |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 809 | b __sys_trace_return_skipped // we already saved x0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 810 | |
| 811 | /* |
| 812 | * Ok, we need to do extra processing, enter the slow path. |
| 813 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 814 | work_pending: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 815 | mov x0, sp // 'regs' |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 816 | bl do_notify_resume |
Catalin Marinas | db3899a | 2015-12-04 12:42:29 +0000 | [diff] [blame] | 817 | #ifdef CONFIG_TRACE_IRQFLAGS |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 818 | bl trace_hardirqs_on // enabled while in userspace |
Catalin Marinas | db3899a | 2015-12-04 12:42:29 +0000 | [diff] [blame] | 819 | #endif |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 820 | ldr x1, [tsk, #TSK_TI_FLAGS] // re-check for single-step |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 821 | b finish_ret_to_user |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 822 | /* |
| 823 | * "slow" syscall return path. |
| 824 | */ |
Catalin Marinas | 59dc67b | 2012-09-10 16:11:46 +0100 | [diff] [blame] | 825 | ret_to_user: |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 826 | disable_irq // disable interrupts |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 827 | ldr x1, [tsk, #TSK_TI_FLAGS] |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 828 | and x2, x1, #_TIF_WORK_MASK |
| 829 | cbnz x2, work_pending |
Chris Metcalf | 421dd6f | 2016-07-14 16:48:14 -0400 | [diff] [blame] | 830 | finish_ret_to_user: |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 831 | enable_step_tsk x1, x2 |
Will Deacon | 412fcb6 | 2015-08-19 15:57:09 +0100 | [diff] [blame] | 832 | kernel_exit 0 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 833 | ENDPROC(ret_to_user) |
| 834 | |
| 835 | /* |
| 836 | * This is how we return from a fork. |
| 837 | */ |
| 838 | ENTRY(ret_from_fork) |
| 839 | bl schedule_tail |
Catalin Marinas | c34501d | 2012-10-05 12:31:20 +0100 | [diff] [blame] | 840 | cbz x19, 1f // not a kernel thread |
| 841 | mov x0, x20 |
| 842 | blr x19 |
| 843 | 1: get_thread_info tsk |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 844 | b ret_to_user |
| 845 | ENDPROC(ret_from_fork) |
| 846 | |
| 847 | /* |
| 848 | * SVC handler. |
| 849 | */ |
| 850 | .align 6 |
| 851 | el0_svc: |
| 852 | adrp stbl, sys_call_table // load syscall table pointer |
| 853 | uxtw scno, w8 // syscall number in w8 |
| 854 | mov sc_nr, #__NR_syscalls |
| 855 | el0_svc_naked: // compat entry point |
| 856 | 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] | 857 | enable_dbg_and_irq |
Larry Bassel | 6c81fe7 | 2014-05-30 12:34:15 -0700 | [diff] [blame] | 858 | ct_user_exit 1 |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 859 | |
Mark Rutland | 5b7e8f7 | 2016-11-03 20:23:13 +0000 | [diff] [blame] | 860 | ldr x16, [tsk, #TSK_TI_FLAGS] // check for syscall hooks |
AKASHI Takahiro | 449f81a | 2014-04-30 10:51:29 +0100 | [diff] [blame] | 861 | tst x16, #_TIF_SYSCALL_WORK |
| 862 | b.ne __sys_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 863 | cmp scno, sc_nr // check upper syscall limit |
| 864 | b.hs ni_sys |
Mark Rutland | f3ed64a | 2018-04-12 12:11:02 +0100 | [diff] [blame] | 865 | mask_nospec64 scno, sc_nr, x19 // enforce bounds for syscall number |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 866 | ldr x16, [stbl, scno, lsl #3] // address in the syscall table |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 867 | blr x16 // call sys_* routine |
| 868 | b ret_fast_syscall |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 869 | ni_sys: |
| 870 | mov x0, sp |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 871 | bl do_ni_syscall |
| 872 | b ret_fast_syscall |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 873 | ENDPROC(el0_svc) |
| 874 | |
| 875 | /* |
| 876 | * This is the really slow path. We're going to be doing context |
| 877 | * switches, and waiting for our parent to respond. |
| 878 | */ |
| 879 | __sys_trace: |
AKASHI Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 880 | mov w0, #-1 // set default errno for |
| 881 | cmp scno, x0 // user-issued syscall(-1) |
| 882 | b.ne 1f |
| 883 | mov x0, #-ENOSYS |
| 884 | str x0, [sp, #S_X0] |
| 885 | 1: mov x0, sp |
AKASHI Takahiro | 3157858 | 2014-04-30 10:51:30 +0100 | [diff] [blame] | 886 | bl syscall_trace_enter |
AKASHI Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 887 | cmp w0, #-1 // skip the syscall? |
| 888 | b.eq __sys_trace_return_skipped |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 889 | uxtw scno, w0 // syscall number (possibly new) |
| 890 | mov x1, sp // pointer to regs |
| 891 | cmp scno, sc_nr // check upper syscall limit |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 892 | b.hs __ni_sys_trace |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 893 | ldp x0, x1, [sp] // restore the syscall args |
| 894 | ldp x2, x3, [sp, #S_X2] |
| 895 | ldp x4, x5, [sp, #S_X4] |
| 896 | ldp x6, x7, [sp, #S_X6] |
| 897 | ldr x16, [stbl, scno, lsl #3] // address in the syscall table |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 898 | blr x16 // call sys_* routine |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 899 | |
| 900 | __sys_trace_return: |
AKASHI Takahiro | 1014c81 | 2014-11-28 05:26:35 +0000 | [diff] [blame] | 901 | str x0, [sp, #S_X0] // save returned x0 |
| 902 | __sys_trace_return_skipped: |
AKASHI Takahiro | 3157858 | 2014-04-30 10:51:30 +0100 | [diff] [blame] | 903 | mov x0, sp |
| 904 | bl syscall_trace_exit |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 905 | b ret_to_user |
| 906 | |
Will Deacon | d54e81f | 2014-09-29 11:44:01 +0100 | [diff] [blame] | 907 | __ni_sys_trace: |
| 908 | mov x0, sp |
| 909 | bl do_ni_syscall |
| 910 | b __sys_trace_return |
| 911 | |
Pratyush Anand | 888b3c8 | 2016-07-08 12:35:50 -0400 | [diff] [blame] | 912 | .popsection // .entry.text |
| 913 | |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 914 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
| 915 | /* |
| 916 | * Exception vectors trampoline. |
| 917 | */ |
| 918 | .pushsection ".entry.tramp.text", "ax" |
| 919 | |
| 920 | .macro tramp_map_kernel, tmp |
| 921 | mrs \tmp, ttbr1_el1 |
| 922 | sub \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE) |
| 923 | bic \tmp, \tmp, #USER_ASID_FLAG |
| 924 | msr ttbr1_el1, \tmp |
Will Deacon | 04b77fe | 2017-11-14 14:29:19 +0000 | [diff] [blame] | 925 | #ifdef CONFIG_ARCH_MSM8996 |
| 926 | /* ASID already in \tmp[63:48] */ |
| 927 | movk \tmp, #:abs_g2_nc:(TRAMP_VALIAS >> 12) |
| 928 | movk \tmp, #:abs_g1_nc:(TRAMP_VALIAS >> 12) |
| 929 | /* 2MB boundary containing the vectors, so we nobble the walk cache */ |
| 930 | movk \tmp, #:abs_g0_nc:((TRAMP_VALIAS & ~(SZ_2M - 1)) >> 12) |
| 931 | isb |
| 932 | tlbi vae1, \tmp |
| 933 | dsb nsh |
| 934 | #endif /* CONFIG_ARCH_MSM8996 */ |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 935 | .endm |
| 936 | |
| 937 | .macro tramp_unmap_kernel, tmp |
| 938 | mrs \tmp, ttbr1_el1 |
| 939 | add \tmp, \tmp, #(SWAPPER_DIR_SIZE + RESERVED_TTBR0_SIZE) |
| 940 | orr \tmp, \tmp, #USER_ASID_FLAG |
| 941 | msr ttbr1_el1, \tmp |
| 942 | /* |
Will Deacon | a80d8e2 | 2018-04-03 12:09:22 +0100 | [diff] [blame] | 943 | * We avoid running the post_ttbr_update_workaround here because |
| 944 | * it's only needed by Cavium ThunderX, which requires KPTI to be |
| 945 | * disabled. |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 946 | */ |
| 947 | .endm |
| 948 | |
| 949 | .macro tramp_ventry, regsize = 64 |
| 950 | .align 7 |
| 951 | 1: |
| 952 | .if \regsize == 64 |
| 953 | msr tpidrro_el0, x30 // Restored in kernel_ventry |
| 954 | .endif |
Will Deacon | f6af532 | 2018-04-03 12:09:11 +0100 | [diff] [blame] | 955 | /* |
| 956 | * Defend against branch aliasing attacks by pushing a dummy |
| 957 | * entry onto the return stack and using a RET instruction to |
| 958 | * enter the full-fat kernel vectors. |
| 959 | */ |
Will Deacon | 7535936 | 2017-11-14 16:15:59 +0000 | [diff] [blame] | 960 | bl 2f |
| 961 | b . |
| 962 | 2: |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 963 | tramp_map_kernel x30 |
Will Deacon | 06fe41f | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 964 | #ifdef CONFIG_RANDOMIZE_BASE |
| 965 | adr x30, tramp_vectors + PAGE_SIZE |
Todd Poynor | b328e52 | 2018-01-08 12:22:41 -0800 | [diff] [blame] | 966 | #ifndef CONFIG_ARCH_MSM8996 |
| 967 | isb |
| 968 | #endif |
Will Deacon | 06fe41f | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 969 | ldr x30, [x30] |
| 970 | #else |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 971 | ldr x30, =vectors |
Will Deacon | 06fe41f | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 972 | #endif |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 973 | prfm plil1strm, [x30, #(1b - tramp_vectors)] |
| 974 | msr vbar_el1, x30 |
| 975 | add x30, x30, #(1b - tramp_vectors) |
| 976 | isb |
Will Deacon | 7535936 | 2017-11-14 16:15:59 +0000 | [diff] [blame] | 977 | ret |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 978 | .endm |
| 979 | |
| 980 | .macro tramp_exit, regsize = 64 |
| 981 | adr x30, tramp_vectors |
| 982 | msr vbar_el1, x30 |
| 983 | tramp_unmap_kernel x30 |
| 984 | .if \regsize == 64 |
| 985 | mrs x30, far_el1 |
| 986 | .endif |
| 987 | eret |
| 988 | .endm |
| 989 | |
| 990 | .align 11 |
| 991 | ENTRY(tramp_vectors) |
| 992 | .space 0x400 |
| 993 | |
| 994 | tramp_ventry |
| 995 | tramp_ventry |
| 996 | tramp_ventry |
| 997 | tramp_ventry |
| 998 | |
| 999 | tramp_ventry 32 |
| 1000 | tramp_ventry 32 |
| 1001 | tramp_ventry 32 |
| 1002 | tramp_ventry 32 |
| 1003 | END(tramp_vectors) |
| 1004 | |
| 1005 | ENTRY(tramp_exit_native) |
| 1006 | tramp_exit |
| 1007 | END(tramp_exit_native) |
| 1008 | |
| 1009 | ENTRY(tramp_exit_compat) |
| 1010 | tramp_exit 32 |
| 1011 | END(tramp_exit_compat) |
| 1012 | |
| 1013 | .ltorg |
| 1014 | .popsection // .entry.tramp.text |
Will Deacon | 06fe41f | 2017-12-06 11:24:02 +0000 | [diff] [blame] | 1015 | #ifdef CONFIG_RANDOMIZE_BASE |
| 1016 | .pushsection ".rodata", "a" |
| 1017 | .align PAGE_SHIFT |
| 1018 | .globl __entry_tramp_data_start |
| 1019 | __entry_tramp_data_start: |
| 1020 | .quad vectors |
| 1021 | .popsection // .rodata |
| 1022 | #endif /* CONFIG_RANDOMIZE_BASE */ |
Will Deacon | a329b06 | 2017-11-14 14:07:40 +0000 | [diff] [blame] | 1023 | #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ |
| 1024 | |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 1025 | /* |
| 1026 | * Special system call wrappers. |
| 1027 | */ |
Catalin Marinas | 60ffc30 | 2012-03-05 11:49:27 +0000 | [diff] [blame] | 1028 | ENTRY(sys_rt_sigreturn_wrapper) |
| 1029 | mov x0, sp |
| 1030 | b sys_rt_sigreturn |
| 1031 | ENDPROC(sys_rt_sigreturn_wrapper) |