blob: 84bdae162c6e7b525206318f7d751743f8d4ebd1 [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
Achin Guptab739f222014-01-18 16:50:09 +000040 .section .vectors, "ax"; .align 11
Achin Gupta4f6ad662013-10-25 09:08:21 +010041
42 /* -----------------------------------------------------
Achin Guptab739f222014-01-18 16:50:09 +000043 * Very simple stackless exception handlers used by all
44 * bootloader stages. BL31 uses them before stacks are
45 * setup. BL1/BL2 use them throughout.
Achin Gupta4f6ad662013-10-25 09:08:21 +010046 * -----------------------------------------------------
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
Achin Gupta4f6ad662013-10-25 09:08:21 +0100118
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119 .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
Achin Gupta5443f2b2014-01-18 16:26:30 +0000164
165 .align 7
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000166
Achin Guptab739f222014-01-18 16:50:09 +0000167 .section .text, "ax"
Jeenu Viswambharan65f07302014-02-07 15:50:57 +0000168process_exception:
169 sub sp, sp, #0x40
170 stp x0, x1, [sp, #0x0]
171 stp x2, x3, [sp, #0x10]
172 stp x4, x5, [sp, #0x20]
173 stp x6, x7, [sp, #0x30]
174
175 mov x19, x0
176 mov x20, x1
177 mov x21, x2
178 mov x0, #SYNC_EXCEPTION_AARCH64
179 bl plat_report_exception
180
181 bl read_esr
182 ubfx x1, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
183 cmp x1, #EC_AARCH64_SMC
184 b.ne panic
185 mov x1, #RUN_IMAGE
186 cmp x19, x1
187 b.ne panic
188 mov x0, x20
189 mov x1, x21
190 mov x2, x3
191 mov x3, x4
192 bl display_boot_progress
193 mov x0, x20
194 bl write_elr
195 mov x0, x21
196 bl write_spsr
197 ubfx x0, x21, #MODE_EL_SHIFT, #2
198 cmp x0, #MODE_EL3
199 b.ne skip_mmu_teardown
200
201 /* ---------------------------------------------
202 * If BL31 is to be executed in EL3 as well
203 * then turn off the MMU so that it can perform
204 * its own setup. TODO: Assuming flat mapped
205 * translations here. Also all should go into a
206 * separate MMU teardown function
207 * ---------------------------------------------
208 */
209 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT)
210 bl read_sctlr
211 bic x0, x0, x1
212 bl write_sctlr
213 mov x0, #DCCISW
214 bl dcsw_op_all
215 bl tlbialle3
216skip_mmu_teardown:
217 ldp x6, x7, [sp, #0x30]
218 ldp x4, x5, [sp, #0x20]
219 ldp x2, x3, [sp, #0x10]
220 ldp x0, x1, [sp, #0x0]
221 add sp, sp, #0x40
222 eret
223
224panic:
225 wfi
226 b panic
227
Achin Gupta5443f2b2014-01-18 16:26:30 +0000228 /* -----------------------------------------------------
229 * BL1 redefines this function to print the fact that
230 * BL2 has done its job and BL31 is about to be loaded.
231 * This weak definition allows other bootloader stages
232 * to use the 'early_exceptions' without running into
233 * compilation errors.
234 * -----------------------------------------------------
235 */
236display_boot_progress:
237 ret