Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch.h> |
Dan Handley | 35e98e5 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 32 | #include <asm_macros.S> |
| 33 | #include <cm_macros.S> |
Dan Handley | 97043ac | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 34 | #include <context.h> |
| 35 | #include <platform.h> |
| 36 | #include <runtime_svc.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | |
| 38 | .globl runtime_exceptions |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 39 | .globl el3_exit |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 41 | .macro save_x18_to_x29_sp_el0 |
| 42 | stp x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18] |
| 43 | stp x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20] |
| 44 | stp x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22] |
| 45 | stp x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24] |
| 46 | stp x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26] |
| 47 | stp x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28] |
| 48 | mrs x18, sp_el0 |
| 49 | str x18, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_SP_EL0] |
| 50 | .endm |
| 51 | |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 52 | .section .vectors, "ax"; .align 11 |
| 53 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 54 | .align 7 |
| 55 | runtime_exceptions: |
| 56 | /* ----------------------------------------------------- |
| 57 | * Current EL with _sp_el0 : 0x0 - 0x180 |
| 58 | * ----------------------------------------------------- |
| 59 | */ |
| 60 | sync_exception_sp_el0: |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 61 | /* ----------------------------------------------------- |
| 62 | * We don't expect any synchronous exceptions from EL3 |
| 63 | * ----------------------------------------------------- |
| 64 | */ |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 65 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 66 | check_vector_size sync_exception_sp_el0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 67 | |
| 68 | .align 7 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 69 | /* ----------------------------------------------------- |
| 70 | * EL3 code is non-reentrant. Any asynchronous exception |
| 71 | * is a serious error. Loop infinitely. |
| 72 | * ----------------------------------------------------- |
| 73 | */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | irq_sp_el0: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 75 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 76 | check_vector_size irq_sp_el0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 77 | |
| 78 | .align 7 |
| 79 | fiq_sp_el0: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 80 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 81 | check_vector_size fiq_sp_el0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 82 | |
| 83 | .align 7 |
| 84 | serror_sp_el0: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 85 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 86 | check_vector_size serror_sp_el0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 87 | |
| 88 | /* ----------------------------------------------------- |
| 89 | * Current EL with SPx: 0x200 - 0x380 |
| 90 | * ----------------------------------------------------- |
| 91 | */ |
| 92 | .align 7 |
| 93 | sync_exception_sp_elx: |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 94 | /* ----------------------------------------------------- |
| 95 | * This exception will trigger if anything went wrong |
| 96 | * during a previous exception entry or exit or while |
| 97 | * handling an earlier unexpected synchronous exception. |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 98 | * There is a high probability that SP_EL3 is corrupted. |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 99 | * ----------------------------------------------------- |
| 100 | */ |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 101 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 102 | check_vector_size sync_exception_sp_elx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
| 104 | .align 7 |
| 105 | irq_sp_elx: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 106 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 107 | check_vector_size irq_sp_elx |
| 108 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 109 | .align 7 |
| 110 | fiq_sp_elx: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 111 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 112 | check_vector_size fiq_sp_elx |
| 113 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 114 | .align 7 |
| 115 | serror_sp_elx: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 116 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 117 | check_vector_size serror_sp_elx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 118 | |
| 119 | /* ----------------------------------------------------- |
| 120 | * Lower EL using AArch64 : 0x400 - 0x580 |
| 121 | * ----------------------------------------------------- |
| 122 | */ |
| 123 | .align 7 |
| 124 | sync_exception_aarch64: |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 125 | /* ----------------------------------------------------- |
| 126 | * This exception vector will be the entry point for |
| 127 | * SMCs and traps that are unhandled at lower ELs most |
| 128 | * commonly. SP_EL3 should point to a valid cpu context |
| 129 | * where the general purpose and system register state |
| 130 | * can be saved. |
| 131 | * ----------------------------------------------------- |
| 132 | */ |
| 133 | handle_sync_exception |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 134 | check_vector_size sync_exception_aarch64 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 135 | |
| 136 | .align 7 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 137 | /* ----------------------------------------------------- |
| 138 | * Asynchronous exceptions from lower ELs are not |
| 139 | * currently supported. Report their occurrence. |
| 140 | * ----------------------------------------------------- |
| 141 | */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 142 | irq_aarch64: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 143 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 144 | check_vector_size irq_aarch64 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 145 | |
| 146 | .align 7 |
| 147 | fiq_aarch64: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 148 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 149 | check_vector_size fiq_aarch64 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | |
| 151 | .align 7 |
| 152 | serror_aarch64: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 153 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 154 | check_vector_size serror_aarch64 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 155 | |
| 156 | /* ----------------------------------------------------- |
| 157 | * Lower EL using AArch32 : 0x600 - 0x780 |
| 158 | * ----------------------------------------------------- |
| 159 | */ |
| 160 | .align 7 |
| 161 | sync_exception_aarch32: |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 162 | /* ----------------------------------------------------- |
| 163 | * This exception vector will be the entry point for |
| 164 | * SMCs and traps that are unhandled at lower ELs most |
| 165 | * commonly. SP_EL3 should point to a valid cpu context |
| 166 | * where the general purpose and system register state |
| 167 | * can be saved. |
| 168 | * ----------------------------------------------------- |
| 169 | */ |
| 170 | handle_sync_exception |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 171 | check_vector_size sync_exception_aarch32 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 172 | |
| 173 | .align 7 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 174 | /* ----------------------------------------------------- |
| 175 | * Asynchronous exceptions from lower ELs are not |
| 176 | * currently supported. Report their occurrence. |
| 177 | * ----------------------------------------------------- |
| 178 | */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 179 | irq_aarch32: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 180 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 181 | check_vector_size irq_aarch32 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 182 | |
| 183 | .align 7 |
| 184 | fiq_aarch32: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 185 | bl dump_intr_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 186 | check_vector_size fiq_aarch32 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 187 | |
| 188 | .align 7 |
| 189 | serror_aarch32: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 190 | bl dump_state_and_die |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 191 | check_vector_size serror_aarch32 |
| 192 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 193 | .align 7 |
| 194 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 195 | /* ----------------------------------------------------- |
| 196 | * The following code handles secure monitor calls. |
| 197 | * Depending upon the execution state from where the SMC |
| 198 | * has been invoked, it frees some general purpose |
| 199 | * registers to perform the remaining tasks. They |
| 200 | * involve finding the runtime service handler that is |
| 201 | * the target of the SMC & switching to runtime stacks |
| 202 | * (SP_EL0) before calling the handler. |
| 203 | * |
| 204 | * Note that x30 has been explicitly saved and can be |
| 205 | * used here |
| 206 | * ----------------------------------------------------- |
| 207 | */ |
Andrew Thoelke | 0a30cf5 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 208 | func smc_handler |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 209 | smc_handler32: |
| 210 | /* Check whether aarch32 issued an SMC64 */ |
| 211 | tbnz x0, #FUNCID_CC_SHIFT, smc_prohibited |
| 212 | |
| 213 | /* ----------------------------------------------------- |
| 214 | * Since we're are coming from aarch32, x8-x18 need to |
| 215 | * be saved as per SMC32 calling convention. If a lower |
| 216 | * EL in aarch64 is making an SMC32 call then it must |
| 217 | * have saved x8-x17 already therein. |
| 218 | * ----------------------------------------------------- |
| 219 | */ |
| 220 | stp x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8] |
| 221 | stp x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10] |
| 222 | stp x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12] |
| 223 | stp x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14] |
| 224 | stp x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16] |
| 225 | |
| 226 | /* x4-x7, x18, sp_el0 are saved below */ |
| 227 | |
| 228 | smc_handler64: |
| 229 | /* ----------------------------------------------------- |
| 230 | * Populate the parameters for the SMC handler. We |
| 231 | * already have x0-x4 in place. x5 will point to a |
| 232 | * cookie (not used now). x6 will point to the context |
| 233 | * structure (SP_EL3) and x7 will contain flags we need |
| 234 | * to pass to the handler Hence save x5-x7. Note that x4 |
| 235 | * only needs to be preserved for AArch32 callers but we |
| 236 | * do it for AArch64 callers as well for convenience |
| 237 | * ----------------------------------------------------- |
| 238 | */ |
| 239 | stp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] |
| 240 | stp x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6] |
| 241 | |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 242 | /* Save rest of the gpregs and sp_el0*/ |
| 243 | save_x18_to_x29_sp_el0 |
| 244 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 245 | mov x5, xzr |
| 246 | mov x6, sp |
| 247 | |
| 248 | /* Get the unique owning entity number */ |
| 249 | ubfx x16, x0, #FUNCID_OEN_SHIFT, #FUNCID_OEN_WIDTH |
| 250 | ubfx x15, x0, #FUNCID_TYPE_SHIFT, #FUNCID_TYPE_WIDTH |
| 251 | orr x16, x16, x15, lsl #FUNCID_OEN_WIDTH |
| 252 | |
| 253 | adr x11, (__RT_SVC_DESCS_START__ + RT_SVC_DESC_HANDLE) |
| 254 | |
| 255 | /* Load descriptor index from array of indices */ |
| 256 | adr x14, rt_svc_descs_indices |
| 257 | ldrb w15, [x14, x16] |
| 258 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 259 | /* ----------------------------------------------------- |
| 260 | * Restore the saved C runtime stack value which will |
| 261 | * become the new SP_EL0 i.e. EL3 runtime stack. It was |
| 262 | * saved in the 'cpu_context' structure prior to the last |
| 263 | * ERET from EL3. |
| 264 | * ----------------------------------------------------- |
| 265 | */ |
| 266 | ldr x12, [x6, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP] |
| 267 | |
| 268 | /* |
| 269 | * Any index greater than 127 is invalid. Check bit 7 for |
| 270 | * a valid index |
| 271 | */ |
| 272 | tbnz w15, 7, smc_unknown |
| 273 | |
| 274 | /* Switch to SP_EL0 */ |
| 275 | msr spsel, #0 |
| 276 | |
| 277 | /* ----------------------------------------------------- |
| 278 | * Get the descriptor using the index |
| 279 | * x11 = (base + off), x15 = index |
| 280 | * |
| 281 | * handler = (base + off) + (index << log2(size)) |
| 282 | * ----------------------------------------------------- |
| 283 | */ |
| 284 | lsl w10, w15, #RT_SVC_SIZE_LOG2 |
| 285 | ldr x15, [x11, w10, uxtw] |
| 286 | |
| 287 | /* ----------------------------------------------------- |
| 288 | * Save the SPSR_EL3, ELR_EL3, & SCR_EL3 in case there |
| 289 | * is a world switch during SMC handling. |
| 290 | * TODO: Revisit if all system registers can be saved |
| 291 | * later. |
| 292 | * ----------------------------------------------------- |
| 293 | */ |
| 294 | mrs x16, spsr_el3 |
| 295 | mrs x17, elr_el3 |
| 296 | mrs x18, scr_el3 |
| 297 | stp x16, x17, [x6, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3] |
| 298 | stp x18, xzr, [x6, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3] |
| 299 | |
| 300 | /* Copy SCR_EL3.NS bit to the flag to indicate caller's security */ |
| 301 | bfi x7, x18, #0, #1 |
| 302 | |
| 303 | mov sp, x12 |
| 304 | |
| 305 | /* ----------------------------------------------------- |
| 306 | * Call the Secure Monitor Call handler and then drop |
| 307 | * directly into el3_exit() which will program any |
| 308 | * remaining architectural state prior to issuing the |
| 309 | * ERET to the desired lower EL. |
| 310 | * ----------------------------------------------------- |
| 311 | */ |
| 312 | #if DEBUG |
| 313 | cbz x15, rt_svc_fw_critical_error |
| 314 | #endif |
| 315 | blr x15 |
| 316 | |
| 317 | /* ----------------------------------------------------- |
| 318 | * This routine assumes that the SP_EL3 is pointing to |
| 319 | * a valid context structure from where the gp regs and |
| 320 | * other special registers can be retrieved. |
Andrew Thoelke | 0a30cf5 | 2014-03-18 13:46:55 +0000 | [diff] [blame] | 321 | * |
| 322 | * Keep it in the same section as smc_handler as this |
| 323 | * function uses a fall-through to el3_exit |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 324 | * ----------------------------------------------------- |
| 325 | */ |
| 326 | el3_exit: ; .type el3_exit, %function |
| 327 | /* ----------------------------------------------------- |
| 328 | * Save the current SP_EL0 i.e. the EL3 runtime stack |
| 329 | * which will be used for handling the next SMC. Then |
| 330 | * switch to SP_EL3 |
| 331 | * ----------------------------------------------------- |
| 332 | */ |
| 333 | mov x17, sp |
| 334 | msr spsel, #1 |
| 335 | str x17, [sp, #CTX_EL3STATE_OFFSET + CTX_RUNTIME_SP] |
| 336 | |
| 337 | /* ----------------------------------------------------- |
| 338 | * Restore SPSR_EL3, ELR_EL3 and SCR_EL3 prior to ERET |
| 339 | * ----------------------------------------------------- |
| 340 | */ |
| 341 | ldp x18, xzr, [sp, #CTX_EL3STATE_OFFSET + CTX_SCR_EL3] |
| 342 | ldp x16, x17, [sp, #CTX_EL3STATE_OFFSET + CTX_SPSR_EL3] |
| 343 | msr scr_el3, x18 |
| 344 | msr spsr_el3, x16 |
| 345 | msr elr_el3, x17 |
| 346 | |
| 347 | /* Restore saved general purpose registers and return */ |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 348 | b restore_gp_registers_eret |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 349 | |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 350 | smc_unknown: |
| 351 | /* |
| 352 | * Here we restore x4-x18 regardless of where we came from. AArch32 |
| 353 | * callers will find the registers contents unchanged, but AArch64 |
| 354 | * callers will find the registers modified (with stale earlier NS |
| 355 | * content). Either way, we aren't leaking any secure information |
| 356 | * through them |
| 357 | */ |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 358 | mov w0, #SMC_UNK |
| 359 | b restore_gp_registers_callee_eret |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 360 | |
| 361 | smc_prohibited: |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 362 | ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR] |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 363 | mov w0, #SMC_UNK |
| 364 | eret |
| 365 | |
| 366 | rt_svc_fw_critical_error: |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 367 | msr spsel, #1 /* Switch to SP_ELx */ |
| 368 | bl dump_state_and_die |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 369 | |
| 370 | /* ----------------------------------------------------- |
| 371 | * The following functions are used to saved and restore |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 372 | * all the general pupose registers. Ideally we would |
| 373 | * only save and restore the callee saved registers when |
| 374 | * a world switch occurs but that type of implementation |
| 375 | * is more complex. So currently we will always save and |
| 376 | * restore these registers on entry and exit of EL3. |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 377 | * These are not macros to ensure their invocation fits |
| 378 | * within the 32 instructions per exception vector. |
| 379 | * ----------------------------------------------------- |
| 380 | */ |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 381 | func save_gp_registers |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 382 | stp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] |
| 383 | stp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
| 384 | stp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] |
| 385 | stp x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6] |
| 386 | stp x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8] |
| 387 | stp x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10] |
| 388 | stp x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12] |
| 389 | stp x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14] |
| 390 | stp x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16] |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 391 | save_x18_to_x29_sp_el0 |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 392 | ret |
| 393 | |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 394 | func restore_gp_registers_eret |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 395 | ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] |
| 396 | ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
| 397 | |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 398 | restore_gp_registers_callee_eret: |
Jeenu Viswambharan | caa8493 | 2014-02-06 10:36:15 +0000 | [diff] [blame] | 399 | ldp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] |
| 400 | ldp x6, x7, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X6] |
| 401 | ldp x8, x9, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X8] |
| 402 | ldp x10, x11, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X10] |
| 403 | ldp x12, x13, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X12] |
| 404 | ldp x14, x15, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X14] |
Soby Mathew | c3260f9 | 2014-04-30 15:36:37 +0100 | [diff] [blame] | 405 | ldp x18, x19, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X18] |
| 406 | ldp x20, x21, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X20] |
| 407 | ldp x22, x23, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X22] |
| 408 | ldp x24, x25, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X24] |
| 409 | ldp x26, x27, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X26] |
| 410 | ldp x28, x29, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X28] |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 411 | ldp x30, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR] |
| 412 | msr sp_el0, x17 |
| 413 | ldp x16, x17, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X16] |
| 414 | eret |