blob: 21f74a42f9527e646bf3e9dca8f1e2be890a4cc1 [file] [log] [blame]
Soby Mathewa43d4312014-04-07 15:28:55 +01001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. 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#include <arch.h>
31#include <asm_macros.S>
32#include <context.h>
33#include <plat_macros.S>
Sandrine Bailleuxe4d13382014-05-27 15:46:07 +010034#include <platform_def.h>
Soby Mathewa43d4312014-04-07 15:28:55 +010035
36 .globl get_crash_stack
37 .globl dump_state_and_die
38 .globl dump_intr_state_and_die
39
Andrew Thoelke9c22b322014-06-03 11:50:53 +010040#if CRASH_REPORTING
Soby Mathewa43d4312014-04-07 15:28:55 +010041 /* ------------------------------------------------------
42 * The below section deals with dumping the system state
43 * when an unhandled exception is taken in EL3.
44 * The layout and the names of the registers which will
45 * be dumped during a unhandled exception is given below.
46 * ------------------------------------------------------
47 */
48.section .rodata.dump_reg_name, "aS"
49caller_saved_regs: .asciz "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",\
50 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16",\
51 "x17", "x18", ""
52
53callee_saved_regs: .asciz "x19", "x20", "x21", "x22", "x23", "x24",\
54 "x25", "x26", "x27", "x28", "x29", "x30", ""
55
56el3_sys_regs: .asciz "scr_el3", "sctlr_el3", "cptr_el3", "tcr_el3",\
57 "daif", "mair_el3", "spsr_el3", "elr_el3", "ttbr0_el3", "esr_el3",\
58 "sp_el3", "far_el3", ""
59
60non_el3_sys_0_regs: .asciz "spsr_el1", "elr_el1", "spsr_abt", "spsr_und",\
61 "spsr_irq", "spsr_fiq", "sctlr_el1", "actlr_el1", "cpacr_el1",\
62 "csselr_el1", "sp_el1", "esr_el1", "ttbr0_el1", "ttbr1_el1",\
63 "mair_el1", "amair_el1", "tcr_el1", "tpidr_el1", ""
64
65non_el3_sys_1_regs: .asciz "tpidr_el0", "tpidrro_el0", "dacr32_el2",\
66 "ifsr32_el2", "par_el1", "far_el1", "afsr0_el1", "afsr1_el1",\
67 "contextidr_el1", "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0",\
68 "cntv_ctl_el0", "cntv_cval_el0", "cntkctl_el1", "fpexc32_el2",\
69 "sp_el0", ""
70
71 /* -----------------------------------------------------
72 * Currently we are stack limited. Hence make sure that
73 * we dont try to dump more than 20 registers using the
74 * stack.
75 * -----------------------------------------------------
76 */
77
78#define REG_SIZE 0x8
79
80/* The caller saved registers are X0 to X18 */
81#define CALLER_SAVED_REG_SIZE (20 * REG_SIZE)
82/* The caller saved registers are X19 to X30 */
83#define CALLEE_SAVED_REG_SIZE (12 * REG_SIZE)
84/* The EL3 sys regs*/
85#define EL3_SYS_REG_SIZE (12 * REG_SIZE)
86/* The non EL3 sys regs set-0 */
87#define NON_EL3_SYS_0_REG_SIZE (18 * REG_SIZE)
88/* The non EL3 sys regs set-1 */
89#define NON_EL3_SYS_1_REG_SIZE (18 * REG_SIZE)
90
91 .macro print_caller_saved_regs
92 sub sp, sp, #CALLER_SAVED_REG_SIZE
93 stp x0, x1, [sp]
94 stp x2, x3, [sp, #(REG_SIZE * 2)]
95 stp x4, x5, [sp, #(REG_SIZE * 4)]
96 stp x6, x7, [sp, #(REG_SIZE * 6)]
97 stp x8, x9, [sp, #(REG_SIZE * 8)]
98 stp x10, x11, [sp, #(REG_SIZE * 10)]
99 stp x12, x13, [sp, #(REG_SIZE * 12)]
100 stp x14, x15, [sp, #(REG_SIZE * 14)]
101 stp x16, x17, [sp, #(REG_SIZE * 16)]
102 stp x18, xzr, [sp, #(REG_SIZE * 18)]
103 adr x0, caller_saved_regs
104 mov x1, sp
105 bl print_string_value
106 add sp, sp, #CALLER_SAVED_REG_SIZE
107 .endm
108
109 .macro print_callee_saved_regs
110 sub sp, sp, CALLEE_SAVED_REG_SIZE
111 stp x19, x20, [sp]
112 stp x21, x22, [sp, #(REG_SIZE * 2)]
113 stp x23, x24, [sp, #(REG_SIZE * 4)]
114 stp x25, x26, [sp, #(REG_SIZE * 6)]
115 stp x27, x28, [sp, #(REG_SIZE * 8)]
116 stp x29, x30, [sp, #(REG_SIZE * 10)]
117 adr x0, callee_saved_regs
118 mov x1, sp
119 bl print_string_value
120 add sp, sp, #CALLEE_SAVED_REG_SIZE
121 .endm
122
123 .macro print_el3_sys_regs
124 sub sp, sp, #EL3_SYS_REG_SIZE
125 mrs x9, scr_el3
126 mrs x10, sctlr_el3
127 mrs x11, cptr_el3
128 mrs x12, tcr_el3
129 mrs x13, daif
130 mrs x14, mair_el3
131 mrs x15, spsr_el3 /*save the elr and spsr regs seperately*/
132 mrs x16, elr_el3
133 mrs x17, ttbr0_el3
134 mrs x8, esr_el3
135 mrs x7, far_el3
136
137 stp x9, x10, [sp]
138 stp x11, x12, [sp, #(REG_SIZE * 2)]
139 stp x13, x14, [sp, #(REG_SIZE * 4)]
140 stp x15, x16, [sp, #(REG_SIZE * 6)]
141 stp x17, x8, [sp, #(REG_SIZE * 8)]
142 stp x0, x7, [sp, #(REG_SIZE * 10)] /* sp_el3 is in x0 */
143
144 adr x0, el3_sys_regs
145 mov x1, sp
146 bl print_string_value
147 add sp, sp, #EL3_SYS_REG_SIZE
148 .endm
149
150 .macro print_non_el3_sys_0_regs
151 sub sp, sp, #NON_EL3_SYS_0_REG_SIZE
152 mrs x9, spsr_el1
153 mrs x10, elr_el1
154 mrs x11, spsr_abt
155 mrs x12, spsr_und
156 mrs x13, spsr_irq
157 mrs x14, spsr_fiq
158 mrs x15, sctlr_el1
159 mrs x16, actlr_el1
160 mrs x17, cpacr_el1
161 mrs x8, csselr_el1
162
163 stp x9, x10, [sp]
164 stp x11, x12, [sp, #(REG_SIZE * 2)]
165 stp x13, x14, [sp, #(REG_SIZE * 4)]
166 stp x15, x16, [sp, #(REG_SIZE * 6)]
167 stp x17, x8, [sp, #(REG_SIZE * 8)]
168
169 mrs x10, sp_el1
170 mrs x11, esr_el1
171 mrs x12, ttbr0_el1
172 mrs x13, ttbr1_el1
173 mrs x14, mair_el1
174 mrs x15, amair_el1
175 mrs x16, tcr_el1
176 mrs x17, tpidr_el1
177
178 stp x10, x11, [sp, #(REG_SIZE * 10)]
179 stp x12, x13, [sp, #(REG_SIZE * 12)]
180 stp x14, x15, [sp, #(REG_SIZE * 14)]
181 stp x16, x17, [sp, #(REG_SIZE * 16)]
182
183 adr x0, non_el3_sys_0_regs
184 mov x1, sp
185 bl print_string_value
186 add sp, sp, #NON_EL3_SYS_0_REG_SIZE
187 .endm
188
189 .macro print_non_el3_sys_1_regs
190 sub sp, sp, #NON_EL3_SYS_1_REG_SIZE
191
192 mrs x9, tpidr_el0
193 mrs x10, tpidrro_el0
194 mrs x11, dacr32_el2
195 mrs x12, ifsr32_el2
196 mrs x13, par_el1
197 mrs x14, far_el1
198 mrs x15, afsr0_el1
199 mrs x16, afsr1_el1
200 mrs x17, contextidr_el1
201 mrs x8, vbar_el1
202
203 stp x9, x10, [sp]
204 stp x11, x12, [sp, #(REG_SIZE * 2)]
205 stp x13, x14, [sp, #(REG_SIZE * 4)]
206 stp x15, x16, [sp, #(REG_SIZE * 6)]
207 stp x17, x8, [sp, #(REG_SIZE * 8)]
208
209 mrs x10, cntp_ctl_el0
210 mrs x11, cntp_cval_el0
211 mrs x12, cntv_ctl_el0
212 mrs x13, cntv_cval_el0
213 mrs x14, cntkctl_el1
214 mrs x15, fpexc32_el2
215 mrs x8, sp_el0
216
217 stp x10, x11, [sp, #(REG_SIZE *10)]
218 stp x12, x13, [sp, #(REG_SIZE * 12)]
219 stp x14, x15, [sp, #(REG_SIZE * 14)]
220 stp x8, xzr, [sp, #(REG_SIZE * 16)]
221
222 adr x0, non_el3_sys_1_regs
223 mov x1, sp
224 bl print_string_value
225 add sp, sp, #NON_EL3_SYS_1_REG_SIZE
226 .endm
227
228 .macro init_crash_stack
229 msr cntfrq_el0, x0 /* we can corrupt this reg to free up x0 */
230 mrs x0, tpidr_el3
231
232 /* Check if tpidr is initialized */
233 cbz x0, infinite_loop
234
235 ldr x0, [x0, #PTR_CACHE_CRASH_STACK_OFFSET]
236 /* store the x30 and sp to stack */
237 str x30, [x0, #-(REG_SIZE)]!
238 mov x30, sp
239 str x30, [x0, #-(REG_SIZE)]!
240 mov sp, x0
241 mrs x0, cntfrq_el0
242 .endm
243
244 /* ---------------------------------------------------
245 * The below function initializes the crash dump stack ,
246 * and prints the system state. This function
247 * will not return.
248 * ---------------------------------------------------
249 */
250func dump_state_and_die
251 init_crash_stack
252 print_caller_saved_regs
253 b print_state
254
255func dump_intr_state_and_die
256 init_crash_stack
257 print_caller_saved_regs
258 plat_print_gic_regs /* fall through to print_state */
259
260print_state:
261 /* copy the original x30 from stack */
262 ldr x30, [sp, #REG_SIZE]
263 print_callee_saved_regs
264 /* copy the original SP_EL3 from stack to x0 and rewind stack */
265 ldr x0, [sp], #(REG_SIZE * 2)
266 print_el3_sys_regs
267 print_non_el3_sys_0_regs
268 print_non_el3_sys_1_regs
Soby Mathewa43d4312014-04-07 15:28:55 +0100269
Andrew Thoelke9c22b322014-06-03 11:50:53 +0100270#else /* CRASH_REPORING */
271
272func dump_state_and_die
273dump_intr_state_and_die:
274
275#endif /* CRASH_REPORING */
276
277infinite_loop:
Soby Mathewa43d4312014-04-07 15:28:55 +0100278 b infinite_loop
279
280
281#define PCPU_CRASH_STACK_SIZE 0x140
282
283 /* -----------------------------------------------------
284 * void get_crash_stack (uint64_t mpidr) : This
285 * function is used to allocate a small stack for
286 * reporting unhandled exceptions
287 * -----------------------------------------------------
288 */
289func get_crash_stack
290 mov x10, x30 // lr
291 get_mp_stack pcpu_crash_stack, PCPU_CRASH_STACK_SIZE
292 ret x10
293
294 /* -----------------------------------------------------
295 * Per-cpu crash stacks in normal memory.
296 * -----------------------------------------------------
297 */
298declare_stack pcpu_crash_stack, tzfw_normal_stacks, \
299 PCPU_CRASH_STACK_SIZE, PLATFORM_CORE_COUNT