Daniel Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 1 | /* |
Ambroise Vincent | 0a0ca8b | 2019-03-27 15:45:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. |
Daniel Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 6 | #ifndef CONSOLE_MACROS_S |
| 7 | #define CONSOLE_MACROS_S |
Daniel Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <drivers/console.h> |
Daniel Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 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. |
Ambroise Vincent | 35e08da | 2019-05-31 16:21:59 +0100 | [diff] [blame] | 18 | * REQUIRES console_t pointer in r0 and a valid return address in lr. |
Daniel Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 19 | */ |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 20 | .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 Boulby | 05e7f56 | 2018-09-19 13:58:20 +0100 | [diff] [blame] | 31 | |
Sandrine Bailleux | f57e203 | 2023-10-11 08:38:00 +0200 | [diff] [blame] | 32 | /* |
| 33 | * If ENABLE_CONSOLE_GETC support is disabled, but a getc callback is |
| 34 | * specified nonetheless, the assembler will abort on encountering the |
| 35 | * CONSOLE_T_GETC macro, which is undefined. |
| 36 | */ |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 37 | .ifne \getc |
| 38 | ldr r1, =console_\_driver\()_getc |
Sandrine Bailleux | f57e203 | 2023-10-11 08:38:00 +0200 | [diff] [blame] | 39 | str r1, [r0, #CONSOLE_T_GETC] |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 40 | .else |
Sandrine Bailleux | f57e203 | 2023-10-11 08:38:00 +0200 | [diff] [blame] | 41 | #if ENABLE_CONSOLE_GETC |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 42 | mov r1, #0 |
Sandrine Bailleux | f57e203 | 2023-10-11 08:38:00 +0200 | [diff] [blame] | 43 | str r1, [r0, #CONSOLE_T_GETC] |
| 44 | #endif |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 45 | .endif |
Soby Mathew | 58873ae | 2018-10-10 16:03:09 +0100 | [diff] [blame] | 46 | |
| 47 | .ifne \flush |
| 48 | ldr r1, =console_\_driver\()_flush |
| 49 | .else |
| 50 | mov r1, #0 |
| 51 | .endif |
| 52 | str r1, [r0, #CONSOLE_T_FLUSH] |
| 53 | |
| 54 | mov r1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH) |
| 55 | str r1, [r0, #CONSOLE_T_FLAGS] |
| 56 | b console_register |
| 57 | .endm |
Ambroise Vincent | 0a0ca8b | 2019-03-27 15:45:35 +0000 | [diff] [blame] | 58 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 59 | #endif /* CONSOLE_MACROS_S */ |