blob: 8adb9cdb1e35fbd208a8c986db8edb9488ef1c53 [file] [log] [blame]
Julius Werner94f89072017-07-31 18:15:11 -07001/*
Ambroise Vincent0a0ca8b2019-03-27 15:45:35 +00002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Julius Werner94f89072017-07-31 18:15:11 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00006#ifndef CONSOLE_MACROS_S
7#define CONSOLE_MACROS_S
Julius Werner94f89072017-07-31 18:15:11 -07008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <drivers/console.h>
Julius Werner94f89072017-07-31 18:15:11 -070010
11/*
12 * This macro encapsulates the common setup that has to be done at the end of
13 * a console driver's register function. It will register all of the driver's
14 * callbacks in the console_t structure and initialize the flags field (by
15 * default consoles are enabled for the "boot" and "crash" states, this can be
16 * changed after registration with the console_set_scope() function). It ends
17 * with a tail call that will include return to the caller.
18 * REQUIRES console_t pointer in x0 and a valid return address in x30.
19 */
Soby Mathew58873ae2018-10-10 16:03:09 +010020 .macro finish_console_register _driver, putc=0, getc=0, flush=0
21 /*
22 * If any of the callback is not specified or set as 0, then the
23 * corresponding callback entry in console_t is set to 0.
24 */
25 .ifne \putc
26 adrp x1, console_\_driver\()_putc
27 add x1, x1, :lo12:console_\_driver\()_putc
28 str x1, [x0, #CONSOLE_T_PUTC]
29 .else
30 str xzr, [x0, #CONSOLE_T_PUTC]
31 .endif
32
Sandrine Bailleuxf57e2032023-10-11 08:38:00 +020033 /*
34 * If ENABLE_CONSOLE_GETC support is disabled, but a getc callback is
35 * specified nonetheless, the assembler will abort on encountering the
36 * CONSOLE_T_GETC macro, which is undefined.
37 */
Soby Mathew58873ae2018-10-10 16:03:09 +010038 .ifne \getc
39 adrp x1, console_\_driver\()_getc
40 add x1, x1, :lo12:console_\_driver\()_getc
41 str x1, [x0, #CONSOLE_T_GETC]
42 .else
Sandrine Bailleuxf57e2032023-10-11 08:38:00 +020043#if ENABLE_CONSOLE_GETC
Soby Mathew58873ae2018-10-10 16:03:09 +010044 str xzr, [x0, #CONSOLE_T_GETC]
Sandrine Bailleuxf57e2032023-10-11 08:38:00 +020045#endif
Soby Mathew58873ae2018-10-10 16:03:09 +010046 .endif
Julius Werner94f89072017-07-31 18:15:11 -070047
Soby Mathew58873ae2018-10-10 16:03:09 +010048 .ifne \flush
49 adrp x1, console_\_driver\()_flush
50 add x1, x1, :lo12:console_\_driver\()_flush
51 str x1, [x0, #CONSOLE_T_FLUSH]
52 .else
53 str xzr, [x0, #CONSOLE_T_FLUSH]
54 .endif
55
56 mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
57 str x1, [x0, #CONSOLE_T_FLAGS]
58 b console_register
59 .endm
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000060
61#endif /* CONSOLE_MACROS_S */