blob: 08a1122514859637c2b0a26bce903512d75ac083 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
2 * Copyright (c) 2013, ARM Limited. All rights reserved.
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>
36
37 .globl early_exceptions
38
39
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 */
117 sub sp, sp, #0x40
118 stp x0, x1, [sp, #0x0]
119 stp x2, x3, [sp, #0x10]
120 stp x4, x5, [sp, #0x20]
121 stp x6, x7, [sp, #0x30]
122 mov x19, x0
123 mov x20, x1
124 mov x21, x2
125
126 mov x0, #SYNC_EXCEPTION_AARCH64
127 bl plat_report_exception
128
129 bl read_esr
130 ubfx x1, x0, #ESR_EC_SHIFT, #ESR_EC_LENGTH
131 cmp x1, #EC_AARCH64_SMC
132 b.ne panic
133 mov x1, #RUN_IMAGE
134 cmp x19, x1
135 b.ne panic
136 mov x0, x20
137 mov x1, x21
138 mov x2, x3
139 mov x3, x4
140 bl display_boot_progress
141 mov x0, x20
142 bl write_elr
143 mov x0, x21
144 bl write_spsr
145 ubfx x0, x21, #MODE_EL_SHIFT, #2
146 cmp x0, #MODE_EL3
147 b.ne skip_mmu_teardown
148 /* ---------------------------------------------
149 * If BL31 is to be executed in EL3 as well
150 * then turn off the MMU so that it can perform
151 * its own setup. TODO: Assuming flat mapped
152 * translations here. Also all should go into a
153 * separate MMU teardown function
154 * ---------------------------------------------
155 */
156 mov x1, #(SCTLR_M_BIT | SCTLR_C_BIT | SCTLR_I_BIT)
157 bl read_sctlr
158 bic x0, x0, x1
159 bl write_sctlr
160 mov x0, #DCCISW
161 bl dcsw_op_all
162 bl tlbialle3
163skip_mmu_teardown:
164 ldp x6, x7, [sp, #0x30]
165 ldp x4, x5, [sp, #0x20]
166 ldp x2, x3, [sp, #0x10]
167 ldp x0, x1, [sp, #0x0]
168 add sp, sp, #0x40
169 eret
170panic:
171 b panic
172 .align 7
173IrqA64:
174 mov x0, #IRQ_AARCH64
175 bl plat_report_exception
176 b IrqA64
177
178 .align 7
179FiqA64:
180 mov x0, #FIQ_AARCH64
181 bl plat_report_exception
182 b FiqA64
183
184 .align 7
185SErrorA64:
186 mov x0, #SERROR_AARCH64
187 bl plat_report_exception
188 b SErrorA64
189
190 /* -----------------------------------------------------
191 * Lower EL using AArch32 : 0x0 - 0x180
192 * -----------------------------------------------------
193 */
194 .align 7
195SynchronousExceptionA32:
196 mov x0, #SYNC_EXCEPTION_AARCH32
197 bl plat_report_exception
198 b SynchronousExceptionA32
199
200 .align 7
201IrqA32:
202 mov x0, #IRQ_AARCH32
203 bl plat_report_exception
204 b IrqA32
205
206 .align 7
207FiqA32:
208 mov x0, #FIQ_AARCH32
209 bl plat_report_exception
210 b FiqA32
211
212 .align 7
213SErrorA32:
214 mov x0, #SERROR_AARCH32
215 bl plat_report_exception
216 b SErrorA32