blob: 90ef4204877f81a726474f431b9bd120391257a1 [file] [log] [blame]
Julius Werner94f89072017-07-31 18:15:11 -07001/*
Soby Mathew58873ae2018-10-10 16:03:09 +01002 * Copyright (c) 2017-2018, 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/*
21 * The USE_FINISH_CONSOLE_REG_2 guard is introduced to allow selection between
22 * the 2 variants of the finish_console_register macro and will be removed
23 * once the deprecated variant is removed.
24 */
25#ifndef USE_FINISH_CONSOLE_REG_2
26#if !ERROR_DEPRECATED
27 /* This version of the macro is deprecated. Use the new version */
Julius Werner94f89072017-07-31 18:15:11 -070028 .macro finish_console_register _driver
29 /*
30 * Add these weak definitions so we will automatically write a 0 if the
31 * function doesn't exist. I'd rather use .ifdef but that only works if
32 * the function was defined (not just declared .global) above this point
33 * in the file, which we can't guarantee.
34 */
35 .weak console_\_driver\()_putc
36 .weak console_\_driver\()_getc
37 .weak console_\_driver\()_flush
38
39 /* Don't use adrp on weak funcs! See GNU ld bugzilla issue 22589. */
40 ldr x1, =console_\_driver\()_putc
41 str x1, [x0, #CONSOLE_T_PUTC]
42 ldr x1, =console_\_driver\()_getc
43 str x1, [x0, #CONSOLE_T_GETC]
44 ldr x1, =console_\_driver\()_flush
45 str x1, [x0, #CONSOLE_T_FLUSH]
46 mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
47 str x1, [x0, #CONSOLE_T_FLAGS]
48 b console_register
49 .endm
Soby Mathew58873ae2018-10-10 16:03:09 +010050#endif /* ERROR_DEPRECATED */
51#else /* USE_FINISH_CONSOLE_REG_2 */
52 /* The new version of the macro not using weak references */
53 .macro finish_console_register _driver, putc=0, getc=0, flush=0
54 /*
55 * If any of the callback is not specified or set as 0, then the
56 * corresponding callback entry in console_t is set to 0.
57 */
58 .ifne \putc
59 adrp x1, console_\_driver\()_putc
60 add x1, x1, :lo12:console_\_driver\()_putc
61 str x1, [x0, #CONSOLE_T_PUTC]
62 .else
63 str xzr, [x0, #CONSOLE_T_PUTC]
64 .endif
65
66 .ifne \getc
67 adrp x1, console_\_driver\()_getc
68 add x1, x1, :lo12:console_\_driver\()_getc
69 str x1, [x0, #CONSOLE_T_GETC]
70 .else
71 str xzr, [x0, #CONSOLE_T_GETC]
72 .endif
Julius Werner94f89072017-07-31 18:15:11 -070073
Soby Mathew58873ae2018-10-10 16:03:09 +010074 .ifne \flush
75 adrp x1, console_\_driver\()_flush
76 add x1, x1, :lo12:console_\_driver\()_flush
77 str x1, [x0, #CONSOLE_T_FLUSH]
78 .else
79 str xzr, [x0, #CONSOLE_T_FLUSH]
80 .endif
81
82 mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
83 str x1, [x0, #CONSOLE_T_FLAGS]
84 b console_register
85 .endm
86#endif /* USE_FINISH_CONSOLE_REG_2 */
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000087
88#endif /* CONSOLE_MACROS_S */