console_macros.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2017-2019, 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. #include <drivers/console.h>
  9. /*
  10. * This macro encapsulates the common setup that has to be done at the end of
  11. * a console driver's register function. It will register all of the driver's
  12. * callbacks in the console_t structure and initialize the flags field (by
  13. * default consoles are enabled for the "boot" and "crash" states, this can be
  14. * changed after registration with the console_set_scope() function). It ends
  15. * with a tail call that will include return to the caller.
  16. * REQUIRES console_t pointer in x0 and a valid return address in x30.
  17. */
  18. .macro finish_console_register _driver, putc=0, getc=0, flush=0
  19. /*
  20. * If any of the callback is not specified or set as 0, then the
  21. * corresponding callback entry in console_t is set to 0.
  22. */
  23. .ifne \putc
  24. adrp x1, console_\_driver\()_putc
  25. add x1, x1, :lo12:console_\_driver\()_putc
  26. str x1, [x0, #CONSOLE_T_PUTC]
  27. .else
  28. str xzr, [x0, #CONSOLE_T_PUTC]
  29. .endif
  30. /*
  31. * If ENABLE_CONSOLE_GETC support is disabled, but a getc callback is
  32. * specified nonetheless, the assembler will abort on encountering the
  33. * CONSOLE_T_GETC macro, which is undefined.
  34. */
  35. .ifne \getc
  36. adrp x1, console_\_driver\()_getc
  37. add x1, x1, :lo12:console_\_driver\()_getc
  38. str x1, [x0, #CONSOLE_T_GETC]
  39. .else
  40. #if ENABLE_CONSOLE_GETC
  41. str xzr, [x0, #CONSOLE_T_GETC]
  42. #endif
  43. .endif
  44. .ifne \flush
  45. adrp x1, console_\_driver\()_flush
  46. add x1, x1, :lo12:console_\_driver\()_flush
  47. str x1, [x0, #CONSOLE_T_FLUSH]
  48. .else
  49. str xzr, [x0, #CONSOLE_T_FLUSH]
  50. .endif
  51. mov x1, #(CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH)
  52. str x1, [x0, #CONSOLE_T_FLAGS]
  53. b console_register
  54. .endm
  55. #endif /* CONSOLE_MACROS_S */