blob: 34e4dcddbeb0c12405fe657058b675e9185fd58a [file] [log] [blame]
Soby Mathew5e5c2072014-04-07 15:28:55 +01001/*
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +00002 * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew5e5c2072014-04-07 15:28:55 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew5e5c2072014-04-07 15:28:55 +01005 */
6#include <arch.h>
7#include <asm_macros.S>
8#include <context.h>
Andrew Thoelke8c28fe02014-06-02 11:40:35 +01009#include <cpu_data.h>
Soby Mathew5e5c2072014-04-07 15:28:55 +010010#include <plat_macros.S>
Sandrine Bailleuxaf1ef2b2014-05-27 15:46:07 +010011#include <platform_def.h>
Soby Mathew5e5c2072014-04-07 15:28:55 +010012
Soby Mathewc1adbbc2014-06-25 10:07:40 +010013 .globl report_unhandled_exception
14 .globl report_unhandled_interrupt
15 .globl el3_panic
Soby Mathew5e5c2072014-04-07 15:28:55 +010016
Andrew Thoelke385f4d42014-06-03 11:50:53 +010017#if CRASH_REPORTING
Soby Mathewc1adbbc2014-06-25 10:07:40 +010018#define REG_SIZE 0x8
19
Soby Mathew5e5c2072014-04-07 15:28:55 +010020 /* ------------------------------------------------------
21 * The below section deals with dumping the system state
22 * when an unhandled exception is taken in EL3.
23 * The layout and the names of the registers which will
24 * be dumped during a unhandled exception is given below.
25 * ------------------------------------------------------
26 */
Soby Mathewc1adbbc2014-06-25 10:07:40 +010027.section .rodata.crash_prints, "aS"
28print_spacer:
29 .asciz " =\t\t0x"
Soby Mathew5e5c2072014-04-07 15:28:55 +010030
Soby Mathewc1adbbc2014-06-25 10:07:40 +010031gp_regs:
32 .asciz "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",\
33 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",\
34 "x16", "x17", "x18", "x19", "x20", "x21", "x22",\
35 "x23", "x24", "x25", "x26", "x27", "x28", "x29", ""
36el3_sys_regs:
37 .asciz "scr_el3", "sctlr_el3", "cptr_el3", "tcr_el3",\
38 "daif", "mair_el3", "spsr_el3", "elr_el3", "ttbr0_el3",\
39 "esr_el3", "far_el3", ""
Soby Mathew5e5c2072014-04-07 15:28:55 +010040
Soby Mathewc1adbbc2014-06-25 10:07:40 +010041non_el3_sys_regs:
42 .asciz "spsr_el1", "elr_el1", "spsr_abt", "spsr_und",\
43 "spsr_irq", "spsr_fiq", "sctlr_el1", "actlr_el1", "cpacr_el1",\
44 "csselr_el1", "sp_el1", "esr_el1", "ttbr0_el1", "ttbr1_el1",\
45 "mair_el1", "amair_el1", "tcr_el1", "tpidr_el1", "tpidr_el0",\
46 "tpidrro_el0", "dacr32_el2", "ifsr32_el2", "par_el1",\
47 "mpidr_el1", "afsr0_el1", "afsr1_el1", "contextidr_el1",\
48 "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0", "cntv_ctl_el0",\
Gerald Lejeune851dc7e2016-03-22 11:11:46 +010049 "cntv_cval_el0", "cntkctl_el1", "fpexc32_el2", "sp_el0",\
50 "isr_el1", ""
Soby Mathew5e5c2072014-04-07 15:28:55 +010051
Soby Mathewc1adbbc2014-06-25 10:07:40 +010052panic_msg:
53 .asciz "PANIC in EL3 at x30 = 0x"
54excpt_msg:
55 .asciz "Unhandled Exception in EL3.\nx30 =\t\t0x"
56intr_excpt_msg:
57 .asciz "Unhandled Interrupt Exception in EL3.\nx30 =\t\t0x"
Soby Mathew5e5c2072014-04-07 15:28:55 +010058
Soby Mathewc1adbbc2014-06-25 10:07:40 +010059 /*
60 * Helper function to print newline to console.
Soby Mathew5e5c2072014-04-07 15:28:55 +010061 */
Soby Mathewc1adbbc2014-06-25 10:07:40 +010062func print_newline
63 mov x0, '\n'
64 b plat_crash_console_putc
Kévin Petita877c252015-03-24 14:03:57 +000065endfunc print_newline
Soby Mathew5e5c2072014-04-07 15:28:55 +010066
Soby Mathewc1adbbc2014-06-25 10:07:40 +010067 /*
68 * Helper function to print from crash buf.
69 * The print loop is controlled by the buf size and
70 * ascii reg name list which is passed in x6. The
71 * function returns the crash buf address in x0.
72 * Clobbers : x0 - x7, sp
73 */
74func size_controlled_print
75 /* Save the lr */
76 mov sp, x30
77 /* load the crash buf address */
78 mrs x7, tpidr_el3
79test_size_list:
80 /* Calculate x5 always as it will be clobbered by asm_print_hex */
81 mrs x5, tpidr_el3
82 add x5, x5, #CPU_DATA_CRASH_BUF_SIZE
83 /* Test whether we have reached end of crash buf */
84 cmp x7, x5
85 b.eq exit_size_print
86 ldrb w4, [x6]
87 /* Test whether we are at end of list */
88 cbz w4, exit_size_print
89 mov x4, x6
90 /* asm_print_str updates x4 to point to next entry in list */
91 bl asm_print_str
92 /* update x6 with the updated list pointer */
93 mov x6, x4
94 adr x4, print_spacer
95 bl asm_print_str
96 ldr x4, [x7], #REG_SIZE
97 bl asm_print_hex
98 bl print_newline
99 b test_size_list
100exit_size_print:
101 mov x30, sp
102 ret
Kévin Petita877c252015-03-24 14:03:57 +0000103endfunc size_controlled_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100104
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100105 /*
106 * Helper function to store x8 - x15 registers to
107 * the crash buf. The system registers values are
108 * copied to x8 to x15 by the caller which are then
109 * copied to the crash buf by this function.
110 * x0 points to the crash buf. It then calls
111 * size_controlled_print to print to console.
112 * Clobbers : x0 - x7, sp
113 */
114func str_in_crash_buf_print
115 /* restore the crash buf address in x0 */
116 mrs x0, tpidr_el3
117 stp x8, x9, [x0]
118 stp x10, x11, [x0, #REG_SIZE * 2]
119 stp x12, x13, [x0, #REG_SIZE * 4]
120 stp x14, x15, [x0, #REG_SIZE * 6]
121 b size_controlled_print
Kévin Petita877c252015-03-24 14:03:57 +0000122endfunc str_in_crash_buf_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100123
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100124 /* ------------------------------------------------------
125 * This macro calculates the offset to crash buf from
126 * cpu_data and stores it in tpidr_el3. It also saves x0
127 * and x1 in the crash buf by using sp as a temporary
128 * register.
129 * ------------------------------------------------------
130 */
131 .macro prepare_crash_buf_save_x0_x1
132 /* we can corrupt this reg to free up x0 */
133 mov sp, x0
134 /* tpidr_el3 contains the address to cpu_data structure */
135 mrs x0, tpidr_el3
136 /* Calculate the Crash buffer offset in cpu_data */
137 add x0, x0, #CPU_DATA_CRASH_BUF_OFFSET
138 /* Store crash buffer address in tpidr_el3 */
139 msr tpidr_el3, x0
140 str x1, [x0, #REG_SIZE]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100141 mov x1, sp
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100142 str x1, [x0]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100143 .endm
144
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100145 /* -----------------------------------------------------
146 * This function allows to report a crash (if crash
147 * reporting is enabled) when an unhandled exception
148 * occurs. It prints the CPU state via the crash console
149 * making use of the crash buf. This function will
150 * not return.
151 * -----------------------------------------------------
152 */
153func report_unhandled_exception
154 prepare_crash_buf_save_x0_x1
155 adr x0, excpt_msg
156 mov sp, x0
157 /* This call will not return */
158 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000159endfunc report_unhandled_exception
Soby Mathew5e5c2072014-04-07 15:28:55 +0100160
Soby Mathew5e5c2072014-04-07 15:28:55 +0100161
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100162 /* -----------------------------------------------------
163 * This function allows to report a crash (if crash
164 * reporting is enabled) when an unhandled interrupt
165 * occurs. It prints the CPU state via the crash console
166 * making use of the crash buf. This function will
167 * not return.
168 * -----------------------------------------------------
169 */
170func report_unhandled_interrupt
171 prepare_crash_buf_save_x0_x1
172 adr x0, intr_excpt_msg
173 mov sp, x0
174 /* This call will not return */
175 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000176endfunc report_unhandled_interrupt
Soby Mathew5e5c2072014-04-07 15:28:55 +0100177
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100178 /* -----------------------------------------------------
179 * This function allows to report a crash (if crash
180 * reporting is enabled) when panic() is invoked from
181 * C Runtime. It prints the CPU state via the crash
182 * console making use of the crash buf. This function
183 * will not return.
184 * -----------------------------------------------------
185 */
186func el3_panic
187 msr spsel, #1
188 prepare_crash_buf_save_x0_x1
189 adr x0, panic_msg
190 mov sp, x0
191 /* This call will not return */
192 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000193endfunc el3_panic
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100194
195 /* ------------------------------------------------------------
196 * The common crash reporting functionality. It requires x0
197 * and x1 has already been stored in crash buf, sp points to
198 * crash message and tpidr_el3 contains the crash buf address.
199 * The function does the following:
200 * - Retrieve the crash buffer from tpidr_el3
201 * - Store x2 to x6 in the crash buffer
202 * - Initialise the crash console.
203 * - Print the crash message by using the address in sp.
204 * - Print x30 value to the crash console.
205 * - Print x0 - x7 from the crash buf to the crash console.
206 * - Print x8 - x29 (in groups of 8 registers) using the
207 * crash buf to the crash console.
208 * - Print el3 sys regs (in groups of 8 registers) using the
209 * crash buf to the crash console.
210 * - Print non el3 sys regs (in groups of 8 registers) using
211 * the crash buf to the crash console.
212 * ------------------------------------------------------------
213 */
214func do_crash_reporting
215 /* Retrieve the crash buf from tpidr_el3 */
216 mrs x0, tpidr_el3
217 /* Store x2 - x6, x30 in the crash buffer */
218 stp x2, x3, [x0, #REG_SIZE * 2]
219 stp x4, x5, [x0, #REG_SIZE * 4]
220 stp x6, x30, [x0, #REG_SIZE * 6]
221 /* Initialize the crash console */
222 bl plat_crash_console_init
223 /* Verify the console is initialized */
224 cbz x0, crash_panic
225 /* Print the crash message. sp points to the crash message */
226 mov x4, sp
227 bl asm_print_str
228 /* load the crash buf address */
229 mrs x0, tpidr_el3
230 /* report x30 first from the crash buf */
231 ldr x4, [x0, #REG_SIZE * 7]
232 bl asm_print_hex
233 bl print_newline
234 /* Load the crash buf address */
235 mrs x0, tpidr_el3
236 /* Now mov x7 into crash buf */
237 str x7, [x0, #REG_SIZE * 7]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100238
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100239 /* Report x0 - x29 values stored in crash buf*/
240 /* Store the ascii list pointer in x6 */
241 adr x6, gp_regs
242 /* Print x0 to x7 from the crash buf */
243 bl size_controlled_print
244 /* Store x8 - x15 in crash buf and print */
245 bl str_in_crash_buf_print
246 /* Load the crash buf address */
247 mrs x0, tpidr_el3
248 /* Store the rest of gp regs and print */
249 stp x16, x17, [x0]
250 stp x18, x19, [x0, #REG_SIZE * 2]
251 stp x20, x21, [x0, #REG_SIZE * 4]
252 stp x22, x23, [x0, #REG_SIZE * 6]
253 bl size_controlled_print
254 /* Load the crash buf address */
255 mrs x0, tpidr_el3
256 stp x24, x25, [x0]
257 stp x26, x27, [x0, #REG_SIZE * 2]
258 stp x28, x29, [x0, #REG_SIZE * 4]
259 bl size_controlled_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100260
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100261 /* Print the el3 sys registers */
262 adr x6, el3_sys_regs
263 mrs x8, scr_el3
264 mrs x9, sctlr_el3
265 mrs x10, cptr_el3
266 mrs x11, tcr_el3
267 mrs x12, daif
268 mrs x13, mair_el3
269 mrs x14, spsr_el3
270 mrs x15, elr_el3
271 bl str_in_crash_buf_print
272 mrs x8, ttbr0_el3
273 mrs x9, esr_el3
274 mrs x10, far_el3
275 bl str_in_crash_buf_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100276
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100277 /* Print the non el3 sys registers */
278 adr x6, non_el3_sys_regs
279 mrs x8, spsr_el1
280 mrs x9, elr_el1
281 mrs x10, spsr_abt
282 mrs x11, spsr_und
283 mrs x12, spsr_irq
284 mrs x13, spsr_fiq
285 mrs x14, sctlr_el1
286 mrs x15, actlr_el1
287 bl str_in_crash_buf_print
288 mrs x8, cpacr_el1
289 mrs x9, csselr_el1
Soby Mathew5e5c2072014-04-07 15:28:55 +0100290 mrs x10, sp_el1
291 mrs x11, esr_el1
292 mrs x12, ttbr0_el1
293 mrs x13, ttbr1_el1
294 mrs x14, mair_el1
295 mrs x15, amair_el1
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100296 bl str_in_crash_buf_print
297 mrs x8, tcr_el1
298 mrs x9, tpidr_el1
299 mrs x10, tpidr_el0
300 mrs x11, tpidrro_el0
301 mrs x12, dacr32_el2
302 mrs x13, ifsr32_el2
303 mrs x14, par_el1
304 mrs x15, mpidr_el1
305 bl str_in_crash_buf_print
306 mrs x8, afsr0_el1
307 mrs x9, afsr1_el1
308 mrs x10, contextidr_el1
309 mrs x11, vbar_el1
310 mrs x12, cntp_ctl_el0
311 mrs x13, cntp_cval_el0
312 mrs x14, cntv_ctl_el0
313 mrs x15, cntv_cval_el0
314 bl str_in_crash_buf_print
315 mrs x8, cntkctl_el1
316 mrs x9, fpexc32_el2
317 mrs x10, sp_el0
Gerald Lejeune851dc7e2016-03-22 11:11:46 +0100318 mrs x11, isr_el1
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100319 bl str_in_crash_buf_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100320
Soby Mathew38b4bc92014-08-14 13:36:41 +0100321 /* Get the cpu specific registers to report */
322 bl do_cpu_reg_dump
323 bl str_in_crash_buf_print
Soby Mathew0da95932014-07-16 09:23:52 +0100324
Gerald Lejeune2c7ed5b2015-11-26 15:47:53 +0100325 /* Print some platform registers */
326 plat_crash_print_regs
Soby Mathew0da95932014-07-16 09:23:52 +0100327
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000328 bl plat_crash_console_flush
329
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100330 /* Done reporting */
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000331 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000332endfunc do_crash_reporting
Soby Mathew5e5c2072014-04-07 15:28:55 +0100333
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100334#else /* CRASH_REPORTING */
335func report_unhandled_exception
336report_unhandled_interrupt:
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000337 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000338endfunc report_unhandled_exception
Sandrine Bailleuxf4119ec2015-12-17 13:58:58 +0000339#endif /* CRASH_REPORTING */
Soby Mathew5e5c2072014-04-07 15:28:55 +0100340
Soby Mathew5e5c2072014-04-07 15:28:55 +0100341
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100342func crash_panic
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000343 no_ret plat_panic_handler
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000344endfunc crash_panic