blob: a80d17884f4a5e2b30eeceb85d2315b88ec39dec [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
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 Viswambharana7934d62014-02-07 15:53:18 +000036#include <asm_macros.S>
Achin Gupta4f6ad662013-10-25 09:08:21 +010037
Sandrine Bailleux4d052752014-03-24 10:24:08 +000038 .globl bl1_exceptions
Achin Gupta4f6ad662013-10-25 09:08:21 +010039
Achin Guptab739f222014-01-18 16:50:09 +000040 .section .vectors, "ax"; .align 11
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
42 /* -----------------------------------------------------
Sandrine Bailleux4d052752014-03-24 10:24:08 +000043 * Very simple stackless exception handlers used by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +010044 * -----------------------------------------------------
45 */
46 .align 7
Sandrine Bailleux4d052752014-03-24 10:24:08 +000047bl1_exceptions:
Achin Gupta4f6ad662013-10-25 09:08:21 +010048 /* -----------------------------------------------------
49 * Current EL with SP0 : 0x0 - 0x180
50 * -----------------------------------------------------
51 */
52SynchronousExceptionSP0:
53 mov x0, #SYNC_EXCEPTION_SP_EL0
54 bl plat_report_exception
55 b SynchronousExceptionSP0
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000056 check_vector_size SynchronousExceptionSP0
Achin Gupta4f6ad662013-10-25 09:08:21 +010057
58 .align 7
59IrqSP0:
60 mov x0, #IRQ_SP_EL0
61 bl plat_report_exception
62 b IrqSP0
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000063 check_vector_size IrqSP0
Achin Gupta4f6ad662013-10-25 09:08:21 +010064
65 .align 7
66FiqSP0:
67 mov x0, #FIQ_SP_EL0
68 bl plat_report_exception
69 b FiqSP0
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000070 check_vector_size FiqSP0
Achin Gupta4f6ad662013-10-25 09:08:21 +010071
72 .align 7
73SErrorSP0:
74 mov x0, #SERROR_SP_EL0
75 bl plat_report_exception
76 b SErrorSP0
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000077 check_vector_size SErrorSP0
Achin Gupta4f6ad662013-10-25 09:08:21 +010078
79 /* -----------------------------------------------------
80 * Current EL with SPx: 0x200 - 0x380
81 * -----------------------------------------------------
82 */
83 .align 7
84SynchronousExceptionSPx:
85 mov x0, #SYNC_EXCEPTION_SP_ELX
86 bl plat_report_exception
87 b SynchronousExceptionSPx
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000088 check_vector_size SynchronousExceptionSPx
Achin Gupta4f6ad662013-10-25 09:08:21 +010089
90 .align 7
91IrqSPx:
92 mov x0, #IRQ_SP_ELX
93 bl plat_report_exception
94 b IrqSPx
Jeenu Viswambharana7934d62014-02-07 15:53:18 +000095 check_vector_size IrqSPx
Achin Gupta4f6ad662013-10-25 09:08:21 +010096
97 .align 7
98FiqSPx:
99 mov x0, #FIQ_SP_ELX
100 bl plat_report_exception
101 b FiqSPx
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000102 check_vector_size FiqSPx
Achin Gupta4f6ad662013-10-25 09:08:21 +0100103
104 .align 7
105SErrorSPx:
106 mov x0, #SERROR_SP_ELX
107 bl plat_report_exception
108 b SErrorSPx
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000109 check_vector_size SErrorSPx
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
111 /* -----------------------------------------------------
112 * Lower EL using AArch64 : 0x400 - 0x580
113 * -----------------------------------------------------
114 */
115 .align 7
116SynchronousExceptionA64:
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 Viswambharan65f07302014-02-07 15:50:57 +0000123 b process_exception
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000124 check_vector_size SynchronousExceptionA64
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000125
126 .align 7
127IrqA64:
128 mov x0, #IRQ_AARCH64
129 bl plat_report_exception
130 b IrqA64
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000131 check_vector_size IrqA64
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000132
133 .align 7
134FiqA64:
135 mov x0, #FIQ_AARCH64
136 bl plat_report_exception
137 b FiqA64
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000138 check_vector_size FiqA64
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000139
140 .align 7
141SErrorA64:
142 mov x0, #SERROR_AARCH64
143 bl plat_report_exception
144 b SErrorA64
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000145 check_vector_size SErrorA64
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000146
147 /* -----------------------------------------------------
148 * Lower EL using AArch32 : 0x0 - 0x180
149 * -----------------------------------------------------
150 */
151 .align 7
152SynchronousExceptionA32:
153 mov x0, #SYNC_EXCEPTION_AARCH32
154 bl plat_report_exception
155 b SynchronousExceptionA32
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000156 check_vector_size SynchronousExceptionA32
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000157
158 .align 7
159IrqA32:
160 mov x0, #IRQ_AARCH32
161 bl plat_report_exception
162 b IrqA32
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000163 check_vector_size IrqA32
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000164
165 .align 7
166FiqA32:
167 mov x0, #FIQ_AARCH32
168 bl plat_report_exception
169 b FiqA32
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000170 check_vector_size FiqA32
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000171
172 .align 7
173SErrorA32:
174 mov x0, #SERROR_AARCH32
175 bl plat_report_exception
176 b SErrorA32
Jeenu Viswambharana7934d62014-02-07 15:53:18 +0000177 check_vector_size SErrorA32
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000178
179 .align 7
180
Achin Guptab739f222014-01-18 16:50:09 +0000181 .section .text, "ax"
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000182process_exception:
Achin Gupta4f6ad662013-10-25 09:08:21 +0100183 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 Viswambharan65f07302014-02-07 15:50:57 +0000188
Achin Gupta4f6ad662013-10-25 09:08:21 +0100189 mov x19, x0
190 mov x20, x1
191 mov x21, x2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100192 mov x0, #SYNC_EXCEPTION_AARCH64
193 bl plat_report_exception
194
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000195 bl read_esr_el3
Achin Gupta4f6ad662013-10-25 09:08:21 +0100196 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 Viswambharan65f07302014-02-07 15:50:57 +0000214
Achin Gupta4f6ad662013-10-25 09:08:21 +0100215 /* ---------------------------------------------
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 Kanigiri78a6e0c2014-03-11 17:41:00 +0000224 bl read_sctlr_el3
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225 bic x0, x0, x1
Vikram Kanigiri78a6e0c2014-03-11 17:41:00 +0000226 bl write_sctlr_el3
Achin Gupta4f6ad662013-10-25 09:08:21 +0100227 mov x0, #DCCISW
228 bl dcsw_op_all
229 bl tlbialle3
230skip_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 Viswambharan65f07302014-02-07 15:50:57 +0000237
Achin Gupta4f6ad662013-10-25 09:08:21 +0100238panic:
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000239 wfi
Achin Gupta4f6ad662013-10-25 09:08:21 +0100240 b panic