blob: 97db2a167999b080d6b1d64469a959936a8d9a6e [file] [log] [blame]
Soby Mathew5e5c2072014-04-07 15:28:55 +01001/*
Alexei Fedorovb8f26e92020-02-06 17:11:03 +00002 * Copyright (c) 2014-2020, 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 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
7#include <plat_macros.S>
8#include <platform_def.h>
9
Soby Mathew5e5c2072014-04-07 15:28:55 +010010#include <arch.h>
11#include <asm_macros.S>
12#include <context.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/el3_runtime/cpu_data.h>
14#include <lib/utils_def.h>
Soby Mathew5e5c2072014-04-07 15:28:55 +010015
Soby Mathewc1adbbc2014-06-25 10:07:40 +010016 .globl report_unhandled_exception
17 .globl report_unhandled_interrupt
18 .globl el3_panic
Soby Mathew5e5c2072014-04-07 15:28:55 +010019
Andrew Thoelke385f4d42014-06-03 11:50:53 +010020#if CRASH_REPORTING
Soby Mathewc1adbbc2014-06-25 10:07:40 +010021
Soby Mathew5e5c2072014-04-07 15:28:55 +010022 /* ------------------------------------------------------
23 * The below section deals with dumping the system state
24 * when an unhandled exception is taken in EL3.
25 * The layout and the names of the registers which will
26 * be dumped during a unhandled exception is given below.
27 * ------------------------------------------------------
28 */
Soby Mathewc1adbbc2014-06-25 10:07:40 +010029.section .rodata.crash_prints, "aS"
30print_spacer:
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010031 .asciz " = 0x"
Soby Mathew5e5c2072014-04-07 15:28:55 +010032
Soby Mathewc1adbbc2014-06-25 10:07:40 +010033gp_regs:
34 .asciz "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",\
35 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",\
36 "x16", "x17", "x18", "x19", "x20", "x21", "x22",\
37 "x23", "x24", "x25", "x26", "x27", "x28", "x29", ""
38el3_sys_regs:
39 .asciz "scr_el3", "sctlr_el3", "cptr_el3", "tcr_el3",\
40 "daif", "mair_el3", "spsr_el3", "elr_el3", "ttbr0_el3",\
41 "esr_el3", "far_el3", ""
Soby Mathew5e5c2072014-04-07 15:28:55 +010042
Soby Mathewc1adbbc2014-06-25 10:07:40 +010043non_el3_sys_regs:
44 .asciz "spsr_el1", "elr_el1", "spsr_abt", "spsr_und",\
45 "spsr_irq", "spsr_fiq", "sctlr_el1", "actlr_el1", "cpacr_el1",\
46 "csselr_el1", "sp_el1", "esr_el1", "ttbr0_el1", "ttbr1_el1",\
47 "mair_el1", "amair_el1", "tcr_el1", "tpidr_el1", "tpidr_el0",\
Imre Kisb5b903c2019-07-22 11:56:45 +020048 "tpidrro_el0", "par_el1", "mpidr_el1", "afsr0_el1", "afsr1_el1",\
49 "contextidr_el1", "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0",\
50 "cntv_ctl_el0", "cntv_cval_el0", "cntkctl_el1", "sp_el0", "isr_el1", ""
51
52#if CTX_INCLUDE_AARCH32_REGS
53aarch32_regs:
54 .asciz "dacr32_el2", "ifsr32_el2", ""
55#endif /* CTX_INCLUDE_AARCH32_REGS */
Soby Mathew5e5c2072014-04-07 15:28:55 +010056
Soby Mathewc1adbbc2014-06-25 10:07:40 +010057panic_msg:
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010058 .asciz "PANIC in EL3.\nx30"
Soby Mathewc1adbbc2014-06-25 10:07:40 +010059excpt_msg:
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010060 .asciz "Unhandled Exception in EL3.\nx30"
Soby Mathewc1adbbc2014-06-25 10:07:40 +010061intr_excpt_msg:
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010062 .asciz "Unhandled Interrupt Exception in EL3.\nx30"
Soby Mathew5e5c2072014-04-07 15:28:55 +010063
Soby Mathewc1adbbc2014-06-25 10:07:40 +010064 /*
Soby Mathewc1adbbc2014-06-25 10:07:40 +010065 * Helper function to print from crash buf.
66 * The print loop is controlled by the buf size and
67 * ascii reg name list which is passed in x6. The
68 * function returns the crash buf address in x0.
69 * Clobbers : x0 - x7, sp
70 */
71func size_controlled_print
72 /* Save the lr */
73 mov sp, x30
74 /* load the crash buf address */
75 mrs x7, tpidr_el3
76test_size_list:
77 /* Calculate x5 always as it will be clobbered by asm_print_hex */
78 mrs x5, tpidr_el3
79 add x5, x5, #CPU_DATA_CRASH_BUF_SIZE
80 /* Test whether we have reached end of crash buf */
81 cmp x7, x5
82 b.eq exit_size_print
83 ldrb w4, [x6]
84 /* Test whether we are at end of list */
85 cbz w4, exit_size_print
86 mov x4, x6
87 /* asm_print_str updates x4 to point to next entry in list */
88 bl asm_print_str
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010089 /* x0 = number of symbols printed + 1 */
90 sub x0, x4, x6
Soby Mathewc1adbbc2014-06-25 10:07:40 +010091 /* update x6 with the updated list pointer */
92 mov x6, x4
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +010093 bl print_alignment
Julius Werner02eb7272017-12-12 14:23:26 -080094 ldr x4, [x7], #REGSZ
Soby Mathewc1adbbc2014-06-25 10:07:40 +010095 bl asm_print_hex
Justin Chadwell76903822019-08-20 10:58:49 +010096 bl asm_print_newline
Soby Mathewc1adbbc2014-06-25 10:07:40 +010097 b test_size_list
98exit_size_print:
99 mov x30, sp
100 ret
Kévin Petita877c252015-03-24 14:03:57 +0000101endfunc size_controlled_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100102
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +0100103 /* -----------------------------------------------------
104 * This function calculates and prints required number
105 * of space characters followed by "= 0x", based on the
106 * length of ascii register name.
107 * x0: length of ascii register name + 1
108 * ------------------------------------------------------
109 */
110func print_alignment
111 /* The minimum ascii length is 3, e.g. for "x0" */
112 adr x4, print_spacer - 3
113 add x4, x4, x0
114 b asm_print_str
115endfunc print_alignment
116
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100117 /*
118 * Helper function to store x8 - x15 registers to
119 * the crash buf. The system registers values are
120 * copied to x8 to x15 by the caller which are then
121 * copied to the crash buf by this function.
122 * x0 points to the crash buf. It then calls
123 * size_controlled_print to print to console.
124 * Clobbers : x0 - x7, sp
125 */
126func str_in_crash_buf_print
127 /* restore the crash buf address in x0 */
128 mrs x0, tpidr_el3
129 stp x8, x9, [x0]
Julius Werner02eb7272017-12-12 14:23:26 -0800130 stp x10, x11, [x0, #REGSZ * 2]
131 stp x12, x13, [x0, #REGSZ * 4]
132 stp x14, x15, [x0, #REGSZ * 6]
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100133 b size_controlled_print
Kévin Petita877c252015-03-24 14:03:57 +0000134endfunc str_in_crash_buf_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100135
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100136 /* ------------------------------------------------------
137 * This macro calculates the offset to crash buf from
138 * cpu_data and stores it in tpidr_el3. It also saves x0
139 * and x1 in the crash buf by using sp as a temporary
140 * register.
141 * ------------------------------------------------------
142 */
143 .macro prepare_crash_buf_save_x0_x1
144 /* we can corrupt this reg to free up x0 */
145 mov sp, x0
146 /* tpidr_el3 contains the address to cpu_data structure */
147 mrs x0, tpidr_el3
148 /* Calculate the Crash buffer offset in cpu_data */
149 add x0, x0, #CPU_DATA_CRASH_BUF_OFFSET
150 /* Store crash buffer address in tpidr_el3 */
151 msr tpidr_el3, x0
Julius Werner02eb7272017-12-12 14:23:26 -0800152 str x1, [x0, #REGSZ]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100153 mov x1, sp
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100154 str x1, [x0]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100155 .endm
156
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100157 /* -----------------------------------------------------
158 * This function allows to report a crash (if crash
159 * reporting is enabled) when an unhandled exception
160 * occurs. It prints the CPU state via the crash console
161 * making use of the crash buf. This function will
162 * not return.
163 * -----------------------------------------------------
164 */
165func report_unhandled_exception
166 prepare_crash_buf_save_x0_x1
167 adr x0, excpt_msg
168 mov sp, x0
169 /* This call will not return */
170 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000171endfunc report_unhandled_exception
Soby Mathew5e5c2072014-04-07 15:28:55 +0100172
Soby Mathew5e5c2072014-04-07 15:28:55 +0100173
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100174 /* -----------------------------------------------------
175 * This function allows to report a crash (if crash
176 * reporting is enabled) when an unhandled interrupt
177 * occurs. It prints the CPU state via the crash console
178 * making use of the crash buf. This function will
179 * not return.
180 * -----------------------------------------------------
181 */
182func report_unhandled_interrupt
183 prepare_crash_buf_save_x0_x1
184 adr x0, intr_excpt_msg
185 mov sp, x0
186 /* This call will not return */
187 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000188endfunc report_unhandled_interrupt
Soby Mathew5e5c2072014-04-07 15:28:55 +0100189
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100190 /* -----------------------------------------------------
191 * This function allows to report a crash (if crash
192 * reporting is enabled) when panic() is invoked from
193 * C Runtime. It prints the CPU state via the crash
194 * console making use of the crash buf. This function
195 * will not return.
196 * -----------------------------------------------------
197 */
198func el3_panic
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +0100199 msr spsel, #MODE_SP_ELX
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100200 prepare_crash_buf_save_x0_x1
201 adr x0, panic_msg
202 mov sp, x0
203 /* This call will not return */
204 b do_crash_reporting
Kévin Petita877c252015-03-24 14:03:57 +0000205endfunc el3_panic
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100206
207 /* ------------------------------------------------------------
208 * The common crash reporting functionality. It requires x0
209 * and x1 has already been stored in crash buf, sp points to
210 * crash message and tpidr_el3 contains the crash buf address.
211 * The function does the following:
212 * - Retrieve the crash buffer from tpidr_el3
213 * - Store x2 to x6 in the crash buffer
214 * - Initialise the crash console.
215 * - Print the crash message by using the address in sp.
216 * - Print x30 value to the crash console.
217 * - Print x0 - x7 from the crash buf to the crash console.
218 * - Print x8 - x29 (in groups of 8 registers) using the
219 * crash buf to the crash console.
220 * - Print el3 sys regs (in groups of 8 registers) using the
221 * crash buf to the crash console.
222 * - Print non el3 sys regs (in groups of 8 registers) using
223 * the crash buf to the crash console.
224 * ------------------------------------------------------------
225 */
226func do_crash_reporting
227 /* Retrieve the crash buf from tpidr_el3 */
228 mrs x0, tpidr_el3
229 /* Store x2 - x6, x30 in the crash buffer */
Julius Werner02eb7272017-12-12 14:23:26 -0800230 stp x2, x3, [x0, #REGSZ * 2]
231 stp x4, x5, [x0, #REGSZ * 4]
232 stp x6, x30, [x0, #REGSZ * 6]
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100233 /* Initialize the crash console */
234 bl plat_crash_console_init
235 /* Verify the console is initialized */
236 cbz x0, crash_panic
237 /* Print the crash message. sp points to the crash message */
238 mov x4, sp
239 bl asm_print_str
Alexei Fedorovc4dfb3b2019-07-29 13:34:07 +0100240 /* Print spaces to align "x30" string */
241 mov x0, #4
242 bl print_alignment
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100243 /* load the crash buf address */
244 mrs x0, tpidr_el3
245 /* report x30 first from the crash buf */
Julius Werner02eb7272017-12-12 14:23:26 -0800246 ldr x4, [x0, #REGSZ * 7]
Alexei Fedorovb8f26e92020-02-06 17:11:03 +0000247
248#if ENABLE_PAUTH
249 /* Demangle address */
250 xpaci x4
251#endif
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100252 bl asm_print_hex
Justin Chadwell76903822019-08-20 10:58:49 +0100253 bl asm_print_newline
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100254 /* Load the crash buf address */
255 mrs x0, tpidr_el3
256 /* Now mov x7 into crash buf */
Julius Werner02eb7272017-12-12 14:23:26 -0800257 str x7, [x0, #REGSZ * 7]
Soby Mathew5e5c2072014-04-07 15:28:55 +0100258
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100259 /* Report x0 - x29 values stored in crash buf*/
260 /* Store the ascii list pointer in x6 */
261 adr x6, gp_regs
262 /* Print x0 to x7 from the crash buf */
263 bl size_controlled_print
264 /* Store x8 - x15 in crash buf and print */
265 bl str_in_crash_buf_print
266 /* Load the crash buf address */
267 mrs x0, tpidr_el3
268 /* Store the rest of gp regs and print */
269 stp x16, x17, [x0]
Julius Werner02eb7272017-12-12 14:23:26 -0800270 stp x18, x19, [x0, #REGSZ * 2]
271 stp x20, x21, [x0, #REGSZ * 4]
272 stp x22, x23, [x0, #REGSZ * 6]
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100273 bl size_controlled_print
274 /* Load the crash buf address */
275 mrs x0, tpidr_el3
276 stp x24, x25, [x0]
Julius Werner02eb7272017-12-12 14:23:26 -0800277 stp x26, x27, [x0, #REGSZ * 2]
278 stp x28, x29, [x0, #REGSZ * 4]
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100279 bl size_controlled_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100280
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100281 /* Print the el3 sys registers */
282 adr x6, el3_sys_regs
283 mrs x8, scr_el3
284 mrs x9, sctlr_el3
285 mrs x10, cptr_el3
286 mrs x11, tcr_el3
287 mrs x12, daif
288 mrs x13, mair_el3
289 mrs x14, spsr_el3
290 mrs x15, elr_el3
291 bl str_in_crash_buf_print
292 mrs x8, ttbr0_el3
293 mrs x9, esr_el3
294 mrs x10, far_el3
295 bl str_in_crash_buf_print
Soby Mathew5e5c2072014-04-07 15:28:55 +0100296
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100297 /* Print the non el3 sys registers */
298 adr x6, non_el3_sys_regs
299 mrs x8, spsr_el1
300 mrs x9, elr_el1
301 mrs x10, spsr_abt
302 mrs x11, spsr_und
303 mrs x12, spsr_irq
304 mrs x13, spsr_fiq
305 mrs x14, sctlr_el1
306 mrs x15, actlr_el1
307 bl str_in_crash_buf_print
308 mrs x8, cpacr_el1
309 mrs x9, csselr_el1
Soby Mathew5e5c2072014-04-07 15:28:55 +0100310 mrs x10, sp_el1
311 mrs x11, esr_el1
312 mrs x12, ttbr0_el1
313 mrs x13, ttbr1_el1
314 mrs x14, mair_el1
315 mrs x15, amair_el1
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100316 bl str_in_crash_buf_print
317 mrs x8, tcr_el1
318 mrs x9, tpidr_el1
319 mrs x10, tpidr_el0
320 mrs x11, tpidrro_el0
Imre Kisb5b903c2019-07-22 11:56:45 +0200321 mrs x12, par_el1
322 mrs x13, mpidr_el1
323 mrs x14, afsr0_el1
324 mrs x15, afsr1_el1
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100325 bl str_in_crash_buf_print
Imre Kisb5b903c2019-07-22 11:56:45 +0200326 mrs x8, contextidr_el1
327 mrs x9, vbar_el1
328 mrs x10, cntp_ctl_el0
329 mrs x11, cntp_cval_el0
330 mrs x12, cntv_ctl_el0
331 mrs x13, cntv_cval_el0
332 mrs x14, cntkctl_el1
333 mrs x15, sp_el0
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100334 bl str_in_crash_buf_print
Imre Kisb5b903c2019-07-22 11:56:45 +0200335 mrs x8, isr_el1
336 bl str_in_crash_buf_print
337
338#if CTX_INCLUDE_AARCH32_REGS
339 /* Print the AArch32 registers */
340 adr x6, aarch32_regs
341 mrs x8, dacr32_el2
342 mrs x9, ifsr32_el2
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100343 bl str_in_crash_buf_print
Imre Kisb5b903c2019-07-22 11:56:45 +0200344#endif /* CTX_INCLUDE_AARCH32_REGS */
Soby Mathew5e5c2072014-04-07 15:28:55 +0100345
Soby Mathew38b4bc92014-08-14 13:36:41 +0100346 /* Get the cpu specific registers to report */
347 bl do_cpu_reg_dump
348 bl str_in_crash_buf_print
Soby Mathew0da95932014-07-16 09:23:52 +0100349
Gerald Lejeune2c7ed5b2015-11-26 15:47:53 +0100350 /* Print some platform registers */
351 plat_crash_print_regs
Soby Mathew0da95932014-07-16 09:23:52 +0100352
Antonio Nino Diazd3ec5432017-02-17 17:11:27 +0000353 bl plat_crash_console_flush
354
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100355 /* Done reporting */
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000356 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000357endfunc do_crash_reporting
Soby Mathew5e5c2072014-04-07 15:28:55 +0100358
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100359#else /* CRASH_REPORTING */
360func report_unhandled_exception
361report_unhandled_interrupt:
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000362 no_ret plat_panic_handler
Kévin Petita877c252015-03-24 14:03:57 +0000363endfunc report_unhandled_exception
Sandrine Bailleuxf4119ec2015-12-17 13:58:58 +0000364#endif /* CRASH_REPORTING */
Soby Mathew5e5c2072014-04-07 15:28:55 +0100365
Soby Mathew5e5c2072014-04-07 15:28:55 +0100366
Soby Mathewc1adbbc2014-06-25 10:07:40 +0100367func crash_panic
Jeenu Viswambharan68aef102016-11-30 15:21:11 +0000368 no_ret plat_panic_handler
Antonio Nino Diaz1f21bcf2016-02-01 13:57:25 +0000369endfunc crash_panic