blob: 996cb327f3f2fcd07e6d07736bf3dc933d9c2c2e [file] [log] [blame]
Daniel Boulby05e7f562018-09-19 13:58:20 +01001/*
Ambroise Vincent0a0ca8b2019-03-27 15:45:35 +00002 * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
Daniel Boulby05e7f562018-09-19 13:58:20 +01003 *
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
Daniel Boulby05e7f562018-09-19 13:58:20 +01008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <drivers/console.h>
Daniel Boulby05e7f562018-09-19 13:58:20 +010010
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.
Ambroise Vincent35e08da2019-05-31 16:21:59 +010018 * REQUIRES console_t pointer in r0 and a valid return address in lr.
Daniel Boulby05e7f562018-09-19 13:58:20 +010019 */
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 ldr r1, =console_\_driver\()_putc
27 .else
28 mov r1, #0
29 .endif
30 str r1, [r0, #CONSOLE_T_PUTC]
Daniel Boulby05e7f562018-09-19 13:58:20 +010031
Soby Mathew58873ae2018-10-10 16:03:09 +010032 .ifne \getc
33 ldr r1, =console_\_driver\()_getc
34 .else
35 mov r1, #0
36 .endif
37 str r1, [r0, #CONSOLE_T_GETC]
38
39 .ifne \flush
40 ldr r1, =console_\_driver\()_flush
41 .else
42 mov r1, #0
43 .endif
44 str r1, [r0, #CONSOLE_T_FLUSH]
45
46 mov r1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
47 str r1, [r0, #CONSOLE_T_FLAGS]
48 b console_register
49 .endm
Ambroise Vincent0a0ca8b2019-03-27 15:45:35 +000050
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000051#endif /* CONSOLE_MACROS_S */