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