blob: ef47f9e33ef9e887d66d8558d1f3a2de00d769bb [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>
36
37 .globl early_exceptions
Achin Gupta5443f2b2014-01-18 16:26:30 +000038 .weak display_boot_progress
Achin Gupta4f6ad662013-10-25 09:08:21 +010039
40 .section .text, "ax"; .align 11
41
42 /* -----------------------------------------------------
43 * Very simple exception handlers used by BL1 and BL2.
44 * Apart from one SMC exception all other traps loop
45 * endlessly.
46 * -----------------------------------------------------
47 */
48 .align 7
49early_exceptions:
50 /* -----------------------------------------------------
51 * Current EL with SP0 : 0x0 - 0x180
52 * -----------------------------------------------------
53 */
54SynchronousExceptionSP0:
55 mov x0, #SYNC_EXCEPTION_SP_EL0
56 bl plat_report_exception
57 b SynchronousExceptionSP0
58
59 .align 7
60IrqSP0:
61 mov x0, #IRQ_SP_EL0
62 bl plat_report_exception
63 b IrqSP0
64
65 .align 7
66FiqSP0:
67 mov x0, #FIQ_SP_EL0
68 bl plat_report_exception
69 b FiqSP0
70
71 .align 7
72SErrorSP0:
73 mov x0, #SERROR_SP_EL0
74 bl plat_report_exception
75 b SErrorSP0
76
77 /* -----------------------------------------------------
78 * Current EL with SPx: 0x200 - 0x380
79 * -----------------------------------------------------
80 */
81 .align 7
82SynchronousExceptionSPx:
83 mov x0, #SYNC_EXCEPTION_SP_ELX
84 bl plat_report_exception
85 b SynchronousExceptionSPx
86
87 .align 7
88IrqSPx:
89 mov x0, #IRQ_SP_ELX
90 bl plat_report_exception
91 b IrqSPx
92
93 .align 7
94FiqSPx:
95 mov x0, #FIQ_SP_ELX
96 bl plat_report_exception
97 b FiqSPx
98
99 .align 7
100SErrorSPx:
101 mov x0, #SERROR_SP_ELX
102 bl plat_report_exception
103 b SErrorSPx
104
105 /* -----------------------------------------------------
106 * Lower EL using AArch64 : 0x400 - 0x580
107 * -----------------------------------------------------
108 */
109 .align 7
110SynchronousExceptionA64:
111 /* ---------------------------------------------
112 * Only a single SMC exception from BL2 to ask
113 * BL1 to pass EL3 control to BL31 is expected
114 * here.
115 * ---------------------------------------------
116 */
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000117 b process_exception
118
119 .align 7
120IrqA64:
121 mov x0, #IRQ_AARCH64
122 bl plat_report_exception
123 b IrqA64
124
125 .align 7
126FiqA64:
127 mov x0, #FIQ_AARCH64
128 bl plat_report_exception
129 b FiqA64
130
131 .align 7
132SErrorA64:
133 mov x0, #SERROR_AARCH64
134 bl plat_report_exception
135 b SErrorA64
136
137 /* -----------------------------------------------------
138 * Lower EL using AArch32 : 0x0 - 0x180
139 * -----------------------------------------------------
140 */
141 .align 7
142SynchronousExceptionA32:
143 mov x0, #SYNC_EXCEPTION_AARCH32
144 bl plat_report_exception
145 b SynchronousExceptionA32
146
147 .align 7
148IrqA32:
149 mov x0, #IRQ_AARCH32
150 bl plat_report_exception
151 b IrqA32
152
153 .align 7
154FiqA32:
155 mov x0, #FIQ_AARCH32
156 bl plat_report_exception
157 b FiqA32
158
159 .align 7
160SErrorA32:
161 mov x0, #SERROR_AARCH32
162 bl plat_report_exception
163 b SErrorA32
164
165 .align 7
166
167process_exception:
Achin Gupta4f6ad662013-10-25 09:08:21 +0100168 sub sp, sp, #0x40
169 stp x0, x1, [sp, #0x0]
170 stp x2, x3, [sp, #0x10]
171 stp x4, x5, [sp, #0x20]
172 stp x6, x7, [sp, #0x30]
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000173
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174 mov x19, x0
175 mov x20, x1
176 mov x21, x2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100177 mov x0, #SYNC_EXCEPTION_AARCH64
178 bl plat_report_exception
179
180 bl read_esr
181 ubfx x1, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
182 cmp x1, #EC_AARCH64_SMC
183 b.ne panic
184 mov x1, #RUN_IMAGE
185 cmp x19, x1
186 b.ne panic
187 mov x0, x20
188 mov x1, x21
189 mov x2, x3
190 mov x3, x4
191 bl display_boot_progress
192 mov x0, x20
193 bl write_elr
194 mov x0, x21
195 bl write_spsr
196 ubfx x0, x21, #MODE_EL_SHIFT, #2
197 cmp x0, #MODE_EL3
198 b.ne skip_mmu_teardown
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000199
Achin Gupta4f6ad662013-10-25 09:08:21 +0100200 /* ---------------------------------------------
201 * If BL31 is to be executed in EL3 as well
202 * then turn off the MMU so that it can perform
203 * its own setup. TODO: Assuming flat mapped
204 * translations here. Also all should go into a
205 * separate MMU teardown function
206 * ---------------------------------------------
207 */
208 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT)
209 bl read_sctlr
210 bic x0, x0, x1
211 bl write_sctlr
212 mov x0, #DCCISW
213 bl dcsw_op_all
214 bl tlbialle3
215skip_mmu_teardown:
216 ldp x6, x7, [sp, #0x30]
217 ldp x4, x5, [sp, #0x20]
218 ldp x2, x3, [sp, #0x10]
219 ldp x0, x1, [sp, #0x0]
220 add sp, sp, #0x40
221 eret
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000222
Achin Gupta4f6ad662013-10-25 09:08:21 +0100223panic:
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000224 wfi
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225 b panic
Achin Gupta4f6ad662013-10-25 09:08:21 +0100226
Achin Gupta5443f2b2014-01-18 16:26:30 +0000227 /* -----------------------------------------------------
228 * BL1 redefines this function to print the fact that
229 * BL2 has done its job and BL31 is about to be loaded.
230 * This weak definition allows other bootloader stages
231 * to use the 'early_exceptions' without running into
232 * compilation errors.
233 * -----------------------------------------------------
234 */
235display_boot_progress:
236 ret