1*f5478dedSAntonio Nino Diaz/* 2*f5478dedSAntonio Nino Diaz * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 3*f5478dedSAntonio Nino Diaz * 4*f5478dedSAntonio Nino Diaz * SPDX-License-Identifier: BSD-3-Clause 5*f5478dedSAntonio Nino Diaz */ 6*f5478dedSAntonio Nino Diaz#ifndef CONSOLE_MACROS_S 7*f5478dedSAntonio Nino Diaz#define CONSOLE_MACROS_S 8*f5478dedSAntonio Nino Diaz 9*f5478dedSAntonio Nino Diaz#include <console.h> 10*f5478dedSAntonio Nino Diaz 11*f5478dedSAntonio Nino Diaz/* 12*f5478dedSAntonio Nino Diaz * This macro encapsulates the common setup that has to be done at the end of 13*f5478dedSAntonio Nino Diaz * a console driver's register function. It will register all of the driver's 14*f5478dedSAntonio Nino Diaz * callbacks in the console_t structure and initialize the flags field (by 15*f5478dedSAntonio Nino Diaz * default consoles are enabled for the "boot" and "crash" states, this can be 16*f5478dedSAntonio Nino Diaz * changed after registration with the console_set_scope() function). It ends 17*f5478dedSAntonio Nino Diaz * with a tail call that will include return to the caller. 18*f5478dedSAntonio Nino Diaz * REQUIRES console_t pointer in x0 and a valid return address in x30. 19*f5478dedSAntonio Nino Diaz */ 20*f5478dedSAntonio Nino Diaz/* 21*f5478dedSAntonio Nino Diaz * The USE_FINISH_CONSOLE_REG_2 guard is introduced to allow selection between 22*f5478dedSAntonio Nino Diaz * the 2 variants of the finish_console_register macro and will be removed 23*f5478dedSAntonio Nino Diaz * once the deprecated variant is removed. 24*f5478dedSAntonio Nino Diaz */ 25*f5478dedSAntonio Nino Diaz#ifndef USE_FINISH_CONSOLE_REG_2 26*f5478dedSAntonio Nino Diaz#if !ERROR_DEPRECATED 27*f5478dedSAntonio Nino Diaz /* This version of the macro is deprecated. Use the new version */ 28*f5478dedSAntonio Nino Diaz .macro finish_console_register _driver 29*f5478dedSAntonio Nino Diaz /* 30*f5478dedSAntonio Nino Diaz * Add these weak definitions so we will automatically write a 0 if the 31*f5478dedSAntonio Nino Diaz * function doesn't exist. I'd rather use .ifdef but that only works if 32*f5478dedSAntonio Nino Diaz * the function was defined (not just declared .global) above this point 33*f5478dedSAntonio Nino Diaz * in the file, which we can't guarantee. 34*f5478dedSAntonio Nino Diaz */ 35*f5478dedSAntonio Nino Diaz .weak console_\_driver\()_putc 36*f5478dedSAntonio Nino Diaz .weak console_\_driver\()_getc 37*f5478dedSAntonio Nino Diaz .weak console_\_driver\()_flush 38*f5478dedSAntonio Nino Diaz 39*f5478dedSAntonio Nino Diaz /* Don't use adrp on weak funcs! See GNU ld bugzilla issue 22589. */ 40*f5478dedSAntonio Nino Diaz ldr x1, =console_\_driver\()_putc 41*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_PUTC] 42*f5478dedSAntonio Nino Diaz ldr x1, =console_\_driver\()_getc 43*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_GETC] 44*f5478dedSAntonio Nino Diaz ldr x1, =console_\_driver\()_flush 45*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_FLUSH] 46*f5478dedSAntonio Nino Diaz mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH) 47*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_FLAGS] 48*f5478dedSAntonio Nino Diaz b console_register 49*f5478dedSAntonio Nino Diaz .endm 50*f5478dedSAntonio Nino Diaz#endif /* ERROR_DEPRECATED */ 51*f5478dedSAntonio Nino Diaz#else /* USE_FINISH_CONSOLE_REG_2 */ 52*f5478dedSAntonio Nino Diaz /* The new version of the macro not using weak references */ 53*f5478dedSAntonio Nino Diaz .macro finish_console_register _driver, putc=0, getc=0, flush=0 54*f5478dedSAntonio Nino Diaz /* 55*f5478dedSAntonio Nino Diaz * If any of the callback is not specified or set as 0, then the 56*f5478dedSAntonio Nino Diaz * corresponding callback entry in console_t is set to 0. 57*f5478dedSAntonio Nino Diaz */ 58*f5478dedSAntonio Nino Diaz .ifne \putc 59*f5478dedSAntonio Nino Diaz adrp x1, console_\_driver\()_putc 60*f5478dedSAntonio Nino Diaz add x1, x1, :lo12:console_\_driver\()_putc 61*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_PUTC] 62*f5478dedSAntonio Nino Diaz .else 63*f5478dedSAntonio Nino Diaz str xzr, [x0, #CONSOLE_T_PUTC] 64*f5478dedSAntonio Nino Diaz .endif 65*f5478dedSAntonio Nino Diaz 66*f5478dedSAntonio Nino Diaz .ifne \getc 67*f5478dedSAntonio Nino Diaz adrp x1, console_\_driver\()_getc 68*f5478dedSAntonio Nino Diaz add x1, x1, :lo12:console_\_driver\()_getc 69*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_GETC] 70*f5478dedSAntonio Nino Diaz .else 71*f5478dedSAntonio Nino Diaz str xzr, [x0, #CONSOLE_T_GETC] 72*f5478dedSAntonio Nino Diaz .endif 73*f5478dedSAntonio Nino Diaz 74*f5478dedSAntonio Nino Diaz .ifne \flush 75*f5478dedSAntonio Nino Diaz adrp x1, console_\_driver\()_flush 76*f5478dedSAntonio Nino Diaz add x1, x1, :lo12:console_\_driver\()_flush 77*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_FLUSH] 78*f5478dedSAntonio Nino Diaz .else 79*f5478dedSAntonio Nino Diaz str xzr, [x0, #CONSOLE_T_FLUSH] 80*f5478dedSAntonio Nino Diaz .endif 81*f5478dedSAntonio Nino Diaz 82*f5478dedSAntonio Nino Diaz mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH) 83*f5478dedSAntonio Nino Diaz str x1, [x0, #CONSOLE_T_FLAGS] 84*f5478dedSAntonio Nino Diaz b console_register 85*f5478dedSAntonio Nino Diaz .endm 86*f5478dedSAntonio Nino Diaz#endif /* USE_FINISH_CONSOLE_REG_2 */ 87*f5478dedSAntonio Nino Diaz 88*f5478dedSAntonio Nino Diaz#endif /* CONSOLE_MACROS_S */ 89