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> |
| 32 | #include <bl_common.h> |
| 33 | #include <bl1.h> |
| 34 | #include <platform.h> |
| 35 | #include <runtime_svc.h> |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 36 | #include <asm_macros.S> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | |
Sandrine Bailleux | 4d05275 | 2014-03-24 10:24:08 +0000 | [diff] [blame] | 38 | .globl bl1_exceptions |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 39 | |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 40 | .section .vectors, "ax"; .align 11 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | |
| 42 | /* ----------------------------------------------------- |
Sandrine Bailleux | 4d05275 | 2014-03-24 10:24:08 +0000 | [diff] [blame] | 43 | * Very simple stackless exception handlers used by BL1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 44 | * ----------------------------------------------------- |
| 45 | */ |
| 46 | .align 7 |
Sandrine Bailleux | 4d05275 | 2014-03-24 10:24:08 +0000 | [diff] [blame] | 47 | bl1_exceptions: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | /* ----------------------------------------------------- |
| 49 | * Current EL with SP0 : 0x0 - 0x180 |
| 50 | * ----------------------------------------------------- |
| 51 | */ |
| 52 | SynchronousExceptionSP0: |
| 53 | mov x0, #SYNC_EXCEPTION_SP_EL0 |
| 54 | bl plat_report_exception |
| 55 | b SynchronousExceptionSP0 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 56 | check_vector_size SynchronousExceptionSP0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 57 | |
| 58 | .align 7 |
| 59 | IrqSP0: |
| 60 | mov x0, #IRQ_SP_EL0 |
| 61 | bl plat_report_exception |
| 62 | b IrqSP0 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 63 | check_vector_size IrqSP0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 64 | |
| 65 | .align 7 |
| 66 | FiqSP0: |
| 67 | mov x0, #FIQ_SP_EL0 |
| 68 | bl plat_report_exception |
| 69 | b FiqSP0 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 70 | check_vector_size FiqSP0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 71 | |
| 72 | .align 7 |
| 73 | SErrorSP0: |
| 74 | mov x0, #SERROR_SP_EL0 |
| 75 | bl plat_report_exception |
| 76 | b SErrorSP0 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 77 | check_vector_size SErrorSP0 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 78 | |
| 79 | /* ----------------------------------------------------- |
| 80 | * Current EL with SPx: 0x200 - 0x380 |
| 81 | * ----------------------------------------------------- |
| 82 | */ |
| 83 | .align 7 |
| 84 | SynchronousExceptionSPx: |
| 85 | mov x0, #SYNC_EXCEPTION_SP_ELX |
| 86 | bl plat_report_exception |
| 87 | b SynchronousExceptionSPx |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 88 | check_vector_size SynchronousExceptionSPx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 89 | |
| 90 | .align 7 |
| 91 | IrqSPx: |
| 92 | mov x0, #IRQ_SP_ELX |
| 93 | bl plat_report_exception |
| 94 | b IrqSPx |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 95 | check_vector_size IrqSPx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 96 | |
| 97 | .align 7 |
| 98 | FiqSPx: |
| 99 | mov x0, #FIQ_SP_ELX |
| 100 | bl plat_report_exception |
| 101 | b FiqSPx |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 102 | check_vector_size FiqSPx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
| 104 | .align 7 |
| 105 | SErrorSPx: |
| 106 | mov x0, #SERROR_SP_ELX |
| 107 | bl plat_report_exception |
| 108 | b SErrorSPx |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 109 | check_vector_size SErrorSPx |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 110 | |
| 111 | /* ----------------------------------------------------- |
| 112 | * Lower EL using AArch64 : 0x400 - 0x580 |
| 113 | * ----------------------------------------------------- |
| 114 | */ |
| 115 | .align 7 |
| 116 | SynchronousExceptionA64: |
| 117 | /* --------------------------------------------- |
| 118 | * Only a single SMC exception from BL2 to ask |
| 119 | * BL1 to pass EL3 control to BL31 is expected |
| 120 | * here. |
| 121 | * --------------------------------------------- |
| 122 | */ |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 123 | b process_exception |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 124 | check_vector_size SynchronousExceptionA64 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 125 | |
| 126 | .align 7 |
| 127 | IrqA64: |
| 128 | mov x0, #IRQ_AARCH64 |
| 129 | bl plat_report_exception |
| 130 | b IrqA64 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 131 | check_vector_size IrqA64 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 132 | |
| 133 | .align 7 |
| 134 | FiqA64: |
| 135 | mov x0, #FIQ_AARCH64 |
| 136 | bl plat_report_exception |
| 137 | b FiqA64 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 138 | check_vector_size FiqA64 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 139 | |
| 140 | .align 7 |
| 141 | SErrorA64: |
| 142 | mov x0, #SERROR_AARCH64 |
| 143 | bl plat_report_exception |
| 144 | b SErrorA64 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 145 | check_vector_size SErrorA64 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 146 | |
| 147 | /* ----------------------------------------------------- |
| 148 | * Lower EL using AArch32 : 0x0 - 0x180 |
| 149 | * ----------------------------------------------------- |
| 150 | */ |
| 151 | .align 7 |
| 152 | SynchronousExceptionA32: |
| 153 | mov x0, #SYNC_EXCEPTION_AARCH32 |
| 154 | bl plat_report_exception |
| 155 | b SynchronousExceptionA32 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 156 | check_vector_size SynchronousExceptionA32 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 157 | |
| 158 | .align 7 |
| 159 | IrqA32: |
| 160 | mov x0, #IRQ_AARCH32 |
| 161 | bl plat_report_exception |
| 162 | b IrqA32 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 163 | check_vector_size IrqA32 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 164 | |
| 165 | .align 7 |
| 166 | FiqA32: |
| 167 | mov x0, #FIQ_AARCH32 |
| 168 | bl plat_report_exception |
| 169 | b FiqA32 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 170 | check_vector_size FiqA32 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 171 | |
| 172 | .align 7 |
| 173 | SErrorA32: |
| 174 | mov x0, #SERROR_AARCH32 |
| 175 | bl plat_report_exception |
| 176 | b SErrorA32 |
Jeenu Viswambharan | a7934d6 | 2014-02-07 15:53:18 +0000 | [diff] [blame] | 177 | check_vector_size SErrorA32 |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 178 | |
| 179 | .align 7 |
| 180 | |
Achin Gupta | b739f22 | 2014-01-18 16:50:09 +0000 | [diff] [blame] | 181 | .section .text, "ax" |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 182 | process_exception: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 183 | sub sp, sp, #0x40 |
| 184 | stp x0, x1, [sp, #0x0] |
| 185 | stp x2, x3, [sp, #0x10] |
| 186 | stp x4, x5, [sp, #0x20] |
| 187 | stp x6, x7, [sp, #0x30] |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 188 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 189 | mov x19, x0 |
| 190 | mov x20, x1 |
| 191 | mov x21, x2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 192 | mov x0, #SYNC_EXCEPTION_AARCH64 |
| 193 | bl plat_report_exception |
| 194 | |
Vikram Kanigiri | 78a6e0c | 2014-03-11 17:41:00 +0000 | [diff] [blame] | 195 | bl read_esr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 196 | ubfx x1, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH |
| 197 | cmp x1, #EC_AARCH64_SMC |
| 198 | b.ne panic |
| 199 | mov x1, #RUN_IMAGE |
| 200 | cmp x19, x1 |
| 201 | b.ne panic |
| 202 | mov x0, x20 |
| 203 | mov x1, x21 |
| 204 | mov x2, x3 |
| 205 | mov x3, x4 |
| 206 | bl display_boot_progress |
| 207 | mov x0, x20 |
| 208 | bl write_elr |
| 209 | mov x0, x21 |
| 210 | bl write_spsr |
| 211 | ubfx x0, x21, #MODE_EL_SHIFT, #2 |
| 212 | cmp x0, #MODE_EL3 |
| 213 | b.ne skip_mmu_teardown |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 214 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 215 | /* --------------------------------------------- |
| 216 | * If BL31 is to be executed in EL3 as well |
| 217 | * then turn off the MMU so that it can perform |
| 218 | * its own setup. TODO: Assuming flat mapped |
| 219 | * translations here. Also all should go into a |
| 220 | * separate MMU teardown function |
| 221 | * --------------------------------------------- |
| 222 | */ |
| 223 | mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT) |
Vikram Kanigiri | 78a6e0c | 2014-03-11 17:41:00 +0000 | [diff] [blame] | 224 | bl read_sctlr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 225 | bic x0, x0, x1 |
Vikram Kanigiri | 78a6e0c | 2014-03-11 17:41:00 +0000 | [diff] [blame] | 226 | bl write_sctlr_el3 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 227 | mov x0, #DCCISW |
| 228 | bl dcsw_op_all |
| 229 | bl tlbialle3 |
| 230 | skip_mmu_teardown: |
| 231 | ldp x6, x7, [sp, #0x30] |
| 232 | ldp x4, x5, [sp, #0x20] |
| 233 | ldp x2, x3, [sp, #0x10] |
| 234 | ldp x0, x1, [sp, #0x0] |
| 235 | add sp, sp, #0x40 |
| 236 | eret |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 237 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 238 | panic: |
Jeenu Viswambharan | 65f0730 | 2014-02-07 15:50:57 +0000 | [diff] [blame] | 239 | wfi |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 240 | b panic |