xref: /rk3399_ARM-atf/include/arch/aarch64/console_macros.S (revision 3312fe8387b9379f6aefe8e075baa28802108244)
1f5478dedSAntonio Nino Diaz/*
2be3991c0SAmbroise Vincent * Copyright (c) 2017-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.
18f5478dedSAntonio Nino Diaz * REQUIRES console_t pointer in x0 and a valid return address in x30.
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	  adrp	x1, console_\_driver\()_putc
27f5478dedSAntonio Nino Diaz	  add	x1, x1, :lo12:console_\_driver\()_putc
28f5478dedSAntonio Nino Diaz	  str	x1, [x0, #CONSOLE_T_PUTC]
29f5478dedSAntonio Nino Diaz	.else
30f5478dedSAntonio Nino Diaz	  str	xzr, [x0, #CONSOLE_T_PUTC]
31f5478dedSAntonio Nino Diaz	.endif
32f5478dedSAntonio Nino Diaz
33*85bebe18SSandrine Bailleux	/*
34*85bebe18SSandrine Bailleux	 * If ENABLE_CONSOLE_GETC support is disabled, but a getc callback is
35*85bebe18SSandrine Bailleux	 * specified nonetheless, the assembler will abort on encountering the
36*85bebe18SSandrine Bailleux	 * CONSOLE_T_GETC macro, which is undefined.
37*85bebe18SSandrine Bailleux	 */
38f5478dedSAntonio Nino Diaz	.ifne \getc
39f5478dedSAntonio Nino Diaz	  adrp	x1, console_\_driver\()_getc
40f5478dedSAntonio Nino Diaz	  add	x1, x1, :lo12:console_\_driver\()_getc
41f5478dedSAntonio Nino Diaz	  str	x1, [x0, #CONSOLE_T_GETC]
42f5478dedSAntonio Nino Diaz	.else
43*85bebe18SSandrine Bailleux#if ENABLE_CONSOLE_GETC
44f5478dedSAntonio Nino Diaz	  str	xzr, [x0, #CONSOLE_T_GETC]
45*85bebe18SSandrine Bailleux#endif
46f5478dedSAntonio Nino Diaz	.endif
47f5478dedSAntonio Nino Diaz
48f5478dedSAntonio Nino Diaz	.ifne \flush
49f5478dedSAntonio Nino Diaz	  adrp	x1, console_\_driver\()_flush
50f5478dedSAntonio Nino Diaz	  add	x1, x1, :lo12:console_\_driver\()_flush
51f5478dedSAntonio Nino Diaz	  str	x1, [x0, #CONSOLE_T_FLUSH]
52f5478dedSAntonio Nino Diaz	.else
53f5478dedSAntonio Nino Diaz	  str	xzr, [x0, #CONSOLE_T_FLUSH]
54f5478dedSAntonio Nino Diaz	.endif
55f5478dedSAntonio Nino Diaz
56f5478dedSAntonio Nino Diaz	mov	x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
57f5478dedSAntonio Nino Diaz	str	x1, [x0, #CONSOLE_T_FLAGS]
58f5478dedSAntonio Nino Diaz	b	console_register
59f5478dedSAntonio Nino Diaz	.endm
60f5478dedSAntonio Nino Diaz
61f5478dedSAntonio Nino Diaz#endif /* CONSOLE_MACROS_S */
62