xref: /arm-trusted-firmware/plat/common/aarch32/crash_console_helpers.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu/*
8*91f16700Schasinglulu * If a platform wishes to use the functions in this file it has to be added to
9*91f16700Schasinglulu * the Makefile of the platform. It is not included in the common Makefile.
10*91f16700Schasinglulu */
11*91f16700Schasinglulu
12*91f16700Schasinglulu#include <asm_macros.S>
13*91f16700Schasinglulu#include <drivers/console.h>
14*91f16700Schasinglulu
15*91f16700Schasinglulu	.globl	plat_crash_console_init
16*91f16700Schasinglulu	.globl	plat_crash_console_putc
17*91f16700Schasinglulu	.globl	plat_crash_console_flush
18*91f16700Schasinglulu
19*91f16700Schasinglulu	/* -----------------------------------------------------
20*91f16700Schasinglulu	 * int plat_crash_console_init(void)
21*91f16700Schasinglulu	 * Use normal console by default. Switch it to crash
22*91f16700Schasinglulu	 * mode so serial consoles become active again.
23*91f16700Schasinglulu	 * NOTE: This default implementation will only work for
24*91f16700Schasinglulu	 * crashes that occur after a normal console (marked
25*91f16700Schasinglulu	 * valid for the crash state) has been registered with
26*91f16700Schasinglulu	 * the console framework. To debug crashes that occur
27*91f16700Schasinglulu	 * earlier, the platform has to override these functions
28*91f16700Schasinglulu	 * with an implementation that initializes a console
29*91f16700Schasinglulu	 * driver with hardcoded parameters. See
30*91f16700Schasinglulu	 * docs/porting-guide.rst for more information.
31*91f16700Schasinglulu	 * -----------------------------------------------------
32*91f16700Schasinglulu	 */
33*91f16700Schasinglulufunc plat_crash_console_init
34*91f16700Schasinglulu#if defined(IMAGE_BL1)
35*91f16700Schasinglulu	/*
36*91f16700Schasinglulu	 * BL1 code can possibly crash so early that the data segment is not yet
37*91f16700Schasinglulu	 * accessible. Don't risk undefined behavior by trying to run the normal
38*91f16700Schasinglulu	 * console framework. Platforms that want to debug BL1 will need to
39*91f16700Schasinglulu	 * override this with custom functions that can run from registers only.
40*91f16700Schasinglulu	 */
41*91f16700Schasinglulu	mov	r0, #0
42*91f16700Schasinglulu	bx	lr
43*91f16700Schasinglulu#else	/* IMAGE_BL1 */
44*91f16700Schasinglulu	mov	r3, lr
45*91f16700Schasinglulu	mov	r0, #CONSOLE_FLAG_CRASH
46*91f16700Schasinglulu	bl	console_switch_state
47*91f16700Schasinglulu	mov	r0, #1
48*91f16700Schasinglulu	bx	r3
49*91f16700Schasinglulu#endif
50*91f16700Schasingluluendfunc plat_crash_console_init
51*91f16700Schasinglulu
52*91f16700Schasinglulu	/* -----------------------------------------------------
53*91f16700Schasinglulu	 * void plat_crash_console_putc(int character)
54*91f16700Schasinglulu	 * Output through the normal console by default.
55*91f16700Schasinglulu	 * -----------------------------------------------------
56*91f16700Schasinglulu	 */
57*91f16700Schasinglulufunc plat_crash_console_putc
58*91f16700Schasinglulu	b	console_putc
59*91f16700Schasingluluendfunc plat_crash_console_putc
60*91f16700Schasinglulu
61*91f16700Schasinglulu	/* -----------------------------------------------------
62*91f16700Schasinglulu	 * void plat_crash_console_flush(void)
63*91f16700Schasinglulu	 * Flush normal console by default.
64*91f16700Schasinglulu	 * -----------------------------------------------------
65*91f16700Schasinglulu	 */
66*91f16700Schasinglulufunc plat_crash_console_flush
67*91f16700Schasinglulu	b	console_flush
68*91f16700Schasingluluendfunc plat_crash_console_flush
69