blob: 0ebea2c1b5e540ef198138d03f6342e95b7e5072 [file] [log] [blame]
Julius Werner94f89072017-07-31 18:15:11 -07001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6#ifndef __CONSOLE_MACROS_S__
7#define __CONSOLE_MACROS_S__
8
9#include <console.h>
10
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 */
20 .macro finish_console_register _driver
21 /*
22 * Add these weak definitions so we will automatically write a 0 if the
23 * function doesn't exist. I'd rather use .ifdef but that only works if
24 * the function was defined (not just declared .global) above this point
25 * in the file, which we can't guarantee.
26 */
27 .weak console_\_driver\()_putc
28 .weak console_\_driver\()_getc
29 .weak console_\_driver\()_flush
30
31 /* Don't use adrp on weak funcs! See GNU ld bugzilla issue 22589. */
32 ldr x1, =console_\_driver\()_putc
33 str x1, [x0, #CONSOLE_T_PUTC]
34 ldr x1, =console_\_driver\()_getc
35 str x1, [x0, #CONSOLE_T_GETC]
36 ldr x1, =console_\_driver\()_flush
37 str x1, [x0, #CONSOLE_T_FLUSH]
38 mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
39 str x1, [x0, #CONSOLE_T_FLAGS]
40 b console_register
41 .endm
42
43#endif /* __CONSOLE_MACROS_S__ */