1a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew/*
2a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew *
4a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * Redistribution and use in source and binary forms, with or without
5a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * modification, are permitted provided that the following conditions are met:
6a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew *
7a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * Redistributions of source code must retain the above copyright notice, this
8a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * list of conditions and the following disclaimer.
9a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew *
10a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * Redistributions in binary form must reproduce the above copyright notice,
11a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * this list of conditions and the following disclaimer in the documentation
12a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * and/or other materials provided with the distribution.
13a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew *
14a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * Neither the name of ARM nor the names of its contributors may be used
15a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * to endorse or promote products derived from this software without specific
16a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * prior written permission.
17a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew *
18a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew * POSSIBILITY OF SUCH DAMAGE.
29a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew */
30a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew#include <arch.h>
31a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew#include <asm_macros.S>
32a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew#include <context.h>
335e910074245fa180cfbe70d3c8bceeff1eaa026eAndrew Thoelke#include <cpu_data.h>
34a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew#include <plat_macros.S>
35e4d133899083fcb4874a70c3f82c296a89455ecdSandrine Bailleux#include <platform_def.h>
36a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
37626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.globl	report_unhandled_exception
38626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.globl	report_unhandled_interrupt
39626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.globl	el3_panic
40a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
419c22b32300320c40aa36f73f84a51cdc5218780eAndrew Thoelke#if CRASH_REPORTING
42626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew#define REG_SIZE	0x8
43626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
44a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	/* ------------------------------------------------------
45a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 * The below section deals with dumping the system state
46a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 * when an unhandled exception is taken in EL3.
47a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 * The layout and the names of the registers which will
48a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 * be dumped during a unhandled exception is given below.
49a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 * ------------------------------------------------------
50a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 */
51626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew.section .rodata.crash_prints, "aS"
52626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewprint_spacer:
53626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz	" =\t\t0x"
54626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
55626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewgp_regs:
56626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz	"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",\
57626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",\
58626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"x16", "x17", "x18", "x19", "x20", "x21", "x22",\
59626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"x23", "x24", "x25", "x26", "x27", "x28", "x29", ""
60626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewel3_sys_regs:
61626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz	"scr_el3", "sctlr_el3", "cptr_el3", "tcr_el3",\
62626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"daif", "mair_el3", "spsr_el3", "elr_el3", "ttbr0_el3",\
63626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"esr_el3", "far_el3", ""
64626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
65626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewnon_el3_sys_regs:
66626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz	"spsr_el1", "elr_el1", "spsr_abt", "spsr_und",\
67626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"spsr_irq", "spsr_fiq", "sctlr_el1", "actlr_el1", "cpacr_el1",\
68626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"csselr_el1", "sp_el1", "esr_el1", "ttbr0_el1", "ttbr1_el1",\
69626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"mair_el1", "amair_el1", "tcr_el1", "tpidr_el1", "tpidr_el0",\
70626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"tpidrro_el0", "dacr32_el2", "ifsr32_el2", "par_el1",\
71626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"mpidr_el1", "afsr0_el1", "afsr1_el1", "contextidr_el1",\
72626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"vbar_el1", "cntp_ctl_el0", "cntp_cval_el0", "cntv_ctl_el0",\
73626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew		"cntv_cval_el0", "cntkctl_el1", "fpexc32_el2", "sp_el0", ""
74626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
75626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewpanic_msg:
76626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz "PANIC in EL3 at x30 = 0x"
77626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewexcpt_msg:
78626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz "Unhandled Exception in EL3.\nx30 =\t\t0x"
79626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewintr_excpt_msg:
80626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.asciz "Unhandled Interrupt Exception in EL3.\nx30 =\t\t0x"
81626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
82626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/*
83626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * Helper function to print newline to console.
84a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	 */
85626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc print_newline
86626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	x0, '\n'
87626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	plat_crash_console_putc
88626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
89626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/*
90626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * Helper function to print from crash buf.
91626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * The print loop is controlled by the buf size and
92626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * ascii reg name list which is passed in x6. The
93626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * function returns the crash buf address in x0.
94626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * Clobbers : x0 - x7, sp
95626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
96626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc size_controlled_print
97626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Save the lr */
98626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	sp, x30
99626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* load the crash buf address */
100626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x7, tpidr_el3
101626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewtest_size_list:
102626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Calculate x5 always as it will be clobbered by asm_print_hex */
103626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x5, tpidr_el3
104626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	add	x5, x5, #CPU_DATA_CRASH_BUF_SIZE
105626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Test whether we have reached end of crash buf */
106626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	cmp	x7, x5
107626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b.eq	exit_size_print
108626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	ldrb	w4, [x6]
109626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Test whether we are at end of list */
110626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	cbz	w4, exit_size_print
111626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	x4, x6
112626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* asm_print_str updates x4 to point to next entry in list */
113626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	asm_print_str
114626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* update x6 with the updated list pointer */
115626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	x6, x4
116626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x4, print_spacer
117626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	asm_print_str
118626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	ldr	x4, [x7], #REG_SIZE
119626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	asm_print_hex
120626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	print_newline
121626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	test_size_list
122626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewexit_size_print:
123626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	x30, sp
124626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	ret
125626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
126626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/*
127626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * Helper function to store x8 - x15 registers to
128626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * the crash buf. The system registers values are
129626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * copied to x8 to x15 by the caller which are then
130626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * copied to the crash buf by this function.
131626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * x0 points to the crash buf. It then calls
132626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * size_controlled_print to print to console.
133626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * Clobbers : x0 - x7, sp
134626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
135626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc str_in_crash_buf_print
136626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* restore the crash buf address in x0 */
137626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
138626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x8, x9, [x0]
139626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x10, x11, [x0, #REG_SIZE * 2]
140626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x12, x13, [x0, #REG_SIZE * 4]
141626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x14, x15, [x0, #REG_SIZE * 6]
142626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	size_controlled_print
143a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
144626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* ------------------------------------------------------
145626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * This macro calculates the offset to crash buf from
146626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * cpu_data and stores it in tpidr_el3. It also saves x0
147626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * and x1 in the crash buf by using sp as a temporary
148626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * register.
149626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * ------------------------------------------------------
150626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
151626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	.macro prepare_crash_buf_save_x0_x1
152626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* we can corrupt this reg to free up x0 */
153626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	sp, x0
154626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* tpidr_el3 contains the address to cpu_data structure */
155626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
156626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Calculate the Crash buffer offset in cpu_data */
157626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	add	x0, x0, #CPU_DATA_CRASH_BUF_OFFSET
158626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Store crash buffer address in tpidr_el3 */
159626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	msr	tpidr_el3, x0
160626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	str	x1, [x0, #REG_SIZE]
161a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mov	x1, sp
162626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	str	x1, [x0]
163a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	.endm
164a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
165626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* -----------------------------------------------------
166626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * This function allows to report a crash (if crash
167626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * reporting is enabled) when an unhandled exception
168626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * occurs. It prints the CPU state via the crash console
169626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * making use of the crash buf. This function will
170626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * not return.
171626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * -----------------------------------------------------
172626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
173626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc report_unhandled_exception
174626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	prepare_crash_buf_save_x0_x1
175626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x0, excpt_msg
176626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	sp, x0
177626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* This call will not return */
178626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	do_crash_reporting
179a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
180a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
181626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* -----------------------------------------------------
182626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * This function allows to report a crash (if crash
183626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * reporting is enabled) when an unhandled interrupt
184626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * occurs. It prints the CPU state via the crash console
185626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * making use of the crash buf. This function will
186626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * not return.
187626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * -----------------------------------------------------
188626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
189626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc report_unhandled_interrupt
190626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	prepare_crash_buf_save_x0_x1
191626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x0, intr_excpt_msg
192626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	sp, x0
193626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* This call will not return */
194626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	do_crash_reporting
195a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
196626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* -----------------------------------------------------
197626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * This function allows to report a crash (if crash
198626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * reporting is enabled) when panic() is invoked from
199626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * C Runtime. It prints the CPU state via the crash
200626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * console making use of the crash buf. This function
201626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * will not return.
202626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * -----------------------------------------------------
203626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
204626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc el3_panic
205626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	msr	spsel, #1
206626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	prepare_crash_buf_save_x0_x1
207626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x0, panic_msg
208626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	sp, x0
209626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* This call will not return */
210626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	do_crash_reporting
211626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
212626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* ------------------------------------------------------------
213626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * The common crash reporting functionality. It requires x0
214626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * and x1 has already been stored in crash buf, sp points to
215626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * crash message and tpidr_el3 contains the crash buf address.
216626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * The function does the following:
217626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Retrieve the crash buffer from tpidr_el3
218626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Store x2 to x6 in the crash buffer
219626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Initialise the crash console.
220626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print the crash message by using the address in sp.
221626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print x30 value to the crash console.
222626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print x0 - x7 from the crash buf to the crash console.
223626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print x8 - x29 (in groups of 8 registers) using the
224626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *     crash buf to the crash console.
225626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print el3 sys regs (in groups of 8 registers) using the
226626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *     crash buf to the crash console.
227626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *   - Print non el3 sys regs (in groups of 8 registers) using
228626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 *     the crash buf to the crash console.
229626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 * ------------------------------------------------------------
230626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	 */
231626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc do_crash_reporting
232626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Retrieve the crash buf from tpidr_el3 */
233626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
234626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Store x2 - x6, x30 in the crash buffer */
235626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x2, x3, [x0, #REG_SIZE * 2]
236626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x4, x5, [x0, #REG_SIZE * 4]
237626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x6, x30, [x0, #REG_SIZE * 6]
238626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Initialize the crash console */
239626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	plat_crash_console_init
240626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Verify the console is initialized */
241626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	cbz	x0, crash_panic
242626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Print the crash message. sp points to the crash message */
243626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mov	x4, sp
244626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	asm_print_str
245626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* load the crash buf address */
246626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
247626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* report x30 first from the crash buf */
248626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	ldr	x4, [x0, #REG_SIZE * 7]
249626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	asm_print_hex
250626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	print_newline
251626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Load the crash buf address */
252626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
253626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Now mov x7 into crash buf */
254626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	str	x7, [x0, #REG_SIZE * 7]
255626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
256626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Report x0 - x29 values stored in crash buf*/
257626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Store the ascii list pointer in x6 */
258626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x6, gp_regs
259626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Print x0 to x7 from the crash buf */
260626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	size_controlled_print
261626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Store x8 - x15 in crash buf and print */
262626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
263626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Load the crash buf address */
264626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
265626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Store the rest of gp regs and print */
266626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x16, x17, [x0]
267626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x18, x19, [x0, #REG_SIZE * 2]
268626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x20, x21, [x0, #REG_SIZE * 4]
269626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x22, x23, [x0, #REG_SIZE * 6]
270626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	size_controlled_print
271626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Load the crash buf address */
272626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x0, tpidr_el3
273626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x24, x25, [x0]
274626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x26, x27, [x0, #REG_SIZE * 2]
275626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	stp	x28, x29, [x0, #REG_SIZE * 4]
276626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	size_controlled_print
277626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
278626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Print the el3 sys registers */
279626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x6, el3_sys_regs
280626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, scr_el3
281626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, sctlr_el3
282626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, cptr_el3
283626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x11, tcr_el3
284626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x12, daif
285626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x13, mair_el3
286626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x14, spsr_el3
287626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x15, elr_el3
288626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
289626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, ttbr0_el3
290626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, esr_el3
291626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, far_el3
292626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
293626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
294626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Print the non el3 sys registers */
295626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	adr	x6, non_el3_sys_regs
296626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, spsr_el1
297626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, elr_el1
298626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, spsr_abt
299626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x11, spsr_und
300626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x12, spsr_irq
301626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x13, spsr_fiq
302626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x14, sctlr_el1
303626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x15, actlr_el1
304626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
305626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, cpacr_el1
306626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, csselr_el1
307a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x10, sp_el1
308a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x11, esr_el1
309a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x12, ttbr0_el1
310a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x13, ttbr1_el1
311a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x14, mair_el1
312a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew	mrs	x15, amair_el1
313626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
314626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, tcr_el1
315626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, tpidr_el1
316626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, tpidr_el0
317626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x11, tpidrro_el0
318626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x12, dacr32_el2
319626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x13, ifsr32_el2
320626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x14, par_el1
321626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x15, mpidr_el1
322626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
323626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, afsr0_el1
324626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, afsr1_el1
325626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, contextidr_el1
326626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x11, vbar_el1
327626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x12, cntp_ctl_el0
328626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x13, cntp_cval_el0
329626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x14, cntv_ctl_el0
330626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x15, cntv_cval_el0
331626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
332626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x8, cntkctl_el1
333626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x9, fpexc32_el2
334626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	mrs	x10, sp_el0
335626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	bl	str_in_crash_buf_print
336626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
337d3f70af6e09d669da9c7d7890b7af5a0cdc4b3a5Soby Mathew	/* Get the cpu specific registers to report */
338d3f70af6e09d669da9c7d7890b7af5a0cdc4b3a5Soby Mathew	bl	do_cpu_reg_dump
339d3f70af6e09d669da9c7d7890b7af5a0cdc4b3a5Soby Mathew	bl	str_in_crash_buf_print
3408c106902368c40e14c558a0ab91cc57defdc7e81Soby Mathew
341626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Print the gic registers */
342626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	plat_print_gic_regs
343626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
3448c106902368c40e14c558a0ab91cc57defdc7e81Soby Mathew	/* Print the interconnect registers */
3458c106902368c40e14c558a0ab91cc57defdc7e81Soby Mathew	plat_print_interconnect_regs
3468c106902368c40e14c558a0ab91cc57defdc7e81Soby Mathew
347626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	/* Done reporting */
348626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	crash_panic
349626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew
350626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew#else	/* CRASH_REPORTING */
351626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc report_unhandled_exception
352626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewreport_unhandled_interrupt:
353626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	crash_panic
3549c22b32300320c40aa36f73f84a51cdc5218780eAndrew Thoelke#endif	/* CRASH_REPORING */
3559c22b32300320c40aa36f73f84a51cdc5218780eAndrew Thoelke
356a43d431b80541ea436b71f967c5749babf978c7aSoby Mathew
357626ed510f179c905a699f4663ee933c10892b4c3Soby Mathewfunc crash_panic
358626ed510f179c905a699f4663ee933c10892b4c3Soby Mathew	b	crash_panic
359