xref: /arm-trusted-firmware/include/arch/aarch32/console_macros.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu#ifndef CONSOLE_MACROS_S
7*91f16700Schasinglulu#define CONSOLE_MACROS_S
8*91f16700Schasinglulu
9*91f16700Schasinglulu#include <drivers/console.h>
10*91f16700Schasinglulu
11*91f16700Schasinglulu/*
12*91f16700Schasinglulu * This macro encapsulates the common setup that has to be done at the end of
13*91f16700Schasinglulu * a console driver's register function. It will register all of the driver's
14*91f16700Schasinglulu * callbacks in the console_t structure and initialize the flags field (by
15*91f16700Schasinglulu * default consoles are enabled for the "boot" and "crash" states, this can be
16*91f16700Schasinglulu * changed after registration with the console_set_scope() function). It ends
17*91f16700Schasinglulu * with a tail call that will include return to the caller.
18*91f16700Schasinglulu * REQUIRES console_t pointer in r0 and a valid return address in lr.
19*91f16700Schasinglulu */
20*91f16700Schasinglulu	.macro	finish_console_register _driver, putc=0, getc=0, flush=0
21*91f16700Schasinglulu	/*
22*91f16700Schasinglulu	 * If any of the callback is not specified or set as 0, then the
23*91f16700Schasinglulu	 * corresponding callback entry in console_t is set to 0.
24*91f16700Schasinglulu	 */
25*91f16700Schasinglulu	.ifne \putc
26*91f16700Schasinglulu	  ldr	r1, =console_\_driver\()_putc
27*91f16700Schasinglulu	.else
28*91f16700Schasinglulu	  mov	r1, #0
29*91f16700Schasinglulu	.endif
30*91f16700Schasinglulu	str	r1, [r0, #CONSOLE_T_PUTC]
31*91f16700Schasinglulu
32*91f16700Schasinglulu	/*
33*91f16700Schasinglulu	 * If ENABLE_CONSOLE_GETC support is disabled, but a getc callback is
34*91f16700Schasinglulu	 * specified nonetheless, the assembler will abort on encountering the
35*91f16700Schasinglulu	 * CONSOLE_T_GETC macro, which is undefined.
36*91f16700Schasinglulu	 */
37*91f16700Schasinglulu	.ifne \getc
38*91f16700Schasinglulu	  ldr	r1, =console_\_driver\()_getc
39*91f16700Schasinglulu	  str	r1, [r0, #CONSOLE_T_GETC]
40*91f16700Schasinglulu	.else
41*91f16700Schasinglulu#if ENABLE_CONSOLE_GETC
42*91f16700Schasinglulu	  mov	r1, #0
43*91f16700Schasinglulu	  str	r1, [r0, #CONSOLE_T_GETC]
44*91f16700Schasinglulu#endif
45*91f16700Schasinglulu	.endif
46*91f16700Schasinglulu
47*91f16700Schasinglulu	.ifne \flush
48*91f16700Schasinglulu	  ldr	r1, =console_\_driver\()_flush
49*91f16700Schasinglulu	.else
50*91f16700Schasinglulu	  mov	r1, #0
51*91f16700Schasinglulu	.endif
52*91f16700Schasinglulu	str	r1, [r0, #CONSOLE_T_FLUSH]
53*91f16700Schasinglulu
54*91f16700Schasinglulu	mov	r1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
55*91f16700Schasinglulu	str	r1, [r0, #CONSOLE_T_FLAGS]
56*91f16700Schasinglulu	b	console_register
57*91f16700Schasinglulu	.endm
58*91f16700Schasinglulu
59*91f16700Schasinglulu#endif /* CONSOLE_MACROS_S */
60